Search in sources :

Example 16 with UnsupportedThrottleLimitTypeException

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

the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyToDTO.

/**
 * Converts a single Advanced Policy model into REST API DTO
 *
 * @param policy 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 fromAdvancedPolicyToDTO(APIPolicy policy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    AdvancedThrottlePolicyDTO policyDTO = new AdvancedThrottlePolicyDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(policy, policyDTO);
    List<ConditionalGroupDTO> groupDTOs = CommonThrottleMappingUtil.fromPipelineListToConditionalGroupDTOList(policy.getPipelines());
    policyDTO.setConditionalGroups(groupDTOs);
    if (policy.getDefaultQuotaPolicy() != null) {
        policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(policy.getDefaultQuotaPolicy()));
    }
    return policyDTO;
}
Also used : ConditionalGroupDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ConditionalGroupDTO) AdvancedThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)

Example 17 with UnsupportedThrottleLimitTypeException

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

the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyDTOToPolicy.

/**
 * Converts a single Advanced Policy DTO into a model object
 *
 * @param dto Advanced policy DTO object
 * @return Converted Advanced policy model object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 * @throws UnsupportedThrottleConditionTypeException - If error occurs
 */
public static APIPolicy fromAdvancedPolicyDTOToPolicy(AdvancedThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    APIPolicy apiPolicy = new APIPolicy(dto.getId(), dto.getPolicyName());
    apiPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, apiPolicy);
    List<Pipeline> pipelines = CommonThrottleMappingUtil.fromConditionalGroupDTOListToPipelineList(dto.getConditionalGroups());
    apiPolicy.setPipelines(pipelines);
    if (dto.getDefaultLimit() != null) {
        apiPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
    }
    return apiPolicy;
}
Also used : APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline)

Example 18 with UnsupportedThrottleLimitTypeException

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

the class ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyDTOToModel.

/**
 * Converts a single Application Policy DTO into a model object
 *
 * @param dto Application Policy DTO Object
 * @return Converted Application Policy Model object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static ApplicationPolicy fromApplicationThrottlePolicyDTOToModel(ApplicationThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException {
    ApplicationPolicy appPolicy = new ApplicationPolicy(dto.getPolicyName());
    appPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, appPolicy);
    if (dto.getDefaultLimit() != null) {
        appPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
    }
    return appPolicy;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)

Example 19 with UnsupportedThrottleLimitTypeException

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

the class BlockingConditionMappingUtil method fromBlockConditionListToListDTO.

/**
 * Converts a List of Block Condition in to REST API LIST DTO Object.
 *
 * @param blockConditionList A List of Block Conditions
 * @return REST API List DTO object derived from Block Condition list
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static BlockingConditionListDTO fromBlockConditionListToListDTO(List<BlockConditions> blockConditionList) throws UnsupportedThrottleLimitTypeException {
    BlockingConditionListDTO listDTO = new BlockingConditionListDTO();
    List<BlockingConditionDTO> blockingConditionDTOList = new ArrayList<>();
    if (blockConditionList != null) {
        for (BlockConditions blockCondition : blockConditionList) {
            BlockingConditionDTO dto = fromBlockingConditionToDTO(blockCondition);
            blockingConditionDTOList.add(dto);
        }
    }
    listDTO.setCount(blockingConditionDTOList.size());
    listDTO.setList(blockingConditionDTOList);
    return listDTO;
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionListDTO) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)

Example 20 with UnsupportedThrottleLimitTypeException

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

the class BlockingConditionMappingUtil method fromBlockingConditionDTOToBlockCondition.

/**
 * Convert BlockingConditionDTO to BlockCondition.
 *
 * @param blockingConditionDTO blockindConditionDTO to be converted
 * @return BlockCondition Object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static BlockConditions fromBlockingConditionDTOToBlockCondition(BlockingConditionDTO blockingConditionDTO) throws UnsupportedThrottleLimitTypeException {
    BlockConditions blockConditions = new BlockConditions();
    blockConditions.setUuid(blockingConditionDTO.getConditionId());
    blockConditions.setConditionType(blockingConditionDTO.getConditionType());
    blockConditions.setConditionValue(blockingConditionDTO.getConditionValue());
    blockConditions.setEnabled(blockingConditionDTO.getStatus());
    if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockConditions.getConditionType())) {
        blockConditions.setStartingIP(blockingConditionDTO.getIpCondition().getStartingIP());
        blockConditions.setEndingIP(blockingConditionDTO.getIpCondition().getEndingIP());
    }
    return blockConditions;
}
Also used : BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions)

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