use of v7db.files.mongodb.V7GridFS in project v7files by thiloplanz.
the class ResourceFactory method init.
public void init(ApplicationConfig config, HttpManager manager) {
try {
endpoint = config.getInitParameter("webdav.endpoint");
endpointName = defaultIfBlank(substringAfterLast(endpoint, "/"), "/");
mongo = Configuration.getMongo();
endpointProperties = new Properties(Configuration.getEndpointProperties(endpoint));
// need to adjust mongo.db in case of multi-tenant mode
endpointProperties.put("mongo.db", dbName);
fs = new V7GridFS(mongo.getDB(dbName));
ROOT = getProperty("root");
if (ROOT == null)
ROOT = endpoint;
authentication = getAuthenticationProvider();
authorisation = AuthorisationProviderFactory.getAuthorisationProvider(endpointProperties);
fakeLocking = "fake".equals(getProperty("locking.provider"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of v7db.files.mongodb.V7GridFS in project v7files by thiloplanz.
the class V7GridFSTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
// the root folder
prepareMockData("test.v7files.files", new BasicBSONObject("_id", "root"));
gridFS = new V7GridFS(getMongo().getDB("test"));
}
use of v7db.files.mongodb.V7GridFS in project v7files by thiloplanz.
the class CopyCommandTest method testSHA.
public void testSHA() throws IOException {
MongoContentStorage storage = new MongoContentStorage(getMongo().getDB("test"));
ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test".getBytes()));
CopyCommand.main(new String[] { "copy", "-sha", sha.getDigest(), "x", "copy.txt" });
V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
V7File file = fs.getFile("x", "copy.txt");
assertEquals("test", IOUtils.toString(file.getInputStream()));
}
use of v7db.files.mongodb.V7GridFS in project v7files by thiloplanz.
the class MkdirCommandTest method testSimple.
public void testSimple() throws IOException {
V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
MkdirCommand.main(new String[] { "mkdir", "x", "123" });
{
V7File check = fs.getFile("x", "123");
assertFalse(check.hasContent());
assertEquals("[]", check.getChildren().toString());
}
MkdirCommand.main(new String[] { "mkdir", "x", "123/456" });
{
V7File check = fs.getFile("x", "123", "456");
assertFalse(check.hasContent());
assertEquals("[]", check.getChildren().toString());
}
}
use of v7db.files.mongodb.V7GridFS in project v7files by thiloplanz.
the class CopyCommand method main.
public static void main(String[] args) throws MongoException, IOException {
if (args.length != 5) {
System.err.println("Copy files");
System.err.println(" by name: copy <sourceRoot> <sourcePath> <targetRoot> <targetPath>");
System.err.println(" by hash: copy -sha <shaHex> <targetRoot> <targetPath>");
System.exit(1);
}
DB db = Configuration.getMongo().getDB(Configuration.getProperty("mongo.db"));
V7GridFS fs = new V7GridFS(db);
if ("-sha".equals(args[1])) {
MongoContentStorage storage = new MongoContentStorage(db);
String sha = args[2];
try {
ContentSHA file = findContentByPrefix(storage, sha);
if (file == null)
throw new FileNotFoundException("-sha " + sha);
String[] path = getPath(args[3], args[4]);
createFile(fs, file, path, null);
} catch (DecoderException e) {
throw new IllegalArgumentException("invalid parameter :" + sha + " is not a hex-encoded SHA-1 prefix");
}
} else {
String[] srcPath = getPath(args[1], args[2]);
String[] targetPath = getPath(args[3], args[4]);
V7File src = fs.getFile(srcPath);
if (src == null) {
throw new FileNotFoundException(args[1] + " " + args[2]);
}
if (src.hasContent()) {
createFile(fs, src.getContentPointer(), targetPath, src.getContentType());
} else {
V7File existing = fs.getFile(targetPath);
if (existing != null) {
throw new IOException("copy target " + targetPath + " already exists");
}
V7File parent = getParent(fs, targetPath);
src.copyTo(parent.getId(), targetPath[targetPath.length - 1]);
}
}
}
Aggregations