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);
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations