use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromConditionToDTO.
/**
* Converts a Throttle Condition model object into a DTO
*
* @param condition Throttle condition model object
* @return Derived DTO object from the model object
* @throws UnsupportedThrottleConditionTypeException
*/
public static // .................
ThrottleConditionDTO fromConditionToDTO(// .................
Condition condition) throws UnsupportedThrottleConditionTypeException {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setInvertCondition(condition.isInvertCondition());
if (condition instanceof IPCondition) {
throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.IPCONDITION);
throttleConditionDTO.setIpCondition(fromIPConditionToDTO((IPCondition) condition));
} else if (condition instanceof HeaderCondition) {
throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.HEADERCONDITION);
throttleConditionDTO.setHeaderCondition(fromHeaderConditionToDTO((HeaderCondition) condition));
} else if (condition instanceof QueryParameterCondition) {
throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.QUERYPARAMETERCONDITION);
throttleConditionDTO.setQueryParameterCondition(fromQueryParameterConditionToDTO((QueryParameterCondition) condition));
} else if (condition instanceof JWTClaimsCondition) {
throttleConditionDTO.setType(ThrottleConditionDTO.TypeEnum.JWTCLAIMSCONDITION);
throttleConditionDTO.setJwtClaimsCondition(fromJWTClaimsConditionToDTO((JWTClaimsCondition) condition));
} else {
String msg = "Throttle Condition type " + condition.getClass().getName() + " is not supported";
throw new UnsupportedThrottleConditionTypeException(msg);
}
return throttleConditionDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO 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 ThrottleConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
throttleConditionDTO.setJwtClaimsCondition(new JWTClaimsConditionDTO());
throttleConditionDTO = updateFieldsFromConditionToDTO(condition, throttleConditionDTO);
throttleConditionDTO.getJwtClaimsCondition().setClaimUrl(condition.getClaimUrl());
throttleConditionDTO.getJwtClaimsCondition().setAttribute(condition.getAttribute());
return throttleConditionDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToJWTClaimsCondition.
/**
* Converts a JWT Claims Condition DTO object into a model object
*
* @param dto JWT Claims Condition DTO object
* @return JWT Claims Condition model object derived from JWT Claims Condition DTO
*/
public static JWTClaimsCondition fromDTOToJWTClaimsCondition(ThrottleConditionDTO dto) {
JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
jwtClaimsCondition = updateFieldsFromDTOToCondition(dto, jwtClaimsCondition);
jwtClaimsCondition.setAttribute(dto.getJwtClaimsCondition().getAttribute());
jwtClaimsCondition.setClaimUrl(dto.getJwtClaimsCondition().getClaimUrl());
return jwtClaimsCondition;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO 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 ThrottleConditionDTO fromIPConditionToDTO(IPCondition ipCondition) throws UnsupportedThrottleConditionTypeException {
String ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
throttleConditionDTO.setIpCondition(new IPConditionDTO());
throttleConditionDTO = updateFieldsFromConditionToDTO(ipCondition, throttleConditionDTO);
throttleConditionDTO.getIpCondition().setIpConditionType(ipConditionType);
throttleConditionDTO.getIpCondition().setSpecificIP(ipCondition.getSpecificIP());
throttleConditionDTO.getIpCondition().setStartingIP(ipCondition.getStartingIP());
throttleConditionDTO.getIpCondition().setEndingIP(ipCondition.getEndingIP());
return throttleConditionDTO;
}
use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtilTestCase method fromJWTConditionDtoToJWTConditionModelTest.
@Test(description = "Convert JWT Condition DTO to JWTCondition Model object")
public void fromJWTConditionDtoToJWTConditionModelTest() throws Exception {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
JWTClaimsConditionDTO jwtClaimsConditionDTO = new JWTClaimsConditionDTO();
jwtClaimsConditionDTO.setAttribute("testAttribute");
jwtClaimsConditionDTO.setClaimUrl("http://wso2.org/claims");
throttleConditionDTO.setJwtClaimsCondition(jwtClaimsConditionDTO);
JWTClaimsCondition condition = (JWTClaimsCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
Assert.assertNotNull(condition);
assertEquals(condition.getAttribute(), "testAttribute");
assertEquals(condition.getClaimUrl(), "http://wso2.org/claims");
}
Aggregations