use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TagDTO 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.rest.api.store.v1.dto.TagDTO in project carbon-apimgt by wso2.
the class TagMappingUtilTestCase method testFromTagToDTO.
@Test
public void testFromTagToDTO() {
Tag.Builder tagBuilder = new Tag.Builder();
Tag tag = tagBuilder.name("tag1").count(1).build();
TagDTO tagDTO = TagMappingUtil.fromTagToDTO(tag);
assertEquals(tag.getName(), tagDTO.getName());
assertEquals((Integer) tag.getCount(), tagDTO.getWeight());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TagDTO in project carbon-apimgt by wso2.
the class TagMappingUtil method fromTagToDTO.
/**
* Converts a Tag object into TagDTO
*
* @param tag Tag object
* @return TagDTO corresponds to Tag object
*/
public static TagDTO fromTagToDTO(Tag tag) {
TagDTO tagDTO = new TagDTO();
tagDTO.setValue(tag.getName());
tagDTO.setCount(tag.getNoOfOccurrences());
return tagDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TagDTO in project carbon-apimgt by wso2.
the class TagMappingUtil method fromTagToDTO.
/**
* Converts a Tag object into TagDTO
*
* @param tag Tag object
* @return TagDTO corresponds to Tag object
*/
public static TagDTO fromTagToDTO(Tag tag) {
TagDTO tagDTO = new TagDTO();
tagDTO.setName(tag.getName());
tagDTO.setWeight(tag.getCount());
return tagDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.TagDTO 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;
}
Aggregations