use of org.wso2.carbon.apimgt.keymgt.model.entity.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromJWTClaimsConditionToDTO.
/**
* Converts a JWT Claims Condition model object into a DTO
*
* @param condition JWT Claims Condition model object
* @return DTO object that was derived from JWT Claims Condition model object
*/
public static JWTClaimsConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
JWTClaimsConditionDTO dto = new JWTClaimsConditionDTO();
dto.setClaimUrl(condition.getClaimUrl());
dto.setAttribute(condition.getAttribute());
return dto;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromConditionalGroupDTOToPipeline.
/**
* Converts a single Conditional Group DTO into a Pipeline object
*
* @param dto Conditional Group DTO
* @return Derived Pipeline object from Conditional Group DTO
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static Pipeline fromConditionalGroupDTOToPipeline(ConditionalGroupDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
Pipeline pipeline = new Pipeline();
pipeline.setDescription(dto.getDescription());
pipeline.setEnabled(true);
pipeline.setQuotaPolicy(fromDTOToQuotaPolicy(dto.getLimit()));
List<Condition> conditions = fromDTOListToConditionList(dto.getConditions());
pipeline.setConditions(conditions);
return pipeline;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.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
* @param invertCondition Invert condition relevant to the DTO
* @return Query Parameter Condition model object derived from Query Parameter Condition DTO
*/
public static QueryParameterCondition fromDTOToQueryParameterCondition(QueryParameterConditionDTO dto, boolean invertCondition) {
QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
queryParameterCondition.setConditionEnabled(Boolean.TRUE.toString());
queryParameterCondition.setInvertCondition(invertCondition);
queryParameterCondition.setParameter(dto.getParameterName());
queryParameterCondition.setValue(dto.getParameterValue());
return queryParameterCondition;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromHeaderConditionToDTO.
/**
* Converts a Header Condition model object into a DTO
*
* @param headerCondition Header Condition model object
* @return DTO object that was derived from Header Condition model object
*/
public static HeaderConditionDTO fromHeaderConditionToDTO(HeaderCondition headerCondition) {
HeaderConditionDTO dto = new HeaderConditionDTO();
dto.setHeaderName(headerCondition.getHeaderName());
dto.setHeaderValue(headerCondition.getValue());
return dto;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Condition in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOListToConditionList.
/**
* Converts a list of Throttle Condition DTOs into a list of Condition model objects
*
* @param throttleConditionDTOs list of Throttle Condition DTOs
* @return Derived list of Condition model objects from Throttle Condition DTOs
* @throws UnsupportedThrottleConditionTypeException
*/
public static List<Condition> fromDTOListToConditionList(List<ThrottleConditionDTO> throttleConditionDTOs) throws UnsupportedThrottleConditionTypeException {
List<Condition> conditions = new ArrayList<>();
String errorMessage;
if (throttleConditionDTOs != null) {
for (ThrottleConditionDTO dto : throttleConditionDTOs) {
ThrottleConditionDTO.TypeEnum conditionType = dto.getType();
if (conditionType != null) {
switch(conditionType) {
case HEADERCONDITION:
{
if (dto.getHeaderCondition() != null) {
conditions.add(fromDTOToHeaderCondition(dto.getHeaderCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.HEADERCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
case IPCONDITION:
{
if (dto.getIpCondition() != null) {
conditions.add(fromDTOToIPCondition(dto.getIpCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.IPCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
case QUERYPARAMETERCONDITION:
{
if (dto.getQueryParameterCondition() != null) {
conditions.add(fromDTOToQueryParameterCondition(dto.getQueryParameterCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.QUERYPARAMETERCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
case JWTCLAIMSCONDITION:
{
if (dto.getJwtClaimsCondition() != null) {
conditions.add(fromDTOToJWTClaimsCondition(dto.getJwtClaimsCondition(), dto.isInvertCondition()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleConditionDTO.TypeEnum.JWTCLAIMSCONDITION) + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
break;
}
default:
return null;
}
} else {
errorMessage = "Condition item 'type' property has not been specified\n" + dto.toString();
throw new UnsupportedThrottleConditionTypeException(errorMessage);
}
}
}
return conditions;
}
Aggregations