Repository: nifi
Updated Branches:
  refs/heads/master 614fa6a6c -> c7ecaba23


NIFI-3509 Fixed ID duplication
Fixed the possibility of duplicated MSB part of the component during template 
creation. This closes #1651


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

Branch: refs/heads/master
Commit: c7ecaba234ced2de4985fca1a4e653462d7bb590
Parents: 614fa6a
Author: Oleg Zhurakousky <[email protected]>
Authored: Thu Apr 6 09:27:25 2017 -0400
Committer: Matt Gilman <[email protected]>
Committed: Thu Apr 6 16:04:27 2017 -0400

----------------------------------------------------------------------
 .../apache/nifi/web/api/dto/FlowSnippetDTO.java | 38 ++++++++++----------
 1 file changed, 18 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/c7ecaba2/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java
index 536c412..1328bfd 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/FlowSnippetDTO.java
@@ -16,6 +16,10 @@
  */
 package org.apache.nifi.web.api.dto;
 
+import com.wordnik.swagger.annotations.ApiModelProperty;
+
+import javax.xml.bind.annotation.XmlType;
+import java.nio.charset.StandardCharsets;
 import java.util.Comparator;
 import java.util.LinkedHashSet;
 import java.util.Map;
@@ -24,10 +28,6 @@ import java.util.Set;
 import java.util.TreeSet;
 import java.util.UUID;
 
-import javax.xml.bind.annotation.XmlType;
-
-import com.wordnik.swagger.annotations.ApiModelProperty;
-
 /**
  * The contents of a flow snippet.
  */
@@ -198,16 +198,20 @@ public class FlowSnippetDTO {
         components.addAll(dtos);
         return components;
     }
+    
+       private long generateMsb(String id) {
+               UUID temp = 
UUID.nameUUIDFromBytes(id.getBytes(StandardCharsets.UTF_8));
+               long msb = temp.getMostSignificantBits();
+               return msb;
+       }
 
     private void removeInstanceIdentifierIfNecessary(Set<? extends 
ComponentDTO> componentDtos) {
         if (this.newTemplate) {
             for (ComponentDTO componentDto : componentDtos) {
-                UUID id = UUID.fromString(componentDto.getId());
-                id = new UUID(id.getMostSignificantBits(), 0);
+                UUID id = new UUID(this.generateMsb(componentDto.getId()), 0);
                 componentDto.setId(id.toString());
 
-                id = UUID.fromString(componentDto.getParentGroupId());
-                id = new UUID(id.getMostSignificantBits(), 0);
+                id = new 
UUID(this.generateMsb(componentDto.getParentGroupId()), 0);
                 componentDto.setParentGroupId(id.toString());
                 if (componentDto instanceof ControllerServiceDTO) {
                     ControllerServiceDTO csDTO = (ControllerServiceDTO) 
componentDto;
@@ -217,8 +221,7 @@ public class FlowSnippetDTO {
                         if (entry.getValue().getIdentifiesControllerService() 
!= null && props.get(entry.getKey()) != null) {
                             String key = entry.getKey();
                             String value = props.get(key);
-                            id = UUID.fromString(value);
-                            id = new UUID(id.getMostSignificantBits(), 0);
+                            id = new UUID(this.generateMsb(value), 0);
                             props.put(key, id.toString());
                         }
                     }
@@ -230,8 +233,7 @@ public class FlowSnippetDTO {
                         if (entry.getValue().getIdentifiesControllerService() 
!= null && props.get(entry.getKey()) != null) {
                             String key = entry.getKey();
                             String value = props.get(key);
-                            id = UUID.fromString(value);
-                            id = new UUID(id.getMostSignificantBits(), 0);
+                            id = new UUID(this.generateMsb(value), 0);
                             props.put(key, id.toString());
                         }
                     }
@@ -240,24 +242,20 @@ public class FlowSnippetDTO {
 
                     ConnectableDTO cdto = connectionDTO.getSource();
                     if (!cdto.getType().equals("REMOTE_INPUT_PORT") && 
!cdto.getType().equals("REMOTE_OUTPUT_PORT")) {
-                        id = UUID.fromString(cdto.getId());
-                        id = new UUID(id.getMostSignificantBits(), 0);
+                       id = new UUID(this.generateMsb(cdto.getId()), 0);
                         cdto.setId(id.toString());
                     }
 
-                    id = UUID.fromString(cdto.getGroupId());
-                    id = new UUID(id.getMostSignificantBits(), 0);
+                    id = new UUID(this.generateMsb(cdto.getGroupId()), 0);
                     cdto.setGroupId(id.toString());
 
                     cdto = connectionDTO.getDestination();
                     if (!cdto.getType().equals("REMOTE_INPUT_PORT") && 
!cdto.getType().equals("REMOTE_OUTPUT_PORT")) {
-                        id = UUID.fromString(cdto.getId());
-                        id = new UUID(id.getMostSignificantBits(), 0);
+                       id = new UUID(this.generateMsb(cdto.getId()), 0);
                         cdto.setId(id.toString());
                     }
 
-                    id = UUID.fromString(cdto.getGroupId());
-                    id = new UUID(id.getMostSignificantBits(), 0);
+                    id = new UUID(this.generateMsb(cdto.getGroupId()), 0);
                     cdto.setGroupId(id.toString());
                 } else if (componentDto instanceof ProcessGroupDTO) {
                     FlowSnippetDTO fsDTO = ((ProcessGroupDTO) 
componentDto).getContents();

Reply via email to