use of org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyListDTO 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 - If error occurs
*/
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(List<ApplicationPolicy> appPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
if (appPolicies != null) {
for (Policy policy : appPolicies) {
ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
appPolicyDTOList.add(dto);
}
}
listDTO.setCount(appPolicyDTOList.size());
listDTO.setList(appPolicyDTOList);
return listDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtilTest method testFromApplicationPolicyArrayToListDTO.
@Test(description = "Convert from Policy Array to DTO")
public void testFromApplicationPolicyArrayToListDTO() throws Exception {
List<ApplicationPolicy> appPolicies = new ArrayList<>();
ApplicationPolicy policy1 = SampleTestObjectCreator.createApplicationPolicyWithRequestLimit("Gold");
ApplicationPolicy policy2 = SampleTestObjectCreator.createApplicationPolicyWithRequestLimit("Silver");
appPolicies.add(policy1);
appPolicies.add(policy2);
ApplicationThrottlePolicyListDTO listDTO = ApplicationThrottlePolicyMappingUtil.fromApplicationPolicyArrayToListDTO(appPolicies);
Assert.assertEquals(listDTO.getCount(), (Integer) appPolicies.size());
Assert.assertNotNull(listDTO.getList().get(0).getPolicyName(), policy1.getPolicyName());
Assert.assertEquals(listDTO.getList().get(0).getId(), policy1.getUuid());
Assert.assertEquals(listDTO.getList().get(0).getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount());
Assert.assertEquals(listDTO.getList().get(0).getDisplayName(), policy1.getDisplayName());
Assert.assertNotNull(listDTO.getList().get(1).getPolicyName(), policy2.getPolicyName());
Assert.assertEquals(listDTO.getList().get(1).getId(), policy2.getUuid());
Assert.assertEquals(listDTO.getList().get(1).getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), ((RequestCountLimit) policy2.getDefaultQuotaPolicy().getLimit()).getRequestCount());
Assert.assertEquals(listDTO.getList().get(1).getDisplayName(), policy2.getDisplayName());
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingApplicationGet.
/**
* Returns all Application Policies deployed in the system
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object Response containing the Application Policy list {@link ApplicationThrottlePolicyListDTO}
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingApplicationGet(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<ApplicationPolicy> policies = apiMgtAdminService.getApplicationPolicies();
ApplicationThrottlePolicyListDTO applicationThrottlePolicyListDTO = ApplicationThrottlePolicyMappingUtil.fromApplicationPolicyArrayToListDTO(policies);
return Response.ok().entity(applicationThrottlePolicyListDTO).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