Example usage for java.util UUID fromString

List of usage examples for java.util UUID fromString

Introduction

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

Prototype

public static UUID fromString(String name) 

Source Link

Document

Creates a UUID from the string standard representation as described in the #toString method.

Usage

From source file:com.formkiq.core.dao.QueueDaoImpl.java

@Override
public QueueMessage findMessage(final String messageid) {
    return getEntityManager().find(QueueMessage.class, UUID.fromString(messageid));
}

From source file:com.microsoft.alm.plugin.context.ServerContextBuilder.java

public ServerContextBuilder userId(final String userId) {
    try {//  w  w  w . j av  a  2  s . c o m
        this.userId = UUID.fromString(userId);
    } catch (Throwable t) {
        logger.warn("userId: is an invalid UUID", t);
        this.userId = null;
    }
    return this;
}

From source file:com.haulmont.cuba.restapi.RestFileDownloadController.java

@RequestMapping(value = "/api/download", method = RequestMethod.GET)
public ModelAndView download(HttpServletRequest request, HttpServletResponse response) throws IOException {
    UserSession userSession = getSession(request, response);
    if (userSession == null) {
        error(response);//from   www .ja va2  s. c o m
        return null;
    }

    AppContext.setSecurityContext(new SecurityContext(userSession));
    try {
        UUID fileId;
        try {
            fileId = UUID.fromString(request.getParameter("f"));
        } catch (Exception e) {
            log.error(e.toString());
            error(response);
            return null;
        }

        FileDescriptor fd = dataService.load(new LoadContext<>(FileDescriptor.class).setId(fileId));
        if (fd == null) {
            log.warn("Unable to find file with id " + fileId);
            error(response);
            return null;
        }

        String fileName = URLEncodeUtils.encodeUtf8(fd.getName());

        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("Content-Type", getContentType(fd));
        response.setHeader("Pragma", "no-cache");

        boolean attach = Boolean.valueOf(request.getParameter("a"));
        response.setHeader("Content-Disposition",
                (attach ? "attachment" : "inline") + "; filename=" + fileName);

        writeResponse(response, userSession, fd);

    } finally {
        AppContext.setSecurityContext(null);
    }
    return null;
}

From source file:ac.dynam.rundeck.plugin.resources.ovirt.oVirtSDKWrapper.java

public Action startVm(String vmid) {
    try {/* ww w  . j  a va 2s.  co m*/
        VM vm = this.api.getVMs().get(UUID.fromString(vmid));
        return vm.start(new Action());
    } catch (ClientProtocolException e) {
        this.message = "Protocol Exception: " + e.getMessage();
    } catch (ServerException e) {
        this.message = "Server Exception: " + e.getReason() + ": " + e.getDetail();
    } catch (IOException e) {
        this.message = "IOException Exception: " + e.getMessage();
    }
    return null;
}

From source file:org.stockwatcher.web.WatchListController.java

@RequestMapping(value = "/{watchListId}/rss", method = RequestMethod.GET)
public String displayWatchListDetailRss(@PathVariable String watchListId, Model model,
        HttpServletRequest request) {//from w  w w  .j ava2 s.c o  m
    UUID id = UUID.fromString(watchListId);
    model.addAttribute("watchListItems", watchListDAO.getWatchListItems(id));
    WatchList watchList = watchListDAO.getWatchList(id);
    model.addAttribute("watchList", watchList);
    model.addAttribute("user", userDAO.getUser(watchList.getUserId()));
    return "watchList.rss";
}

From source file:eu.dasish.annotation.backend.dao.impl.JdbcCachedRepresentationDaoTest.java

/**
 * Test of getInternalId method, of class JdbcCachedRepresentationDao.
 * public Number getInternalId(UUID externalID);
 *//* w w w  .j a va 2 s  .  c o m*/
@Test
public void testGetInternalId() throws NotInDataBaseException {
    System.out.println("test getInternalID");
    UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000051");
    Number result = jdbcCachedRepresentationDao.getInternalID(externalID);
    assertEquals(1, result.intValue());
}

From source file:com.bskyb.cg.environments.message.MessageHandler.java

public void processMessage(byte[] rawMessage) {

    try {/*from   ww w. j a va  2 s  .c o m*/

        String textMessage = new String(rawMessage);

        logger.info("Raw message :" + textMessage);

        String msgtype = BaseMessageFormat.getMessageType(textMessage, "||");

        MessageFormatFactory messageFormatFactory = (MessageFormatFactory) applicationContext
                .getBean("messageFormatFactory");

        MessageFormat logMessageFormat = messageFormatFactory.getMessageFormat(msgtype);

        Message logMessage = logMessageFormat.parse(rawMessage);

        String key = logMessage.getKey();

        Map<String, String> keyfields = getFields(key);

        String uuid = keyfields.get("uuid");
        String date = keyfields.get("date");
        String hostname = keyfields.get("hostname");
        String epochtime = keyfields.get("epochtime");

        logger.info("UUID :" + uuid);
        logger.info("date :" + date);
        logger.info("hostname :" + hostname);
        logger.info("epochtime :" + epochtime);

        UUID cassandrauuid = UUID.fromString(uuid);
        String syslogMsg = new String(logMessage.getMessage());
        String rowKey = hostname + ":" + date;

        persistentHash.add(key, logMessage);
        cassandraConfigurationBuilder.setMsgType(msgtype);
        MessageDaoFactory messageDaoFactory = new MessageDaoFactory(cassandraConfigurationBuilder);

        MessageDao messageDao = messageDaoFactory.getObject();
        messageDao.insert(cassandrauuid, epochtime, msgtype, syslogMsg, rowKey, hostname);
        persistentHash.remove(key);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

/**
 * @param value/*from   w w w  .  j  a  v  a  2  s  . c  o  m*/
 * @param f
 * @return
 */
public static ByteBuffer toBytes(Object value, Class<?> clazz) {
    if (clazz.isAssignableFrom(String.class)) {
        return UTF8Type.instance.decompose((String) value);
    } else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class)) {
        return Int32Type.instance.decompose(Integer.parseInt(value.toString()));
    } else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class)) {
        return LongType.instance.decompose(Long.parseLong(value.toString()));
    } else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class)) {
        return BooleanType.instance.decompose(Boolean.valueOf(value.toString()));
    } else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class)) {
        return DoubleType.instance.decompose(Double.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(java.util.UUID.class)) {
        return UUIDType.instance.decompose(UUID.fromString(value.toString()));
    } else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class)) {
        return FloatType.instance.decompose(Float.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(Date.class)) {
        DateAccessor dateAccessor = new DateAccessor();
        return DateType.instance.decompose((Date) value);
    } else {
        if (value.getClass().isAssignableFrom(String.class)) {
            value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString());
        }
        return BytesType.instance
                .decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value)));
    }
}

From source file:at.alladin.rmbt.controlServer.TestResultResource.java

@Post("json")
public String request(final String entity) {
    long startTime = System.currentTimeMillis();
    addAllowOrigin();/*from  w w w .ja  v a  2s.  c  om*/

    JSONObject request = null;

    final ErrorList errorList = new ErrorList();
    final JSONObject answer = new JSONObject();
    String answerString;

    final String clientIpRaw = getIP();
    System.out.println(MessageFormat.format(labels.getString("NEW_TESTRESULT"), clientIpRaw));

    if (entity != null && !entity.isEmpty())
        // try parse the string to a JSON object
        try {
            request = new JSONObject(entity);

            String lang = request.optString("language");

            // Load Language Files for Client

            final List<String> langs = Arrays
                    .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

            if (langs.contains(lang)) {
                errorList.setLanguage(lang);
                labels = ResourceManager.getSysMsgBundle(new Locale(lang));
            } else
                lang = settings.getString("RMBT_DEFAULT_LANGUAGE");

            //                System.out.println(request.toString(4));

            if (conn != null) {
                final Client client = new Client(conn);
                final Test test = new Test(conn);

                final String testUuid = request.optString("test_uuid");
                if (testUuid != null && test.getTestByUuid(UUID.fromString(testUuid)) > 0
                        && client.getClientByUid(test.getField("client_id").intValue())
                        && "FINISHED".equals(test.getField("status").toString())) {

                    final Locale locale = new Locale(lang);
                    final Format format = new SignificantFormat(2, locale);

                    final JSONArray resultList = new JSONArray();

                    final JSONObject jsonItem = new JSONObject();

                    JSONArray jsonItemList = new JSONArray();

                    // RMBTClient Info
                    //also send open-uuid (starts with 'P')
                    final String openUUID = "P" + ((UUIDField) test.getField("open_uuid")).toString();
                    jsonItem.put("open_uuid", openUUID);

                    //and open test-uuid (starts with 'O')
                    final String openTestUUID = "O" + ((UUIDField) test.getField("open_test_uuid")).toString();
                    jsonItem.put("open_test_uuid", openTestUUID);

                    final Date date = ((TimestampField) test.getField("time")).getDate();
                    final long time = date.getTime();
                    final String tzString = test.getField("timezone").toString();
                    final TimeZone tz = TimeZone.getTimeZone(tzString);
                    jsonItem.put("time", time);
                    jsonItem.put("timezone", tzString);
                    final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                            DateFormat.MEDIUM, locale);
                    dateFormat.setTimeZone(tz);
                    final String timeString = dateFormat.format(date);
                    jsonItem.put("time_string", timeString);

                    final Field fieldDown = test.getField("speed_download");
                    JSONObject singleItem = new JSONObject();
                    singleItem.put("title", labels.getString("RESULT_DOWNLOAD"));
                    final String downloadString = String.format("%s %s",
                            format.format(fieldDown.doubleValue() / 1000d),
                            labels.getString("RESULT_DOWNLOAD_UNIT"));
                    singleItem.put("value", downloadString);
                    singleItem.put("classification",
                            Classification.classify(classification.THRESHOLD_DOWNLOAD, fieldDown.intValue()));

                    jsonItemList.put(singleItem);

                    final Field fieldUp = test.getField("speed_upload");
                    singleItem = new JSONObject();
                    singleItem.put("title", labels.getString("RESULT_UPLOAD"));
                    final String uploadString = String.format("%s %s",
                            format.format(fieldUp.doubleValue() / 1000d),
                            labels.getString("RESULT_UPLOAD_UNIT"));
                    singleItem.put("value", uploadString);
                    singleItem.put("classification",
                            Classification.classify(classification.THRESHOLD_UPLOAD, fieldUp.intValue()));

                    jsonItemList.put(singleItem);

                    final Field fieldPing = test.getField("ping_median");
                    String pingString = "";
                    if (!fieldPing.isNull()) {
                        final double pingValue = fieldPing.doubleValue() / 1000000d;
                        singleItem = new JSONObject();
                        singleItem.put("title", labels.getString("RESULT_PING"));
                        pingString = String.format("%s %s", format.format(pingValue),
                                labels.getString("RESULT_PING_UNIT"));
                        singleItem.put("value", pingString);
                        singleItem.put("classification",
                                Classification.classify(classification.THRESHOLD_PING, fieldPing.longValue()));

                        jsonItemList.put(singleItem);
                    }

                    final int networkType = test.getField("network_type").intValue();

                    final Field signalField = test.getField("signal_strength"); // signal strength as RSSI (GSM, UMTS, Wifi, sometimes LTE)
                    final Field lteRsrpField = test.getField("lte_rsrp"); // signal strength as RSRP, used in LTE
                    String signalString = null;
                    if (!signalField.isNull() || !lteRsrpField.isNull()) {
                        if (lteRsrpField.isNull()) { // only RSSI value, output RSSI to JSON  
                            final int signalValue = signalField.intValue();
                            final int[] threshold = networkType == 99 || networkType == 0
                                    ? classification.THRESHOLD_SIGNAL_WIFI
                                    : classification.THRESHOLD_SIGNAL_MOBILE;
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_SIGNAL"));
                            signalString = signalValue + " " + labels.getString("RESULT_SIGNAL_UNIT");
                            singleItem.put("value", signalString);
                            singleItem.put("classification", Classification.classify(threshold, signalValue));
                        } else { // use RSRP value else (RSRP value has priority if both are available (e.g. 3G/4G-test))
                            final int signalValue = lteRsrpField.intValue();
                            final int[] threshold = classification.THRESHOLD_SIGNAL_RSRP;
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_SIGNAL_RSRP"));
                            signalString = signalValue + " " + labels.getString("RESULT_SIGNAL_UNIT");
                            singleItem.put("value", signalString);
                            singleItem.put("classification", Classification.classify(threshold, signalValue));

                        }
                        jsonItemList.put(singleItem);
                    }

                    jsonItem.put("measurement", jsonItemList);

                    jsonItemList = new JSONArray();

                    singleItem = new JSONObject();
                    singleItem.put("title", labels.getString("RESULT_NETWORK_TYPE"));
                    final String networkTypeString = Helperfunctions.getNetworkTypeName(networkType);
                    singleItem.put("value", networkTypeString);

                    jsonItemList.put(singleItem);

                    if (networkType == 98 || networkType == 99) // mobile wifi or browser
                    {
                        final Field providerNameField = test.getField("provider_id_name");
                        if (!providerNameField.isNull()) {
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_OPERATOR_NAME"));
                            singleItem.put("value", providerNameField.toString());
                            jsonItemList.put(singleItem);
                        }
                        if (networkType == 99) // mobile wifi
                        {
                            final Field ssid = test.getField("wifi_ssid");
                            if (!ssid.isNull()) {
                                singleItem = new JSONObject();
                                singleItem.put("title", labels.getString("RESULT_WIFI_SSID"));
                                singleItem.put("value", ssid.toString());
                                jsonItemList.put(singleItem);
                            }

                        }
                    } else // mobile
                    {
                        final Field operatorNameField = test.getField("network_operator_name");
                        if (!operatorNameField.isNull()) {
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_OPERATOR_NAME"));
                            singleItem.put("value", operatorNameField.toString());
                            jsonItemList.put(singleItem);
                        }

                        final Field roamingTypeField = test.getField("roaming_type");
                        if (!roamingTypeField.isNull() && roamingTypeField.intValue() > 0) {
                            singleItem = new JSONObject();
                            singleItem.put("title", labels.getString("RESULT_ROAMING"));
                            singleItem.put("value",
                                    Helperfunctions.getRoamingType(labels, roamingTypeField.intValue()));
                            jsonItemList.put(singleItem);
                        }
                    }

                    jsonItem.put("net", jsonItemList);

                    final Field latField = test.getField("geo_lat");
                    final Field longField = test.getField("geo_long");
                    boolean includeLocation = false;
                    final Field accuracyField = test.getField("geo_accuracy");
                    if (!(latField.isNull() || longField.isNull() || accuracyField.isNull())) {
                        final double accuracy = accuracyField.doubleValue();
                        if (accuracy < Double.parseDouble(getSetting("rmbt_geo_accuracy_button_limit", lang))) {
                            includeLocation = true;
                            jsonItem.put("geo_lat", latField.doubleValue());
                            jsonItem.put("geo_long", longField.doubleValue());
                        }
                    }

                    //geo location
                    JSONObject locationJson = TestResultDetailResource.getGeoLocation(this, test, settings,
                            conn, labels);
                    if (locationJson != null) {
                        if (locationJson.has("location")) {
                            jsonItem.put("location", locationJson.getString("location"));
                        }
                        if (locationJson.has("motion")) {
                            jsonItem.put("motion", locationJson.getString("motion"));
                        }
                    }

                    resultList.put(jsonItem);

                    final Field zip_code = test.getField("zip_code");
                    if (!zip_code.isNull())
                        jsonItem.put("zip_code", zip_code.intValue());

                    final Field zip_code_geo = test.getField("zip_code_geo");
                    if (!zip_code_geo.isNull())
                        jsonItem.put("zip_code_geo", zip_code_geo.intValue());

                    String providerString = test.getField("provider_id_name").toString();
                    if (providerString == null)
                        providerString = "";
                    String platformString = test.getField("plattform").toString();
                    if (platformString == null)
                        platformString = "";
                    String modelString = test.getField("model_fullname").toString();
                    if (modelString == null)
                        modelString = "";

                    String mobileNetworkString = null;
                    final Field networkOperatorField = test.getField("network_operator");
                    final Field mobileProviderNameField = test.getField("mobile_provider_name");
                    if (!networkOperatorField.isNull()) {
                        if (mobileProviderNameField.isNull())
                            mobileNetworkString = networkOperatorField.toString();
                        else
                            mobileNetworkString = String.format("%s (%s)", mobileProviderNameField,
                                    networkOperatorField);
                    }

                    /*
                    RESULT_SHARE_TEXT = My Result:\nDate/time: {0}\nDownload: {1}\nUpload: {2}\nPing: {3}\n{4}Network type: {5}\n{6}{7}Platform: {8}\nModel: {9}\n{10}\n\n
                    RESULT_SHARE_TEXT_SIGNAL_ADD = Signal strength: {0}\n
                    RESULT_SHARE_TEXT_RSRP_ADD = Signal strength (RSRP): {0}\n
                    RESULT_SHARE_TEXT_MOBILE_ADD = Mobile network: {0}\n
                    RESULT_SHARE_TEXT_PROVIDER_ADD = Operator: {0}\n
                            
                    */
                    String shareTextField4 = "";
                    if (signalString != null) //info on signal strength, field 4
                        if (lteRsrpField.isNull()) { //add RSSI if RSRP is not available
                            shareTextField4 = MessageFormat
                                    .format(labels.getString("RESULT_SHARE_TEXT_SIGNAL_ADD"), signalString);
                        } else { //add RSRP
                            shareTextField4 = MessageFormat
                                    .format(labels.getString("RESULT_SHARE_TEXT_RSRP_ADD"), signalString);
                        }
                    String shareLocation = "";
                    if (includeLocation && locationJson != null) {

                        shareLocation = MessageFormat.format(labels.getString("RESULT_SHARE_TEXT_LOCATION_ADD"),
                                locationJson.getString("location"));
                    }

                    final String shareText = MessageFormat.format(labels.getString("RESULT_SHARE_TEXT"),
                            timeString, //field 0
                            downloadString, //field 1
                            uploadString, //field 2
                            pingString, //field 3
                            shareTextField4, //contains field 4
                            networkTypeString, //field 5
                            providerString.isEmpty() ? ""
                                    : MessageFormat.format(labels.getString("RESULT_SHARE_TEXT_PROVIDER_ADD"),
                                            providerString), //field 6
                            mobileNetworkString == null ? ""
                                    : MessageFormat.format(labels.getString("RESULT_SHARE_TEXT_MOBILE_ADD"),
                                            mobileNetworkString), //field 7
                            platformString, //field 8
                            modelString, //field 9
                            //dz add location
                            shareLocation, //field 10
                            getSetting("url_open_data_prefix", lang) + openTestUUID); //field 11
                    jsonItem.put("share_text", shareText);

                    final String shareSubject = MessageFormat.format(labels.getString("RESULT_SHARE_SUBJECT"),
                            timeString //field 0
                    );
                    jsonItem.put("share_subject", shareSubject);

                    jsonItem.put("network_type", networkType);

                    if (resultList.length() == 0)
                        errorList.addError("ERROR_DB_GET_TESTRESULT");
                    // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"),
                    // new Object[] {uuid}));

                    answer.put("testresult", resultList);
                } else
                    errorList.addError("ERROR_REQUEST_NO_UUID");

            } else
                errorList.addError("ERROR_DB_CONNECTION");

        } catch (final JSONException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            System.out.println("Error parsing JSDON Data " + e.toString());
        }
    else
        errorList.addErrorString("Expected request is missing.");

    try {
        answer.putOpt("error", errorList.getList());
    } catch (final JSONException e) {
        System.out.println("Error saving ErrorList: " + e.toString());
    }

    answerString = answer.toString();

    long elapsedTime = System.currentTimeMillis() - startTime;
    System.out.println(MessageFormat.format(labels.getString("NEW_TESTRESULT_SUCCESS"), clientIpRaw,
            Long.toString(elapsedTime)));

    return answerString;
}

From source file:com.turt2live.uuid.turt2live.v2.ApiV2Service.java

@Override
protected PlayerRecord parsePlayerRecord(String json) {
    if (json == null)
        return null;

    JSONObject jsonValue = (JSONObject) JSONValue.parse(json);
    if (jsonValue.containsKey("uuid") && jsonValue.containsKey("name") && jsonValue.containsKey("offline-uuid")
            && jsonValue.containsKey("expires-in") && jsonValue.containsKey("expires-on")) {
        String uuidStr = (String) jsonValue.get("uuid");
        String name = (String) jsonValue.get("name");
        String offlineStr = (String) jsonValue.get("offline-uuid");
        Object expiresOn = jsonValue.get("expires-on");
        Object expiresIn = jsonValue.get("expires-in");
        boolean cached = jsonValue.containsKey("source")
                && ((String) jsonValue.get("source")).equalsIgnoreCase("cache");

        if (name.equals("unknown") || uuidStr.equals("unknown"))
            return null;
        if (expiresOn == null)
            expiresOn = "0";
        if (expiresIn == null)
            expiresIn = "0";

        long expOn, expIn;

        try {/*from   w w w  .  j  ava  2  s  .  co m*/
            if (expiresOn instanceof String)
                expOn = Long.parseLong((String) expiresOn);
            else
                expOn = (Long) expiresOn;
            expOn *= 1000; // Milliseconds

            if (expiresIn instanceof String)
                expIn = Long.parseLong((String) expiresIn);
            else
                expIn = (Long) expiresIn;
        } catch (Exception ignored) {
            return null; // Connection problem or other issue
        }

        UUID uuid = UUID.fromString(uuidStr);
        UUID offlineUuid = UUID.fromString(offlineStr);

        return new Turt2LivePlayerRecord(uuid, name, offlineUuid, expIn, expOn, cached);
    }

    return null;
}