Search in sources :

Example 36 with Limit

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;
}
Also used : Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionListDTO)

Example 37 with Limit

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;
}
Also used : TagListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.TagListDTO) TagDTO(org.wso2.carbon.apimgt.rest.api.store.dto.TagDTO) Tag(org.wso2.carbon.apimgt.core.models.Tag)

Example 38 with Limit

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;
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) TierDTO(org.wso2.carbon.apimgt.rest.api.store.dto.TierDTO) TierListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.TierListDTO)

Example 39 with Limit

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;
}
Also used : DecimalFormat(java.text.DecimalFormat) RatingDTO(org.wso2.carbon.apimgt.rest.api.store.dto.RatingDTO) RatingListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.RatingListDTO)

Example 40 with Limit

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;
}
Also used : ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationInfoDTO) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationListDTO)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)49 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)41 Test (org.testng.annotations.Test)29 PreparedStatement (java.sql.PreparedStatement)22 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)21 API (org.wso2.carbon.apimgt.api.model.API)20 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 Map (java.util.Map)18 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 SQLException (java.sql.SQLException)16 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)16 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)15 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)15 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)14 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)13 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)13 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)13 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)12