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 79d94ebc41..33296f894c 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 @@ -21,6 +21,7 @@ import com.wordnik.swagger.annotations.ApiModelProperty; import javax.xml.bind.annotation.XmlType; import java.nio.charset.StandardCharsets; import java.util.Comparator; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; import java.util.Map.Entry; @@ -34,6 +35,8 @@ import java.util.UUID; @XmlType(name = "flowSnippet") public class FlowSnippetDTO { + private static final long LSB = 0; + private Set processGroups = new LinkedHashSet<>(); private Set remoteProcessGroups = new LinkedHashSet<>(); private Set processors = new LinkedHashSet<>(); @@ -45,6 +48,7 @@ public class FlowSnippetDTO { private Set controllerServices = new LinkedHashSet<>(); private final boolean newTemplate; + private Set convertedUuids = new HashSet<>(); public FlowSnippetDTO() { this(false); @@ -200,18 +204,25 @@ public class FlowSnippetDTO { } private long generateMsb(String id) { - UUID temp = UUID.nameUUIDFromBytes(id.getBytes(StandardCharsets.UTF_8)); - long msb = temp.getMostSignificantBits(); - return msb; + final UUID temp; + if (convertedUuids.contains(id)) { + temp = UUID.fromString(id); + } else { + temp = UUID.nameUUIDFromBytes(id.getBytes(StandardCharsets.UTF_8)); + + // record what the converted uuid will be so we do not re-convert a previously converted uuid + convertedUuids.add(new UUID(temp.getMostSignificantBits(), LSB).toString()); + } + return temp.getMostSignificantBits(); } private void removeInstanceIdentifierIfNecessary(Set componentDtos) { if (this.newTemplate) { for (ComponentDTO componentDto : componentDtos) { - UUID id = new UUID(this.generateMsb(componentDto.getId()), 0); + UUID id = new UUID(this.generateMsb(componentDto.getId()), LSB); componentDto.setId(id.toString()); - id = new UUID(this.generateMsb(componentDto.getParentGroupId()), 0); + id = new UUID(this.generateMsb(componentDto.getParentGroupId()), LSB); componentDto.setParentGroupId(id.toString()); if (componentDto instanceof ControllerServiceDTO) { ControllerServiceDTO csDTO = (ControllerServiceDTO) componentDto; @@ -221,7 +232,7 @@ public class FlowSnippetDTO { if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) { String key = entry.getKey(); String value = props.get(key); - id = new UUID(this.generateMsb(value), 0); + id = new UUID(this.generateMsb(value), LSB); props.put(key, id.toString()); } } @@ -233,7 +244,7 @@ public class FlowSnippetDTO { if (entry.getValue().getIdentifiesControllerService() != null && props.get(entry.getKey()) != null) { String key = entry.getKey(); String value = props.get(key); - id = new UUID(this.generateMsb(value), 0); + id = new UUID(this.generateMsb(value), LSB); props.put(key, id.toString()); } } @@ -242,20 +253,20 @@ public class FlowSnippetDTO { ConnectableDTO cdto = connectionDTO.getSource(); if (!cdto.getType().equals("REMOTE_INPUT_PORT") && !cdto.getType().equals("REMOTE_OUTPUT_PORT")) { - id = new UUID(this.generateMsb(cdto.getId()), 0); + id = new UUID(this.generateMsb(cdto.getId()), LSB); cdto.setId(id.toString()); } - id = new UUID(this.generateMsb(cdto.getGroupId()), 0); + id = new UUID(this.generateMsb(cdto.getGroupId()), LSB); cdto.setGroupId(id.toString()); cdto = connectionDTO.getDestination(); if (!cdto.getType().equals("REMOTE_INPUT_PORT") && !cdto.getType().equals("REMOTE_OUTPUT_PORT")) { - id = new UUID(this.generateMsb(cdto.getId()), 0); + id = new UUID(this.generateMsb(cdto.getId()), LSB); cdto.setId(id.toString()); } - id = new UUID(this.generateMsb(cdto.getGroupId()), 0); + id = new UUID(this.generateMsb(cdto.getGroupId()), LSB); cdto.setGroupId(id.toString()); } else if (componentDto instanceof ProcessGroupDTO) { FlowSnippetDTO fsDTO = ((ProcessGroupDTO) componentDto).getContents();