Search in sources :

Example 1 with SubscriptionPolicyDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO in project carbon-apimgt by wso2.

the class SubscriptionValidationDAO method populateSubscriptionPolicyList.

private List<SubscriptionPolicy> populateSubscriptionPolicyList(ResultSet resultSet) throws SQLException {
    List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
    if (resultSet != null) {
        while (resultSet.next()) {
            SubscriptionPolicy subscriptionPolicyDTO = new SubscriptionPolicy();
            subscriptionPolicyDTO.setId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_POLICY_ID));
            subscriptionPolicyDTO.setName(resultSet.getString(ThrottlePolicyConstants.COLUMN_POLICY_NAME));
            subscriptionPolicyDTO.setQuotaType(resultSet.getString(ThrottlePolicyConstants.COLUMN_QUOTA_POLICY_TYPE));
            subscriptionPolicyDTO.setTenantId(resultSet.getInt(ThrottlePolicyConstants.COLUMN_TENANT_ID));
            String tenantDomain = APIUtil.getTenantDomainFromTenantId(subscriptionPolicyDTO.getTenantId());
            subscriptionPolicyDTO.setTenantDomain(tenantDomain);
            subscriptionPolicyDTO.setRateLimitCount(resultSet.getInt(ThrottlePolicyConstants.COLUMN_RATE_LIMIT_COUNT));
            subscriptionPolicyDTO.setRateLimitTimeUnit(resultSet.getString(ThrottlePolicyConstants.COLUMN_RATE_LIMIT_TIME_UNIT));
            subscriptionPolicyDTO.setStopOnQuotaReach(resultSet.getBoolean(ThrottlePolicyConstants.COLUMN_STOP_ON_QUOTA_REACH));
            subscriptionPolicyDTO.setGraphQLMaxDepth(resultSet.getInt(ThrottlePolicyConstants.COLUMN_MAX_DEPTH));
            subscriptionPolicyDTO.setGraphQLMaxComplexity(resultSet.getInt(ThrottlePolicyConstants.COLUMN_MAX_COMPLEXITY));
            setCommonProperties(subscriptionPolicyDTO, resultSet);
            subscriptionPolicies.add(subscriptionPolicyDTO);
        }
    }
    return subscriptionPolicies;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy) ArrayList(java.util.ArrayList)

Example 2 with SubscriptionPolicyDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO 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 3 with SubscriptionPolicyDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO in project carbon-apimgt by wso2.

the class ThrottlingPolicyMappingUtil method fromSubscriptionToDTO.

public static SubscriptionPolicyDTO fromSubscriptionToDTO(SubscriptionPolicy subscriptionPolicy, int position) {
    SubscriptionPolicyDTO dto = new SubscriptionPolicyDTO();
    dto.setRateLimitCount(subscriptionPolicy.getRateLimitCount());
    dto.setRateLimitTimeUnit(subscriptionPolicy.getRateLimitTimeUnit());
    dto.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
    ThrottleLimitDTO limitDTO = new ThrottleLimitDTO();
    limitDTO.setType(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT);
    EventCountLimit eventCountLimit = (EventCountLimit) subscriptionPolicy.getDefaultQuotaPolicy().getLimit();
    EventCountLimitDTO eventCountLimitDTO = new EventCountLimitDTO();
    eventCountLimitDTO.setEventCount(eventCountLimit.getEventCount());
    eventCountLimitDTO.setTimeUnit(eventCountLimit.getTimeUnit());
    eventCountLimitDTO.setUnitTime(eventCountLimit.getUnitTime());
    limitDTO.setEventCount(eventCountLimitDTO);
    dto.setDefaultLimit(limitDTO);
    dto.setSubscriberCount(subscriptionPolicy.getSubscriberCount());
    dto.setDisplayName(subscriptionPolicy.getDisplayName());
    dto.setDescription(subscriptionPolicy.getDescription());
    dto.setIsDeployed(subscriptionPolicy.isDeployed());
    dto.setPolicyName(subscriptionPolicy.getPolicyName());
    dto.setBillingPlan(subscriptionPolicy.getBillingPlan());
    dto.setPolicyId(position);
    dto.setUuid(subscriptionPolicy.getUUID());
    dto.setIsDeployed(subscriptionPolicy.isDeployed());
    dto.setTenantDomain(subscriptionPolicy.getTenantDomain());
    dto.setTenantId(subscriptionPolicy.getTenantId());
    return dto;
}
Also used : EventCountLimit(org.wso2.carbon.apimgt.api.model.policy.EventCountLimit) EventCountLimitDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EventCountLimitDTO) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottleLimitDTO) SubscriptionPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyDTO)

Example 4 with SubscriptionPolicyDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO 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)

Example 5 with SubscriptionPolicyDTO

use of org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO in project carbon-apimgt by wso2.

the class APIUtil method getJwtTokenInfoDTO.

public static JwtTokenInfoDTO getJwtTokenInfoDTO(Application application, String userName, String tenantDomain) throws APIManagementException {
    int applicationId = application.getId();
    String appOwner = application.getOwner();
    APISubscriptionInfoDTO[] apis = ApiMgtDAO.getInstance().getSubscribedAPIsForAnApp(appOwner, applicationId);
    JwtTokenInfoDTO jwtTokenInfoDTO = new JwtTokenInfoDTO();
    jwtTokenInfoDTO.setSubscriber("sub");
    jwtTokenInfoDTO.setEndUserName(userName);
    jwtTokenInfoDTO.setContentAware(true);
    Set<String> subscriptionTiers = new HashSet<>();
    List<SubscribedApiDTO> subscribedApiDTOList = new ArrayList<SubscribedApiDTO>();
    for (APISubscriptionInfoDTO api : apis) {
        subscriptionTiers.add(api.getSubscriptionTier());
        SubscribedApiDTO subscribedApiDTO = new SubscribedApiDTO();
        subscribedApiDTO.setName(api.getApiName());
        subscribedApiDTO.setContext(api.getContext());
        subscribedApiDTO.setVersion(api.getVersion());
        subscribedApiDTO.setPublisher(APIUtil.replaceEmailDomainBack(api.getProviderId()));
        subscribedApiDTO.setSubscriptionTier(api.getSubscriptionTier());
        subscribedApiDTO.setSubscriberTenantDomain(tenantDomain);
        subscribedApiDTOList.add(subscribedApiDTO);
    }
    jwtTokenInfoDTO.setSubscribedApiDTOList(subscribedApiDTOList);
    if (subscriptionTiers.size() > 0) {
        SubscriptionPolicy[] subscriptionPolicies = ApiMgtDAO.getInstance().getSubscriptionPolicies(subscriptionTiers.toArray(new String[0]), APIUtil.getTenantId(appOwner));
        Map<String, SubscriptionPolicyDTO> subscriptionPolicyDTOList = new HashMap<>();
        for (SubscriptionPolicy subscriptionPolicy : subscriptionPolicies) {
            SubscriptionPolicyDTO subscriptionPolicyDTO = new SubscriptionPolicyDTO();
            subscriptionPolicyDTO.setSpikeArrestLimit(subscriptionPolicy.getRateLimitCount());
            subscriptionPolicyDTO.setSpikeArrestUnit(subscriptionPolicy.getRateLimitTimeUnit());
            subscriptionPolicyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
            subscriptionPolicyDTO.setTierQuotaType(subscriptionPolicy.getTierQuotaType());
            subscriptionPolicyDTO.setGraphQLMaxDepth(subscriptionPolicy.getGraphQLMaxDepth());
            subscriptionPolicyDTO.setGraphQLMaxComplexity(subscriptionPolicy.getGraphQLMaxComplexity());
            subscriptionPolicyDTOList.put(subscriptionPolicy.getPolicyName(), subscriptionPolicyDTO);
        }
        jwtTokenInfoDTO.setSubscriptionPolicyDTOList(subscriptionPolicyDTOList);
    }
    return jwtTokenInfoDTO;
}
Also used : SubscribedApiDTO(org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) JwtTokenInfoDTO(org.wso2.carbon.apimgt.impl.dto.JwtTokenInfoDTO) ArrayList(java.util.ArrayList) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) APISubscriptionInfoDTO(org.wso2.carbon.apimgt.impl.dto.APISubscriptionInfoDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SubscriptionPolicyDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionPolicyDTO)

Aggregations

ArrayList (java.util.ArrayList)3 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)2 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy)2 SubscriptionPolicyDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyDTO)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 EventCountLimit (org.wso2.carbon.apimgt.api.model.policy.EventCountLimit)1 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)1 APISubscriptionInfoDTO (org.wso2.carbon.apimgt.impl.dto.APISubscriptionInfoDTO)1 JwtTokenInfoDTO (org.wso2.carbon.apimgt.impl.dto.JwtTokenInfoDTO)1 SubscribedApiDTO (org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO)1 SubscriptionPolicyDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionPolicyDTO)1 SubscriptionPolicyDTO (org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyDTO)1 SubscriptionPolicyListDTO (org.wso2.carbon.apimgt.internal.service.dto.SubscriptionPolicyListDTO)1 EventCountLimitDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EventCountLimitDTO)1 SubscriptionPolicyListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionPolicyListDTO)1 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ThrottleLimitDTO)1