use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class DbFileStorePlugin method createFileInfoDto.
private Entity createFileInfoDto(final FileInfo fileInfo) {
// Il doit exister un DtObjet associé à storeDtDefinition avec la structure attendue.
final Entity fileInfoDto = DtObjectUtil.createEntity(storeDtDefinition);
// -----
final VFile vFile = fileInfo.getVFile();
setValue(fileInfoDto, DtoFields.FILE_NAME, vFile.getFileName());
setValue(fileInfoDto, DtoFields.MIME_TYPE, vFile.getMimeType());
setValue(fileInfoDto, DtoFields.LAST_MODIFIED, vFile.getLastModified());
setValue(fileInfoDto, DtoFields.LENGTH, vFile.getLength());
setValue(fileInfoDto, DtoFields.FILE_DATA, new VFileDataStream(vFile));
if (fileInfo.getURI() != null) {
setIdValue(fileInfoDto, fileInfo.getURI().getKey());
}
return fileInfoDto;
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class TwoTablesDbFileStorePlugin method createFileEntity.
private Entity createFileEntity(final FileInfo fileInfo) {
final Entity fileDataDto = DtObjectUtil.createEntity(storeFileDtDefinition);
final VFile vFile = fileInfo.getVFile();
setValue(fileDataDto, DtoFields.FILE_NAME, vFile.getFileName());
setValue(fileDataDto, DtoFields.FILE_DATA, new VFileDataStream(vFile));
return fileDataDto;
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class TwoTablesDbFileStorePlugin method createMetaDataEntity.
private Entity createMetaDataEntity(final FileInfo fileInfo) {
final Entity fileMetadataDto = DtObjectUtil.createEntity(storeMetaDataDtDefinition);
final VFile vFile = fileInfo.getVFile();
setValue(fileMetadataDto, DtoFields.FILE_NAME, vFile.getFileName());
setValue(fileMetadataDto, DtoFields.MIME_TYPE, vFile.getMimeType());
setValue(fileMetadataDto, DtoFields.LAST_MODIFIED, vFile.getLastModified());
setValue(fileMetadataDto, DtoFields.LENGTH, vFile.getLength());
return fileMetadataDto;
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class FsFullFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI uri) {
/* read metadata*/
try {
final String metadataUri = obtainFullMetaDataFilePath(uri);
final Path metadataPath = Paths.get(metadataUri);
final List<String> infos = Files.readAllLines(metadataPath, Charset.forName(METADATA_CHARSET));
// récupération des infos
final String fileName = infos.get(0);
final String mimeType = infos.get(1);
final Instant lastModified = DateUtil.parseToInstant(infos.get(2), INFOS_DATE_PATTERN);
final Long length = Long.valueOf(infos.get(3));
final InputStreamBuilder inputStreamBuilder = new FileInputStreamBuilder(new File(obtainFullFilePath(uri)));
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
// retourne le fileinfo avec le fichier et son URI
final FsFileInfo fsFileInfo = new FsFileInfo(uri.getDefinition(), vFile);
fsFileInfo.setURIStored(uri);
return fsFileInfo;
} catch (final IOException e) {
throw WrappedException.wrap(e, "Can't read fileInfo " + uri.toURN());
}
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class FsFullFileStorePlugin method update.
/**
* {@inheritDoc}
*/
@Override
public void update(final FileInfo fileInfo) {
Assertion.checkNotNull(fileInfo.getURI() != null, "Only file with an id can be updated.");
// -----
final VFile vFile = fileInfo.getVFile();
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(INFOS_DATE_PATTERN).withZone(ZoneId.of("UTC"));
final String metaData = new StringBuilder().append(vFile.getFileName()).append('\n').append(vFile.getMimeType()).append('\n').append(formatter.format(vFile.getLastModified())).append(vFile.getLength()).append('\n').toString();
saveFile(metaData, fileInfo);
}
Aggregations