use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyListDTO in project carbon-apimgt by wso2.
the class ThrottlingPoliciesApiServiceImpl method getSubscriptionThrottlingPolicies.
/**
* Retrieves all the Tiers
*
* @param limit max number of objects returns
* @param offset starting index
* @param ifNoneMatch If-None-Match header value
* @return Response object containing resulted tiers
*/
@Override
public Response getSubscriptionThrottlingPolicies(Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String userName = RestApiCommonUtil.getLoggedInUsername();
Policy[] policies = apiProvider.getPolicies(userName, PolicyConstants.POLICY_LEVEL_SUB);
List<SubscriptionPolicy> streamingPolicies = new ArrayList<>();
for (Policy policy : policies) {
if (EVENT_COUNT_TYPE.equals(policy.getDefaultQuotaPolicy().getType())) {
streamingPolicies.add((SubscriptionPolicy) policy);
}
}
SubscriptionPolicyListDTO subscriptionPolicyListDTO = new SubscriptionPolicyListDTO();
List<SubscriptionPolicyDTO> subscriptionPolicyDTOs = subscriptionPolicyListDTO.getList();
if (subscriptionPolicyDTOs == null) {
subscriptionPolicyDTOs = new ArrayList<>();
subscriptionPolicyListDTO.setList(subscriptionPolicyDTOs);
}
int size = streamingPolicies.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = Math.min(offset + limit - 1, size - 1);
for (int i = start; i <= end; i++) {
subscriptionPolicyDTOs.add(ThrottlingPolicyMappingUtil.fromSubscriptionToDTO(streamingPolicies.get(i), i));
}
subscriptionPolicyListDTO.setCount(subscriptionPolicyDTOs.size());
return Response.ok().entity(subscriptionPolicyListDTO).build();
}
use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyListDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromSubscriptionPolicyToSubscriptionPolicyListDTO.
public static SubscriptionPolicyListDTO fromSubscriptionPolicyToSubscriptionPolicyListDTO(List<SubscriptionPolicy> model) {
SubscriptionPolicyListDTO subscriptionPolicyListDTO = new SubscriptionPolicyListDTO();
if (model != null) {
for (SubscriptionPolicy subscriptionPolicyModel : model) {
SubscriptionPolicyDTO subscriptionPolicyDTO = new SubscriptionPolicyDTO();
subscriptionPolicyDTO.setId(subscriptionPolicyModel.getId());
subscriptionPolicyDTO.setName(subscriptionPolicyModel.getName());
subscriptionPolicyDTO.setQuotaType(subscriptionPolicyModel.getQuotaType());
subscriptionPolicyDTO.setGraphQLMaxDepth(subscriptionPolicyModel.getGraphQLMaxDepth());
subscriptionPolicyDTO.setGraphQLMaxComplexity(subscriptionPolicyModel.getGraphQLMaxComplexity());
subscriptionPolicyDTO.setTenantId(subscriptionPolicyModel.getTenantId());
subscriptionPolicyDTO.setTenantDomain(subscriptionPolicyModel.getTenantDomain());
subscriptionPolicyDTO.setRateLimitCount(subscriptionPolicyModel.getRateLimitCount());
subscriptionPolicyDTO.setStopOnQuotaReach(subscriptionPolicyModel.isStopOnQuotaReach());
subscriptionPolicyDTO.setRateLimitTimeUnit(subscriptionPolicyModel.getRateLimitTimeUnit());
subscriptionPolicyDTO.setDefaultLimit(getThrottleLimitDTO(subscriptionPolicyModel));
subscriptionPolicyListDTO.getList().add(subscriptionPolicyDTO);
}
subscriptionPolicyListDTO.setCount(model.size());
} else {
subscriptionPolicyListDTO.setCount(0);
}
return subscriptionPolicyListDTO;
}
Aggregations