use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesGet.
@Override
public Response policiesGet(String accept, Request request) throws NotFoundException {
PolicyListDTO policyListDTO = new PolicyListDTO();
try {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
List<PolicyDTO> policyDTOList = MappingUtil.convertToPolicyDtoList(adminService.getAllPolicies());
policyListDTO.setList(policyDTOList);
policyListDTO.setCount(policyDTOList.size());
return Response.ok().entity(policyListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Policies";
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.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class MappingUtil method convertToPolicyDtoList.
/**
* Convert policy validation data list to policy dto list
*
* @param allPolicies all policies
* @return PolicyDTO list
*/
public static List<PolicyDTO> convertToPolicyDtoList(Set<PolicyValidationData> allPolicies) {
List<PolicyDTO> policyDTOList = new ArrayList<>();
allPolicies.forEach(v -> {
PolicyDTO policyDTO = new PolicyDTO();
policyDTO.setId(v.getId());
policyDTO.setName(v.getName());
policyDTO.setStopOnQuotaReach(v.isStopOnQuotaReach());
policyDTOList.add(policyDTO);
});
return policyDTOList;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyToDTO.
/**
* Converts a single Advanced Policy model into REST API DTO
*
* @param policy Advanced Policy model object
* @return Converted Advanced policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static AdvancedThrottlePolicyDTO fromAdvancedPolicyToDTO(APIPolicy policy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyDTO policyDTO = new AdvancedThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(policy, policyDTO);
List<ConditionalGroupDTO> groupDTOs = CommonThrottleMappingUtil.fromPipelineListToConditionalGroupDTOList(policy.getPipelines());
policyDTO.setConditionalGroups(groupDTOs);
if (policy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(policy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtilTestCase method fromAdvancedPolicyToInfoDTOTest.
@Test(description = "Convert Policy DTO to Policy object")
public void fromAdvancedPolicyToInfoDTOTest() throws Exception {
APIPolicy apiPolicy = new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY);
String uuid = UUID.randomUUID().toString();
String displayName = "SampleAPIPolicy";
String description = "Sample Description";
apiPolicy.setUuid(uuid);
apiPolicy.setDisplayName(displayName);
apiPolicy.setDescription(description);
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("requestCount");
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
quotaPolicy.setLimit(requestCountLimit);
apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
AdvancedThrottlePolicyDTO policyDTO = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToInfoDTO(apiPolicy);
Assert.assertNotNull(policyDTO);
Assert.assertEquals(policyDTO.getDisplayName(), displayName);
Assert.assertEquals(policyDTO.getDescription(), description);
Assert.assertEquals(policyDTO.getDefaultLimit().getType(), "RequestCountLimit");
Assert.assertEquals(policyDTO.getDefaultLimit().getTimeUnit(), apiPolicy.getDefaultQuotaPolicy().getLimit().getTimeUnit());
Assert.assertEquals(policyDTO.getDefaultLimit().getUnitTime(), (Integer) apiPolicy.getDefaultQuotaPolicy().getLimit().getUnitTime());
Assert.assertEquals(policyDTO.getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) apiPolicy.getDefaultQuotaPolicy().getLimit()).getRequestCount());
}
Aggregations