Skip to content

Commit

Permalink
Remove the service URL builds at organization core level
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Nov 9, 2023
1 parent 3dc9a6e commit fb4460d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SUPER;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SUPER_ORG_ID;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SW;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.buildURIForBody;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.getAuthenticatedUsername;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.getOrganizationId;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.getTenantDomain;
Expand Down Expand Up @@ -229,18 +228,13 @@ public Organization getOrganization(String organizationId, boolean showChildren,
throw handleClientException(ERROR_CODE_INVALID_ORGANIZATION, organizationId);
}

if (!SUPER.equals(organization.getName())) {
organization.getParent().setRef(buildURIForBody(organization.getParent().getId()));
}

if (showChildren) {
List<String> childOrganizationIds = organizationManagementDAO.getChildOrganizationIds(organizationId);
if (CollectionUtils.isNotEmpty(childOrganizationIds)) {
List<ChildOrganizationDO> childOrganizations = new ArrayList<>();
for (String childOrganizationId : childOrganizationIds) {
ChildOrganizationDO childOrganization = new ChildOrganizationDO();
childOrganization.setId(childOrganizationId);
childOrganization.setRef(buildURIForBody(childOrganizationId));
childOrganizations.add(childOrganization);
}
organization.setChildOrganizations(childOrganizations);
Expand Down Expand Up @@ -377,12 +371,7 @@ public Organization patchOrganization(String organizationId, List<PatchOperation

getListener().postPatchOrganization(organizationId, patchOperations);

Organization organization = organizationManagementDAO.getOrganization(organizationId);
if (!SUPER.equals(organization.getName())) {
organization.getParent().setRef(buildURIForBody(organization.getParent().getId()));
}

return organization;
return organizationManagementDAO.getOrganization(organizationId);
}

@Override
Expand Down Expand Up @@ -410,9 +399,6 @@ public Organization updateOrganization(String organizationId, String currentOrga
organizationManagementDAO.updateOrganization(organizationId, organization);

Organization updatedOrganization = organizationManagementDAO.getOrganization(organizationId);
if (!SUPER.equals(updatedOrganization.getName())) {
updatedOrganization.getParent().setRef(buildURIForBody(updatedOrganization.getParent().getId()));
}

if (StringUtils.equals(TENANT.toString(), organization.getType())) {
updateTenantStatus(organization.getStatus(), organizationId);
Expand Down Expand Up @@ -726,7 +712,6 @@ private void validateParentOrganization(Organization organization) throws Organi

validateAddOrganizationParentStatus(parentId);
parentOrganization.setId(parentId);
parentOrganization.setRef(buildURIForBody(parentId));
}

private void validateUpdateOrganizationRequest(String currentOrganizationName, Organization organization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_CREATING_NEW_SYSTEM_ROLE;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.IS_CARBON_ROLE_VALIDATION_ENABLED_FOR_LEVEL_ONE_ORGS;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.IS_ORG_QUALIFIED_URLS_SUPPORTED_FOR_LEVEL_ONE_ORGS;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ORGANIZATION_CONTEXT_PATH_COMPONENT;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ORGANIZATION_PATH;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.PATH_SEPARATOR;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SERVER_API_PATH_COMPONENT;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.SUB_ORG_START_LEVEL;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.V1_API_PATH_COMPONENT;
import static org.wso2.carbon.identity.organization.management.service.constant.SQLConstants.MICROSOFT;
import static org.wso2.carbon.identity.organization.management.service.constant.SQLConstants.MYSQL;
import static org.wso2.carbon.identity.organization.management.service.constant.SQLConstants.ORACLE;
Expand Down Expand Up @@ -254,36 +250,6 @@ public static String getUserId() {
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserId();
}

/**
* Build URI prepending the server API context with the proxy context path to the endpoint.
*
* @param organizationId The organization ID.
* @return Relative URI.
*/
public static String buildURIForBody(String organizationId) {

String context = getContext(V1_API_PATH_COMPONENT + PATH_SEPARATOR + ORGANIZATION_PATH
+ PATH_SEPARATOR + organizationId);

return context;
}

/**
* Builds the API context.
*
* @param endpoint Relative endpoint path.
* @return Context of the API.
*/
public static String getContext(String endpoint) {

String organizationId = getOrganizationId();
if (StringUtils.isNotBlank(organizationId)) {
return String.format(ORGANIZATION_CONTEXT_PATH_COMPONENT, organizationId) + SERVER_API_PATH_COMPONENT +
endpoint;
}
return SERVER_API_PATH_COMPONENT + endpoint;
}

/**
* Generate unique identifier for the organization.
*
Expand Down

0 comments on commit fb4460d

Please sign in to comment.