Search in sources :

Example 21 with Page

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

the class PageResource method getPageByPageId.

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

Example 22 with Page

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

the class ApiResourceNotAuthenticatedTest method callResourceAndCheckResult.

private void callResourceAndCheckResult(Integer expectedTotalPage, Integer expectedTotalPlan) {
    final Response response = target(API).queryParam("include", "pages", "plans").request().get();
    assertEquals(OK_200, response.getStatus());
    Api responseApi = response.readEntity(Api.class);
    assertNotNull(responseApi);
    List<Page> pages = responseApi.getPages();
    assertNotNull(pages);
    assertEquals(expectedTotalPage.intValue(), pages.size());
    List<Plan> plans = responseApi.getPlans();
    assertNotNull(plans);
    assertEquals(expectedTotalPlan.intValue(), plans.size());
}
Also used : Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) Api(io.gravitee.rest.api.portal.rest.model.Api) Plan(io.gravitee.rest.api.portal.rest.model.Plan)

Example 23 with Page

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

the class PageResourceNotAuthenticatedTest method init.

@Before
public void init() {
    resetAllMocks();
    mockAnotherPage = new PageEntity();
    mockAnotherPage.setPublished(true);
    mockAnotherPage.setVisibility(Visibility.PUBLIC);
    Map<String, String> metadataMap = new HashMap<>();
    metadataMap.put(ANOTHER_PAGE, ANOTHER_PAGE);
    mockAnotherPage.setMetadata(metadataMap);
    doReturn(mockAnotherPage).when(pageService).findById(ANOTHER_PAGE, null);
    doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) HashMap(java.util.HashMap) Page(io.gravitee.rest.api.portal.rest.model.Page) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Example 24 with Page

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

the class PageResourceTest method shouldNotHaveMetadataCleared.

@Test
public void shouldNotHaveMetadataCleared() {
    Response response = target(ANOTHER_PAGE).request().get();
    assertEquals(OK_200, response.getStatus());
    Page pageResponse = response.readEntity(Page.class);
    assertNotNull(pageResponse);
    assertFalse(mockAnotherPage.getMetadata().isEmpty());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) Test(org.junit.Test)

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