Example usage for java.util UUID randomUUID

List of usage examples for java.util UUID randomUUID

Introduction

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

Prototype

public static UUID randomUUID() 

Source Link

Document

Static factory to retrieve a type 4 (pseudo randomly generated) UUID.

Usage

From source file:com.images3.data.impl.ShortUUID.java

public static String randomUUID() {
    return new String(Base64.encodeBase64(toByteArray(UUID.randomUUID()), false, true)).toLowerCase();
}

From source file:launcher.workflow.logs.UploadLogsWorkflow.java

public static void begin(final Settings launcherCfg, final String license) {
    WorkflowStep prepare = new WorkflowStep("Preparing to upload logs.", new WorkflowAction() {
        @Override/* w ww  . j  ava2 s.  c o  m*/
        public boolean act() {
            String licenseId = license;
            if (license.isEmpty()) {
                licenseId = "nolicense";
            }
            LogsWorkflowData.LogID = launcherCfg.windowTitle.replaceAll(" ", "") + "--" + licenseId + "--"
                    + UUID.randomUUID();
            LogsWorkflowData.LogsArchive = new File(LogsWorkflowData.LogID + ".zip");
            LogsWorkflowData.Logs = new File(launcherCfg.logsDirectory);

            if (!LogsWorkflowData.Logs.exists()) {
                LaunchLogger.error("No logs were found to upload.");
                return false;
            }
            return true;
        }
    });

    WorkflowStep archive = new WorkflowStep("Archiving the logs directory", new WorkflowAction() {
        @Override
        public boolean act() {
            WorkflowWindowManager.setProgressVisible(true);
            Archive.zipDir(LogsWorkflowData.Logs, LogsWorkflowData.LogsArchive);
            WorkflowWindowManager.setProgressVisible(false);
            return true;
        }
    });

    WorkflowStep upload = new WorkflowStep("Uploading logs archive.", new WorkflowAction() {
        @Override
        public boolean act() throws Exception {
            WorkflowWindowManager.setProgressVisible(true);
            REST.fileUpload(LogsWorkflowData.LogsArchive.getAbsoluteFile(), launcherCfg.logUploadApi);
            WorkflowWindowManager.setProgressVisible(false);
            LaunchLogger.info("Thank you for uploading your logs!");
            LaunchLogger.info("Log ID: " + LogsWorkflowData.LogID);
            return true;
        }
    });

    WorkflowStep cleanup = new WorkflowStep("Cleaning up temporary files.", new WorkflowAction() {
        @Override
        public boolean act() throws Exception {
            FileUtils.forceDelete(LogsWorkflowData.LogsArchive);
            return true;
        }
    });

    prepare.setOnSuccess(archive);
    archive.setOnSuccess(upload);
    upload.setOnSuccess(cleanup);

    prepare.execute();
}

From source file:Main.java

private static void writeInstallationFile(File installation) throws IOException {
    FileOutputStream out = new FileOutputStream(installation);
    String id = UUID.randomUUID().toString();
    out.write(id.getBytes());//  w w w.ja v a  2s  .  com
    out.close();
}

From source file:Main.java

/**
 * Creates an empty node list. Creates an empty document then selects nodes
 * using a random UUID to ensure an empty result.
 *
 * @return an empty Node list//from  ww w .  j a v  a  2s  .c o  m
 */
public static NodeList createEmptyNodeList() {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("Problem creating document", e);
    }
    Document document = builder.newDocument();
    assert document != null;

    final NodeList emptyNodesList = document.getElementsByTagName(UUID.randomUUID().toString());
    return emptyNodesList;
}

From source file:org.opensafety.hishare.model.factories.AuthenticationServerFactory.java

private static String createAuthenticationServerId() {
    return UUID.randomUUID().toString();
}

From source file:com.rdsic.pcm.service.impl.GenericQueryImpl.java

/**
 * Implementation method for operation Select
 *
 * @param req// ww w. j ava 2s.  c om
 * @return
 */
public static SelectQueryRes select(SelectQueryReq req) {
    String key = UUID.randomUUID().toString();
    String opr = "GenericQuery/Select";
    Logger.LogReq(key, opr, req);

    Date now = new Date();
    SelectQueryRes res = new SelectQueryRes();
    if (!Util.validateRequest(req, opr, Constant.FUNCTIONALITY_ACTION.WS_INVOKE, res)) {
        Logger.LogRes(key, opr, res);
        return res;
    }

    try {
        int maxRow = req.getQuery().getMaxRowCount() == null
                ? Configuration.getInt(Constant.CONFIG_KEY.PCM_QUERY_MAX_ROW)
                : req.getQuery().getMaxRowCount();
        String sql = req.getQuery().getSQL();

        List<Object> params = new ArrayList<>();

        if (req.getQuery().getParams() != null) {
            if (req.getQuery().getParams().getDatetimeParam() != null) {
                req.getQuery().getParams().getDatetimeParam().stream().map((p) -> {
                    params.add(p.getName());
                    return p;
                }).forEach((p) -> {
                    params.add(Util.toDate(p.getValue()));
                });
            }

            if (req.getQuery().getParams().getNumericParam() != null) {
                req.getQuery().getParams().getNumericParam().stream().map((p) -> {
                    params.add(p.getName());
                    return p;
                }).forEach((p) -> {
                    params.add(p.getValue());
                });
            }

            if (req.getQuery().getParams().getStringParam() != null) {
                req.getQuery().getParams().getStringParam().stream().map((p) -> {
                    params.add(p.getName());
                    return p;
                }).forEach((p) -> {
                    params.add(p.getValue());
                });
            }
        }
        // execute the query
        List<Map<String, Object>> list = GenericHql.INSTANCE.querySQL(sql, maxRow, params.toArray());

        // this setting for all null object to empty string to advoid item missing in output json
        for (Map<String, Object> m : list) {
            for (String k : m.keySet()) {
                if (m.get(k) == null) {
                    m.put(k, "");
                }
            }
        }
        JSONObject json = new JSONObject();
        json.put("items", list);

        SelectQueryResponseType response = new SelectQueryResponseType();
        response.setRecordCount(list.size());
        response.setJSONData(json.toString());

        res.setDataSet(response);

        res.setStatus(Constant.STATUS_CODE.OK);
    } catch (Exception e) {
        Util.handleException(e, res);
    }

    res.setResponseDateTime(Util.toXmlGregorianCalendar(now));
    Logger.LogRes(key, opr, res);
    return res;

}

From source file:com.eryansky.common.utils.io.FileUtil.java

/**
 * ???? ??,UUID??,??????/* w w  w  .ja v a 2 s. co  m*/
 * 
 * @param fileName
 *            ??+?
 * @return
 */
public static String generateUUIDFileName(String fileName) {

    UUID uuid = UUID.randomUUID();
    String str = fileName;
    System.out.println(str);
    str = uuid.toString() + "." + str.substring(str.lastIndexOf(".") + 1);
    return str;
}

From source file:Test.java

private static void startUpdateThread(int i, final ConcurrentMap<Integer, String> concurrentMap) {
    Thread thread = new Thread(new Runnable() {
        public void run() {
            while (!Thread.interrupted()) {
                Random random = new Random();
                int randomInt = random.nextInt(20);
                concurrentMap.put(randomInt, UUID.randomUUID().toString());
            }//  w  ww.j a v  a  2  s .c  om
        }
    });
    thread.setName("Update Thread " + i);
    updateThreads.add(thread);
    thread.start();
}

From source file:com.impetus.kundera.graphbrowser.IMDBUtils.java

public static String getUniqueId() {
    return UUID.randomUUID().toString();
}

From source file:com.rdsic.pcm.service.impl.ReportImpl.java

/**
 * Implementation method for operation RunDayend
 *
 * @param req//from  www  .  j a  va 2  s. c  om
 * @return
 */
public static DayendRes runDayend(DayendReq req) {
    String key = UUID.randomUUID().toString();
    String opr = "Report/RunDayend";
    Logger.LogReq(key, opr, req);

    Date now = new Date();
    DayendRes res = new DayendRes();
    if (!Util.validateRequest(req, opr, Constant.FUNCTIONALITY_ACTION.WS_INVOKE, res)) {
        Logger.LogRes(key, opr, res);
        return res;
    }

    try {
        String defaultProc = "DAYEND";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String defaultParam = "CURRDT=" + formatter.format(Util.toDate(req.getWorkingDate()));

        String result = execProc(defaultProc, defaultParam);

        res.setStatus(Constant.STATUS_CODE.OK);
        res.setErrorMessage(result);
    } catch (Exception e) {
        Util.handleException(e, res);
    }
    res.setResponseDateTime(Util.toXmlGregorianCalendar(now));
    Logger.LogRes(key, opr, res);
    return res;
}