use of org.wso2.carbon.apimgt.api.model.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;
}
use of org.wso2.carbon.apimgt.api.model.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;
}
Aggregations