@Test public void validateIdOrdering() throws Exception { UUID seed = ComponentIdGenerator.generateId(); UUID currentId1 = ComponentIdGenerator.generateId(); UUID currentId2 = ComponentIdGenerator.generateId(); UUID currentId3 = ComponentIdGenerator.generateId(); UUID id1 = new UUID(currentId1.getMostSignificantBits(), UUID.nameUUIDFromBytes((currentId1.toString() + seed.toString()).getBytes(StandardCharsets.UTF_8)) .getLeastSignificantBits()); UUID id2 = new UUID(currentId2.getMostSignificantBits(), UUID.nameUUIDFromBytes((currentId2.toString() + seed.toString()).getBytes(StandardCharsets.UTF_8)) .getLeastSignificantBits()); UUID id3 = new UUID(currentId3.getMostSignificantBits(), UUID.nameUUIDFromBytes((currentId3.toString() + seed.toString()).getBytes(StandardCharsets.UTF_8)) .getLeastSignificantBits()); List<UUID> list = new ArrayList<>(); list.add(id2); list.add(id3); list.add(id1); Collections.sort(list); assertEquals(id1, list.get(0)); assertEquals(id2, list.get(1)); assertEquals(id3, list.get(2)); }
private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); } else { uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); }
SnippetUtils { private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); } else { uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); } }
SnippetUtils { private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); } else { uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); }  }
SnippetUtils { private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); } else { uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); }  @SuppressWarnings({"rawtypes", "unchecked"}) FlowSnippetDTO populateFlowSnippet(final Snippet snippet, final boolean recurse, final boolean includeControllerServices, boolean removeInstanceId); FlowSnippetDTO copy(final FlowSnippetDTO snippetContents, final ProcessGroup group, final String idGenerationSeed, boolean isCopy); void rollbackClonedPolicies(final FlowSnippetDTO snippet); void setDtoFactory(final DtoFactory dtoFactory); void setFlowController(final FlowController flowController); void setAccessPolicyDAO(AccessPolicyDAO accessPolicyDAO); }
SnippetUtils { private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); } else { uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); }  @SuppressWarnings({"rawtypes", "unchecked"}) FlowSnippetDTO populateFlowSnippet(final Snippet snippet, final boolean recurse, final boolean includeControllerServices, boolean removeInstanceId); FlowSnippetDTO copy(final FlowSnippetDTO snippetContents, final ProcessGroup group, final String idGenerationSeed, boolean isCopy); void rollbackClonedPolicies(final FlowSnippetDTO snippet); void setDtoFactory(final DtoFactory dtoFactory); void setFlowController(final FlowController flowController); void setAccessPolicyDAO(AccessPolicyDAO accessPolicyDAO);  }