Search in sources :

Example 56 with ApplicationPolicy

use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationPoliciesApiServiceImpl method applicationPoliciesGet.

@Override
public Response applicationPoliciesGet(String xWSO2Tenant, String policyName, MessageContext messageContext) {
    SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    if (StringUtils.isNotEmpty(xWSO2Tenant)) {
        if (APIConstants.CHAR_ASTERIX.equals(xWSO2Tenant)) {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(subscriptionValidationDAO.getAllApplicationPolicies())).build();
        } else if (StringUtils.isNotEmpty(policyName)) {
            List<ApplicationPolicy> model = new ArrayList<>();
            ApplicationPolicy applicationPolicy = subscriptionValidationDAO.getApplicationPolicyByNameForTenant(policyName, xWSO2Tenant);
            if (applicationPolicy != null) {
                model.add(applicationPolicy);
            }
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(model)).build();
        } else {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(subscriptionValidationDAO.getAllApplicationPolicies(xWSO2Tenant))).build();
        }
    } else {
        if (StringUtils.isNotEmpty(policyName)) {
            return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
        }
    }
    return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(subscriptionValidationDAO.getAllApplicationPolicies())).build();
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.subscription.ApplicationPolicy) List(java.util.List) ArrayList(java.util.ArrayList) SubscriptionValidationDAO(org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)

Example 57 with ApplicationPolicy

use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyToDTO.

/**
 * Converts a single Application Policy model into REST API DTO
 *
 * @param appPolicy An Application Policy model object
 * @return Converted Application policy REST API DTO object
 * @throws UnsupportedThrottleLimitTypeException
 */
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(ApplicationPolicy appPolicy) throws UnsupportedThrottleLimitTypeException {
    ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
    if (appPolicy.getDefaultQuotaPolicy() != null) {
        policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
    }
    policyDTO.setType(APPLICATION_THROTTLING_POLICY_TYPE);
    return policyDTO;
}
Also used : ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO)

Example 58 with ApplicationPolicy

use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.

the class ApplicationThrottlePolicyMappingUtil method fromApplicationPolicyArrayToListDTO.

/**
 * Converts an array of Application Policy objects into a List DTO
 *
 * @param appPolicies Array of Application Policies
 * @return A List DTO of converted Application Policies
 * @throws UnsupportedThrottleLimitTypeException
 */
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(ApplicationPolicy[] appPolicies) throws UnsupportedThrottleLimitTypeException {
    ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
    List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
    if (appPolicies != null) {
        for (ApplicationPolicy policy : appPolicies) {
            ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
            appPolicyDTOList.add(dto);
        }
    }
    listDTO.setCount(appPolicyDTOList.size());
    listDTO.setList(appPolicyDTOList);
    return listDTO;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) ApplicationThrottlePolicyListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyListDTO) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO)

Example 59 with ApplicationPolicy

use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.

the class PolicyRetriever method getApplicationPolicy.

/**
 * Get a application policy given the name.
 *
 * @param policyName   policy name
 * @param tenantDomain tenant domain
 * @return application policy
 * @throws ThrottlePolicyDeployerException if failure occurs
 */
public ApplicationPolicy getApplicationPolicy(String policyName, String tenantDomain) throws ThrottlePolicyDeployerException {
    String path = APIConstants.SubscriptionValidationResources.APPLICATION_POLICIES + "?policyName=" + policyName;
    ApplicationPolicyList applicationPolicyList = getPolicies(path, tenantDomain, ApplicationPolicyList.class);
    if (applicationPolicyList.getList() != null && !applicationPolicyList.getList().isEmpty()) {
        return applicationPolicyList.getList().get(0);
    }
    return null;
}
Also used : ApplicationPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicyList)

Example 60 with ApplicationPolicy

use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.

the class TestUtil method getPolicyAppLevel.

/**
 * Generate a dummy Application Policy object
 *
 * @return an Application Policy
 */
public static ApplicationPolicy getPolicyAppLevel() {
    ApplicationPolicy applicationPolicy = new ApplicationPolicy();
    applicationPolicy.setId(1);
    applicationPolicy.setTenantId(-1234);
    applicationPolicy.setTenantDomain("carbon.super");
    applicationPolicy.setName("policy1");
    applicationPolicy.setQuotaType("requestCount");
    QuotaPolicy defaultLimit = new QuotaPolicy();
    defaultLimit.setQuotaType("requestCount");
    RequestCountLimit requestCountLimit = new RequestCountLimit();
    requestCountLimit.setRequestCount(1);
    requestCountLimit.setTimeUnit("min");
    requestCountLimit.setUnitTime(1);
    defaultLimit.setRequestCount(requestCountLimit);
    applicationPolicy.setDefaultLimit(defaultLimit);
    return applicationPolicy;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy)

Aggregations

ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)56 Test (org.testng.annotations.Test)30 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)29 ArrayList (java.util.ArrayList)24 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)18 Application (org.wso2.carbon.apimgt.core.models.Application)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)13 BeforeTest (org.testng.annotations.BeforeTest)13 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)13 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)13 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12