use of org.wso2.carbon.apimgt.rest.api.store.dto.TierDTO in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesTierLevelTierNameGet.
/**
* Retrieves a tier by tier name and level
*
* @param tierName Name of the tier
* @param tierLevel Level of the tier
* @param ifNoneMatch If-Non-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return The requested tier as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response policiesTierLevelTierNameGet(String tierName, String tierLevel, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
TierDTO tierDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = policiesTierLevelTierNameGetFingerprint(tierName, tierLevel, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
Policy tier = apiStore.getPolicy(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum(tierLevel), tierName);
tierDTO = TierMappingUtil.fromTierToDTO(tier, tierLevel);
return Response.ok().entity(tierDTO).header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving tier";
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.TIER_LEVEL, tierLevel);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.TierDTO in project carbon-apimgt by wso2.
the class TierMappingUtil method fromTierListToDTO.
/**
* Converts a List object of Tiers into a DTO
*
* @param tiers a list of Tier objects
* @param limit max number of objects returned
* @param offset starting index
* @return TierListDTO object containing TierDTOs
*/
public static TierListDTO fromTierListToDTO(List<Policy> tiers, String tierLevel, int limit, int offset) {
TierListDTO tierListDTO = new TierListDTO();
List<TierDTO> tierDTOs = tierListDTO.getList();
if (tierDTOs == null) {
tierDTOs = new ArrayList<>();
tierListDTO.setList(tierDTOs);
}
// identifying the proper start and end indexes
int size = tiers.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
Policy tier = tiers.get(i);
tierDTOs.add(fromTierToDTO(tier, tierLevel));
}
tierListDTO.setCount(tierDTOs.size());
return tierListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.TierDTO in project carbon-apimgt by wso2.
the class TierMappingUtil method fromTierToDTO.
/**
* Converts a Tier object into TierDTO
*
* @param tier Tier object
* @param tierLevel tier level (api/application or resource)
* @return TierDTO corresponds to Tier object
*/
public static TierDTO fromTierToDTO(Policy tier, String tierLevel) {
TierDTO dto = new TierDTO();
dto.setName(tier.getPolicyName());
dto.setDescription(tier.getDescription());
dto.setTierLevel(TierDTO.TierLevelEnum.valueOf(StringUtils.upperCase(tierLevel)));
dto.setUnitTime((long) tier.getDefaultQuotaPolicy().getLimit().getUnitTime());
Limit limit = tier.getDefaultQuotaPolicy().getLimit();
if (limit instanceof RequestCountLimit) {
dto.setRequestCount((long) ((RequestCountLimit) limit).getRequestCount());
} else if (limit instanceof BandwidthLimit) {
dto.setRequestCount((long) ((BandwidthLimit) limit).getDataAmount());
}
// // TODO: 08/12/16 More fields to map
return dto;
}
Aggregations