Search in sources :

Example 6 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException 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;
}
Also used : ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)

Example 7 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException 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;
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) ApplicationThrottlePolicyListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyListDTO) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)

Example 8 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.

the class BlockingConditionMappingUtil method fromBlockingConditionToDTO.

/**
 * Converts a single Block Condition model object into REST API DTO object.
 *
 * @param blockCondition Block condition model object
 * @return Block condition DTO object derived from block condition model object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static BlockingConditionDTO fromBlockingConditionToDTO(BlockConditions blockCondition) throws UnsupportedThrottleLimitTypeException {
    if (blockCondition.getUuid() == null) {
        return null;
    }
    BlockingConditionDTO dto = new BlockingConditionDTO();
    dto.setConditionId(blockCondition.getUuid());
    dto.setConditionType(blockCondition.getConditionType());
    dto.setStatus(blockCondition.isEnabled());
    if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockCondition.getConditionType())) {
        dto.setIpCondition(fromBlockConditionToIpConditionDTO(blockCondition));
    }
    String conditionValue = blockCondition.getConditionValue();
    dto.setConditionValue(conditionValue);
    return dto;
}
Also used : BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)

Example 9 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromPipelineToConditionalGroupDTO.

/**
 * Converts a single Pipeline object into a Conditional Group DTO object
 *
 * @param pipeline Pipeline object
 * @return Derived DTO object from Pipeline object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 * @throws UnsupportedThrottleConditionTypeException - If error occurs
 */
public static ConditionalGroupDTO fromPipelineToConditionalGroupDTO(Pipeline pipeline) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    ConditionalGroupDTO groupDTO = new ConditionalGroupDTO();
    groupDTO.setDescription(pipeline.getDescription());
    groupDTO.setLimit(fromQuotaPolicyToDTO(pipeline.getQuotaPolicy()));
    List<ThrottleConditionDTO> conditionDTOList = fromConditionListToDTOList(pipeline.getConditions());
    groupDTO.setConditions(conditionDTOList);
    return groupDTO;
}
Also used : ConditionalGroupDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ConditionalGroupDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 10 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException 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);
    }
}
Also used : UnsupportedThrottleLimitTypeException(org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) Limit(org.wso2.carbon.apimgt.core.models.policy.Limit) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Aggregations

ArrayList (java.util.ArrayList)10 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)3 UnsupportedThrottleLimitTypeException (org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException)3 JSONParser (org.json.simple.parser.JSONParser)2 UnsupportedThrottleLimitTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException)2 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)2 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)2 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)2 Pipeline (org.wso2.carbon.apimgt.api.model.policy.Pipeline)2 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)2 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)2 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)2 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)2 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)2 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)2 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)2 ApplicationThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)2 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)2