Skip to content

Commit

Permalink
#678 - return null instead of throwing error for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Jan 9, 2024
1 parent cc839e7 commit ef156c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ default void updateConceptSyncAttributesForSubjectType(Long subjectTypeId, Strin

default EntityApprovalStatus saveEAS(EntityApprovalStatus entityToSave) {
EntityApprovalStatus latestEAS = this.findFirstByEntityIdAndEntityTypeAndIsVoidedFalseOrderByStatusDateTimeDesc(entityToSave.getEntityId(), entityToSave.getEntityType());
if (latestEAS != null && latestEAS.getApprovalStatus().getStatus().equals(entityToSave.getApprovalStatus().getStatus()))
throw new RuntimeException(String.format("The latest approval for this entity has the same latest status. %s %s %s", entityToSave.getEntityType(), entityToSave.getEntityId(), entityToSave.getApprovalStatus().getStatus()));
if (latestEAS != null && latestEAS.getApprovalStatus().getStatus().equals(entityToSave.getApprovalStatus().getStatus())) {
return null;
// check the number clients on version < 6.1 before uncommenting
// throw new RuntimeException(String.format("The latest approval for this entity has the same latest status. %s %s %s", entityToSave.getEntityType(), entityToSave.getEntityId(), entityToSave.getApprovalStatus().getStatus()));
}
return this.save(entityToSave);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public EntityApprovalStatusService(EntityApprovalStatusRepository entityApproval
this.typeMap.put(ProgramEnrolment, programEnrolmentRepository);
}

public EntityApprovalStatus save(EntityApprovalStatusRequest request) {
public void save(EntityApprovalStatusRequest request) {
EntityApprovalStatus entityApprovalStatus = entityApprovalStatusRepository.findByUuid(request.getUuid());
if (entityApprovalStatus == null) {
entityApprovalStatus = new EntityApprovalStatus();
Expand All @@ -58,7 +58,7 @@ public EntityApprovalStatus save(EntityApprovalStatusRequest request) {

CHSEntity chsEntity = this.typeMap.get(entityType).findByUuid(request.getEntityUuid());
updateIndividualAndSyncAttributes(chsEntity, entityApprovalStatus, entityType);
return entityApprovalStatusRepository.saveEAS(entityApprovalStatus);
entityApprovalStatusRepository.saveEAS(entityApprovalStatus);
}

public void createStatus(EntityApprovalStatus.EntityType entityType, Long entityId, ApprovalStatus.Status status, String entityTypeUuid, FormMapping formMapping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.jdbc.Sql;

import static org.junit.Assert.fail;
import static org.junit.Assert.*;

@Sql(value = {"/tear-down.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(value = {"/tear-down.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
Expand Down Expand Up @@ -63,11 +63,8 @@ public void doNotAllowDuplicateEAS() {
.setStatusDateTime(new DateTime())
.setEntityId(subject.getId())
.setIndividual(subject).build();
try {
entityApprovalStatusRepository.saveEAS(entityApprovalStatus2);
fail();
} catch (RuntimeException re) {
}

assertNull(entityApprovalStatusRepository.saveEAS(entityApprovalStatus2));
}

@Test
Expand All @@ -79,14 +76,14 @@ public void allow_Same_EAS_If_There_Is_Intermediate_EAS_With_Different_Status()
.setStatusDateTime(new DateTime())
.setEntityId(subject.getId())
.setIndividual(subject).build();
entityApprovalStatusRepository.saveEAS(entityApprovalStatus2);
assertNotNull(entityApprovalStatusRepository.saveEAS(entityApprovalStatus2));

EntityApprovalStatus entityApprovalStatus3 = new EntityApprovalStatusBuilder()
.setEntityType(EntityApprovalStatus.EntityType.Subject)
.setApprovalStatus(pending).setEntityTypeUuid(st1.getUuid())
.setStatusDateTime(new DateTime())
.setEntityId(subject.getId())
.setIndividual(subject).build();
entityApprovalStatusRepository.saveEAS(entityApprovalStatus3);
assertNotNull(entityApprovalStatusRepository.saveEAS(entityApprovalStatus3));
}
}

0 comments on commit ef156c2

Please sign in to comment.