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();
}
}
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());
}
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());
}
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());
}
Aggregations