List of usage examples for java.util UUID fromString
public static UUID fromString(String name)
From source file:com.mozilla.bagheera.validation.Validator.java
public boolean isValidId(String id) { boolean isValid = false; try {// w w w. j av a 2 s . co m UUID.fromString(id); isValid = true; } catch (IllegalArgumentException e) { LOG.error("Invalid ID: " + id); } return isValid; }
From source file:org.usergrid.rest.applications.users.UsersResource.java
@Override @Path("{entityId: [A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}") public AbstractContextResource addIdParameter(@Context UriInfo ui, @PathParam("entityId") PathSegment entityId) throws Exception { logger.info("ServiceResource.addIdParameter"); UUID itemId = UUID.fromString(entityId.getPath()); addParameter(getServiceParameters(), itemId); addMatrixParams(getServiceParameters(), ui, entityId); return getSubResource(UserResource.class).init(Identifier.fromUUID(itemId)); }
From source file:de.static_interface.reallifeplugin.module.contract.database.table.ContractUsersTable.java
@Override public ContractUserRow[] deserialize(ResultSet rs) throws SQLException { int rowcount = 0; if (rs.last()) { rowcount = rs.getRow();//from ww w .j a v a2s .c om rs.beforeFirst(); } ContractUserRow[] rows = new ContractUserRow[rowcount]; int i = 0; while (rs.next()) { ContractUserRow row = new ContractUserRow(); if (hasColumn(rs, "id")) { row.id = rs.getInt("id"); } if (hasColumn(rs, "uuid")) { row.uuid = UUID.fromString(rs.getString("uuid")); } rows[i] = row; i++; } return rows; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAst.CFAstSecDeviceHPKey.java
public CFAstSecDeviceHPKey() { super();//from w w w. ja v a2 s .co m requiredSecUserId = UUID.fromString(CFAstSecDeviceBuff.SECUSERID_INIT_VALUE.toString()); requiredDevName = new String(CFAstSecDeviceBuff.DEVNAME_INIT_VALUE); }
From source file:com.v2soft.dnremote.dao.Server.java
public Server(JSONObject in) throws JSONException { this(UUID.fromString(in.getString(KEY_ID)), in.getString(KEY_NAME), in.getString(KEY_SERVER), in.getInt(KEY_PORT), in.getBoolean(KEY_RELATIVE), null); }
From source file:com.mstiles92.plugins.stileslib.player.UUIDFetcher.java
private UUID getUUID(String rawId) { return UUID.fromString(rawId.substring(0, 8) + "-" + rawId.substring(8, 12) + "-" + rawId.substring(12, 16) + "-" + rawId.substring(16, 20) + "-" + rawId.substring(20, 32)); }
From source file:at.alladin.rmbt.controlServer.SyncResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();//from w w w. j av a 2 s . co m JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; System.out.println(MessageFormat.format(labels.getString("NEW_SYNC_REQUEST"), getIP())); 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 JSONArray syncList = new JSONArray(); UUID uuid = null; if (request.optString("uuid").length() > 0) uuid = UUID.fromString(request.getString("uuid")); if (uuid != null && request.optString("sync_code").length() == 0) { String syncCode = ""; try { final PreparedStatement st = conn .prepareStatement("SELECT rmbt_get_sync_code(CAST (? AS UUID)) AS code"); st.setString(1, uuid.toString()); final ResultSet rs = st.executeQuery(); if (rs.next()) syncCode = rs.getString("code"); else errorList.addError("ERROR_DB_GET_SYNC_SQL"); // 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_SYNC_SQL"); // errorList.addError("ERROR_DB_GET_CLIENT_SQL"); } if (errorList.getLength() == 0) { final JSONObject jsonItem = new JSONObject(); //lower case code is easier to enter on mobile devices jsonItem.put("sync_code", syncCode.toLowerCase(Locale.US)); syncList.put(jsonItem); } } else if (uuid != null && request.optString("sync_code").length() > 0) { final String syncCode = request.getString("sync_code").toUpperCase(Locale.US); int syncGroup1 = 0; int uid1 = 0; int syncGroup2 = 0; int uid2 = 0; String msgTitle = labels.getString("SYNC_SUCCESS_TITLE"); String msgText = labels.getString("SYNC_SUCCESS_TEXT"); boolean error = false; try { PreparedStatement st = conn.prepareStatement( "SELECT * FROM client WHERE sync_code = ? AND sync_code_timestamp + INTERVAL '1 month' > NOW()"); st.setString(1, syncCode); ResultSet rs = st.executeQuery(); if (rs.next()) { syncGroup1 = rs.getInt("sync_group_id"); uid1 = rs.getInt("uid"); } else { msgTitle = labels.getString("SYNC_CODE_TITLE"); msgText = labels.getString("SYNC_CODE_TEXT"); error = true; // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); } rs.close(); st.close(); st = conn.prepareStatement("SELECT * FROM client WHERE uuid = CAST(? AS UUID)"); st.setString(1, uuid.toString()); rs = st.executeQuery(); if (rs.next()) { syncGroup2 = rs.getInt("sync_group_id"); uid2 = rs.getInt("uid"); } else { msgTitle = labels.getString("SYNC_UUID_TITLE"); msgText = labels.getString("SYNC_UUID_TEXT"); error = true; // errorList.addError(MessageFormat.format(labels.getString("ERROR_DB_GET_CLIENT"), // new Object[] {uuid})); } rs.close(); st.close(); if (syncGroup1 > 0 && syncGroup1 == syncGroup2) { msgTitle = labels.getString("SYNC_GROUP_TITLE"); msgText = labels.getString("SYNC_GROUP_TEXT"); error = true; } if (uid1 > 0 && uid1 == uid2) { msgTitle = labels.getString("SYNC_CLIENT_TITLE"); msgText = labels.getString("SYNC_CLIENT_TEXT"); error = true; } if (!error) if (syncGroup1 == 0 && syncGroup2 == 0) { int key = 0; // create new group st = conn.prepareStatement("INSERT INTO sync_group(tstamp) " + "VALUES(now())", Statement.RETURN_GENERATED_KEYS); int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_STORE_SYNC_GROUP"); else { rs = st.getGeneratedKeys(); if (rs.next()) // Retrieve the auto generated // key(s). key = rs.getInt(1); rs.close(); } st.close(); if (key > 0) { st = conn.prepareStatement( "UPDATE client SET sync_group_id = ? WHERE uid = ? OR uid = ?"); st.setInt(1, key); st.setInt(2, uid1); st.setInt(3, uid2); affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); } } else if (syncGroup1 == 0 && syncGroup2 > 0) { // add 1 to 2 st = conn.prepareStatement("UPDATE client SET sync_group_id = ? WHERE uid = ?"); st.setInt(1, syncGroup2); st.setInt(2, uid1); final int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); } else if (syncGroup1 > 0 && syncGroup2 == 0) { // add 2 to 1 st = conn .prepareStatement("UPDATE client SET sync_group_id = ? WHERE uid = ? "); st.setInt(1, syncGroup1); st.setInt(2, uid2); final int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); } else if (syncGroup1 > 0 && syncGroup2 > 0) { // add all of 2 to 1 st = conn.prepareStatement( "UPDATE client SET sync_group_id = ? WHERE sync_group_id = ?"); st.setInt(1, syncGroup1); st.setInt(2, syncGroup2); int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_UPDATE_SYNC_GROUP"); else { // Delete empty group st = conn.prepareStatement("DELETE FROM sync_group WHERE uid = ?"); st.setInt(1, syncGroup2); affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_DELETE_SYNC_GROUP"); } } } catch (final SQLException e) { e.printStackTrace(); errorList.addError("ERROR_DB_GET_SYNC_SQL"); // errorList.addError("ERROR_DB_GET_CLIENT_SQL"); } if (errorList.getLength() == 0) { final JSONObject jsonItem = new JSONObject(); jsonItem.put("msg_title", msgTitle); jsonItem.put("msg_text", msgText); jsonItem.put("success", !error); syncList.put(jsonItem); } } answer.put("sync", syncList); } 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(); return answerString; }
From source file:org.trustedanalytics.serviceexposer.checker.CheckerJob.java
public void updateDeletedServiceInstances(String serviceType, Set<CcExtendedServiceInstance> serviceInstances) { Set<String> servicesGuids = serviceInstances.stream() .map(instance -> instance.getMetadata().getGuid().toString()).collect(Collectors.toSet()); for (String serviceInstanceGuid : store.getSurplusServicesGuids(serviceType, servicesGuids)) { credentialsRetriver.deleteServiceInstance(serviceType, UUID.fromString(serviceInstanceGuid)); }// www .j a v a 2 s .co m }
From source file:com.modwiz.sponge.statue.utils.skins.SkinResolverService.java
public SkinResolverService(final File cacheDir) { checkNotNull(cacheDir);/*from www . ja va2 s. co m*/ if (!cacheDir.exists()) { cacheDir.mkdirs(); } else { File[] cachedSkins = cacheDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".json"); } }); JsonParser parser = new JsonParser(); for (File file : cachedSkins) { try { JsonObject element = parser.parse(new FileReader(file)).getAsJsonObject(); long now = new Date().getTime(); long timestamp = element.get("timestamp").getAsLong(); if (new Date(now - timestamp).getMinutes() <= 45) { // Less than 45 minutes old UUID uuid = UUID.fromString(element.get("uuid").getAsString()); BufferedImage texture = ImageIO.read(new File(String.format("%s.png", uuid.toString()))); MinecraftSkin.Type skinType = MinecraftSkin.Type.valueOf(element.get("type").getAsString()); MinecraftSkin skin = new MinecraftSkin(skinType, uuid, texture, timestamp); skinCache.put(uuid, skin); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } this.cacheDir = cacheDir; skinCache = new HashMap<UUID, MinecraftSkin>(100); skinLoader = new SkinLoader(); }
From source file:com.consol.citrus.samples.todolist.dao.JdbcTodoListDao.java
@Override public List<TodoEntry> list() { try {// w w w .ja v a 2 s. c o m Connection connection = getConnection(); try { Statement statement = connection.createStatement(); try { ResultSet resultSet = statement.executeQuery("SELECT id, title, description FROM todo_entries"); try { List<TodoEntry> list = new ArrayList<>(); while (resultSet.next()) { String id = resultSet.getString(1); String title = resultSet.getString(2); String description = resultSet.getString(3); list.add(new TodoEntry(UUID.fromString(id), title, description)); } return list; } finally { resultSet.close(); } } finally { statement.close(); } } finally { connection.close(); } } catch (SQLException e) { throw new DataAccessException("Could not list entries", e); } }