List of usage examples for org.springframework.data.mongodb.gridfs GridFsCriteria whereFilename
public static GridFsCriteria whereFilename()
From source file:piecework.content.concrete.GridFSContentProviderReceiver.java
private GridFsContentResource gridFsContentResource(GridFSFile current, String location) throws NotFoundError { // Retrieve in ascending order, then reverse versions - this allows us to count up in an intuition way, // setting version numbers if (location == null) return null; List<GridFSDBFile> files; Date uploadDate = null;/*w w w . ja v a2 s. co m*/ int indexOf = location.indexOf("?uploadDate="); if (indexOf != -1) { String uploadDateMillis = location.substring(indexOf + 12); uploadDate = new Date(Long.valueOf(uploadDateMillis)); location = location.substring(0, indexOf); files = gridFsOperations.find(query(GridFsCriteria.whereFilename().is(location)) .addCriteria(GridFsCriteria.where("uploadDate").is(uploadDate))); } else { files = gridFsOperations.find(query(GridFsCriteria.whereFilename().is(location)) .with(new Sort(Sort.Direction.ASC, "uploadDate"))); } List<Version> versions = new ArrayList<Version>(); GridFSFile latest = current; if (files != null && !files.isEmpty()) { int count = 1; for (GridFSDBFile file : files) { DBObject dbObject = file.getMetaData(); Object createDateObj = dbObject != null ? dbObject.get(GridFsContentResource.LAST_MODIFIED) : null; Long createDate = createDateObj != null ? Long.class.cast(createDateObj) : Long.valueOf(0); Object createdByObj = dbObject != null ? dbObject.get(GridFsContentResource.LAST_MODIFIED_BY) : null; String createdBy = createdByObj != null ? createdByObj.toString() : null; String versionId = file != null && file.getUploadDate() != null ? file.getId().toString() + "?uploadDate=" + file.getUploadDate().getTime() : null; String versionLocation = file != null && file.getUploadDate() != null ? location + "?uploadDate=" + file.getUploadDate().getTime() : null; versions.add( new Version("" + count, createdBy, createDate.longValue(), versionId, versionLocation)); if (current == null) latest = file; count++; } } if (latest == null) throw new NotFoundError(); uploadDate = latest.getUploadDate(); Collections.reverse(versions); return new GridFsContentResource(gridFsOperations, latest, location, uploadDate, versions); }
From source file:piecework.content.concrete.GridFsContentResource.java
@Override public InputStream getInputStream() throws IOException { Query query = query(GridFsCriteria.whereFilename().is(location)); if (uploadDate != null) query.addCriteria(GridFsCriteria.where("uploadDate").is(uploadDate)); GridFSDBFile file = gridFsOperations.findOne(query); return file.getInputStream(); }