Search in sources :

Example 1 with VFile

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) VFile(io.vertigo.dynamo.file.model.VFile)

Example 2 with VFile

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) VFile(io.vertigo.dynamo.file.model.VFile)

Example 3 with VFile

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) VFile(io.vertigo.dynamo.file.model.VFile)

Example 4 with VFile

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());
    }
}
Also used : Path(java.nio.file.Path) InputStreamBuilder(io.vertigo.dynamo.file.model.InputStreamBuilder) Instant(java.time.Instant) IOException(java.io.IOException) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) VFile(io.vertigo.dynamo.file.model.VFile)

Example 5 with VFile

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

Aggregations

VFile (io.vertigo.dynamo.file.model.VFile)25 File (java.io.File)12 Entity (io.vertigo.dynamo.domain.model.Entity)7 Test (org.junit.Test)7 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)6 Instant (java.time.Instant)6 GET (io.vertigo.vega.webservice.stereotype.GET)4 IOException (java.io.IOException)4 URL (java.net.URL)4 DtObject (io.vertigo.dynamo.domain.model.DtObject)3 FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)3 FileInfo (io.vertigo.dynamo.file.model.FileInfo)3 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)2 URI (io.vertigo.dynamo.domain.model.URI)2 FSFile (io.vertigo.dynamo.impl.file.model.FSFile)2 DataStream (io.vertigo.lang.DataStream)2 OutputStream (java.io.OutputStream)2 StringBufferInputStream (java.io.StringBufferInputStream)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 FileInfoStd (io.vertigo.dynamo.store.data.fileinfo.FileInfoStd)1