use of io.gravitee.rest.api.portal.rest.model.CategoryLinks in project gravitee-management-rest-api by gravitee-io.
the class CategoryMapper method convert.
public Category convert(CategoryEntity categoryEntity, UriBuilder baseUriBuilder) {
final Category category = new Category();
category.setDescription(categoryEntity.getDescription());
category.setId(categoryEntity.getKey());
category.setName(categoryEntity.getName());
category.setOrder(categoryEntity.getOrder());
category.setPage(categoryEntity.getPage());
category.setTotalApis(categoryEntity.getTotalApis());
CategoryLinks categoryLinks = new CategoryLinks();
String basePath = PortalApiLinkHelper.categoriesURL(baseUriBuilder.clone(), categoryEntity.getId());
String highlightApi = categoryEntity.getHighlightApi();
if (highlightApi != null) {
categoryLinks.setHighlightedApi(PortalApiLinkHelper.apisURL(baseUriBuilder.clone(), highlightApi));
}
final String hash = categoryEntity.getUpdatedAt() == null ? "" : String.valueOf(categoryEntity.getUpdatedAt().getTime());
categoryLinks.setPicture(basePath + "/picture?" + hash);
categoryLinks.setBackground(basePath + "/background?" + hash);
categoryLinks.setSelf(basePath);
category.setLinks(categoryLinks);
return category;
}
use of io.gravitee.rest.api.portal.rest.model.CategoryLinks in project gravitee-management-rest-api by gravitee-io.
the class CategoryMapperTest method testConvert.
@Test
public void testConvert() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
CategoryEntity categoryEntity = new CategoryEntity();
categoryEntity.setCreatedAt(nowDate);
categoryEntity.setDescription(CATEGORY_DESCRIPTION);
categoryEntity.setHidden(true);
categoryEntity.setHighlightApi(CATEGORY_HIGHLIGHT_API);
categoryEntity.setId(CATEGORY_ID);
categoryEntity.setKey(CATEGORY_KEY);
categoryEntity.setName(CATEGORY_NAME);
categoryEntity.setOrder(11);
categoryEntity.setPage(CATEGORY_PAGE);
categoryEntity.setPicture(CATEGORY_PICTURE);
categoryEntity.setPictureUrl(CATEGORY_PICTURE_URL);
categoryEntity.setTotalApis(42);
categoryEntity.setUpdatedAt(nowDate);
categoryEntity.setPicture(CATEGORY_BACKGROUND);
categoryEntity.setPictureUrl(CATEGORY_BACKGROUND_URL);
// init
Category category = categoryMapper.convert(categoryEntity, UriBuilder.fromPath(CATEGORY_BASE_URL));
assertEquals(CATEGORY_DESCRIPTION, category.getDescription());
assertEquals(CATEGORY_KEY, category.getId());
assertEquals(CATEGORY_NAME, category.getName());
assertEquals(CATEGORY_PAGE, category.getPage());
assertEquals(11, category.getOrder().intValue());
assertEquals(42, category.getTotalApis().longValue());
CategoryLinks links = category.getLinks();
assertNotNull(links);
assertEquals(CATEGORY_BASE_URL + "/environments/DEFAULT/apis/" + CATEGORY_HIGHLIGHT_API, links.getHighlightedApi());
assertEquals(CATEGORY_BASE_URL + "/environments/DEFAULT/categories/" + CATEGORY_ID + "/picture?" + nowDate.getTime(), links.getPicture());
assertEquals(CATEGORY_BASE_URL + "/environments/DEFAULT/categories/" + CATEGORY_ID + "/background?" + nowDate.getTime(), links.getBackground());
assertEquals(CATEGORY_BASE_URL + "/environments/DEFAULT/categories/" + CATEGORY_ID, links.getSelf());
}
Aggregations