Search in sources :

Example 1 with TagDTO

use of org.wso2.carbon.apimgt.rest.api.store.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;
}
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 2 with TagDTO

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

Example 3 with TagDTO

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

Aggregations

TagDTO (org.wso2.carbon.apimgt.rest.api.store.dto.TagDTO)3 Tag (org.wso2.carbon.apimgt.core.models.Tag)2 Test (org.testng.annotations.Test)1 TagListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.TagListDTO)1