use of org.wso2.carbon.apimgt.api.model.subscription.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();
}
use of org.wso2.carbon.apimgt.api.model.subscription.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;
}
use of org.wso2.carbon.apimgt.api.model.subscription.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;
}
use of org.wso2.carbon.apimgt.api.model.subscription.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;
}
use of org.wso2.carbon.apimgt.api.model.subscription.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;
}
Aggregations