List of usage examples for com.mongodb.gridfs GridFSFile getFilename
public String getFilename()
From source file:com.sangupta.urn.service.impl.MongoGridFSUrnStorageServiceImpl.java
License:Apache License
@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); }/*w w w. j ava 2 s . com*/ 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(); }
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. j a v a 2 s .c o m attributes = new HashMap<>(); }
From source file:org.eclipse.hawkbit.artifact.repository.ArtifactStore.java
License:Open Source License
/** * Maps a single {@link GridFSFile} to {@link DbArtifact}. * * @param tenant/*from w w w . j a va 2 s. c o m*/ * the tenant * @param dbFile * the mongoDB gridFs file. * @return a mapped artifact from the given dbFile */ private static GridFsArtifact map(final GridFSFile fsFile) { if (fsFile == null) { return null; } final GridFsArtifact artifact = new GridFsArtifact(fsFile); artifact.setArtifactId(fsFile.getId().toString()); artifact.setSize(fsFile.getLength()); artifact.setContentType(fsFile.getContentType()); artifact.setHashes(new DbArtifactHash(fsFile.getFilename(), fsFile.getMD5())); return artifact; }
From source file:org.opentestsystem.authoring.testauth.publish.SharedPublisherHelper.java
License:Open Source License
public List<ScoringRule> retrieveScoringRules(final String assessmentId) { final List<ScoringRule> scoringRuleList = this.scoringRuleService .getScoringRulesByAssessmentId(assessmentId); for (final ScoringRule scoringRule : scoringRuleList) { if (scoringRule != null && scoringRule.getComputationRuleId() != null) { scoringRule.setComputationRule( this.computationRuleService.getComputationRule(scoringRule.getComputationRuleId())); }/*from w w w . j a v a 2s. com*/ if (scoringRule != null && scoringRule.getValueConversionTableGridFsId() != null) { final GridFSFile gridFsFile = this.gridFsRepository .getById(scoringRule.getValueConversionTableGridFsId()); scoringRule.setValueConversionTableFilename(gridFsFile.getFilename()); } if (scoringRule != null && scoringRule.getStandardErrorConversionTableGridFsId() != null) { final GridFSFile gridFsFile = this.gridFsRepository .getById(scoringRule.getStandardErrorConversionTableGridFsId()); scoringRule.setStandardErrorConversionTableFilename(gridFsFile.getFilename()); } } return scoringRuleList; }
From source file:org.opentestsystem.authoring.testauth.service.impl.ScoringRuleServiceImpl.java
License:Open Source License
private void populateConversionTableFilenames(final ScoringRule scoringRule) { if (scoringRule != null && scoringRule.getValueConversionTableGridFsId() != null) { final GridFSFile gridFsFile = this.gridFsRepository .getById(scoringRule.getValueConversionTableGridFsId()); if (gridFsFile == null) { throw new LocalizedException("scoringRule.valueConversionTableGridFsId.file.not.found"); }//from w w w .j a va 2 s . co m scoringRule.setValueConversionTableFilename(gridFsFile.getFilename()); } if (scoringRule != null && scoringRule.getStandardErrorConversionTableGridFsId() != null) { final GridFSFile gridFsFile = this.gridFsRepository .getById(scoringRule.getStandardErrorConversionTableGridFsId()); if (gridFsFile == null) { throw new LocalizedException("scoringRule.standardErrorConversionTableGridFsId.file.not.found"); } scoringRule.setStandardErrorConversionTableFilename(gridFsFile.getFilename()); } }
From source file:org.opentestsystem.shared.progman.service.impl.AssetPoolServiceImpl.java
License:Open Source License
@Override public Asset saveAssetFile(final String assetPoolId, final String fileName, final byte[] inBytes, final String fileContentType) { final AssetType assetType = determineAssetType(fileContentType); if (assetType == null) { throw new LocalizedException("upload.type.not.supported", new String[] { fileContentType }); }/*from ww w . j a v a 2 s. c om*/ final AssetPool assetPool = getAssetPool(assetPoolId); if (assetPool == null) { throw createAssetPoolNotFoundException(assetPoolId); } final DBObject metadata = null; final GridFSFile gridFile = this.assetGridFsRepository.save(inBytes, fileName, metadata); final Asset asset = new Asset(); asset.setType(assetType); asset.setAssetFileGridId(gridFile.getId().toString()); asset.setAssetFileName(gridFile.getFilename()); asset.setBasePath(this.pmBaseUrl); asset.setFileContentType(fileContentType); asset.setProperty("/assetPool" + asset.calculatePropertyValueForFile()); assetPool.addAsset(asset); final Set<String> duplicateFiles = findDuplicateFileNames(assetPool.getAssets()); if (!duplicateFiles.isEmpty()) { throw new LocalizedException("assetPool.duplicate.assets", new String[] { duplicateFiles.toString() }); } saveAssetPool(assetPool); return asset; }
From source file:org.springframework.data.samples._02_mongo.MongoPopulator.java
License:Apache License
private void storeFile(String filename, String pictureName) throws IOException { InputStream pictureStream = MongoPopulator.class.getResourceAsStream(filename); GridFSFile file = gridFs.store(pictureStream, pictureName); pictureStream.close();//from w w w . j a v a 2 s .c o m pictureNames.add(file.getFilename()); }