Search in sources :

Example 6 with TierNameComparator

use of org.wso2.carbon.apimgt.impl.utils.TierNameComparator in project carbon-apimgt by wso2.

the class TierNameComparatorTest method testCompareWhenDisplayNameNotSetNotEquals.

@Test
public void testCompareWhenDisplayNameNotSetNotEquals() {
    TierNameComparator tierNameComparator = new TierNameComparator();
    Tier tier1 = new Tier("GOLD");
    Tier tier2 = new Tier("SILVER");
    int result = tierNameComparator.compare(tier1, tier2);
    Assert.assertNotEquals(0, result);
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) TierNameComparator(org.wso2.carbon.apimgt.impl.utils.TierNameComparator) Test(org.junit.Test)

Example 7 with TierNameComparator

use of org.wso2.carbon.apimgt.impl.utils.TierNameComparator in project carbon-apimgt by wso2.

the class TierNameComparatorTest method testCompareEquals.

@Test
public void testCompareEquals() {
    TierNameComparator tierNameComparator = new TierNameComparator();
    Tier tier1 = new Tier("GOLD");
    tier1.setDisplayName("GOLD");
    Tier tier2 = new Tier("GOLD");
    tier2.setDisplayName("GOLD");
    int result = tierNameComparator.compare(tier1, tier2);
    Assert.assertEquals(0, result);
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) TierNameComparator(org.wso2.carbon.apimgt.impl.utils.TierNameComparator) Test(org.junit.Test)

Example 8 with TierNameComparator

use of org.wso2.carbon.apimgt.impl.utils.TierNameComparator in project carbon-apimgt by wso2.

the class AbstractAPIManager method getAllTiers.

public Set<Tier> getAllTiers(String tenantDomain) throws APIManagementException {
    Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator());
    Map<String, Tier> tierMap;
    boolean isTenantFlowStarted = false;
    try {
        if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            startTenantFlow(tenantDomain);
            isTenantFlowStarted = true;
        }
        int requestedTenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        if (requestedTenantId == MultitenantConstants.SUPER_TENANT_ID || requestedTenantId == MultitenantConstants.INVALID_TENANT_ID) {
            tierMap = APIUtil.getAllTiers();
        } else {
            tierMap = APIUtil.getAllTiers(requestedTenantId);
        }
    } finally {
        if (isTenantFlowStarted) {
            endTenantFlow();
        }
    }
    tiers.addAll(tierMap.values());
    return tiers;
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) TreeSet(java.util.TreeSet) TierNameComparator(org.wso2.carbon.apimgt.impl.utils.TierNameComparator)

Example 9 with TierNameComparator

use of org.wso2.carbon.apimgt.impl.utils.TierNameComparator in project carbon-apimgt by wso2.

the class AbstractAPIManager method getTiers.

/**
 * Returns a list of pre-defined # {@link org.wso2.carbon.apimgt.api.model.Tier} in the system.
 *
 * @param tierType type of the tiers (api,resource ot application)
 * @param username current logged user
 * @return Set<Tier> return list of tier names
 * @throws APIManagementException APIManagementException if failed to get the predefined tiers
 */
public Set<Tier> getTiers(int tierType, String username) throws APIManagementException {
    Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator());
    String tenantDomain = getTenantDomain(username);
    Map<String, Tier> tierMap;
    int tenantIdFromUsername = APIUtil.getTenantId(username);
    if (tierType == APIConstants.TIER_API_TYPE) {
        tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_SUB, tenantIdFromUsername);
    } else if (tierType == APIConstants.TIER_RESOURCE_TYPE) {
        tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_API, tenantIdFromUsername);
    } else if (tierType == APIConstants.TIER_APPLICATION_TYPE) {
        tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_APP, tenantIdFromUsername);
    } else {
        throw new APIManagementException("No such a tier type : " + tierType);
    }
    tiers.addAll(tierMap.values());
    return tiers;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Tier(org.wso2.carbon.apimgt.api.model.Tier) TreeSet(java.util.TreeSet) TierNameComparator(org.wso2.carbon.apimgt.impl.utils.TierNameComparator)

Aggregations

Tier (org.wso2.carbon.apimgt.api.model.Tier)9 TierNameComparator (org.wso2.carbon.apimgt.impl.utils.TierNameComparator)9 TreeSet (java.util.TreeSet)5 Test (org.junit.Test)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1