Skip to content

Commit

Permalink
Support updating api resource type
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Feb 8, 2024
1 parent 2f3ea60 commit 53448c2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ 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 SCOPE_API_ID_COLUMN_NAME = "API_ID";
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";
Expand Down Expand Up @@ -138,7 +139,7 @@ public class SQLConstants {
"OR TENANT_ID IS NULL)";
public static final String DELETE_SCOPES_BY_API = "DELETE FROM SCOPE WHERE API_ID = ? AND ( TENANT_ID = ? " +
"OR TENANT_ID IS NULL)";
public static final String UPDATE_API_RESOURCE = "UPDATE API_RESOURCE SET NAME = ?, DESCRIPTION = ?" +
public static final String UPDATE_API_RESOURCE = "UPDATE API_RESOURCE SET NAME = ?, DESCRIPTION = ?, TYPE = ?" +
" WHERE ID = ?";
public static final String IS_SCOPE_EXIST_BY_ID = "SELECT ID FROM SCOPE WHERE ID = ? AND TENANT_ID = ?";
public static final String GET_SCOPE_BY_NAME = "SELECT ID, NAME, DISPLAY_NAME, DESCRIPTION, API_ID, TENANT_ID "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ public void updateAPIResource(APIResource apiResource, List<Scope> addedScopes,
try {
preparedStatement.setString(1, apiResource.getName());
preparedStatement.setString(2, apiResource.getDescription());
preparedStatement.setString(3, apiResource.getId());
preparedStatement.setString(3, apiResource.getType());
preparedStatement.setString(4, apiResource.getId());
preparedStatement.executeUpdate();

if (CollectionUtils.isNotEmpty(addedScopes)) {
Expand Down Expand Up @@ -434,7 +435,7 @@ public List<Scope> getScopesByTenantId(Integer tenantId, List<ExpressionNode> ex
resultSet.getString(SQLConstants.NAME_COLUMN_NAME),
resultSet.getString(SQLConstants.DISPLAY_NAME_COLUMN_NAME),
resultSet.getString(SQLConstants.DESCRIPTION_COLUMN_NAME),
resultSet.getString("API_ID"),
resultSet.getString(SQLConstants.SCOPE_API_ID_COLUMN_NAME),
resultSet.getString(SQLConstants.TENANT_ID_COLUMN_NAME)
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,23 @@ public static void addSystemAPIs() {
if (addedScopes.isEmpty()) {
continue;
}

APIResource updatedAPIResourceFromDB = new APIResource.APIResourceBuilder()
.id(apiResourceFromDB.getId())
.name(apiResourceFromDB.getName())
.description(apiResourceFromDB.getDescription())
.identifier(apiResourceFromDB.getIdentifier())
// Set the type as the updated API resource type.
.type(updatedAPIResource.getType())
.tenantId(apiResourceFromDB.getTenantId())
.requiresAuthorization(apiResourceFromDB.isAuthorizationRequired())
.scopes(updatedAPIResource.getScopes())
.subscribedApplications(apiResourceFromDB.getSubscribedApplications())
.properties(apiResourceFromDB.getProperties())
.build();

// If there are scopes which are not in the existing API resource, update the API resource.
APIResourceManagerImpl.getInstance().updateAPIResource(apiResourceFromDB, addedScopes,
APIResourceManagerImpl.getInstance().updateAPIResource(updatedAPIResourceFromDB, addedScopes,
new ArrayList<>(), tenantDomain);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,11 @@
version="${org.wso2.carbon.identity.organization.management.core.version.range}",
org.wso2.carbon.identity.api.resource.mgt.model; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.api.resource.mgt.util; version="${carbon.identity.package.import.version.range}",
*;resolution:=optional
</Import-Package>
<Export-Package>
!org.wso2.carbon.identity.application.mgt.internal,
org.wso2.carbon.identity.application.mgt.*; version="${carbon.identity.package.export.version}"
</Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
Expand Down

0 comments on commit 53448c2

Please sign in to comment.