You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2017/11/14 21:32:30 UTC

[2/6] nifi-registry git commit: NIFIREG-53 Adding author to VersionedFlowSnapshotMetadata and storing in DB as created_by

NIFIREG-53 Adding author to VersionedFlowSnapshotMetadata and storing in DB as created_by


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

Branch: refs/heads/master
Commit: 99067b50d913f99bdb6a1c94585e3f0a024a82f7
Parents: 47345d4
Author: Bryan Bende <bb...@apache.org>
Authored: Mon Nov 13 15:41:48 2017 -0500
Committer: Bryan Bende <bb...@apache.org>
Committed: Tue Nov 14 14:34:50 2017 -0500

----------------------------------------------------------------------
 .../flow/VersionedFlowSnapshotMetadata.java         | 12 ++++++++++++
 .../nifi/registry/db/entity/FlowSnapshotEntity.java | 12 ++++++++++++
 .../nifi/registry/service/DataModelMapper.java      |  2 ++
 .../src/main/resources/db/migration/V1__Initial.sql |  1 +
 .../db/repository/TestFlowSnapshotRepository.java   |  1 +
 .../nifi/registry/service/TestRegistryService.java  |  1 +
 .../src/test/resources/application.properties       | 16 ++++++++++++++--
 .../db/migration/V999999.1__test-setup.sql          | 12 ++++++------
 .../nifi/registry/web/api/BucketFlowResource.java   |  5 +++++
 .../org/apache/nifi/registry/web/api/FlowsIT.java   |  3 +++
 .../src/test/resources/db/FlowsIT.sql               |  8 ++++----
 11 files changed, 61 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java
----------------------------------------------------------------------
diff --git a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java
index 09b51c9..eb4cb07 100644
--- a/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java
+++ b/nifi-registry-data-model/src/main/java/org/apache/nifi/registry/flow/VersionedFlowSnapshotMetadata.java
@@ -52,6 +52,9 @@ public class VersionedFlowSnapshotMetadata extends LinkableEntity implements Com
     @Min(1)
     private long timestamp;
 
+    @NotBlank
+    private String author;
+
     private String comments;
 
 
@@ -118,6 +121,15 @@ public class VersionedFlowSnapshotMetadata extends LinkableEntity implements Com
         this.timestamp = timestamp;
     }
 
+    @ApiModelProperty("The user that created this snapshot of the flow.")
+    public String getAuthor() {
+        return author;
+    }
+
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+
     @ApiModelProperty("The comments provided by the user when creating the snapshot.")
     public String getComments() {
         return comments;

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/entity/FlowSnapshotEntity.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/entity/FlowSnapshotEntity.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/entity/FlowSnapshotEntity.java
index de30845..be0935d 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/entity/FlowSnapshotEntity.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/entity/FlowSnapshotEntity.java
@@ -16,6 +16,7 @@
  */
 package org.apache.nifi.registry.db.entity;
 
+import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
@@ -34,6 +35,9 @@ public class FlowSnapshotEntity {
 
     private Date created;
 
+    @Column(name = "CREATED_BY")
+    private String createdBy;
+
     private String comments;
 
     @ManyToOne(fetch = FetchType.LAZY)
@@ -56,6 +60,14 @@ public class FlowSnapshotEntity {
         this.created = created;
     }
 
+    public String getCreatedBy() {
+        return createdBy;
+    }
+
+    public void setCreatedBy(String createdBy) {
+        this.createdBy = createdBy;
+    }
+
     public String getComments() {
         return comments;
     }

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
index e51f9b8..d0c6cae 100644
--- a/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
+++ b/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/DataModelMapper.java
@@ -115,6 +115,7 @@ public class DataModelMapper {
         flowSnapshotEntity.setId(key);
         flowSnapshotEntity.setComments(versionedFlowSnapshot.getComments());
         flowSnapshotEntity.setCreated(new Date(versionedFlowSnapshot.getTimestamp()));
+        flowSnapshotEntity.setCreatedBy(versionedFlowSnapshot.getAuthor());
         return flowSnapshotEntity;
     }
 
@@ -128,6 +129,7 @@ public class DataModelMapper {
         metadata.setFlowDescription(flowSnapshotEntity.getFlow().getDescription());
         metadata.setComments(flowSnapshotEntity.getComments());
         metadata.setTimestamp(flowSnapshotEntity.getCreated().getTime());
+        metadata.setAuthor(flowSnapshotEntity.getCreatedBy());
         return metadata;
     }
 

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-framework/src/main/resources/db/migration/V1__Initial.sql
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/main/resources/db/migration/V1__Initial.sql b/nifi-registry-framework/src/main/resources/db/migration/V1__Initial.sql
index eb71ae7..a6b4960 100644
--- a/nifi-registry-framework/src/main/resources/db/migration/V1__Initial.sql
+++ b/nifi-registry-framework/src/main/resources/db/migration/V1__Initial.sql
@@ -40,6 +40,7 @@ CREATE TABLE FLOW_SNAPSHOT (
     FLOW_ID VARCHAR2(50) NOT NULL,
     VERSION INT NOT NULL,
     CREATED TIMESTAMP NOT NULL,
+    CREATED_BY VARCHAR2(200) NOT NULL,
     COMMENTS VARCHAR(4096),
     PRIMARY KEY (FLOW_ID, VERSION),
     FOREIGN KEY (FLOW_ID) REFERENCES FLOW(ID)

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
index dcf2236..d2d5985 100644
--- a/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
+++ b/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/repository/TestFlowSnapshotRepository.java
@@ -71,6 +71,7 @@ public class TestFlowSnapshotRepository extends DatabaseBaseTest {
         assertNotNull(flowSnapshot);
         assertEquals(key, flowSnapshot.getId());
         assertNotNull(flowSnapshot.getFlow());
+        assertEquals("user1", flowSnapshot.getCreatedBy());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/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 07bc4a9..e2e75e6 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
@@ -569,6 +569,7 @@ public class TestRegistryService {
         snapshotMetadata.setVersion(1);
         snapshotMetadata.setComments("This is the first snapshot");
         snapshotMetadata.setBucketIdentifier("b1");
+        snapshotMetadata.setAuthor("user1");
 
         final VersionedProcessGroup processGroup = new VersionedProcessGroup();
         processGroup.setIdentifier("pg1");

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-framework/src/test/resources/application.properties
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/resources/application.properties b/nifi-registry-framework/src/test/resources/application.properties
index fb91fb6..5b42515 100644
--- a/nifi-registry-framework/src/test/resources/application.properties
+++ b/nifi-registry-framework/src/test/resources/application.properties
@@ -15,5 +15,17 @@
 
 # Properties for Spring Boot tests
 
-spring.jpa.hibernate.ddl-auto=validate
-spring.jpa.show-sql=true
\ No newline at end of file
+# Properties for Spring Boot integration tests
+# Documentation for commoon Spring Boot application properties can be found at:
+# https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
+
+# These verbose log levels can be enabled locally for dev testing, but disable them in the repo to minimize travis logs.
+#logging.level.org.springframework.core.io.support: DEBUG
+#logging.level.org.springframework.context.annotation: DEBUG
+#logging.level.org.springframework.web: DEBUG
+
+# These properties should match the defaultProperties hardcoded in NiFiRegistryApiApplication.configure()
+spring.jpa.hibernate.ddl-auto = none
+spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
+
+spring.jpa.show-sql = true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-framework/src/test/resources/db/migration/V999999.1__test-setup.sql
----------------------------------------------------------------------
diff --git a/nifi-registry-framework/src/test/resources/db/migration/V999999.1__test-setup.sql b/nifi-registry-framework/src/test/resources/db/migration/V999999.1__test-setup.sql
index 8d9d6fb..6a10a87 100644
--- a/nifi-registry-framework/src/test/resources/db/migration/V999999.1__test-setup.sql
+++ b/nifi-registry-framework/src/test/resources/db/migration/V999999.1__test-setup.sql
@@ -54,14 +54,14 @@ insert into flow (id) values ('3');
 
 -- test data for flow snapshots
 
-insert into flow_snapshot (flow_id, version, created, comments)
-  values ('1', 1, parsedatetime('2017-09-11 12:57:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'This is flow 1 snapshot 1');
+insert into flow_snapshot (flow_id, version, created, created_by, comments)
+  values ('1', 1, parsedatetime('2017-09-11 12:57:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'user1', 'This is flow 1 snapshot 1');
 
-insert into flow_snapshot (flow_id, version, created, comments)
-  values ('1', 2, parsedatetime('2017-09-11 12:58:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'This is flow 1 snapshot 2');
+insert into flow_snapshot (flow_id, version, created, created_by, comments)
+  values ('1', 2, parsedatetime('2017-09-11 12:58:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'user1', 'This is flow 1 snapshot 2');
 
-insert into flow_snapshot (flow_id, version, created, comments)
-  values ('1', 3, parsedatetime('2017-09-11 12:59:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'This is flow 1 snapshot 3');
+insert into flow_snapshot (flow_id, version, created, created_by, comments)
+  values ('1', 3, parsedatetime('2017-09-11 12:59:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'user1', 'This is flow 1 snapshot 3');
 
 
 -- test data for signing keys

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
index f2a419d..1b22a5d 100644
--- a/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
+++ b/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/api/BucketFlowResource.java
@@ -29,6 +29,7 @@ import org.apache.nifi.registry.exception.ResourceNotFoundException;
 import org.apache.nifi.registry.flow.VersionedFlow;
 import org.apache.nifi.registry.flow.VersionedFlowSnapshot;
 import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata;
+import org.apache.nifi.registry.security.authorization.user.NiFiUserUtils;
 import org.apache.nifi.registry.service.AuthorizationService;
 import org.apache.nifi.registry.service.RegistryService;
 import org.apache.nifi.registry.service.QueryParameters;
@@ -265,6 +266,10 @@ public class BucketFlowResource extends AuthorizableApplicationResource {
         authorizeBucketAccess(RequestAction.WRITE, bucketId);
 
         setSnaphotMetadataIfMissing(bucketId, flowId, snapshot);
+
+        final String userIdentity = NiFiUserUtils.getNiFiUserIdentity();
+        snapshot.getSnapshotMetadata().setAuthor(userIdentity);
+
         final VersionedFlowSnapshot createdSnapshot = registryService.createFlowSnapshot(snapshot);
         if (createdSnapshot.getSnapshotMetadata() != null) {
             linkService.populateSnapshotLinks(createdSnapshot.getSnapshotMetadata());

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/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 0a238b2..63d7e58 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
@@ -272,6 +272,7 @@ public class FlowsIT extends UnsecuredITBase {
                 "\"flowName\":\"Flow 1\"," +
                 "\"version\":1," +
                 "\"timestamp\":1505091420000," +
+                "\"createdBy\" : \"user1\"," +
                 "\"comments\":\"This is flow 1 snapshot 1\"," +
                 "\"link\":{\"params\":{\"rel\":\"content\"},\"href\":\"buckets/1/flows/1/versions/1\"}}," +
                 "{\"bucketIdentifier\":\"1\"," +
@@ -279,6 +280,7 @@ public class FlowsIT extends UnsecuredITBase {
                 "\"flowName\":\"Flow 1\"," +
                 "\"version\":2," +
                 "\"timestamp\":1505091480000," +
+                "\"createdBy\" : \"user2\"," +
                 "\"comments\":\"This is flow 1 snapshot 2\"," +
                 "\"link\":{\"params\":{\"rel\":\"content\"},\"href\":\"buckets/1/flows/1/versions/2\"}}]";
 
@@ -346,6 +348,7 @@ public class FlowsIT extends UnsecuredITBase {
 
         assertFlowSnapshotsEqual(flowSnapshot, createdFlowSnapshot, false);
         assertTrue(createdFlowSnapshot.getSnapshotMetadata().getTimestamp() - testStartTime > 0L); // both server and client in same JVM, so there shouldn't be skew
+        assertEquals("anonymous", createdFlowSnapshot.getSnapshotMetadata().getAuthor());
         assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink());
         assertNotNull(createdFlowSnapshot.getSnapshotMetadata().getLink().getUri());
 

http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/99067b50/nifi-registry-web-api/src/test/resources/db/FlowsIT.sql
----------------------------------------------------------------------
diff --git a/nifi-registry-web-api/src/test/resources/db/FlowsIT.sql b/nifi-registry-web-api/src/test/resources/db/FlowsIT.sql
index ba7c865..c36f987 100644
--- a/nifi-registry-web-api/src/test/resources/db/FlowsIT.sql
+++ b/nifi-registry-web-api/src/test/resources/db/FlowsIT.sql
@@ -43,8 +43,8 @@ insert into flow (id) values ('3');
 
 -- test data for flow snapshots
 
-insert into flow_snapshot (flow_id, version, created, comments)
-  values ('1', 1, parsedatetime('2017-09-11 12:57:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'This is flow 1 snapshot 1');
+insert into flow_snapshot (flow_id, version, created, created_by, comments)
+  values ('1', 1, parsedatetime('2017-09-11 12:57:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'user1', 'This is flow 1 snapshot 1');
 
-insert into flow_snapshot (flow_id, version, created, comments)
-  values ('1', 2, parsedatetime('2017-09-11 12:58:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'This is flow 1 snapshot 2');
+insert into flow_snapshot (flow_id, version, created, created_by, comments)
+  values ('1', 2, parsedatetime('2017-09-11 12:58:00.000 UTC', 'yyyy-MM-dd hh:mm:ss.SSS z'), 'user2', 'This is flow 1 snapshot 2');