use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAPIPolicyArrayToListDTO.
/**
* Converts an array of Advanced Policy objects into a List DTO
*
* @param policies Array of Advanced Policies
* @return A List DTO of converted Advanced Policies
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static AdvancedThrottlePolicyListDTO fromAPIPolicyArrayToListDTO(List<APIPolicy> policies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyListDTO listDTO = new AdvancedThrottlePolicyListDTO();
List<AdvancedThrottlePolicyDTO> advancedPolicyDTOs = new ArrayList<>();
if (policies != null) {
for (APIPolicy policy : policies) {
advancedPolicyDTOs.add(fromAdvancedPolicyToDTO(policy));
}
}
listDTO.setList(advancedPolicyDTOs);
listDTO.setCount(advancedPolicyDTOs.size());
return listDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtilTestCase method fromAPIPolicyArrayToListDTOTest.
@Test(description = "Convert Policy list to Policy List DTO object")
public void fromAPIPolicyArrayToListDTOTest() throws Exception {
APIPolicy policy1 = SampleTestObjectCreator.createAPIPolicyWithRequestLimit("Gold1");
APIPolicy policy2 = SampleTestObjectCreator.createAPIPolicyWithRequestLimit("Gold2");
List<APIPolicy> policyList = new ArrayList<>();
policyList.add(policy1);
policyList.add(policy2);
AdvancedThrottlePolicyListDTO listDTO = AdvancedThrottlePolicyMappingUtil.fromAPIPolicyArrayToListDTO(policyList);
Assert.assertEquals((Integer) policyList.size(), listDTO.getCount());
Assert.assertEquals(policy1.getDisplayName(), listDTO.getList().get(0).getDisplayName());
Assert.assertEquals(policy1.getDescription(), listDTO.getList().get(0).getDescription());
Assert.assertEquals(policy1.getDefaultQuotaPolicy().getType(), "requestCount");
Assert.assertEquals(policy1.getDefaultQuotaPolicy().getLimit().getTimeUnit(), listDTO.getList().get(0).getDefaultLimit().getTimeUnit());
Assert.assertEquals((Integer) policy1.getDefaultQuotaPolicy().getLimit().getUnitTime(), listDTO.getList().get(0).getDefaultLimit().getUnitTime());
Assert.assertEquals((Integer) ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount(), listDTO.getList().get(0).getDefaultLimit().getRequestCountLimit().getRequestCount());
Assert.assertEquals(policy2.getDisplayName(), listDTO.getList().get(1).getDisplayName());
Assert.assertEquals(policy2.getDescription(), listDTO.getList().get(1).getDescription());
Assert.assertEquals(policy2.getDefaultQuotaPolicy().getType(), "requestCount");
Assert.assertEquals(policy2.getDefaultQuotaPolicy().getLimit().getTimeUnit(), listDTO.getList().get(1).getDefaultLimit().getTimeUnit());
Assert.assertEquals((Integer) policy2.getDefaultQuotaPolicy().getLimit().getUnitTime(), listDTO.getList().get(1).getDefaultLimit().getUnitTime());
Assert.assertEquals((Integer) ((RequestCountLimit) policy2.getDefaultQuotaPolicy().getLimit()).getRequestCount(), listDTO.getList().get(1).getDefaultLimit().getRequestCountLimit().getRequestCount());
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingAdvancedGet.
/**
* Get 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 policiesThrottlingAdvancedGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Advance Throttle Policy GET request");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<APIPolicy> policies = apiMgtAdminService.getApiPolicies();
AdvancedThrottlePolicyListDTO advancedThrottlePolicyListDTO = AdvancedThrottlePolicyMappingUtil.fromAPIPolicyArrayToListDTO(policies);
return Response.ok().entity(advancedThrottlePolicyListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving Advance 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();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesAdvancedGet.
/**
* Retrieves all Advanced level policies
*
* @param accept Accept header value
* @return All matched Advanced Throttle policies to the given request
*/
@Override
public Response throttlingPoliciesAdvancedGet(String accept, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
Policy[] apiPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_API);
List<APIPolicy> policies = new ArrayList<>();
for (Policy policy : apiPolicies) {
policies.add((APIPolicy) policy);
}
AdvancedThrottlePolicyListDTO listDTO = AdvancedThrottlePolicyMappingUtil.fromAPIPolicyArrayToListDTO(policies.toArray(new APIPolicy[policies.size()]));
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Advanced level policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAPIPolicyArrayToListDTO.
/**
* Converts an array of Advanced Policy objects into a List DTO
*
* @param apiPolicies Array of Advanced Policies
* @return A List DTO of converted Advanced Policies
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static AdvancedThrottlePolicyListDTO fromAPIPolicyArrayToListDTO(APIPolicy[] apiPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyListDTO listDTO = new AdvancedThrottlePolicyListDTO();
List<AdvancedThrottlePolicyInfoDTO> advancedPolicyDTOs = new ArrayList<>();
if (apiPolicies != null) {
for (APIPolicy apiPolicy : apiPolicies) {
advancedPolicyDTOs.add(fromAdvancedPolicyToInfoDTO(apiPolicy));
}
}
listDTO.setList(advancedPolicyDTOs);
listDTO.setCount(advancedPolicyDTOs.size());
return listDTO;
}
Aggregations