Skip to content

Commit

Permalink
Merge pull request #253 from PasinduYeshan/arc-pr-213
Browse files Browse the repository at this point in the history
Address review comments in PR 213
  • Loading branch information
sadilchamishka authored Jul 25, 2024
2 parents 762b2f7 + d55d7c5 commit 3225a23
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.wso2.carbon.identity.configuration.mgt.core.model.Resource;
import org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile;
import org.wso2.carbon.identity.configuration.mgt.core.model.Resources;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementConstants.ErrorMessage;
import org.wso2.carbon.identity.notification.sender.tenant.config.clustering.EventPublisherClusterInvalidationMessage;
import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO;
Expand All @@ -49,7 +48,6 @@
import org.wso2.carbon.identity.notification.sender.tenant.config.handlers.ChannelConfigurationHandler;
import org.wso2.carbon.identity.notification.sender.tenant.config.internal.NotificationSenderTenantConfigDataHolder;
import org.wso2.carbon.identity.notification.sender.tenant.config.utils.NotificationSenderUtils;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementException;
Expand Down Expand Up @@ -234,7 +232,8 @@ public SMSSenderDTO getSMSSender(String senderName) throws NotificationSenderMan
return buildSmsSenderFromResource(resource);
}
if (OrganizationManagementUtil.isOrganization(tenantDomain)) {
resourceOptional = getPublisherResource(getPrimaryTenantId(), senderName);
resourceOptional =
getPublisherResource(NotificationSenderUtils.getPrimaryTenantId(tenantDomain), senderName);
if (resourceOptional.isPresent()) {
Resource resource = resourceOptional.get();
return buildSmsSenderFromResource(resource);
Expand Down Expand Up @@ -306,7 +305,8 @@ private Resources getPublisherResources(boolean inheritTenantSettings)
publisherResources.getResources().isEmpty()) {
publisherResources = NotificationSenderTenantConfigDataHolder.getInstance()
.getConfigurationManager()
.getResourcesByType(getPrimaryTenantId(), PUBLISHER_RESOURCE_TYPE);
.getResourcesByType(NotificationSenderUtils.getPrimaryTenantId(tenantDomain),
PUBLISHER_RESOURCE_TYPE);
}
return publisherResources;
}
Expand Down Expand Up @@ -733,21 +733,4 @@ private boolean canSenderDelete(String senderName) throws NotificationSenderMana
}
return true;
}

/**
* Get the primary tenant id of the given tenant domain.
*
* @return Primary tenant id.
* @throws OrganizationManagementException If an error occurred while getting the primary tenant id.
*/
private int getPrimaryTenantId() throws OrganizationManagementException {

String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
OrganizationManager organizationManager = NotificationSenderTenantConfigDataHolder.getInstance()
.getOrganizationManager();
String orgId = organizationManager.resolveOrganizationId(tenantDomain);
String primaryOrgId = organizationManager.getPrimaryOrganizationId(orgId);
String primaryTenantDomain = organizationManager.resolveTenantDomain(primaryOrgId);
return IdentityTenantUtil.getTenantId(primaryTenantDomain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import org.w3c.dom.Element;
import org.wso2.carbon.identity.configuration.mgt.core.model.Attribute;
import org.wso2.carbon.identity.configuration.mgt.core.model.Resource;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.notification.sender.tenant.config.dto.EmailSenderDTO;
import org.wso2.carbon.identity.notification.sender.tenant.config.dto.SMSSenderDTO;
import org.wso2.carbon.identity.notification.sender.tenant.config.internal.NotificationSenderTenantConfigDataHolder;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -417,4 +420,20 @@ public static SMSSenderDTO buildSmsSenderFromResource(Resource resource) {
});
return smsSender;
}

/**
* Get the primary tenant id of the given tenant domain.
*
* @return Primary tenant id.
* @throws OrganizationManagementException If an error occurred while getting the primary tenant id.
*/
public static int getPrimaryTenantId(String tenantDomain) throws OrganizationManagementException {

OrganizationManager organizationManager = NotificationSenderTenantConfigDataHolder.getInstance()
.getOrganizationManager();
String orgId = organizationManager.resolveOrganizationId(tenantDomain);
String primaryOrgId = organizationManager.getPrimaryOrganizationId(orgId);
String primaryTenantDomain = organizationManager.resolveTenantDomain(primaryOrgId);
return IdentityTenantUtil.getTenantId(primaryTenantDomain);
}
}

0 comments on commit 3225a23

Please sign in to comment.