Search in sources :

Example 1 with FileInfo

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

the class FileStoreImpl method read.

/**
 * {@inheritDoc}
 */
@Override
public FileInfo read(final FileInfoURI uri) {
    Assertion.checkNotNull(uri);
    // -----
    final FileInfo fileInfo = getPhysicalStore(uri.getDefinition()).read(uri);
    // -----
    Assertion.checkNotNull(fileInfo, "Le fichier {0} n''a pas été trouvé", uri);
    return fileInfo;
}
Also used : FileInfo(io.vertigo.dynamo.file.model.FileInfo)

Example 2 with FileInfo

use of io.vertigo.dynamo.file.model.FileInfo 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 3 with FileInfo

use of io.vertigo.dynamo.file.model.FileInfo 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 4 with FileInfo

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

the class AbstractStoreManagerTest method testCreateFile.

@Test
public void testCreateFile() throws Exception {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        // 1.Création du fichier depuis un fichier texte du FS
        final VFile vFile = TestUtil.createVFile(fileManager, "../data/lautreamont.txt", AbstractStoreManagerTest.class);
        // 2. Sauvegarde en BDD
        final FileInfo fileInfo = new FileInfoStd(vFile);
        final FileInfo createdFileInfo = storeManager.getFileStore().create(fileInfo);
        // 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 : FileInfoStd(io.vertigo.dynamo.store.data.fileinfo.FileInfoStd) FileInfo(io.vertigo.dynamo.file.model.FileInfo) OutputStream(java.io.OutputStream) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) VFile(io.vertigo.dynamo.file.model.VFile) Test(org.junit.Test)

Aggregations

FileInfo (io.vertigo.dynamo.file.model.FileInfo)4 VFile (io.vertigo.dynamo.file.model.VFile)3 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)2 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2 DtObject (io.vertigo.dynamo.domain.model.DtObject)1 Entity (io.vertigo.dynamo.domain.model.Entity)1 FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)1 URI (io.vertigo.dynamo.domain.model.URI)1 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)1 FileInfoStd (io.vertigo.dynamo.store.data.fileinfo.FileInfoStd)1 FileInfoTemp (io.vertigo.dynamo.store.data.fileinfo.FileInfoTemp)1 AbstractStoreManagerTest (io.vertigo.dynamo.store.datastore.AbstractStoreManagerTest)1 DataStream (io.vertigo.lang.DataStream)1 Instant (java.time.Instant)1