use of org.wso2.carbon.apimgt.rest.api.admin.v1.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.v1.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.v1.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();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.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 UnsupportedThrottleLimitTypeException
* @throws ParseException
*/
public static SubscriptionThrottlePolicyListDTO fromSubscriptionPolicyArrayToListDTO(SubscriptionPolicy[] subscriptionPolicies) throws UnsupportedThrottleLimitTypeException, ParseException {
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.v1.dto.SubscriptionThrottlePolicyListDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesSubscriptionGet.
/**
* Retrieves all Subscription level policies
*
* @param accept Accept header value
* @return All matched Subscription Throttle policies to the given request
*/
@Override
public Response throttlingPoliciesSubscriptionGet(String accept, MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
Policy[] subscriptionPolicies = apiAdmin.getPolicies(tenantId, PolicyConstants.POLICY_LEVEL_SUB);
List<SubscriptionPolicy> policies = new ArrayList<>();
for (Policy policy : subscriptionPolicies) {
policies.add((SubscriptionPolicy) policy);
}
SubscriptionThrottlePolicyListDTO listDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(policies.toArray(new SubscriptionPolicy[policies.size()]));
return Response.ok().entity(listDTO).build();
} catch (APIManagementException | ParseException e) {
String errorMessage = "Error while retrieving Subscription level policies";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations