com.mongodb.client.gridfs.GridFSBuckets Java Examples

The following examples show how to use com.mongodb.client.gridfs.GridFSBuckets. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridFSITTestBase.java    From nifi with Apache License 2.0 6 votes vote down vote up
public boolean fileHasProperties(String name, String bucketName, Map<String, String> attrs) {
    GridFSBucket bucket = GridFSBuckets.create(client.getDatabase(DB), bucketName);
    MongoCursor it = bucket.find(Document.parse(String.format("{ \"filename\": \"%s\" }", name))).iterator();
    boolean retVal = false;

    if (it.hasNext()) {
        GridFSFile file = (GridFSFile)it.next();
        Document metadata = file.getMetadata();
        if (metadata != null && metadata.size() == attrs.size()) {
            retVal = true;
            for (Map.Entry<String, Object> entry : metadata.entrySet()) {
                Object val = attrs.get(entry.getKey());
                if (val == null || !entry.getValue().equals(val)) {
                    retVal = false;
                    break;
                }
            }
        }
    }

    it.close();

    return retVal;
}
 
Example #2
Source File: AbstractGridFSProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected GridFSBucket getBucket(FlowFile input, ProcessContext context) {
    final String name = getBucketName(input, context);
    if (StringUtils.isEmpty(name)) {
        return GridFSBuckets.create(getDatabase(input, context));
    } else {
        return GridFSBuckets.create(getDatabase(input, context), name);
    }
}
 
Example #3
Source File: GridFSITTestBase.java    From nifi with Apache License 2.0 5 votes vote down vote up
public boolean fileExists(String name, String bucketName) {
    GridFSBucket bucket = GridFSBuckets.create(client.getDatabase(DB), bucketName);
    MongoCursor it = bucket.find(Document.parse(String.format("{ \"filename\": \"%s\" }", name))).iterator();
    boolean retVal = it.hasNext();
    it.close();

    return retVal;
}
 
Example #4
Source File: GridFSITTestBase.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ObjectId writeTestFile(String fileName, String content, String bucketName, Map<String, Object> attrs) {
    GridFSBucket bucket = GridFSBuckets.create(client.getDatabase(DB), bucketName);
    GridFSUploadOptions options = new GridFSUploadOptions().metadata(new Document(attrs));
    ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes());
    ObjectId retVal = bucket.uploadFromStream(fileName, input, options);

    return retVal;
}
 
Example #5
Source File: MongoFileService.java    From elepy with Apache License 2.0 4 votes vote down vote up
public MongoFileService(MongoDatabase mongoDatabase, String bucket) {
    this.bucket = GridFSBuckets.create(mongoDatabase, bucket == null ? "fs" : bucket);
}
 
Example #6
Source File: MongoDbStore.java    From swellrt with Apache License 2.0 4 votes vote down vote up
MongoDbStore(MongoDatabase database) {
  this.database = database;
  attachmentGrid = GridFSBuckets.create(database, "attachments");
  thumbnailGrid = GridFSBuckets.create(database, "thumbnails");
  metadataGrid = GridFSBuckets.create(database, "metadata");
}
 
Example #7
Source File: MongoDocumentStorage.java    From lumongo with Apache License 2.0 4 votes vote down vote up
private GridFSBucket createGridFSConnection() {
	MongoDatabase db = mongoClient.getDatabase(database);
	return GridFSBuckets.create(db, ASSOCIATED_FILES);
}