Search in sources :

Example 46 with PageEntity

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();
    }
}
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 47 with PageEntity

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);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 48 with PageEntity

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());
}
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 49 with PageEntity

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());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) InjectMocks(org.mockito.InjectMocks) PageServiceImpl(io.gravitee.rest.api.service.impl.PageServiceImpl) java.util(java.util) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) PageType(io.gravitee.rest.api.model.PageType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Mock(org.mockito.Mock) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity) PageReferenceType(io.gravitee.repository.management.model.PageReferenceType) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Page(io.gravitee.repository.management.model.Page) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) PageRepository(io.gravitee.repository.management.api.PageRepository) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) PageConfigurationKeys(io.gravitee.rest.api.model.PageConfigurationKeys) PageEntity(io.gravitee.rest.api.model.PageEntity) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity) Test(org.junit.Test)

Example 50 with PageEntity

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);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePlanEntity(io.gravitee.rest.api.model.UpdatePlanEntity)

Aggregations

PageEntity (io.gravitee.rest.api.model.PageEntity)67 Test (org.junit.Test)48 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)15 OAIDescriptor (io.gravitee.rest.api.service.swagger.OAIDescriptor)15 Page (io.gravitee.rest.api.portal.rest.model.Page)13 Response (javax.ws.rs.core.Response)13 UpdatePageEntity (io.gravitee.rest.api.model.UpdatePageEntity)9 PageConfigurationOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)6 EntrypointsOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer)6 SwaggerDescriptor (io.gravitee.rest.api.service.swagger.SwaggerDescriptor)5 Before (org.junit.Before)5 Page (io.gravitee.repository.management.model.Page)4 NewPageEntity (io.gravitee.rest.api.model.NewPageEntity)4 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)4 ArgumentMatchers (org.mockito.ArgumentMatchers)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 PageRepository (io.gravitee.repository.management.api.PageRepository)3 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)3