List of usage examples for java.util Map toString
public String toString()
From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java
/** * Retourne la liste des langues sous forme de MAP (nom + id) si le * thesaurus n'existe pas dans la langue demande, on rcupre seulement son * id// w w w.j ava2 s .c o m * * @param ds * @param idLang * @return */ public Map getListThesaurus(HikariDataSource ds, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; Map map = new HashMap(); ArrayList tabIdThesaurus = new ArrayList(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select DISTINCT id_thesaurus from thesaurus"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { while (resultSet.next()) { tabIdThesaurus.add(resultSet.getString("id_thesaurus")); } for (Object tabIdThesauru : tabIdThesaurus) { query = "select title from thesaurus_label where" + " id_thesaurus = '" + tabIdThesauru + "'" + " and lang = '" + idLang + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { resultSet.next(); if (resultSet.getRow() == 0) { map.put("(" + tabIdThesauru + ")", tabIdThesauru); } else { map.put(resultSet.getString("title") + "(" + tabIdThesauru + ")", tabIdThesauru); } } else { } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting Map of thesaurus : " + map.toString(), sqle); } return map; }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
private boolean thumbnailIsFine(File file) { boolean isFine = false; BufferedImage image = null;//w ww. j a v a2 s . co m try { image = ImageIO.read(file); } catch (IOException e) { log.error(e.getMessage()); return false; } log.info("Recording thumbnail dimensions: {}x{}", image.getWidth(), image.getHeight()); Map<String, Long> colorMap = this.averageColor(image); log.info("Thumbnail map color: {}", colorMap.toString()); isFine = this.checkVideoAverageRgbGreen(colorMap); return isFine; }
From source file:com.moviejukebox.plugin.FanartTvPlugin.java
/** * Scan and return the artwork type requested (or all if type is null) * * @param movie/* w w w . ja va2s .c o m*/ * @param artworkType Artwork type required (null is all) * @return */ public boolean scan(Movie movie, final FTArtworkType artworkType) { if (artworkType != null && !ARTWORK_TYPES.containsKey(artworkType)) { LOG.debug("{} not required", artworkType.toString().toLowerCase()); return true; } ArtworkList ftArtwork; String requiredLanguage; Map<FTArtworkType, Integer> requiredArtworkTypes = new EnumMap<>(ARTWORK_TYPES); if (movie.isTVShow()) { int tvdbid = NumberUtils.toInt(movie.getId(TheTvDBPlugin.THETVDB_PLUGIN_ID), 0); // Remove the non-TV types for (FTArtworkType at : requiredArtworkTypes.keySet()) { if (at.getSourceType() != FTSourceType.TV) { requiredArtworkTypes.remove(at); } } // Get all the artwork to speed up any subsequent requests ftArtwork = getTvArtwork(tvdbid); requiredLanguage = LANG_TV; } else { int tmdbId = NumberUtils.toInt(movie.getId(TheMovieDbPlugin.TMDB_PLUGIN_ID), 0); // Remove the non-Movie types for (FTArtworkType at : requiredArtworkTypes.keySet()) { if (at.getSourceType() != FTSourceType.MOVIE) { requiredArtworkTypes.remove(at); } } // Get all the artwork to speed up any subsequent requests ftArtwork = getMovieArtwork(tmdbId, movie.getId(ImdbPlugin.IMDB_PLUGIN_ID)); requiredLanguage = LANG_MOVIE; } if (ftArtwork.hasArtwork()) { LOG.debug("Found {} artwork items", ftArtwork.getArtwork().size()); FTArtworkType ftType; for (Map.Entry<FTArtworkType, List<FTArtwork>> entry : ftArtwork.getArtwork().entrySet()) { LOG.trace("Found '{}' with {} items", entry.getKey(), entry.getValue().size()); ftType = entry.getKey(); if (requiredArtworkTypes.containsKey(ftType) && requiredArtworkTypes.get(ftType) > 0) { LOG.trace("Processing '{}' artwork, {} are requried", entry.getKey(), requiredArtworkTypes.get(ftType)); int left = processArtworkToMovie(movie, ftType, requiredLanguage, requiredArtworkTypes.get(ftType), entry.getValue()); // Update the required artwork counter requiredArtworkTypes.put(ftType, left); // remove the count from the requiredQuantity } } int requiredQuantity = 0; for (Map.Entry<FTArtworkType, Integer> entry : requiredArtworkTypes.entrySet()) { requiredQuantity += entry.getValue(); } if (requiredQuantity > 0) { LOG.debug("Not all required artwork was found for '{}' - {}", movie.getBaseName(), requiredArtworkTypes.toString()); return false; } LOG.debug("All required artwork was found for '{}'", movie.getBaseName()); return true; } LOG.debug("No artwork found for {}", movie.getBaseName()); return false; }
From source file:dev.meng.wikipedia.profiler.metadata.Metadata.java
private List<Map<String, Object>> queryRevisionListWorker(String lang, String pageId, String cont, String start, String end) {//from w w w . j a va 2 s .com Map<String, Object> params = new HashMap<>(); params.put("format", "json"); params.put("action", "query"); params.put("pageids", pageId); params.put("prop", "revisions"); params.put("rvprop", "ids|timestamp"); params.put("rvstart", start); params.put("rvend", end); params.put("rvdir", "newer"); if (cont != null) { params.put("rvcontinue", cont); } List<Map<String, Object>> result = new LinkedList<>(); try { String urlString = StringUtils.replace(Configure.METADATA.API_ENDPOINT, lang) + "?" + StringUtils.mapToURLParameters(params); URL url = new URL(urlString); JSONObject response = queryForJSONResponse(url); try { JSONObject pageRecord = response.getJSONObject("query").getJSONObject("pages") .getJSONObject(pageId); if (pageRecord.has("revisions")) { JSONArray revisions = pageRecord.getJSONArray("revisions"); for (int i = 0; i < revisions.length(); i++) { JSONObject revision = revisions.getJSONObject(i); Map<String, Object> record = new HashMap<>(); record.put("revid", Long.toString(revision.getLong("revid"))); record.put("timestamp", StringUtils.parseTimestamp(revision.getString("timestamp"), Configure.METADATA.TIMESTAMP_FORMAT)); result.add(record); } } String queryContinue = null; if (response.has("query-continue")) { queryContinue = response.getJSONObject("query-continue").getJSONObject("revisions") .get("rvcontinue").toString(); } if (queryContinue != null) { List<Map<String, Object>> moreResult = queryRevisionListWorker(lang, pageId, queryContinue, start, end); result.addAll(moreResult); } } catch (Exception ex) { LogHandler.log(this, LogLevel.WARN, "Error in response: " + urlString + ", " + response.toString() + ", " + ex.getMessage()); } } catch (UnsupportedEncodingException ex) { LogHandler.log(this, LogLevel.WARN, "Error in encoding: " + params.toString() + ", " + ex.getMessage()); } catch (MalformedURLException ex) { LogHandler.log(this, LogLevel.ERROR, ex); } catch (IOException ex) { LogHandler.log(this, LogLevel.ERROR, ex); } return result; }
From source file:dev.meng.wikipedia.profiler.metadata.Metadata.java
private Map<String, String>[] queryPageIdsBatchWorker(String lang, String titles, String cont) { Map<String, Object> params = new HashMap<>(); params.put("format", "json"); params.put("action", "query"); params.put("titles", titles); params.put("prop", "info"); if (cont != null) { params.put("incontinue", cont); }//from ww w . ja v a2s.c om Map<String, String> norm = new HashMap<>(); Map<String, String> result = new HashMap<>(); try { String urlString = StringUtils.replace(Configure.METADATA.API_ENDPOINT, lang) + "?" + StringUtils.mapToURLParameters(params); URL url = new URL(urlString); JSONObject response = queryForJSONResponse(url); if (response != null && response.has("query")) { JSONObject responseQuery = response.getJSONObject("query"); if (responseQuery.has("normalized")) { JSONArray normalizations = responseQuery.getJSONArray("normalized"); for (int i = 0; i < normalizations.length(); i++) { JSONObject normalization = normalizations.getJSONObject(i); norm.put(normalization.getString("from"), normalization.getString("to")); } } if (responseQuery.has("pages")) { JSONObject pages = responseQuery.getJSONObject("pages"); for (String pageKey : (Set<String>) pages.keySet()) { if (Long.parseLong(pageKey) > 0) { JSONObject page = pages.getJSONObject(pageKey); if (page.has("ns") && page.getLong("ns") == 0L) { result.put(page.getString("title"), Long.toString(page.getLong("pageid"))); } } } } String queryContinue = null; if (response.has("query-continue")) { queryContinue = response.getJSONObject("query-continue").getJSONObject("info") .getString("incontinue"); } if (queryContinue != null) { Map<String, String>[] moreResult = queryPageIdsBatchWorker(lang, titles, queryContinue); norm.putAll(moreResult[0]); result.putAll(moreResult[1]); } } } catch (UnsupportedEncodingException ex) { LogHandler.log(this, LogLevel.WARN, "Error in encoding: " + params.toString() + ", " + ex.getMessage()); } catch (MalformedURLException ex) { LogHandler.log(this, LogLevel.ERROR, ex); } catch (IOException ex) { LogHandler.log(this, LogLevel.ERROR, ex); } return new Map[] { norm, result }; }
From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java
/** * retourne la liste des thsaurus d'un utilisateur * @param ds/*from ww w .jav a2s. c o m*/ * @param idUser * @param idLang * @return */ public Map getListThesaurusOfUser(HikariDataSource ds, int idUser, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; Map map = new HashMap(); ArrayList tabIdThesaurus = new ArrayList(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT DISTINCT user_role.id_thesaurus FROM" + " user_role WHERE" + " id_user = " + idUser; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { while (resultSet.next()) { if (!resultSet.getString("id_thesaurus").isEmpty()) tabIdThesaurus.add(resultSet.getString("id_thesaurus")); } for (Object tabIdThesauru : tabIdThesaurus) { query = "select title from thesaurus_label where" + " id_thesaurus = '" + tabIdThesauru + "'" + " and lang = '" + idLang + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { resultSet.next(); if (resultSet.getRow() == 0) { map.put("(" + tabIdThesauru + ")", tabIdThesauru); } else { map.put(resultSet.getString("title") + "(" + tabIdThesauru + ")", tabIdThesauru); } } else { } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting Map of thesaurus : " + map.toString(), sqle); } return map; }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
@Test @DisplayName("Video filter test") void videoFilterTest() throws Exception { setupBrowser("chrome"); log.info("Video filter test"); // Configure publisher user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElements(By.cssSelector("#openvidu-instance-0 .subscribe-checkbox")).get(0).click(); user.getDriver().findElements(By.cssSelector("#openvidu-instance-0 .send-audio-checkbox")).get(0).click(); user.getDriver().findElement(By.id("session-settings-btn-0")).click(); Thread.sleep(1000);//from www . ja v a 2 s . c o m user.getDriver().findElement(By.id("add-allowed-filter-btn")).click(); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); // Configure subscriber user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .publish-checkbox")).click(); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have a video only track", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true)); WebElement subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 video")); // Analyze Chrome fake video stream without gray filter (GREEN color) Map<String, Long> rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average green", checkVideoAverageRgbGreen(rgb)); // Try to apply none allowed filter user.getDriver().findElement(By.cssSelector(".filter-btn")).click(); WebElement filterTypeInput = user.getDriver().findElement(By.id("filter-type-field")); filterTypeInput.clear(); filterTypeInput.sendKeys("NotAllowedFilter"); user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Error [You don't have permissions to apply a filter]")); // Try to execute method over not applied filter user.getDriver().findElement(By.id("exec-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "has no filter applied in session")); // Apply allowed video filter filterTypeInput.clear(); filterTypeInput.sendKeys("GStreamerFilter"); WebElement filterOptionsInput = user.getDriver().findElement(By.id("filter-options-field")); filterOptionsInput.clear(); filterOptionsInput.sendKeys("{\"command\": \"videobalance saturation=0.0\"}"); user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter applied")); // Try to apply another filter user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "already has a filter applied in session")); // Analyze Chrome fake video stream with gray filter (GRAY color) user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 2); Thread.sleep(500); rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average gray", checkVideoAverageRgbGray(rgb)); // Execute filter method WebElement filterMethodInput = user.getDriver().findElement(By.id("filter-method-field")); filterMethodInput.clear(); filterMethodInput.sendKeys("setElementProperty"); WebElement filterParamsInput = user.getDriver().findElement(By.id("filter-params-field")); filterParamsInput.clear(); filterParamsInput.sendKeys("{\"propertyName\":\"saturation\",\"propertyValue\":\"1.0\"}"); user.getDriver().findElement(By.id("exec-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter method executed")); // Analyze Chrome fake video stream without gray filter (GREEN color) user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 4); Thread.sleep(500); rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average green", checkVideoAverageRgbGreen(rgb)); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); // Publisher leaves and connects with active filter user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 2); user.getEventManager().waitUntilEventReaches("connectionDestroyed", 1); user.getEventManager().waitUntilEventReaches("sessionDisconnected", 1); user.getDriver().findElement(By.id("publisher-settings-btn-0")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(500); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .join-btn")).click(); user.getEventManager().waitUntilEventReaches("connectionCreated", 7); user.getEventManager().waitUntilEventReaches("accessAllowed", 2); user.getEventManager().waitUntilEventReaches("streamCreated", 4); user.getEventManager().waitUntilEventReaches("streamPlaying", 4); // Analyze Chrome fake video stream with gray filter (GRAY color) subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 video")); rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average gray", checkVideoAverageRgbGray(rgb)); // Remove filter user.getDriver().findElement(By.cssSelector(".filter-btn")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("remove-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter removed")); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6); Thread.sleep(1000); // Analyze Chrome fake video stream with gray filter (GREEN color) rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average green", checkVideoAverageRgbGreen(rgb)); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); gracefullyLeaveParticipants(2); }
From source file:com.redsqirl.workflow.server.connect.HDFSInterface.java
protected Map<String, String> getProperties(String path, FileStatus stat) throws RemoteException { Map<String, String> prop = new LinkedHashMap<String, String>(); try {// w ww . java 2 s . c om if (stat == null) { logger.debug("File status not available for " + path); return null; } else { if (stat.isDir()) { prop.put(key_type, "directory"); prop.put(key_children, "true"); } else { prop.put(key_type, "file"); prop.put(key_children, "false"); double res = stat.getBlockSize(); boolean end = res < 1024; int pow = 0; while (!end) { res /= 1024; ++pow; end = res < 1024; } DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(1); String size = df.format(res); if (pow == 1) { size += "K"; } else if (pow == 2) { size += "M"; } else if (pow == 3) { size += "G"; } else if (pow == 4) { size += "T"; } else if (pow == 5) { size += "P"; } else if (pow == 6) { size += "E"; } else if (pow == 7) { size += "Z"; } else if (pow == 8) { size += "Y"; } prop.put(key_size, size); } } prop.put(key_owner, stat.getOwner()); prop.put(key_group, stat.getGroup()); prop.put(key_permission, stat.getPermission().toString()); // fs.close(); } catch (Exception e) { logger.error("Not expected exception: " + e); logger.error(e.getMessage()); } logger.debug("Properties of " + path + ": " + prop.toString()); return prop; }
From source file:com.novartis.opensource.yada.YADARequest.java
/** * Takes all parameters and values from {@code paraMap}, typically set in the {@link javax.servlet.http.HttpServletRequest}, and * adds them to a local {@link java.util.Map}. This is called by {@link Service#handleRequest(HttpServletRequest)}. * The inclusion of the map enables the use of otherwise unsupported url parameters in plugins. * @param paraMap the parameter map originally set in the request * @see Service#handleRequest(String, Map) *///from w ww. j a v a 2s . co m public void setParameterMap(Map<String, String[]> paraMap) { this.getParameterMap().putAll(paraMap); l.debug(getFormattedDebugString("parameterMap", paraMap.toString())); }