Repository: nifi-registry
Updated Branches:
  refs/heads/master e8ff47d7d -> c6aaca673


NIFIREG-135 Fix versionCount for createFlowVersion result

This closes 98.

Signed-off-by: Bryan Bende <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi-registry/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-registry/commit/c6aaca67
Tree: http://git-wip-us.apache.org/repos/asf/nifi-registry/tree/c6aaca67
Diff: http://git-wip-us.apache.org/repos/asf/nifi-registry/diff/c6aaca67

Branch: refs/heads/master
Commit: c6aaca673f7a4100ea3fc4ef7fe5239db25fa522
Parents: e8ff47d
Author: Kevin Doran <[email protected]>
Authored: Thu Feb 1 16:00:20 2018 -0500
Committer: Bryan Bende <[email protected]>
Committed: Fri Mar 9 11:15:00 2018 -0500

----------------------------------------------------------------------
 .../apache/nifi/registry/service/RegistryService.java  | 13 ++++++++++---
 .../nifi/registry/service/TestRegistryService.java     |  7 ++++---
 .../java/org/apache/nifi/registry/web/api/FlowsIT.java |  1 +
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/c6aaca67/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/RegistryService.java
----------------------------------------------------------------------
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 802121e..acc37be 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
@@ -565,8 +565,8 @@ public class RegistryService {
                 throw new ResourceNotFoundException("The specified bucket ID 
does not exist in this registry.");
             }
 
-            // 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) {
                 LOGGER.warn("The specified flow id [{}] does not exist.", 
snapshotMetadata.getFlowIdentifier());
 
@@ -617,8 +617,15 @@ public class RegistryService {
             // 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();

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/c6aaca67/nifi-registry-framework/src/test/java/org/apache/nifi/registry/service/TestRegistryService.java
----------------------------------------------------------------------
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 f593518..9b759d2 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 class TestRegistryService {
         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 class TestRegistryService {
         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 class TestRegistryService {
         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 class TestRegistryService {
         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);

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/c6aaca67/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/web/api/FlowsIT.java
----------------------------------------------------------------------
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 1b4fa82..eea6969 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 class FlowsIT extends UnsecuredITBase {
         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

Reply via email to