protected String getSuccessResponseString(String oid) { return new JsonSimple(getSuccessResponse(oid)).toString(true); } }
@SuppressWarnings(value = { "unchecked" }) private void loadIncludedDir(JsonSimple config) { List<String> extList = config.getStringList(INCLUDE_DIR_KEY_EXT); log.trace( "Inclusion directory found:'" + INCLUDE_DIR_KEY + "', merging all files in '" + config.getString(null, INCLUDE_DIR_KEY) + "' ending with: {}", extList); List<File> configFiles = new ArrayList(FileUtils.listFiles(new File( config.getString(null, INCLUDE_DIR_KEY)), extList .toArray(new String[extList.size()]), true)); JsonSimple jsonConfig = new JsonSimple(configFile); mergeConfig(config.getJsonObject(), jsonConfig.getJsonObject()); } catch (IOException e) { log.error("Failed to load file: {}", configFile);
/** * Retrieve the Boolean value on the given path. * * <strong>IMPORTANT:</strong> The default value only applies if the path is * not found. If a string on the path is found it will be considered * <b>false</b> unless the value is 'true' (ignoring case). This is the * default behaviour of the Boolean.parseBoolean() method. * * @param defaultValue : The fallback value to use if the path is invalid or * not found * @param path : An array of indeterminate length to use as the path * @return Boolean : The Boolean value found on the given path, or null if * no default provided */ @Override public Boolean getBoolean(Boolean defaultValue, Object... path) { Boolean bool = super.getBoolean(null, path); if (bool == null) { if (systemConfig != null) { return systemConfig.getBoolean(defaultValue, path); } return defaultValue; } return bool; }
/** * <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; }
/** * <p> * Retrieve a map 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 JsonObject or not found, the function will return NULL. * </p> * * @param path : An array of indeterminate length to use as the path * @return Map<String, JsonSimple> : A map of JSONSimple objects, or null */ public Map<String, JsonSimple> getJsonSimpleMap(Object... path) { JsonObject object = getObject(path); if (isObject(object)) { return JsonSimple.toJavaMap(object); } return null; }
JsonObject toRespond = message.getObject("respond"); JSONArray newRelations = message.getArray("relationships"); if (toRespond == null && newRelations == null) { log.warn("This request requires no responses and specifies" metadata = new JsonSimple(inStream); inStream.close(); } catch (IOException ex) { JSONArray responses = metadata.writeArray("responses"); boolean duplicate = false; String newOid = (String) toRespond.get("oid"); JSONArray relations = metadata.writeArray("relationships"); for (JsonSimple newRelation : JsonSimple.toJavaList(newRelations)) { boolean duplicate = false; String uniqueString = newRelation.toString(); for (JsonSimple relation : JsonSimple.toJavaList(relations)) { String storedUnique = relation.getString(null, "uniqueString"); if (uniqueString.equals(storedUnique)) { newRelation.getJsonObject().put( "uniqueString", uniqueString); relations.add(newRelation.getJsonObject()); String jsonString = metadata.toString(true);
JSONArray relations = data.writeArray("relationships"); for (Object relation : relations) { JsonSimple json = new JsonSimple((JsonObject) relation); String broker = json.getString(brokerUrl, "broker"); boolean localRecord = broker.equals(brokerUrl); String relatedId = json.getString(null, "identifier"); String relatedOid = json.getString(null, "oid"); if (relatedOid == null && localRecord) { String identifier = json.getString(null, "identifier"); if (identifier == null) { log.error("Cannot resolve identifer: '{}'", identifier); boolean authority = json.getBoolean(false, "authority"); if (authority) { boolean isCurated = json.getBoolean(false, "isCurated"); if (isCurated) { log.debug(" * Publishing '{}'", relatedId);
public JsonSimple parseMessage(JsonSimple message) throws TransactionException { log.debug("\n{}", message.toString(true)); JsonObject harvester = message.getObject("harvester"); String repoType= message.getString("", "indexer", "params", "repository.type"); if (harvester != null && !"Attachment".equalsIgnoreCase(repoType)) { try { String oid = message.getString(null, "oid"); JsonSimple response = new JsonSimple(); audit(response, oid, "Tool Chain"); String task = message.getString(null, "task"); if (task != null) { String oid = message.getString(null, "oid"); JsonSimple response = new JsonSimple(); workflowCuration(response, message); return response; JsonSimple response = new JsonSimple(); String eventType = message.getString(null, "eventType"); String newStep = message.getString(null, "newStep"); .getBoolean(false, "quickIndex"); if (quickIndex) { JsonObject order = newIndex(response, oid);
/** * Accept and parse raw JSON data from an InputStream. Field name String * literals will be broken down into meaningful JSON data structures. * * @param input The form data to parse from an InputStream * @return JsonSimple The parsed form data in JSON * @throws IOException if there are errors reading/parsing the form data */ public static JsonSimple parse(InputStream input) throws IOException { JsonSimple inputData = new JsonSimple(input); JsonSimple responseData = new JsonSimple(); // Go through every top level node JsonObject object = inputData.getJsonObject(); for (Object key : object.keySet()) { // Ignoring some non-form related nodes String strKey = validString(key); if (!EXCLUDED_FIELDS.contains(strKey)) { // And parse them into the repsonse String data = validString(object.get(key)); parseField(responseData, strKey, data); } } return responseData; }
itemConfig = new JsonSimple(jsonConfig); } catch (IOException ex) { throw new TransformerException("Invalid configuration! '{}'", ex); .getString(systemPayload, "sourcePayload"); Payload sourcePayload = null; try { json = new JsonSimple(sourcePayload.open()); sourcePayload.close(); } catch (Exception ex) { String portalId = itemConfig.getString(systemPortal, "portalId"); vc.put("urlBase", urlBase + portalId); JsonObject params = (JsonObject) itemConfig.getJsonObject().get("velocityContextParams"); if (params != null) { for (Object key : params.keySet()) { String payloadName = itemConfig.getString(payloadName(file.getName()), "outputFilename"); log.info("payloadName is: " + payloadName); if (itemConfig.getBoolean(false, "transformSource")) { payloadName = sourcePayload.getId();
JsonSimple options = new JsonSimple(getJsonConfig().getObject("harvester", "csv")); String filePath = options.getString(null, "fileLocation"); if (filePath == null) { throw new HarvesterException("No data file provided!"); idPrefix = options.getString("", "recordIDPrefix"); maxRows = options.getInteger(-1, "maxRows"); delimiter = options.getString(String.valueOf(DEFAULT_DELIMITER), "delimiter").charAt(0); ignoredFields = getStringList(options, "ignoreFields"); includedFields = getStringList(options, "includedFields"); multiValueFields = getStringList(options, "multiValueFields"); multiValueFieldDelimiter = options.getString(String.valueOf(DEFAULT_MULTI_VALUE_FIELD_DELIMITER), "multiValueFieldDelimiter").charAt(0); payloadId = options.getString(DEFAULT_PAYLOAD_ID, "payloadId"); batchSize = options.getInteger(DEFAULT_BATCH_SIZE, "batchSize"); hasMore = true; if (options.getBoolean(true, "headerRow")) { dataFields = Arrays.asList(csvReader.readNext()); } else { idColumn = options.getString(null, "idColumn"); if (idColumn != null && !dataFields.contains(idColumn)) { throw new HarvesterException("ID column '" + idColumn + "' was invalid or not found in the data!"); List<JsonSimple> filterConfig = options.getJsonSimpleList("filters"); if (filterConfig != null) { for(JsonSimple singleFilterConfig : filterConfig) {
/***** * Parse a JSON object from an inputstream * * @param in, the inputstream to read and parse * @return JsonConfigHelper object after parsing */ public JsonSimple getJsonObject(InputStream in) { try { return new JsonSimple(in); } catch (IOException ex) { log.error("Failure during stream access", ex); return null; } }
log.debug("Initializing ReportStats..."); statMap = new HashMap<String, Stat>(); JSONArray stats = config.getArray("config", "stats"); int idx = 0; if (stats!=null) { if (name.startsWith("redbox")) { String query = (String)jsonStat.get("query"); List<String> fq = config.getStringList("config", "stats", idx, "params", "fq"); 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;
private JsonSimple getMintData(DateFormat solrDateFormat) throws IOException { String url = systemConfig.getString("http://localhost:9001/mint", "proxy-urls", "Published_Records_By_Type") + "&dateFrom=" + solrDateFormat.format(fromDate) + "&dateTo=" + solrDateFormat.format(toDate); BasicHttpClient client = new BasicHttpClient(url); GetMethod get = new GetMethod(url); client.executeMethod(get); JsonSimple mintResult = new JsonSimple(get.getResponseBodyAsString()); return mintResult; }
JsonSimple config = new JsonSimple(text); String oid = config.getString(null, "oid"); log.info("Received notification request, object id={}", oid); List<String> toList = config.getStringList("to"); List<String> ccList = config.getStringList("cc"); String fromAddress = config.getString(this.fromAddress, "from", "address"); boolean isHtml = config.getString("plain", "format").equals("html") ? true : false; String fromName = config.getString(this.fromName, "from", "name"); String subject = config.getString(defaultSubject, "subject"); String body = config.getString(defaultBody, "body");
/** * Process an index order * * @param order The complete JSON order * @param boolean True if successful, otherwise False */ private boolean index(JsonSimple order) { // Sanity check our OID String oid = order.getString(null, "oid"); if (oid == null) { log.error("Invalid indexer order, no OID supplied!"); return false; } // Let the indexer do its thing try { indexer.index(oid); if (order.getBoolean(false, "forceCommit")) { indexer.commit(); } return true; } catch (IndexerException ex) { log.error("Error indexing OID '{}'", oid, ex); return false; } }
/** * Generate orders for the list of normal transformers scheduled to execute * on the tool chain * * @param message The incoming message, which contains the tool chain config * for this object * @param response The response to edit * @param oid The object to schedule for clearing */ private void scheduleTransformers(JsonSimple message, JsonSimple response) { String oid = message.getString(null, "oid"); List<String> list = message.getStringList( "transformer", "metadata"); if (list != null && !list.isEmpty()) { for (String id : list) { JsonObject order = newTransform(response, id, oid); // Add item config to message... if it exists JsonObject itemConfig = message.getObject( "transformerOverrides", id); if (itemConfig != null) { JsonObject config = (JsonObject) order.get("config"); config.putAll(itemConfig); } } } }
JsonSimple config = new JsonSimple(text); String oid = config.getString(null, "oid"); log.info("Received job, object id={}", oid); if (config.getBoolean(true, "commit")) { indexer.commit();
/** * Send AMQ Message to schedule indicated object is ready for transformation * and indexing. * * @param oid The Object ID to send. * @param config Item configuration for this object. */ private void queueHarvest(String oid, JsonSimple config) { // NOTE: The oid is being updated in memory here // (including in the cache) // This OK so long as this process remains single threaded // and only keys that are overwritten EVERY time are used; // like 'oid'. log.info("Sending oid: " + oid + " to the harvest queue"); JsonObject json; try { json = new JsonSimple(config.toString(false)).getJsonObject(); } catch (IOException e) { json = config.getJsonObject(); } json.put("oid", oid); try { messaging.queueMessage(toolChainEntry, json.toString()); } catch (Exception ex) { log.error("Failed sending OID '{}' to the harvest message queue!", oid); log.error("Error stacktrace: ", ex); } log.info("Finished sending oid: " + oid + " to the harvest queue"); }
List<String> exPath = config.getStringList("excludeCondition", "path"); String exValue = config.getString(null, "excludeCondition", "value"); if (exPath != null && !exPath.isEmpty() && exValue != null) { String value = baseNode.getString(null, exPath.toArray()); if (value != null && value.equals(exValue)) { log.info("Excluding relationship '{}' based on config", field); String exStartsWith = config.getString(null, "excludeCondition", "startsWith"); String exDoesntStartWith = config.getString(null, "excludeCondition", "doesntStartWith"); if (exPath != null && !exPath.isEmpty() && exStartsWith != null) { String value = baseNode.getString(null, exPath.toArray()); if (value != null && value.startsWith(exStartsWith)) { log.info("Excluding relationship '{}' based on config", field); String value = baseNode.getString(null, exPath.toArray()); if (value != null) { if (exDoesntStartWith instanceof String && !value.startsWith(exDoesntStartWith)) { List<String> idPath = config.getStringList("identifier"); if (idPath == null || idPath.isEmpty()) { log.error("Ignoring invalid relationship '{}'. No 'identifier'" String id = baseNode.getString(null, idPath.toArray()); if (id != null && !id.equals("")) { newRelation.put("identifier", id.trim()); String staticRelation = config.getString(null, "relationship");