use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromPipelineToConditionalGroupDTO.
/**
* Converts a single Pipeline object into a Conditional Group DTO object
*
* @param pipeline Pipeline object
* @return Derived DTO object from Pipeline object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static ConditionalGroupDTO fromPipelineToConditionalGroupDTO(Pipeline pipeline) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ConditionalGroupDTO groupDTO = new ConditionalGroupDTO();
groupDTO.setDescription(pipeline.getDescription());
groupDTO.setLimit(fromQuotaPolicyToDTO(pipeline.getQuotaPolicy()));
List<ThrottleConditionDTO> conditionDTOList = fromConditionListToDTOList(pipeline.getConditions());
groupDTO.setConditions(conditionDTOList);
return groupDTO;
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyToInfoDTO.
/**
* Converts a single Advanced Policy model into REST API DTO
*
* @param apiPolicy Advanced Policy model object
* @return Converted Advanced policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException
* @throws UnsupportedThrottleConditionTypeException
*/
public static AdvancedThrottlePolicyInfoDTO fromAdvancedPolicyToInfoDTO(APIPolicy apiPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
AdvancedThrottlePolicyInfoDTO policyDTO = new AdvancedThrottlePolicyInfoDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(apiPolicy, policyDTO);
if (apiPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(apiPolicy.getDefaultQuotaPolicy()));
}
policyDTO.setType(ADVACNCED_THROTTLING_POLICY_INFO_TYPE);
return policyDTO;
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException 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.api.UnsupportedThrottleConditionTypeException 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;
}
use of org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException 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;
}
Aggregations