Search in sources :

Example 11 with VFile

use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.

the class FileManagerTest method testCreateTempFileWithFixedNameAndMime.

@Test
public void testCreateTempFileWithFixedNameAndMime() {
    final String fileName = "monTestFile.txt";
    final String typeMime = "monTypeMime";
    final File file = TestUtil.getFile("data/testFile.txt", getClass());
    final VFile vFile = fileManager.createFile(fileName, typeMime, file);
    checkVFile(vFile, fileName, null, typeMime, 71092L);
}
Also used : VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) VFile(io.vertigo.dynamo.file.model.VFile) Test(org.junit.Test)

Example 12 with VFile

use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.

the class FileManagerTest method testObtainReadOnlyFile.

@Test
public void testObtainReadOnlyFile() {
    final File file = TestUtil.getFile("data/testFile.txt", getClass());
    final VFile vFile = fileManager.createFile(file);
    checVFile(fileManager.obtainReadOnlyFile(vFile), file);
}
Also used : VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) VFile(io.vertigo.dynamo.file.model.VFile) Test(org.junit.Test)

Example 13 with VFile

use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.

the class MultiStoreManagerTest method testOtherStoreFile.

@Test
public void testOtherStoreFile() throws Exception {
    final VFile vFile = TestUtil.createVFile(fileManager, "../data/lautreamont.txt", AbstractStoreManagerTest.class);
    // 1.Création du fichier depuis un fichier texte du FS
    final FileInfo fileInfo = new FileInfoTemp(vFile);
    final FileInfo createdFileInfo;
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        // 2. Sauvegarde en Temp
        createdFileInfo = storeManager.getFileStore().create(fileInfo);
        // can't read file if not commited (TODO ?)
        transaction.commit();
    }
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        // 3.relecture du fichier
        final FileInfo readFileInfo = storeManager.getFileStore().read(createdFileInfo.getURI());
        // 4. comparaison du fichier créé et du fichier lu.
        final String source;
        try (final OutputStream sourceOS = new java.io.ByteArrayOutputStream()) {
            FileUtil.copy(vFile.createInputStream(), sourceOS);
            source = sourceOS.toString();
        }
        final String read;
        try (final OutputStream readOS = new java.io.ByteArrayOutputStream()) {
            FileUtil.copy(readFileInfo.getVFile().createInputStream(), readOS);
            read = readOS.toString();
        }
        // on vérifie que le contenu des fichiers est identique.
        // assertEquals("toto", "toto");
        // assertEquals("toto", "ti");
        Assert.assertEquals(source, read);
        Assert.assertTrue("Test contenu du fichier", read.startsWith("Chant I"));
        Assert.assertTrue("Test contenu du fichier : " + secureSubString(read, 16711, "ses notes langoureuses,"), read.indexOf("ses notes langoureuses,") > 0);
        Assert.assertTrue("Test contenu du fichier : " + secureSubString(read, 11004, "mal : \"Adolescent,"), read.indexOf("mal : \"Adolescent,") > 0);
    // On désactive pour l'instant
    // Ne marche pas sur la PIC pour cause de charset sur le àé
    // Assert.assertTrue("Test contenu du fichier : " + secureSubString(read, 15579, "adieu !à ;"), read.indexOf("adieu !à ;") > 0);
    }
}
Also used : FileInfo(io.vertigo.dynamo.file.model.FileInfo) OutputStream(java.io.OutputStream) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) VFile(io.vertigo.dynamo.file.model.VFile) FileInfoTemp(io.vertigo.dynamo.store.data.fileinfo.FileInfoTemp) Test(org.junit.Test) AbstractStoreManagerTest(io.vertigo.dynamo.store.datastore.AbstractStoreManagerTest)

Example 14 with VFile

use of io.vertigo.dynamo.file.model.VFile in project vertigo by KleeGroup.

the class DbFileStorePlugin method read.

/**
 * {@inheritDoc}
 */
@Override
public FileInfo read(final FileInfoURI uri) {
    Assertion.checkNotNull(uri);
    checkDefinitionStoreBinding(uri.getDefinition());
    // -----
    final URI<Entity> dtoUri = new URI<>(storeDtDefinition, uri.getKey());
    final Entity fileInfoDto = getStoreManager().getDataStore().readOne(dtoUri);
    final InputStreamBuilder inputStreamBuilder = new DataStreamInputStreamBuilder(getValue(fileInfoDto, DtoFields.FILE_DATA, DataStream.class));
    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 VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
    return new DatabaseFileInfo(uri.getDefinition(), vFile);
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) InputStreamBuilder(io.vertigo.dynamo.file.model.InputStreamBuilder) DataStream(io.vertigo.lang.DataStream) 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)

Example 15 with VFile

use of io.vertigo.dynamo.file.model.VFile 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)

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