diff --git a/avni-server-api/src/main/java/org/avni/server/dao/EntityApprovalStatusRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/EntityApprovalStatusRepository.java index 3dd173746..ae3828fe7 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/EntityApprovalStatusRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/EntityApprovalStatusRepository.java @@ -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); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/EntityApprovalStatusService.java b/avni-server-api/src/main/java/org/avni/server/service/EntityApprovalStatusService.java index 563d0c4d6..783616885 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/EntityApprovalStatusService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/EntityApprovalStatusService.java @@ -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(); @@ -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) { diff --git a/avni-server-api/src/test/java/org/avni/server/dao/EntityApprovalStatusRepositoryIntegrationTest.java b/avni-server-api/src/test/java/org/avni/server/dao/EntityApprovalStatusRepositoryIntegrationTest.java index ebd9085ea..a2fff4678 100644 --- a/avni-server-api/src/test/java/org/avni/server/dao/EntityApprovalStatusRepositoryIntegrationTest.java +++ b/avni-server-api/src/test/java/org/avni/server/dao/EntityApprovalStatusRepositoryIntegrationTest.java @@ -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) @@ -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 @@ -79,7 +76,7 @@ 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) @@ -87,6 +84,6 @@ public void allow_Same_EAS_If_There_Is_Intermediate_EAS_With_Different_Status() .setStatusDateTime(new DateTime()) .setEntityId(subject.getId()) .setIndividual(subject).build(); - entityApprovalStatusRepository.saveEAS(entityApprovalStatus3); + assertNotNull(entityApprovalStatusRepository.saveEAS(entityApprovalStatus3)); } }