List of usage examples for java.util UUID fromString
public static UUID fromString(String name)
From source file:org.mitre.uma.service.impl.TestDefaultPermissionService.java
@Test public void testCreate_uuid() { PermissionTicket perm = permissionService.createTicket(rs1, scopes1); // we expect this to be a UUID UUID uuid = UUID.fromString(perm.getTicket()); assertNotNull(uuid);//from ww w . j a v a 2 s . co m }
From source file:com.haulmont.cuba.web.sys.LinkHandler.java
/** * Called to handle the link.//w w w .java 2 s . c om */ public void handle() { try { String folderId = requestParams.get("folder"); if (!StringUtils.isEmpty(folderId)) { AbstractSearchFolder folder = loadFolder(UUID.fromString(folderId)); if (folder != null) { folders.openFolder(folder); } else { log.warn("Folder not found: {}", folderId); } return; } String screenName = requestParams.get("screen"); if (screenName == null) { log.warn("ScreenId not found in request parameters"); return; } WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); final WindowInfo windowInfo = windowConfig.getWindowInfo(screenName); if (windowInfo == null) { log.warn("WindowInfo not found for screen: {}", screenName); return; } UUID userId = getUUID(requestParams.get("user")); UserSession userSession = app.getConnection().getSession(); if (userSession == null) { log.warn("No user session"); return; } if (!(userId == null || userSession.getCurrentOrSubstitutedUser().getId().equals(userId))) { substituteUserAndOpenWindow(windowInfo, userId); } else { openWindow(windowInfo, requestParams); } } catch (AccessDeniedException e) { accessDeniedHandler.handle(e, app.getWindowManager()); } catch (NoSuchScreenException e) { noSuchScreenHandler.handle(e, app.getWindowManager()); } catch (EntityAccessException e) { entityAccessExceptionHandler.handle(e, app.getWindowManager()); } finally { VaadinRequest request = VaadinService.getCurrentRequest(); WrappedSession wrappedSession = request.getWrappedSession(); wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR); wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR); } }
From source file:com.sk89q.commandbook.locations.FlatFileLocationsManager.java
public void load() throws IOException { FileInputStream input = null; Map<String, NamedLocation> locs = new HashMap<String, NamedLocation>(); boolean needsSaved = false; if (file.getParentFile().exists() || file.getParentFile().mkdirs()) { if (!file.exists()) { file.createNewFile();//from w ww . j ava 2 s . c o m } } try { input = new FileInputStream(file); InputStreamReader streamReader = new InputStreamReader(input, "utf-8"); BufferedReader reader = new BufferedReader(streamReader); CSVReader csv = new CSVReader(reader); String[] line; while ((line = csv.readNext()) != null) { int lineLen = line.length; if (lineLen < 8) { logger().warning(type + " data file has an invalid line with < 8 fields"); } else { try { int i = 0; String name = line[i++].trim().replace(" ", ""); String worldName = line[i++]; // Set to null if the world exists String creator = line[i++]; double x = Double.parseDouble(line[i++]); double y = Double.parseDouble(line[i++]); double z = Double.parseDouble(line[i++]); float pitch = Float.parseFloat(line[i++]); float yaw = Float.parseFloat(line[i++]); World world = CommandBook.server().getWorld(worldName); if (world != null) { // We shouldn't have this warp if (castWorld != null && !castWorld.equals(world)) { continue; } } Location loc = new Location(world, x, y, z, yaw, pitch); NamedLocation warp = new NamedLocation(name, loc); warp.setWorldName(worldName); try { warp.setCreatorID(UUID.fromString(creator)); } catch (IllegalArgumentException ex) { logger().finest("Converting " + type + " " + name + "'s owner record to UUID..."); UUID creatorID = UUIDUtil.convert(creator); if (creatorID != null) { warp.setCreatorID(creatorID); needsSaved = true; logger().finest("Success!"); } else { warp.setCreatorName(creator); logger().warning(type + " " + name + "'s owner could not be converted!"); } } if (world == null) { getNestedList(unloadedLocations, worldName).add(warp); } else { locs.put(name.toLowerCase(), warp); } } catch (IllegalArgumentException e) { if (e instanceof NumberFormatException) { logger().warning(type + " data file has an invalid line with an invalid UUID field"); } else { logger().warning( type + " data file has an invalid line with non-numeric numeric fields"); } } } } this.locations = locs; if (castWorld != null) { logger().info(locs.size() + " " + type + "(s) loaded for " + castWorld.getName()); } else { logger().info(locs.size() + " " + type + "(s) loaded"); } } finally { if (input != null) { try { input.close(); } catch (IOException ignore) { } } } if (needsSaved) save(); }
From source file:de.static_interface.reallifeplugin.module.corporation.database.table.CorpsTable.java
@Override public CorpRow[] deserialize(ResultSet rs) throws SQLException { int rowcount = 0; if (rs.last()) { rowcount = rs.getRow();/*from w w w . ja v a 2s . c om*/ rs.beforeFirst(); } CorpRow[] rows = new CorpRow[rowcount]; int i = 0; while (rs.next()) { CorpRow row = new CorpRow(); if (hasColumn(rs, "id")) { row.id = rs.getInt("id"); } if (hasColumn(rs, "balance")) { row.balance = rs.getDouble("balance"); } if (hasColumn(rs, "base_id")) { row.baseId = rs.getString("base_id"); } if (hasColumn(rs, "base_world")) { row.baseWorld = rs.getString("base_world"); } if (hasColumn(rs, "ceo_uuid")) { row.ceoUniqueId = UUID.fromString(rs.getString("ceo_uuid")); } if (hasColumn(rs, "corp_name")) { row.corpName = rs.getString("corp_name"); } if (hasColumn(rs, "isdeleted")) { row.isDeleted = rs.getBoolean("isdeleted"); } if (hasColumn(rs, "tag")) { row.tag = rs.getString("tag"); } if (hasColumn(rs, "time")) { row.time = rs.getLong("time"); } rows[i] = row; i++; } return rows; }
From source file:com.dbsvg.controllers.PageControllerTest.java
@Test public void removePage() throws SQLException { String dbi = "10"; String pageName = "4e801310-b40f-42e3-8569-30c25071041d"; when(currentSchema.getDbi()).thenReturn(dbi); when(currentSchema.getPage(pageName)).thenReturn(schemaPage); when(schemaPage.getId()).thenReturn(UUID.fromString(pageName)); when(currentSchema.getNumPages()).thenReturn(2); ModelAndView result = instance.removePage(dbi, pageName, model, response, request); verify(iDAO).deleteSchemaPage(schemaPage, iDAOconn); verify(currentSchema).removePage(UUID.fromString(pageName)); verify(model).addAttribute(VAL, pageName); assertNull(result);/*from w w w . ja v a2 s.c o m*/ }
From source file:edu.purdue.cybercenter.dm.service.TermService.java
@CacheEvict(value = "vocabulary", allEntries = true) public edu.purdue.cybercenter.dm.domain.Term save(Term term, String filename, boolean isTemplate) { String sUuid = term.getUuid(); String sVersionNumber = term.getVersion(); if (sUuid == null || sVersionNumber == null) { throw new RuntimeException( String.format("A term cannot be saved with a null UUID: \"%s\" and/or version number: \"%s\"", sUuid, sVersionNumber)); }/*from ww w . j a v a 2 s .c o m*/ UUID uuid = UUID.fromString(sUuid); UUID versionNumber = UUID.fromString(sVersionNumber); String key; if (filename == null || filename.isEmpty()) { key = Helper.replaceSpecialCharacters(term.getName()) + ".xml"; } else { key = filename; } // check if the uuid and version number has been used edu.purdue.cybercenter.dm.domain.Term dbTerm = findByUuidAndVersionNumber(uuid, versionNumber); if (dbTerm != null && versionNumber != null) { // The term already exists if (!isLatest(term)) { dbTerm.setTimeUpdated(new Date()); dbTerm = domainObjectService.merge(dbTerm, edu.purdue.cybercenter.dm.domain.Term.class); } else { throw new RuntimeException(String.format( "The combination of UUID: \"%s\" and version: \"%s\" has been used by an existing term: ", sUuid, sVersionNumber)); } } else { // It's a new term // check if a term of the same definition already exists dbTerm = new edu.purdue.cybercenter.dm.domain.Term(); dbTerm.setUuid(uuid); dbTerm.setVersionNumber(versionNumber); dbTerm.setName(term.getName()); dbTerm.setDescription(term.getDescription()); dbTerm.setContent(convertTermToXml(term)); dbTerm.setIsTemplate(isTemplate); dbTerm.setKey(key); domainObjectService.persist(dbTerm, edu.purdue.cybercenter.dm.domain.Term.class); } return dbTerm; }
From source file:de.static_interface.sinkbans.commands.BanRequestCommand.java
@Override protected boolean onExecute(CommandSender sender, String label, String[] args) throws ParseException { if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Usage: /banrequest <new|list|cancel|accept|deny>"); return true; }// www. j a va 2 s . c o m switch (args[0].toLowerCase().trim()) { case "new": { if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: /banrequest new <name> [reason]"); return true; } IngameUser target = SinkLibrary.getInstance().getIngameUser(args[1]); if (target == null || StringUtil.isEmptyOrNull(target.getDisplayName())) { throw new UserNotFoundException(args[1]); } String reason = null; if (args.length >= 3) { for (int i = 2; i < args.length; i++) { if (reason == null) { reason = args[i]; continue; } reason += " " + args[i]; } } int id = DatabaseBanManager.createBanRequest(sender, target, reason, -1).id; String msg = sender.getName() + ChatColor.DARK_RED + " hat einen Bannantrag fr " + target.getDisplayName() + ChatColor.DARK_RED + " erstellt." + (reason == null ? "" : " Grund: " + ChatColor.RED + reason + ".") + ChatColor.GRAY + " (" + ChatColor.GOLD + "#" + id + ChatColor.GRAY + ")"; String perm = "sinkbans.banrequestnotification"; SinkLibrary.getInstance().getMessageStream("sb_ban_requests").sendMessage(null, msg, perm); if (!sender.hasPermission(perm)) { sender.sendMessage(msg); } break; } case "list": { sender.sendMessage(ChatColor.GOLD + "--- Ban Requests ---"); List<BanRequest> banRequests = DatabaseBanManager.getAllBanRequests(); int i = 0; for (BanRequest request : banRequests) { if (request.state != RequestState.PENDING) continue; String reason = request.reason != null ? request.reason : "Du wurdest permanent gesperrt"; IngameUser target = SinkLibrary.getInstance().getIngameUser(UUID.fromString(request.target_uuid)); sender.sendMessage(ChatColor.GOLD + "#" + request.id + " " + request.creator + ChatColor.GRAY + " -> " + target.getDisplayName() + ChatColor.GRAY + ": " + ChatColor.RED + reason); i++; } if (i == 0) { sender.sendMessage(ChatColor.GREEN + "No requests found :)"); break; } break; } case "cancel": { if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: /banrequest accept <id>"); return true; } int id = getArg(args, 1, int.class); BanRequest request = DatabaseBanManager.getBanRequest(id); if (request == null) { sender.sendMessage(ChatColor.RED + "Banrequest " + ChatColor.GOLD + "#" + id + " " + ChatColor.RED + " not found!"); return true; } if (!sender.hasPermission("sinkbans.closeothers")) { if ((request.creator != null && sender instanceof Player && !((Player) sender).getUniqueId().equals(UUID.fromString(request.creator_uuid))) || (request.creator != null && !(sender instanceof Player)) || (request.creator == null && sender instanceof Player) || (request.creator == null && !(sender instanceof Player)) && !request.creator.equals(ChatColor.stripColor(sender.getName()))) { sender.sendMessage(ChatColor.RED + "This is not your banrequest"); return true; } } long time = System.currentTimeMillis(); DatabaseBanManager.closeBanRequest(sender, request, RequestState.CANCELLED, time); sender.sendMessage(ChatColor.DARK_GREEN + "Dein Antrag " + ChatColor.GOLD + "#" + id + " " + ChatColor.DARK_GREEN + " wurde abgebrochen!"); break; } case "accept": { if (!sender.hasPermission("sinkbans.acceptbanrequest")) { sender.sendMessage(ChatColor.DARK_RED + "You don't have permission"); return true; } if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: /banrequest accept <id>"); return true; } int id = Integer.valueOf(args[1]); BanRequest request = DatabaseBanManager.getBanRequest(id); if (request == null) { sender.sendMessage(ChatColor.RED + "Banrequest " + ChatColor.GOLD + "#" + id + " " + ChatColor.RED + " not found!"); return true; } long time = System.currentTimeMillis(); IngameUser target = SinkLibrary.getInstance().getIngameUser(UUID.fromString(request.target_uuid)); DatabaseBanManager.closeBanRequest(sender, request, RequestState.ACCEPTED, time); target.ban(SinkLibrary.getInstance().getUser(sender), request.reason); if (target.isOnline()) { target.getPlayer().kickPlayer(ChatColor.DARK_RED + "Gesperrt: " + ChatColor.RED + request.reason); } SinkUser user = SinkLibrary.getInstance().getUser(sender); String msg = user.getDisplayName() + ChatColor.RED + " hat den Antrag von " + request.creator + ChatColor.RED + " fr " + target.getDisplayName() + ChatColor.RED + " angenommen."; String perm = "sinkbans.banrequestacceptednotification"; SinkLibrary.getInstance().getMessageStream("sb_ban_requests").sendMessage(null, msg, perm); if (!sender.hasPermission(perm)) { sender.sendMessage(msg); } IngameUser creator = SinkLibrary.getInstance().getIngameUser(UUID.fromString(request.creator)); if (request.creator != null && creator.isOnline()) { creator.sendMessage(ChatColor.DARK_GREEN + "Dein Antrag " + ChatColor.GOLD + "#" + id + " " + ChatColor.DARK_GREEN + " wurde angenommen!"); } break; } case "deny": { if (!sender.hasPermission("sinkbans.denybanrequest")) { sender.sendMessage(ChatColor.DARK_RED + "You don't have permission"); return true; } if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: /banrequest deny <id>"); return true; } int id = Integer.valueOf(args[1]); BanRequest request = DatabaseBanManager.getBanRequest(id); if (request == null) { sender.sendMessage(ChatColor.RED + "Banrequest " + ChatColor.GOLD + "#" + id + " " + ChatColor.RED + " not found!"); return true; } long time = System.currentTimeMillis(); DatabaseBanManager.closeBanRequest(sender, request, RequestState.DENIED, time); IngameUser creator = SinkLibrary.getInstance().getIngameUser(UUID.fromString(request.creator)); sender.sendMessage(ChatColor.DARK_RED + "Du hast den Antrag " + ChatColor.GOLD + "#" + id + " " + ChatColor.DARK_RED + " abgelehnt!"); if (request.creator != null && creator.isOnline()) { creator.sendMessage(ChatColor.DARK_RED + "Dein Antrag " + ChatColor.GOLD + "#" + id + " " + ChatColor.DARK_RED + " wurde abgelehnt!"); } break; } default: { sender.sendMessage(ChatColor.RED + "Usage: /banrequest <new|list|cancel|accept|deny>"); return true; } } return true; }
From source file:com.cognizant.glass.bluetoothconnect.DemoAppRecieverService.java
@Override public void onCreate() { mAdapter = BluetoothAdapter.getDefaultAdapter(); mDeviceAddresses = new ArrayList<String>(); mConnThreads = new ArrayList<ConnectedThread>(); mSockets = new ArrayList<BluetoothSocket>(); mUuids = new ArrayList<UUID>(); mUuids.add(UUID.fromString(clientId)); beaconList = new ArrayList<String>(); start();/* w w w .j av a2s . c om*/ }
From source file:com.blackducksoftware.integration.hub.api.report.AggregateBomViewEntry.java
public List<UUID> getBomEntryUUIds() { final List<UUID> bomEntryUUIds = new ArrayList<UUID>(); for (final String bomEntryId : bomEntryIds) { if (StringUtils.isBlank(bomEntryId)) { continue; }//from ww w . ja va 2s . c o m try { bomEntryUUIds.add(UUID.fromString(bomEntryId)); } catch (final IllegalArgumentException e) { continue; } } return bomEntryUUIds; }
From source file:dbsimulator.dal.mysql.MySqlSimDal.java
@Override public String loadTestControls(String testKey, SessionTest sessTest) { try (SQLConnection connection = getSQLConnection()) { UUID session = UUID.fromString(getSessionKey()); MultiDataResultSet sets = _simdll.SIM_GetTestControls2_SP(connection, session, testKey); Iterator<SingleDataResultSet> iterator = sets.getResultSets(); if (iterator.hasNext()) { // First result set SingleDataResultSet rs = iterator.next(); if (rs.getCount() != 1) return String.format("Error loading test %s", testKey); DbResultRecord rec = rs.getRecords().next(); sessTest.setLanguage(rec.<String>get("language")); sessTest.setOpportunities(rec.<Integer>get("opportunities")); sessTest.setMeanProficiency(rec.<Float>get("meanProficiency")); sessTest.setSdProficiency(rec.<Float>get("sdProficiency")); sessTest.setStrandCorrelation(rec.<Float>get("strandCorrelation")); String handScoreItemTypes = rec.<String>get("handScoreItemTypes"); if (StringUtils.isEmpty(handScoreItemTypes) == false) { String[] types = handScoreItemTypes.split(","); for (String type : types) { sessTest.addHandScoreItemTypes(type); }// ww w. ja va 2 s .co m } sessTest.setItemBank(rec.<String>get("itembank")); sessTest.setNumThreads(rec.<Integer>get("threads")); sessTest.setThinkTime(rec.<Integer>get("thinktime")); sessTest.setTotalOpps(rec.<Integer>get("simulations")); } if (iterator.hasNext()) { // Second result set SingleDataResultSet rs = iterator.next(); Iterator<DbResultRecord> iter = rs.getRecords(); while (iter.hasNext()) { DbResultRecord rec = iter.next(); String strand = rec.<String>get("strand"); sessTest.addStrand(strand); } } return null; } catch (SQLException se) { _logger.error(se.getMessage()); } catch (ReturnStatusException re) { _logger.error(re.getMessage()); } return String.format("Error loading test %s", testKey); }