Search in sources :

Example 16 with EventCountLimit

use of org.wso2.carbon.apimgt.api.model.policy.EventCountLimit in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromEventCountLimitToDTO.

public static EventCountLimitDTO fromEventCountLimitToDTO(EventCountLimit eventCountLimit) {
    EventCountLimitDTO dto = new EventCountLimitDTO();
    dto.setTimeUnit(eventCountLimit.getTimeUnit());
    dto.setUnitTime(eventCountLimit.getUnitTime());
    dto.setEventCount(eventCountLimit.getEventCount());
    return dto;
}
Also used : EventCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EventCountLimitDTO)

Example 17 with EventCountLimit

use of org.wso2.carbon.apimgt.api.model.policy.EventCountLimit 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;
}
Also used : UnsupportedThrottleLimitTypeException(org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException) QuotaPolicy(org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleLimitDTO)

Aggregations

EventCountLimit (org.wso2.carbon.apimgt.api.model.policy.EventCountLimit)14 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)12 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)10 QuotaPolicy (org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy)9 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)4 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)4 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 UnsupportedThrottleLimitTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException)2 Tier (org.wso2.carbon.apimgt.api.model.Tier)2 Limit (org.wso2.carbon.apimgt.api.model.policy.Limit)2 Pipeline (org.wso2.carbon.apimgt.api.model.policy.Pipeline)2 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)2 ThrottleLimitDTO (org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO)2 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleLimitDTO)2