Search in sources :

Example 1 with PolicyDTO

use of org.wso2.carbon.identity.entitlement.dto.PolicyDTO in project carbon-apimgt by wso2.

the class CustomPolicyMappingUtil method fromCustomPolicyToDTO.

/**
 * Converts a single Custom Policy model object into DTO object.
 *
 * @param globalPolicy Custom Policy model object
 * @return DTO object derived from the Policy model object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static CustomRuleDTO fromCustomPolicyToDTO(CustomPolicy globalPolicy) throws UnsupportedThrottleLimitTypeException {
    CustomRuleDTO policyDTO = new CustomRuleDTO();
    policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(globalPolicy, policyDTO);
    policyDTO.setKeyTemplate(globalPolicy.getKeyTemplate());
    policyDTO.setSiddhiQuery(globalPolicy.getSiddhiQuery());
    return policyDTO;
}
Also used : CustomRuleDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.CustomRuleDTO)

Example 2 with PolicyDTO

use of org.wso2.carbon.identity.entitlement.dto.PolicyDTO in project carbon-apimgt by wso2.

the class SubscriptionThrottlePolicyMappingUtil method fromSubscriptionThrottlePolicyToDTO.

/**
 * Converts a single Subscription Policy model into REST API DTO
 *
 * @param policy Subscription Policy model object
 * @return Converted Subscription policy REST API DTO object
 * @throws SubscriptionThrottlePolicyException - If error occurs
 */
public static SubscriptionThrottlePolicyDTO fromSubscriptionThrottlePolicyToDTO(SubscriptionPolicy policy) throws SubscriptionThrottlePolicyException {
    try {
        SubscriptionThrottlePolicyDTO policyDTO = new SubscriptionThrottlePolicyDTO();
        policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(policy, policyDTO);
        SubscriptionPolicy subscriptionPolicy = policy;
        policyDTO.setBillingPlan(subscriptionPolicy.getBillingPlan());
        policyDTO.setRateLimitCount(subscriptionPolicy.getRateLimitCount());
        policyDTO.setRateLimitTimeUnit(subscriptionPolicy.getRateLimitTimeUnit());
        policyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
        byte[] customAttributes = subscriptionPolicy.getCustomAttributes();
        if (customAttributes != null && customAttributes.length > 0) {
            List<CustomAttributeDTO> customAttributeDTOs = new ArrayList<>();
            JSONParser parser = new JSONParser();
            JSONArray attributeArray = (JSONArray) parser.parse(new String(customAttributes, StandardCharsets.UTF_8));
            for (Object attributeObj : attributeArray) {
                JSONObject attribute = (JSONObject) attributeObj;
                CustomAttributeDTO customAttributeDTO = CommonThrottleMappingUtil.getCustomAttribute(attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_NAME).toString(), attribute.get(RestApiConstants.THROTTLING_CUSTOM_ATTRIBUTE_VALUE).toString());
                customAttributeDTOs.add(customAttributeDTO);
            }
            policyDTO.setCustomAttributes(customAttributeDTOs);
        }
        if (policy.getDefaultQuotaPolicy() != null) {
            policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(policy.getDefaultQuotaPolicy()));
        }
        return policyDTO;
    } catch (ParseException | UnsupportedThrottleLimitTypeException e) {
        throw new SubscriptionThrottlePolicyException(e.getMessage(), e);
    }
}
Also used : SubscriptionThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyDTO) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) SubscriptionThrottlePolicyException(org.wso2.carbon.apimgt.rest.api.admin.exceptions.SubscriptionThrottlePolicyException) UnsupportedThrottleLimitTypeException(org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException) JSONObject(org.json.simple.JSONObject) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) CustomAttributeDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.CustomAttributeDTO)

Example 3 with PolicyDTO

use of org.wso2.carbon.identity.entitlement.dto.PolicyDTO in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImplTestCase method createThreatProtectionPolicyDTO.

private ThreatProtectionPolicyDTO createThreatProtectionPolicyDTO() {
    ThreatProtectionPolicyDTO policyDTO = new ThreatProtectionPolicyDTO();
    policyDTO.setName("TEST-POLICY");
    policyDTO.setType("XML");
    policyDTO.setUuid(UUID.randomUUID().toString());
    return policyDTO;
}
Also used : ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)

Example 4 with PolicyDTO

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

Example 5 with PolicyDTO

use of org.wso2.carbon.identity.entitlement.dto.PolicyDTO 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)

Aggregations

PolicyDTO (org.wso2.carbon.identity.entitlement.dto.PolicyDTO)29 ArrayList (java.util.ArrayList)19 PolicyDTO (org.wso2.carbon.identity.entitlement.stub.dto.PolicyDTO)16 EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)15 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 Test (org.testng.annotations.Test)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)11 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)11 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)9 PolicyStoreDTO (org.wso2.carbon.identity.entitlement.dto.PolicyStoreDTO)8 Resource (org.wso2.carbon.registry.core.Resource)8 URISyntaxException (java.net.URISyntaxException)7 AbstractPolicy (org.wso2.balana.AbstractPolicy)7 IOException (java.io.IOException)6 URI (java.net.URI)6 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)6 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)6 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)6 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)6 PAPPolicyStoreManager (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager)5