Search in sources :

Example 6 with VFile

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

the class TestUtil method createVFile.

/**
 * Crée un VFile relativement d'un class de base.
 * @param fileName Nom/path du fichier
 * @param baseClass Class de base pour le chemin relatif
 * @return VFile
 */
public static VFile createVFile(final FileManager fileManager, final String fileName, final Class<?> baseClass) {
    try {
        try (final InputStream in = baseClass.getResourceAsStream(fileName)) {
            Assertion.checkNotNull(in, "fichier non trouvé : {0}", fileName);
            final File file = new TempFile("tmp", '.' + FileUtil.getFileExtension(fileName));
            FileUtil.copy(in, file);
            return fileManager.createFile(file);
        }
    } catch (final IOException e) {
        throw WrappedException.wrap(e);
    }
}
Also used : TempFile(io.vertigo.util.TempFile) InputStream(java.io.InputStream) IOException(java.io.IOException) TempFile(io.vertigo.util.TempFile) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File)

Example 7 with VFile

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

the class TextIdentityProviderPlugin method getPhoto.

/**
 * {@inheritDoc}
 */
@Override
public <E extends Entity> Optional<VFile> getPhoto(final URI<E> accountURI) {
    final IdentityUserInfo identityAccountInfo = users.get(accountURI.getId());
    Assertion.checkNotNull(identityAccountInfo, "No account found for {0}", accountURI);
    if (identityAccountInfo.getPhotoUrl() == null) {
        return Optional.empty();
    }
    final File photoFile = new File(identityAccountInfo.getPhotoUrl());
    if (!photoFile.exists()) {
        return Optional.empty();
    }
    try {
        final String contentType = Files.probeContentType(photoFile.toPath());
        return Optional.of(new FSFile("photoOf" + accountURI.getId(), contentType, photoFile));
    } catch (final IOException e) {
        throw WrappedException.wrap(e);
    }
}
Also used : IOException(java.io.IOException) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) FSFile(io.vertigo.dynamo.impl.file.model.FSFile) FSFile(io.vertigo.dynamo.impl.file.model.FSFile)

Example 8 with VFile

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

the class FileDownloadWebServices method testDownloadFile.

@AnonymousAccessAllowed
@GET("/downloadFileContentType")
public VFile testDownloadFile(@QueryParam("id") final Integer id) {
    final URL imageUrl = resourcetManager.resolve("npi2loup.png");
    final File imageFile = asFile(imageUrl);
    return fileManager.createFile("image" + id + generateSpecialChars(id) + ".png", "image/png", imageFile);
}
Also used : VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) URL(java.net.URL) GET(io.vertigo.vega.webservice.stereotype.GET) AnonymousAccessAllowed(io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed)

Example 9 with VFile

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

the class AdvancedTestWebServices method testExportContact.

@GET("/export/pdf/{conId}")
public VFile testExportContact(@PathParam("conId") final long conId) throws URISyntaxException {
    final URL tempFile = resourcetManager.resolve("io/vertigo/vega/webservice/data/ws/contact2.pdf");
    final VFile result = fileManager.createFile(new File(tempFile.toURI()));
    // 200
    return result;
}
Also used : VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) URL(java.net.URL) VFile(io.vertigo.dynamo.file.model.VFile) GET(io.vertigo.vega.webservice.stereotype.GET)

Example 10 with VFile

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

the class AdvancedTestWebServices method testDownloadFile.

@GET("/downloadFile")
public VFile testDownloadFile(@QueryParam("id") final Integer id) {
    final URL imageUrl = resourcetManager.resolve("npi2loup.png");
    final File imageFile = asFile(imageUrl);
    final VFile imageVFile = fileManager.createFile("image" + id + ".png", "image/png", imageFile);
    return imageVFile;
}
Also used : VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) URL(java.net.URL) VFile(io.vertigo.dynamo.file.model.VFile) GET(io.vertigo.vega.webservice.stereotype.GET)

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