Search in sources :

Example 1 with TenantsListResponse

use of org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse in project identity-api-server by wso2.

the class ServerTenantManagementService method listTenants.

/**
 * Get tenant list.
 *
 * @param limit     Items per page.
 * @param offset    Offset.
 * @param filter    Filter string. E.g. filter="domainName" sw "wso2.com"
 * @param sortBy    Attribute to sort the tenants by. E.g. domainName
 * @param sortOrder Order in which tenants should be sorted. Can be either ASC or DESC.
 * @return TenantsListResponse.
 */
public TenantsListResponse listTenants(Integer limit, Integer offset, String sortOrder, String sortBy, String filter) {
    handleNotImplementedCapabilities(filter);
    TenantMgtService tenantMgtService = TenantManagementServiceHolder.getTenantMgtService();
    try {
        TenantSearchResult tenantSearchResult = tenantMgtService.listTenants(limit, offset, sortOrder, sortBy, filter);
        return createTenantListResponse(tenantSearchResult);
    } catch (TenantMgtException e) {
        throw handleTenantManagementException(e, TenantManagementConstants.ErrorMessage.ERROR_CODE_ERROR_LISTING_TENANTS, null);
    }
}
Also used : TenantSearchResult(org.wso2.carbon.user.core.tenant.TenantSearchResult) TenantMgtException(org.wso2.carbon.stratos.common.exception.TenantMgtException) TenantMgtService(org.wso2.carbon.tenant.mgt.services.TenantMgtService)

Example 2 with TenantsListResponse

use of org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse in project identity-api-server by wso2.

the class ServerTenantManagementService method createTenantListResponse.

private TenantsListResponse createTenantListResponse(TenantSearchResult tenantSearchResult) {
    List<Tenant> tenants = tenantSearchResult.getTenantList();
    TenantsListResponse listResponse = new TenantsListResponse();
    if (CollectionUtils.isNotEmpty(tenants)) {
        List<TenantListItem> tenantListItems = getTenantListItems(tenants);
        listResponse.setTenants(tenantListItems);
        listResponse.setCount(tenantListItems.size());
    } else {
        listResponse.setCount(0);
    }
    listResponse.setTotalResults(tenantSearchResult.getTotalTenantCount());
    listResponse.setStartIndex(tenantSearchResult.getOffSet() + 1);
    listResponse.setLinks(createLinks(V1_API_PATH_COMPONENT + TENANT_MANAGEMENT_PATH_COMPONENT, tenantSearchResult.getLimit(), tenantSearchResult.getOffSet(), tenantSearchResult.getTotalTenantCount(), tenantSearchResult.getFilter()));
    return listResponse;
}
Also used : Tenant(org.wso2.carbon.user.core.tenant.Tenant) TenantListItem(org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantListItem) TenantsListResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)

Aggregations

TenantListItem (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantListItem)1 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)1 TenantMgtException (org.wso2.carbon.stratos.common.exception.TenantMgtException)1 TenantMgtService (org.wso2.carbon.tenant.mgt.services.TenantMgtService)1 Tenant (org.wso2.carbon.user.core.tenant.Tenant)1 TenantSearchResult (org.wso2.carbon.user.core.tenant.TenantSearchResult)1