Search in sources :

Example 11 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException 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
 * @throws UnsupportedThrottleConditionTypeException
 */
public static AdvancedThrottlePolicyInfoDTO fromAdvancedPolicyToInfoDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
    AdvancedThrottlePolicyInfoDTO policyDTO = new AdvancedThrottlePolicyInfoDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
    if (apiPolicy.getDefaultQuotaPolicy() != null) {
        policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
    }
    policyDTO.setType(ADVACNCED_THROTTLING_POLICY_INFO_TYPE);
    return policyDTO;
}
Also used : AdvancedThrottlePolicyInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AdvancedThrottlePolicyInfoDTO)

Example 12 with UnsupportedThrottleLimitTypeException

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

the class GlobalThrottlePolicyMappingUtil method fromGlobalThrottlePolicyToDTO.

/**
 * Converts a single Global Policy model object into DTO object
 *
 * @param globalPolicy Global Policy model object
 * @return DTO object derived from the Policy model object
 * @throws UnsupportedThrottleLimitTypeException
 */
public static CustomRuleDTO fromGlobalThrottlePolicyToDTO(GlobalPolicy globalPolicy) throws UnsupportedThrottleLimitTypeException {
    CustomRuleDTO policyDTO = new CustomRuleDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(globalPolicy, policyDTO);
    policyDTO.setKeyTemplate(globalPolicy.getKeyTemplate());
    policyDTO.setSiddhiQuery(globalPolicy.getSiddhiQuery());
    policyDTO.setType(CUSTOM_RULE_THROTTLING_POLICY_TYPE);
    return policyDTO;
}
Also used : CustomRuleDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomRuleDTO)

Example 13 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.api.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
 */
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(ApplicationPolicy appPolicy) throws UnsupportedThrottleLimitTypeException {
    ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
    if (appPolicy.getDefaultQuotaPolicy() != null) {
        policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
    }
    policyDTO.setType(APPLICATION_THROTTLING_POLICY_TYPE);
    return policyDTO;
}
Also used : ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO)

Example 14 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.api.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
 */
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(ApplicationPolicy[] appPolicies) throws UnsupportedThrottleLimitTypeException {
    ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
    List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
    if (appPolicies != null) {
        for (ApplicationPolicy policy : appPolicies) {
            ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
            appPolicyDTOList.add(dto);
        }
    }
    listDTO.setCount(appPolicyDTOList.size());
    listDTO.setList(appPolicyDTOList);
    return listDTO;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) ApplicationThrottlePolicyListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyListDTO) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ApplicationThrottlePolicyDTO)

Example 15 with UnsupportedThrottleLimitTypeException

use of org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException 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
 * @throws UnsupportedThrottleConditionTypeException
 */
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 : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) Condition(org.wso2.carbon.apimgt.api.model.policy.Condition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) Pipeline(org.wso2.carbon.apimgt.api.model.policy.Pipeline)

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