/** * <p> * Returns a reference to the underlying system configuration object. This * is meant to be used on conjunction with storeSystemConfig() to make * changes to the config file on disk. * </p> * * <p> * Normal modifications to this objects JSON are not written to disk unless * they they are made via writableSystemConfig(). * </p> * * @return JsonObject : A reference to the system configuration JSON object */ public JsonObject writableSystemConfig() { return systemConfig.getJsonObject(); }
public JsonObject getJsonObject() { if (payloadData != null) { return payloadData.getJsonObject(); } return indexedData.getJsonObject(); }
/** * <p> * Take all of the JsonSimple objects in the given Map and return a Map * having replace them all with their base JsonObjects. * </p> * * Useful in when combining stacks of JSON objects. * * @return String : The JSON String */ public static Map<String, JsonObject> fromJavaMap( Map<String, JsonSimple> from) { Map<String, JsonObject> response = new LinkedHashMap<String, JsonObject>(); if (from != null && !from.isEmpty()) { for (String key : from.keySet()) { response.put(key, from.get(key).getJsonObject()); } } return response; }
/** * Return the String representation of this object's JSON, optionally * formatted for human readability. * * @return String : The JSON String */ public String toString(boolean pretty) { // Simple, just a plain old string if (!pretty) { return jsonObject.toJSONString(); } // More complicated return printNode(null, getJsonObject(), ""); }
for (Object oKey : json.getJsonObject().keySet()) {
mergeConfig(config.getJsonObject(), jsonConfig.getJsonObject()); } catch (IOException e) { log.error("Failed to load file: {}", configFile);
/** * Get the requested node from the manifest. * * @param id : The node key to retrieve * @return ManifestNode : The retrieved node, null if not found */ public List<ManifestNode> getTopNodes() { List<ManifestNode> nodes = new ArrayList<ManifestNode>(); Map<String, JsonSimple> manifest = getJsonSimpleMap("manifest"); if (manifest == null) { return nodes; } for (String key : manifest.keySet()) { // This node ManifestNode manNode = new ManifestNode( manifest.get(key).getJsonObject()); manNode.setParentKey(null); manNode.setKey(key); nodes.add(manNode); } return nodes; }
/** * 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"); }
/** * Return a list of children for this node. The list will reflect the order * of the underlying manifest. * * @return List<ManifestNode> : List of child nodes. Will not return null, * a zero length List will be returned if no children are found. */ public List<ManifestNode> getChildren() { List<ManifestNode> response = new ArrayList<ManifestNode>(); Map<String, JsonSimple> children = getJsonSimpleMap("children"); if (children == null) { return response; } for (String key : children.keySet()) { ManifestNode manNode = new ManifestNode( children.get(key).getJsonObject()); manNode.setParentKey(this.getKey()); manNode.setKey(key); response.add(manNode); } return response; }
boolean systemHasIncludedDir = systemConfig.getJsonObject() .containsKey(INCLUDE_DIR_KEY); if (hasIncludedDir) {
public void mergeAttributes(User user) { try { attributes.clear(); setUsername(user.getUsername()); setSource(user.getSource()); String metaDataStr = user.describeMetadata(); Map<Object, Object> metaMap = new JsonSimple(metaDataStr) .getJsonObject(); for (Object keyObj : metaMap.keySet()) { String keyVal = keyObj.toString(); String valueType = metaMap.get(keyObj).toString(); if ("String".equalsIgnoreCase(valueType) && !keyVal.equals("username")) { String value = user.get(keyVal); HibernateUserAttribute attr = new HibernateUserAttribute( keyVal, value); attr.setUser(this); attributes.put(keyVal, attr); set(keyVal, value); } } } catch (IOException e) { log.debug("Error:", e); } } }
/** * To delete object processing from queue * * @param oid Object id * @param jsonFile Configuration file * @throws MessagingException if the message could not be sent */ private void queueDelete(String oid, File jsonFile) throws MessagingException { try { JsonObject json = new JsonSimple(jsonFile).getJsonObject(); json.put("oid", oid); json.put("deleted", "true"); messaging.queueMessage(toolChainEntry, json.toString()); } catch (IOException ioe) { log.error("Failed to parse message: {}", ioe.getMessage()); throw new MessagingException(ioe); } }
/** * To queue object to be processed * * @param oid Object id * @param jsonFile Configuration file * @param commit To commit each request to Queue (true) or not (false) * @param queueName Name of the queue to route to * @throws MessagingException if the message could not be sent */ private void queueHarvest(String oid, File jsonFile, boolean commit, String queueName) throws MessagingException { try { JsonObject json = new JsonSimple(jsonFile).getJsonObject(); json.put("oid", oid); if (commit) { json.put("commit", "true"); } messaging.queueMessage(queueName, json.toString()); } catch (IOException ioe) { log.error("Failed to parse message: {}", ioe.getMessage()); throw new MessagingException(ioe); } }
/** * Generate a fairly common list of orders to transform and index an object. * This mirrors the traditional tool chain. * * @param message The response to modify * @param message The message we received */ private void reharvest(JsonSimple response, JsonSimple message) { String oid = message.getString(null, "oid"); try { if (oid != null) { setRenderFlag(oid); // Transformer config JsonSimple itemConfig = getConfigFromStorage(oid); if (itemConfig == null) { log.error("Error accessing item configuration!"); return; } itemConfig.getJsonObject().put("oid", oid); // Tool chain scheduleTransformers(itemConfig, response); newIndex(response, oid); createTask(response, oid, "clear-render-flag"); } else { log.error("Cannot reharvest without an OID!"); } } catch (Exception ex) { log.error("Error during reharvest setup: ", ex); } }
/** * Merge the newly processed data with an (possible) existing data already * present, also convert the completed JSON merge into a Stream for storage. * * @param dataJson an instantiated JSON object containing data to store * @param metaJson an instantiated JSON object containing metadata to store * @param existing an instantiated JsonSimple object with any existing data * @throws IOException if any character encoding issues effect the Stream */ private InputStream streamMergedJson(JsonObject dataJson, JsonObject metaJson, JsonSimple existing) throws IOException { // Overwrite and/or create only nodes we consider new data existing.getJsonObject().put("recordIDPrefix", idPrefix); JsonObject existingData = existing.writeObject("data"); existingData.putAll(dataJson); JsonObject existingMeta = existing.writeObject("metadata"); existingMeta.putAll(metaJson); // Turn into a stream to return String jsonString = existing.toString(true); return IOUtils.toInputStream(jsonString, "UTF-8"); } }
return; itemConfig.getJsonObject().put("oid", 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; }
@ApiOperation(value = "updates the record's Object Metadata", tags="objectmeta") @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, defaultValue = "false", dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "The object metadata is updated"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Post("json") public String updateMetadataResource(JsonRepresentation data) throws IOException, PluginException, MessagingException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); JsonSimple metadataJson = new JsonSimple(data.getText()); JsonObject metadataObject = metadataJson.getJsonObject(); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); Properties metadata = digitalObject.getMetadata(); for (Object key : metadataObject.keySet()) { metadata.setProperty((String) key, (String) metadataObject.get(key)); } ByteArrayOutputStream output = new ByteArrayOutputStream(); metadata.store(output, null); ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray()); StorageUtils.createOrUpdatePayload(digitalObject, "TF-OBJ-META", input); reindex(oid); return getSuccessResponseString(oid); }
@ApiOperation(value = "gets the record's metadata", tags = "recordmeta") @ApiResponses({ @ApiResponse(code = 200, message = "The record's metadata is returned"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get("json") public String getMetadataResource() throws StorageException, IOException { JsonSimpleConfig config = new JsonSimpleConfig(); Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); String payloadId; if ("mint".equals(config.getString(null, "system"))) { payloadId = "metadata.json"; } else { payloadId = findTfPackagePayload(digitalObject); } Payload payload = digitalObject.getPayload(payloadId); JsonSimple metadataObject = new JsonSimple(payload.open()); return gson.toJson(metadataObject.getJsonObject()); }
IOUtils.toInputStream(gson.toJson(metadataJson.getJsonObject()), "utf-8"));