private String findTFPackageId(String storageId) throws StorageException { DigitalObject object = storage.getObject(storageId); if (object.getPayload("metadata.tfpackage") != null) { return "metadata.tfpackage"; } for (String payloadId : object.getPayloadIdList()) { if (payloadId.endsWith(".tfpackage")) { return payloadId; } } return "metadata.tfpackage"; }
/** * Get a payload object in the specified Storage instance by its object ID * and the name of payload * * @param storage : Storage object * @param oid : ID of a Digital object * @param payloadName : name of payload * @return a Payload object * @throws StorageException */ public static Payload getPayload(Storage storage, String oid, String payloadName) throws StorageException { DigitalObject digitalObject = getDigitalObject(storage, oid); Payload payload = digitalObject.getPayload(payloadName); return payload; }
/** * Retrieve a Payload from storage * * @param oid The Object ID of the object in storage * @param pid The Payload ID in the object * @return Payload An instantiated Payload Object, or null for errors */ private Payload getPayload(String oid, String pid) { // Get the object from storage DigitalObject digitalObject = null; try { digitalObject = storage.getObject(oid); } catch (StorageException ex) { log.error("Retrieving OID '{}' failed!: ", oid, ex); return null; } // Return the payload... if it exists try { return digitalObject.getPayload(pid); } catch (StorageException ex) { return null; } }
/** * Get the data payload (ending in '.tfpackage') from the provided object. * * @param object * The digital object holding our payload * @return Payload The payload requested * @throws StorageException * if an errors occurs or the payload is not found */ private Payload getDataPayload(DigitalObject object) throws StorageException { for (String pid : object.getPayloadIdList()) { if (pid.endsWith(DATA_PAYLOAD_SUFFIX)) { return object.getPayload(pid); } } throw new StorageException("Data payload not found on storage!"); }
/** * Retrieve the payload from storage and return as a byte array. * * @param object Our digital object. * @param pid The payload ID to retrieve. * @return byte[] The byte array containing payload data * @throws Exception on any errors */ private byte[] getBytes(DigitalObject object, String pid) throws Exception { // These can happily throw exceptions higher Payload payload = object.getPayload(pid); InputStream in = payload.open(); byte[] result = null; // But here, the payload must receive // a close before throwing the error try { result = IOUtils.toByteArray(in); } catch (Exception ex) { throw ex; } finally { payload.close(); } return result; }
/** * Index an object and all of its payloads * * @param oid : The identifier of the object * @throws IndexerException if there were errors during indexing */ @Override public void index(String oid) throws IndexerException { try { DigitalObject object = storage.getObject(oid); // Some workflow actions create payloads, so we can't iterate // directly against the object. String[] oldManifest = {}; oldManifest = object.getPayloadIdList().toArray(oldManifest); for (String payloadId : oldManifest) { Payload payload = object.getPayload(payloadId); index(object, payload); } } catch (StorageException ex) { throw new IndexerException(ex); } }
/** * Retrieve the payload from storage and return as a byte array. * * @param object : Our digital object. * @param pid : The payload ID to retrieve. * @return byte[] : The byte array containing payload data * @throws Exception on any errors */ private byte[] getBytes(DigitalObject object, String pid) throws Exception { // These can happily throw exceptions higher Payload payload = object.getPayload(pid); InputStream in = payload.open(); byte[] result = null; // But here, the payload must receive // a close before throwing the error try { result = IOUtils.toByteArray(in); } catch (Exception ex) { throw ex; } finally { payload.close(); } return result; }
Payload payload = configObj.getPayload(configObj.getSourceId()); configFile = File.createTempFile("reharvest", ".json"); OutputStream out = new FileOutputStream(configFile);
payload = in.getPayload(pid); } catch (StorageException ex) { log.error("Error accessing payload '{}' in storage: ", pid, ex);
/** * Get the stored data from storage for the indicated object. * * @param oid The object we want */ private JsonSimple getDataFromStorage(String oid) { // Get our data from Storage Payload payload = null; try { DigitalObject object = storage.getObject(oid); payload = object.getPayload(DATA_PAYLOAD_ID); } catch (StorageException ex) { log.error("Error accessing object '{}' in storage: ", oid, ex); return null; } // Parse the JSON try { try { return new JsonSimple(payload.open()); } catch (IOException ex) { log.error("Error parsing data '{}': ", oid, ex); return null; } finally { payload.close(); } } catch (StorageException ex) { log.error("Error accessing data '{}' in storage: ", oid, ex); return null; } }
/** * Save the provided object data back into storage * * @param data The data to save * @param oid The object we want it saved in */ private void saveObjectData(JsonSimple data, String oid) throws TransactionException { // Get from storage DigitalObject object = null; try { object = storage.getObject(oid); object.getPayload(DATA_PAYLOAD_ID); } catch (StorageException ex) { log.error("Error accessing object '{}' in storage: ", oid, ex); throw new TransactionException(ex); } // Store modifications String jsonString = data.toString(true); try { InputStream inStream = new ByteArrayInputStream( jsonString.getBytes("UTF-8")); object.updatePayload(DATA_PAYLOAD_ID, inStream); } catch (Exception ex) { log.error("Unable to store data '{}': ", oid, ex); throw new TransactionException(ex); } }
Payload payload = object.getPayload(configPid); try { return new JsonSimple(payload.open());
/** * Index a specific payload * * @param oid : The identifier of the payload's object * @param pid : The identifier of the payload * @throws IndexerException if there were errors during indexing */ @Override public void index(String oid, String pid) throws IndexerException { try { DigitalObject object = storage.getObject(oid); Payload payload = object.getPayload(pid); index(object, payload); } catch (StorageException ex) { throw new IndexerException(ex); } }
try { DigitalObject object = storage.getObject(oid); payload = object.getPayload(WORKFLOW_PAYLOAD); } catch (StorageException ex) { log.error("Error accessing object '{}' in storage: ", oid, ex);
/** * Index an annotation * * @param oid : The identifier of the annotation's object * @param pid : The identifier of the annotation * @throws IndexerException if there were errors during indexing */ @Override public void annotate(String oid, String pid) throws IndexerException { // At this stage this is identical to the 'index()' method // above, but there may be changes at a later date. try { DigitalObject object = storage.getObject(oid); Payload payload = object.getPayload(pid); annotate(object, payload); } catch (StorageException ex) { throw new IndexerException(ex); } }
/***** * 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; }
Payload payload = object.getPayload(object.getSourceId()); log.debug("First time parsing config file: '{}'", oid); configFile = new JsonSimpleConfig(payload.open());
@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()); }
@ApiOperation(value = "Delete a datastream in a ReDBox object", tags = "datastream") @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"), @ApiImplicitParam(name = "datastreamId", value="The identifier of the datastream", required = true, allowMultiple = false, dataType = "string") }) @Delete public String deleteDatastream() throws FileUploadException, IOException, PluginException, MessagingException { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); String payloadId = getQueryValue("datastreamId"); DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); try { @SuppressWarnings("unused") Payload payload = digitalObject.getPayload(payloadId); } catch (StorageException e) { throw new ResourceException(404, e, "Datastream does not exist in the object"); } digitalObject.removePayload(payloadId); reindex(oid); return getSuccessResponseString(oid); }
@ApiOperation(value = "Get a datastream from a ReDBox object", tags = "datastream") @ApiImplicitParams({ @ApiImplicitParam(name = "datastreamId", value="The identifier of the datastream", required = true, allowMultiple = false, dataType = "string") }) @ApiResponses({ @ApiResponse(code = 200, message = "The datastream is retrieved"), @ApiResponse(code = 500, message = "General Error", response = Exception.class) }) @Get("application/octet-stream") public Representation getDatastream() throws IOException { try { Storage storage = (Storage) ApplicationContextProvider.getApplicationContext().getBean("fascinatorStorage"); String oid = getAttribute("oid"); String payloadId = getQueryValue("datastreamId"); if (payloadId != null) { DigitalObject digitalObject = StorageUtils.getDigitalObject(storage, oid); Payload payload = digitalObject.getPayload(payloadId); return new ByteArrayRepresentation(IOUtils.toByteArray(payload.open())); } else { throw new ResourceException(400, "Call requires a datastreamId value"); } } catch (StorageException e) { throw new ResourceException(500, e, e.getMessage()); } }