Search in sources :

Example 1 with UpdatePageEntity

use of io.gravitee.rest.api.model.UpdatePageEntity 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 UpdatePageEntity

use of io.gravitee.rest.api.model.UpdatePageEntity 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 UpdatePageEntity

use of io.gravitee.rest.api.model.UpdatePageEntity 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 UpdatePageEntity

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

the class PortalPagesResourceAdminTest method shouldNotUpdateSystemFolder.

@Test
public void shouldNotUpdateSystemFolder() {
    reset(apiService, pageService, membershipService);
    final PageEntity pageMock = new PageEntity();
    pageMock.setType("SYSTEM_FOLDER");
    doReturn(pageMock).when(pageService).findById(PAGE_NAME);
    final Response response = envTarget(PAGE_NAME).request().put(Entity.json(new UpdatePageEntity()));
    assertEquals(BAD_REQUEST_400, response.getStatus());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) NewPageEntity(io.gravitee.rest.api.model.NewPageEntity) Response(javax.ws.rs.core.Response) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) Test(org.junit.Test)

Example 5 with UpdatePageEntity

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

the class PortalPagesResourceAdminTest method shouldNotUpdatePatchSystemFolder.

@Test
public void shouldNotUpdatePatchSystemFolder() {
    reset(apiService, pageService, membershipService);
    final PageEntity pageMock = new PageEntity();
    pageMock.setType("SYSTEM_FOLDER");
    doReturn(pageMock).when(pageService).findById(PAGE_NAME);
    final Response response = envTarget(PAGE_NAME).request().method(javax.ws.rs.HttpMethod.PATCH, Entity.json(new UpdatePageEntity()));
    assertEquals(BAD_REQUEST_400, response.getStatus());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) NewPageEntity(io.gravitee.rest.api.model.NewPageEntity) Response(javax.ws.rs.core.Response) UpdatePageEntity(io.gravitee.rest.api.model.UpdatePageEntity) Test(org.junit.Test)

Aggregations

PageEntity (io.gravitee.rest.api.model.PageEntity)5 UpdatePageEntity (io.gravitee.rest.api.model.UpdatePageEntity)5 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)3 NewPageEntity (io.gravitee.rest.api.model.NewPageEntity)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2