List of usage examples for org.json.simple JSONArray addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.apache.metron.alerts.TelemetryAlertsBolt.java
@SuppressWarnings("unchecked") public void execute(Tuple tuple) { LOG.trace("[Metron] Starting to process message for alerts"); JSONObject original_message = null;/*from w ww .j av a 2s . c om*/ String key = null; try { key = tuple.getStringByField("key"); original_message = (JSONObject) tuple.getValueByField("message"); if (original_message == null || original_message.isEmpty()) throw new Exception("Could not parse message from byte stream"); if (key == null) throw new Exception("Key is not valid"); LOG.trace("[Metron] Received tuple: " + original_message); JSONObject alerts_tag = new JSONObject(); Map<String, JSONObject> alerts_list = _adapter.alert(original_message); JSONArray uuid_list = new JSONArray(); if (alerts_list == null || alerts_list.isEmpty()) { System.out.println("[Metron] No alerts detected in: " + original_message); _collector.ack(tuple); _collector.emit("message", new Values(key, original_message)); } else { for (String alert : alerts_list.keySet()) { uuid_list.add(alert); LOG.trace("[Metron] Checking alerts cache: " + alert); if (cache.getIfPresent(alert) == null) { System.out.println("[Metron]: Alert not found in cache: " + alert); JSONObject global_alert = new JSONObject(); global_alert.putAll(_identifier); global_alert.putAll(alerts_list.get(alert)); global_alert.put("timestamp", System.currentTimeMillis()); _collector.emit("alert", new Values(global_alert)); cache.put(alert, ""); } else LOG.trace("Alert located in cache: " + alert); LOG.debug("[Metron] Alerts are: " + alerts_list); if (original_message.containsKey("alerts")) { JSONArray already_triggered = (JSONArray) original_message.get("alerts"); uuid_list.addAll(already_triggered); LOG.trace("[Metron] Messages already had alerts...tagging more"); } original_message.put("alerts", uuid_list); LOG.debug("[Metron] Detected alerts: " + alerts_tag); _collector.ack(tuple); _collector.emit("message", new Values(key, original_message)); } /* * if (metricConfiguration != null) { emitCounter.inc(); * ackCounter.inc(); } */ } } catch (Exception e) { e.printStackTrace(); LOG.error("Failed to tag message :" + original_message); e.printStackTrace(); _collector.fail(tuple); /* * if (metricConfiguration != null) { failCounter.inc(); } */ JSONObject error = ErrorUtils.generateErrorMessage("Alerts problem: " + original_message, e); _collector.emit("error", new Values(error)); } }
From source file:org.apache.metron.tagging.TelemetryTaggerBolt.java
@SuppressWarnings("unchecked") public void execute(Tuple tuple) { LOG.trace("[Metron] Starting to process message for alerts"); JSONObject original_message = null;//w ww . ja v a 2 s. c o m try { original_message = (JSONObject) tuple.getValue(0); if (original_message == null || original_message.isEmpty()) throw new Exception("Could not parse message from byte stream"); LOG.trace("[Metron] Received tuple: " + original_message); JSONObject alerts_tag = new JSONObject(); JSONArray alerts_list = _adapter.tag(original_message); LOG.trace("[Metron] Tagged message: " + alerts_list); if (alerts_list.size() != 0) { if (original_message.containsKey("alerts")) { JSONObject tag = (JSONObject) original_message.get("alerts"); JSONArray already_triggered = (JSONArray) tag.get("triggered"); alerts_list.addAll(already_triggered); LOG.trace("[Metron] Created a new string of alerts"); } alerts_tag.put("identifier", _identifier); alerts_tag.put("triggered", alerts_list); original_message.put("alerts", alerts_tag); LOG.debug("[Metron] Detected alerts: " + alerts_tag); } else { LOG.debug("[Metron] The following messages did not contain alerts: " + original_message); } _collector.ack(tuple); _collector.emit(new Values(original_message)); /*if (metricConfiguration != null) { emitCounter.inc(); ackCounter.inc(); }*/ } catch (Exception e) { e.printStackTrace(); LOG.error("Failed to tag message :" + original_message); e.printStackTrace(); _collector.fail(tuple); /* if (metricConfiguration != null) { failCounter.inc(); }*/ } }
From source file:org.apache.oozie.servlet.BaseAdminServlet.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private JSONArray availableTimeZonesToJsonArray() { JSONArray array = new JSONArray(); for (String tzId : TimeZone.getAvailableIDs()) { // skip id's that are like "Etc/GMT+01:00" because their display names are like "GMT-01:00", which is confusing if (!tzId.startsWith("Etc/GMT")) { JSONObject json = new JSONObject(); TimeZone tZone = TimeZone.getTimeZone(tzId); json.put(JsonTags.TIME_ZOME_DISPLAY_NAME, tZone.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")"); json.put(JsonTags.TIME_ZONE_ID, tzId); array.add(json);/*from ww w. j a v a 2 s.c om*/ } } // The combo box this populates cannot be edited, so the user can't type in GMT offsets (like in the CLI), so we'll add // in some hourly offsets here (though the user will not be able to use other offsets without editing the cookie manually // and they are not in order) array.addAll(GMTOffsetTimeZones); return array; }
From source file:org.apache.oozie.servlet.V2JobServlet.java
@SuppressWarnings("unchecked") @Override/*from w w w . java 2s.co m*/ JSONArray getActionRetries(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException { JSONArray jsonArray = new JSONArray(); String jobId = getResourceName(request); try { jsonArray.addAll(Services.get().get(DagEngineService.class).getDagEngine(getUser(request)) .getWorkflowActionRetries(jobId)); return jsonArray; } catch (BaseEngineException ex) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex); } }
From source file:org.apache.oozie.servlet.V2JobServlet.java
@SuppressWarnings("unchecked") @Override//from ww w . j a v a2 s . c o m protected JSONObject getCoordActionMissingDependencies(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException { String jobId = getResourceName(request); String actions = request.getParameter(RestConstants.JOB_COORD_SCOPE_ACTION_LIST); String dates = request.getParameter(RestConstants.JOB_COORD_SCOPE_DATE); try { List<Pair<CoordinatorActionBean, Map<String, ActionDependency>>> dependenciesList = Services.get() .get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request)) .getCoordActionMissingDependencies(jobId, actions, dates); JSONArray dependenciesArray = new JSONArray(); for (Pair<CoordinatorActionBean, Map<String, ActionDependency>> dependencies : dependenciesList) { JSONObject json = new JSONObject(); JSONArray parentJsonArray = new JSONArray(); for (String key : dependencies.getSecond().keySet()) { JSONObject dependencyList = new JSONObject(); JSONArray jsonArray = new JSONArray(); jsonArray.addAll(dependencies.getSecond().get(key).getMissingDependencies()); dependencyList.put(JsonTags.COORDINATOR_ACTION_MISSING_DEPS, jsonArray); dependencyList.put(JsonTags.COORDINATOR_ACTION_DATASET, key); parentJsonArray.add(dependencyList); } json.put(JsonTags.COORD_ACTION_FIRST_MISSING_DEPENDENCIES, CoordCommandUtils.getFirstMissingDependency(dependencies.getFirst())); json.put(JsonTags.COORDINATOR_ACTION_ID, dependencies.getFirst().getActionNumber()); json.put(JsonTags.COORDINATOR_ACTION_DATASETS, parentJsonArray); dependenciesArray.add(json); } JSONObject jsonObject = new JSONObject(); jsonObject.put(JsonTags.COORD_ACTION_MISSING_DEPENDENCIES, dependenciesArray); return jsonObject; } catch (CommandException e) { throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, e); } }
From source file:org.chromium.sdk.tests.internal.JsonBuilderUtil.java
@SuppressWarnings("unchecked") public static JSONArray jsonArray(JSONObject... objects) { JSONArray array = new JSONArray(); array.addAll(Arrays.asList(objects)); return array; }
From source file:org.daxplore.presenter.server.servlets.AdminPrefixServlet.java
@SuppressWarnings("unchecked") private static String listToJson(List<String> texts) { JSONArray jsonArray = new JSONArray(); jsonArray.addAll(texts); jsonArray.toJSONString();//from ww w .j a va2 s.c o m return jsonArray.toJSONString(); }
From source file:org.eclipse.birt.report.engine.emitter.json.JsonEmitter.java
@SuppressWarnings("unchecked") @Override// w w w . j av a 2s. c o m public void endTableGroup(ITableGroupContent tableGroup) throws BirtException { JSONObject groupObj = groupObjStack.pop(); JSONArray valueArray = new ArrayList<JSONArray>(groupObj.values()).get(0); valueArray.addAll(jsonObjectList); jsonObjectList.clear(); if (groupObjStack.size() != 0) { JSONObject parentGrpObj = groupObjStack.pop(); valueArray = new ArrayList<JSONArray>(parentGrpObj.values()).get(0); valueArray.add(groupObj); groupObjStack.push(parentGrpObj); } else { groupObjectList.add(groupObj); } }
From source file:org.epics.archiverappliance.utils.ui.GetUrlContent.java
/** * Combine JSON arrays from multiple URL's in sequence and return a JSON Array. * We need the supress warnings here as JSONArray is a raw collection. * /* ww w . j av a2s . c o m*/ * @param urlStrs multiple URLs * @return Combined JSON arrays */ @SuppressWarnings("unchecked") public static JSONArray combineJSONArrays(List<String> urlStrs) { JSONArray result = new JSONArray(); for (String urlStr : urlStrs) { try { logger.debug("Getting the contents of " + urlStr + " as a JSON array."); JSONParser parser = new JSONParser(); try (InputStream is = getURLContentAsStream(urlStr)) { JSONArray content = (JSONArray) parser.parse(new InputStreamReader(is)); if (content != null) { result.addAll(content); } else { logger.debug(urlStr + " returned an empty array"); } } } catch (IOException ex) { logger.error("Exception getting contents of internal URL " + urlStr, ex); } catch (ParseException pex) { logger.error( "Parse exception getting contents of internal URL " + urlStr + " at " + pex.getPosition(), pex); } } return result; }
From source file:org.exoplatform.addons.es.domain.Document.java
public String toJSON() { String json;//from ww w . ja va 2s . c o m JSONObject obj = new JSONObject(); if (getPermissions() != null) { JSONArray permissionsJSON = new JSONArray(); permissionsJSON.addAll(getPermissions()); obj.put("permissions", permissionsJSON); } if (getSites() != null) { JSONArray sitesJSON = new JSONArray(); sitesJSON.addAll(Arrays.asList(getSites())); obj.put("sites", sitesJSON); } if (getUrl() != null) obj.put("url", getUrl()); if (getLastUpdatedDate() != null) obj.put("lastUpdatedDate", getLastUpdatedDate().getTime()); if (getFields() != null) { for (String fieldName : getFields().keySet()) { obj.put(fieldName, getFields().get(fieldName)); } } json = obj.toJSONString(); return json; }