Search in sources :

Example 31 with UnsupportedThrottleLimitTypeException

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

the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyToDTO.

/**
 * 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 AdvancedThrottlePolicyDTO fromAdvancedPolicyToDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    AdvancedThrottlePolicyDTO policyDTO = new AdvancedThrottlePolicyDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
    List<ConditionalGroupDTO> groupDTOs = CommonThrottleMappingUtil.fromPipelineListToConditionalGroupDTOList(apiPolicy.getPipelines());
    policyDTO.setConditionalGroups(groupDTOs);
    policyDTO.setType(ADVANCED_THROTTLING_POLICY_TYPE);
    if (apiPolicy.getDefaultQuotaPolicy() != null) {
        policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
    }
    return policyDTO;
}
Also used : ConditionalGroupDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ConditionalGroupDTO) AdvancedThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyDTO)

Example 32 with UnsupportedThrottleLimitTypeException

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

the class GlobalThrottlePolicyMappingUtil method fromGlobalThrottlePolicyDTOToModel.

/**
 * Converts a single Global policy DTO object into model object
 *
 * @param dto Global policy DTO object
 * @return Model object derived from DTO
 * @throws UnsupportedThrottleLimitTypeException
 */
public static GlobalPolicy fromGlobalThrottlePolicyDTOToModel(CustomRuleDTO dto) throws UnsupportedThrottleLimitTypeException {
    // update mandatory fields such as tenantDomain etc.
    dto = CommonThrottleMappingUtil.updateDefaultMandatoryFieldsOfThrottleDTO(dto);
    GlobalPolicy globalPolicy = new GlobalPolicy(dto.getPolicyName());
    globalPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, globalPolicy);
    globalPolicy.setKeyTemplate(dto.getKeyTemplate());
    globalPolicy.setSiddhiQuery(dto.getSiddhiQuery());
    return globalPolicy;
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)

Example 33 with UnsupportedThrottleLimitTypeException

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

the class GlobalThrottlePolicyMappingUtil method fromGlobalPolicyArrayToListDTO.

/**
 * Converts an array of Global policy model objects into REST API DTO objects
 *
 * @param GlobalPolicies An array of Global Policy model objects
 * @return A List DTO of Global Policy DTOs derived from the array of model objects
 * @throws UnsupportedThrottleLimitTypeException
 */
public static CustomRuleListDTO fromGlobalPolicyArrayToListDTO(GlobalPolicy[] GlobalPolicies) throws UnsupportedThrottleLimitTypeException {
    CustomRuleListDTO listDTO = new CustomRuleListDTO();
    List<CustomRuleDTO> globalPolicyDTOList = new ArrayList<>();
    if (GlobalPolicies != null) {
        for (GlobalPolicy policy : GlobalPolicies) {
            CustomRuleDTO dto = fromGlobalThrottlePolicyToDTO(policy);
            globalPolicyDTOList.add(dto);
        }
    }
    listDTO.setCount(globalPolicyDTOList.size());
    listDTO.setList(globalPolicyDTOList);
    return listDTO;
}
Also used : CustomRuleDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomRuleDTO) GlobalPolicy(org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy) ArrayList(java.util.ArrayList) CustomRuleListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomRuleListDTO)

Example 34 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.api.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
 */
public static ApplicationPolicy fromApplicationThrottlePolicyDTOToModel(ApplicationThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException {
    // update mandatory fields such as tenantDomain etc.
    dto = CommonThrottleMappingUtil.updateDefaultMandatoryFieldsOfThrottleDTO(dto);
    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.api.model.policy.ApplicationPolicy)

Example 35 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.api.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
 * @throws UnsupportedThrottleConditionTypeException
 */
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.v1.dto.ConditionalGroupDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO)

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