use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class ThrottlingApiServiceImpl method throttlingPoliciesApplicationPolicyIdGet.
/**
* Get a specific Application Policy by its uuid
*
* @param policyId uuid of the policy
* @return Matched Application Throttle Policy by the given name
*/
@Override
public Response throttlingPoliciesApplicationPolicyIdGet(String policyId, MessageContext messageContext) {
try {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String username = RestApiCommonUtil.getLoggedInUsername();
// This will give PolicyNotFoundException if there's no policy exists with UUID
ApplicationPolicy appPolicy = apiProvider.getApplicationPolicyByUUID(policyId);
if (!RestApiAdminUtils.isPolicyAccessibleToUser(username, appPolicy)) {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_APP_POLICY, policyId, log);
}
ApplicationThrottlePolicyDTO policyDTO = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(appPolicy);
return Response.ok().entity(policyDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_APP_POLICY, policyId, e, log);
} else {
String errorMessage = "Error while retrieving Application level policy: " + policyId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyToInfoDTO.
/**
* Converts a single Advanced Policy model into REST API DTO
*
* @param apiPolicy Advanced Policy model object
* @return Converted Advanced policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static AdvancedThrottlePolicyInfoDTO fromAdvancedPolicyToInfoDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyInfoDTO policyDTO = new AdvancedThrottlePolicyInfoDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
if (apiPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
}
policyDTO.setType(ADVACNCED_THROTTLING_POLICY_INFO_TYPE);
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class GlobalThrottlePolicyMappingUtil method fromGlobalThrottlePolicyToDTO.
/**
* Converts a single Global Policy model object into DTO object
*
* @param globalPolicy Global Policy model object
* @return DTO object derived from the Policy model object
* @throws UnsupportedThrottleLimitTypeException
*/
public static CustomRuleDTO fromGlobalThrottlePolicyToDTO(GlobalPolicy globalPolicy) throws UnsupportedThrottleLimitTypeException {
CustomRuleDTO policyDTO = new CustomRuleDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(globalPolicy, policyDTO);
policyDTO.setKeyTemplate(globalPolicy.getKeyTemplate());
policyDTO.setSiddhiQuery(globalPolicy.getSiddhiQuery());
policyDTO.setType(CUSTOM_RULE_THROTTLING_POLICY_TYPE);
return policyDTO;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromApiPolicyToApiPolicyListDTO.
public static ApiPolicyListDTO fromApiPolicyToApiPolicyListDTO(List<APIPolicy> model) {
ApiPolicyListDTO apiPolicyListDTO = new ApiPolicyListDTO();
if (model != null) {
for (APIPolicy apiPolicyModel : model) {
ApiPolicyDTO policyDTO = new ApiPolicyDTO();
policyDTO.setName(apiPolicyModel.getName());
policyDTO.setQuotaType(apiPolicyModel.getQuotaType());
policyDTO.setTenantId(apiPolicyModel.getTenantId());
policyDTO.setTenantDomain(apiPolicyModel.getTenantDomain());
policyDTO.setApplicableLevel(apiPolicyModel.getApplicableLevel());
policyDTO.setDefaultLimit(getThrottleLimitDTO(apiPolicyModel));
apiPolicyListDTO.getList().add(policyDTO);
List<APIPolicyConditionGroup> retrievedGroups = apiPolicyModel.getConditionGroups();
List<ApiPolicyConditionGroupDTO> condGroups = new ArrayList<ApiPolicyConditionGroupDTO>();
for (APIPolicyConditionGroup retGroup : retrievedGroups) {
ApiPolicyConditionGroupDTO group = new ApiPolicyConditionGroupDTO();
group.setConditionGroupId(retGroup.getConditionGroupId());
group.setQuotaType(retGroup.getQuotaType());
group.setDefaultLimit(getThrottleLimitDTO(retGroup));
group.setPolicyId(retGroup.getPolicyId());
List<org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO> condition = new ArrayList<org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO>();
List<ConditionDTO> retrievedConditions = retGroup.getConditionDTOS();
for (ConditionDTO retrievedCondition : retrievedConditions) {
org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO conditionDTO = new org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO();
conditionDTO.setConditionType(retrievedCondition.getConditionType());
conditionDTO.setIsInverted(retrievedCondition.isInverted());
conditionDTO.setName(retrievedCondition.getConditionName());
conditionDTO.setValue(retrievedCondition.getConditionValue());
condition.add(conditionDTO);
}
group.setCondition(condition);
condGroups.add(group);
}
policyDTO.setConditionGroups(condGroups);
}
apiPolicyListDTO.setCount(model.size());
} else {
apiPolicyListDTO.setCount(0);
}
return apiPolicyListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyToDTO.
/**
* Converts a single Application Policy model into REST API DTO
*
* @param appPolicy An Application Policy model object
* @return Converted Application policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException
*/
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(ApplicationPolicy appPolicy) throws UnsupportedThrottleLimitTypeException {
ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
if (appPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
}
policyDTO.setType(APPLICATION_THROTTLING_POLICY_TYPE);
return policyDTO;
}
Aggregations