Search in sources :

Example 1 with SubscriptionPolicyListDTO

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();
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.api.model.policy.Policy) SubscriptionPolicyListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyListDTO) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) SubscriptionPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyDTO)

Example 2 with SubscriptionPolicyListDTO

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;
}
Also used : SubscriptionPolicyListDTO(org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyListDTO) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy) SubscriptionPolicyDTO(org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO)

Aggregations

ArrayList (java.util.ArrayList)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)1 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)1 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy)1 SubscriptionPolicyDTO (org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO)1 SubscriptionPolicyListDTO (org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyListDTO)1 SubscriptionPolicyDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyDTO)1 SubscriptionPolicyListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyListDTO)1