Search in sources :

Example 16 with Page

use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.

the class PagesResourceTest method init.

@Before
public void init() throws IOException {
    resetAllMocks();
    doReturn(new Page()).when(pageMapper).convert(any());
    doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
}
Also used : Page(io.gravitee.rest.api.portal.rest.model.Page) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Before(org.junit.Before)

Example 17 with Page

use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.

the class PagesResourceTest method shouldGetNoPageIfAuthorizeAndPublishedPageAndSystemFolder.

@Test
public void shouldGetNoPageIfAuthorizeAndPublishedPageAndSystemFolder() {
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    publishedPage.setType("SYSTEM_FOLDER");
    doReturn(singletonList(publishedPage)).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(0, pages.size());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Test(org.junit.Test)

Example 18 with Page

use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.

the class PageMapperTest method testMinimalConvert.

@Test
public void testMinimalConvert() {
    // init
    pageEntity = new PageEntity();
    pageEntity.setType(PAGE_TYPE);
    Instant now = Instant.now();
    pageEntity.setLastModificationDate(Date.from(now));
    // Test
    Page responsePage = pageMapper.convert(pageEntity);
    assertNotNull(responsePage);
    PageConfiguration pageConfiguration = responsePage.getConfiguration();
    assertNull(pageConfiguration);
    List<Metadata> metadatas = responsePage.getMetadata();
    assertNull(metadatas);
    assertEquals(TypeEnum.SWAGGER, responsePage.getType());
    assertEquals(now.toEpochMilli(), responsePage.getUpdatedAt().toInstant().toEpochMilli());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageConfiguration(io.gravitee.rest.api.portal.rest.model.PageConfiguration) Instant(java.time.Instant) Metadata(io.gravitee.rest.api.portal.rest.model.Metadata) Page(io.gravitee.rest.api.portal.rest.model.Page) Test(org.junit.Test)

Example 19 with Page

use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.

the class ApiPagesResource method getAncestors.

private List<String> getAncestors(Map<String, Page> pages, Page page) {
    List<String> ancestors = new ArrayList<>();
    String parentId = page.getParent();
    if (parentId == null) {
        return ancestors;
    }
    ancestors.add(parentId);
    Page parentPage = pages.get(parentId);
    if (parentPage != null) {
        ancestors.addAll(getAncestors(pages, parentPage));
    }
    return ancestors;
}
Also used : ArrayList(java.util.ArrayList) Page(io.gravitee.rest.api.portal.rest.model.Page)

Example 20 with Page

use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.

the class ApiPageResource method getPageByApiIdAndPageId.

@GET
@Produces(MediaType.APPLICATION_JSON)
@RequirePortalAuth
public Response getPageByApiIdAndPageId(@HeaderParam("Accept-Language") String acceptLang, @PathParam("apiId") String apiId, @PathParam("pageId") String pageId, @QueryParam("include") List<String> include) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    if (accessControlService.canAccessApiFromPortal(apiId)) {
        final String acceptedLocale = HttpHeadersUtil.getFirstAcceptedLocaleName(acceptLang);
        PageEntity pageEntity = pageService.findById(pageId, acceptedLocale);
        if (accessControlService.canAccessPageFromPortal(apiId, pageEntity)) {
            pageService.transformSwagger(pageEntity, apiId);
            if (!isAuthenticated() && pageEntity.getMetadata() != null) {
                pageEntity.getMetadata().clear();
            }
            Page page = pageMapper.convert(uriInfo.getBaseUriBuilder(), apiId, pageEntity);
            if (include.contains(INCLUDE_CONTENT)) {
                page.setContent(pageEntity.getContent());
            }
            page.setLinks(pageMapper.computePageLinks(PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, pageId), PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, page.getParent())));
            return Response.ok(page).build();
        } else {
            throw new UnauthorizedAccessException();
        }
    }
    throw new ApiNotFoundException(apiId);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) UnauthorizedAccessException(io.gravitee.rest.api.service.exceptions.UnauthorizedAccessException) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) Page(io.gravitee.rest.api.portal.rest.model.Page) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Aggregations

Page (io.gravitee.rest.api.portal.rest.model.Page)24 Response (javax.ws.rs.core.Response)14 Test (org.junit.Test)14 PageEntity (io.gravitee.rest.api.model.PageEntity)13 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)7 Before (org.junit.Before)6 PagesResponse (io.gravitee.rest.api.portal.rest.model.PagesResponse)4 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 PageLinks (io.gravitee.rest.api.portal.rest.model.PageLinks)3 RequirePortalAuth (io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)3 ArrayList (java.util.ArrayList)3 Visibility (io.gravitee.rest.api.model.Visibility)2 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)2 Api (io.gravitee.rest.api.portal.rest.model.Api)2 Metadata (io.gravitee.rest.api.portal.rest.model.Metadata)2 PageConfiguration (io.gravitee.rest.api.portal.rest.model.PageConfiguration)2 Plan (io.gravitee.rest.api.portal.rest.model.Plan)2 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)2 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)2 UnauthorizedAccessException (io.gravitee.rest.api.service.exceptions.UnauthorizedAccessException)2