Skip to content

Commit

Permalink
Add a method to get primary organization of given organization
Browse files Browse the repository at this point in the history
  • Loading branch information
dewniMW committed Sep 25, 2023
1 parent 40d5351 commit 22b8f35
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,17 @@ int getRelativeDepthBetweenOrganizationsInSameBranch(String firstOrgId, String s
/**
* Check if the provided organization ID is a primary organization.
*
* @param organizationId The organization ID.
* @param organizationId The organization ID.
* @return True if the organization is the primary organization; otherwise, false.
*/
boolean isPrimaryOrganization(String organizationId) throws OrganizationManagementServerException;

/**
* Fetch the primary organization of the given organization.
*
* @param organizationId The ID of the organization whose primary organization is to be fetched.
* @return The ID of the primary organization.
* @throws OrganizationManagementServerException The server exception thrown when fetching the primary organization.
*/
String getPrimaryOrganizationId(String organizationId) throws OrganizationManagementServerException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,20 @@ public boolean isPrimaryOrganization(String organizationId) throws OrganizationM
return Utils.getSubOrgStartLevel() == getOrganizationDepthInHierarchy(organizationId);
}

@Override
public String getPrimaryOrganizationId(String organizationId) throws OrganizationManagementServerException {

List<String> ancestorOrgIds = getAncestorOrganizationIds(organizationId);
// Primary organization is the parent level organization of the sub organization start level.
int primaryOrgDepth = Utils.getSubOrgStartLevel() - 1;
if (ancestorOrgIds != null && ancestorOrgIds.size() > primaryOrgDepth) {
// Ancestor organization list is in reverse order. Hence, the primary organization index has to be derived.
int primaryOrgIndex = ancestorOrgIds.size() - primaryOrgDepth - 1;
return ancestorOrgIds.get(primaryOrgIndex);
}
return null;
}

private void updateTenantStatus(String status, String organizationId) throws OrganizationManagementServerException {

if (StringUtils.equals(ACTIVE.toString(), status)) {
Expand Down

0 comments on commit 22b8f35

Please sign in to comment.