use of org.wso2.carbon.apimgt.api.model.policy.Policy 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 - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static AdvancedThrottlePolicyDTO fromAdvancedPolicyToInfoDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyDTO policyDTO = new AdvancedThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
if (apiPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy 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 - If error occurs
*/
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(Policy appPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
if (appPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationPolicyArrayToListDTO.
/**
* Converts an array of Application Policy objects into a List DTO
*
* @param appPolicies Array of Application Policies
* @return A List DTO of converted Application Policies
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(List<ApplicationPolicy> appPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
if (appPolicies != null) {
for (Policy policy : appPolicies) {
ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
appPolicyDTOList.add(dto);
}
}
listDTO.setCount(appPolicyDTOList.size());
listDTO.setList(appPolicyDTOList);
return listDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromQuotaPolicyToDTO.
/**
* Converts a Quota Policy object into a Throttle Limit DTO object
*
* @param quotaPolicy Quota Policy object
* @return Throttle Limit DTO object derived from the Quota Policy object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) throws UnsupportedThrottleLimitTypeException {
Limit limit = quotaPolicy.getLimit();
String throttleLimitType = quotaPolicy.getType();
if (PolicyConstants.REQUEST_COUNT_TYPE.equals(throttleLimitType)) {
if (limit instanceof RequestCountLimit) {
RequestCountLimit requestCountLimit = (RequestCountLimit) limit;
return fromRequestCountLimitToDTO(requestCountLimit);
} else {
String msg = "Throttle limit type " + throttleLimitType + " is not of type RequestCountLimit";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
} else if (PolicyConstants.BANDWIDTH_TYPE.equals(throttleLimitType)) {
if (limit instanceof BandwidthLimit) {
BandwidthLimit bandwidthLimit = (BandwidthLimit) limit;
return fromBandwidthLimitToDTO(bandwidthLimit);
} else {
String msg = "Throttle limit type " + throttleLimitType + " is not of type BandwidthLimit";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
} else {
String msg = "Throttle limit type " + throttleLimitType + " is not supported";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingCustomRuleIdDelete.
/**
* Delete a custom rule specified by uuid.
*
* @param ruleId uuid of the policy
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return 200 OK response if successfully deleted the policy
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingCustomRuleIdDelete(String ruleId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Custom Policy DELETE request with rule ID = " + ruleId);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
apiMgtAdminService.deleteCustomRule(ruleId);
return Response.ok().build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while deleting a custom policy uuid : " + ruleId;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.TIER, ruleId);
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations