use of org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionPolicyArrayToListDTO.
/**
* Converts an array of Subscription Policy objects into a List DTO
*
* @param subscriptionPolicies Array of Subscription Policies
* @return A List DTO of converted Subscription Policies
* @throws SubscriptionThrottlePolicyException - If error occurs
*/
public static SubscriptionThrottlePolicyListDTO fromSubscriptionPolicyArrayToListDTO(List<SubscriptionPolicy> subscriptionPolicies) throws SubscriptionThrottlePolicyException {
SubscriptionThrottlePolicyListDTO listDTO = new SubscriptionThrottlePolicyListDTO();
List<SubscriptionThrottlePolicyDTO> subscriptionPolicyDTOList = new ArrayList<>();
if (subscriptionPolicies != null) {
for (SubscriptionPolicy policy : subscriptionPolicies) {
SubscriptionThrottlePolicyDTO dto = fromSubscriptionThrottlePolicyToDTO(policy);
subscriptionPolicyDTOList.add(dto);
}
}
listDTO.setCount(subscriptionPolicyDTOList.size());
listDTO.setList(subscriptionPolicyDTOList);
return listDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtilTest method fromSubscriptionPolicyArrayToListDTOTest.
@Test(description = "Convert Subscription Throttle Policy List to List DTO")
public void fromSubscriptionPolicyArrayToListDTOTest() throws Exception {
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
SubscriptionPolicy policy1 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold1");
SubscriptionPolicy policy2 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold2");
subscriptionPolicies.add(policy1);
subscriptionPolicies.add(policy2);
SubscriptionThrottlePolicyListDTO listDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(subscriptionPolicies);
assertEquals(listDTO.getCount(), (Integer) subscriptionPolicies.size());
assertEquals(listDTO.getList().get(0).getPolicyName(), policy1.getPolicyName());
assertEquals(listDTO.getList().get(0).getDescription(), policy1.getDescription());
assertEquals(listDTO.getList().get(0).getDefaultLimit().getUnitTime(), (Integer) policy1.getDefaultQuotaPolicy().getLimit().getUnitTime());
assertEquals(listDTO.getList().get(0).getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount());
assertEquals(listDTO.getList().get(1).getPolicyName(), policy2.getPolicyName());
assertEquals(listDTO.getList().get(1).getDescription(), policy2.getDescription());
assertEquals(listDTO.getList().get(1).getDefaultLimit().getUnitTime(), (Integer) policy2.getDefaultQuotaPolicy().getLimit().getUnitTime());
assertEquals(listDTO.getList().get(1).getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) policy2.getDefaultQuotaPolicy().getLimit()).getRequestCount());
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingSubscriptionGet.
/**
* Get subscription level policies
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingSubscriptionGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Application Throttle Policy GET request");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<SubscriptionPolicy> policies = apiMgtAdminService.getSubscriptionPolicies();
SubscriptionThrottlePolicyListDTO subscriptionThrottlePolicyListDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(policies);
return Response.ok().entity(subscriptionThrottlePolicyListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving Application Policies";
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations