Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for API Resource properties #5020

Merged
merged 4 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ APIResourceSearchResult getAPIResources(String after, String before, Integer lim
String tenantDomain)
throws APIResourceMgtException;

/**
* Get API resources with required attributes.
*
* @param after Get API resources after this value.
* @param before Get API resources before this value.
* @param limit Number of API resources to retrieve.
* @param filter Filter expression.
* @param sortOrder Sort order.
* @param tenantDomain Tenant domain.
* @param requiredAttributes Required attributes.
* @return API resource search result with required attributes.
* @throws APIResourceMgtException If an error occurs while retrieving API resources with required attributes.
*/
APIResourceSearchResult getAPIResourcesWithRequiredAttributes(String after, String before, Integer limit,
String filter, String sortOrder,
String tenantDomain, List<String> requiredAttributes)
throws APIResourceMgtException;

/**
* Get API resource by id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ public APIResourceSearchResult getAPIResources(String after, String before, Inte
return result;
}

@Override
public APIResourceSearchResult getAPIResourcesWithRequiredAttributes(String after, String before, Integer limit,
String filter, String sortOrder,
String tenantDomain,
List<String> requiredAttributes)
throws APIResourceMgtException {

APIResourceSearchResult result = new APIResourceSearchResult();
List<ExpressionNode> expressionNodes = getExpressionNodes(filter, after, before);
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
result.setTotalCount(CACHE_BACKED_DAO.getAPIResourcesCount(tenantId, expressionNodes));
result.setAPIResources(CACHE_BACKED_DAO.getAPIResourcesWithRequiredAttributes(limit, tenantId, sortOrder,
expressionNodes, requiredAttributes));
return result;
}

@Override
public APIResource getAPIResourceById(String apiResourceId, String tenantDomain)
throws APIResourceMgtException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class APIResourceManagementConstants {
public static final String TYPE = "type";
public static final String BEFORE = "before";
public static final String AFTER = "after";
public static final String PROPERTIES = "properties";
public static final String EQ = "eq";
public static final String CO = "co";
public static final String SW = "sw";
Expand Down Expand Up @@ -98,6 +99,10 @@ public enum ErrorMessages {
" scope.", "Error while checking existence of scope in the database."),
ERROR_CODE_ERROR_WHILE_CHECKING_API_RESOURCE_EXISTENCE("65011", "Error while checking existence " +
"of API resource.", "Error while checking existence of API resource in the database."),
ERROR_CODE_ERROR_WHILE_RETRIEVING_API_RESOURCE_PROPERTIES("65013", "Error while retrieving API " +
SujanSanjula96 marked this conversation as resolved.
Show resolved Hide resolved
"resource properties.", "Error while retrieving API resource properties from the database."),
ERROR_CODE_ERROR_WHILE_ADDING_API_RESOURCE_PROPERTIES("65014", "Error while adding API resource " +
"properties.", "Error while adding API resource properties to the database."),
;

private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class SQLConstants {
// DB types.
public static final String MICROSOFT = "Microsoft";
public static final String DB2 = "DB2";
public static final String H2 = "H2";

// Column names.
public static final String ID_COLUMN_NAME = "ID";
Expand All @@ -37,6 +38,7 @@ public class SQLConstants {
public static final String TYPE_COLUMN_NAME = "TYPE";
public static final String REQUIRES_AUTHORIZATION_COLUMN_NAME = "REQUIRES_AUTHORIZATION";
public static final String DISPLAY_NAME_COLUMN_NAME = "DISPLAY_NAME";
public static final String VALUE_COLUMN_NAME = "VALUE";
public static final String API_RESOURCE_ID_COLUMN_NAME = "API_RESOURCE_ID";
public static final String API_RESOURCE_NAME_COLUMN_NAME = "API_RESOURCE_NAME";
public static final String API_RESOURCE_IDENTIFIER_COLUMN_NAME = "API_RESOURCE_IDENTIFIER";
Expand All @@ -47,6 +49,9 @@ public class SQLConstants {
public static final String SCOPE_QUALIFIED_NAME_COLUMN_NAME = "SCOPE_QUALIFIED_NAME";
public static final String SCOPE_DISPLAY_NAME_COLUMN_NAME = "SCOPE_DISPLAY_NAME";
public static final String SCOPE_DESCRIPTION_COLUMN_NAME = "SCOPE_DESCRIPTION";
public static final String API_RESOURCE_PROPERTY_ID_COLUMN_NAME = "PROPERTY_ID";
public static final String API_RESOURCE_PROPERTY_NAME_COLUMN_NAME = "PROPERTY_NAME";
public static final String API_RESOURCE_PROPERTY_VALUE_COLUMN_NAME = "PROPERTY_VALUE";

// Database constraint names.
public static final String API_RESOURCE_UNIQUE_CONSTRAINT = "identifier_unique";
Expand All @@ -62,6 +67,34 @@ public class SQLConstants {
" TENANT_ID = %d ORDER BY CURSOR_KEY %s LIMIT %d";
public static final String GET_API_RESOURCES_TAIL_MSSQL =
" TENANT_ID = %d ORDER BY CURSOR_KEY %s";
public static final String GET_API_RESOURCES_WITH_PROPERTIES_SELECTION = "SELECT" +
" AR.ID AS API_RESOURCE_ID," +
" AR.CURSOR_KEY AS CURSOR_KEY," +
" AR.NAME AS API_RESOURCE_NAME," +
" AR.IDENTIFIER AS API_RESOURCE_IDENTIFIER," +
" AR.DESCRIPTION AS API_RESOURCE_DESCRIPTION," +
" AR.TENANT_ID AS API_RESOURCE_TENANT_ID," +
" AR.TYPE AS API_RESOURCE_TYPE," +
" AR.REQUIRES_AUTHORIZATION AS REQUIRES_AUTHORIZATION," +
" ARP.ID AS PROPERTY_ID," +
" ARP.NAME AS PROPERTY_NAME," +
" ARP.VALUE AS PROPERTY_VALUE" +
" FROM (";
public static final String GET_API_RESOURCES_WITH_PROPERTIES_SELECTION_H2 = "SELECT" +
" AR.ID AS API_RESOURCE_ID," +
" AR.CURSOR_KEY AS CURSOR_KEY," +
" AR.NAME AS API_RESOURCE_NAME," +
" AR.IDENTIFIER AS API_RESOURCE_IDENTIFIER," +
" AR.DESCRIPTION AS API_RESOURCE_DESCRIPTION," +
" AR.TENANT_ID AS API_RESOURCE_TENANT_ID," +
" AR.TYPE AS API_RESOURCE_TYPE," +
" AR.REQUIRES_AUTHORIZATION AS REQUIRES_AUTHORIZATION," +
" ARP.ID AS PROPERTY_ID," +
" ARP.NAME AS PROPERTY_NAME," +
" ARP.`VALUE` AS PROPERTY_VALUE" +
" FROM (";
public static final String GET_API_RESOURCES_WITH_PROPERTIES_JOIN = ") AR" +
" LEFT JOIN API_RESOURCE_PROPERTY ARP ON AR.ID = ARP.API_ID ORDER BY CURSOR_KEY %s";
public static final String GET_API_RESOURCES_COUNT = "SELECT COUNT(DISTINCT(ID)) FROM API_RESOURCE WHERE ";
public static final String GET_API_RESOURCES_COUNT_TAIL = " TENANT_ID = ?";
public static final String GET_API_RESOURCE_BY_ID = "SELECT" +
Expand Down Expand Up @@ -111,4 +144,18 @@ public class SQLConstants {
"TENANT_ID FROM SCOPE WHERE ";
public static final String GET_SCOPES_BY_TENANT_ID_TAIL = " TENANT_ID = ?";
public static final String DELETE_SCOPE_BY_NAME = "DELETE FROM SCOPE WHERE NAME = ? AND TENANT_ID = ?";
public static final String GET_API_RESOURCE_PROPERTIES_BY_API_ID = "SELECT ID, NAME, VALUE FROM " +
"API_RESOURCE_PROPERTY WHERE API_ID = ?";
public static final String GET_API_RESOURCE_PROPERTIES_BY_API_ID_H2 = "SELECT ID, NAME, `VALUE` FROM " +
"API_RESOURCE_PROPERTY WHERE API_ID = ?";
public static final String GET_API_RESOURCE_PROPERTIES_BY_API_IDENTIFIER = "SELECT ARP.ID, ARP.NAME, ARP.VALUE " +
"FROM API_RESOURCE AR JOIN API_RESOURCE_PROPERTY ARP ON AR.ID = ARP.API_ID WHERE AR.IDENTIFIER = ? " +
"AND AR.TENANT_ID = ?";
public static final String GET_API_RESOURCE_PROPERTIES_BY_API_IDENTIFIER_H2 = "SELECT ARP.ID, ARP.NAME, " +
"ARP.`VALUE` FROM API_RESOURCE AR JOIN API_RESOURCE_PROPERTY ARP ON AR.ID = ARP.API_ID WHERE " +
"AR.IDENTIFIER = ? AND AR.TENANT_ID = ?";
public static final String ADD_API_RESOURCE_PROPERTY = "INSERT INTO API_RESOURCE_PROPERTY (API_ID, NAME, VALUE) " +
"VALUES (?, ?, ?)";
public static final String ADD_API_RESOURCE_PROPERTY_H2 = "INSERT INTO API_RESOURCE_PROPERTY (API_ID, NAME, " +
"`VALUE`) VALUES (?, ?, ?)";
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public interface APIResourceManagementDAO {
List<APIResource> getAPIResources(Integer limit, Integer tenantId, String sortOrder,
List<ExpressionNode> expressionNodes) throws APIResourceMgtException;

/**
* Retrieve the API resources under a given tenantId.
*
* @param limit Maximum number of records to return.
* @param tenantId Tenant Id.
* @param sortOrder Sort order for the cursor based pagination.
* @param expressionNodes Expression nodes.
* @param requiredAttributes List of required attributes
* @return List of <code>APIResource</code>.
* @throws APIResourceMgtException If an error occurs while retrieving the API resources.
*/
List<APIResource> getAPIResourcesWithRequiredAttributes(Integer limit, Integer tenantId, String sortOrder,
List<ExpressionNode> expressionNodes,
List<String> requiredAttributes)
throws APIResourceMgtException;

/**
* Retrieve the count of API resources under a given tenantId.
*
Expand Down
Loading
Loading