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

Retrieve Discoverable Applications info for Sub-Org #392

Merged
merged 10 commits into from
Sep 18, 2024
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 @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.organization.management.application;

import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.organization.management.application.model.SharedApplication;
import org.wso2.carbon.identity.organization.management.service.exception.NotImplementedException;
Expand Down Expand Up @@ -176,4 +177,37 @@ default Map<String, String> getChildAppIds(String parentAppId, String parentOrgI

throw new NotImplementedException("getChildAppIds method is not implemented in " + this.getClass().getName());
}

/*
* Get the discoverable application basic info.
asha15 marked this conversation as resolved.
Show resolved Hide resolved
* @param limit Maximum no of applications to be returned in the result set (optional).
* @param offset Zero based index of the first application to be returned in the result set (optional).
* @param filter Filter to search for applications (optional).
* @param sortOrder Sort order, ascending or descending (optional).
* @param sortBy Attribute to sort from (optional).
* @param tenantDomain Tenant domain.
asha15 marked this conversation as resolved.
Show resolved Hide resolved
* @return List of DiscoverableApplicationBasicInfo of applications matching the given criteria.
* @throws OrganizationManagementException If an error occurred when retrieving the discoverable applications.
*/
default List<ApplicationBasicInfo> getDiscoverableApplicationBasicInfo(int limit, int offset, String filter,
asha15 marked this conversation as resolved.
Show resolved Hide resolved
String sortOrder,
String sortBy, String tenantDomain)
throws OrganizationManagementException {

return null;
}

/*
* Get the count of discoverable applications.
asha15 marked this conversation as resolved.
Show resolved Hide resolved
* @param filter Filter to search for applications (optional).
* @param tenantDomain Tenant domain.
* @return Count of discoverable applications matching given filter.
* @throws OrganizationManagementException If an error occurred when retrieving the count of
* discoverable applications.
*/
default int getCountOfDiscoverableApplications(String filter, String tenantDomain)
throws OrganizationManagementException {

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo;
import org.wso2.carbon.identity.application.common.model.AuthenticationStep;
import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.model.IdentityProvider;
Expand Down Expand Up @@ -59,6 +60,7 @@
import org.wso2.carbon.identity.organization.management.application.model.SharedApplicationDO;
import org.wso2.carbon.identity.organization.management.ext.Constants;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.OrganizationManagerImpl;
import org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementClientException;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
Expand Down Expand Up @@ -709,6 +711,29 @@ public Map<String, String> getChildAppIds(String parentAppId, String parentOrgId
return Collections.emptyMap();
}

@Override
public List<ApplicationBasicInfo> getDiscoverableApplicationBasicInfo(int limit, int offset, String filter,
String sortOrder, String sortBy,
String tenantDomain)
throws OrganizationManagementException {

OrganizationManagerImpl organizationManager = new OrganizationManagerImpl();
VivekVinushanth marked this conversation as resolved.
Show resolved Hide resolved
String rootOrgId = organizationManager.getPrimaryOrganizationId(tenantDomain);

asha15 marked this conversation as resolved.
Show resolved Hide resolved
return getOrgApplicationMgtDAO().getDiscoverableApplicationBasicInfo(limit, offset, filter, sortOrder,
sortBy, tenantDomain, rootOrgId);
}

@Override
public int getCountOfDiscoverableApplications(String filter, String tenantDomain)
throws OrganizationManagementException {

OrganizationManagerImpl organizationManager = new OrganizationManagerImpl();
String rootOrgId = organizationManager.getPrimaryOrganizationId(tenantDomain);

return getOrgApplicationMgtDAO().getCountOfDiscoverableApplications(filter, tenantDomain, rootOrgId);
}

/**
* Returns whether the given application is a main application.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,110 @@ public class SQLConstants {
SQLPlaceholders.DB_SCHEMA_COLUMN_NAME_OWNER_ORG_ID + "; AND SHARED_ORG_ID IN (" +
SQLPlaceholders.SHARED_ORG_ID_LIST_PLACEHOLDER + ")";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_MYSQL =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND ssa.OWNER_ORG_ID = ? ) SELECT ID, APP_NAME, " +
"DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM DiscoverableApps WHERE " +
"rn = 1 ORDER BY ID DESC LIMIT ?, ?";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_POSTGRES =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND ssa.OWNER_ORG_ID = ? ) SELECT ID, APP_NAME, " +
"DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM DiscoverableApps WHERE " +
"rn = 1 ORDER BY ID DESC OFFSET ? LIMIT ?";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_ORACLE =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY " +
"sa.APP_NAME ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn " +
"FROM SP_APP sa JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND ssa.OWNER_ORG_ID = ? ) SELECT ID, APP_NAME, " +
"DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM DiscoverableApps WHERE " +
"rn = 1 BETWEEN ? AND ? ORDER BY ID DESC";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_MSSQL =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND ssa.OWNER_ORG_ID = ? ) SELECT ID, APP_NAME, " +
"DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM DiscoverableApps WHERE " +
"rn = 1 ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_INFORMIX =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND ssa.OWNER_ORG_ID = ? ) SELECT ID, APP_NAME, " +
"DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM DiscoverableApps WHERE " +
"rn = 1 ORDER BY ID DESC SKIP ? LIMIT ?";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_AND_APP_NAME_MYSQL =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND sa.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? ) " +
"SELECT ID, APP_NAME, DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM " +
"DiscoverableApps WHERE rn = 1 ORDER BY ID DESC LIMIT ?, ?";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_AND_APP_NAME_POSTGRESL =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND sa.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? ) " +
"SELECT ID, APP_NAME, DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM " +
"DiscoverableApps WHERE rn = 1 ORDER BY ID DESC OFFSET ? LIMIT ?";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_AND_APP_NAME_ORACLE =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND sa.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? ) " +
"SELECT ID, APP_NAME, DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM " +
"DiscoverableApps WHERE rn = 1 BETWEEN ? AND ? ORDER BY ID DESC";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_AND_APP_NAME_MSSQL =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND sa.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? ) " +
"SELECT ID, APP_NAME, DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM " +
"DiscoverableApps WHERE rn = 1 ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";

public static final String LOAD_DISCOVERABLE_APPS_BY_TENANT_AND_APP_NAME_INFORMIX =
"WITH DiscoverableApps AS ( SELECT sa.ID, sa.APP_NAME, sa.DESCRIPTION, sa.UUID, sa.IMAGE_URL, " +
"sa.ACCESS_URL, sa.USERNAME, sa.USER_STORE, sa.TENANT_ID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND sa.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? ) " +
"SELECT ID, APP_NAME, DESCRIPTION, UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM " +
"DiscoverableApps WHERE rn = 1 ORDER BY ID DESC SKIP ? LIMIT ?";

public static final String LOAD_DISCOVERABLE_APP_COUNT_BY_TENANT =
"WITH DiscoverableApps AS ( SELECT sa.UUID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME " +
"ORDER BY CASE WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa " +
"JOIN SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND ssa.OWNER_ORG_ID = ? ) SELECT count(UUID) " +
"FROM DiscoverableApps WHERE rn = 1";

public static final String LOAD_DISCOVERABLE_APP_COUNT_BY_APP_NAME_AND_TENANT =
"WITH DiscoverableApps AS ( SELECT sa.UUID, ROW_NUMBER() OVER ( PARTITION BY sa.APP_NAME ORDER BY CASE " +
"WHEN sa.UUID = ssa.SHARED_APP_ID THEN 1 ELSE 2 END, sa.ID DESC ) AS rn FROM SP_APP sa JOIN " +
"SP_SHARED_APP ssa ON sa.UUID = ssa.SHARED_APP_ID OR sa.UUID = ssa.MAIN_APP_ID WHERE " +
"ssa.SHARED_ORG_ID = ? AND sa.IS_DISCOVERABLE = '1' AND sa.APP_NAME LIKE ? AND ssa.OWNER_ORG_ID = ? ) " +
"SELECT count(UUID) FROM DiscoverableApps WHERE rn = 1";

private SQLConstants() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.organization.management.application.dao;

import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo;
import org.wso2.carbon.identity.organization.management.application.model.MainApplicationDO;
import org.wso2.carbon.identity.organization.management.application.model.SharedApplicationDO;
import org.wso2.carbon.identity.organization.management.service.exception.NotImplementedException;
Expand Down Expand Up @@ -138,4 +139,40 @@ default List<SharedApplicationDO> getSharedApplications(String mainAppId, String
throw new NotImplementedException(
"getSharedApplications method is not implemented in " + this.getClass().getName());
}

/**
* Returns the basic information of the shared applications
asha15 marked this conversation as resolved.
Show resolved Hide resolved
* @param limit Maximum no of applications to be returned in the result set (optional).
* @param offset Zero based index of the first application to be returned in the result set (optional).
* @param filter Filter to search for applications (optional).
* @param sortOrder Sort order, ascending or descending (optional).
* @param sortBy Attribute to sort from (optional).
* @param tenantDomain Tenant domain.
* @param rootOrgId Root organization ID.
* @return List of DiscoverableApplicationBasicInfo of applications matching the given criteria.
* @throws OrganizationManagementException The server exception is thrown in a failure when retrieving the
* discoverable applications.
*/
default List<ApplicationBasicInfo> getDiscoverableApplicationBasicInfo(int limit, int offset, String filter,
VivekVinushanth marked this conversation as resolved.
Show resolved Hide resolved
String sortOrder, String sortBy,
String tenantDomain, String rootOrgId)
throws OrganizationManagementException {

return null;
}

/*
* Returns the count of discoverable applications matching given filter.
asha15 marked this conversation as resolved.
Show resolved Hide resolved
* @param filter Filter to search for applications (optional).
* @param tenantDomain Tenant domain.
* @param rootOrgId Root organization ID.
* @return Count of discoverable applications matching given filter.
* @throws OrganizationManagementException The server exception is thrown in a failure when retrieving the
* discoverable applications count.
*/
default int getCountOfDiscoverableApplications(String filter, String tenantDomain, String rootOrgId)
throws OrganizationManagementException {

return 0;
}
}
Loading
Loading