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