Search in sources :

Example 21 with IPCondition

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

the class ApiMgtDAO method createConditionGroupDTO.

/**
 * Converts an {@code Pipeline} object into a {@code ConditionGroupDTO}.{@code ConditionGroupDTO} class tries to
 * contain the same information held by  {@code Pipeline}, but in a much lightweight fashion.
 *
 * @param conditionGroup Id of the condition group ({@code Pipeline}) to be converted
 * @return An object of {@code ConditionGroupDTO} type.
 * @throws APIManagementException
 */
public ConditionGroupDTO createConditionGroupDTO(int conditionGroup) throws APIManagementException {
    List<Condition> conditions = getConditions(conditionGroup);
    ArrayList<ConditionDTO> conditionDTOs = new ArrayList<ConditionDTO>(conditions.size());
    for (Condition condition : conditions) {
        ConditionDTO conditionDTO = new ConditionDTO();
        conditionDTO.setConditionType(condition.getType());
        conditionDTO.isInverted(condition.isInvertCondition());
        if (PolicyConstants.IP_RANGE_TYPE.equals(condition.getType())) {
            IPCondition ipRangeCondition = (IPCondition) condition;
            conditionDTO.setConditionName(ipRangeCondition.getStartingIP());
            conditionDTO.setConditionValue(ipRangeCondition.getEndingIP());
        } else if (PolicyConstants.IP_SPECIFIC_TYPE.equals(condition.getType())) {
            IPCondition ipCondition = (IPCondition) condition;
            conditionDTO.setConditionName(PolicyConstants.IP_SPECIFIC_TYPE);
            conditionDTO.setConditionValue(ipCondition.getSpecificIP());
        } else if (PolicyConstants.HEADER_TYPE.equals(condition.getType())) {
            HeaderCondition headerCondition = (HeaderCondition) condition;
            conditionDTO.setConditionName(headerCondition.getHeaderName());
            conditionDTO.setConditionValue(headerCondition.getValue());
        } else if (PolicyConstants.JWT_CLAIMS_TYPE.equals(condition.getType())) {
            JWTClaimsCondition jwtClaimsCondition = (JWTClaimsCondition) condition;
            conditionDTO.setConditionName(jwtClaimsCondition.getClaimUrl());
            conditionDTO.setConditionValue(jwtClaimsCondition.getAttribute());
        } else if (PolicyConstants.QUERY_PARAMETER_TYPE.equals(condition.getType())) {
            QueryParameterCondition parameterCondition = (QueryParameterCondition) condition;
            conditionDTO.setConditionName(parameterCondition.getParameter());
            conditionDTO.setConditionValue(parameterCondition.getValue());
        }
        conditionDTOs.add(conditionDTO);
    }
    ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
    conditionGroupDTO.setConditions(conditionDTOs.toArray(new ConditionDTO[] {}));
    return conditionGroupDTO;
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition) Condition(org.wso2.carbon.apimgt.api.model.policy.Condition) IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition) HeaderCondition(org.wso2.carbon.apimgt.api.model.policy.HeaderCondition) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) ArrayList(java.util.ArrayList) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Example 22 with IPCondition

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

the class CommonThrottleMappingUtil method fromIPConditionToDTO.

/**
 * Converts an IP Condition model object into a DTO
 *
 * @param ipCondition IP Condition model object
 * @return DTO object derived from model object
 */
public static IPConditionDTO fromIPConditionToDTO(IPCondition ipCondition) {
    IPConditionDTO.IpConditionTypeEnum ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
    IPConditionDTO dto = new IPConditionDTO();
    dto.setIpConditionType(ipConditionType);
    dto.setSpecificIP(ipCondition.getSpecificIP());
    dto.setStartingIP(ipCondition.getStartingIP());
    dto.setEndingIP(ipCondition.getEndingIP());
    return dto;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.IPConditionDTO)

Aggregations

IPCondition (org.wso2.carbon.apimgt.api.model.policy.IPCondition)9 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)8 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)8 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)8 ArrayList (java.util.ArrayList)7 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)7 Condition (org.wso2.carbon.apimgt.api.model.policy.Condition)5 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Test (org.testng.annotations.Test)3 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)3 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)3 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)3 ConditionDto (org.wso2.carbon.apimgt.impl.dto.ConditionDto)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 JSONObject (org.json.simple.JSONObject)2 UnsupportedThrottleConditionTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException)2 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)2