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:org.energyos.espi.datacustodian.web.custodian.AssociateUsagePointController.java

@RequestMapping(value = Routes.DATA_CUSTODIAN_RETAIL_CUSTOMER_USAGE_POINTS_CREATE, method = RequestMethod.POST)
public String create(@PathVariable Long retailCustomerId,
        @ModelAttribute("usagePointForm") @Valid UsagePointForm usagePointForm, BindingResult result) {
    if (result.hasErrors())
        return "/custodian/retailcustomers/usagepoints/form";

    Subscription subscription = retailCustomerService.associateByUUID(retailCustomerId,
            UUID.fromString(usagePointForm.getUUID()));

    if (subscription != null) {
        notificationService.notify(subscription, null, null);
    }/*from w  ww .j a  va2s  .  co  m*/
    return "redirect:/custodian/retailcustomers";
}

From source file:fr.syncarnet.tasks.DeletedTasks.java

public void unJsonify(String json) {
    try {/*from   w w w  . jav  a  2 s .  c o  m*/
        JSONObject jsonDT = new JSONObject(json);
        JSONArray jsonUUIDs = new JSONArray(jsonDT.getString("uuids"));
        for (int i = 0; i < this.size(); i++)
            this.add(UUID.fromString(jsonUUIDs.getString(i)));
        Log.d(TAG, "Recreated uuids from json");

        JSONArray jsonTimestamps = new JSONArray(jsonDT.getString("timestamps"));
        JSONObject jsonTTemp;
        for (int i = 0; i < jsonTimestamps.length(); i++) {
            jsonTTemp = new JSONObject(jsonTimestamps.getString(i));
            timestamps.put(UUID.fromString(jsonTTemp.getString("uuid")), jsonTTemp.getLong("timestamp"));
        }
        Log.d(TAG, "Recreated timestamps from json");
    } catch (JSONException e) {
        Log.e(TAG, "Exception while unjsonifying");
    }
}

From source file:com.blackducksoftware.integration.hub.api.report.DetailedReleaseSummary.java

public UUID getVersionUUId() {
    if (StringUtils.isBlank(versionId)) {
        return null;
    }/* w  w  w  . j a va  2 s .  c om*/
    try {
        return UUID.fromString(versionId);
    } catch (final IllegalArgumentException e) {
        return null;
    }
}

From source file:com.edmunds.etm.system.api.ControllerInstance.java

/**
 * Creates a ControllerInstance from the specified DTO.
 *
 * @param dto the DTO to read// w  ww  .j  a  v a 2  s . c o  m
 * @return an ControllerInstance object
 */
public static ControllerInstance readDto(ControllerInstanceDto dto) {
    if (dto == null) {
        return null;
    }

    UUID id = null;
    try {
        id = UUID.fromString(dto.getId());
    } catch (IllegalArgumentException e) {
        logger.error(String.format("Cannot parse UUID from dto: %s", dto), e);
        return null;
    }

    String ipAddress = dto.getIpAddress();
    String version = dto.getVersion();

    FailoverState failoverState;
    try {
        failoverState = FailoverState.valueOf(dto.getFailoverState());
    } catch (RuntimeException e) {
        logger.error("Invalid failover state read from DTO", e);
        failoverState = FailoverState.UNKNOWN;
    }

    ControllerInstance obj = null;
    try {
        obj = new ControllerInstance(id, ipAddress, version, failoverState);
    } catch (IllegalArgumentException e) {
        logger.error("Invalid controller instance DTO", e);
    }
    return obj;
}

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

@Post("json")
public String request(final String entity) {
    addAllowOrigin();//from ww  w  .ja v  a 2s  .  c  o  m
    JSONObject request = null;

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

    final String clientIpRaw = getIP();
    final InetAddress clientAddress = InetAddresses.forString(clientIpRaw);

    System.out.println(MessageFormat.format(labels.getString("NEW_IP_REQ"), clientIpRaw));

    if (entity != null && !entity.isEmpty()) {
        // try parse the string to a JSON object
        try {
            // debug parameters sent
            request = new JSONObject(entity);
            System.out.println(request.toString(4));

            /* sample request data
            {
                "api_level": "21",
                "device": "hammerhead",
                "language": "en",
                "model": "Nexus 5",
                "os_version": "5.0(1570415)",
                "plattform": "Android",
                "product": "hammerhead",
                "softwareRevision": "master_initial-2413-gf89049d",
                "softwareVersionCode": 20046,
                "softwareVersionName": "2.0.46",
                "timezone": "Europe/Vienna",
                "type": "MOBILE",
                "uuid": "........(uuid)........"
                "location": {
            "accuracy": 20,
            "age": 7740,
            "lat": 51.1053539,
            "long": 17.4921002,
            "provider": "network"
             },
            }
            */
            UUID uuid = null;
            final String uuidString = request.optString("uuid", "");
            if (uuidString.length() != 0)
                uuid = UUID.fromString(uuidString);

            final String clientPlattform = request.getString("plattform");
            final String clientModel = request.getString("model");
            final String clientProduct = request.getString("product");
            final String clientDevice = request.getString("device");
            final String clientSoftwareVersionCode = request.getString("softwareVersionCode");
            final String clientApiLevel = request.getString("api_level");

            final JSONObject location = request.optJSONObject("location");

            long geoage = 0; // age in ms
            double geolat = 0;
            double geolong = 0;
            float geoaccuracy = 0; // in m
            double geoaltitude = 0;
            float geospeed = 0; // in m/s
            String geoprovider = "";

            if (!request.isNull("location")) {
                geoage = location.optLong("age", 0);
                geolat = location.optDouble("lat", 0);
                geolong = location.optDouble("long", 0);
                geoaccuracy = (float) location.optDouble("accuracy", 0);
                geoaltitude = location.optDouble("altitude", 0);
                geospeed = (float) location.optDouble("speed", 0);
                geoprovider = location.optString("provider", "");
            }

            if (errorList.getLength() == 0)
                try {
                    PreparedStatement st;
                    st = conn.prepareStatement(
                            "INSERT INTO status(client_uuid,time,plattform,model,product,device,software_version_code,api_level,ip,"
                                    + "age,lat,long,accuracy,altitude,speed,provider)"
                                    + "VALUES(?, NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                            Statement.RETURN_GENERATED_KEYS);
                    int i = 1;
                    st.setObject(i++, uuid);
                    st.setObject(i++, clientPlattform);
                    st.setObject(i++, clientModel);
                    st.setObject(i++, clientProduct);
                    st.setObject(i++, clientDevice);
                    st.setObject(i++, clientSoftwareVersionCode);
                    st.setObject(i++, clientApiLevel);
                    st.setObject(i++, clientIpRaw);
                    // location information
                    st.setObject(i++, geoage);
                    st.setObject(i++, geolat);
                    st.setObject(i++, geolong);
                    st.setObject(i++, geoaccuracy);
                    st.setObject(i++, geoaltitude);
                    st.setObject(i++, geospeed);
                    st.setObject(i++, geoprovider);

                    final int affectedRows = st.executeUpdate();
                    if (affectedRows == 0)
                        errorList.addError("ERROR_DB_STORE_STATUS");
                } catch (final SQLException e) {
                    errorList.addError("ERROR_DB_STORE_GENERAL");
                    e.printStackTrace();
                }

            answer.put("ip", clientIpRaw);
            if (clientAddress instanceof Inet4Address) {
                answer.put("v", "4");
            } else if (clientAddress instanceof Inet6Address) {
                answer.put("v", "6");
            } else {
                answer.put("v", "0");
            }
        } catch (final JSONException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            System.out.println("Error parsing JSON 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();

    return answerString;
}

From source file:com.urbancode.ud.client.VersionClient.java

public UUID createVersion(String component, String version, String description)
        throws IOException, JSONException {
    UUID result = null;// ww  w .  ja va2 s .  c om
    String uri = url + "/cli/version/createVersion/?name=" + encodePath(version) + "&component="
            + encodePath(component) + "&description=" + encodePath(description);

    HttpPost method = new HttpPost(uri);
    HttpResponse response = invokeMethod(method);
    String body = getBody(response);
    JSONObject jsonResult = new JSONObject(body);
    result = UUID.fromString((String) jsonResult.get("id"));

    return result;
}

From source file:com.v2soft.dnremote.dao.Server.java

public Server(Parcel in) {
    this(UUID.fromString(in.readString()), in.readString(), in.readString(), in.readInt(), in.readByte() == 1,
            readIPAddr(in));
}

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

/**
 * Test of getInternalID method, of class JdbcTargetDao.
 *//*from   w  w w . j  a va 2  s . com*/
@Test
public void testGetInternalId() throws NotInDataBaseException {
    System.out.println("getInternalId");
    UUID externalID = UUID.fromString("00000000-0000-0000-0000-000000000031");
    Number result = jdbcTargetDao.getInternalID(externalID);
    assertEquals(1, result);
}

From source file:com.ltasks.BaseClient.java

/**
 * This method validates the api key by trying to parse it using
 * {@link UUID#fromString(String)}. If it fails it throws an exception.
 * //from   w w  w .  ja  v a 2 s .  co m
 * @param aApiKey
 *            the user api key
 * @throws IllegalArgumentException
 *             the api key does not conform with the standard
 *             representation.
 */
private void validateApiKey(String aApiKey) throws IllegalArgumentException {
    UUID.fromString(aApiKey);
}

From source file:edu.purdue.cybercenter.dm.web.TermController.java

private String fetchTermDetails(String uuid, String version) {
    edu.purdue.cybercenter.dm.domain.Term dbTerm = termService.findByUuidAndVersionNumber(UUID.fromString(uuid),
            version != null ? UUID.fromString(version) : null);
    return fetchTermDetails(dbTerm);
}