Search in sources :

Example 1 with ResourcePathDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromResourcePathListToDTO.

/**
 * Converts a List object of API resource paths into a DTO.
 *
 * @param resourcePathList List of API resource paths
 * @param limit            maximum number of API resource paths to be returned
 * @param offset           starting index
 * @return ResourcePathListDTO object containing ResourcePathDTOs
 */
public static ResourcePathListDTO fromResourcePathListToDTO(List<ResourcePath> resourcePathList, int limit, int offset) {
    ResourcePathListDTO resourcePathListDTO = new ResourcePathListDTO();
    List<ResourcePathDTO> resourcePathDTOs = new ArrayList<ResourcePathDTO>();
    // identifying the proper start and end indexes
    int size = resourcePathList.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++) {
        ResourcePath path = resourcePathList.get(i);
        ResourcePathDTO dto = new ResourcePathDTO();
        dto.setId(path.getId());
        dto.setResourcePath(path.getResourcePath());
        dto.setHttpVerb(path.getHttpVerb());
        resourcePathDTOs.add(dto);
    }
    resourcePathListDTO.setCount(resourcePathDTOs.size());
    resourcePathListDTO.setList(resourcePathDTOs);
    return resourcePathListDTO;
}
Also used : ResourcePathDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathDTO) ResourcePath(org.wso2.carbon.apimgt.api.model.ResourcePath) ArrayList(java.util.ArrayList) ResourcePathListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathListDTO)

Aggregations

ArrayList (java.util.ArrayList)1 ResourcePath (org.wso2.carbon.apimgt.api.model.ResourcePath)1 ResourcePathDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathDTO)1 ResourcePathListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ResourcePathListDTO)1