Search in sources :

Example 1 with QueryParameterCondition

use of org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromQueryParameterConditionToDTO.

/**
 * Converts a Query Parameter Condition model object into a DTO
 *
 * @param condition Query Parameter Condition model object
 * @return DTO object that was derived from Query Parameter Condition model object
 */
public static ThrottleConditionDTO fromQueryParameterConditionToDTO(QueryParameterCondition condition) {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.QUERY_PARAMS_CONDITION_TYPE);
    throttleConditionDTO.setQueryParameterCondition(new QueryParameterConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(condition, throttleConditionDTO);
    throttleConditionDTO.getQueryParameterCondition().setParameterName(condition.getParameter());
    throttleConditionDTO.getQueryParameterCondition().setParameterValue(condition.getValue());
    return throttleConditionDTO;
}
Also used : QueryParameterConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.QueryParameterConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 2 with QueryParameterCondition

use of org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition 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
 * @return Query Parameter Condition model object derived from Query Parameter Condition DTO
 */
public static QueryParameterCondition fromDTOToQueryParameterCondition(ThrottleConditionDTO dto) {
    QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
    queryParameterCondition = updateFieldsFromDTOToCondition(dto, queryParameterCondition);
    queryParameterCondition.setParameter(dto.getQueryParameterCondition().getParameterName());
    queryParameterCondition.setValue(dto.getQueryParameterCondition().getParameterValue());
    return queryParameterCondition;
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)

Example 3 with QueryParameterCondition

use of org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultPipelines.

/**
 * create default pipeline for api policy
 *
 * @return list of Pipeline objects is returned
 */
public static List<Pipeline> createDefaultPipelines() {
    // Pipeline 1
    IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
    ipCondition.setStartingIP("192.168.12.3");
    ipCondition.setEndingIP("192.168.88.19");
    IPCondition ipConditionSpecific = new IPCondition(PolicyConstants.IP_SPECIFIC_TYPE);
    ipConditionSpecific.setSpecificIP("123.42.14.56");
    // adding above conditions to condition list of pipeline 1
    // contains conditions for each pipeline
    List<Condition> conditionsList = new ArrayList<>();
    conditionsList.add(ipCondition);
    conditionsList.add(ipConditionSpecific);
    // set quota policy with bandwidth limit
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_MONTH, 1, 1000, PolicyConstants.MB);
    QuotaPolicy quotaPolicy1 = new QuotaPolicy();
    quotaPolicy1.setType(PolicyConstants.BANDWIDTH_TYPE);
    quotaPolicy1.setLimit(bandwidthLimit);
    Pipeline pipeline1 = new Pipeline();
    pipeline1.setId(0);
    pipeline1.setConditions(conditionsList);
    pipeline1.setQuotaPolicy(quotaPolicy1);
    // End of pipeline 1 -> Beginning of pipeline 2
    HeaderCondition headerCondition = new HeaderCondition();
    headerCondition.setHeader("Browser");
    headerCondition.setValue("Chrome");
    JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
    jwtClaimsCondition.setClaimUrl("/path/path2");
    jwtClaimsCondition.setAttribute("attributed");
    QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
    queryParameterCondition.setParameter("Location");
    queryParameterCondition.setValue("Colombo");
    // adding conditions to condition list of pipeline2
    conditionsList = new ArrayList<>();
    conditionsList.add(headerCondition);
    conditionsList.add(jwtClaimsCondition);
    conditionsList.add(queryParameterCondition);
    // pipeline 2 with request count as quota policy
    RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
    QuotaPolicy quotaPolicy2 = new QuotaPolicy();
    quotaPolicy2.setType(REQUEST_COUNT_TYPE);
    quotaPolicy2.setLimit(requestCountLimit);
    Pipeline pipeline2 = new Pipeline();
    pipeline2.setId(1);
    pipeline2.setConditions(conditionsList);
    pipeline2.setQuotaPolicy(quotaPolicy2);
    // adding pipelines
    // contains all the default pipelines
    List<Pipeline> pipelineList = new ArrayList<>();
    pipelineList.add(pipeline1);
    pipelineList.add(pipeline2);
    return pipelineList;
}
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) JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) ArrayList(java.util.ArrayList) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 4 with QueryParameterCondition

use of org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromQueryParamsConditionDtoToQueryParamsConditionModelTest.

@Test(description = "Convert Query param Condition DTO to QueryParamCondition Model object")
public void fromQueryParamsConditionDtoToQueryParamsConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.QUERY_PARAMS_CONDITION_TYPE);
    QueryParameterConditionDTO queryParameterConditionDTO = new QueryParameterConditionDTO();
    queryParameterConditionDTO.setParameterName("testParam");
    queryParameterConditionDTO.setParameterValue("testParamValue");
    throttleConditionDTO.setQueryParameterCondition(queryParameterConditionDTO);
    QueryParameterCondition condition = (QueryParameterCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    assertEquals(condition.getParameter(), "testParam");
    assertEquals(condition.getValue(), "testParamValue");
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) Test(org.testng.annotations.Test)

Example 5 with QueryParameterCondition

use of org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition in project carbon-apimgt by wso2.

the class PolicyDAOImpl method setQueryParameterConditions.

/**
 * Add Query parameter conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
 * provided {@link Condition} array
 *
 * @param pipelineId Id of the pipeline
 * @param conditions condition array to populate
 * @throws SQLException
 */
private void setQueryParameterConditions(int pipelineId, ArrayList<Condition> conditions, Connection connection) throws SQLException {
    final String query = "SELECT " + "PARAMETER_NAME,PARAMETER_VALUE , IS_PARAM_MAPPING " + "FROM " + "AM_QUERY_PARAMETER_CONDITION " + "WHERE " + "CONDITION_GROUP_ID =?";
    try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        preparedStatement.setInt(1, pipelineId);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
                queryParameterCondition.setParameter(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_PARAMETER_NAME));
                queryParameterCondition.setValue(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_PARAMETER_VALUE));
                queryParameterCondition.setInvertCondition(resultSet.getBoolean(APIMgtConstants.ThrottlePolicyConstants.COLUMN_IS_PARAM_MAPPING));
                conditions.add(queryParameterCondition);
            }
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)

Aggregations

QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)5 ArrayList (java.util.ArrayList)2 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)2 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)2 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)2 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)2 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)2 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)2 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)2 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Test (org.testng.annotations.Test)1 QueryParameterConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.QueryParameterConditionDTO)1 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)1