Finalisation améliorations controlleurs/services
This commit is contained in:
parent
747d593c40
commit
cbaa4ea850
|
@ -1,6 +1,5 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.file.FileHandler;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.PasswordService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.FilesService;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -12,7 +11,6 @@ import org.springframework.context.MessageSource;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
|
@ -54,8 +52,8 @@ public class ColorRecipesExplorerApplication {
|
|||
String filePath = String.format("%s/%s.txt", UPLOAD_LOCATION, USERS_FILE_NAME);
|
||||
|
||||
try {
|
||||
if(filesService.fileExists(filePath)) filesService.createFile(filePath);
|
||||
List<String> fileContent = filesService.readFileAsStrings(filePath);
|
||||
if(filesService.exists(filePath)) filesService.create(filePath);
|
||||
List<String> fileContent = filesService.readAsStrings(filePath);
|
||||
|
||||
if (fileContent.size() < 1) {
|
||||
LOGGER.warn("Aucun mot de passe trouvé. Il sera impossible d'utiliser certaines fonctionnalités de l'application.");
|
||||
|
|
|
@ -6,7 +6,9 @@ import org.hibernate.validator.constraints.Length;
|
|||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -52,12 +54,34 @@ public class Recipe implements IModel {
|
|||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL)
|
||||
private List<RecipeStep> recipeSteps;
|
||||
|
||||
/**
|
||||
* Récupère les mélanges triés par leur identifiant.
|
||||
*
|
||||
* @return Les mélanges triés par leur identifiant
|
||||
*/
|
||||
public List<Mix> getMixesSortedById() {
|
||||
List<Mix> sortedMixes = new ArrayList<>(mixes);
|
||||
sortedMixes.sort(Comparator.comparing(Mix::getId));
|
||||
return sortedMixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les types de mélange des mélanges de la recette.
|
||||
*
|
||||
* @return Les types de mélange contenus dans la recette
|
||||
*/
|
||||
public Collection<MixType> getMixTypes() {
|
||||
return mixes.stream()
|
||||
.map(Mix::getMixType)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si la recette contient un type de mélange.
|
||||
*
|
||||
* @param mixType Le type de mélange
|
||||
* @return Si la recette contient le type de mélange
|
||||
*/
|
||||
public boolean hasMixType(MixType mixType) {
|
||||
return getMixTypes().contains(mixType);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,16 @@ public class GenericService<T extends IModel, R extends JpaRepository<T, Long>>
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(T entity) {
|
||||
return entity != null && entity.getId() != null && existsById(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(Long id) {
|
||||
return dao.existsById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getById(Long id) {
|
||||
Optional<T> found = dao.findById(id);
|
||||
|
@ -106,16 +116,6 @@ public class GenericService<T extends IModel, R extends JpaRepository<T, Long>>
|
|||
return entity.getId() != null && existsById(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(T entity) {
|
||||
return entity != null && entity.getId() != null && existsById(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(Long id) {
|
||||
return dao.existsById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforme un objet en Json.
|
||||
*
|
||||
|
|
|
@ -7,6 +7,17 @@ import java.util.List;
|
|||
|
||||
public interface IGenericService<T extends IModel> {
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
boolean exists(T entity);
|
||||
|
||||
/**
|
||||
* Vérifie si une entité correspondant à un identifiant existe.
|
||||
*
|
||||
* @param id L'identifiant de l'entité
|
||||
* @return Si un entité correspondant à l'identifiant existe
|
||||
*/
|
||||
boolean existsById(Long id);
|
||||
|
||||
/**
|
||||
* Récupère toutes les entités de type T.
|
||||
*
|
||||
|
@ -66,15 +77,4 @@ public interface IGenericService<T extends IModel> {
|
|||
* @param entities Les entités à supprimer
|
||||
*/
|
||||
void deleteAll(List<T> entities);
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
boolean exists(T entity);
|
||||
|
||||
/**
|
||||
* Vérifie si une entité correspondant à un identifiant existe.
|
||||
*
|
||||
* @param id L'identifiant de l'entité
|
||||
* @return Si un entité correspondant à l'identifiant existe
|
||||
*/
|
||||
boolean existsById(Long id);
|
||||
}
|
||||
|
|
|
@ -21,12 +21,22 @@ public class TouchUpKitService {
|
|||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
public byte[] getPdfForJobNumber(String jobNumber) throws IOException {
|
||||
return new PdfBuilder(resourceLoader, true, FONT_SIZE)
|
||||
.addLine(TOUCH_UP_FR, true, 0)
|
||||
.addLine(TOUCH_UP_EN, true, 0)
|
||||
.addLine(jobNumber, false, 10)
|
||||
.build();
|
||||
/**
|
||||
* Génère un PDF de kit de retouche pour une job.
|
||||
*
|
||||
* @param jobNumber La job
|
||||
* @return Le PDF de kit de retouche pour la job
|
||||
*/
|
||||
public byte[] generatePdfForJobNumber(String jobNumber) {
|
||||
try {
|
||||
return new PdfBuilder(resourceLoader, true, FONT_SIZE)
|
||||
.addLine(TOUCH_UP_FR, true, 0)
|
||||
.addLine(TOUCH_UP_EN, true, 0)
|
||||
.addLine(jobNumber, false, 10)
|
||||
.build();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(String.format("Impossible de générer un PDF de kit de retouche pour la job '%s': %s", jobNumber, ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class FilesService {
|
|||
* @param path Le chemin vers la fichier (sans classpath:, depuis le dossier resources)
|
||||
* @return Le contenu du fichier
|
||||
*/
|
||||
public String readResourceFile(String path) {
|
||||
public String readResource(String path) {
|
||||
String fullPath = String.format("classpath:%s", path);
|
||||
try (InputStream stream = resources.getResource(fullPath).getInputStream()) {
|
||||
return readInputStreamAsString(stream);
|
||||
|
@ -62,7 +62,7 @@ public class FilesService {
|
|||
* @return Le contenu du fichier dans un tableau de Byte
|
||||
* @throws IOException La lecture du fichier a échoué
|
||||
*/
|
||||
public byte[] readFileAsBytes(String path) throws IOException {
|
||||
public byte[] readAsBytes(String path) throws IOException {
|
||||
return Files.readAllBytes(Paths.get(path));
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class FilesService {
|
|||
* @return Le contenu du fichier dans une liste de String
|
||||
* @throws IOException La lecture du fichier a échoué
|
||||
*/
|
||||
public List<String> readFileAsStrings(String path) throws IOException {
|
||||
public List<String> readAsStrings(String path) throws IOException {
|
||||
return Files.readAllLines(Paths.get(path));
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,11 @@ public class FilesService {
|
|||
* @param path Le chemin vers le fichier
|
||||
* @return Si le fichier a bien été créé
|
||||
*/
|
||||
public boolean writeMultiPartFile(MultipartFile multipartFile, String path) {
|
||||
public boolean write(MultipartFile multipartFile, String path) {
|
||||
if (multipartFile.getSize() <= 0) return true;
|
||||
|
||||
try {
|
||||
File file = createFile(path);
|
||||
File file = create(path);
|
||||
multipartFile.transferTo(file.toPath());
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
|
@ -104,7 +104,7 @@ public class FilesService {
|
|||
* @return Le fichier créé
|
||||
* @throws IOException La création du fichier échoue
|
||||
*/
|
||||
public File createFile(String path) throws IOException {
|
||||
public File create(String path) throws IOException {
|
||||
File file = getFile(path);
|
||||
|
||||
if (!file.exists() || file.isDirectory()) {
|
||||
|
@ -121,7 +121,7 @@ public class FilesService {
|
|||
* @param path Le chemin vers le fichier
|
||||
* @throws IOException La suppression du fichier échoue
|
||||
*/
|
||||
public void deleteFile(String path) {
|
||||
public void delete(String path) {
|
||||
File file = getFile(path);
|
||||
|
||||
try {
|
||||
|
@ -137,7 +137,7 @@ public class FilesService {
|
|||
* @param path Le chemin vers le fichier
|
||||
* @return Si le fichier existe
|
||||
*/
|
||||
public boolean fileExists(String path) {
|
||||
public boolean exists(String path) {
|
||||
File file = getFile(path);
|
||||
|
||||
return file.exists() && !file.isDirectory();
|
||||
|
|
|
@ -22,22 +22,46 @@ public class ImagesService {
|
|||
this.filesService = filesService;
|
||||
}
|
||||
|
||||
public byte[] readImage(String name) {
|
||||
/**
|
||||
* Lit une image.
|
||||
*
|
||||
* @param name Le nom de l'image
|
||||
* @return Le contenu de l'image
|
||||
*/
|
||||
public byte[] read(String name) {
|
||||
try {
|
||||
return filesService.readFileAsBytes(getPath(name));
|
||||
return filesService.readAsBytes(getPath(name));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Erreur lors de la lecture d'une image: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean writeMultipartImage(MultipartFile image, String name) {
|
||||
return filesService.writeMultiPartFile(image, getPath(name));
|
||||
/**
|
||||
* Écrit des données image sur le disque.
|
||||
*
|
||||
* @param image Le contenu du fichier
|
||||
* @param name Le nom de l'image
|
||||
* @return Si l'écriture du fichier s'est achevée
|
||||
*/
|
||||
public boolean write(MultipartFile image, String name) {
|
||||
return filesService.write(image, getPath(name));
|
||||
}
|
||||
|
||||
public void deleteImage(String name) {
|
||||
filesService.deleteFile(getPath(name));
|
||||
/**
|
||||
* Supprime un fichier image.
|
||||
*
|
||||
* @param name Le nom de l'image
|
||||
*/
|
||||
public void delete(String name) {
|
||||
filesService.delete(getPath(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un InputStream contient une image.
|
||||
*
|
||||
* @param input L'InputStream
|
||||
* @return Si l'InputStream contient une image
|
||||
*/
|
||||
public boolean isImage(InputStream input) {
|
||||
try {
|
||||
return !(ImageIO.read(input) == null);
|
||||
|
|
|
@ -22,8 +22,8 @@ public class MarkdownFilesService {
|
|||
* @param path Le chemin vers la fichier (sans classpath:, depuis le dossier resources)
|
||||
* @return Le MarkDown rendu en HTML
|
||||
*/
|
||||
public String renderMarkdown(String path) {
|
||||
String fileContent = filesService.readResourceFile(path);
|
||||
public String render(String path) {
|
||||
String fileContent = filesService.readResource(path);
|
||||
|
||||
Parser parser = Parser.builder().build();
|
||||
Node document = parser.parse(fileContent);
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.files;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.ColorRecipesExplorerApplication;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.SimdutException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -17,24 +20,49 @@ public class SimdutService {
|
|||
private MaterialService materialService;
|
||||
|
||||
@Autowired
|
||||
public SimdutService(FilesService filesService, MaterialService materialService) {
|
||||
public SimdutService(FilesService filesService) {
|
||||
this.filesService = filesService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
public void setMaterialService(MaterialService materialService) {
|
||||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un produit a un fichier SIMDUT.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return Si le produit a un fichier SIMDUT
|
||||
*/
|
||||
public boolean exists(Material material) {
|
||||
return filesService.exists(getPath(material));
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si le produit correspondant à un identifiant a un fichier SIMDUT.
|
||||
*
|
||||
* @param id L'identifiant du produit
|
||||
* @return si le produit correspondant à l'identifiant a un fichier SIMDUT
|
||||
*/
|
||||
public boolean exists(Long id) {
|
||||
return exists(materialService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit le fichier SIMDUT d'un produit et retourne son contenu.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return Le contenu du fichier SIMDUT du produit
|
||||
*/
|
||||
public byte[] readSimdutForMaterial(Material material) {
|
||||
public byte[] read(Material material) {
|
||||
String path = getPath(material);
|
||||
|
||||
if (filesService.fileExists(path)) return new byte[0];
|
||||
if (filesService.exists(path)) return new byte[0];
|
||||
|
||||
try {
|
||||
return filesService.readFileAsBytes(path);
|
||||
return filesService.readAsBytes(path);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Impossible de lire un fichier SIMDUT: " + ex.getMessage());
|
||||
}
|
||||
|
@ -46,32 +74,58 @@ public class SimdutService {
|
|||
* @param id L'identifiant du produit
|
||||
* @return Le contenu du fichier SIMDUT du produit correspondant à l'identifiant
|
||||
*/
|
||||
public byte[] readSimdutForMaterialId(Long id) {
|
||||
return readSimdutForMaterial(materialService.getById(id));
|
||||
public byte[] read(Long id) {
|
||||
return read(materialService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un produit a un fichier SIMDUT.
|
||||
* Écrit le fichier SIMDUT d'un produit.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return Si le produit a un fichier SIMDUT
|
||||
* @param simdut Le contenu du fichier SIMDUT à écrire
|
||||
*/
|
||||
public boolean simdutExistsForMaterial(Material material) {
|
||||
return filesService.fileExists(getPath(material));
|
||||
public void write(Material material, MultipartFile simdut) {
|
||||
if (!filesService.write(simdut, getPath(material))) throw new SimdutException(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si le produit correspondant à un identifiant a un fichier SIMDUT.
|
||||
* Met à jour le fichier SIMDUT d'un produit
|
||||
*
|
||||
* @param id L'identifiant du produit
|
||||
* @return si le produit correspondant à l'identifiant a un fichier SIMDUT
|
||||
* @param simdut Le contenu du fichier SIMDUT mis à jour
|
||||
* @param material Le produit du SIMDUT
|
||||
*/
|
||||
public boolean simdutExistsForMaterialId(Long id) {
|
||||
return simdutExistsForMaterial(materialService.getById(id));
|
||||
public void update(MultipartFile simdut, Material material) {
|
||||
delete(material);
|
||||
write(material, simdut);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime le fichier SIMDUT pour un produit.
|
||||
*
|
||||
* @param material Le produit
|
||||
*/
|
||||
public void delete(Material material) {
|
||||
filesService.delete(getPath(material));
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le chemin vers le fichier SIMDUT d'un produit.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return Le chemin vers le fichier SIMDUT du produit
|
||||
*/
|
||||
private String getPath(Material material) {
|
||||
return String.format("%s/%s/%s", ColorRecipesExplorerApplication.UPLOAD_LOCATION, SIMDUT_DIRECTORY, materialService.getSimdutFileName(material));
|
||||
return String.format("%s/%s/%s", ColorRecipesExplorerApplication.UPLOAD_LOCATION, SIMDUT_DIRECTORY, getSimdutFileName(material));
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le nom du fichier SIMDUT d'un produit.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return Le nom du fichier SIMDUT du produit
|
||||
*/
|
||||
public String getSimdutFileName(Material material) {
|
||||
return String.format("%s_%s", material.getId(), material.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class XlsService {
|
|||
* @param recipe La recette
|
||||
* @return Le fichier XLS de la recette
|
||||
*/
|
||||
public byte[] generateXlsForRecipe(Recipe recipe) {
|
||||
public byte[] generate(Recipe recipe) {
|
||||
return new XlsxExporter().generate(recipe);
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ public class XlsService {
|
|||
* @param id L'identifiant de la recette
|
||||
* @return Le fichier XLS de la recette
|
||||
*/
|
||||
public byte[] generateXlsForRecipeId(Long id) {
|
||||
return generateXlsForRecipe(recipeService.getById(id));
|
||||
public byte[] generate(Long id) {
|
||||
return generate(recipeService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,13 +48,13 @@ public class XlsService {
|
|||
*
|
||||
* @return Le fichier ZIP contenant tous les fichiers XLS
|
||||
*/
|
||||
public byte[] generateXlsForAllRecipes() {
|
||||
public byte[] generateForAll() {
|
||||
ColorRecipesExplorerApplication.LOGGER.info("Exportation de toutes les couleurs en XLS");
|
||||
|
||||
Collection<Recipe> recipes = recipeService.getAll();
|
||||
try (ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); ZipOutputStream zipOutput = new ZipOutputStream(byteOutput)) {
|
||||
for (Recipe recipe : recipes) {
|
||||
byte[] recipeXLS = generateXlsForRecipe(recipe);
|
||||
byte[] recipeXLS = generate(recipe);
|
||||
zipOutput.putNextEntry(new ZipEntry(String.format("%s_%s.xlsx", recipe.getCompany().getName(), recipe.getName())));
|
||||
zipOutput.write(recipeXLS, 0, recipeXLS.length);
|
||||
zipOutput.closeEntry();
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityLinkedException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.CompanyDao;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.RecipeDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Service
|
||||
public class CompanyService extends GenericService<Company, CompanyDao> {
|
||||
|
||||
private RecipeDao recipeDao; // Utilise le Dao pour éviter une erreur au démarrage, citant une récursion (CompanyService -> RecipeService -> CompanyService -> ...)
|
||||
private RecipeService recipeService;
|
||||
|
||||
@Autowired
|
||||
public CompanyService(CompanyDao companyDao, RecipeDao recipeDao) {
|
||||
public CompanyService(CompanyDao companyDao) {
|
||||
super(companyDao, Company.class);
|
||||
this.recipeDao = recipeDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Company entity) {
|
||||
if (isLinkedToRecipes(entity)) throw new EntityLinkedException(type);
|
||||
|
||||
super.delete(entity);
|
||||
// Pour éviter les dépendances circulaires
|
||||
@Autowired
|
||||
@Lazy
|
||||
public void setRecipeService(RecipeService recipeService) {
|
||||
this.recipeService = recipeService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +46,22 @@ public class CompanyService extends GenericService<Company, CompanyDao> {
|
|||
* @return Si la bannière est liée à une recette
|
||||
*/
|
||||
public boolean isLinkedToRecipes(Company company) {
|
||||
return !recipeDao.findAllByCompany(company).isEmpty();
|
||||
return recipeService.existsByCompany(company);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company save(@NotNull Company entity) {
|
||||
if (existsByName(entity.getName()))
|
||||
throw new EntityAlreadyExistsException(type, ModelException.IdentifierType.NAME, entity.getName());
|
||||
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Company entity) {
|
||||
if (isLinkedToRecipes(entity)) throw new EntityLinkedException(type);
|
||||
|
||||
super.delete(entity);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.ColorRecipesExplorerApplication;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.SimdutException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.file.FileHandler;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.FilesService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.SimdutService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.dao.MaterialDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -17,7 +14,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -26,19 +22,23 @@ import java.util.stream.Collectors;
|
|||
public class MaterialService extends GenericService<Material, MaterialDao> {
|
||||
|
||||
private MixQuantityService mixQuantityService;
|
||||
private FilesService filesService;
|
||||
private SimdutService simdutService;
|
||||
|
||||
@Autowired
|
||||
public MaterialService(MaterialDao materialDao, MixQuantityService mixQuantityService, FilesService filesService) {
|
||||
public MaterialService(MaterialDao materialDao, MixQuantityService mixQuantityService, SimdutService simdutService) {
|
||||
super(materialDao, Material.class);
|
||||
this.mixQuantityService = mixQuantityService;
|
||||
this.filesService = filesService;
|
||||
this.simdutService = simdutService;
|
||||
}
|
||||
|
||||
public List<Material> getAllByMaterialType(MaterialType materialType) {
|
||||
if (materialType == null) return new ArrayList<>();
|
||||
|
||||
return dao.findAllByMaterialType(materialType);
|
||||
/**
|
||||
* Vérifie si un produit est lié à un ou plusieurs mélanges.
|
||||
*
|
||||
* @param material Le produit à vérifier.
|
||||
* @return Si le produit est lié à d'autres mélanges.
|
||||
*/
|
||||
public boolean isLinkedToMixes(Material material) {
|
||||
return mixQuantityService.existsByMaterial(material);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,10 +53,26 @@ public class MaterialService extends GenericService<Material, MaterialDao> {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Material> getAllOrdered() {
|
||||
return getAll().stream()
|
||||
.sorted(Comparator.comparing(Material::getName))
|
||||
.collect(Collectors.toList());
|
||||
/**
|
||||
* Vérifie si des produits sont d'un type de produit
|
||||
*
|
||||
* @param materialType Le type de produit
|
||||
* @return Si des produits sont du type de produit
|
||||
*/
|
||||
public boolean existsByMaterialType(MaterialType materialType) {
|
||||
return dao.existsByMaterialType(materialType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère tous les produits qui sont d'un type de produit.
|
||||
*
|
||||
* @param materialType Le type de produit des produits
|
||||
* @return Tous les produits qui sont du type de produit
|
||||
*/
|
||||
public List<Material> getAllByMaterialType(MaterialType materialType) {
|
||||
if (materialType == null) return new ArrayList<>();
|
||||
|
||||
return dao.findAllByMaterialType(materialType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,8 +88,13 @@ public class MaterialService extends GenericService<Material, MaterialDao> {
|
|||
return found.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material save(@NotNull Material entity) {
|
||||
throw new UnsupportedOperationException("Cette méthode n'est pas supportée pour les produits. Utiliser MaterialService::save(Material, MultipartFile)");
|
||||
}
|
||||
|
||||
public Material save(@NotNull Material material, MultipartFile file) {
|
||||
addSimdut(file, material);
|
||||
simdutService.write(material, file);
|
||||
|
||||
return super.save(material);
|
||||
}
|
||||
|
@ -87,20 +108,17 @@ public class MaterialService extends GenericService<Material, MaterialDao> {
|
|||
return super.update(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Material material) {
|
||||
removeSimdut(material);
|
||||
super.delete(material);
|
||||
public Material update(Material material, MultipartFile simdut) {
|
||||
simdutService.update(simdut, material);
|
||||
|
||||
return update(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un produit est lié à un ou plusieurs mélanges.
|
||||
*
|
||||
* @param material Le produit à vérifier.
|
||||
* @return Si le produit est lié à d'autres mélanges.
|
||||
*/
|
||||
public boolean isLinkedToMixes(Material material) {
|
||||
return mixQuantityService.existsByMaterial(material);
|
||||
@Override
|
||||
public void delete(Material material) {
|
||||
simdutService.delete(material);
|
||||
|
||||
super.delete(material);
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.3.0", forRemoval = true)
|
||||
|
@ -109,56 +127,4 @@ public class MaterialService extends GenericService<Material, MaterialDao> {
|
|||
delete(material);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le chemin vers le fichier SIMDUT d'un produit.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return Le chemin vers le fichier SIMDUT du produit
|
||||
*/
|
||||
private String getSimdutPath(Material material) {
|
||||
return String.format("%s/simdut/%s_%s.pdf",
|
||||
ColorRecipesExplorerApplication.UPLOAD_LOCATION,
|
||||
material.getId(),
|
||||
material.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée le fichier SIMDUT sur le disque et y transfert le contenu du MultipartFile passé en paramètre.
|
||||
* <p>
|
||||
* Cette méthode retournera true si le simdut est null ou si le transfert du fichier vers le disque a fonctionné.
|
||||
* Cette méthode retournera false si la création du fichier échoue ou si une erreur survient lors du transfert.
|
||||
*
|
||||
* @param simdut Le contenu du fichier SIMDUT
|
||||
* @param material Le produit du SIMDUT
|
||||
*/
|
||||
public void addSimdut(MultipartFile simdut, Material material) {
|
||||
if (filesService.writeMultiPartFile(simdut, getSimdutPath(material))) throw new SimdutException(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour le fichier SIMDUT sur le disque.
|
||||
*
|
||||
* @param simdut Le contenu du fichier SIMDUT mis à jour
|
||||
* @param material Le produit du SIMDUT
|
||||
*/
|
||||
public void updateSimdut(MultipartFile simdut, Material material) {
|
||||
removeSimdut(material);
|
||||
addSimdut(simdut, material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime le fichier SIMDUT pour un produit.
|
||||
* <p>
|
||||
* Cette méthode retournera true si le fichier SIMDUT du produit n'existe pas ou si la suppression est faîtes.
|
||||
*
|
||||
* @param material Le produit dont on veut supprimer le fichier SIMDUT
|
||||
*/
|
||||
public void removeSimdut(Material material) {
|
||||
filesService.deleteFile(getSimdutPath(material));
|
||||
}
|
||||
|
||||
public String getSimdutFileName(Material material) {
|
||||
return String.format("%s_%s", material.getId(), material.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,54 @@ public class MaterialTypeService extends GenericService<MaterialType, MaterialTy
|
|||
this.materialService = materialService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un type de produit correspondant à un nom existe.
|
||||
*
|
||||
* @param name Le nom à vérifier
|
||||
* @return Si un type de produit ayant le nom existe
|
||||
*/
|
||||
public boolean existsByName(String name) {
|
||||
return dao.existsByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un type de produit correspondant à un préfixe existe.
|
||||
*
|
||||
* @param prefix Le préfixe à vérifier
|
||||
* @return Si un type de produit ayant le préfixe existe
|
||||
*/
|
||||
public boolean existsByPrefix(String prefix) {
|
||||
return dao.existsByPrefix(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un type de produit est utilisé par des produits.
|
||||
*
|
||||
* @param materialType Le type de produit
|
||||
* @return si le type de produit est utilisé par des produits.
|
||||
*/
|
||||
public boolean isLinkedToMaterials(MaterialType materialType) {
|
||||
return !materialService.getAllByMaterialType(materialType).isEmpty();
|
||||
return !materialService.existsByMaterialType(materialType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère un type de produit par son nom.
|
||||
*
|
||||
* @param name Le nom du type de produit à récupérer
|
||||
* @return Le type de produit correspondant au nom.
|
||||
*/
|
||||
public MaterialType getByName(String name) {
|
||||
return dao.findByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère un type de produit par son préfixe.
|
||||
*
|
||||
* @param prefix Le préfixe du type de produit à récupérer
|
||||
* @return Le type de produit correspondant au préfixe
|
||||
*/
|
||||
public MaterialType getByPrefix(String prefix) {
|
||||
return dao.findByPrefix(prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,44 +109,4 @@ public class MaterialTypeService extends GenericService<MaterialType, MaterialTy
|
|||
|
||||
return materialType.getId().equals(materialTypeByPrefix.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère un type de produit par son nom.
|
||||
*
|
||||
* @param name Le nom du type de produit à récupérer
|
||||
* @return Le type de produit correspondant au nom.
|
||||
*/
|
||||
public MaterialType getByName(String name) {
|
||||
return dao.findByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère un type de produit par son préfixe.
|
||||
*
|
||||
* @param prefix Le préfixe du type de produit à récupérer
|
||||
* @return Le type de produit correspondant au préfixe
|
||||
*/
|
||||
public MaterialType getByPrefix(String prefix) {
|
||||
return dao.findByPrefix(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un type de produit correspondant à un nom existe.
|
||||
*
|
||||
* @param name Le nom à vérifier
|
||||
* @return Si un type de produit ayant le nom existe
|
||||
*/
|
||||
public boolean existsByName(String name) {
|
||||
return dao.existsByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un type de produit correspondant à un préfixe existe.
|
||||
*
|
||||
* @param prefix Le préfixe à vérifier
|
||||
* @return Si un type de produit ayant le préfixe existe
|
||||
*/
|
||||
public boolean existsByPrefix(String prefix) {
|
||||
return dao.existsByPrefix(prefix);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ public class MixQuantityService extends GenericService<MixQuantity, MixQuantityD
|
|||
super(mixQuantityDao, MixQuantity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie s'il y a un mélange qui contient un produit.
|
||||
*
|
||||
* @param material Le produit
|
||||
* @return S'il y a un mélange qui contient le produit
|
||||
*/
|
||||
public boolean existsByMaterial(Material material) {
|
||||
return dao.existsByMaterial(material);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@ package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
|||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityAlreadyExistsException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.ModelException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.*;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Material;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.utils.MixBuilder;
|
||||
|
@ -12,11 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -78,7 +77,7 @@ public class MixService extends GenericService<Mix, MixDao> {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public void create(MixFormDto formDto) {
|
||||
public void save(MixFormDto formDto) {
|
||||
Mix mix = new MixBuilder(mixTypeService, materialService)
|
||||
.withDto(formDto)
|
||||
.build();
|
||||
|
@ -90,7 +89,7 @@ public class MixService extends GenericService<Mix, MixDao> {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public void edit(Mix mix, MixFormDto formDto) {
|
||||
public void update(Mix mix, MixFormDto formDto) {
|
||||
mix = new MixBuilder(mixTypeService, materialService)
|
||||
.withMix(mix)
|
||||
.withDto(formDto)
|
||||
|
@ -116,26 +115,4 @@ public class MixService extends GenericService<Mix, MixDao> {
|
|||
public void deleteById(Long id) {
|
||||
delete(getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée une liste de MixQuantity, pour la création d'un mélange
|
||||
*
|
||||
* @param mix Le mélange associé aux MixQuantity
|
||||
* @param materials Les matériaux
|
||||
* @param quantities Les quantités
|
||||
* @return La liste des MixQuantity créés.
|
||||
*/
|
||||
public List<MixQuantity> createMixQuantities(Mix mix, List<Material> materials, List<Float> quantities) {
|
||||
List<MixQuantity> mixQuantities = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
Material material = materials.get(i);
|
||||
float quantity = quantities.get(i);
|
||||
|
||||
MixQuantity mixQuantity = new MixQuantity(mix, material, quantity);
|
||||
mixQuantities.add(mixQuantity);
|
||||
}
|
||||
|
||||
return mixQuantities;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class MixTypeService extends GenericService<MixType, MixTypeDao> {
|
|||
* @param materialType Le type de produit du type de mélange
|
||||
* @return Le type de mélange créé
|
||||
*/
|
||||
public MixType createByName(String name, MaterialType materialType) {
|
||||
public MixType save(String name, MaterialType materialType) {
|
||||
Material mixTypeMaterial = new Material(name, 0f, true, materialType);
|
||||
MixType mixType = new MixType(name, mixTypeMaterial);
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.core.services.model;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.*;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeEditorFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.RecipeExplorerFormDto;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.GenericService;
|
||||
|
@ -9,7 +11,6 @@ import dev.fyloz.trial.colorrecipesexplorer.dao.RecipeDao;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -33,25 +34,23 @@ public class RecipeService extends GenericService<Recipe, RecipeDao> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Récupère la liste des recettes associées à une compagnie.
|
||||
* Vérifie s'il y a une recette liée à une compagnie.
|
||||
*
|
||||
* @param company La compagnie.
|
||||
* @return La liste des recettes associées à cette compagnie.
|
||||
* @param company La compagnie
|
||||
* @return S'il y a une recette liée à la compagnie
|
||||
*/
|
||||
public List<Recipe> getByCompany(Company company) {
|
||||
return dao.findAllByCompany(company);
|
||||
public boolean existsByCompany(Company company) {
|
||||
return dao.existsByCompany(company);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère une liste triée des mélanges pour une recette.
|
||||
* Récupère toutes les recettes pour une compagnie.
|
||||
*
|
||||
* @param recipe La recette dont on veut récupérer les mélanges
|
||||
* @return Une liste triée des mélanges.
|
||||
* @param company La compagnie
|
||||
* @return Toutes les recettes pour la compagnie
|
||||
*/
|
||||
public List<Mix> getSortedMixes(Recipe recipe) {
|
||||
List<Mix> mixes = recipe.getMixes();
|
||||
mixes.sort(Comparator.comparing(Mix::getId));
|
||||
return new ArrayList<>(mixes); // Convertit le PersistentBag en ArrayList
|
||||
public Collection<Recipe> getAllByCompany(Company company) {
|
||||
return dao.findAllByCompany(company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,8 +58,9 @@ public class RecipeService extends GenericService<Recipe, RecipeDao> {
|
|||
*
|
||||
* @return Un Map contenant les recettes classées par compagnie.
|
||||
*/
|
||||
public Map<Company, List<Recipe>> getRecipesByCompany() {
|
||||
return mappedByCompany(getAll());
|
||||
public Map<Company, Collection<Recipe>> getAllMappedByCompany() {
|
||||
return companyService.getAll().stream()
|
||||
.collect(Collectors.toMap(c -> c, this::getAllByCompany));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,11 +69,14 @@ public class RecipeService extends GenericService<Recipe, RecipeDao> {
|
|||
* @param recipeDto Les informations de la recette à mettre à jour
|
||||
* @return La recette mise à jour
|
||||
*/
|
||||
@Transactional
|
||||
public Recipe updateRecipeAndSteps(RecipeEditorFormDto recipeDto) {
|
||||
Recipe recipe = recipeDto.getRecipe();
|
||||
|
||||
List<RecipeStep> steps = stepService.createAllForRecipe(recipe, recipeDto.getStep());
|
||||
return setSteps(recipe, steps);
|
||||
stepService.deleteAll(recipe.getRecipeSteps());
|
||||
recipe.setRecipeSteps(stepService.createAllForRecipe(recipe, recipeDto.getStep()));
|
||||
|
||||
return update(recipe);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,7 +124,12 @@ public class RecipeService extends GenericService<Recipe, RecipeDao> {
|
|||
return Arrays.stream(allImages).map(File::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// TODO test
|
||||
/**
|
||||
* Récupère l'index de la prochaine image pour une recette.
|
||||
*
|
||||
* @param recipe La recette
|
||||
* @return L'index de la prochaine image pour la recette
|
||||
*/
|
||||
public int getNextImageIndex(Recipe recipe) {
|
||||
String imageName = getImageFileName(recipe);
|
||||
List<String> allImages = getImageFiles(recipe);
|
||||
|
@ -130,66 +138,42 @@ public class RecipeService extends GenericService<Recipe, RecipeDao> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Récupère les mélanges d'une recette triés selon leur identifiant.
|
||||
* Récupère le nom des fichiers image d'une recette.
|
||||
*
|
||||
* @param recipe La recette
|
||||
* @return Les mélanges de la recette triés selon leur identifiant
|
||||
* @return Le nom des fichiers image de la recette
|
||||
*/
|
||||
public Collection<Mix> getMixesSortedById(Recipe recipe) {
|
||||
return getMixesSorted(recipe, Comparator.comparing(Mix::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les mélanges d'une recette triés selon un comparateur.
|
||||
*
|
||||
* @param recipe La recette
|
||||
* @param comparator Le comparateur, ou la méthode de triage
|
||||
* @return Les mélanges de la recette triés selon le comparateur
|
||||
*/
|
||||
public Collection<Mix> getMixesSorted(Recipe recipe, Comparator<? super Mix> comparator) {
|
||||
return recipe
|
||||
.getMixes()
|
||||
.parallelStream()
|
||||
.sorted(comparator)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<Company, List<Recipe>> mappedByCompany(List<Recipe> recipes) {
|
||||
List<Company> companies = companyService.getAll();
|
||||
Map<Company, List<Recipe>> mappedRecipes = new HashMap<>();
|
||||
|
||||
for (Company c : companies) {
|
||||
List<Recipe> recipesForCompany = recipes.stream().filter(r -> r.getCompany().equals(c)).collect(Collectors.toList());
|
||||
|
||||
if (recipesForCompany.size() > 0) {
|
||||
mappedRecipes.put(c, recipesForCompany);
|
||||
}
|
||||
}
|
||||
|
||||
return mappedRecipes;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected Recipe setSteps(Recipe recipe, List<RecipeStep> steps) {
|
||||
stepService.deleteAll(recipe.getRecipeSteps());
|
||||
recipe.setRecipeSteps(steps);
|
||||
|
||||
return update(recipe);
|
||||
}
|
||||
|
||||
private void removeAllFiles(Recipe recipe) {
|
||||
getImageFiles(recipe).forEach(f -> imagesService.deleteImage(f));
|
||||
}
|
||||
|
||||
public String getImageFileName(Recipe recipe) {
|
||||
return String.format("%s_%s", recipe.getId(), recipe.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le nom du fichier image d'une recette avec le prochain index disponible.
|
||||
*
|
||||
* @param recipe La recette
|
||||
* @return Le nom du fichier image de la recette avec le prochain index disponible
|
||||
*/
|
||||
public String getImageFileNameWithIndex(Recipe recipe) {
|
||||
return getImageFileNameWithIndex(recipe, getNextImageIndex(recipe));
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le nom du fichier image d'une recette avec un index.
|
||||
*
|
||||
* @param recipe La recette
|
||||
* @param index L'index du fichier image
|
||||
* @return Le nom du fichier image de la recette avec l'index
|
||||
*/
|
||||
public String getImageFileNameWithIndex(Recipe recipe, int index) {
|
||||
return String.format("%s-%s", getImageFileName(recipe), index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime tous les fichiers image d'une recette.
|
||||
*
|
||||
* @param recipe La recette
|
||||
*/
|
||||
private void removeAllFiles(Recipe recipe) {
|
||||
getImageFiles(recipe).forEach(f -> imagesService.delete(f));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class MixBuilder {
|
|||
|
||||
public MixBuilder withDto(MixFormDto dto) {
|
||||
if (this.mixType == null) {
|
||||
this.mixType = mixTypeService.createByName(dto.getMixTypeName(), dto.getMaterialType());
|
||||
this.mixType = mixTypeService.save(dto.getMixTypeName(), dto.getMaterialType());
|
||||
} else {
|
||||
this.mixType.setName(dto.getMixTypeName());
|
||||
this.mixType.getMaterial().setMaterialType(dto.getMaterialType());
|
||||
|
|
|
@ -14,7 +14,6 @@ public interface MaterialDao extends JpaRepository<Material, Long> {
|
|||
|
||||
List<Material> findAllByMaterialType(MaterialType materialType);
|
||||
|
||||
List<Material> findAllByNameContainingIgnoreCase(String stringSearch);
|
||||
boolean existsByMaterialType(MaterialType materialType);
|
||||
|
||||
boolean existsByName(String name);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@ public interface RecipeDao extends JpaRepository<Recipe, Long> {
|
|||
|
||||
Recipe findByName(String name);
|
||||
|
||||
@Query("select r from Recipe r where upper(r.name) like %?1% or upper(r.description) like %?1%")
|
||||
List<Recipe> findAllByRecipeDescriptionContainsOrRecipeCodeContains(String searchWordUpperCase);
|
||||
boolean existsByCompany(Company company);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web;
|
|||
public class WebsitePaths {
|
||||
// Autres
|
||||
public static final String INDEX = "index";
|
||||
public static final String SEARCH = "search";
|
||||
public static final String SEARCH_INVENTORY = "inventory/search";
|
||||
public static final String SIMDUT_FILES = "simdut/{id}";
|
||||
public static final String PASSWORD_VALIDATION = "password/valid";
|
||||
public static final String RECIPE_XLS = "recipe/xls/{id}";
|
||||
|
@ -35,7 +33,6 @@ public class WebsitePaths {
|
|||
public static final String EXPLORER_RECIPE = "recipe/explore";
|
||||
public static final String EXPLORER_RECIPE_SPECIFIC = "recipe/explore/{id}";
|
||||
public static final String CREATOR_RECIPE = "recipe/creator";
|
||||
public static final String CREATOR_RECIPE_SUCCESS = "recipe/created";
|
||||
public static final String EDITOR_RECIPE = "recipe/editor";
|
||||
public static final String EDITOR_RECIPE_SPECIFIC = "recipe/editor/{id}";
|
||||
public static final String EDITOR_RECIPE_EDITOR = "recipe/edit";
|
||||
|
@ -44,7 +41,6 @@ public class WebsitePaths {
|
|||
|
||||
// Compagnies
|
||||
public static final String CREATOR_COMPANY = "company/creator";
|
||||
public static final String CREATOR_COMPANY_SUCCESS = "company/created";
|
||||
public static final String REMOVER_COMPANY = "company/remover";
|
||||
public static final String REMOVER_COMPANY_SPECIFIC = "company/remover/{id}";
|
||||
|
||||
|
@ -52,7 +48,6 @@ public class WebsitePaths {
|
|||
public static final String CREATOR_MATERIAL = "material/creator";
|
||||
public static final String EDIT_MATERIAL_SIMDUT = "material/simdut";
|
||||
public static final String EDIT_MATERIAL_SIMDUT_SPECIFIC = "material/simdut/{id}";
|
||||
public static final String CREATOR_MATERIAL_SUCCESS = "material/created";
|
||||
public static final String REMOVER_MATERIAL = "material/remover";
|
||||
public static final String REMOVER_MATERIAL_SPECIFIC = "material/remover/{id}";
|
||||
public static final String EDITOR_MATERIAL = "material/editor";
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.JSONResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Company;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.PasswordService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -13,10 +10,7 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.INDEX;
|
||||
import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.PASSWORD_VALIDATION;
|
||||
|
@ -39,7 +33,7 @@ public class IndexController {
|
|||
@GetMapping({INDEX, "/"})
|
||||
public ModelAndView getPage() {
|
||||
return new ModelResponseBuilder(INDEX)
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getRecipesByCompany())
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getAllMappedByCompany())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,6 @@ public class OthersController {
|
|||
@GetMapping(value = UPDATES_GET, produces = MediaType.TEXT_HTML_VALUE)
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> getUpdates() {
|
||||
return new ResponseEntity<>(markdownService.renderMarkdown("updates.md"), HttpStatus.OK);
|
||||
return new ResponseEntity<>(markdownService.render("updates.md"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class RecipeExplorerController {
|
|||
|
||||
return modelResponseBuilder
|
||||
.addResponseData(ResponseDataType.RECIPE, recipe)
|
||||
.addResponseData(ResponseDataType.MIXES, recipeService.getMixesSortedById(recipe))
|
||||
.addResponseData(ResponseDataType.MIXES, recipe.getMixesSortedById())
|
||||
.addResponseData(ResponseDataType.IMAGES, recipeService.getImageFiles(recipe))
|
||||
.build();
|
||||
} catch (EntityNotFoundException e) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class CompanyCreatorController {
|
|||
}
|
||||
|
||||
@GetMapping(CREATOR_COMPANY)
|
||||
public ModelAndView showCreationPage(ModelAndView model, Company company) {
|
||||
public ModelAndView getPage(ModelAndView model, Company company) {
|
||||
return new ModelResponseBuilder(model)
|
||||
.withView(CREATOR_COMPANY)
|
||||
.addResponseData(ResponseDataType.COMPANY, company)
|
||||
|
@ -48,6 +48,6 @@ public class CompanyCreatorController {
|
|||
modelResponseBuilder.addResponseCode(ResponseCode.COMPANY_ALREADY_EXIST, company.getName());
|
||||
}
|
||||
|
||||
return showCreationPage(modelResponseBuilder.build(), company);
|
||||
return getPage(modelResponseBuilder.build(), company);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class MaterialCreatorController {
|
|||
}
|
||||
|
||||
@GetMapping(CREATOR_MATERIAL)
|
||||
public ModelAndView showCreationPage(ModelAndView model, Material material) {
|
||||
public ModelAndView getPage(ModelAndView model, Material material) {
|
||||
return new ModelResponseBuilder(model)
|
||||
.withView(CREATOR_MATERIAL)
|
||||
.addResponseData(ResponseDataType.MATERIAL, material != null ? material : new Material())
|
||||
|
@ -42,12 +42,12 @@ public class MaterialCreatorController {
|
|||
}
|
||||
|
||||
@PostMapping(value = CREATOR_MATERIAL, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ModelAndView create(@Valid Material material, MultipartFile simdut) {
|
||||
public ModelAndView createMaterial(@Valid Material material, MultipartFile simdut) {
|
||||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder();
|
||||
|
||||
try {
|
||||
materialService.save(material, simdut);
|
||||
return showCreationPage(
|
||||
return getPage(
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.SUCCESS_SAVING_MATERIAL, material.getName()).build(),
|
||||
null
|
||||
);
|
||||
|
@ -58,6 +58,6 @@ public class MaterialCreatorController {
|
|||
modelResponseBuilder.addResponseCode(ResponseCode.ERROR_SAVING_SIMDUT);
|
||||
}
|
||||
|
||||
return showCreationPage(modelResponseBuilder.build(), material);
|
||||
return getPage(modelResponseBuilder.build(), material);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class MaterialTypeCreatorController {
|
|||
}
|
||||
|
||||
@PostMapping(CREATOR_MATERIAL_TYPE)
|
||||
public ModelAndView create(@Valid MaterialType materialType) {
|
||||
public ModelAndView createMaterialType(@Valid MaterialType materialType) {
|
||||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder(ControllerUtils.redirect(INDEX));
|
||||
|
||||
try {
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MixCreatorController {
|
|||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder();
|
||||
|
||||
try {
|
||||
mixService.create(formDto);
|
||||
mixService.save(formDto);
|
||||
|
||||
return modelResponseBuilder
|
||||
.withRedirect(EDITOR_RECIPE_SPECIFIC, formDto.getRecipe().getId())
|
||||
|
|
|
@ -30,7 +30,7 @@ public class RecipeCreatorController {
|
|||
}
|
||||
|
||||
@GetMapping(CREATOR_RECIPE)
|
||||
public ModelAndView showCreationPage(ModelAndView model, Recipe recipe) {
|
||||
public ModelAndView getPage(ModelAndView model, Recipe recipe) {
|
||||
ModelResponseBuilder responseBuilder = new ModelResponseBuilder(model)
|
||||
.withView(CREATOR_RECIPE)
|
||||
.addResponseData(ResponseDataType.COMPANIES, companyService.getAll())
|
||||
|
|
|
@ -58,7 +58,7 @@ public class MaterialEditorController {
|
|||
}
|
||||
|
||||
@PostMapping(value = EDITOR_MATERIAL, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public ModelAndView saveEditedMaterial(Material material) {
|
||||
public ModelAndView updateMaterial(Material material) {
|
||||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder();
|
||||
|
||||
try {
|
||||
|
@ -77,7 +77,7 @@ public class MaterialEditorController {
|
|||
}
|
||||
|
||||
@GetMapping(value = EDIT_MATERIAL_SIMDUT_SPECIFIC)
|
||||
public ModelAndView chooseSIMDUTFile(ModelAndView model, @PathVariable Long id) {
|
||||
public ModelAndView getSimdutPage(ModelAndView model, @PathVariable Long id) {
|
||||
return new ModelResponseBuilder(model)
|
||||
.withView(EDIT_MATERIAL_SIMDUT)
|
||||
.addResponseData(ResponseDataType.MATERIAL_ID, id)
|
||||
|
@ -85,14 +85,14 @@ public class MaterialEditorController {
|
|||
}
|
||||
|
||||
@PostMapping(value = EDIT_MATERIAL_SIMDUT, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ModelAndView saveSIMDUT(Long id, MultipartFile simdut) {
|
||||
public ModelAndView updateSimdut(Long id, MultipartFile simdut) {
|
||||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder().withRedirect(EDITOR_MATERIAL_SPECIFIC, id);
|
||||
|
||||
try {
|
||||
Material material = materialService.getById(id);
|
||||
materialService.updateSimdut(simdut, material);
|
||||
materialService.update(material, simdut);
|
||||
} catch (EntityNotFoundException ex) {
|
||||
return chooseSIMDUTFile(
|
||||
return getSimdutPage(
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND, id).build(),
|
||||
id
|
||||
);
|
||||
|
|
|
@ -62,29 +62,11 @@ public class MixEditorController {
|
|||
try {
|
||||
Mix mix = mixService.getById(id);
|
||||
|
||||
mixService.edit(mix, formDto);
|
||||
mixService.update(mix, formDto);
|
||||
} catch (EntityNotFoundException ex) {
|
||||
return getPage(modelResponseBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, id).build(), id);
|
||||
}
|
||||
|
||||
return modelResponseBuilder.build();
|
||||
}
|
||||
|
||||
@GetMapping(REMOVER_MIX_SPECIFIC)
|
||||
public ModelAndView deleteMix(@PathVariable Long id) {
|
||||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder();
|
||||
|
||||
try {
|
||||
Mix mix = mixService.getById(id);
|
||||
mixService.delete(mix);
|
||||
|
||||
return modelResponseBuilder
|
||||
.withRedirect(EDITOR_RECIPE_SPECIFIC, mix.getRecipe().getId())
|
||||
.build();
|
||||
} catch (EntityNotFoundException ex) {
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, id);
|
||||
}
|
||||
|
||||
return getPage(modelResponseBuilder.build(), id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import dev.fyloz.trial.colorrecipesexplorer.core.services.model.CompanyService;
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -36,7 +35,7 @@ public class RecipeEditorController {
|
|||
public ModelAndView getPage(ModelAndView model) {
|
||||
return new ModelResponseBuilder(model)
|
||||
.withView(EDITOR_RECIPE)
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getRecipesByCompany())
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getAllMappedByCompany())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -50,7 +49,7 @@ public class RecipeEditorController {
|
|||
modelResponseBuilder
|
||||
.addResponseData(ResponseDataType.RECIPE, recipe)
|
||||
.addResponseData(ResponseDataType.COMPANIES, companyService.getAll())
|
||||
.addResponseData(ResponseDataType.MIXES, recipeService.getSortedMixes(recipe))
|
||||
.addResponseData(ResponseDataType.MIXES, recipe.getMixesSortedById())
|
||||
.addResponseData(ResponseDataType.IMAGES, recipeService.getImageFiles(recipe))
|
||||
.addResponseData(ResponseDataType.RECIPE_JSON, recipeService.asJson(recipe));
|
||||
} catch (EntityNotFoundException ex) {
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
@ -40,7 +39,7 @@ public class ImageFilesController {
|
|||
public ResponseEntity<byte[]> getImage(@PathVariable String image) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.IMAGE_JPEG);
|
||||
return new ResponseEntity<>(imagesService.readImage(image), headers, HttpStatus.OK);
|
||||
return new ResponseEntity<>(imagesService.read(image), headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(ADD_IMAGE_SPECIFIC)
|
||||
|
@ -61,7 +60,7 @@ public class ImageFilesController {
|
|||
} else {
|
||||
Recipe recipe = recipeService.getById(id);
|
||||
|
||||
if (imagesService.writeMultipartImage(image, recipeService.getImageFileNameWithIndex(recipe)))
|
||||
if (imagesService.write(image, recipeService.getImageFileNameWithIndex(recipe)))
|
||||
return modelResponseBuilder.build();
|
||||
else modelResponseBuilder.addResponseCode(ResponseCode.ERROR_SAVING_IMAGE);
|
||||
}
|
||||
|
@ -75,7 +74,7 @@ public class ImageFilesController {
|
|||
@GetMapping(value = DELETE_IMAGE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public Map<String, Object> deleteImage(@PathVariable String image) {
|
||||
imagesService.deleteImage(image);
|
||||
imagesService.delete(image);
|
||||
|
||||
return new JSONResponseBuilder().build();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.files;
|
|||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.files.SimdutService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -33,8 +32,8 @@ public class SIMDUTFilesController {
|
|||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
try {
|
||||
if (simdutService.simdutExistsForMaterialId(id)) {
|
||||
byte[] simdutContent = simdutService.readSimdutForMaterialId(id);
|
||||
if (simdutService.exists(id)) {
|
||||
byte[] simdutContent = simdutService.read(id);
|
||||
headers.setContentType(MediaType.APPLICATION_PDF);
|
||||
return new ResponseEntity<>(simdutContent, headers, HttpStatus.OK);
|
||||
} else {
|
||||
|
@ -50,7 +49,7 @@ public class SIMDUTFilesController {
|
|||
@PostMapping(SIMDUT_FILES)
|
||||
public ResponseEntity<Void> getFile(@PathVariable Long id) {
|
||||
try {
|
||||
return ResponseEntity.status(simdutService.simdutExistsForMaterialId(id) ? HttpStatus.FOUND : HttpStatus.NOT_FOUND).build();
|
||||
return ResponseEntity.status(simdutService.exists(id) ? HttpStatus.FOUND : HttpStatus.NOT_FOUND).build();
|
||||
} catch (EntityNotFoundException ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package dev.fyloz.trial.colorrecipesexplorer.web.controller.files;
|
|||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.TouchUpKitService;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -11,11 +11,8 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.*;
|
||||
|
||||
@Controller
|
||||
|
@ -34,19 +31,19 @@ public class TouchUpKitController {
|
|||
public ModelAndView getPage(ModelAndView model) {
|
||||
return new ModelResponseBuilder(model)
|
||||
.withView(TOUCHUP)
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getRecipesByCompany())
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getAllMappedByCompany())
|
||||
.build();
|
||||
}
|
||||
|
||||
@PostMapping(value = TOUCHUP_PDF, produces = MediaType.APPLICATION_PDF_VALUE)
|
||||
public ResponseEntity<byte[]> getTouchUpKitPdf(@RequestBody String jobNumber) throws IOException {
|
||||
return new ResponseEntity<>(touchUpKitService.getPdfForJobNumber(jobNumber.replace("jobNumber=", "")), HttpStatus.FOUND);
|
||||
public ResponseEntity<byte[]> getTouchUpKitPdf(String jobNumber) {
|
||||
return new ResponseEntity<>(touchUpKitService.generatePdfForJobNumber(jobNumber), HttpStatus.FOUND);
|
||||
}
|
||||
|
||||
@PostMapping(value = TOUCHUP_PTOUCH)
|
||||
public ModelAndView getTouchUpKitPtouch(@RequestBody String jobNumber) {
|
||||
public ModelAndView getTouchUpKitPtouch(String jobNumber) {
|
||||
return new ModelResponseBuilder(TOUCHUP_PTOUCH_PAGE)
|
||||
.addAttribute("jobNumber", jobNumber.replace("jobNumber=", ""))
|
||||
.addAttribute("jobNumber", jobNumber)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class XlsExporterController {
|
|||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
try {
|
||||
byte[] xlsContent = xlsService.generateXlsForRecipeId(id);
|
||||
byte[] xlsContent = xlsService.generate(id);
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.headers(headers)
|
||||
|
@ -49,7 +49,7 @@ public class XlsExporterController {
|
|||
public ResponseEntity<byte[]> getAllXls() throws IOException {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
byte[] allXlsContent = xlsService.generateXlsForAllRecipes();
|
||||
byte[] allXlsContent = xlsService.generateForAll();
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.headers(headers)
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package dev.fyloz.trial.colorrecipesexplorer.web.controller.removers;
|
||||
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundException;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.*;
|
||||
|
||||
@Controller
|
||||
public class MixRemoverController {
|
||||
|
||||
private MixService mixService;
|
||||
|
||||
public MixRemoverController(MixService mixService) {
|
||||
this.mixService = mixService;
|
||||
}
|
||||
|
||||
@GetMapping(REMOVER_MIX_SPECIFIC)
|
||||
public ModelAndView removeMix(@PathVariable Long id) {
|
||||
ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder();
|
||||
|
||||
try {
|
||||
Mix mix = mixService.getById(id);
|
||||
mixService.delete(mix);
|
||||
|
||||
return modelResponseBuilder
|
||||
.withRedirect(EDITOR_RECIPE_SPECIFIC, mix.getRecipe().getId())
|
||||
.build();
|
||||
} catch (EntityNotFoundException ex) {
|
||||
modelResponseBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, id);
|
||||
}
|
||||
|
||||
return modelResponseBuilder
|
||||
.withRedirect(EDITOR_MIX_SPECIFIC, id)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import dev.fyloz.trial.colorrecipesexplorer.core.exception.model.EntityNotFoundE
|
|||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ModelResponseBuilder;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseCode;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.io.response.ResponseDataType;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe;
|
||||
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -12,8 +11,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.REMOVER_RECIPE;
|
||||
import static dev.fyloz.trial.colorrecipesexplorer.web.WebsitePaths.REMOVER_RECIPE_SPECIFIC;
|
||||
|
||||
|
@ -30,7 +27,7 @@ public class RecipeRemoverController {
|
|||
public ModelAndView getPage(ModelAndView model) {
|
||||
return new ModelResponseBuilder(model)
|
||||
.withView(REMOVER_RECIPE)
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getRecipesByCompany())
|
||||
.addResponseData(ResponseDataType.RECIPE_MAP, recipeService.getAllMappedByCompany())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue