use of org.wso2.carbon.apimgt.rest.api.store.dto.TagListDTO in project carbon-apimgt by wso2.
the class TagsApiServiceImpl method tagsGet.
/**
* Retrieve tags of APIs
*
* @param limit Maximum number of tags to return
* @param offset Starting position of the pagination
* @param ifNoneMatch If-None-Match header value
* @param request msf4j request object
* @return A list of qualifying tags as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response tagsGet(Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
TagListDTO tagListDTO = null;
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<Tag> tagList = apiStore.getAllTags();
tagListDTO = TagMappingUtil.fromTagListToDTO(tagList, limit, offset);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving tags";
HashMap<String, String> paramList = new HashMap<String, String>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return Response.ok().entity(tagListDTO).build();
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.TagListDTO 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.dto.TagListDTO in project carbon-apimgt by wso2.
the class TagMappingUtilTestCase method testFromTagListToDTO.
@Test
public void testFromTagListToDTO() {
Tag.Builder tagBuilder = new Tag.Builder();
Tag tag1 = tagBuilder.name("tag1").count(2).build();
Tag tag2 = tagBuilder.name("tag2").count(2).build();
List<Tag> tags = new ArrayList<>();
tags.add(tag1);
tags.add(tag2);
TagListDTO tagListDTO = TagMappingUtil.fromTagListToDTO(tags, 10, 0);
assertEquals((Integer) tags.size(), tagListDTO.getCount());
assertEquals(tagListDTO.getList().get(0).getName(), tag1.getName());
assertEquals(tagListDTO.getList().get(0).getWeight(), (Integer) tag1.getCount());
assertEquals(tagListDTO.getList().get(1).getName(), tag2.getName());
assertEquals(tagListDTO.getList().get(1).getWeight(), (Integer) tag2.getCount());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.TagListDTO in project carbon-apimgt by wso2.
the class TagsApiServiceImpl method tagsGet.
@Override
public Response tagsGet(Integer limit, Integer offset, String xWSO2Tenant, String ifNoneMatch, MessageContext messageContext) {
// pre-processing
limit = limit != null ? limit : RestApiConstants.TAG_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.TAG_OFFSET_DEFAULT;
Set<Tag> tagSet;
List<Tag> tagList = new ArrayList<>();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
tagSet = apiConsumer.getAllTags(organization);
if (tagSet != null) {
tagList.addAll(tagSet);
}
TagListDTO tagListDTO = TagMappingUtil.fromTagListToDTO(tagList, limit, offset);
TagMappingUtil.setPaginationParams(tagListDTO, limit, offset, tagList.size());
return Response.ok().entity(tagListDTO).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving tags", e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.TagListDTO 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