Search in sources :

Example 1 with CategoryLinks

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;
}
Also used : Category(io.gravitee.rest.api.portal.rest.model.Category) CategoryLinks(io.gravitee.rest.api.portal.rest.model.CategoryLinks)

Example 2 with CategoryLinks

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());
}
Also used : Category(io.gravitee.rest.api.portal.rest.model.Category) Instant(java.time.Instant) CategoryLinks(io.gravitee.rest.api.portal.rest.model.CategoryLinks) Date(java.util.Date) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Test(org.junit.Test)

Aggregations

Category (io.gravitee.rest.api.portal.rest.model.Category)2 CategoryLinks (io.gravitee.rest.api.portal.rest.model.CategoryLinks)2 CategoryEntity (io.gravitee.rest.api.model.CategoryEntity)1 Instant (java.time.Instant)1 Date (java.util.Date)1 Test (org.junit.Test)1