public static void main(String[] args) { System.out.println(UUIDUtil.randomUUID().toUpperCase()); }
@Override public String deploymentID() { // In Gentics Mesh we use shortened UUIDs instead of the full Uuids. return UUIDUtil.toShortUuid(super.deploymentID()); }
/** * Create a random UUID string which does not include dashes. * * @return */ public static String randomUUID() { final UUID uuid = UUID_GENERATOR.generate(); return (digits(uuid.getMostSignificantBits() >> 32, 8) + digits(uuid.getMostSignificantBits() >> 16, 4) + digits(uuid.getMostSignificantBits(), 4) + digits(uuid.getLeastSignificantBits() >> 48, 4) + digits(uuid.getLeastSignificantBits(), 12)); }
@Test public void testIsUUID() { String validUUID = "dd5e85cebb7311e49640316caf57479f"; String uuid = UUIDUtil.randomUUID(); System.out.println(uuid); assertTrue("The uuid {" + uuid + "} is not a valid uuid.", UUIDUtil.isUUID(uuid)); assertFalse(UUIDUtil.isUUID("")); assertFalse(UUIDUtil.isUUID("123")); assertFalse(UUIDUtil.isUUID("-1")); assertFalse(UUIDUtil.isUUID("1")); assertFalse(UUIDUtil.isUUID("0")); assertFalse(UUIDUtil.isUUID("/test/1235.html")); assertTrue(UUIDUtil.isUUID(validUUID)); assertFalse(UUIDUtil.isUUID(validUUID.replace("f", "z"))); }
public JsonObjectAssert pathIsUuid(String path, String msg) { if (msg == null) { msg = ""; } String value = JsonPath.read(actual.toString(), path); assertNotNull("Value on path {" + path + "} was null", value); assertTrue("The specified value {" + value + "} on path {" + path + "} was no uuid: " + msg, UUIDUtil.isUUID(value)); return this; }
@Test public void testConversion() { String fullUuid = "8fdfd492-e005-4503-875e-13d73c633b2c"; String shortUuid = UUIDUtil.toShortUuid(fullUuid); assertEquals("8fdfd492e0054503875e13d73c633b2c", shortUuid); assertEquals("8fdfd492e0054503875e13d73c633b2c", UUIDUtil.toShortUuid(shortUuid)); assertEquals(fullUuid, UUIDUtil.toFullUuid(shortUuid)); assertEquals(fullUuid, UUIDUtil.toFullUuid(fullUuid)); } }
if (!UUIDUtil.isUUID(uuid)) { throw error(BAD_REQUEST, "error_illegal_uuid", uuid);
/** * Generate a default configuration with meaningful default settings. The keystore password will be randomly generated and set. * * @return */ private static MeshOptions generateDefaultConfig() { MeshOptions options = new MeshOptions(); options.getAuthenticationOptions().setKeystorePassword(UUIDUtil.randomUUID()); options.setNodeName(MeshNameProvider.getInstance().getRandomName()); return options; }
@Test public void testModel() { ConflictWarning warning = new ConflictWarning(); warning.setNodeUuid(UUIDUtil.randomUUID()); System.out.println(warning.toJson()); JobWarningList warnings = new JobWarningList(); warnings.add(warning); String json = JsonUtil.toJson(warnings); System.out.println(json); JobWarningList remapped = JsonUtil.readValue(json, JobWarningList.class); assertEquals("node-conflict-resolution", remapped.getData().get(0).getType()); } }
@Override public Completable validateCreateViaTemplate(IndexInfo info) { JsonObject json = createIndexSettings(info); if (log.isDebugEnabled()) { log.debug("Validating index configuration {" + json.encodePrettily() + "}"); } String randomName = info.getIndexName() + UUIDUtil.randomUUID(); String templateName = randomName.toLowerCase(); json.put("template", templateName); return client.createIndexTemplate(templateName, json).async() .doOnSuccess(response -> { if (log.isDebugEnabled()) { log.debug("Created template {" + templateName + "} response: {" + response.toString() + "}"); } }).onErrorResumeNext(error -> { if (error instanceof HttpErrorException) { HttpErrorException re = (HttpErrorException) error; JsonObject errorInfo = re.getBodyObject(JsonObject::new); String reason = errorInfo.getJsonObject("error").getString("reason"); return Single.error(error(BAD_REQUEST, "schema_error_index_validation", reason)); } else { return Single.error(error(BAD_REQUEST, "schema_error_index_validation", error.getMessage())); } }).toCompletable() .andThen(client.deleteIndexTemplate(templateName).async().toCompletable()) .compose(withTimeoutAndLog("Template validation", false)); }