Search in sources :

Example 6 with ComponentEntity

use of org.apache.nifi.web.api.entity.ComponentEntity in project nifi by apache.

the class SnippetResource method deleteSnippet.

/**
 * Removes the specified snippet.
 *
 * @param httpServletRequest request
 * @param snippetId          The id of the snippet to remove.
 * @return A entity containing the client id and an updated revision.
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes the components in a snippet and discards the snippet", response = SnippetEntity.class, authorizations = { @Authorization(value = "Write - /{component-type}/{uuid} - For each component in the Snippet and their descendant components"), @Authorization(value = "Write - Parent Process Group - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response deleteSnippet(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The snippet id.", required = true) @PathParam("id") final String snippetId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }
    final ComponentEntity requestEntity = new ComponentEntity();
    requestEntity.setId(snippetId);
    // get the revision from this snippet
    final Set<Revision> requestRevisions = serviceFacade.getRevisionsFromSnippet(snippetId);
    return withWriteLock(serviceFacade, requestEntity, requestRevisions, lookup -> {
        // ensure write permission to every component in the snippet excluding referenced services
        final SnippetAuthorizable snippet = lookup.getSnippet(snippetId);
        authorizeSnippet(snippet, authorizer, lookup, RequestAction.WRITE, true, false);
        // ensure write permission to the parent process group
        snippet.getParentProcessGroup().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyDeleteSnippet(snippetId, requestRevisions.stream().map(rev -> rev.getComponentId()).collect(Collectors.toSet())), (revisions, entity) -> {
        // delete the specified snippet
        final SnippetEntity snippetEntity = serviceFacade.deleteSnippet(revisions, entity.getId());
        return generateOkResponse(snippetEntity).build();
    });
}
Also used : PathParam(javax.ws.rs.PathParam) Revision(org.apache.nifi.web.Revision) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) ApiResponses(io.swagger.annotations.ApiResponses) HttpMethod(javax.ws.rs.HttpMethod) ApiOperation(io.swagger.annotations.ApiOperation) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Api(io.swagger.annotations.Api) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AuthorizableLookup(org.apache.nifi.authorization.AuthorizableLookup) RequestAction(org.apache.nifi.authorization.RequestAction) Set(java.util.Set) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) Authorizer(org.apache.nifi.authorization.Authorizer) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) PUT(javax.ws.rs.PUT) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) Authorization(io.swagger.annotations.Authorization) Revision(org.apache.nifi.web.Revision) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ComponentEntity (org.apache.nifi.web.api.entity.ComponentEntity)6 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 DELETE (javax.ws.rs.DELETE)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 PUT (javax.ws.rs.PUT)2 MediaType (javax.ws.rs.core.MediaType)2 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 Authorization (io.swagger.annotations.Authorization)1 IOException (java.io.IOException)1