use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResourceNotAuthenticatedTest method init.
@Before
public void init() {
resetAllMocks();
mockApi = new ApiEntity();
mockApi.setId(API);
doReturn(mockApi).when(apiService).findById(API);
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
doReturn(mockApis).when(apiService).findPublishedByUser(isNull(), argThat(q -> singletonList(API).equals(q.getIds())));
mockPage = new PageEntity();
mockPage.setPublished(true);
mockPage.setVisibility(Visibility.PUBLIC);
doReturn(mockPage).when(pageService).findById(PAGE, null);
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 ApiPagesResource method getPagesByApiId.
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequirePortalAuth
public Response getPagesByApiId(@HeaderParam("Accept-Language") String acceptLang, @PathParam("apiId") String apiId, @BeanParam PaginationParam paginationParam, @QueryParam("homepage") Boolean homepage, @QueryParam("parent") String parent) {
final ApiQuery apiQuery = new ApiQuery();
apiQuery.setIds(Collections.singletonList(apiId));
if (accessControlService.canAccessApiFromPortal(apiId)) {
final String acceptedLocale = HttpHeadersUtil.getFirstAcceptedLocaleName(acceptLang);
Stream<Page> pageStream = pageService.search(new PageQuery.Builder().api(apiId).homepage(homepage).published(true).build(), acceptedLocale, GraviteeContext.getCurrentEnvironment()).stream().filter(page -> accessControlService.canAccessPageFromPortal(apiId, page)).map(pageMapper::convert).map(page -> this.addPageLink(apiId, page));
List<Page> pages;
if (parent != null) {
pages = new ArrayList<>();
Map<String, Page> pagesMap = pageStream.collect(Collectors.toMap(Page::getId, page -> page));
pagesMap.values().forEach(page -> {
List<String> ancestors = this.getAncestors(pagesMap, page);
if (ancestors.contains(parent)) {
pages.add(page);
}
});
} else {
pages = pageStream.collect(Collectors.toList());
}
return createListResponse(pages, paginationParam);
}
throw new ApiNotFoundException(apiId);
}
use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.
the class PagesResource method getAncestors.
private List<String> getAncestors(Map<String, Page> pages, Page page) {
final List<String> ancestors = new ArrayList<>();
final String parentId = page.getParent();
if (parentId == null) {
return ancestors;
}
ancestors.add(parentId);
final 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 PageResourceTest method shouldGetPageWithInclude.
@Test
public void shouldGetPageWithInclude() {
final Response response = target(PUBLISHED_PAGE).queryParam("include", "content").request().get();
assertEquals(OK_200, response.getStatus());
final Page pageResponse = response.readEntity(Page.class);
assertNotNull(pageResponse);
assertEquals(PAGE_CONTENT, pageResponse.getContent());
assertNotNull(pageResponse.getLinks());
}
use of io.gravitee.rest.api.portal.rest.model.Page in project gravitee-management-rest-api by gravitee-io.
the class PageResourceTest method init.
@Before
public void init() {
resetAllMocks();
PageEntity publishedPage = new PageEntity();
publishedPage.setPublished(true);
publishedPage.setVisibility(Visibility.PUBLIC);
publishedPage.setContent(PAGE_CONTENT);
doReturn(publishedPage).when(pageService).findById(PUBLISHED_PAGE, null);
PageEntity unPublishedPage = new PageEntity();
unPublishedPage.setPublished(false);
publishedPage.setVisibility(Visibility.PUBLIC);
unPublishedPage.setContent(PAGE_CONTENT);
doReturn(unPublishedPage).when(pageService).findById(UNPUBLISHED_PAGE, null);
mockAnotherPage = new PageEntity();
mockAnotherPage.setPublished(true);
publishedPage.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);
doThrow(new PageNotFoundException(UNKNOWN_PAGE)).when(pageService).findById(UNKNOWN_PAGE, null);
doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
doReturn(true).when(accessControlService).canAccessApiFromPortal(anyString());
doReturn(true).when(accessControlService).canAccessPageFromPortal(any());
}
Aggregations