private static String getJsonString(Collection<String> strings) { JSONArray array = new JSONArray(); if (strings != null && !strings.isEmpty()) { array.addAll(strings); } return array.toString(); } }
/** {@inheritDoc} */ @Override JSONObject toJson() { JSONObject ret = super.toJson(); if (hasSingleAttribute()) { ret.put("attribute",attributes.get(0)); } else if (!hasAllAttributes()) { JSONArray attrs = new JSONArray(); attrs.addAll(attributes); ret.put("attribute",attrs); } if (path != null) { ret.put("path",path); } return ret; }
@SuppressWarnings({"unchecked"}) public JSONObject getJSONObject() { JSONObject errorMessage = new JSONObject(); errorMessage.put(Constants.GUID, UUID.randomUUID().toString()); errorMessage.put(Constants.SENSOR_TYPE, "error"); if (sensorTypes.size() == 1) { errorMessage.put(ErrorFields.FAILED_SENSOR_TYPE.getName(), sensorTypes.iterator().next()); } else { errorMessage .put(ErrorFields.FAILED_SENSOR_TYPE.getName(), new JSONArray().addAll(sensorTypes)); } errorMessage.put(ErrorFields.ERROR_TYPE.getName(), errorType.getType()); addMessageString(errorMessage); addStacktrace(errorMessage); addTimestamp(errorMessage); addHostname(errorMessage); addRawMessages(errorMessage); addErrorHash(errorMessage); return errorMessage; }
/** * Transform an ArrayList into a JSONArray. * * @param list an ArrayList that we want to convert into a List. * @return list the list parameter. */ @SuppressWarnings("unchecked") private static JSONArray listToJson(List<String> list) { final JSONArray array = new JSONArray(); array.addAll(list); return array; } }
public JSONArray coerceTuple(TridentTuple tuple){ JSONArray array = new JSONArray(); array.addAll(tuple); return array; }
public JSONObject toJSON(){ JSONObject json = new JSONObject(); json.put("@source", source); json.put("@timestamp", DateFormat.getDateInstance().format(timestamp)); json.put("@source_host",sourceHost); json.put("@source_path",sourcePath); json.put("@message",message); json.put("@type",type); JSONArray temp = new JSONArray(); temp.addAll(tags); json.put("@tags", temp); JSONObject fieldTemp = new JSONObject(); fieldTemp.putAll(fields); json.put("@fields",fieldTemp); return json; }
@SuppressWarnings(value = { "unchecked" }) private void mergeConfig(Map targetMap, Map srcMap) { for (Object key : srcMap.keySet()) { Object src = srcMap.get(key); Object target = targetMap.get(key); if (target == null) { targetMap.put(key, src); } else { if (src instanceof Map && target instanceof Map) { mergeConfig((Map) target, (Map) src); } else if (src instanceof JSONArray && target instanceof JSONArray) { JSONArray srcArray = (JSONArray) src; JSONArray targetArray = (JSONArray) target; targetArray.addAll(srcArray); } else { targetMap.put(key, src); } } } }
/** * Return the list of flags and their data as a json string * * @return the flags */ public String getFlags() { JSONObject json = new JSONObject(); // writing the list of flags to json JSONArray warring = new JSONArray(); warring.addAll(warringClans.keySet()); json.put("warring", warring); json.put("homeX", homeX); json.put("homeY", homeY); json.put("homeZ", homeZ); json.put("homeWorld", homeWorld == null ? "" : homeWorld); return json.toString(); }
private static JSONObject toJSONObject(Map<String, Object> map) { JSONObject object = new JSONObject(); for (String key : map.keySet()) { Object content = map.get(key); if (content instanceof Collection) { JSONArray array = new JSONArray(); array.addAll((Collection<?>) content); object.put(key, array); } else if (content instanceof Map) { object.put(key, toJSONObject((Map<String, Object>) content)); } else { object.put(key, content); } } return object; } }
@Override public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { InputStream propsIn = SpringBatchConfigServlet.class.getClassLoader().getResourceAsStream("springbatch.properties"); httpServletResponse.setHeader("Content-type", "application/json"); if (propsIn == null) { writeEmpty(httpServletResponse.getWriter()); return; } Properties properties = new Properties(); properties.load(propsIn); JSONObject responseJson = new JSONObject(); JSONArray springBatchServersJson = new JSONArray(); List<? extends String> springBatchServers = Arrays.asList(properties.getProperty("springBatchServerList").split(",")); springBatchServersJson.addAll(springBatchServers); responseJson.put("springBatchServerList", springBatchServersJson); String res = "success"; httpServletResponse.getWriter().println(responseJson.toJSONString()); }
@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); } } // 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; }
@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); } } // 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; }
@Override public JSONObject jsonValueForSubject(Subject subject, Boolean timeStamp) throws IncomputableFieldException { List<TimedValue> timedValues = TimedValueUtils.getBySubjectAndAttribute(subject, getAttribute()); if (timedValues.isEmpty()) { throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel())); } JSONArray arr = new JSONArray(); arr.addAll(timedValues.stream().map(timedValue -> { JSONObject pair = new JSONObject(); pair.put("timestamp", timedValue.getId().getTimestamp().format(TimedValueId.DATE_TIME_FORMATTER)); pair.put("value", timedValue.getValue()); return pair; }).collect(Collectors.toList())); return withinMetadata(arr); } }
errorMsgList.addAll(errors); lraaForm.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws");
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);
/** * This is an ajax call triggered after a user submits the leave entry form. * If there is any error, it will return error messages as a json object. * * @param mapping * @param form * @param request * @param response * @return jsonObj * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward validateLeaveEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LeaveCalendarWSForm lcf = (LeaveCalendarWSForm) form; JSONArray errorMsgList = new JSONArray(); errorMsgList.addAll(LeaveCalendarValidationUtil.validateLeaveEntry(lcf)); lcf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }
@SuppressWarnings("unchecked") @Override 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); } }
@SuppressWarnings("unchecked") @Override 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); } }
@SuppressWarnings("unchecked") @ApiOperation(value = "get information about the ReDBox instance", tags = "info") @ApiResponses({ @ApiResponse(code = 200, message = "The datastreams are listed"), @ApiResponse(code = 500, message = "Server configuration not found", response = IOException.class) }) @Get("json") public String getServerInformation() throws IOException{ JsonObject responseObject = getSuccessResponse(null); JsonSimpleConfig config = new JsonSimpleConfig(); responseObject.put("institution", config.getString(null, "identity","institution")); responseObject.put("applicationVersion", config.getString(null, "redbox.version.string")); JSONArray packageTypes = new JSONArray(); if ("mint".equals(config.getString(null, "system"))) { packageTypes.addAll(getPackageTypesFromFileSystem()); } else { JsonObject packageTypesObject = config.getObject("portal", "packageTypes"); packageTypes.addAll(packageTypesObject.keySet()); } responseObject.put("packageTypes", packageTypes); return new JsonSimple(responseObject).toString(true); }
@SuppressWarnings("unchecked") @ApiOperation(value = "List datastreams in an object", tags = "datastream") @ApiResponses({ @ApiResponse(code = 200, message = "The datastreams are listed"), @ApiResponse(code = 500, message = "Oid does not exist in storage", response = StorageException.class) }) @Get("json") public JsonRepresentation getDatastreamList() throws StorageException, IOException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); JsonObject responseObject = getSuccessResponse(oid); JSONArray dataStreamIds = new JSONArray(); dataStreamIds.addAll(digitalObject.getPayloadIdList()); responseObject.put("datastreamIds", dataStreamIds); return new JsonRepresentation(new JsonSimple(responseObject).toString(true)); }