Search in sources :

Example 71 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-apimgt by wso2.

the class SubscriptionValidationDataUtil method fromApiPolicyToApiPolicyListDTO.

public static ApiPolicyListDTO fromApiPolicyToApiPolicyListDTO(List<APIPolicy> model) {
    ApiPolicyListDTO apiPolicyListDTO = new ApiPolicyListDTO();
    if (model != null) {
        for (APIPolicy apiPolicyModel : model) {
            ApiPolicyDTO policyDTO = new ApiPolicyDTO();
            policyDTO.setName(apiPolicyModel.getName());
            policyDTO.setQuotaType(apiPolicyModel.getQuotaType());
            policyDTO.setTenantId(apiPolicyModel.getTenantId());
            policyDTO.setTenantDomain(apiPolicyModel.getTenantDomain());
            policyDTO.setApplicableLevel(apiPolicyModel.getApplicableLevel());
            policyDTO.setDefaultLimit(getThrottleLimitDTO(apiPolicyModel));
            apiPolicyListDTO.getList().add(policyDTO);
            List<APIPolicyConditionGroup> retrievedGroups = apiPolicyModel.getConditionGroups();
            List<ApiPolicyConditionGroupDTO> condGroups = new ArrayList<ApiPolicyConditionGroupDTO>();
            for (APIPolicyConditionGroup retGroup : retrievedGroups) {
                ApiPolicyConditionGroupDTO group = new ApiPolicyConditionGroupDTO();
                group.setConditionGroupId(retGroup.getConditionGroupId());
                group.setQuotaType(retGroup.getQuotaType());
                group.setDefaultLimit(getThrottleLimitDTO(retGroup));
                group.setPolicyId(retGroup.getPolicyId());
                List<org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO> condition = new ArrayList<org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO>();
                List<ConditionDTO> retrievedConditions = retGroup.getConditionDTOS();
                for (ConditionDTO retrievedCondition : retrievedConditions) {
                    org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO conditionDTO = new org.wso2.carbon.apimgt.internal.service.dto.ConditionDTO();
                    conditionDTO.setConditionType(retrievedCondition.getConditionType());
                    conditionDTO.setIsInverted(retrievedCondition.isInverted());
                    conditionDTO.setName(retrievedCondition.getConditionName());
                    conditionDTO.setValue(retrievedCondition.getConditionValue());
                    condition.add(conditionDTO);
                }
                group.setCondition(condition);
                condGroups.add(group);
            }
            policyDTO.setConditionGroups(condGroups);
        }
        apiPolicyListDTO.setCount(model.size());
    } else {
        apiPolicyListDTO.setCount(0);
    }
    return apiPolicyListDTO;
}
Also used : APIPolicyConditionGroup(org.wso2.carbon.apimgt.api.model.subscription.APIPolicyConditionGroup) ArrayList(java.util.ArrayList) ApiPolicyConditionGroupDTO(org.wso2.carbon.apimgt.internal.service.dto.ApiPolicyConditionGroupDTO) ApiPolicyDTO(org.wso2.carbon.apimgt.internal.service.dto.ApiPolicyDTO) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) APIPolicy(org.wso2.carbon.apimgt.api.model.subscription.APIPolicy) ApiPolicyListDTO(org.wso2.carbon.apimgt.internal.service.dto.ApiPolicyListDTO)

Example 72 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-apimgt by wso2.

the class WSDLSOAPOperationExtractorImplTestCase method testGetSwaggerModelForSimpleType.

@Test
public void testGetSwaggerModelForSimpleType() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/sample-service.wsdl").toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent, wsdlReader);
    Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
    Assert.assertNotNull(parameterModelMap);
    // get simple type
    Assert.assertNotNull(parameterModelMap.get("Condition"));
    Assert.assertEquals("string", parameterModelMap.get("Condition").getType());
    // get simple type inside complex type
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Availability"));
    Assert.assertEquals("string", parameterModelMap.get("ItemSearchRequest").getProperties().get("Availability").getType());
}
Also used : APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 73 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromJWTClaimsConditionToDTO.

/**
 * Converts a JWT Claims Condition model object into a DTO
 *
 * @param condition JWT Claims Condition model object
 * @return DTO object that was derived from JWT Claims Condition model object
 */
public static JWTClaimsConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
    JWTClaimsConditionDTO dto = new JWTClaimsConditionDTO();
    dto.setClaimUrl(condition.getClaimUrl());
    dto.setAttribute(condition.getAttribute());
    return dto;
}
Also used : JWTClaimsConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.JWTClaimsConditionDTO)

Example 74 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition 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)

Example 75 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToQueryParameterCondition.

/**
 * Converts a Query Parameter Condition DTO object into a model object
 *
 * @param dto             Query Parameter Condition DTO object
 * @param invertCondition Invert condition relevant to the DTO
 * @return Query Parameter Condition model object derived from Query Parameter Condition DTO
 */
public static QueryParameterCondition fromDTOToQueryParameterCondition(QueryParameterConditionDTO dto, boolean invertCondition) {
    QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
    queryParameterCondition.setConditionEnabled(Boolean.TRUE.toString());
    queryParameterCondition.setInvertCondition(invertCondition);
    queryParameterCondition.setParameter(dto.getParameterName());
    queryParameterCondition.setValue(dto.getParameterValue());
    return queryParameterCondition;
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Aggregations

HashMap (java.util.HashMap)39 Test (org.junit.Test)32 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)30 List (java.util.List)26 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)26 ConditionDto (org.wso2.carbon.apimgt.impl.dto.ConditionDto)26 MessageContext (org.apache.synapse.MessageContext)25 PreparedStatement (java.sql.PreparedStatement)23 Map (java.util.Map)22 ResultSet (java.sql.ResultSet)20 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)18 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)18 Connection (java.sql.Connection)16 SQLException (java.sql.SQLException)16 TreeMap (java.util.TreeMap)16 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)15 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)15 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)15 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)15