From c7ecaba234ced2de4985fca1a4e653462d7bb590 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 6 Apr 2017 09:27:25 -0400 Subject: [PATCH] NIFI-3509 Fixed ID duplication Fixed the possibility of duplicated MSB part of the component during template creation. This closes #1651 --- .../nifi/web/api/dto/FlowSnippetDTO.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) 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 536c412e8b..1328bfde52 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 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();