List of usage examples for java.util UUID fromString
public static UUID fromString(String name)
From source file:at.alladin.rmbt.controlServer.HistoryResource.java
@Post("json") public String request(final String entity) { long startTime = System.currentTimeMillis(); addAllowOrigin();/* w w w .java 2 s .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_HISTORY"), 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); if (request.optString("uuid").length() > 0 && client.getClientByUuid(UUID.fromString(request.getString("uuid"))) > 0) { final Locale locale = new Locale(lang); final Format format = new SignificantFormat(2, locale); String limitRequest = ""; if (request.optInt("result_limit", 0) != 0) { final int limit = request.getInt("result_limit"); //get offset string if there is one String offsetString = ""; if ((request.optInt("result_offset", 0) != 0) && (request.getInt("result_offset") >= 0)) { offsetString = " OFFSET " + request.getInt("result_offset"); } limitRequest = " LIMIT " + limit + offsetString; } final ArrayList<String> deviceValues = new ArrayList<>(); String deviceRequest = ""; if (request.optJSONArray("devices") != null) { final JSONArray devices = request.getJSONArray("devices"); boolean checkUnknown = false; final StringBuffer sb = new StringBuffer(); for (int i = 0; i < devices.length(); i++) { final String device = devices.getString(i); if (device.equals("Unknown Device")) checkUnknown = true; else { if (sb.length() > 0) sb.append(','); deviceValues.add(device); sb.append('?'); } } if (sb.length() > 0) deviceRequest = " AND (COALESCE(adm.fullname, t.model) IN (" + sb.toString() + ")" + (checkUnknown ? " OR model IS NULL OR model = ''" : "") + ")"; // System.out.println(deviceRequest); } final ArrayList<String> filterValues = new ArrayList<>(); String networksRequest = ""; if (request.optJSONArray("networks") != null) { final JSONArray tmpArray = request.getJSONArray("networks"); final StringBuilder tmpString = new StringBuilder(); if (tmpArray.length() >= 1) { tmpString.append("AND nt.group_name IN ("); boolean first = true; for (int i = 0; i < tmpArray.length(); i++) { if (first) first = false; else tmpString.append(','); tmpString.append('?'); filterValues.add(tmpArray.getString(i)); } tmpString.append(')'); } networksRequest = tmpString.toString(); } final JSONArray historyList = new JSONArray(); final PreparedStatement st; try { if (client.getSync_group_id() == 0) { //use faster request ignoring sync-group as user is not synced (id=0) st = conn.prepareStatement(String.format( "SELECT DISTINCT" + " t.uuid, time, timezone, speed_upload, speed_download, ping_median, network_type, nt.group_name network_type_group_name," + " COALESCE(adm.fullname, t.model) model" + " FROM test t" + " LEFT JOIN device_map adm ON adm.codename=t.model" + " LEFT JOIN network_type nt ON t.network_type=nt.uid" + " WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED'" + " AND client_id = ?" + " %s %s" + " ORDER BY time DESC" + " %s", deviceRequest, networksRequest, limitRequest)); } else { //use slower request including sync-group if client is synced st = conn.prepareStatement(String.format("SELECT DISTINCT" + " t.uuid, time, timezone, speed_upload, speed_download, ping_median, network_type, nt.group_name network_type_group_name," + " COALESCE(adm.fullname, t.model) model" + " FROM test t" + " LEFT JOIN device_map adm ON adm.codename=t.model" + " LEFT JOIN network_type nt ON t.network_type=nt.uid" + " WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED'" + " AND (t.client_id IN (SELECT ? UNION SELECT uid FROM client WHERE sync_group_id = ? ))" + " %s %s" + " ORDER BY time DESC" + " %s", deviceRequest, networksRequest, limitRequest)); } int i = 1; st.setLong(i++, client.getUid()); if (client.getSync_group_id() != 0) st.setInt(i++, client.getSync_group_id()); for (final String value : deviceValues) st.setString(i++, value); for (final String filterValue : filterValues) st.setString(i++, filterValue); //System.out.println(st.toString()); final ResultSet rs = st.executeQuery(); while (rs.next()) { final JSONObject jsonItem = new JSONObject(); jsonItem.put("test_uuid", rs.getString("uuid")); final Date date = rs.getTimestamp("time"); final long time = date.getTime(); final String tzString = rs.getString("timezone"); 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); jsonItem.put("time_string", dateFormat.format(date)); jsonItem.put("speed_upload", format.format(rs.getInt("speed_upload") / 1000d)); jsonItem.put("speed_download", format.format(rs.getInt("speed_download") / 1000d)); final long ping = rs.getLong("ping_median"); jsonItem.put("ping", format.format(ping / 1000000d)); // backwards compatibility for old clients jsonItem.put("ping_shortest", format.format(ping / 1000000d)); jsonItem.put("model", rs.getString("model")); jsonItem.put("network_type", rs.getString("network_type_group_name")); //for appscape-iPhone-Version: also add classification to the response jsonItem.put("speed_upload_classification", Classification .classify(classification.THRESHOLD_UPLOAD, rs.getInt("speed_upload"))); jsonItem.put("speed_download_classification", Classification .classify(classification.THRESHOLD_DOWNLOAD, rs.getInt("speed_download"))); jsonItem.put("ping_classification", Classification .classify(classification.THRESHOLD_PING, rs.getLong("ping_median"))); // backwards compatibility for old clients jsonItem.put("ping_shortest_classification", Classification .classify(classification.THRESHOLD_PING, rs.getLong("ping_median"))); historyList.put(jsonItem); } if (historyList.length() == 0) errorList.addError("ERROR_DB_GET_HISTORY"); // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); rs.close(); st.close(); } catch (final SQLException e) { e.printStackTrace(); errorList.addError("ERROR_DB_GET_HISTORY_SQL"); // errorList.addError("ERROR_DB_GET_CLIENT_SQL"); } answer.put("history", historyList); } 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()); } catch (final IllegalArgumentException e) { errorList.addError("ERROR_REQUEST_NO_UUID"); } 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_HISTORY_SUCCESS"), clientIpRaw, Long.toString(elapsedTime))); return answerString; }
From source file:com.quatico.base.aem.test.api.AemMatchers.java
public static Matcher<String> pathEndsWithUuid() { return new TypeSafeMatcher<String>() { @Override// ww w . j a v a 2s. c om protected boolean matchesSafely(String value) { try { UUID.fromString(StringUtils.substringAfterLast(value, "/")); } catch (IllegalArgumentException ex) { return false; } return true; } @Override public void describeTo(Description description) { description.appendText("String should end with a UUID"); } }; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.CFAccAccountEntryHPKey.java
public CFAccAccountEntryHPKey() { super();//from w w w . j a v a 2s .com requiredTenantId = CFAccAccountEntryBuff.TENANTID_INIT_VALUE; requiredAccountId = CFAccAccountEntryBuff.ACCOUNTID_INIT_VALUE; requiredEntryId = UUID.fromString(CFAccAccountEntryBuff.ENTRYID_INIT_VALUE.toString()); }
From source file:org.trustedanalytics.servicebroker.hdfs.plans.HdfsPlanCreateUserDirectory.java
@Override public Map<String, Object> bind(ServiceInstance serviceInstance) throws ServiceBrokerException { UUID instanceId = UUID.fromString(serviceInstance.getServiceInstanceId()); UUID orgId = UUID.fromString(serviceInstance.getOrganizationGuid()); Map<String, Object> configurationMap = bindingOperations.createCredentialsMap(instanceId, orgId); Map<String, Object> storedCredentials = credentialsStore.get(instanceId); Map<String, Object> credentials = new HashMap<>(); credentials.putAll(configurationMap); credentials.putAll(storedCredentials); return credentials; }
From source file:me.sonarbeserk.lockup.utils.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<String, UUID>(); String body = buildBody(names); for (int i = 1; i < MAX_SEARCH; i++) { HttpURLConnection connection = createConnection(i); writeBody(connection, body);//from ww w.j a v a 2 s. c o m JSONObject jsonObject = (JSONObject) jsonParser .parse(new InputStreamReader(connection.getInputStream())); JSONArray array = (JSONArray) jsonObject.get("profiles"); Number count = (Number) jsonObject.get("size"); if (count.intValue() == 0) { break; } for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32)); uuidMap.put(name, uuid); } } return uuidMap; }
From source file:com.microsoft.graph.connect.ConnectActivity.java
private static boolean hasAzureConfiguration() { try {/*w ww . j a v a 2 s. co m*/ UUID.fromString(Constants.CLIENT_ID); URI.create(Constants.REDIRECT_URI); return true; } catch (IllegalArgumentException e) { return false; } }
From source file:gemlite.core.internal.domain.utilClass.MqDataSource.java
@Override public UUID getUUID(String name) { String str = map.get(name);//from w w w .jav a2 s. co m if (str == null) return null; return UUID.fromString(str); }
From source file:occi.infrastructure.Storage.java
public Storage(Set<Link> links, Set<String> attributes) throws URISyntaxException, SchemaViolationException { super(links, attributes); storageList.put(UUID.fromString(this.getId().toString()), this); generateActionNames();/*from www . j a v a2 s . c o m*/ generateAttributeList(); }
From source file:com.formkiq.core.dao.FolderDaoImpl.java
@SuppressWarnings("resource") @Override/* www .ja v a 2s .co m*/ public void deleteFolder(final String folder) { UUID folderId = UUID.fromString(folder); String sql0 = "delete from folders where folder_id=:folder"; String sql1 = "delete from folders_access where folder_id=:folder"; Session session = getEntityManager().unwrap(Session.class); session.createSQLQuery(sql1).setParameter("folder", folderId, PostgresUUIDType.INSTANCE).executeUpdate(); session.createSQLQuery(sql0).setParameter("folder", folderId, PostgresUUIDType.INSTANCE).executeUpdate(); }
From source file:com.jim.im.login.rest.LoginRestService.java
/** * ???/*from www . j ava 2s.c o m*/ * * @param sessionID * @param userID * @throws ImParamException */ private void checkParamValid(String sessionID, int userID) throws ImParamException { if (StringUtils.isEmpty(sessionID)) throw new ImParamException("sessionID must be not null"); if (userID == 0) throw new ImParamException("userID must be not null"); try { UUID.fromString(sessionID); } catch (Exception e) { throw new ImParamException("sessionID must is UUID String", e); } }