List of usage examples for java.util Map toString
public String toString()
From source file:org.apache.kylin.job.execution.ExecutableManager.java
public void addJobInfo(String id, Map<String, String> info) { if (info == null) { return;/* ww w.j a v a2 s . c om*/ } // post process if (info.containsKey(MR_JOB_ID) && !info.containsKey(ExecutableConstants.YARN_APP_ID)) { String jobId = info.get(MR_JOB_ID); if (jobId.startsWith("job_")) { info.put(YARN_APP_ID, jobId.replace("job_", "application_")); } } if (info.containsKey(YARN_APP_ID) && !StringUtils.isEmpty(config.getJobTrackingURLPattern())) { String pattern = config.getJobTrackingURLPattern(); try { String newTrackingURL = String.format(pattern, info.get(YARN_APP_ID)); info.put(YARN_APP_URL, newTrackingURL); } catch (IllegalFormatException ife) { logger.error("Illegal tracking url pattern: " + config.getJobTrackingURLPattern()); } } try { ExecutableOutputPO output = executableDao.getJobOutput(id); Preconditions.checkArgument(output != null, "there is no related output for job id:" + id); output.getInfo().putAll(info); executableDao.updateJobOutput(output); } catch (PersistentException e) { logger.error("error update job info, id:" + id + " info:" + info.toString()); throw new RuntimeException(e); } }
From source file:de.fhg.fokus.odp.middleware.ckan.CKANGatewayUtil.java
/** * Submit comment for a package.//from w w w. j a v a2s . co m * * @param dataSetId * the id of the dataset. * @param userId * the user ID. * @param date * the date of the commenting * @param comment * the comment. * @return true if everything is fine, false otherwise. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static boolean postDatasetComment(String dataSetId, String userId, Date date, String comment) { // check the parameters if (dataSetId == null || dataSetId.equals("") || userId == null || userId.equals("") || comment == null || comment.equals("")) { return false; } // get the package details Object obj = CKANGatewayCore.getDataSetDetails(dataSetId); if (obj == null) { return false; } // prepare the extras string // pick the extras Map mMap = (Map) obj; String resource = mMap.get("resources").toString(); Map eMap = (Map) mMap.get("extras"); JSONArray tArray = (JSONArray) mMap.get("tags"); JSONArray gArray = (JSONArray) mMap.get("groups"); // check weather extras is defined if (eMap != null) { JSONArray comments = null; try { if (eMap.get("comments") instanceof java.lang.String) { JSONParser parser = new JSONParser(); comments = (JSONArray) parser.parse((String) eMap.get("comments")); } else { comments = (JSONArray) eMap.get("comments"); } } catch (ParseException e) { log.log(Level.SEVERE, "Failed to parse result" + (String) eMap.get("comments")); } if (comments == null) { comments = new JSONArray(); } Map<String, String> toadd = new HashMap<String, String>(); toadd.put("userId", userId); toadd.put("comment", comment); toadd.put("date", date.toString()); comments.add(toadd); eMap.put("comments", comments); } // prepare the hash map for the update method HashMap<String, String> hm = new HashMap<String, String>(); hm.put("extras", eMap.toString()); hm.put("resources", resource); hm.put("tags", tArray.toJSONString()); hm.put("groups", gArray.toJSONString()); // update the meta data set HashMap<String, HashMap> res = CKANGatewayCore.updateDataSet(dataSetId, hm); boolean toreturn = (res != null); return toreturn; }
From source file:com.wizecommerce.hecuba.astyanax.AstyanaxBasedHecubaClientManager.java
@Override public CassandraResultSet readAllColumnsBySecondaryIndex(Map<String, String> parameters, int limit) { List<PreparedIndexExpression<K, String>> clauses = new ArrayList<PreparedIndexExpression<K, String>>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { PreparedIndexExpression<K, String> clause = columnFamily.newIndexClause().whereColumn(entry.getKey()) .equals().value(entry.getValue()); clauses.add(clause);/*from www.j a v a 2 s . c om*/ } OperationResult<Rows<K, String>> result; try { result = keyspace.prepareQuery(columnFamily).searchWithIndex() // .setStartKey(0L) .addPreparedExpressions(clauses).execute(); Rows<K, String> rowItems = result.getResult(); if (rowItems.size() > 0) { Row<K, String> row = rowItems.getRowByIndex(0); AstyanaxResultSet<K, String> resultSet = new AstyanaxResultSet<K, String>(row.getColumns()); return resultSet; } } catch (ConnectionException e) { log.warn("HecubaClientManager error while reading secondary index key " + parameters.toString()); if (log.isDebugEnabled()) { log.debug("Caught Exception", e); } } return null; }
From source file:webim.controller.WebimController.java
@RequestMapping(value = "/online", method = RequestMethod.POST) @ResponseBody// www. j a v a 2 s. c om public Map<String, Object> online(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("online....."); WebimEndpoint endpoint = currentEndpoint(request, response); String uid = endpoint.getId(); String show = request.getParameter("show"); if (show != null) { endpoint.setShow(show); } Map<String, Object> data = new HashMap<String, Object>(); List<WebimEndpoint> buddies = this.plugin.buddies(uid); //pending buddies ids that need to read buddy Set<String> pendingIds = new HashSet<String>(); String chatlinkIds = request.getParameter("chatlink_ids"); if (chatlinkIds != null) { for (String id : chatlinkIds.split(",")) { pendingIds.add(id); } ; } List<WebimHistory> offlineHistories = this.model.offlineHistories(uid, 100); for (WebimHistory h : offlineHistories) { pendingIds.add(h.getFrom()); } pendingIds.removeAll(buddyIds(buddies)); if (pendingIds.size() > 0) { buddies.addAll(this.plugin.buddiesByIds(uid, pendingIds.toArray(new String[pendingIds.size()]))); } List<WebimRoom> rooms = this.plugin.rooms(uid); rooms.addAll(this.model.rooms(uid)); // Forward Online to IM Server WebimClient client = this.client(endpoint, request, ""); Set<String> buddyIds = buddyIds(buddies); Set<String> roomIds = roomIds(rooms); try { data = client.online(buddyIds, roomIds); System.out.println(data.toString()); // Online Buddies Map<String, WebimEndpoint> buddyMap = new HashMap<String, WebimEndpoint>(); for (WebimEndpoint e : buddies) { buddyMap.put(e.getId(), e); } @SuppressWarnings("unchecked") Map<String, String> presences = (Map<String, String>) data.get("presences"); Iterator<String> it = presences.keySet().iterator(); while (it.hasNext()) { String key = it.next(); WebimEndpoint buddy = buddyMap.get(key); show = presences.get(key); if (!show.equals("invisible")) { buddy.setPresence("online"); buddy.setShow(show); } } Collection<WebimEndpoint> rtBuddies; if (this.config.getBoolean("show_unavailable")) { rtBuddies = buddyMap.values(); } else { rtBuddies = new ArrayList<WebimEndpoint>(); for (WebimEndpoint e : buddyMap.values()) { if (e.getPresence() == "online") rtBuddies.add(e); } } // need test this.model.offlineHistoriesReaded(uid); //data.remove("presences"); data.put("buddies", rtBuddies.toArray()); data.put("rooms", rooms.toArray()); data.put("new_messages", offlineHistories.toArray()); data.put("server_time", System.currentTimeMillis()); // TODO: / data.put("user", endpoint); } catch (Exception e) { e.printStackTrace(); data.put("success", false); data.put("error_msg", "IM Server is not found"); } return data; }
From source file:org.evosuite.utils.GenericClass.java
/** * Determine if there exists an instantiation of the type variables such * that the class matches otherType//w w w . j a v a 2s .c o m * * @param otherType * is the class we want to generate * @return */ public boolean canBeInstantiatedTo(GenericClass otherType) { if (isPrimitive() && otherType.isWrapperType()) return false; if (isAssignableTo(otherType)) return true; if (!isTypeVariable() && !otherType.isTypeVariable() && otherType.isGenericSuperTypeOf(this)) return true; Class<?> otherRawClass = otherType.getRawClass(); if (otherRawClass.isAssignableFrom(rawClass)) { logger.debug("Raw classes are assignable: {}, have: {}", otherType, toString()); Map<TypeVariable<?>, Type> typeMap = otherType.getTypeVariableMap(); if (otherType.isParameterizedType()) { typeMap.putAll(TypeUtils.determineTypeArguments(rawClass, (ParameterizedType) otherType.getType())); } logger.debug(typeMap.toString()); try { GenericClass instantiation = getGenericInstantiation(typeMap); if (equals(instantiation)) { logger.debug("Instantiation is equal to original, so I think we can't assign: {}", instantiation); if (hasWildcardOrTypeVariables()) return false; else return true; } logger.debug("Checking instantiation: {}", instantiation); return instantiation.canBeInstantiatedTo(otherType); } catch (ConstructionFailedException e) { logger.debug("Failed to instantiate {}", toString()); return false; } } // TODO logger.debug("Not assignable? Want: {}, have: {}", otherType, toString()); return false; }
From source file:org.jenkinsci.plugins.uithemes.model.UIThemeContribution.java
public Resource createUserLessResource(File userHome, UIThemeImplementation implementation) throws IOException { if (lessTemplate == null) { return null; }// w w w . j a va 2 s . c om Map<String, String> userConfig = getUserThemeImplConfig(userHome); if (userConfig.isEmpty() && implementation != null) { UIThemeImplSpec themeImplSpec = implementation.getThemeImplSpec(); if (themeImplSpec != null) { userConfig = themeImplSpec.getDefaultConfig(); } } File lessFile = UIThemesProcessor.getUserThemeImplLESSFile(themeName, themeImplName, userHome); StringWriter writer = new StringWriter(); try { lessTemplate.process(userConfig, writer); FileUtils.write(lessFile, writer.toString(), "UTF-8"); return new URLResource(lessFile.toURI().toURL(), this); } catch (TemplateException e) { throw new IOException(String.format( "Error applying user theme impl configuration to LESS resource template. UserHome '%s', ThemeImpl '%s'.\n" + " > There seems to be an issue/mismatch between the variables used in the template and those provided in the theme implementation configuration.\n" + " > Check for mismatches/omissions between the template variables and the theme configuration variables:\n" + " > Template Contributor: %s\n" + " > Template: %s\n" + " > Template Error Expression: ${%s} (Line %d, Column %d)\n" + " > Theme Implementation Config: %s\n", userHome.getAbsolutePath(), getQName().toString(), contributor.getName(), getTemplatePath(), e.getBlamedExpressionString(), e.getLineNumber(), e.getColumnNumber(), (userConfig.isEmpty() ? "{} !!EMPTY!!" : userConfig.toString())), e); } finally { writer.close(); } }
From source file:de.fhg.fokus.odp.middleware.ckan.CKANGatewayUtil.java
/** * Submit rating for a package [rating: number of stars, 1..5] * /*from w ww. ja v a 2 s . c o m*/ * @param dataSetId * the id of the dataset to rate. * @param userId * the ID of the user submitting the rating. * @param date * the date at which the rating takes place. * @param rating * the rating value. * @return true in case of success, false otherwise. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static boolean postDataSetRating(String dataSetId, String userId, Date date, int rating) { // check the parameters if (dataSetId == null || dataSetId.equals("") || userId == null || userId.equals("") || rating < 0 || rating > 5) { return false; } // get the package details Object obj = CKANGatewayCore.getDataSetDetails(dataSetId); if (obj == null) { return false; } // prepare the extras string // pick the extras Map mMap = (Map) obj; Map eMap = (Map) mMap.get("extras"); String resource = mMap.get("resources").toString(); JSONArray tArray = (JSONArray) mMap.get("tags"); JSONArray gArray = (JSONArray) mMap.get("groups"); // check weather extras is defined if (eMap != null) { JSONArray ratings = null; try { if (eMap.get("ratings") instanceof java.lang.String) { JSONParser parser = new JSONParser(); ratings = (JSONArray) parser.parse((String) eMap.get("ratings")); } else { ratings = (JSONArray) eMap.get("ratings"); } } catch (ParseException e) { log.log(Level.SEVERE, "Failed to parse result" + (String) eMap.get("ratings")); } if (ratings == null) { ratings = new JSONArray(); } Map<String, String> toadd = new HashMap<String, String>(); toadd.put("userId", userId); toadd.put("ratingValue", Integer.valueOf(rating).toString()); toadd.put("date", date.toString()); ratings.add(toadd); eMap.put("ratings", ratings); } // prepare the hash map for the update method HashMap<String, String> hm = new HashMap<String, String>(); hm.put("extras", eMap.toString()); hm.put("resources", resource); hm.put("tags", tArray.toJSONString()); hm.put("groups", gArray.toJSONString()); // update the meta data set HashMap<String, HashMap> res = CKANGatewayCore.updateDataSet(dataSetId, hm); boolean toreturn = (res != null); return toreturn; }
From source file:dev.meng.wikidata.fileusage.Fileusage.java
private void queryFileInfo(String lang, String title, FileInfo file) { Map<String, Object> params = new HashMap<>(); params.put("format", "json"); params.put("action", "query"); params.put("titles", title); params.put("prop", "imageinfo"); params.put("iiprop", "size"); try {/*from w ww. j a va2 s .com*/ String urlString = String.format(Configure.FILEUSAGE.API_ENDPOINT, lang) + "?" + StringUtils.mapToURLParameters(params, Configure.FILEUSAGE.DEFAULT_ENCODING); URL url = new URL(urlString); JSONObject response = HttpUtils.queryForJSONResponse(url, Configure.FILEUSAGE.DEFAULT_ENCODING); try { JSONObject pageMap = response.getJSONObject("query").getJSONObject("pages"); JSONObject pageRecord = pageMap.getJSONObject((String) pageMap.keys().next()); if (pageRecord.has("imageinfo")) { JSONArray fileInfoList = pageRecord.getJSONArray("imageinfo"); file.setSize(fileInfoList.getJSONObject(0).getLong("size")); } else { file.setSize(0L); } } catch (JSONException ex) { Logger.log(this.getClass(), LogLevel.WARNING, "Error in response: " + urlString + ", " + response.toString() + ", " + ex.getMessage()); } } catch (UnsupportedEncodingException ex) { Logger.log(this.getClass(), LogLevel.WARNING, "Error in encoding: " + params.toString() + ", " + ex.getMessage()); } catch (MalformedURLException ex) { Logger.log(this.getClass(), LogLevel.ERROR, ex); } catch (IOException ex) { Logger.log(this.getClass(), LogLevel.ERROR, ex); } catch (StringConvertionException ex) { Logger.log(this.getClass(), LogLevel.ERROR, ex); } }
From source file:org.gbif.ipt.task.GenerateDCAT.java
/** * This method loads the DCAT settings from dcatsettings.properties. *//*from w w w . j a v a2 s . co m*/ private Map<String, String> loadDCATSettings() { Map<String, String> loadedSettings = Maps.newHashMap(); Closer closer = Closer.create(); try { InputStream configStream = closer.register(streamUtils.classpathStream(DCAT_SETTINGS)); if (configStream == null) { LOG.error("Failed to load DCAT settings: " + DCAT_SETTINGS); } else { Properties properties = new Properties(); properties.load(configStream); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = StringUtils.trim((String) entry.getKey()); String value = StringUtils.trim((String) entry.getValue()); if (key != null && value != null) { loadedSettings.put(key, value); } else { throw new InvalidConfigException(InvalidConfigException.TYPE.INVALID_PROPERTIES_FILE, "Invalid properties file: " + DCAT_SETTINGS); } } LOG.debug("Loaded static DCAT settings: " + loadedSettings.toString()); } } catch (Exception e) { LOG.error("Failed to load DCAT settings from: " + DCAT_SETTINGS, e); } finally { try { closer.close(); } catch (IOException e) { LOG.debug("Failed to close input stream on DCAT settings file: " + DCAT_SETTINGS, e); } } return loadedSettings; }
From source file:dev.meng.wikidata.fileusage.Fileusage.java
private void queryPageInfoBatch(String lang, Map<String, PageInfo> pages) { Map<String, Object> params = new HashMap<>(); params.put("format", "json"); params.put("action", "query"); params.put("pageids", Joiner.on("|").join(pages.keySet())); params.put("prop", "info"); try {/*from w ww . j a v a2 s .c o m*/ String urlString = String.format(Configure.FILEUSAGE.API_ENDPOINT, lang) + "?" + StringUtils.mapToURLParameters(params, Configure.FILEUSAGE.DEFAULT_ENCODING); URL url = new URL(urlString); JSONObject response = HttpUtils.queryForJSONResponse(url, Configure.FILEUSAGE.DEFAULT_ENCODING); try { JSONObject pageInfos = response.getJSONObject("query").getJSONObject("pages"); for (String pageId : pages.keySet()) { JSONObject pageInfo = pageInfos.getJSONObject(pageId); PageInfo page = pages.get(pageId); page.setTitle(pageInfo.getString("title")); page.setSize(pageInfo.getLong("length")); page.setLastRevisionId(Long.toString(pageInfo.getLong("lastrevid"))); } } catch (JSONException ex) { Logger.log(this.getClass(), LogLevel.WARNING, "Error in response: " + urlString + ", " + response.toString() + ", " + ex.getMessage()); } } catch (UnsupportedEncodingException ex) { Logger.log(this.getClass(), LogLevel.WARNING, "Error in encoding: " + params.toString() + ", " + ex.getMessage()); } catch (MalformedURLException ex) { Logger.log(this.getClass(), LogLevel.ERROR, ex); } catch (IOException ex) { Logger.log(this.getClass(), LogLevel.ERROR, ex); } catch (StringConvertionException ex) { Logger.log(this.getClass(), LogLevel.ERROR, ex); } }