/***** * Parse RDF data stored in a payload * * @param payload containing the data * @return Model object after parsing */ public Model getRdfModel(Payload payload) { try { Model model = getRdfModel(payload.open()); payload.close(); return model; } catch (StorageException ioe) { log.info("Failed to read payload stream", ioe); } return null; }
/** * Creates a copy of the specified payload * * @param payload payload to copy */ public GenericPayload(Payload payload) { if (payload != null) { setId(payload.getId()); setLabel(payload.getLabel()); setContentType(payload.getContentType()); setType(payload.getType()); try { setInputStream(payload.open()); } catch (StorageException e) { log.error( "Error accessing input stream during payload creation", e); } } metaChanged = false; }
/** * Get a playload in JsonSimple format from the payload instance * * @param payload : Payload object * @return JsonSimple or null */ public JsonSimple getPayloadJsonSimple(Payload payload) { JsonSimple jsonSimple = null; if (payload == null) { return null; } try { jsonSimple = new JsonSimple(payload.open()); } catch (Exception e) { log.error("Failed to retrive payload. ID of payload: {}, more: {}", payload.getId(), e.getMessage()); } return jsonSimple; }
/***** * Find the MIME type to use at display time, giving first priority to the * preview payload, then to the source payload. * * @param indexerFormats The list of types so far allocated by the rules * script. * @param object The object being indexed. * @param preview The preview payload * @return String The MIME type to be used at display time. */ public String getDisplayMimeType(String[] indexerFormats, DigitalObject object, String preview) { // The source should be the first type given by the indexer String result = indexerFormats[0]; // Lets look for a preview payload if (preview != null) { try { Payload payload = object.getPayload(preview); PayloadType type = payload.getType(); if (type != null && type.equals(PayloadType.Preview)) { if (payload.getContentType() != null) { result = payload.getContentType(); } } } catch (StorageException ex) { log.error("Error accessing payload: '{}'", preview, ex); } } return result; }
JsonSimple workflow = null; try { workflow = new JsonSimple(wfPayload.open()); } catch (Exception ex) { throw ex; } finally { wfPayload.close(); String mimeType = payload.getContentType(); if (mimeType == null) { mimeType = "application/octet-stream";
setSourceId(null); payload.setType(PayloadType.Annotation); payload.setLabel(METADATA_LABEL); Payload metaPayload = man.get(METADATA_PAYLOAD); metadata = new Properties(); InputStream is = metaPayload.open(); metadata.load(is); metadata.setProperty("metaPid", METADATA_PAYLOAD); metaPayload.close(); is.close(); log.debug("Closed init metadata input Stream");
json = new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error parsing existing JSON: '{}' => '{}'", "Error parsing existing JSON: ", ex); } finally { payload.close(); payload.setContentType("application/json"); payload.close(); } catch (Exception ex) { log.error("Error setting Payload MIME type and closing: ", ex);
in = payload.open(); JsonSimple config = new JsonSimple(in);
/** * Remove a payload from the object * * @param a payload identifier * @throws StorageException if there was an error removing the payload */ @Override public void removePayload(String pid) throws StorageException { Map<String, Payload> man = getManifest(); if (man.containsKey(pid)) { // Close the payload just in case, // since we are about to orphan it man.get(pid).close(); man.remove(pid); } else { throw new StorageException("ID '" + pid + "' does not exist."); } }
payload.setContentType("text/xml"); payload.setType(PayloadType.Source); object.setSourceId(pid); } else { payload.setType(PayloadType.Enrichment); payload.close();
/** * Index a specific annotation * * @param object : The annotation's object * @param pid : The annotation payload * @throws IndexerException if there were errors during indexing */ private void annotate(DigitalObject object, Payload payload) throws IndexerException { String pid = payload.getId(); if (propertiesId.equals(pid)) { return; } try { Properties props = new Properties(); props.setProperty("metaPid", pid); String doc = index(object, payload, null, ANOTAR_RULES_OID, props); if (doc != null) { doc = "<add>" + doc + "</add>"; anotar.request(new DirectXmlRequest("/update", doc)); if (anotarAutoCommit) { anotar.commit(); } } } catch (Exception e) { log.error("Indexing failed!\n-----\n", e); } }
realPid + "' : ", ex); mimeType = payload.getContentType();
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); } } }
JsonSimple workflow = null; try { workflow = new JsonSimple(wfPayload.open()); } catch (Exception ex) { throw ex; } finally { wfPayload.close(); String mimeType = payload.getContentType(); if (mimeType == null) { mimeType = "application/octet-stream";
@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()); }
Map<String, Payload> man = getManifest(); for (String pid : man.keySet()) { man.get(pid).close();
throws IndexerException { String oid = object.getId(); String pid = payload.getId();
+ realPid + "' : ", ex); mimeType = payload.getContentType();
/***** * Parse an XML document stored in a payload * * @param payload holding the document * @return Document object after parsing */ public Document getXmlDocument(Payload payload) { try { Document doc = getXmlDocument(payload.open()); payload.close(); return doc; } catch (StorageException ex) { log.error("Failed to access payload", ex); } return null; }