diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java index d57269e89..cb5c06d40 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManager.java @@ -214,13 +214,13 @@ default int getCountOfDiscoverableSharedApplications(String filter, String tenan } /** - * Check whether the main application has fragment applications. + * Check whether the main application has shared applications. * * @param mainApplicationId Main application ID. - * @return True if the main application has fragment applications. - * @throws OrganizationManagementException If an error occurred when checking fragment applications. + * @return True if the main application has shared applications. + * @throws OrganizationManagementException If an error occurred when checking shared applications. */ - default boolean hasFragmentApps(String mainApplicationId) throws OrganizationManagementException { + default boolean hasSharedApps(String mainApplicationId) throws OrganizationManagementException { return false; } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java index cb9febd77..f65434de2 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/OrgApplicationManagerImpl.java @@ -730,7 +730,7 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant } @Override - public boolean hasFragmentApps(String mainApplicationId) throws OrganizationManagementException { + public boolean hasSharedApps(String mainApplicationId) throws OrganizationManagementException { return getOrgApplicationMgtDAO().hasFragments(mainApplicationId); } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java index 3a559bd06..008a739e5 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/constant/SQLConstants.java @@ -176,7 +176,7 @@ public class SQLConstants { "sa_shared.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? AND (sa_main.IS_DISCOVERABLE = '1' OR " + "sa_shared.IS_DISCOVERABLE = '1')"; - public static final String DELETE_SHARED_APP_LINK = "DELETE FROM SP_SHARED_APP WHERE SHARED_ORG_ID = :" + + public static final String DELETE_SHARED_APP_LINKS_OF_ORG = "DELETE FROM SP_SHARED_APP WHERE SHARED_ORG_ID = :" + SQLPlaceholders.DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID + ";"; private SQLConstants() { diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java index c334394d1..ca243cf37 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/OrgApplicationMgtDAO.java @@ -173,7 +173,7 @@ List getDiscoverableSharedApplicationBasicInfo(int limit, int getCountOfDiscoverableSharedApplications(String filter, String tenantDomain, String rootOrgId) throws OrganizationManagementException; - default void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException { + default void deleteSharedAppLinks(String organizationId) throws OrganizationManagementServerException { return; } diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java index b5744af35..3717d1eff 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/dao/impl/OrgApplicationMgtDAOImpl.java @@ -57,7 +57,7 @@ import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getConsoleAccessUrlFromServerConfig; import static org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil.getMyAccountAccessUrlFromServerConfig; import static org.wso2.carbon.identity.organization.management.application.constant.OrgApplicationMgtConstants.IS_FRAGMENT_APP; -import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.DELETE_SHARED_APP_LINK; +import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.DELETE_SHARED_APP_LINKS_OF_ORG; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_FILTERED_SHARED_APPLICATIONS; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_MAIN_APPLICATION; import static org.wso2.carbon.identity.organization.management.application.constant.SQLConstants.GET_SHARED_APPLICATION; @@ -383,11 +383,11 @@ public int getCountOfDiscoverableSharedApplications(String filter, String tenant } @Override - public void deleteSharedAppLink(String organizationId) throws OrganizationManagementServerException { + public void deleteSharedAppLinks(String organizationId) throws OrganizationManagementServerException { NamedJdbcTemplate namedJdbcTemplate = getNewTemplate(); try { - namedJdbcTemplate.executeUpdate(DELETE_SHARED_APP_LINK, preparedStatement -> { + namedJdbcTemplate.executeUpdate(DELETE_SHARED_APP_LINKS_OF_ORG, preparedStatement -> { preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID, organizationId); }); } catch (DataAccessException e) { diff --git a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java index 4c326b192..9c42f8743 100644 --- a/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java +++ b/components/org.wso2.carbon.identity.organization.management.application/src/main/java/org/wso2/carbon/identity/organization/management/application/listener/OrganizationCreationHandler.java @@ -55,7 +55,6 @@ import static org.wso2.carbon.identity.organization.management.application.constant.OrgApplicationMgtConstants.SHARE_WITH_ALL_CHILDREN; import static org.wso2.carbon.identity.organization.management.application.util.OrgApplicationManagerUtil.setIsAppSharedProperty; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.IS_APP_SHARED; -import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ORGANIZATION_ID_PROPERTY; import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SUPER_ORG_ID; import static org.wso2.carbon.identity.organization.management.service.util.Utils.getAuthenticatedUsername; @@ -71,9 +70,10 @@ public class OrganizationCreationHandler extends AbstractEventHandler { public void handleEvent(Event event) throws IdentityEventException { String eventName = event.getEventName(); + Map eventProperties = event.getEventProperties(); + String organizationId = (String) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION_ID); if (Constants.EVENT_POST_ADD_ORGANIZATION.equals(eventName)) { - Map eventProperties = event.getEventProperties(); Organization organization = (Organization) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION); try { addSharedApplicationsToOrganization(organization); @@ -84,10 +84,7 @@ public void handleEvent(Event event) throws IdentityEventException { } if (Constants.EVENT_PRE_DELETE_ORGANIZATION.equals(eventName)) { - Map eventProperties = event.getEventProperties(); - String organizationId = (String) eventProperties.get(Constants.EVENT_PROP_ORGANIZATION_ID); try { - handleSharedAppDeletionForPostDeleteOrganization(event); handleMainApplicationUpdateForPreDeleteOrganization(organizationId); } catch (IdentityApplicationManagementException | OrganizationManagementException e) { throw new IdentityEventException("An error occurred while retrieving main applications of " + @@ -97,6 +94,7 @@ public void handleEvent(Event event) throws IdentityEventException { if (Constants.EVENT_POST_DELETE_ORGANIZATION.equals(eventName)) { try { + handleSharedAppDeletionForPostDeleteOrganization(organizationId); handleMainApplicationUpdateForPostDeleteOrganization(); } catch (OrganizationManagementException | IdentityApplicationManagementException e) { throw new IdentityEventException("An error occurred while updating main application based " + @@ -164,16 +162,15 @@ private void addSharedApplicationsToOrganization(Organization organization) /** * Handle shared application deletion for post delete organization. * - * @param event Event. + * @param organizationId ID of the organization. */ - private void handleSharedAppDeletionForPostDeleteOrganization(Event event) + private void handleSharedAppDeletionForPostDeleteOrganization(String organizationId) throws OrganizationManagementServerException { - String organizationId = (String) event.getEventProperties().get(ORGANIZATION_ID_PROPERTY); if (StringUtils.isBlank(organizationId)) { return; } - getOrgApplicationMgtDAO().deleteSharedAppLink(organizationId); + getOrgApplicationMgtDAO().deleteSharedAppLinks(organizationId); } @@ -223,7 +220,7 @@ private void handleMainApplicationUpdateForPostDeleteOrganization() throws Ident PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(rootTenantDomain, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(username); for (String mainAppId : mainAppIds) { - boolean hasFragmentsApps = getOrgApplicationManager().hasFragmentApps(mainAppId); + boolean hasFragmentsApps = getOrgApplicationManager().hasSharedApps(mainAppId); // Since the application doesn't have any shared organizations, isAppShared service provider property // should be set to false. if (!hasFragmentsApps) {