use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class FsFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI uri) {
// récupération de l'objet en base
final URI<Entity> dtoUri = createDtObjectURI(uri);
final DtObject fileInfoDto = getStoreManager().getDataStore().readOne(dtoUri);
// récupération du fichier
final String fileName = getValue(fileInfoDto, DtoFields.FILE_NAME, String.class);
final String mimeType = getValue(fileInfoDto, DtoFields.MIME_TYPE, String.class);
final Instant lastModified = getValue(fileInfoDto, DtoFields.LAST_MODIFIED, Instant.class);
final Long length = getValue(fileInfoDto, DtoFields.LENGTH, Long.class);
final String filePath = getValue(fileInfoDto, DtoFields.FILE_PATH, String.class);
final InputStreamBuilder inputStreamBuilder = new FileInputStreamBuilder(new File(documentRoot + filePath));
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;
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class FsFileStorePlugin method createFileInfoEntity.
private Entity createFileInfoEntity(final FileInfo fileInfo) {
final Entity fileInfoDto = createFileInfoEntity(fileInfo.getDefinition());
// -----
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());
if (fileInfo.getURI() == null) {
// cas de la création, on ajoute en base un chemin fictif (colonne not null)
setValue(fileInfoDto, DtoFields.FILE_PATH, "/dev/null");
} else {
// cas de l'update
setIdValue(fileInfoDto, fileInfo.getURI().getKey());
// récupération de l'objet en base pour récupérer le path du fichier et ne pas modifier la base
final URI<Entity> dtoUri = createDtObjectURI(fileInfo.getURI());
final DtObject fileInfoDtoBase = getStoreManager().getDataStore().readOne(dtoUri);
final String pathToSave = getValue(fileInfoDtoBase, DtoFields.FILE_PATH, String.class);
setValue(fileInfoDto, DtoFields.FILE_PATH, pathToSave);
}
return fileInfoDto;
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class FsFullFileStorePlugin method create.
/**
* {@inheritDoc}
*/
@Override
public FileInfo create(final FileInfo fileInfo) {
Assertion.checkNotNull(fileInfo);
Assertion.checkArgument(fileInfo.getURI() == null, "Only file without any id can be created.");
// -----
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('\n').append(vFile.getLength()).append('\n').toString();
final FileInfoURI uri = createNewFileInfoURI(fileInfo.getDefinition());
fileInfo.setURIStored(uri);
saveFile(metaData, fileInfo);
return fileInfo;
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class TextAccountStorePlugin method createVFile.
private static Optional<VFile> createVFile(final URI<Account> accountURI, final URL fileURL, final String photoUrl) {
File photoFile;
try {
photoFile = new File(fileURL.toURI());
} catch (final URISyntaxException e) {
return Optional.empty();
}
Assertion.checkArgument(photoFile.exists(), "Account {0} photo {1} not found", accountURI, photoUrl);
Assertion.checkArgument(photoFile.isFile(), "Account {0} photo {1} must be a file", accountURI, photoUrl);
try {
final String contentType = Files.probeContentType(photoFile.toPath());
return Optional.of(new FSFile(photoFile.getName(), contentType, photoFile));
} catch (final IOException e) {
throw WrappedException.wrap(e);
}
}
use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.
the class FileManagerTest method testCreateTempFileWithNoFile.
@Test
public void testCreateTempFileWithNoFile() {
final String fileName = "monTestFile.txt";
final String typeMime = "monTypeMime";
final Instant lastModified = Instant.now();
final long length = 123;
final InputStreamBuilder inputStreamBuilder = new InputStreamBuilder() {
@Override
public InputStream createInputStream() {
return new StringBufferInputStream("Contenu test");
}
};
final VFile vFile = fileManager.createFile(fileName, typeMime, lastModified, length, inputStreamBuilder);
checkVFile(vFile, fileName, lastModified, typeMime, length);
}
Aggregations