use of org.wso2.carbon.user.core.model.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.user.core.model.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.user.core.model.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.user.core.model.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;
}
use of org.wso2.carbon.user.core.model.Condition in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtil method fromBlockingConditionToDTO.
/**
* Converts a single Block Condition model object into REST API DTO object.
*
* @param blockCondition Block condition model object
* @return Block condition DTO object derived from block condition model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static BlockingConditionDTO fromBlockingConditionToDTO(BlockConditions blockCondition) throws UnsupportedThrottleLimitTypeException {
if (blockCondition.getUuid() == null) {
return null;
}
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(blockCondition.getUuid());
dto.setConditionType(blockCondition.getConditionType());
dto.setStatus(blockCondition.isEnabled());
if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockCondition.getConditionType())) {
dto.setIpCondition(fromBlockConditionToIpConditionDTO(blockCondition));
}
String conditionValue = blockCondition.getConditionValue();
dto.setConditionValue(conditionValue);
return dto;
}
Aggregations