Search in sources :

Example 11 with UnsupportedThrottleConditionTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException 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 12 with UnsupportedThrottleConditionTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException 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 13 with UnsupportedThrottleConditionTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromIPConditionToDTO.

/**
 * Converts an IP Condition model object into a DTO
 *
 * @param ipCondition IP Condition model object
 * @return DTO object derived from model object
 */
public static ThrottleConditionDTO fromIPConditionToDTO(IPCondition ipCondition) throws UnsupportedThrottleConditionTypeException {
    String ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    throttleConditionDTO.setIpCondition(new IPConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(ipCondition, throttleConditionDTO);
    throttleConditionDTO.getIpCondition().setIpConditionType(ipConditionType);
    throttleConditionDTO.getIpCondition().setSpecificIP(ipCondition.getSpecificIP());
    throttleConditionDTO.getIpCondition().setStartingIP(ipCondition.getStartingIP());
    throttleConditionDTO.getIpCondition().setEndingIP(ipCondition.getEndingIP());
    return throttleConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 14 with UnsupportedThrottleConditionTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromConditionalGroupDTOToPipeline.

/**
 * Converts a single Conditional Group DTO into a Pipeline object
 *
 * @param dto Conditional Group DTO
 * @return Derived Pipeline object from Conditional Group DTO
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 * @throws UnsupportedThrottleConditionTypeException - If error occurs
 */
public static Pipeline fromConditionalGroupDTOToPipeline(ConditionalGroupDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    Pipeline pipeline = new Pipeline();
    pipeline.setDescription(dto.getDescription());
    pipeline.setEnabled(true);
    pipeline.setQuotaPolicy(fromDTOToQuotaPolicy(dto.getLimit()));
    List<Condition> conditions = fromDTOListToConditionList(dto.getConditions());
    pipeline.setConditions(conditions);
    return pipeline;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) Condition(org.wso2.carbon.apimgt.core.models.policy.Condition) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline)

Example 15 with UnsupportedThrottleConditionTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException 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
 * @throws UnsupportedThrottleConditionTypeException
 */
public static APIPolicy fromAdvancedPolicyDTOToPolicy(AdvancedThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    // update mandatory fields such as tenantDomain etc.
    dto = CommonThrottleMappingUtil.updateDefaultMandatoryFieldsOfThrottleDTO(dto);
    APIPolicy apiPolicy = new APIPolicy(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.api.model.policy.APIPolicy) Pipeline(org.wso2.carbon.apimgt.api.model.policy.Pipeline)

Aggregations

ArrayList (java.util.ArrayList)4 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)3 IPCondition (org.wso2.carbon.apimgt.api.model.policy.IPCondition)3 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)3 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)3 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)3 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO)3 UnsupportedThrottleConditionTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException)2 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)2 Condition (org.wso2.carbon.apimgt.api.model.policy.Condition)2 Pipeline (org.wso2.carbon.apimgt.api.model.policy.Pipeline)2 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)2 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)2 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)2 ApplicationThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)2 ConditionalGroupDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ConditionalGroupDTO)2 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)2 AdvancedThrottlePolicyInfoDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyInfoDTO)2 ConditionalGroupDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ConditionalGroupDTO)2 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)1