Example usage for com.mongodb.gridfs GridFSFile getUploadDate

List of usage examples for com.mongodb.gridfs GridFSFile getUploadDate

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFSFile getUploadDate.

Prototype

public Date getUploadDate() 

Source Link

Document

Gets the upload date.

Usage

From source file:com.kurento.kmf.repository.internal.repoimpl.mongo.MongoRepositoryItem.java

License:Open Source License

private static RepositoryItemAttributes loadAttributes(GridFSFile file) {

    RepositoryItemAttributes attributes = new RepositoryItemAttributes();

    attributes.setContentLength(file.getLength());
    attributes.setLastModified(file.getUploadDate().getTime());
    attributes.setMimeType(file.getContentType());

    return attributes;
}

From source file:org.craftercms.commons.mongo.FileInfo.java

License:Open Source License

FileInfo(final GridFSFile savedFile, final boolean withInputStream) {
    this.md5 = savedFile.getMD5();
    this.fileId = (ObjectId) savedFile.getId();
    this.contentType = savedFile.getContentType();
    this.fileSize = FileUtils.readableFileSize(savedFile.getLength());
    this.storeName = savedFile.getFilename();
    this.savedDate = savedFile.getUploadDate();
    this.fileSizeBytes = savedFile.getLength();
    if (withInputStream && savedFile instanceof GridFSDBFile) {
        this.inputStream = ((GridFSDBFile) savedFile).getInputStream();
    }//from w  w w  . java 2 s.c o  m
    attributes = new HashMap<>();
}

From source file:piecework.content.concrete.GridFSContentProviderReceiver.java

License:Educational Community License

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;//from   w  ww . java  2 s.c om
    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);
}