Ejemplo n.º 1
0
 private DBObject applyFieldFilter(DBObject object) {
   if (object instanceof GridFSFile) {
     GridFSFile file = (GridFSFile) object;
     DBObject metadata = file.getMetaData();
     if (metadata != null) {
       file.setMetaData(applyFieldFilter(metadata));
     }
   } else {
     object = MongoDBHelper.applyExcludeFields(object, definition.getExcludeFields());
     object = MongoDBHelper.applyIncludeFields(object, definition.getIncludeFields());
   }
   return object;
 }
  @Override
  protected String save(UrnObject urnObject) {
    ByteArrayInputStream stream = new ByteArrayInputStream(urnObject.bytes);

    DBObject metadata = new BasicDBObject();
    metadata.put(FIELD_STORED, urnObject.stored);

    if (AssertUtils.isNotEmpty(urnObject.name)) {
      metadata.put(FIELD_NAME, urnObject.name);
    }
    if (AssertUtils.isNotEmpty(urnObject.name)) {
      metadata.put(FIELD_MIME, urnObject.mime);
    }
    if (urnObject.expiry > 0) {
      metadata.put(FIELD_EXPIRY, urnObject.expiry);
    }

    GridFSFile file = this.template.store(stream, urnObject.key, urnObject.mime, metadata);
    if (file == null) {
      return null;
    }

    return file.getFilename();
  }