use of io.vertigo.dynamo.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class TwoTablesDbFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI fileInfoUri) {
checkDefinitionStoreBinding(fileInfoUri.getDefinition());
// Ramène FileMetada
final URI<Entity> dtoMetaDataUri = new URI<>(storeMetaDataDtDefinition, fileInfoUri.getKey());
final DtObject fileMetadataDto = getStoreManager().getDataStore().readOne(dtoMetaDataUri);
final Object fdtId = getValue(fileMetadataDto, DtoFields.FDT_ID, Object.class);
// Ramène FileData
final URI<Entity> dtoDataUri = new URI<>(storeFileDtDefinition, fdtId);
final DtObject fileDataDto = getStoreManager().getDataStore().readOne(dtoDataUri);
// Construction du vFile.
final InputStreamBuilder inputStreamBuilder = new DataStreamInputStreamBuilder(getValue(fileDataDto, DtoFields.FILE_DATA, DataStream.class));
final String fileName = getValue(fileMetadataDto, DtoFields.FILE_NAME, String.class);
final String mimeType = getValue(fileMetadataDto, DtoFields.MIME_TYPE, String.class);
final Instant lastModified = getValue(fileMetadataDto, DtoFields.LAST_MODIFIED, Instant.class);
final Long length = getValue(fileMetadataDto, DtoFields.LENGTH, Long.class);
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
// TODO passer par une factory de FileInfo à partir de la FileInfoDefinition (comme DomainFactory)
final FileInfo fileInfo = new DatabaseFileInfo(fileInfoUri.getDefinition(), vFile);
fileInfo.setURIStored(fileInfoUri);
return fileInfo;
}
use of io.vertigo.dynamo.domain.model.FileInfoURI 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.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class FsFullFileStorePlugin method createNewFileInfoURI.
private static FileInfoURI createNewFileInfoURI(final FileInfoDefinition fileInfoDefinition) {
final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd-", Locale.FRANCE);
final String pathToSave = format.format(new Date()) + UUID.randomUUID();
return new FileInfoURI(fileInfoDefinition, pathToSave);
}
Aggregations