use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromQuotaPolicyToDTO.
/**
* Converts a Quota Policy object into a Throttle Limit DTO object
*
* @param quotaPolicy Quota Policy object
* @return Throttle Limit DTO object derived from the Quota Policy object
* @throws UnsupportedThrottleLimitTypeException
*/
public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) throws UnsupportedThrottleLimitTypeException {
ThrottleLimitDTO defaultLimitType = new ThrottleLimitDTO();
if (PolicyConstants.REQUEST_COUNT_TYPE.equals(quotaPolicy.getType())) {
RequestCountLimit requestCountLimit = (RequestCountLimit) quotaPolicy.getLimit();
defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT);
defaultLimitType.setRequestCount(fromRequestCountLimitToDTO(requestCountLimit));
} else if (PolicyConstants.BANDWIDTH_TYPE.equals(quotaPolicy.getType())) {
BandwidthLimit bandwidthLimit = (BandwidthLimit) quotaPolicy.getLimit();
defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.BANDWIDTHLIMIT);
defaultLimitType.setBandwidth(fromBandwidthLimitToDTO(bandwidthLimit));
} else if (PolicyConstants.EVENT_COUNT_TYPE.equals(quotaPolicy.getType())) {
EventCountLimit eventCountLimit = (EventCountLimit) quotaPolicy.getLimit();
defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT);
defaultLimitType.setEventCount(fromEventCountLimitToDTO(eventCountLimit));
} else {
String msg = "Throttle limit type " + quotaPolicy.getType() + " is not supported";
throw new UnsupportedThrottleLimitTypeException(msg);
}
return defaultLimitType;
}
use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToQuotaPolicy.
/**
* Converts a Throttle Limit DTO object into a Quota Policy object
*
* @param dto Throttle limit DTO object
* @return Derived Quota policy object from DTO
* @throws UnsupportedThrottleLimitTypeException
*/
public static QuotaPolicy fromDTOToQuotaPolicy(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
String errorMessage;
QuotaPolicy quotaPolicy = new QuotaPolicy();
ThrottleLimitDTO.TypeEnum limitType = dto.getType();
if (limitType != null) {
switch(dto.getType()) {
case REQUESTCOUNTLIMIT:
{
if (dto.getRequestCount() != null) {
quotaPolicy.setLimit(fromDTOToRequestCountLimit(dto.getRequestCount()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleLimitDTO.TypeEnum.REQUESTCOUNTLIMIT) + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
break;
}
case BANDWIDTHLIMIT:
{
if (dto.getBandwidth() != null) {
quotaPolicy.setLimit(fromDTOToBandwidthLimit(dto.getBandwidth()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleLimitDTO.TypeEnum.BANDWIDTHLIMIT) + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
break;
}
case EVENTCOUNTLIMIT:
{
if (dto.getEventCount() != null) {
quotaPolicy.setLimit(fromDTOToEventCountLimit(dto.getEventCount()));
} else {
errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT) + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
break;
}
}
quotaPolicy.setType(mapQuotaPolicyTypeFromDTOToModel(dto.getType()));
} else {
errorMessage = "defaultLimit 'type' property has not been specified\n" + dto.toString();
throw new UnsupportedThrottleLimitTypeException(errorMessage);
}
return quotaPolicy;
}
use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToLimit.
/**
* Converts a Throttle Limit DTO object into a Limit object
*
* @param dto Throttle Limit DTO object
* @return Limit object derived from DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static Limit fromDTOToLimit(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
if (PolicyConstants.BANDWIDTH_LIMIT_TYPE.equals(dto.getType())) {
// check if all required params are available
if (dto.getBandwidthLimit() == null || dto.getBandwidthLimit().getDataAmount() == null || dto.getBandwidthLimit().getDataUnit() == null) {
// can't continue, throw
String errorMsg = "One or more required params are missing for the ThrottleLimit type: " + dto.getType();
log.error(errorMsg);
throw new UnsupportedThrottleLimitTypeException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
return fromDTOToBandwidthLimit(dto);
} else if (PolicyConstants.REQUEST_COUNT_LIMIT_TYPE.equals(dto.getType())) {
// check if all required params are available
if (dto.getRequestCountLimit() == null || dto.getRequestCountLimit().getRequestCount() == null) {
// can't continue, throw
String errorMsg = "One or more required params are missing for the ThrottleLimit type: " + dto.getType();
log.error(errorMsg);
throw new UnsupportedThrottleLimitTypeException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
}
return fromDTOToRequestCountLimit(dto);
} else {
String msg = "Throttle limit type " + dto.getType() + " is not supported";
log.error(msg);
throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
}
}
use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromRequestCountLimitToDTO.
/**
* Converts a Request Count Limit model object into a Request Count Limit DTO object
*
* @param requestCountLimit Request Count Limit model object
* @return Request Count DTO object derived from model
*/
public static ThrottleLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
// done
ThrottleLimitDTO dto = new ThrottleLimitDTO();
dto = updateFieldsFromLimitToDTO(requestCountLimit, dto);
dto.setType("RequestCountLimit");
dto.setRequestCountLimit(new RequestCountLimitDTO());
dto.getRequestCountLimit().setRequestCount(requestCountLimit.getRequestCount());
return dto;
}
use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToQuotaPolicy.
/**
* Converts a Throttle Limit DTO object into a Quota Policy object
*
* @param dto Throttle limit DTO object
* @return Derived Quota policy object from DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static QuotaPolicy fromDTOToQuotaPolicy(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setLimit(fromDTOToLimit(dto));
quotaPolicy.setType(mapQuotaPolicyTypeFromDTOToModel(dto.getType()));
return quotaPolicy;
}
Aggregations