Example usage for java.util UUID nameUUIDFromBytes

List of usage examples for java.util UUID nameUUIDFromBytes

Introduction

In this page you can find the example usage for java.util UUID nameUUIDFromBytes.

Prototype

public static UUID nameUUIDFromBytes(byte[] name) 

Source Link

Document

Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.

Usage

From source file:com.feedzai.fos.impl.dummy.DummyManager.java

@Override
public UUID addModel(ModelConfig config, Model model) {
    try {/*from   w  ww.jav  a  2s  . com*/
        logger.trace("config='{}', model='{}'", mapper.writeValueAsString(config),
                mapper.writeValueAsString(model));
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return UUID.nameUUIDFromBytes(new byte[0]);
}

From source file:com.brainasylum.andruid.UniqueIdentifierManager.java

public synchronized UUID getUdid(Context context) {
    if (_udid == null) {
        // we are using the shared-preferences as a "cache" to
        // store the current UDID. This value doesn't persist
        // across application uninstall, so we fall back to the
        // external storage.
        // we (re)serialized always in order to keep the
        // preferences and external storage synched.
        if ((_udid = getPreferencesUdid(context)) != null) {
            Log.d(TAG, "UDID from preferences: " + _udid);
        } else if ((_udid = getSdCardUdid(context)) != null) {
            Log.d(TAG, "UDID from sd-card: " + _udid);
        }/*from w  ww  .ja  v a 2s  .  com*/
        if ((_udid = _identifier.getId(context)) != null) {
            Log.d(TAG, "UDID from instance: " + _udid);
        } else {
            _udid = getGeneratedUdid();
            Log.d(TAG, "UDID auto-generated: " + _udid);
        }
        serializeUdid(context, _udid);
        Log.d(TAG, "UDID serialized");
    }
    try {
        return UUID.nameUUIDFromBytes(_udid.getBytes("utf8"));
    } catch (UnsupportedEncodingException e) {
        clearUdid(context);
        return null;
    }
}

From source file:com.ngdata.sep.impl.SepModelImpl.java

@Override
public boolean addSubscriptionSilent(String name) throws InterruptedException, KeeperException, IOException {
    ReplicationAdmin replicationAdmin = new ReplicationAdmin(hbaseConf);
    try {//  w  w w. j a v  a  2s  . c o m
        String internalName = toInternalSubscriptionName(name);
        if (replicationAdmin.listPeers().containsKey(internalName)) {
            return false;
        }

        String basePath = baseZkPath + "/" + internalName;
        UUID uuid = UUID.nameUUIDFromBytes(Bytes.toBytes(internalName)); // always gives the same uuid for the same name
        ZkUtil.createPath(zk, basePath + "/hbaseid", Bytes.toBytes(uuid.toString()));
        ZkUtil.createPath(zk, basePath + "/rs");

        try {
            replicationAdmin.addPeer(internalName, zkQuorumString + ":" + zkClientPort + ":" + basePath);
        } catch (IllegalArgumentException e) {
            if (e.getMessage().equals("Cannot add existing peer")) {
                return false;
            }
            throw e;
        } catch (Exception e) {
            // HBase 0.95+ throws at least one extra exception: ReplicationException which we convert into IOException
            if (e instanceof InterruptedException) {
                throw (InterruptedException) e;
            } else if (e instanceof KeeperException) {
                throw (KeeperException) e;
            } else {
                throw new IOException(e);
            }
        }

        return true;
    } finally {
        Closer.close(replicationAdmin);
    }
}

From source file:com.cloud.hypervisor.xen.resource.Xenserver625StorageProcessor.java

protected boolean mountNfs(Connection conn, String remoteDir, String localDir) {
    if (localDir == null) {
        localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(remoteDir.getBytes());
    }//from  w ww.j a  v  a2 s .co m
    String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-storage",
            "mountNfsSecondaryStorage", 100 * 1000, "localDir", localDir, "remoteDir", remoteDir);
    if (results == null || results.isEmpty()) {
        String errMsg = "Could not mount secondary storage " + remoteDir + " on host " + localDir;
        s_logger.warn(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    return true;
}

From source file:com.feedzai.fos.impl.dummy.DummyManager.java

@Override
public UUID addModel(ModelConfig config, ModelDescriptor descriptor) {
    try {/*w w w.ja  v a  2 s  .c  om*/
        logger.trace("config='{}', model='{}'", mapper.writeValueAsString(config),
                mapper.writeValueAsString(descriptor.getModelFilePath()));
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return UUID.nameUUIDFromBytes(new byte[0]);
}

From source file:org.openmrs.util.databasechange.CreateCodedOrderFrequencyForDrugOrderFrequencyChangeset.java

private void insertUniqueFrequencies(JdbcConnection connection, Set<String> uniqueFrequencies)
        throws CustomChangeException, SQLException, DatabaseException {
    PreparedStatement insertOrderFrequencyStatement = null;
    Boolean autoCommit = null;/*from  ww w  . ja  v a  2s  .c  o m*/
    try {
        autoCommit = connection.getAutoCommit();
        connection.setAutoCommit(false);
        insertOrderFrequencyStatement = connection.prepareStatement("insert into order_frequency "
                + "(concept_id, creator, date_created, retired, uuid) values (?, ?, ?, ?, ?)");

        Date date = new Date(new java.util.Date().getTime());

        for (String frequency : uniqueFrequencies) {
            if (StringUtils.isBlank(frequency)) {
                continue;
            }

            Integer conceptIdForFrequency = UpgradeUtil.getConceptIdForUnits(frequency);
            if (conceptIdForFrequency == null) {
                throw new CustomChangeException("No concept mapping found for frequency: " + frequency);
            }

            Integer orderFrequencyId = UpgradeUtil.getOrderFrequencyIdForConceptId(
                    connection.getUnderlyingConnection(), conceptIdForFrequency);
            if (orderFrequencyId != null) {
                //a single concept is mapped to more than one text or there is an order frequency already
                continue;
            }

            //Generating UUID for order frequency. Generated UUIDs will be the same if concepts UUIDs are the same.
            String uuid = UpgradeUtil.getConceptUuid(connection.getUnderlyingConnection(),
                    conceptIdForFrequency);
            uuid += "-6925ebb0-7c69-11e3-baa7-0800200c9a66"; //Adding random value for order frequency
            uuid = UUID.nameUUIDFromBytes(uuid.getBytes()).toString();

            insertOrderFrequencyStatement.setInt(1, conceptIdForFrequency);
            insertOrderFrequencyStatement.setInt(2, 1);
            insertOrderFrequencyStatement.setDate(3, date);
            insertOrderFrequencyStatement.setBoolean(4, false);
            insertOrderFrequencyStatement.setString(5, uuid);

            insertOrderFrequencyStatement.executeUpdate();
            insertOrderFrequencyStatement.clearParameters();
        }
        connection.commit();
    } catch (DatabaseException e) {
        handleError(connection, e);
    } catch (SQLException e) {
        handleError(connection, e);
    } finally {
        if (autoCommit != null) {
            connection.setAutoCommit(autoCommit);
        }
        if (insertOrderFrequencyStatement != null) {
            insertOrderFrequencyStatement.close();
        }
    }
}

From source file:au.org.ala.biocache.dao.JsonPersistentQueueDAOImpl.java

/**
 * @see au.org.ala.biocache.dao.PersistentQueueDAO#getNextDownload()
 */// ww w  . j av a2s.c o  m
@Override
public DownloadDetailsDTO getNextDownload() {
    if (offlineDownloadList.size() > 0) {
        for (DownloadDetailsDTO dd : offlineDownloadList) {
            if (dd.getFileLocation() == null) {
                //give a place for the downlaod
                dd.setFileLocation(downloadDirectory + File.separator
                        + UUID.nameUUIDFromBytes(dd.getEmail().getBytes()) + File.separator + dd.getStartTime()
                        + File.separator + dd.getRequestParams().getFile() + ".zip");
                return dd;
            }
        }
    }

    //if we reached here all of the downloads have started or there are no downloads on the list
    return null;
}

From source file:org.openmrs.module.metadatasharing.converter.ConceptMap19Converter.java

@Override
public void convert(Document doc, Version fromVersion, Version toVersion, ConverterContext context)
        throws SerializationException {
    if (fromVersion.compareTo(new Version("1.9")) >= 0 || toVersion.compareTo(new Version("1.9")) < 0) {
        return;/*w ww  .ja  v  a2  s.  c o  m*/
    }

    Map<String, Element> mapTypeElements = new HashMap<String, Element>();

    NodeList maps = doc.getElementsByTagName("org.openmrs.ConceptMap");
    for (int i = 0; i < maps.getLength(); i++) {
        Node map = maps.item(i);

        Element commentElement = getChildElement(map, "comment");
        if (commentElement == null) {
            continue;
        }

        map.removeChild(commentElement);

        String mapTypeName = getMapTypeName(commentElement);

        if (mapTypeName == null) {
            continue;
        }

        Element mapTypeElement = mapTypeElements.get(mapTypeName);

        if (mapTypeElement == null) {
            ConceptMapType mapType = Context.getConceptService().getConceptMapTypeByName(mapTypeName);

            if (mapType == null) {
                continue;
            }

            mapTypeElement = newElement(doc, "conceptMapType", mapType, context);
            mapTypeElements.put(mapTypeName, mapTypeElement);

            map.appendChild(mapTypeElement);
        } else {
            Element reference = doc.createElement("conceptMapTye");
            newReferenced(reference, mapTypeElement);
            map.appendChild(reference);
        }
    }

    Map<String, Element> referenceTermElements = new HashMap<String, Element>();

    for (int i = 0; i < maps.getLength(); i++) {
        Node map = maps.item(i);
        Element source = getChildElement(map, "source");
        map.removeChild(source);
        Element referencedSource = (Element) reference(source, context);

        Element sourceCode = getChildElement(map, "sourceCode");
        map.removeChild(sourceCode);

        //ConceptReferenceTerms are the same if source and sourceCode are the same
        String key = referencedSource.getAttribute("uuid") + sourceCode.getTextContent();

        Element referenceTermElement = referenceTermElements.get(key);

        if (referenceTermElement == null) {
            ConceptReferenceTerm referenceTerm = new ConceptReferenceTerm();
            String uuid = UUID.nameUUIDFromBytes(((Element) map).getAttribute("uuid").getBytes()).toString();
            referenceTerm.setUuid(uuid);
            referenceTerm.setCode(sourceCode.getTextContent());
            referenceTermElement = newElement(doc, "conceptReferenceTerm", referenceTerm, context);
            source = (Element) source.cloneNode(true);
            source = (Element) doc.renameNode(source, "", "conceptSource");
            referenceTermElement.appendChild(source);

            referenceTermElements.put(key, referenceTermElement);
            map.appendChild(referenceTermElement);
        } else {
            Element reference = doc.createElement("conceptReferenceTerm");
            newReferenced(reference, referenceTermElement);
            map.appendChild(reference);
        }
    }
}

From source file:org.eclipse.buckminster.p2.remote.client.RemoteRepositoryFactory.java

protected File getCacheLocation(URI location) {
    File cacheArea = new File(org.eclipse.buckminster.p2.remote.Activator.getAgentLocation(), "cache");
    cacheArea.mkdir();/*  w w  w.ja  va2  s  .c o m*/
    UUID uuid;
    try {
        uuid = UUID.nameUUIDFromBytes(location.toASCIIString().getBytes("US-ASCII"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    return new File(cacheArea, uuid.toString());
}

From source file:com.cloud.hypervisor.xenserver.resource.Xenserver625StorageProcessor.java

protected boolean mountNfs(final Connection conn, final String remoteDir, String localDir) {
    if (localDir == null) {
        localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(remoteDir.getBytes());
    }//from  w  ww.j  a va 2s. c  o  m

    final String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-storage",
            "mountNfsSecondaryStorage", 100 * 1000, "localDir", localDir, "remoteDir", remoteDir);

    if (results == null || results.isEmpty()) {
        final String errMsg = "Could not mount secondary storage " + remoteDir + " on host " + localDir;

        s_logger.warn(errMsg);

        throw new CloudRuntimeException(errMsg);
    }

    return true;
}