Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
update valitadion method
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Jul 3, 2024
1 parent 27205c6 commit 00243c2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void deleteMedicalInventory(MedicalInventory medicalInventory) throws OHS
* @return {@code true} if the code is already in use, {@code false} otherwise.
* @throws OHServiceException
*/
public boolean referenceExists(String reference) {
public boolean referenceExists(String reference) throws OHServiceException {
return ioOperations.referenceExists(reference);
}

Expand Down Expand Up @@ -166,13 +166,24 @@ public Page<MedicalInventory> getMedicalInventoryByParamsPageable(LocalDateTime
return ioOperations.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, page, size);
}

/**
* Fetch {@link MedicalInventory} with param.
*
* @param inventoryId - the {@link MedicalInventory} id.
* @return {@link MedicalInventory}. It could be {@code empty}.
* @throws OHServiceException
*/
public MedicalInventory getInventoryById(Integer inventoryId) throws OHServiceException {
return ioOperations.getInventoryById(inventoryId);
}

/**
* Verify if the object is valid for CRUD and return a list of errors, if any.
*
* @param medInventory
* @throws OHDataValidationException
*/
private void validationMedicalInventory(MedicalInventory medInventory) throws OHDataValidationException {
private void validationMedicalInventory(MedicalInventory medInventory) throws OHServiceException {
List<OHExceptionMessage> errors = new ArrayList<>();
LocalDateTime tomorrow = LocalDateTime.now().plusDays(1);
String reference = medInventory.getInventoryReference();
Expand All @@ -186,10 +197,13 @@ private void validationMedicalInventory(MedicalInventory medInventory) throws OH
if (reference == null || reference.equals("")) {
errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.mustenterareference.msg")));
}
if (this.referenceExists(reference)) {
errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.referencealreadyused.msg")));
MessageDialog.error(null, "");
return ;
boolean exist = ioOperations.referenceExists(reference);
if (exist) {
MedicalInventory medInv = ioOperations.getInventoryByReference(reference);
if (medInv != null && medInv.getId() != inventoryId) {
System.out.println(inventoryId+" "+medInv.getId());
errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.referencealreadyused.msg")));
}
}
if (!errors.isEmpty()) {
throw new OHDataValidationException(errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ public void deleteMedicalInventoryRows(List<MedicalInventoryRow> inventoryRowsTo
* @return the {@link MedicalInventoryRow} object.
* @throws OHServiceException
*/
public MedicalInventoryRow getMedicalInventoryRowById(Integer invRowId) {
Optional<MedicalInventoryRow> medInvRow = ioOperation.getMedicalInventoryRowById(invRowId);
if (medInvRow.isPresent()) {
return medInvRow.get();
public MedicalInventoryRow getMedicalInventoryRowById(Integer invRowId) throws OHServiceException {
if (invRowId != null) {
Optional<MedicalInventoryRow> medInvRow = ioOperation.getMedicalInventoryRowById(invRowId);
if (medInvRow.isPresent()) {
return medInvRow.get();
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void deleteMedicalInventory(MedicalInventory medicalInventory) throws OHS
* @return {@code true} if the code is already in use, {@code false} otherwise.
* @throws OHServiceException
*/
public boolean referenceExists(String reference) {
public boolean referenceExists(String reference) throws OHServiceException {
MedicalInventory medInv = repository.findByReference(reference);
if (medInv != null) {
return true;
Expand Down Expand Up @@ -173,14 +173,25 @@ public boolean isCodePresent(Integer id) throws OHServiceException {
return repository.existsById(id);
}

/**
* Fetch {@link MedicalInventory} with param.
*
* @param reference - the {@link MedicalInventory} reference.
* @return {@link MedicalInventory}. It could be {@code empty}.
* @throws OHServiceException
*/
public MedicalInventory getInventoryByReference(String reference) throws OHServiceException {
return repository.findByReference(reference);
}

/**
* Fetch {@link MedicalInventory} with param.
*
* @param inventoryId - the {@link MedicalInventory} id.
* @return {@link MedicalInventory}. It could be {@code empty}.
* @throws OHServiceException
*/
public MedicalInventory getInventoryById(Integer inventoryId) throws OHServiceException {
public MedicalInventory getInventoryById(Integer inventoryId) throws OHServiceException {
Optional<MedicalInventory> inventory = repository.findById(inventoryId);
if (inventory.isPresent()) {
return inventory.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<MedicalInventoryRow> getMedicalInventoryRowByInventoryId(int invento
* @return {@link MedicalInventoryRow} with the specified id, {@code null} otherwise.
* @throws OHServiceException
*/
public Optional<MedicalInventoryRow> getMedicalInventoryRowById(Integer id) {
public Optional<MedicalInventoryRow> getMedicalInventoryRowById(Integer id) throws OHServiceException {
return repository.findById(id);
}
}

0 comments on commit 00243c2

Please sign in to comment.