use of io.gravitee.rest.api.model.PageEntity 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.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPagesResourceNotAdminTest method shouldGetPublicApiPublishedPage.
@Test
public void shouldGetPublicApiPublishedPage() {
reset(apiService, pageService, membershipService, accessControlService);
final ApiEntity apiMock = mock(ApiEntity.class);
when(apiMock.getVisibility()).thenReturn(Visibility.PUBLIC);
when(apiMock.getName()).thenReturn(API_NAME);
doReturn(apiMock).when(apiService).findById(API_NAME);
final PageEntity pageMock = new PageEntity();
pageMock.setPublished(true);
pageMock.setName(PAGE_NAME);
when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
doReturn(pageMock).when(pageService).findById(PAGE_NAME, null);
doReturn(true).when(accessControlService).canAccessPageFromConsole(apiMock, pageMock);
final Response response = envTarget().request().get();
assertEquals(OK_200, response.getStatus());
final PageEntity responsePage = response.readEntity(PageEntity.class);
assertNotNull(responsePage);
assertEquals(PAGE_NAME, responsePage.getName());
verify(membershipService, never()).getRoles(any(), any(), any(), any());
verify(apiService, times(1)).findById(API_NAME);
verify(pageService, times(1)).findById(PAGE_NAME, null);
}
use of io.gravitee.rest.api.model.PageEntity 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.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_FindByIdTest method shouldFindById.
@Test
public void shouldFindById() throws TechnicalException {
when(translationPage.getId()).thenReturn(TRANSLATION_ID);
when(translationPage.getOrder()).thenReturn(1);
when(translationPage.getParentId()).thenReturn(PAGE_ID);
when(translationPage.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
when(translationPage.getReferenceId()).thenReturn("envId");
when(translationPage.getVisibility()).thenReturn("PUBLIC");
Map<String, String> conf = new HashMap<>();
conf.put(PageConfigurationKeys.TRANSLATION_LANG, "FR");
when(translationPage.getConfiguration()).thenReturn(conf);
when(page1.getId()).thenReturn(PAGE_ID);
when(page1.getType()).thenReturn(PageType.MARKDOWN.name());
when(page1.getOrder()).thenReturn(1);
when(page1.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
when(page1.getReferenceId()).thenReturn("envId");
when(page1.getVisibility()).thenReturn("PUBLIC");
when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page1));
when(pageRepository.search(argThat(p -> "TRANSLATION".equals(p.getType()) && PAGE_ID.equals(p.getParent())))).thenReturn(Arrays.asList(translationPage));
final PageRevisionEntity pageRevision = new PageRevisionEntity();
pageRevision.setRevision(5);
pageRevision.setPageId(PAGE_ID);
when(pageRevisionService.findLastByPageId(PAGE_ID)).thenReturn(Optional.of(pageRevision));
final PageEntity pageEntity = pageService.findById(PAGE_ID);
assertNotNull(pageEntity);
assertEquals(1, pageEntity.getOrder());
assertEquals(PAGE_ID, pageEntity.getId());
List<PageEntity> translations = pageEntity.getTranslations();
assertNotNull(translations);
assertEquals(1, translations.size());
PageEntity oneTranslation = translations.get(0);
assertNotNull(oneTranslation);
assertEquals(TRANSLATION_ID, oneTranslation.getId());
assertNotNull(pageEntity.getContentRevisionId());
assertEquals(PAGE_ID, pageEntity.getContentRevisionId().getPageId());
assertEquals(5, pageEntity.getContentRevisionId().getRevision());
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PlanService_UpdateTest method shouldNotUpdate_withNotPublished_GCUPage.
private void shouldNotUpdate_withNotPublished_GCUPage(Plan.Status planStatus) throws TechnicalException {
final String PAGE_ID = "PAGE_ID_TEST";
when(plan.getStatus()).thenReturn(planStatus);
when(plan.getType()).thenReturn(Plan.PlanType.API);
when(plan.getSecurity()).thenReturn(Plan.PlanSecurityType.API_KEY);
when(plan.getApi()).thenReturn(API_ID);
when(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
when(parameterService.findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT))).thenReturn(true);
UpdatePlanEntity updatePlan = mock(UpdatePlanEntity.class);
when(updatePlan.getId()).thenReturn(PLAN_ID);
when(updatePlan.getName()).thenReturn("NameUpdated");
when(updatePlan.getGeneralConditions()).thenReturn(PAGE_ID);
PageEntity unpublishedPage = new PageEntity();
unpublishedPage.setId(PAGE_ID);
unpublishedPage.setOrder(1);
unpublishedPage.setType("MARKDOWN");
unpublishedPage.setPublished(false);
doReturn(unpublishedPage).when(pageService).findById(PAGE_ID);
planService.update(updatePlan);
}
Aggregations