Search in sources :

Example 1 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 2 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)

Example 3 with PageEntity

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

the class ApiPageResource method updatePageContent.

@PUT
@Path("/content")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Put the page's content", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page content successfully updated"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public String updatePageContent(@ApiParam(name = "content", required = true) @Valid @NotNull String content) {
    pageService.findById(page);
    UpdatePageEntity updatePageEntity = new UpdatePageEntity();
    updatePageEntity.setContent(content);
    PageEntity update = pageService.update(page, updatePageEntity, true);
    return update.getContent();
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 4 with PageEntity

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

the class ApiPageResource method deleteApiPage.

@DELETE
@ApiOperation(value = "Delete a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 204, message = "Page successfully deleted"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.DELETE) })
public void deleteApiPage() {
    PageEntity existingPage = pageService.findById(page);
    if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
        throw new PageSystemFolderActionException("Delete");
    } else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
        throw new PageMarkdownTemplateActionException("Delete");
    }
    pageService.delete(page);
}
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 5 with PageEntity

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

the class PortalPageMediaResource method getPortalPageMedia.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieve all media for a Portal page", notes = "User must have the ENVIRONMENT_DOCUMENTATION[READ] permission to use this service")
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_DOCUMENTATION, acls = RolePermissionAction.READ) })
public Response getPortalPageMedia() {
    final PageEntity currentPage = pageService.findById(page);
    List<MediaEntity> pageMedia = mediaService.findAllWithoutContent(currentPage.getAttachedMedia());
    if (pageMedia != null && !pageMedia.isEmpty()) {
        return Response.ok(pageMedia).build();
    }
    return Response.noContent().build();
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) MediaEntity(io.gravitee.rest.api.model.MediaEntity) 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