Example usage for com.mongodb.gridfs GridFS findOne

List of usage examples for com.mongodb.gridfs GridFS findOne

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFS findOne.

Prototype

public GridFSDBFile findOne(final DBObject query) 

Source Link

Document

Finds one file matching the given query.

Usage

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageStoreServiceIT.java

License:Open Source License

@Test(groups = "largeTests", enabled = true)
public void testSave() {
    final ShsMessageEntry entry = make(a(ShsMessageEntryMaker.ShsMessageEntry));
    final se.inera.axel.shs.mime.ShsMessage shsMessage = make(a(ShsMessage));

    messageStore.save(entry, shsMessage);

    mongoOperations.execute(new DbCallback<Object>() {
        @Override/*from www.j ava  2s.c om*/
        public Object doInDB(DB db) throws MongoException, DataAccessException {
            GridFS gridFs = new GridFS(db);

            assertNotNull(gridFs.findOne(entry.getId()), "Saved file was not found in grid");

            return null;
        }
    });
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageStoreServiceIT.java

License:Open Source License

@Test(groups = "largeTests", enabled = true)
public void existingFileShouldBeDeleted() {
    messageStore.delete(entry1);/*from  w w  w .  j a v  a2s.  c o m*/

    mongoOperations.execute(new DbCallback<Object>() {
        @Override
        public Object doInDB(DB db) throws MongoException, DataAccessException {
            GridFS gridFs = new GridFS(db);

            assertNull(gridFs.findOne(entry1.getId()), "Entry was not deleted");

            return null;
        }
    });
}

From source file:xbdd.webapp.resource.feature.Attachment.java

License:Apache License

@GET
@Path("/{id}")
public javax.ws.rs.core.Response getAttachment(@PathParam("id") final String id) throws IOException {
    final DB db = this.client.getDB("grid");
    final GridFS gridFS = new GridFS(db);
    final GridFSDBFile file = gridFS.findOne(id);
    // log.info(file);
    if (file == null) {
        throw new WebApplicationException(404);
    }/*from  w  w  w  .  j a  v a2  s .  co  m*/
    return Response.ok(org.apache.commons.io.IOUtils.toByteArray(file.getInputStream()), file.getContentType())
            .build();

}