@Test public void validateWithSameSeedSameInceptionIdNotSameInstanceIdIsCopyNotSet() throws Exception { Method generateIdMethod = SnippetUtils.class.getDeclaredMethod("generateId", String.class, String.class, boolean.class); generateIdMethod.setAccessible(true); SnippetUtils utils = new SnippetUtils(); String seed = ComponentIdGenerator.generateId().toString(); UUID rootId = ComponentIdGenerator.generateId(); String id1 = (String) generateIdMethod.invoke(utils, new UUID(rootId.getMostSignificantBits(), ComponentIdGenerator.generateId().getLeastSignificantBits()).toString(), seed, false); String id2 = (String) generateIdMethod.invoke(utils, new UUID(rootId.getMostSignificantBits(), ComponentIdGenerator.generateId().getLeastSignificantBits()).toString(), seed, false); String id3 = (String) generateIdMethod.invoke(utils, new UUID(rootId.getMostSignificantBits(), ComponentIdGenerator.generateId().getLeastSignificantBits()).toString(), seed, false); assertNotEquals(id1, id2); assertNotEquals(id2, id3); UUID uuid1 = UUID.fromString(id1); UUID uuid2 = UUID.fromString(id2); UUID uuid3 = UUID.fromString(id3); uuid1.timestamp(); uuid2.timestamp(); uuid3.timestamp(); assertEquals(uuid1.getMostSignificantBits(), uuid2.getMostSignificantBits()); assertEquals(uuid2.getMostSignificantBits(), uuid3.getMostSignificantBits()); }
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);  }