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