use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class APIThrottlePolicyTemplateBuilder method getPolicyConditionForDefault.
/**
* Produces final condition inside a pipeline for default policy with null string
*
* @param conditions list of default throttle conditions
* @return formatted condition list
*/
private static String getPolicyConditionForDefault(List<Condition> conditions) {
String conditionString = null;
int i = 0;
for (Condition condition : conditions) {
String conditionStringComplete = condition.getCondition();
if (i == 0) {
conditionString = conditionStringComplete;
} else {
conditionString = conditionString + AND + conditionStringComplete;
}
i++;
}
return conditionString;
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultBlockCondition.
public static BlockConditions createDefaultBlockCondition(String conditionType) {
BlockConditions blockConditions = new BlockConditions();
blockConditions.setConditionType(conditionType);
blockConditions.setEnabled(true);
if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP)) {
blockConditions.setConditionValue(SAMPLE_IP_1);
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE)) {
blockConditions.setStartingIP(SAMPLE_IP_1);
blockConditions.setEndingIP(SAMPLE_IP_2);
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_API)) {
try {
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.build();
DAOFactory.getApiDAO().addAPI(api);
blockConditions.setConditionValue(api.getContext());
} catch (APIMgtDAOException e) {
log.error("Error while adding default api in default block condition", e);
}
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_APPLICATION)) {
try {
Application app = createDefaultApplication();
DAOFactory.getApplicationDAO().addApplication(app);
blockConditions.setConditionValue(app.getId() + ":" + app.getName());
} catch (APIMgtDAOException e) {
log.error("Error while adding default app in default block condition", e);
}
} else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_USER)) {
blockConditions.setConditionValue(ADMIN);
}
return blockConditions;
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToIPCondition.
/**
* Converts a IP Condition DTO object into a model object
*
* @param dto IP Condition DTO object
* @return IP Condition model object derived from DTO
*/
public static IPCondition fromDTOToIPCondition(ThrottleConditionDTO dto) throws UnsupportedThrottleConditionTypeException {
String ipConditionType = mapIPConditionTypeFromDTOToModel(dto.getIpCondition().getIpConditionType());
IPCondition ipCondition = new IPCondition(ipConditionType);
ipCondition = updateFieldsFromDTOToCondition(dto, ipCondition);
ipCondition.setSpecificIP(dto.getIpCondition().getSpecificIP());
ipCondition.setStartingIP(dto.getIpCondition().getStartingIP());
ipCondition.setEndingIP(dto.getIpCondition().getEndingIP());
return ipCondition;
}
use of org.wso2.carbon.apimgt.core.models.policy.Condition 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;
}
use of org.wso2.carbon.apimgt.core.models.policy.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
* @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;
}
Aggregations