use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionListToDTO.
/**
* Converts a List object of SubscribedAPIs into a DTO
*
* @param subscriptions a list of SubscribedAPI objects
* @param limit max number of objects returned
* @param offset starting index
* @return SubscriptionListDTO object containing SubscriptionDTOs
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<Subscription> subscriptions, Integer limit, Integer offset) {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
subscriptionListDTO.setList(subscriptionDTOs);
}
// identifying the proper start and end indexes
int size = subscriptions.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++) {
Subscription subscription = subscriptions.get(i);
subscriptionDTOs.add(fromSubscriptionToDTO(subscription));
}
subscriptionListDTO.setCount(subscriptionDTOs.size());
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class TagMappingUtil method fromTagListToDTO.
/**
* Converts a List object of Tags into a DTO
*
* @param tags a list of Tag objects
* @param limit max number of objects returned
* @param offset starting index
* @return TierListDTO object containing TierDTOs
*/
public static TagListDTO fromTagListToDTO(List<Tag> tags, int limit, int offset) {
TagListDTO tagListDTO = new TagListDTO();
List<TagDTO> tierDTOs = tagListDTO.getList();
if (tierDTOs == null) {
tierDTOs = new ArrayList<>();
tagListDTO.setList(tierDTOs);
}
// identifying the proper start and end indexes
int size = tags.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++) {
Tag tag = tags.get(i);
tierDTOs.add(fromTagToDTO(tag));
}
tagListDTO.setCount(tierDTOs.size());
return tagListDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit 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.api.model.policy.Limit in project carbon-apimgt by wso2.
the class RatingMappingUtil method fromRatingDTOListToRatingListDTO.
/**
* Constructs a RatingListDTO from a list of RatingDTO objects and other information
*
* @param avgRating Average Rating of the API
* @param userRating User Rating for the API
* @param offset starting index
* @param limit maximum number of ratings to return
* @param ratingList List of RatingDTO Objects available for the API
* @return a new RatingLIstDTO object
*/
public static RatingListDTO fromRatingDTOListToRatingListDTO(double avgRating, double userRating, Integer offset, Integer limit, List<RatingDTO> ratingList) {
RatingListDTO ratingListDTO = new RatingListDTO();
List<RatingDTO> ratingDTOs = ratingListDTO.getList();
DecimalFormat decimalFormat = new DecimalFormat("#.#");
ratingListDTO.setAvgRating(String.valueOf(decimalFormat.format(avgRating)));
ratingListDTO.setUserRating(String.valueOf(decimalFormat.format(userRating)));
if (ratingList == null) {
ratingList = new ArrayList<>();
ratingListDTO.setList(ratingList);
}
// add the required range of objects to be returned
int start = offset < ratingList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= ratingList.size() - 1 ? offset + limit - 1 : ratingList.size() - 1;
for (int i = start; i <= end; i++) {
ratingDTOs.add(ratingList.get(i));
}
ratingListDTO.setCount(ratingDTOs.size());
return ratingListDTO;
}
use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationsToDTO.
/**
* Converts an Application[] array into a corresponding ApplicationListDTO
*
* @param applications array of Application objects
* @param limit limit parameter
* @param offset starting index
* @return ApplicationListDTO object corresponding to Application[] array
*/
public static ApplicationListDTO fromApplicationsToDTO(List<Application> applications, int limit, int offset) {
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
List<ApplicationInfoDTO> applicationInfoDTOs = applicationListDTO.getList();
if (applicationInfoDTOs == null) {
applicationInfoDTOs = new ArrayList<>();
applicationListDTO.setList(applicationInfoDTOs);
}
// identifying the proper start and end indexes
int start = offset < applications.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= applications.size() - 1 ? offset + limit - 1 : applications.size() - 1;
for (int i = start; i <= end; i++) {
applicationInfoDTOs.add(fromApplicationToInfoDTO(applications.get(i)));
}
applicationListDTO.setCount(applicationInfoDTOs.size());
return applicationListDTO;
}
Aggregations