Search in sources :

Example 26 with PageEntity

use of io.gravitee.rest.api.model.PageEntity 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());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) OK_200(io.gravitee.common.http.HttpStatusCode.OK_200) SecurityContext(javax.ws.rs.core.SecurityContext) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Page(io.gravitee.rest.api.portal.rest.model.Page) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Collections.singletonList(java.util.Collections.singletonList) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Priority(javax.annotation.Priority) Principal(java.security.Principal) Response(javax.ws.rs.core.Response) Visibility(io.gravitee.rest.api.model.Visibility) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) PageEntity(io.gravitee.rest.api.model.PageEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.rest.api.portal.rest.model.Page) Before(org.junit.Before)

Example 27 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class DefaultPageRevisionUpgrader method upgrade.

@Override
public boolean upgrade() {
    if (hasNoRevisions()) {
        logger.info("No page revisions found. Create a default revision based on pages.");
        final int pageSize = 100;
        int pageNumber = 0;
        Page<PageEntity> pagesSubSet = null;
        do {
            Pageable pageable = new PageableImpl(pageNumber, pageSize);
            pagesSubSet = pageService.findAll(pageable);
            if (!pagesSubSet.getContent().isEmpty()) {
                pagesSubSet.getContent().stream().filter(entity -> pageService.shouldHaveRevision(entity.getType())).forEach(entity -> pageRevisionService.create(convert(entity)));
                ++pageNumber;
            }
        } while (!pagesSubSet.getContent().isEmpty());
    }
    return true;
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) PageEntity(io.gravitee.rest.api.model.PageEntity) PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) Upgrader(io.gravitee.rest.api.service.Upgrader) Ordered(org.springframework.core.Ordered) Logger(org.slf4j.Logger) Pageable(io.gravitee.rest.api.model.common.Pageable) Page(io.gravitee.common.data.domain.Page) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Component(org.springframework.stereotype.Component) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) PageService(io.gravitee.rest.api.service.PageService) PageRevisionService(io.gravitee.rest.api.service.PageRevisionService) Pageable(io.gravitee.rest.api.model.common.Pageable)

Example 28 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiPageResource method getPageContentByApiIdAndPageId.

@GET
@Path("content")
@Produces(MediaType.TEXT_PLAIN)
@RequirePortalAuth
public Response getPageContentByApiIdAndPageId(@PathParam("apiId") String apiId, @PathParam("pageId") String pageId) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    if (accessControlService.canAccessApiFromPortal(apiId)) {
        PageEntity pageEntity = pageService.findById(pageId, null);
        if (accessControlService.canAccessPageFromPortal(apiId, pageEntity)) {
            pageService.transformSwagger(pageEntity, apiId);
            return Response.ok(pageEntity.getContent()).build();
        } else {
            throw new UnauthorizedAccessException();
        }
    }
    throw new ApiNotFoundException(apiId);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) UnauthorizedAccessException(io.gravitee.rest.api.service.exceptions.UnauthorizedAccessException) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 29 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiPageResource method updateApiPage.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public PageEntity updateApiPage(@ApiParam(name = "page", required = true) @Valid @NotNull UpdatePageEntity updatePageEntity) {
    PageEntity existingPage = pageService.findById(page);
    if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
        throw new PageSystemFolderActionException("Update");
    } else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
        throw new PageMarkdownTemplateActionException("Update");
    }
    updatePageEntity.setLastContributor(getAuthenticatedUser());
    return pageService.update(page, updatePageEntity);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 30 with PageEntity

use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiPageResource method partialUpdateApiPage.

@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public PageEntity partialUpdateApiPage(@ApiParam(name = "page") UpdatePageEntity updatePageEntity) {
    PageEntity existingPage = pageService.findById(page);
    if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
        throw new PageSystemFolderActionException("Update");
    } else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
        throw new PageMarkdownTemplateActionException("Update");
    }
    updatePageEntity.setLastContributor(getAuthenticatedUser());
    return pageService.update(page, updatePageEntity, true);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

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