From 619abb047392f1b202a80bf7d20d2b17f1a1dd4d Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Mon, 14 Oct 2024 16:52:07 +0100 Subject: [PATCH 1/6] update: Add methods to find exam and exam type by codes --- .../isf/exa/manager/ExamBrowsingManager.java | 55 +++++++---- .../org/isf/exa/service/ExamIoOperations.java | 97 ++++++++++++++----- .../manager/ExamTypeBrowserManager.java | 21 ++-- .../exatype/service/ExamTypeIoOperation.java | 25 +++-- 4 files changed, 138 insertions(+), 60 deletions(-) diff --git a/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java b/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java index 86c34ab2c..450e6ead7 100644 --- a/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java +++ b/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java @@ -35,17 +35,13 @@ import org.springframework.stereotype.Component; /** - * Class that provides gui separation from database operations and gives some - * useful logic manipulations of the dinamic data (memory) - * - * @author bob - * 19-dec-2005 - * 14-jan-2006 + * Class that provides gui separation from database operations and gives some useful logic manipulations of the dinamic data (memory) + * @author bob 19-dec-2005 14-jan-2006 */ @Component public class ExamBrowsingManager { - private ExamIoOperations ioOperations; + private final ExamIoOperations ioOperations; public ExamBrowsingManager(ExamIoOperations examIoOperations) { this.ioOperations = examIoOperations; @@ -53,7 +49,6 @@ public ExamBrowsingManager(ExamIoOperations examIoOperations) { /** * Verify if the object is valid for CRUD and return a list of errors, if any - * * @param exam * @param insert {@code true} or updated {@code false} * @throws OHServiceException @@ -78,7 +73,6 @@ protected void validateExam(Exam exam, boolean insert) throws OHServiceException /** * Returns the list of {@link Exam}s - * * @return the list of {@link Exam}s. It could be {@code null} * @throws OHServiceException */ @@ -88,7 +82,6 @@ public List getExams() throws OHServiceException { /** * Returns the list of {@link Exam}s that matches passed description - * * @param description - the exam description * @return the list of {@link Exam}s. It could be {@code null} * @throws OHServiceException @@ -99,7 +92,6 @@ public List getExams(String description) throws OHServiceException { /** * Returns the list of {@link Exam}s by {@link ExamType} description - * * @param description - the exam description * @return the list of {@link Exam}s. It could be {@code null} * @throws OHServiceException @@ -110,7 +102,6 @@ public List getExamsByTypeDescription(String description) throws OHService /** * Returns the list of {@link ExamType}s - * * @return the list of {@link ExamType}s. It could be {@code null} * @throws OHServiceException */ @@ -119,10 +110,7 @@ public List getExamType() throws OHServiceException { } /** - * This function controls the presence of a record with the same key as in - * the parameter; Returns false if the query finds no record, else returns - * true - * + * This function controls the presence of a record with the same key as in the parameter; Returns false if the query finds no record, else returns true * @param exam the {@link Exam} * @return {@code true} if the Exam code has already been used, {@code false} otherwise * @throws OHServiceException @@ -131,9 +119,30 @@ public boolean isKeyPresent(Exam exam) throws OHServiceException { return ioOperations.isKeyPresent(exam); } + /** + * Insert a new {@link Exam} in the DB with exam rows. + * @param payload - the {@link Exam} to insert + * @param rows - the {@link List} to associate as exam rows + * @return the newly persisted {@link Exam}. + * @throws OHServiceException + */ + public Exam create(Exam payload, List rows) throws OHServiceException { + return ioOperations.create(payload, rows); + } + + /** + * Update an existing {@link Exam} in the DB with exam rows. + * @param payload - the {@link Exam} to insert + * @param rows - the {@link List} to associate as exam rows + * @return the newly persisted {@link Exam}. + * @throws OHServiceException + */ + public Exam update(Exam payload, List rows) throws OHServiceException { + return ioOperations.update(payload, rows); + } + /** * Insert a new {@link Exam} in the DB. - * * @param exam - the {@link Exam} to insert * @return the newly persisted {@link Exam}. * @throws OHServiceException @@ -145,7 +154,6 @@ public Exam newExam(Exam exam) throws OHServiceException { /** * Updates an existing {@link Exam} in the db - * * @param exam - the {@link Exam} to update * @return {@code true} if the existing {@link Exam} has been updated, {@code false} otherwise * @throws OHServiceException @@ -157,11 +165,20 @@ public Exam updateExam(Exam exam) throws OHServiceException { /** * Delete an {@link Exam} - * * @param exam - the {@link Exam} to delete * @throws OHServiceException */ public void deleteExam(Exam exam) throws OHServiceException { ioOperations.deleteExam(exam); } + + /** + * Find exam by code + * @param code - the code + * @return The exam if found, {@code null} otherwise. + * @throws OHServiceException + */ + public Exam findByCode(String code) throws OHServiceException { + return ioOperations.findByCode(code); + } } diff --git a/src/main/java/org/isf/exa/service/ExamIoOperations.java b/src/main/java/org/isf/exa/service/ExamIoOperations.java index a668b8952..fe2da85c3 100644 --- a/src/main/java/org/isf/exa/service/ExamIoOperations.java +++ b/src/main/java/org/isf/exa/service/ExamIoOperations.java @@ -22,6 +22,7 @@ package org.isf.exa.service; import java.util.List; +import java.util.Objects; import org.isf.exa.model.Exam; import org.isf.exa.model.ExamRow; @@ -33,18 +34,18 @@ import org.springframework.transaction.annotation.Transactional; @Service -@Transactional(rollbackFor=OHServiceException.class) +@Transactional(rollbackFor = OHServiceException.class) @TranslateOHServiceException public class ExamIoOperations { - private ExamIoOperationRepository repository; + private final ExamIoOperationRepository repository; - private ExamRowIoOperationRepository rowRepository; + private final ExamRowIoOperationRepository rowRepository; - private ExamTypeIoOperationRepository typeRepository; + private final ExamTypeIoOperationRepository typeRepository; public ExamIoOperations(ExamIoOperationRepository examIoOperationRepository, ExamRowIoOperationRepository examRowIoOperationRepository, - ExamTypeIoOperationRepository examTypeIoOperationRepository) { + ExamTypeIoOperationRepository examTypeIoOperationRepository) { this.repository = examIoOperationRepository; this.rowRepository = examRowIoOperationRepository; this.typeRepository = examTypeIoOperationRepository; @@ -58,7 +59,7 @@ public ExamIoOperations(ExamIoOperationRepository examIoOperationRepository, Exa public List getExams() throws OHServiceException { return getExamsByDesc(null); } - + /** * Returns the list of {@link Exam}s that matches passed description * @param description - the exam description @@ -67,9 +68,9 @@ public List getExams() throws OHServiceException { */ public List getExamsByDesc(String description) throws OHServiceException { return description != null ? repository.findByDescriptionContainingOrderByExamtypeDescriptionAscDescriptionAsc(description) : - repository.findByOrderByDescriptionAscDescriptionAsc(); + repository.findByOrderByDescriptionAscDescriptionAsc(); } - + /** * Returns the list of {@link Exam}s by {@link ExamType} description * @param description - the exam description @@ -78,7 +79,7 @@ public List getExamsByDesc(String description) throws OHServiceException { */ public List getExamsByExamTypeDesc(String description) throws OHServiceException { return description != null ? repository.findByExamtype_DescriptionContainingOrderByExamtypeDescriptionAscDescriptionAsc(description) : - repository.findByOrderByDescriptionAscDescriptionAsc(); + repository.findByOrderByDescriptionAscDescriptionAsc(); } /** @@ -90,12 +91,57 @@ public List getExamType() throws OHServiceException { return typeRepository.findAllByOrderByDescriptionAsc(); } + /** + * Insert a new {@link Exam} in the DB with exam rows. + * @param payload - the {@link Exam} to insert + * @param rows - the {@link List} to associate as exam rows + * @return the newly persisted {@link Exam}. + * @throws OHServiceException + */ + @Transactional + public Exam create(Exam payload, List rows) throws OHServiceException { + Exam exam = repository.save(payload); + if (exam.getProcedure() == 3) { + return exam; + } + if (rows != null && !rows.isEmpty()) { + rowRepository.saveAll(rows.stream().map(description -> new ExamRow(exam, description)).toList()); + } + return exam; + } + + /** + * Update an existing {@link Exam} in the DB with exam rows. + * @param payload - the {@link Exam} to insert + * @param rows - the {@link List} to associate as exam rows + * @return the newly persisted {@link Exam}. + * @throws OHServiceException + */ + @Transactional + public Exam update(Exam payload, List rows) throws OHServiceException { + Exam exam = repository.save(payload); + if (exam.getProcedure() == 3) { + return exam; + } + List examRows = rowRepository.findAllByExam_CodeOrderByDescription(exam.getCode()); + List rowsToRemove = examRows.stream().filter(examRow -> !rows.contains(examRow.getDescription())).toList(); + List rowsToAdd = rows.stream().filter(row -> examRows.stream().noneMatch(examRow -> Objects.equals(row, examRow.getDescription()))) + .map(description -> new ExamRow(exam, description)).toList(); + + if (!rowsToRemove.isEmpty()) { + rowRepository.deleteAll(rowsToRemove); + } + if (!rowsToAdd.isEmpty()) { + rowRepository.saveAll(rowsToAdd); + } + return exam; + } + /** * Insert a new {@link Exam} in the DB. - * * @param exam - the {@link Exam} to insert * @return the newly persisted {@link Exam}. - * @throws OHServiceException + * @throws OHServiceException */ public Exam newExam(Exam exam) throws OHServiceException { return repository.save(exam); @@ -103,7 +149,6 @@ public Exam newExam(Exam exam) throws OHServiceException { /** * Insert a new {@link ExamRow} in the DB. - * * @param examRow - the {@link ExamRow} to insert * @return the newly persisted {@link ExamRow}. * @throws OHServiceException @@ -142,21 +187,17 @@ public void deleteExamRow(ExamRow examRow) throws OHServiceException { } /** - * This function controls the presence of a record with the same key as in - * the parameter; Returns false if the query finds no record, else returns - * true - * + * This function controls the presence of a record with the same key as in the parameter; Returns false if the query finds no record, else returns true * @param exam the {@link Exam} * @return {@code true} if the Exam code has already been used, {@code false} otherwise - * @throws OHServiceException + * @throws OHServiceException */ public boolean isKeyPresent(Exam exam) throws OHServiceException { return repository.findById(exam.getCode()).orElse(null) != null; } - + /** - * Sanitize the given {@link String} value. - * This method is maintained only for backward compatibility. + * Sanitize the given {@link String} value. This method is maintained only for backward compatibility. * @param value the value to sanitize. * @return the sanitized value or {@code null} if the passed value is {@code null}. */ @@ -169,10 +210,9 @@ protected String sanitize(String value) { /** * Checks if the code is already in use - * * @param code - the exam code * @return {@code true} if the code is already in use, {@code false} otherwise - * @throws OHServiceException + * @throws OHServiceException */ public boolean isCodePresent(String code) throws OHServiceException { return repository.existsById(code); @@ -180,12 +220,21 @@ public boolean isCodePresent(String code) throws OHServiceException { /** * Checks if the code is already in use - * * @param code - the exam row code * @return {@code true} if the code is already in use, {@code false} otherwise - * @throws OHServiceException + * @throws OHServiceException */ public boolean isRowPresent(Integer code) throws OHServiceException { return rowRepository.existsById(code); } + + /** + * Find exam by code + * @param code - the code + * @return The exam if found, {@code null} otherwise. + * @throws OHServiceException + */ + public Exam findByCode(String code) throws OHServiceException { + return repository.findById(code).orElse(null); + } } diff --git a/src/main/java/org/isf/exatype/manager/ExamTypeBrowserManager.java b/src/main/java/org/isf/exatype/manager/ExamTypeBrowserManager.java index 4c6c0337d..5bd2d83b7 100644 --- a/src/main/java/org/isf/exatype/manager/ExamTypeBrowserManager.java +++ b/src/main/java/org/isf/exatype/manager/ExamTypeBrowserManager.java @@ -36,7 +36,7 @@ @Component public class ExamTypeBrowserManager { - private ExamTypeIoOperation ioOperations; + private final ExamTypeIoOperation ioOperations; public ExamTypeBrowserManager(ExamTypeIoOperation examTypeIoOperation) { this.ioOperations = examTypeIoOperation; @@ -44,7 +44,6 @@ public ExamTypeBrowserManager(ExamTypeIoOperation examTypeIoOperation) { /** * Verify if the object is valid for CRUD and return a list of errors, if any - * * @param examType * @param insert {@code true} or updated {@code false} * @throws OHServiceException @@ -72,7 +71,6 @@ protected void validateExamType(ExamType examType, boolean insert) throws OHServ /** * Return the list of {@link ExamType}s. - * * @return the list of {@link ExamType}s. It could be {@code null} * @throws OHServiceException */ @@ -82,7 +80,6 @@ public List getExamType() throws OHServiceException { /** * Insert a new {@link ExamType} into the DB. - * * @param examType - the {@link ExamType} to insert. * @return the newly inserted {@link ExamType}. * @throws OHServiceException @@ -94,7 +91,6 @@ public ExamType newExamType(ExamType examType) throws OHServiceException { /** * Update an already existing {@link ExamType}. - * * @param examType - the {@link ExamType} to update * @return the updated {@link ExamType}. * @throws OHServiceException @@ -105,9 +101,7 @@ public ExamType updateExamType(ExamType examType) throws OHServiceException { } /** - * This checks for the presence of a record with the same code as in - * the parameter. - * + * This checks for the presence of a record with the same code as in the parameter. * @param code - the code * @return {@code true} if the code is present, {@code false} otherwise. * @throws OHServiceException @@ -118,11 +112,20 @@ public boolean isCodePresent(String code) throws OHServiceException { /** * Delete the passed {@link ExamType}. - * * @param examType - the {@link ExamType} to delete. * @throws OHServiceException */ public void deleteExamType(ExamType examType) throws OHServiceException { ioOperations.deleteExamType(examType); } + + /** + * Find exam type by code + * @param code - the code + * @return The exam type if found, {@code null} otherwise. + * @throws OHServiceException + */ + public ExamType findByCode(String code) throws OHServiceException { + return ioOperations.findByCode(code); + } } diff --git a/src/main/java/org/isf/exatype/service/ExamTypeIoOperation.java b/src/main/java/org/isf/exatype/service/ExamTypeIoOperation.java index 196e7d256..25c99b45c 100644 --- a/src/main/java/org/isf/exatype/service/ExamTypeIoOperation.java +++ b/src/main/java/org/isf/exatype/service/ExamTypeIoOperation.java @@ -30,11 +30,11 @@ import org.springframework.transaction.annotation.Transactional; @Service -@Transactional(rollbackFor=OHServiceException.class) +@Transactional(rollbackFor = OHServiceException.class) @TranslateOHServiceException public class ExamTypeIoOperation { - private ExamTypeIoOperationRepository repository; + private final ExamTypeIoOperationRepository repository; public ExamTypeIoOperation(ExamTypeIoOperationRepository examTypeIoOperationRepository) { this.repository = examTypeIoOperationRepository; @@ -48,7 +48,7 @@ public ExamTypeIoOperation(ExamTypeIoOperationRepository examTypeIoOperationRepo public List getExamType() throws OHServiceException { return repository.findAllByOrderByDescriptionAsc(); } - + /** * Update an already existing {@link ExamType}. * @param examType - the {@link ExamType} to update @@ -58,7 +58,7 @@ public List getExamType() throws OHServiceException { public ExamType updateExamType(ExamType examType) throws OHServiceException { return repository.save(examType); } - + /** * Insert a new {@link ExamType} in the DB. * @param examType - the {@link ExamType} to insert. @@ -68,7 +68,7 @@ public ExamType updateExamType(ExamType examType) throws OHServiceException { public ExamType newExamType(ExamType examType) throws OHServiceException { return repository.save(examType); } - + /** * Delete the passed {@link ExamType}. * @param examType - the {@link ExamType} to delete. @@ -77,10 +77,9 @@ public ExamType newExamType(ExamType examType) throws OHServiceException { public void deleteExamType(ExamType examType) throws OHServiceException { repository.delete(examType); } - + /** - * This function controls the presence of a record with the same code as in - * the parameter. + * This function controls the presence of a record with the same code as in the parameter. * @param code - the code * @return {@code true} if the code is present, {@code false} otherwise. * @throws OHServiceException @@ -88,4 +87,14 @@ public void deleteExamType(ExamType examType) throws OHServiceException { public boolean isCodePresent(String code) throws OHServiceException { return repository.existsById(code); } + + /** + * Find exam type by code + * @param code - the code + * @return The exam type if found, {@code null} otherwise. + * @throws OHServiceException + */ + public ExamType findByCode(String code) throws OHServiceException { + return repository.findById(code).orElse(null); + } } From 92aa4c5612b34d4e1d20c3ec4a792dd39a0cf26b Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Tue, 15 Oct 2024 10:15:23 +0100 Subject: [PATCH 2/6] chore: Fix doc --- .../org/isf/exa/manager/ExamBrowsingManager.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java b/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java index 450e6ead7..5611924a3 100644 --- a/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java +++ b/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java @@ -35,8 +35,11 @@ import org.springframework.stereotype.Component; /** - * Class that provides gui separation from database operations and gives some useful logic manipulations of the dinamic data (memory) - * @author bob 19-dec-2005 14-jan-2006 + * Class that provides gui separation from database operations and gives some useful logic + * manipulations of the dynamic data (memory) + * @author bob + * 19-dec-2005 + * 14-jan-2006 */ @Component public class ExamBrowsingManager { @@ -120,7 +123,7 @@ public boolean isKeyPresent(Exam exam) throws OHServiceException { } /** - * Insert a new {@link Exam} in the DB with exam rows. + * Insert a new {@link Exam} with exam rows. * @param payload - the {@link Exam} to insert * @param rows - the {@link List} to associate as exam rows * @return the newly persisted {@link Exam}. @@ -131,7 +134,7 @@ public Exam create(Exam payload, List rows) throws OHServiceException { } /** - * Update an existing {@link Exam} in the DB with exam rows. + * Update an existing {@link Exam}with exam rows. * @param payload - the {@link Exam} to insert * @param rows - the {@link List} to associate as exam rows * @return the newly persisted {@link Exam}. @@ -142,7 +145,7 @@ public Exam update(Exam payload, List rows) throws OHServiceException { } /** - * Insert a new {@link Exam} in the DB. + * Insert a new {@link Exam}. * @param exam - the {@link Exam} to insert * @return the newly persisted {@link Exam}. * @throws OHServiceException @@ -153,7 +156,7 @@ public Exam newExam(Exam exam) throws OHServiceException { } /** - * Updates an existing {@link Exam} in the db + * Updates an existing {@link Exam}. * @param exam - the {@link Exam} to update * @return {@code true} if the existing {@link Exam} has been updated, {@code false} otherwise * @throws OHServiceException From 3488bf014a55607a06157884ca23ac80b6ea9dff Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Tue, 15 Oct 2024 10:17:35 +0100 Subject: [PATCH 3/6] chore: Fix java doc --- src/main/java/org/isf/exa/service/ExamIoOperations.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/isf/exa/service/ExamIoOperations.java b/src/main/java/org/isf/exa/service/ExamIoOperations.java index fe2da85c3..382caab9e 100644 --- a/src/main/java/org/isf/exa/service/ExamIoOperations.java +++ b/src/main/java/org/isf/exa/service/ExamIoOperations.java @@ -92,7 +92,7 @@ public List getExamType() throws OHServiceException { } /** - * Insert a new {@link Exam} in the DB with exam rows. + * Insert a new {@link Exam} with exam rows. * @param payload - the {@link Exam} to insert * @param rows - the {@link List} to associate as exam rows * @return the newly persisted {@link Exam}. @@ -111,7 +111,7 @@ public Exam create(Exam payload, List rows) throws OHServiceException { } /** - * Update an existing {@link Exam} in the DB with exam rows. + * Update an existing {@link Exam} with exam rows. * @param payload - the {@link Exam} to insert * @param rows - the {@link List} to associate as exam rows * @return the newly persisted {@link Exam}. @@ -138,7 +138,7 @@ public Exam update(Exam payload, List rows) throws OHServiceException { } /** - * Insert a new {@link Exam} in the DB. + * Insert a new {@link Exam}. * @param exam - the {@link Exam} to insert * @return the newly persisted {@link Exam}. * @throws OHServiceException @@ -148,7 +148,7 @@ public Exam newExam(Exam exam) throws OHServiceException { } /** - * Insert a new {@link ExamRow} in the DB. + * Insert a new {@link ExamRow}. * @param examRow - the {@link ExamRow} to insert * @return the newly persisted {@link ExamRow}. * @throws OHServiceException From ad286a65f4c9a2e194e2866b4e59b12f6dce1cfa Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Tue, 15 Oct 2024 11:50:12 +0100 Subject: [PATCH 4/6] chore: Remove autor and revision date in ExamBrowsingManager --- src/main/java/org/isf/exa/manager/ExamBrowsingManager.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java b/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java index 5611924a3..bba4e7fbf 100644 --- a/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java +++ b/src/main/java/org/isf/exa/manager/ExamBrowsingManager.java @@ -37,9 +37,6 @@ /** * Class that provides gui separation from database operations and gives some useful logic * manipulations of the dynamic data (memory) - * @author bob - * 19-dec-2005 - * 14-jan-2006 */ @Component public class ExamBrowsingManager { From ed898e2f3d66ad20b24628375b783921bc725b6e Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Tue, 22 Oct 2024 17:10:10 +0100 Subject: [PATCH 5/6] fix: Delete exam rows when procedure switch to 3 --- src/main/java/org/isf/exa/service/ExamIoOperations.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/isf/exa/service/ExamIoOperations.java b/src/main/java/org/isf/exa/service/ExamIoOperations.java index 382caab9e..1f0a0c26f 100644 --- a/src/main/java/org/isf/exa/service/ExamIoOperations.java +++ b/src/main/java/org/isf/exa/service/ExamIoOperations.java @@ -119,11 +119,15 @@ public Exam create(Exam payload, List rows) throws OHServiceException { */ @Transactional public Exam update(Exam payload, List rows) throws OHServiceException { + Exam oldExam = findByCode(payload.getCode()); Exam exam = repository.save(payload); + List examRows = rowRepository.findAllByExam_CodeOrderByDescription(exam.getCode()); if (exam.getProcedure() == 3) { + if (oldExam.getProcedure() != 3) { + rowRepository.deleteAll(examRows); + } return exam; } - List examRows = rowRepository.findAllByExam_CodeOrderByDescription(exam.getCode()); List rowsToRemove = examRows.stream().filter(examRow -> !rows.contains(examRow.getDescription())).toList(); List rowsToAdd = rows.stream().filter(row -> examRows.stream().noneMatch(examRow -> Objects.equals(row, examRow.getDescription()))) .map(description -> new ExamRow(exam, description)).toList(); From 63e4f5dfe4880d70eb6732c8baa1221ef37fefde Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Wed, 23 Oct 2024 10:20:42 +0100 Subject: [PATCH 6/6] chore: Refactor exam update method --- .../org/isf/exa/service/ExamIoOperations.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/isf/exa/service/ExamIoOperations.java b/src/main/java/org/isf/exa/service/ExamIoOperations.java index 1f0a0c26f..c079d3e61 100644 --- a/src/main/java/org/isf/exa/service/ExamIoOperations.java +++ b/src/main/java/org/isf/exa/service/ExamIoOperations.java @@ -122,21 +122,19 @@ public Exam update(Exam payload, List rows) throws OHServiceException { Exam oldExam = findByCode(payload.getCode()); Exam exam = repository.save(payload); List examRows = rowRepository.findAllByExam_CodeOrderByDescription(exam.getCode()); - if (exam.getProcedure() == 3) { - if (oldExam.getProcedure() != 3) { - rowRepository.deleteAll(examRows); + if (exam.getProcedure() == 3 && oldExam.getProcedure() != 3) { + rowRepository.deleteAll(examRows); + } else { + List rowsToRemove = examRows.stream().filter(examRow -> !rows.contains(examRow.getDescription())).toList(); + List rowsToAdd = rows.stream().filter(row -> examRows.stream().noneMatch(examRow -> Objects.equals(row, examRow.getDescription()))) + .map(description -> new ExamRow(exam, description)).toList(); + + if (!rowsToRemove.isEmpty()) { + rowRepository.deleteAll(rowsToRemove); + } + if (!rowsToAdd.isEmpty()) { + rowRepository.saveAll(rowsToAdd); } - return exam; - } - List rowsToRemove = examRows.stream().filter(examRow -> !rows.contains(examRow.getDescription())).toList(); - List rowsToAdd = rows.stream().filter(row -> examRows.stream().noneMatch(examRow -> Objects.equals(row, examRow.getDescription()))) - .map(description -> new ExamRow(exam, description)).toList(); - - if (!rowsToRemove.isEmpty()) { - rowRepository.deleteAll(rowsToRemove); - } - if (!rowsToAdd.isEmpty()) { - rowRepository.saveAll(rowsToAdd); } return exam; }