private File getPath(String oid) throws StorageException { if (oid.length() < 6) { throw new StorageException("oID '" + oid + "' length must be greater than 6."); } String dir = oid.substring(0, 2) + File.separator + oid.substring(2, 4) + File.separator + oid.substring(4, 6) + File.separator; File file = new File(homeDir, dir + oid); return file; }
log.error("Failed to parse message: {}", ioe.getMessage()); } catch (StorageException se) { log.error("Failed to update storage: {}", se.getMessage()); } catch (IndexerException ie) { log.error("Failed to index object: {}", ie.getMessage());
/** * Indexing single object * * TODO: Might let the user to fill in form in the portal regards to which * rules to be used * * @param objectId Object Id to be indexed */ public void indexObject(String objectId) { DigitalObject object = null; try { object = realStorage.getObject(objectId); } catch (StorageException ex) { log.error("Error getting object", ex); } try { Properties sofMeta = object.getMetadata(); String rulesOid = sofMeta.getProperty("rulesOid"); if (!rulesList.contains(rulesOid)) { updateRules(rulesOid); rulesList.add(rulesOid); } processObject(object, rulesOid, null, true); } catch (StorageException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
log.error("Failed to parse message: {}", ioe.getMessage()); } catch (StorageException se) { log.error("Failed to update storage: {}", se.getMessage()); } catch (TransformerException te) { log.error("Failed to transform object: {}", te.getMessage());
/** * Remove the indicated object from storage. * * @param oid * the Object ID to remove from storage * @throws StorageException * if any errors occur */ @Override public synchronized void removeObject(String oid) throws StorageException { // log.debug("removeObject({})", oid); if (oid == null) { throw new StorageException("Error; Null OID recieved"); } try { removeBlobStoreObject(oid); } catch (Exception e) { throw new StorageException("Unable to remove object", e); } }
log.error("Failed to index object: {}", ie.getMessage()); } catch (StorageException e) { log.error("Failed to delete object: {}", e.getMessage());
@Override public Payload createLinkedPayload(String pid, String linkPath) throws StorageException { try { ByteArrayInputStream in = new ByteArrayInputStream(linkPath .getBytes("UTF-8")); Payload payload = createPayload(pid, in, true); return payload; } catch (UnsupportedEncodingException ex) { throw new StorageException(ex); } }
@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()); } }
@Override public Payload createLinkedPayload(String pid, String linkPath) throws StorageException { log.warn("This storage plugin does not support linked payloads..." + " converting to stored."); try { FileInputStream in = new FileInputStream(linkPath); return createStoredPayload(pid, in); } catch (FileNotFoundException fnfe) { throw new StorageException(fnfe); } }
/** * Gets the payload with the specified identifier * * @param pid payload identifier * @return a payload * @throws StorageException if there was an error instantiating the payload * or the ID does not exist. */ @Override public Payload getPayload(String pid) throws StorageException { Map<String, Payload> man = getManifest(); if (man.containsKey(pid)) { return man.get(pid); } else { throw new StorageException("ID '" + pid + "' does not exist."); } }
@Override public DigitalObject getObject(String oid) throws StorageException { if (getManifest().containsKey(oid)) { return getManifest().get(oid); } throw new StorageException("ID '" + oid + "' does no exist."); }
File linkFile = new File(linkPath); if (!linkFile.exists()) { throw new StorageException("External file not found : " + linkFile.getAbsolutePath()); return in; } catch (IOException ex) { throw new StorageException(ex); return in; } catch (FileNotFoundException ex) { throw new StorageException(ex);
@Override public Payload getPayload(String pid) throws StorageException { if (pid == null) { throw new StorageException("Error; Null PID recieved"); } // Confirm we actually have this payload first Map<String, Payload> manifest = getManifest(); if (!manifest.containsKey(pid)) { throw new StorageException("pID '" + pid + "': was not found"); } Map<String, Object> fileInfo = getFileInfo(pid); return new MongoPayload(this, pid, (String) fileInfo.get("payloadId"), payloadBackend); }
/** * Created a stored payload in storage as a datastream of this Object. This * is the only payload supported by this plugin. * * @param pid * the Payload ID to use * @param in * an InputStream containing the data to store * @return Payload the Payload Object * @throws StorageException * if any errors occur */ @Override public synchronized Payload createStoredPayload(String pid, InputStream in) throws StorageException { // log.debug("createStoredPayload({},{})", getId(), pid); if (pid == null || in == null) { throw new StorageException("Error; Null parameter recieved"); } Payload payload = createPayload(pid, in, false); return payload; }
/** * Created a linked payload in storage as a datastream of this Object. * Linked payloads are not truly supported by this plugin, and the provided * File will instead be ingested into the BlobStore as stored payloads. * * @param pid * the Payload ID to use * @param linkPath * a file path to the file to store * @return Payload the Payload Object * @throws StorageException * if any errors occur */ @Override public synchronized Payload createLinkedPayload(String pid, String linkPath) throws StorageException { log.warn("This storage plugin does not support linked payloads..." + " converting to stored."); try { FileInputStream in = new FileInputStream(linkPath); return createStoredPayload(pid, in); } catch (FileNotFoundException fnfe) { throw new StorageException(fnfe); } }
@Override public DigitalObject createObject(String oid) throws StorageException { // log.debug("createObject(" + oid + ")"); File objHome = getPath(oid); if (objHome.exists()) { throw new StorageException("oID '" + oid + "' already exists in storage."); } return new FileSystemDigitalObject(objHome, oid); }
@Override public DigitalObject getObject(String oid) throws StorageException { File objHome = getPath(oid); if (objHome.exists()) { FileSystemDigitalObject obj = new FileSystemDigitalObject(objHome, oid); // log.debug("getObject(" + oid + "), sourceId: " + // obj.getSourceId()); return obj; } throw new StorageException("oID '" + oid + "' doesn't exist in storage."); }
/** * Update the data payload (ending in '.tfpackage') in the provided object. * * @param object * The digital object holding our payload * @param input * The String to store * @throws StorageException * if an errors occurs or the payload is not found */ private void updateDataPayload(DigitalObject object, String input) throws StorageException { try { for (String pid : object.getPayloadIdList()) { if (pid.endsWith(DATA_PAYLOAD_SUFFIX)) { InputStream inStream = new ByteArrayInputStream( input.getBytes("UTF-8")); object.updatePayload(pid, inStream); return; } } throw new StorageException("Data payload not found on storage!"); } catch (Exception ex) { throw new StorageException("Error storing payload data!", ex); } } }
public synchronized JsonDigitalObject createObject(String oid, String collectionName) throws StorageException { if (oid == null) { throw new StorageException( "Cannot create object in storage with NULL oid"); } // start with the object... MongoDigitalObject obj = new MongoDigitalObject(mongoDb, collectionName, objectMetadataCollectionName, oid, payloadBackend); if (obj.existsInStorage()) { throw new StorageException( "Error; object '" + oid + "' already exists in MongoDB"); } obj.save(); return obj; }
/** * 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."); } }