List of usage examples for java.util UUID nameUUIDFromBytes
public static UUID nameUUIDFromBytes(byte[] name)
From source file:org.usergrid.persistence.cassandra.ConnectionRefImpl.java
public static UUID getId(EntityRef connectingEntity, ConnectedEntityRef connectedEntity, ConnectedEntityRef... pairedConnections) { UUID uuid = null;//w w w .j a v a2 s. co m try { if (connectionsNull(pairedConnections) && connectionsNull(connectedEntity)) { return connectingEntity.getUuid(); } ByteArrayOutputStream byteStream = new ByteArrayOutputStream(16 + (32 * pairedConnections.length)); byteStream.write(uuidToBytesNullOk(connectingEntity.getUuid())); for (ConnectedEntityRef connection : pairedConnections) { String connectionType = connection.getConnectionType(); UUID connectedEntityID = connection.getUuid(); byteStream.write(ascii(StringUtils.lowerCase(connectionType))); byteStream.write(uuidToBytesNullOk(connectedEntityID)); } String connectionType = connectedEntity.getConnectionType(); if (connectionType == null) { connectionType = NULL_ENTITY_TYPE; } UUID connectedEntityID = connectedEntity.getUuid(); byteStream.write(ascii(StringUtils.lowerCase(connectionType))); byteStream.write(uuidToBytesNullOk(connectedEntityID)); byte[] raw_id = byteStream.toByteArray(); // logger.info("raw connection index id: " + // Hex.encodeHexString(raw_id)); uuid = UUID.nameUUIDFromBytes(raw_id); // logger.info("connection index uuid: " + uuid); } catch (IOException e) { logger.error("Unable to create connection UUID", e); } return uuid; }
From source file:org.wso2.carbon.analytics.data.commons.utils.AnalyticsCommonUtils.java
public static String generateRecordIdFromPrimaryKeyValues(Map<String, Object> values, List<String> primaryKeys) { StringBuilder builder = new StringBuilder(); Object obj;/*from w w w .j a v a 2 s . co m*/ for (String key : primaryKeys) { obj = values.get(key); if (obj != null) { builder.append(obj.toString()); } } // to make sure, we don't have an empty string builder.append(""); try { byte[] data = builder.toString().getBytes(AnalyticsCommonConstants.DEFAULT_CHARSET); return UUID.nameUUIDFromBytes(data).toString(); } catch (UnsupportedEncodingException e) { // This wouldn't happen throw new RuntimeException(e); } }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
protected void executeAdapterResultViewer(final AdaptedTableConfig table, final boolean isMap, final AdapterConfig... includeAdapters) { RunMe<Void> runMe = new RunMe<Void>() { @Override//from w w w . jav a2 s.c o m public Void runMe(ExecutionReport report) { // get the id of the adapter containing the table String dsid = ScriptUtils.getAdapterId(script, table); if (dsid == null) { throw new RuntimeException(); } // Take copy of the script and set all unsynced options. // This will avoid problems if part of the script is set to sync incorrectly... Script copy = ScriptIO.instance().deepCopy(script); ScriptUtils.setAllUnsynced(copy); // Remove other instructions from the option which are unneeded (otherwise table may appear twice etc...) // Assume that any instructions in the option containing the target adapter table are unneeded. // This should cover all but some very unusual circumstances... String optionid = ScriptUtils.getOptionIdByAdapterId(copy, dsid); Option option = ScriptUtils.getOption(copy, optionid); option.getInstructions().clear(); // Get adapter ids String[] adapterIds = new String[includeAdapters.length]; for (int i = 0; i < adapterIds.length; i++) { adapterIds[i] = includeAdapters[i].getId(); } // Get the collapsed subset of the script TableId tableId = new TableId(dsid, table.getName()); Script subscript = OptionsSubpath.getSubpathScript(copy, new TableId[] { tableId }, adapterIds, report); if (report.isFailed()) { return null; } if (subscript.getOptions().size() > 0) { // script should now be collapsed... throw new RuntimeException(); } // remove all other tables in the adapter containing the target table as they are definitely not needed AdapterConfig adapterConfig = ScriptUtils.getAdapterById(subscript, dsid, true); Iterator<AdaptedTableConfig> itTable = adapterConfig.getTables().iterator(); while (itTable.hasNext()) { if (Strings.equalsStd(itTable.next().getName(), table.getName()) == false) { itTable.remove(); } } // if we're showing a map then rename all remaining tables (could be multiple for a union) to drawables if (isMap) { for (AdaptedTableConfig tableConfig : adapterConfig.getTables()) { tableConfig.setName(api.standardComponents().map().getDrawableTableDefinition().getName()); } } // treat like a standard adapter, not a VLS adapterConfig.setAdapterType(ScriptAdapterType.NORMAL); // // create a single dummy adapter which just copies the table contents, excluding any sort columns // ScriptOptionImpl builder = new ScriptOptionImpl(api,null, subscript,null); // ScriptAdapter adapter= builder.addDataAdapter("DummyAdapter"); // final String adptId =adapter.getAdapterId(); // ScriptAdapterTable dummyTable = adapter.addEmptyTable(table.getName()); // dummyTable.setSourceTable(dsid, table.getName()); // for(int i =0;i<table.getColumnCount(); i++){ // if(table.getColumn(i).getSortField() == SortField.NO){ // dummyTable.addColumn(table.getColumnName(i), table.getColumnType(i), false, table.getColumnName(i)); // } // } // if(isMap){ // // set table to have "drawables" name // dummyTable.setTableName(api.standardComponents().map().getDrawableTableDefinition().getName()); // } // // add instruction to the end of the script ScriptOptionImpl builder = new ScriptOptionImpl(api, null, subscript, null); builder.addInstruction(adapterConfig.getId(), isMap ? api.standardComponents().map().getId() : api.standardComponents().tableViewer().getId(), ODLComponent.MODE_DEFAULT); // give script a unique id String name = isMap ? "Map data" : "Table result"; UUID uuid = UUID.nameUUIDFromBytes((script.getUuid().toString() + "-" + name).getBytes()); subscript.setUuid(uuid); // finally run the temporary script runner.executeScript(subscript, null, "Result of data adapter table"); return null; } }; // run the runnable! RunProcessWithExecReport.runProcess((JFrame) SwingUtilities.getWindowAncestor(this), runMe); }
From source file:org.usergrid.persistence.cassandra.ConnectionRefImpl.java
public static UUID getIndexId(EntityRef connectingEntity, String connectionType, String connectedEntityType, ConnectedEntityRef... pairedConnections) { UUID uuid = null;/* w ww .j ava 2s. co m*/ try { if (connectionsNull(pairedConnections) && ((connectionType == null) && (connectedEntityType == null))) { return connectingEntity.getUuid(); } ByteArrayOutputStream byteStream = new ByteArrayOutputStream(16 + (32 * pairedConnections.length)); byteStream.write(uuidToBytesNullOk(connectingEntity.getUuid())); for (ConnectedEntityRef connection : pairedConnections) { String type = connection.getConnectionType(); UUID id = connection.getUuid(); byteStream.write(ascii(StringUtils.lowerCase(type))); byteStream.write(uuidToBytesNullOk(id)); } if (connectionType == null) { connectionType = NULL_ENTITY_TYPE; } if (connectedEntityType == null) { connectedEntityType = NULL_ENTITY_TYPE; } byteStream.write(ascii(StringUtils.lowerCase(connectionType))); byteStream.write(ascii(StringUtils.lowerCase(connectedEntityType))); byte[] raw_id = byteStream.toByteArray(); logger.info("raw connection index id: " + Hex.encodeHexString(raw_id)); uuid = UUID.nameUUIDFromBytes(raw_id); logger.info("connection index uuid: " + uuid); } catch (IOException e) { logger.error("Unable to create connection index UUID", e); } return uuid; }
From source file:tigase.hinest.HinestRegister.java
private Element prepareRegistrationForm(final XMPPResourceConnection session) throws NoConnectionIdException { Element query = new Element("query", new String[] { "xmlns" }, XMLNSS); query.addChild(new Element("instructions", "Use the enclosed form to register.")); Form form = new Form(SignatureCalculator.SUPPORTED_TYPE, "Contest Registration", "Please provide the following information to sign up for our special contests!"); form.addField(Field.fieldTextSingle("username", "", "Username")); form.addField(Field.fieldTextPrivate("password", "", "Password")); form.addField(Field.fieldTextSingle("email", "", "Email")); SignatureCalculator sc = new SignatureCalculator(oauthConsumerKey, oauthConsumerSecret); sc.setOauthToken(/*from ww w . ja v a2 s .c o m*/ UUID.nameUUIDFromBytes((session.getConnectionId() + "|" + session.getSessionId()).getBytes()) .toString()); sc.addEmptyFields(form); query.addChild(form.getElement()); return query; }
From source file:com.cloud.hypervisor.kvm.storage.LibvirtStorageAdaptor.java
@Override public KVMStoragePool getStoragePoolByURI(String uri) { URI storageUri = null;// w w w . ja v a2 s .co m try { storageUri = new URI(uri); } catch (URISyntaxException e) { throw new CloudRuntimeException(e.toString()); } String sourcePath = null; String uuid = null; String sourceHost = ""; StoragePoolType protocal = null; if (storageUri.getScheme().equalsIgnoreCase("nfs")) { sourcePath = storageUri.getPath(); sourcePath = sourcePath.replace("//", "/"); sourceHost = storageUri.getHost(); uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString(); protocal = StoragePoolType.NetworkFilesystem; } return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocal); }
From source file:org.opendaylight.genius.itm.impl.ItmUtils.java
public static String getUniqueIdString(String idKey) { return UUID.nameUUIDFromBytes(idKey.getBytes()).toString().substring(0, 12).replace("-", ""); }
From source file:com.collective.celos.ci.mode.test.TestConfigurationParserTest.java
@Test public void testHiveTable() throws IOException { String js = "ci.hiveTable(\"dbname\", \"tablename\")"; TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader(js), "string"); OutputFixTableFromHiveCreator creator = (OutputFixTableFromHiveCreator) creatorObj.unwrap(); TestRun testRun = mock(TestRun.class); doReturn(UUID.nameUUIDFromBytes("fake".getBytes())).when(testRun).getTestUUID(); Assert.assertEquals("Hive table celosci_dbname_144c9def_ac04_369c_bbfa_d8efaa8ea194.tablename", creator.getDescription(testRun)); }
From source file:org.apache.nifi.authorization.FileAuthorizer.java
/** * Finds the User with the given identity, or creates a new one and adds it to the Tenants. * * @param tenants the Tenants reference//from www .ja v a 2s .c om * @param userIdentity the user identity to find or create * @return the User from Tenants with the given identity, or a new instance that was added to Tenants */ private org.apache.nifi.authorization.file.tenants.generated.User getOrCreateUser(final Tenants tenants, final String userIdentity) { if (StringUtils.isBlank(userIdentity)) { return null; } org.apache.nifi.authorization.file.tenants.generated.User foundUser = null; for (org.apache.nifi.authorization.file.tenants.generated.User user : tenants.getUsers().getUser()) { if (user.getIdentity().equals(userIdentity)) { foundUser = user; break; } } if (foundUser == null) { final String userIdentifier = UUID.nameUUIDFromBytes(userIdentity.getBytes(StandardCharsets.UTF_8)) .toString(); foundUser = new org.apache.nifi.authorization.file.tenants.generated.User(); foundUser.setIdentifier(userIdentifier); foundUser.setIdentity(userIdentity); tenants.getUsers().getUser().add(foundUser); } return foundUser; }