Search in sources :

Example 1 with PageSystemFolderActionException

use of io.gravitee.rest.api.service.exceptions.PageSystemFolderActionException in project gravitee-management-rest-api by gravitee-io.

the class ApiPagesResource method createApiPage.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully created", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.CREATE) })
public Response createApiPage(@ApiParam(name = "page", required = true) @Valid @NotNull NewPageEntity newPageEntity) {
    if (newPageEntity.getType().equals(PageType.SYSTEM_FOLDER)) {
        throw new PageSystemFolderActionException("Create");
    } else if (newPageEntity.getType().equals(PageType.MARKDOWN_TEMPLATE)) {
        throw new PageMarkdownTemplateActionException("Create");
    }
    int order = pageService.findMaxApiPageOrderByApi(api) + 1;
    newPageEntity.setOrder(order);
    newPageEntity.setLastContributor(getAuthenticatedUser());
    PageEntity newPage = pageService.createPage(api, newPageEntity, GraviteeContext.getCurrentEnvironment());
    if (newPage != null) {
        return Response.created(this.getLocationHeader(newPage.getId())).entity(newPage).build();
    }
    return Response.serverError().build();
}
Also used : PageSystemFolderActionException(io.gravitee.rest.api.service.exceptions.PageSystemFolderActionException) PageMarkdownTemplateActionException(io.gravitee.rest.api.service.exceptions.PageMarkdownTemplateActionException) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Aggregations

Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 PageMarkdownTemplateActionException (io.gravitee.rest.api.service.exceptions.PageMarkdownTemplateActionException)1 PageSystemFolderActionException (io.gravitee.rest.api.service.exceptions.PageSystemFolderActionException)1