Search in sources :

Example 6 with FileInfoURI

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) DataStream(io.vertigo.lang.DataStream) DtObject(io.vertigo.dynamo.domain.model.DtObject) Instant(java.time.Instant) URI(io.vertigo.dynamo.domain.model.URI) FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI) VFile(io.vertigo.dynamo.file.model.VFile) FileInfo(io.vertigo.dynamo.file.model.FileInfo) InputStreamBuilder(io.vertigo.dynamo.file.model.InputStreamBuilder) DtObject(io.vertigo.dynamo.domain.model.DtObject)

Example 7 with FileInfoURI

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;
}
Also used : FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI) DateTimeFormatter(java.time.format.DateTimeFormatter) VFile(io.vertigo.dynamo.file.model.VFile)

Example 8 with FileInfoURI

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);
}
Also used : FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)8 Entity (io.vertigo.dynamo.domain.model.Entity)6 DtObject (io.vertigo.dynamo.domain.model.DtObject)3 URI (io.vertigo.dynamo.domain.model.URI)3 VFile (io.vertigo.dynamo.file.model.VFile)3 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)2 DataStream (io.vertigo.lang.DataStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Instant (java.time.Instant)2 Date (java.util.Date)2 FileInfo (io.vertigo.dynamo.file.model.FileInfo)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1