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; }
@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); } }
@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); } }
@Override public DigitalObject getObject(String oid) throws StorageException { if (getManifest().containsKey(oid)) { return getManifest().get(oid); } throw new StorageException("ID '" + oid + "' does no exist."); }
@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); }
@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."); }
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."); } }
@Override public void init(File jsonFile) throws StorageException { try { setVariable(new JsonSimpleConfig(jsonFile)); } catch (IOException ioe) { throw new StorageException(ioe); } }
@Override public void init(String jsonString) throws PluginException { try { systemConfig = new JsonSimpleConfig(jsonString); init(); } catch (IOException ioe) { throw new StorageException("Failed to read string configuration!", ioe); } }
@Override public void init(File jsonFile) throws PluginException { try { systemConfig = new JsonSimpleConfig(jsonFile); init(); } catch (IOException ioe) { throw new StorageException("Failed to read file configuration!", ioe); } }
@Override public void init(String jsonString) throws StorageException { try { setVariable(new JsonSimpleConfig(jsonString)); } catch (IOException e) { throw new StorageException(e); } }
@Override public DigitalObject getObject(String oid) throws StorageException { DigitalObject obj = storage.getObject(oid); if (isAccessAllowed(obj)) { return obj; } throw new StorageException("Access denied"); }
/** * 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!"); }
/** * Public init method for File based configuration. * * @param jsonFile * The File containing JSON configuration * @throws StorageException * if any errors occur */ static void init(File jsonFile) throws StorageException { try { systemConfig = new JsonSimpleConfig(jsonFile); init(); } catch (IOException ioe) { throw new StorageException("Failed to read file configuration!", ioe); } }
/** * Public init method for String based configuration. * * @param jsonString * The String containing JSON configuration * @throws StorageException * if any errors occur */ static void init(String jsonString) throws StorageException { try { systemConfig = new JsonSimpleConfig(jsonString); init(); } catch (IOException ioe) { throw new StorageException("Failed to read string configuration!", ioe); } }
public void load() throws StorageException { boolean isInStorage = existsInStorage(); if (!isInStorage) { throw new StorageException( "Object with OID: " + oid + ", doesn't exist!"); } else { getObjectMetadata(); getRecordMetadata(); } }
public void remove() throws StorageException { MongoCollection<Document> objectMetaCol = getObjectMetadataCollection(); MongoCollection<Document> metaCol = getMetaCollection(); boolean isInStorage = existsInStorage(); if (!isInStorage) { throw new StorageException( "Object with OID: " + oid + ", doesn't exist!"); } else { objectMetaCol.findOneAndDelete(eq("redboxOid", oid)); metaCol.findOneAndDelete(eq("redboxOid", oid)); } }
/** * Perform the actual removal from Fedora * * @param fedoraPid * the Fedora PID to remove from storage * @throws StorageException * if any errors occur */ private void removeBlobStoreObject(String oid) throws StorageException { if (BlobStoreClient.getClient().directoryExists(BlobStoreClient.getContainerName(), oid)) { BlobStoreClient.getClient().deleteDirectory(BlobStoreClient.getContainerName(), oid); } else { throw new StorageException("Object " + oid + " doesn't exist to be deleted"); } }