use of com.faforever.api.security.Audit in project faf-java-api by FAForever.
the class AvatarService method updateAvatar.
@SneakyThrows
@Transactional
@Audit(messageTemplate = "Avatar ''{0}'' updated with [''{1}'' - ''{2}''].", expressions = { "${avatarId}", "${avatarMetadata.name}", "${originalFilename}" })
public void updateAvatar(Integer avatarId, AvatarMetadata avatarMetadata, String originalFilename, InputStream imageDataInputStream, long avatarImageFileSize) {
final Avatar existingAvatar = getExistingAvatar(avatarId);
final String normalizedAvatarFileName = getFileNameFromUrl(existingAvatar.getUrl());
existingAvatar.setTooltip(avatarMetadata.getName());
final InputStream markSupportedImageInputStream = getMarkSupportedInputStream(imageDataInputStream);
validateImageFile(originalFilename, avatarImageFileSize);
checkImageDimensions(markSupportedImageInputStream, originalFilename);
final Path imageTargetPath = properties.getAvatar().getTargetDirectory().resolve(normalizedAvatarFileName);
avatarRepository.save(existingAvatar);
copyAvatarFile(markSupportedImageInputStream, imageTargetPath, true);
}
use of com.faforever.api.security.Audit in project faf-java-api by FAForever.
the class AvatarService method createAvatar.
@SneakyThrows
@Transactional
@Audit(messageTemplate = "Avatar [''{0}'' - ''{1}''] created.", expressions = { "${avatarMetadata.name}", "${originalFilename}" })
public void createAvatar(AvatarMetadata avatarMetadata, String originalFilename, InputStream imageDataInputStream, long avatarImageFileSize) {
final Avatar avatarToCreate = new Avatar();
final String normalizedAvatarFileName = FileNameUtil.normalizeFileName(originalFilename);
String url = String.format(properties.getAvatar().getDownloadUrlFormat(), normalizedAvatarFileName);
avatarRepository.findOneByUrl(url).ifPresent(existingAvatar -> {
throw new ApiException(new Error(ErrorCode.AVATAR_NAME_CONFLICT, normalizedAvatarFileName));
});
avatarToCreate.setTooltip(avatarMetadata.getName()).setUrl(url);
final InputStream markSupportedImageInputStream = getMarkSupportedInputStream(imageDataInputStream);
validateImageFile(originalFilename, avatarImageFileSize);
checkImageDimensions(markSupportedImageInputStream, normalizedAvatarFileName);
final Path imageTargetPath = properties.getAvatar().getTargetDirectory().resolve(normalizedAvatarFileName);
avatarRepository.save(avatarToCreate);
copyAvatarFile(markSupportedImageInputStream, imageTargetPath, false);
}
use of com.faforever.api.security.Audit in project faf-java-api by FAForever.
the class AvatarService method deleteAvatar.
@SneakyThrows
@Transactional
@Audit(messageTemplate = "Avatar ''{0}'' deleted.", expressions = "${avatarId}")
public void deleteAvatar(Integer avatarId) {
final Avatar avatar = getExistingAvatar(avatarId);
if (!avatar.getAssignments().isEmpty()) {
throw new ApiException(new Error(ErrorCode.AVATAR_IN_USE, avatarId));
}
// TODO: 21.11.2017 !!!!!!!!!!!! HACK TO GET FILENAME FROM URL..... !!!!!!!!!!!!!!!
final String fileName = getFileNameFromUrl(avatar.getUrl());
final Path avatarImageFilePath = properties.getAvatar().getTargetDirectory().resolve(fileName);
Files.deleteIfExists(avatarImageFilePath);
avatarRepository.delete(avatar);
}
Aggregations