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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations