|
@@ -20,13 +20,13 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import scot.carricksoftware.grants.commands.images.ImageCommand;
|
|
import scot.carricksoftware.grants.commands.images.ImageCommand;
|
|
|
import scot.carricksoftware.grants.commands.images.ImageCommandImpl;
|
|
import scot.carricksoftware.grants.commands.images.ImageCommandImpl;
|
|
|
import scot.carricksoftware.grants.constants.*;
|
|
import scot.carricksoftware.grants.constants.*;
|
|
|
|
|
+import scot.carricksoftware.grants.converters.images.ConvertToBase64;
|
|
|
import scot.carricksoftware.grants.converters.images.image.ImageCommandConverterImpl;
|
|
import scot.carricksoftware.grants.converters.images.image.ImageCommandConverterImpl;
|
|
|
import scot.carricksoftware.grants.converters.images.image.ImageConverterImpl;
|
|
import scot.carricksoftware.grants.converters.images.image.ImageConverterImpl;
|
|
|
import scot.carricksoftware.grants.services.images.image.ImageService;
|
|
import scot.carricksoftware.grants.services.images.image.ImageService;
|
|
|
import scot.carricksoftware.grants.validators.images.ImageCommandValidator;
|
|
import scot.carricksoftware.grants.validators.images.ImageCommandValidator;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.util.Base64;
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("LoggingSimilarMessage")
|
|
@SuppressWarnings("LoggingSimilarMessage")
|
|
|
@Controller
|
|
@Controller
|
|
@@ -38,18 +38,20 @@ public class ImageFormControllerImpl implements ImageFormController {
|
|
|
private final ImageCommandConverterImpl imageCommandConverter;
|
|
private final ImageCommandConverterImpl imageCommandConverter;
|
|
|
private final ImageConverterImpl imageConverter;
|
|
private final ImageConverterImpl imageConverter;
|
|
|
private final ImageCommandValidator imageCommandValidator;
|
|
private final ImageCommandValidator imageCommandValidator;
|
|
|
|
|
+ private final ConvertToBase64 convertToBase64;
|
|
|
|
|
|
|
|
|
|
|
|
|
public ImageFormControllerImpl(ImageService imageService,
|
|
public ImageFormControllerImpl(ImageService imageService,
|
|
|
ImageCommandConverterImpl imageCommandConverter,
|
|
ImageCommandConverterImpl imageCommandConverter,
|
|
|
ImageConverterImpl imageConverter,
|
|
ImageConverterImpl imageConverter,
|
|
|
- ImageCommandValidator imageCommandValidator) {
|
|
|
|
|
|
|
+ ImageCommandValidator imageCommandValidator, ConvertToBase64 convertToBase64) {
|
|
|
this.imageService = imageService;
|
|
this.imageService = imageService;
|
|
|
this.imageCommandConverter = imageCommandConverter;
|
|
this.imageCommandConverter = imageCommandConverter;
|
|
|
|
|
|
|
|
|
|
|
|
|
this.imageConverter = imageConverter;
|
|
this.imageConverter = imageConverter;
|
|
|
this.imageCommandValidator = imageCommandValidator;
|
|
this.imageCommandValidator = imageCommandValidator;
|
|
|
|
|
+ this.convertToBase64 = convertToBase64;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("SameReturnValue")
|
|
@SuppressWarnings("SameReturnValue")
|
|
@@ -77,11 +79,10 @@ public class ImageFormControllerImpl implements ImageFormController {
|
|
|
logger.debug("ImageFormControllerImpl::saveOrUpdate");
|
|
logger.debug("ImageFormControllerImpl::saveOrUpdate");
|
|
|
|
|
|
|
|
imageCommand.setFileName(file.getOriginalFilename());
|
|
imageCommand.setFileName(file.getOriginalFilename());
|
|
|
- imageCommand.setImageData(convertToBase64(file.getBytes()));
|
|
|
|
|
|
|
+ imageCommand.setImageData(convertToBase64.convert(file.getBytes()));
|
|
|
|
|
|
|
|
imageCommandValidator.validate(imageCommand, bindingResult);
|
|
imageCommandValidator.validate(imageCommand, bindingResult);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
if (bindingResult.hasErrors()) {
|
|
|
bindingResult.getAllErrors().forEach(error -> logger.debug(error.getDefaultMessage()));
|
|
bindingResult.getAllErrors().forEach(error -> logger.debug(error.getDefaultMessage()));
|
|
|
return ViewConstants.IMAGE_FORM;
|
|
return ViewConstants.IMAGE_FORM;
|
|
@@ -102,8 +103,5 @@ public class ImageFormControllerImpl implements ImageFormController {
|
|
|
return ViewConstants.IMAGE_FORM;
|
|
return ViewConstants.IMAGE_FORM;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String convertToBase64(byte[] byteData) {
|
|
|
|
|
- return Base64.getMimeEncoder().encodeToString(byteData);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|