From 9a399d4c36f641337e2002700e970b9fc136cb45 Mon Sep 17 00:00:00 2001 From: Kevin Doran Date: Thu, 1 Feb 2018 16:00:20 -0500 Subject: [PATCH] NIFIREG-135 Fix versionCount for createFlowVersion result --- .../nifi/registry/service/RegistryService.java | 13 ++++++++++--- .../nifi/registry/service/TestRegistryService.java | 7 ++++--- .../org/apache/nifi/registry/web/api/FlowsIT.java | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java index fad517f49..0e953a419 100644 --- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java +++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java @@ -539,8 +539,8 @@ public VersionedFlowSnapshot createFlowSnapshot(final VersionedFlowSnapshot flow throw new ResourceNotFoundException("Bucket does not exist for identifier " + snapshotMetadata.getBucketIdentifier()); } - // ensure the flow exists, we need to use "with counts" here so we can return this is a part of the response - final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(snapshotMetadata.getFlowIdentifier()); + // ensure the flow exists + final FlowEntity existingFlow = metadataService.getFlowById(snapshotMetadata.getFlowIdentifier()); if (existingFlow == null) { throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + snapshotMetadata.getFlowIdentifier()); } @@ -589,8 +589,15 @@ public VersionedFlowSnapshot createFlowSnapshot(final VersionedFlowSnapshot flow // update the modified date on the flow metadataService.updateFlow(existingFlow); + // get the updated flow, we need to use "with counts" here so we can return this is a part of the response + final FlowEntity updatedFlow = metadataService.getFlowByIdWithSnapshotCounts(snapshotMetadata.getFlowIdentifier()); + if (updatedFlow == null) { + throw new ResourceNotFoundException("Versioned flow does not exist for identifier " + snapshotMetadata.getFlowIdentifier()); + } + final VersionedFlow updatedVersionedFlow = DataModelMapper.map(existingBucket, updatedFlow); + flowSnapshot.setBucket(bucket); - flowSnapshot.setFlow(versionedFlow); + flowSnapshot.setFlow(updatedVersionedFlow); return flowSnapshot; } finally { writeLock.unlock(); diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java index f59351815..9b759d2f9 100644 --- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java +++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java @@ -670,7 +670,7 @@ public void testCreateSnapshotVersionAlreadyExists() { existingFlow.setModified(new Date()); existingFlow.setBucketId(existingBucket.getId()); - when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow); + when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow); // make a snapshot that has the same version as the one being created final FlowSnapshotEntity existingSnapshot = new FlowSnapshotEntity(); @@ -715,7 +715,7 @@ public void testCreateSnapshotVersionNotNextVersion() { existingSnapshot.setCreated(new Date()); existingSnapshot.setCreatedBy("test-user"); - when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow); + when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow); // set the version to something that is not the next one-up version snapshot.getSnapshotMetadata().setVersion(100); @@ -743,6 +743,7 @@ public void testCreateFirstSnapshot() { existingFlow.setModified(new Date()); existingFlow.setBucketId(existingBucket.getId()); + when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow); when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow); final VersionedFlowSnapshot createdSnapshot = registryService.createFlowSnapshot(snapshot); @@ -777,7 +778,7 @@ public void testCreateFirstSnapshotWithBadVersion() { existingFlow.setModified(new Date()); existingFlow.setBucketId(existingBucket.getId()); - when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow); + when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow); // set the first version to something other than 1 snapshot.getSnapshotMetadata().setVersion(100); diff --git a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/FlowsIT.java b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/FlowsIT.java index 1b4fa82fc..eea6969d4 100644 --- a/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/FlowsIT.java +++ b/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/FlowsIT.java @@ -356,6 +356,7 @@ public void testCreateFlowVersionGetFlowVersion() throws Exception { assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink()); assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink().getUri()); assertNotNull(createdFlowSnapshot.getFlow()); + assertEquals(1, createdFlowSnapshot.getFlow().getVersionCount()); assertNotNull(createdFlowSnapshot.getBucket()); // And when .../flows/{id}/versions is queried, then the newly created flow snapshot is returned in the list