/** * Walk down the JSON nodes specified by the path and retrieve the target * JSONArray. * * @param path : Variable length array of path segments * @return JSONArray : The target node, or NULL if path invalid or not an * array */ @Override public JSONArray getArray(Object... path) { JSONArray array = super.getArray(path); if (array == null && systemConfig != null) { return systemConfig.getArray(path); } return array; }
public JsonObject findJsonObjectWithKey(String keyName) { Object[] reportCriteriaOptions = reportCriteriaOptionsJson.getArray( "results").toArray(); for (Object object : reportCriteriaOptions) { JsonObject jsonObject = (JsonObject) object; if (keyName.equals(jsonObject.get("key"))) { return jsonObject; } } return null; }
/** * <p> * Retrieve a list of JsonSimple objects found on the given path. Note that * this is a utility function, and not designed for data traversal. It * <b>will</b> only retrieve valid JsonObjects found on the provided node, * and wrap them in JsonSimple objects. * </p> * * <p> * Other objects found on that path will be ignored, and if the path itself * is not a JSONArray or not found, the function will return NULL. * </p> * * @param path : An array of indeterminate length to use as the path * @return List<JsonSimple> : A list of JSONSimple objects, or null */ public List<JsonSimple> getJsonSimpleList(Object... path) { JSONArray array = getArray(path); if (isArray(array)) { return JsonSimple.toJavaList(array); } return null; }
/** * Generates the report specific query from parameters */ @Override public String getQueryAsString() { String query = ""; JsonObject queryFilters = config.getObject("query", "filter"); String[] keyArray = Arrays.copyOf( new ArrayList<Object>(queryFilters.keySet()).toArray(), queryFilters.keySet().size(), String[].class); List<String> keys = Arrays.asList(keyArray); java.util.Collections.sort(keys); reportCriteriaOptionsJson.getArray("results"); query += processDateCriteria(queryFilters); query += processShowCriteria(queryFilters); int i = 1; /*while (true) { if (keys.indexOf("report-criteria." + i + ".dropdown") == -1) { break; } query += processReportCriteria(queryFilters, i); i++; }*/ query += " AND workflow_id:dataset"; return query; }
private void getMintStats(Stat stat, String query, StatisticalReport report) throws IOException { StringBuilder param = new StringBuilder(); param.append("dateFrom="); param.append(report.getStrStartDate()); param.append("&dateTo="); param.append(report.getStrEndDate()); param.append("&published="); param.append(report.getStrPublished()); String targetUrl = stat.getUrl() + param.toString(); log.debug("Using url"+targetUrl); BasicHttpClient client = new BasicHttpClient(targetUrl); GetMethod get = new GetMethod(targetUrl); client.executeMethod(get); JsonSimple mintResult = new JsonSimple(get.getResponseBodyAsString()); for (String fldKey : stat.getFields()) { StatResult result = stat.getResults().get(fldKey); if (fldKey.indexOf(":") >= 0) { JSONArray groupList = mintResult.getArray(fldKey); for (Object entry : groupList) { String groupName = (String) entry; int counts = mintResult.getInteger(new Integer("0"), fldKey+"counts", groupName).intValue(); result.getGroupMap().put(groupName, new Integer(counts)); result.setCounts(result.getCounts()+counts); } } else { int counts = mintResult.getInteger(new Integer(-1), fldKey); result.setCounts(counts); } } }
/** * Initial load of the authorized key map * * @throws IOException */ public ApiKeyTokenService() throws IOException { JsonSimpleConfig sysconfig = new JsonSimpleConfig(); String apiKeyFilePath = sysconfig.getString(FascinatorHome.getPath(SECURITY_APIKEYS_JSON_PATH), "api", "apiKeyFile"); this.apiKeysFile = new File(apiKeyFilePath); if (!this.apiKeysFile.exists()) { updateAndSaveKeys(new JSONArray()); } JsonSimple apiKeyJson = new JsonSimple(apiKeysFile); this.clients = apiKeyJson.getArray("api", "clients"); initialiseKeyMap(); }
log.debug("Initializing ReportStats..."); statMap = new HashMap<String, Stat>(); JSONArray stats = config.getArray("config", "stats"); int idx = 0; if (stats!=null) { String rows = config.getString("0", "config", "stats", idx, "params", "rows"); stat = new Stat(name, query, fq, rows); JSONArray fieldsArray = config.getArray("config", "stats", idx, "fields"); for (Object fieldObj : fieldsArray) { JsonObject field = (JsonObject) fieldObj; String url = new JsonSimple(jsonStat).getString("http://localhost:9001/mint", "url"); stat = new Stat(name, url); JSONArray fieldsArray = config.getArray("config", "stats", idx, "fields"); for (Object fieldObj : fieldsArray) { JsonObject field = (JsonObject) fieldObj;
JSONArray newRelations = message.getArray("relationships"); if (toRespond == null && newRelations == null) { log.warn("This request requires no responses and specifies"
JSONArray newRelations = message.getArray("relationships"); if (toRespond == null && newRelations == null) { log.warn("This request requires no responses and specifies"
private void buildManifest() throws StorageException { Map<String, Payload> manifest = getManifest(); BlobStore blobStore = BlobStoreClient.getClient(); Blob manifestBlob = blobStore.getBlob(BlobStoreClient.getContainerName(), getId() + "/object-manifest"); if (manifestBlob == null) { String manifestString = "{}"; manifestBlob = blobStore.blobBuilder(getId() + "/object-manifest").build(); manifestBlob.setPayload(manifestString); blobStore.putBlob(BlobStoreClient.getContainerName(), manifestBlob); } else { InputStreamReader isr; try { JsonSimple manifestObject = new JsonSimple(manifestBlob.getPayload().openStream()); if (manifestObject.getArray("items") != null) { for (Object itemObject : manifestObject.getArray("items")) { JsonObject item = (JsonObject) itemObject; String name = (String) item.get("name"); Payload payload = new BlobStorePayload(getId(), name); if (PayloadType.Source.equals(payload.getType())) { setSourceId(name); } manifest.put(name, payload); } } } catch (IOException e) { new StorageException("Failed to build manifest", e); } } }
@ApiOperation(value = "create a new ReDBox Object", tags = "object") @ApiImplicitParams({ @ApiImplicitParam(name = "skipReindex", value = "Skip the reindex process. Useful if you are batching many changes to a ReDBox object at once.", required = false, allowMultiple = false, dataType = "boolean"), @ApiImplicitParam(name = "oid", value = "The desired object identifier. If not supplied, one will be randomly generated", required = false, allowMultiple = false, dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "An object is created"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Post("json") public String harvestObjects(JsonRepresentation data) throws IOException, PluginException, MessagingException { JsonObject responseJsonObject = new JsonObject(); String packageType = getAttribute("packageType"); JSONArray responses = new JSONArray(); JsonSimple batchJson = new JsonSimple(data.getText()); JSONArray recordsArray = batchJson.getArray("records"); for (Object recordObject : recordsArray) { JsonObject processResult = processRecord((JsonObject) recordObject, packageType); try { responses.add(processResult); } catch (Exception e) { log.error("Error processing record in harvest", e); JsonObject responseObject = new JsonObject(); responseObject.put("status", "error"); responseObject.put("reason", ExceptionUtils.getStackTrace(e)); responses.add(responseObject); } } responseJsonObject.put("results", responses); return new JsonSimple(responseJsonObject).toString(); }