From 43963363d5294292a26987346673dfb152deb6d0 Mon Sep 17 00:00:00 2001 From: Alessandro Domanico Date: Wed, 30 Oct 2024 23:22:18 +0100 Subject: [PATCH] Expose lotExists method (#1441) --- .../manager/MovStockInsertingManager.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java index e2050edf1..5c78e695a 100644 --- a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java +++ b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java @@ -32,6 +32,7 @@ import org.isf.medicals.service.MedicalsIoOperations; import org.isf.medicalstock.model.Lot; import org.isf.medicalstock.model.Movement; +import org.isf.medicalstock.service.LotIoOperationRepository; import org.isf.medicalstock.service.MedicalStockIoOperations; import org.isf.utils.db.TranslateOHServiceException; import org.isf.utils.exception.OHDataValidationException; @@ -48,9 +49,13 @@ public class MovStockInsertingManager { private MedicalsIoOperations ioOperationsMedicals; - public MovStockInsertingManager(MedicalStockIoOperations medicalStockIoOperations, MedicalsIoOperations medicalsIoOperations) { + private LotIoOperationRepository ioOperationsLots; + + public MovStockInsertingManager(MedicalStockIoOperations medicalStockIoOperations, MedicalsIoOperations medicalsIoOperations, + LotIoOperationRepository ioOperationsLots) { this.ioOperations = medicalStockIoOperations; this.ioOperationsMedicals = medicalsIoOperations; + this.ioOperationsLots = ioOperationsLots; } /** @@ -209,6 +214,17 @@ private void validateLot(List errors, Lot lot, boolean check } } + /** + * Checks if the specified {@link Lot} exists. + * + * @param lotCode the lot code. + * @return {@code true} if exists, {@code false} otherwise. + * @throws OHServiceException if an error occurs during the check. + */ + public boolean lotExists(String lotCode) throws OHServiceException { + return ioOperationsLots.findById(String.valueOf(lotCode)).orElse(null) != null; + } + /** * Verify if the referenceNumber is valid for CRUD and return a list of errors, if any *