Search in sources :

Example 1 with FSFile

use of io.vertigo.dynamo.impl.file.model.FSFile 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 2 with FSFile

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

the class TextAccountStorePlugin method createVFile.

private static Optional<VFile> createVFile(final URI<Account> accountURI, final URL fileURL, final String photoUrl) {
    File photoFile;
    try {
        photoFile = new File(fileURL.toURI());
    } catch (final URISyntaxException e) {
        return Optional.empty();
    }
    Assertion.checkArgument(photoFile.exists(), "Account {0} photo {1} not found", accountURI, photoUrl);
    Assertion.checkArgument(photoFile.isFile(), "Account {0} photo {1} must be a file", accountURI, photoUrl);
    try {
        final String contentType = Files.probeContentType(photoFile.toPath());
        return Optional.of(new FSFile(photoFile.getName(), contentType, photoFile));
    } catch (final IOException e) {
        throw WrappedException.wrap(e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) 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)

Aggregations

VFile (io.vertigo.dynamo.file.model.VFile)2 FSFile (io.vertigo.dynamo.impl.file.model.FSFile)2 File (java.io.File)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)1