use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class TestRegistryService method testCreateFlowWithSameName.
@Test(expected = IllegalStateException.class)
public void testCreateFlowWithSameName() {
final BucketEntity existingBucket = new BucketEntity();
existingBucket.setId("b1");
existingBucket.setName("My Bucket");
existingBucket.setDescription("This is my bucket");
existingBucket.setCreated(new Date());
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
// setup a flow with the same name that already exists
final FlowEntity flowWithSameName = new FlowEntity();
flowWithSameName.setId("flow1");
flowWithSameName.setName("Flow 1");
flowWithSameName.setDescription("This is flow 1");
flowWithSameName.setCreated(new Date());
flowWithSameName.setModified(new Date());
when(metadataService.getFlowsByName(existingBucket.getId(), flowWithSameName.getName())).thenReturn(Collections.singletonList(flowWithSameName));
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setName(flowWithSameName.getName());
versionedFlow.setBucketIdentifier("b1");
registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class TestRegistryService method testDeleteFlowWithSnapshots.
@Test
public void testDeleteFlowWithSnapshots() {
final BucketEntity existingBucket = new BucketEntity();
existingBucket.setId("b1");
existingBucket.setName("My Bucket");
existingBucket.setDescription("This is my bucket");
existingBucket.setCreated(new Date());
final FlowEntity flowToDelete = new FlowEntity();
flowToDelete.setId("flow1");
flowToDelete.setName("My Flow");
flowToDelete.setDescription("This is my flow.");
flowToDelete.setCreated(new Date());
flowToDelete.setModified(new Date());
flowToDelete.setBucketId(existingBucket.getId());
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowById(flowToDelete.getId())).thenReturn(flowToDelete);
when(metadataService.getFlowsByName(flowToDelete.getName())).thenReturn(Collections.singletonList(flowToDelete));
final VersionedFlow deletedFlow = registryService.deleteFlow(existingBucket.getId(), flowToDelete.getId());
assertNotNull(deletedFlow);
assertEquals(flowToDelete.getId(), deletedFlow.getIdentifier());
verify(flowPersistenceProvider, times(1)).deleteAllFlowContent(flowToDelete.getBucketId(), flowToDelete.getId());
verify(metadataService, times(1)).deleteFlow(flowToDelete);
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class BucketFlowResource method getFlow.
@GET
@Path("{flowId}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a flow", response = VersionedFlow.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "read"), @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") }) })
@ApiResponses({ @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400), @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getFlow(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @PathParam("flowId") @ApiParam("The flow identifier") final String flowId) {
authorizeBucketAccess(RequestAction.READ, bucketId);
final VersionedFlow flow = registryService.getFlow(bucketId, flowId);
permissionsService.populateItemPermissions(flow);
linkService.populateFlowLinks(flow);
return Response.status(Response.Status.OK).entity(flow).build();
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class BucketFlowResource method createFlow.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates a flow", notes = "The flow id is created by the server and populated in the returned entity.", response = VersionedFlow.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "write"), @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") }) })
@ApiResponses({ @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400), @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response createFlow(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @ApiParam(value = "The details of the flow to create.", required = true) final VersionedFlow flow) {
authorizeBucketAccess(RequestAction.WRITE, bucketId);
verifyPathParamsMatchBody(bucketId, flow);
final VersionedFlow createdFlow = registryService.createFlow(bucketId, flow);
permissionsService.populateItemPermissions(createdFlow);
linkService.populateFlowLinks(createdFlow);
return Response.status(Response.Status.OK).entity(createdFlow).build();
}
use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.
the class BucketFlowResource method deleteFlow.
@DELETE
@Path("{flowId}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Deletes a flow, including all saved versions of that flow.", response = VersionedFlow.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "delete"), @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") }) })
@ApiResponses({ @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response deleteFlow(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @PathParam("flowId") @ApiParam("The flow identifier") final String flowId) {
authorizeBucketAccess(RequestAction.DELETE, bucketId);
final VersionedFlow deletedFlow = registryService.deleteFlow(bucketId, flowId);
return Response.status(Response.Status.OK).entity(deletedFlow).build();
}
Aggregations