From 7c0d77538745535d96a668e8f457480f77f80bb4 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Mon, 18 Nov 2024 14:25:06 +0530 Subject: [PATCH 1/5] #813 - added hibernate converter for LocalDate and DateTime. Reverted all moves from Date/DateTime/LocalDate to Instant. --- .../avni/messaging/domain/MessageRequest.java | 26 +++++----- .../MessageRequestQueueRepository.java | 7 +-- .../server/dao/ApprovalStatusRepository.java | 8 ++-- .../org/avni/server/dao/CHSRepository.java | 12 ++--- .../server/dao/ChecklistItemRepository.java | 3 +- .../avni/server/dao/ChecklistRepository.java | 3 +- .../avni/server/dao/EncounterRepository.java | 10 ++-- .../dao/EndOfLife1EndpointRepository.java | 5 +- .../dao/EntityApprovalStatusRepository.java | 6 +-- .../dao/FindByLastModifiedDateTime.java | 19 ++------ .../server/dao/GroupPrivilegeRepository.java | 9 ++-- .../server/dao/GroupSubjectRepository.java | 9 ++-- .../dao/IdentifierAssignmentRepository.java | 7 ++- .../dao/IdentifierSourceRepository.java | 7 ++- .../avni/server/dao/IndividualRepository.java | 12 ++--- .../server/dao/LocationMappingRepository.java | 11 ++--- .../avni/server/dao/LocationRepository.java | 14 +++--- .../org/avni/server/dao/NewsRepository.java | 7 ++- ...eratingIndividualScopeAwareRepository.java | 9 ++-- .../OperationalEncounterTypeRepository.java | 5 +- .../dao/OperationalProgramRepository.java | 3 +- .../dao/OperationalSubjectTypeRepository.java | 5 +- .../dao/PlatformTranslationRepository.java | 7 ++- .../avni/server/dao/PrivilegeRepository.java | 7 ++- .../dao/ProgramEncounterRepository.java | 13 ++--- .../dao/ProgramEnrolmentRepository.java | 17 ++++--- .../avni/server/dao/ResetSyncRepository.java | 6 +-- .../server/dao/RuleDependencyRepository.java | 7 ++- .../dao/StandardReportCardTypeRepository.java | 7 ++- .../server/dao/SyncTelemetryRepository.java | 5 +- .../avni/server/dao/UserGroupRepository.java | 7 ++- .../org/avni/server/dao/UserRepository.java | 3 +- .../dao/UserSubjectAssignmentRepository.java | 11 ++--- .../IndividualRelationshipRepository.java | 3 +- .../avni/server/dao/task/TaskRepository.java | 7 ++- .../dao/task/TaskUnAssignmentRepository.java | 7 ++- .../avni/server/domain/AbstractEncounter.java | 36 +++++++------- .../avni/server/domain/ApprovalStatus.java | 17 +++---- .../org/avni/server/domain/CHSEntity.java | 23 +++------ .../org/avni/server/domain/Checklist.java | 10 ++-- .../org/avni/server/domain/ChecklistItem.java | 10 ++-- .../org/avni/server/domain/CommentThread.java | 17 +++---- .../server/domain/EntityApprovalStatus.java | 10 ++-- .../org/avni/server/domain/GroupSubject.java | 17 +++---- .../org/avni/server/domain/Individual.java | 25 +++++----- .../java/org/avni/server/domain/News.java | 8 ++-- .../avni/server/domain/ProgramEnrolment.java | 16 ++++--- .../server/domain/RuleFailureTelemetry.java | 24 ++++++---- .../server/domain/StandardReportCardType.java | 17 +++---- .../org/avni/server/domain/SyncTelemetry.java | 17 +++---- .../java/org/avni/server/domain/User.java | 17 +++---- .../avni/server/domain/VideoTelemetric.java | 24 +++++----- .../domain/accessControl/Privilege.java | 17 +++---- .../IndividualRelationship.java | 17 +++---- .../program/SubjectProgramEligibility.java | 8 ++-- .../org/avni/server/domain/task/Task.java | 17 +++---- .../exporter/ExportBatchConfiguration.java | 20 ++++---- .../hibernate/JodaDateTimeConverter.java | 28 +++++++++++ .../hibernate/JodaLocalDateConverter.java | 29 ++++++++++++ .../server/service/ApprovalStatusService.java | 2 +- .../service/IdentifierAssignmentService.java | 2 +- .../service/IdentifierSourceService.java | 2 +- .../service/LocationHierarchyService.java | 2 +- .../org/avni/server/service/NewsService.java | 2 +- .../service/PlatformTranslationService.java | 2 +- .../avni/server/service/ResetSyncService.java | 2 +- .../server/service/RuleDependencyService.java | 2 +- .../StandardReportCardTypeService.java | 2 +- .../org/avni/server/service/UserService.java | 2 +- .../accessControl/PrivilegeService.java | 2 +- .../org/avni/server/util/DateTimeUtil.java | 47 ------------------- .../avni/server/web/DashboardController.java | 2 +- .../server/web/DashboardFilterController.java | 2 +- ...DashboardSectionCardMappingController.java | 2 +- .../web/DashboardSectionController.java | 2 +- .../server/web/GroupDashboardController.java | 2 +- .../web/IndividualRelationshipController.java | 2 +- .../web/ProgramEncounterController.java | 2 +- .../avni/server/web/ReportCardController.java | 2 +- .../server/web/SyncTelemetryController.java | 5 +- .../api/GeneralEncounterApiController.java | 2 +- .../api/ProgramEncounterApiController.java | 2 +- .../avni/server/util/DateTimeUtilTest.java | 9 ---- 83 files changed, 389 insertions(+), 442 deletions(-) create mode 100644 avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaDateTimeConverter.java create mode 100644 avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaLocalDateConverter.java diff --git a/avni-server-api/src/main/java/org/avni/messaging/domain/MessageRequest.java b/avni-server-api/src/main/java/org/avni/messaging/domain/MessageRequest.java index 1e37c5f68..896a5b505 100644 --- a/avni-server-api/src/main/java/org/avni/messaging/domain/MessageRequest.java +++ b/avni-server-api/src/main/java/org/avni/messaging/domain/MessageRequest.java @@ -1,13 +1,9 @@ package org.avni.messaging.domain; -import org.avni.server.domain.OrganisationAwareEntity; -import org.avni.server.util.DateTimeUtil; -import org.joda.time.DateTime; - import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; - -import java.time.Instant; +import org.avni.server.domain.OrganisationAwareEntity; +import org.joda.time.DateTime; @Entity @Table(name = "message_request_queue") @@ -31,7 +27,7 @@ public class MessageRequest extends OrganisationAwareEntity { @Column @NotNull - private Instant scheduledDateTime; + private DateTime scheduledDateTime; @Column @NotNull @@ -39,7 +35,7 @@ public class MessageRequest extends OrganisationAwareEntity { private MessageDeliveryStatus deliveryStatus; @Column - private Instant deliveredDateTime; + private DateTime deliveredDateTime; public void setMessageRule(MessageRule messageRule) { this.messageRule = messageRule; @@ -54,7 +50,7 @@ public void setEntityId(Long entityId) { } public void setScheduledDateTime(DateTime scheduledDateTime) { - this.scheduledDateTime = DateTimeUtil.toInstant(scheduledDateTime); + this.scheduledDateTime = scheduledDateTime; } public void setDeliveryStatus(MessageDeliveryStatus deliveryStatus) { @@ -62,7 +58,7 @@ public void setDeliveryStatus(MessageDeliveryStatus deliveryStatus) { } public void setDeliveredDateTime(DateTime deliveredDateTime) { - this.deliveredDateTime = DateTimeUtil.toInstant(deliveredDateTime); + this.deliveredDateTime = deliveredDateTime; } public MessageRequest() { @@ -72,20 +68,20 @@ public MessageRequest(MessageRule messageRule, MessageReceiver messageReceiverId this.messageRule = messageRule; this.messageReceiver = messageReceiverId; this.entityId = entityId; - this.setScheduledDateTime(scheduledDateTime); + this.scheduledDateTime = scheduledDateTime; this.deliveryStatus = MessageDeliveryStatus.NotSent; } public MessageRequest(ManualMessage manualMessage, MessageReceiver messageReceiver, DateTime scheduledDateTime) { this.manualMessage = manualMessage; this.messageReceiver = messageReceiver; - this.setScheduledDateTime(scheduledDateTime); + this.scheduledDateTime = scheduledDateTime; this.deliveryStatus = MessageDeliveryStatus.NotSent; } public void markComplete() { deliveryStatus = MessageDeliveryStatus.Sent; - setDeliveredDateTime(DateTime.now()); + deliveredDateTime = DateTime.now(); } public MessageRule getMessageRule() { @@ -101,7 +97,7 @@ public Long getEntityId() { } public DateTime getScheduledDateTime() { - return DateTimeUtil.toJodaDateTime(scheduledDateTime); + return scheduledDateTime; } public MessageDeliveryStatus getDeliveryStatus() { @@ -109,7 +105,7 @@ public MessageDeliveryStatus getDeliveryStatus() { } public DateTime getDeliveredDateTime() { - return DateTimeUtil.toJodaDateTime(deliveredDateTime); + return deliveredDateTime; } public boolean isDelivered() { diff --git a/avni-server-api/src/main/java/org/avni/messaging/repository/MessageRequestQueueRepository.java b/avni-server-api/src/main/java/org/avni/messaging/repository/MessageRequestQueueRepository.java index 6c114acab..e4a0e5ab4 100644 --- a/avni-server-api/src/main/java/org/avni/messaging/repository/MessageRequestQueueRepository.java +++ b/avni-server-api/src/main/java/org/avni/messaging/repository/MessageRequestQueueRepository.java @@ -6,14 +6,12 @@ import org.avni.messaging.domain.MessageRule; import org.avni.server.dao.CHSRepository; import org.avni.server.framework.security.UserContextHolder; -import org.avni.server.util.DateTimeUtil; import org.joda.time.DateTime; import org.joda.time.Duration; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.Optional; import java.util.stream.Stream; @@ -21,12 +19,11 @@ @Repository public interface MessageRequestQueueRepository extends CHSRepository { - Stream findAllByDeliveryStatusNotAndIsVoidedFalseAndScheduledDateTimeBetween(MessageDeliveryStatus messageDeliveryStatus, Instant then, Instant now); + Stream findAllByDeliveryStatusNotAndIsVoidedFalseAndScheduledDateTimeBetween(MessageDeliveryStatus messageDeliveryStatus, DateTime then, DateTime now); Optional findByEntityIdAndMessageRule(Long entityId, MessageRule messageRule); default Stream findDueMessageRequests(Duration duration) { - return findAllByDeliveryStatusNotAndIsVoidedFalseAndScheduledDateTimeBetween(MessageDeliveryStatus.Sent, - DateTimeUtil.toInstant(DateTime.now().minus(duration)), DateTimeUtil.toInstant(DateTime.now())); + return findAllByDeliveryStatusNotAndIsVoidedFalseAndScheduledDateTimeBetween(MessageDeliveryStatus.Sent, DateTime.now().minus(duration), DateTime.now()); } @Modifying(clearAutomatically = true, flushAutomatically=true) diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ApprovalStatusRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ApprovalStatusRepository.java index 94fe1b405..e7520aefa 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ApprovalStatusRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ApprovalStatusRepository.java @@ -10,20 +10,18 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; - @Repository @RepositoryRestResource(collectionResourceRel = "approvalStatus", path = "approvalStatus") public interface ApprovalStatusRepository extends AvniJpaRepository { @RestResource(path = "lastModified", rel = "lastModified") Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable); ApprovalStatus findByUuid(String uuid); ApprovalStatus findByStatus(ApprovalStatus.Status status); - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/CHSRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/CHSRepository.java index f127c63fe..4d5964a33 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/CHSRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/CHSRepository.java @@ -2,14 +2,12 @@ import org.avni.server.domain.CHSEntity; import org.avni.server.domain.Concept; -import org.avni.server.util.DateTimeUtil; import org.joda.time.DateTime; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.repository.NoRepositoryBean; import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -48,7 +46,7 @@ default Expression convertToDate(Path path, CriteriaBuilder cb) { return cb.function("TO_CHAR", String.class, path, cb.literal("yyyy-MM-dd")); } - default Specification lastModifiedBetween(Instant lastModifiedDateTime, Instant now) { + default Specification lastModifiedBetween(Date lastModifiedDateTime, Date now) { Specification spec = (Root root, CriteriaQuery query, CriteriaBuilder cb) -> { List predicates = new ArrayList<>(); @@ -63,10 +61,6 @@ default Specification lastModifiedBetween(Instant lastModifiedDateTime, Instant return spec; } - default Specification lastModifiedBetween(Date lastModifiedDateTime, Date now) { - return this.lastModifiedBetween(DateTimeUtil.toInstant(lastModifiedDateTime), DateTimeUtil.toInstant(now)); - } - default Specification withConceptValues(Map concepts, String observationField) { Specification spec = (Root root, CriteriaQuery query, CriteriaBuilder cb) -> { List predicates = new ArrayList<>(); @@ -85,9 +79,9 @@ default void voidEntity(Long id) { this.save(entity); } - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(Date lastModifiedDateTime); default boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime) { - return existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime == null ? null : lastModifiedDateTime.toDate()); } } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java index d7b25dfff..a2a900fa5 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistItemRepository.java @@ -13,7 +13,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -24,7 +23,7 @@ public interface ChecklistItemRepository extends TransactionalDataRepository, OperatingIndividualScopeAwareRepository, SubjectTreeItemRepository { Page findByChecklistProgramEnrolmentIndividualAddressLevelVirtualCatchmentsIdAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - long catchmentId, Instant lastModifiedDateTime, Instant now, Pageable pageable); + long catchmentId, Date lastModifiedDateTime, Date now, Pageable pageable); ChecklistItem findByChecklistUuidAndChecklistItemDetailUuid(String checklistUUID, String checklistItemDetailUUID); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java index e7c377594..801eb03a9 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ChecklistRepository.java @@ -13,7 +13,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -24,7 +23,7 @@ public interface ChecklistRepository extends TransactionalDataRepository, OperatingIndividualScopeAwareRepository, SubjectTreeItemRepository { Page findByProgramEnrolmentIndividualAddressLevelVirtualCatchmentsIdAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - long catchmentId, Instant lastModifiedDateTime, Instant now, Pageable pageable); + long catchmentId, Date lastModifiedDateTime, Date now, Pageable pageable); Checklist findByProgramEnrolmentId(long programEnrolmentId); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/EncounterRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/EncounterRepository.java index 23a40ff9e..7d32a9c1b 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/EncounterRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/EncounterRepository.java @@ -14,7 +14,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -24,10 +23,10 @@ @RepositoryRestResource(collectionResourceRel = "encounter", path = "encounter", exported = false) public interface EncounterRepository extends TransactionalDataRepository, OperatingIndividualScopeAwareRepository, SubjectTreeItemRepository { Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - Instant lastModifiedDateTime, Instant now, Pageable pageable); + Date lastModifiedDateTime, Date now, Pageable pageable); Page findByIndividualAddressLevelVirtualCatchmentsIdAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - long catchmentId, Instant lastModifiedDateTime, Instant now, Pageable pageable); + long catchmentId, Date lastModifiedDateTime, Date now, Pageable pageable); @Override default Specification syncTypeIdSpecification(Long typeId) { @@ -83,13 +82,12 @@ default Specification withIndividualId(Long id) { default Specification withEncounterEarliestVisitDateTime(DateTime earliestVisitDateTime) { return (Root root, CriteriaQuery query, CriteriaBuilder cb) -> - earliestVisitDateTime == null ? null : cb.equal(root.get("earliestVisitDateTime").as(Instant.class), DateTimeUtil.toInstant(earliestVisitDateTime)); + earliestVisitDateTime == null ? null : cb.equal(root.get("earliestVisitDateTime").as(java.sql.Date.class), earliestVisitDateTime.toDate()); } default Specification withEncounterDateTime(DateTime encounterDateTime) { return (Root root, CriteriaQuery query, CriteriaBuilder cb) -> - encounterDateTime == null ? null : cb.equal(root.get("encounterDateTime").as(Instant.class), - DateTimeUtil.toInstant(encounterDateTime)); + encounterDateTime == null ? null : cb.equal(root.get("encounterDateTime").as(java.sql.Date.class), encounterDateTime.toDate()); } default Specification withNotNullEncounterDateTime() { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/EndOfLife1EndpointRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/EndOfLife1EndpointRepository.java index 76cd621d3..0763ae8b5 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/EndOfLife1EndpointRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/EndOfLife1EndpointRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.format.annotation.DateTimeFormat; -import java.time.Instant; import java.util.Date; /* @@ -21,7 +20,7 @@ public interface EndOfLife1EndpointRepository { @RestResource(path = "lastModified", rel = "lastModified") Page findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); } 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 3ce640f2a..94a7a4a2d 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 @@ -23,8 +23,8 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; @Repository @@ -35,8 +35,8 @@ public interface EntityApprovalStatusRepository extends TransactionalDataReposit @PreAuthorize("hasAnyAuthority('user')") @RestResource(path = "lastModified", rel = "lastModified") Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); default Page findEntityApprovalStatuses(EntityApprovalStatusSearchParams searchParams, Pageable pageable) { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/FindByLastModifiedDateTime.java b/avni-server-api/src/main/java/org/avni/server/dao/FindByLastModifiedDateTime.java index df0b19b16..8e981623d 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/FindByLastModifiedDateTime.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/FindByLastModifiedDateTime.java @@ -15,23 +15,14 @@ public interface FindByLastModifiedDateTime { @RestResource(path = "lastModified", rel = "lastModified") Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); default Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - Date lastModifiedDateTime, - Date now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), - DateTimeUtil.toInstant(now), pageable); - } - - default Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - DateTime lastModifiedDateTime, - DateTime now, - Pageable pageable) { - return findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), - DateTimeUtil.toInstant(now), pageable); + return findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(CHSEntity.toDate(lastModifiedDateTime), CHSEntity.toDate(now), pageable); } } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/GroupPrivilegeRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/GroupPrivilegeRepository.java index 39e7d6317..ad460b54b 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/GroupPrivilegeRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/GroupPrivilegeRepository.java @@ -12,7 +12,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.List; @@ -42,14 +41,14 @@ default GroupPrivilege findByNameIgnoreCase(String name) { @RestResource(path = "lastModified", rel = "lastModified") Page findBySubjectTypeIsNotNullAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); - boolean existsByLastModifiedDateTimeGreaterThan(@Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(@Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime); default boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime) { - return existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime == null ? null : lastModifiedDateTime.toDate()); } default GroupPrivilege saveGroupPrivilege(GroupPrivilege groupPrivilege) { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/GroupSubjectRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/GroupSubjectRepository.java index bc0a2ef33..0cf8d7b41 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/GroupSubjectRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/GroupSubjectRepository.java @@ -18,7 +18,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -30,8 +29,8 @@ public interface GroupSubjectRepository extends TransactionalDataRepository findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); default GroupSubject findByName(String name) { @@ -78,7 +77,7 @@ Page findByMemberSubjectUuidOrderByLastModifiedDateTimeAscIdAsc( "and m.isVoided = false " + "and g.registrationDate between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR g.addressLevel.id in :locationIds)") - Stream findNonVoidedGroupSubjects(Long subjectTypeId, List locationIds, Instant startDateTime, Instant endDateTime); + Stream findNonVoidedGroupSubjects(Long subjectTypeId, List locationIds, LocalDate startDateTime, LocalDate endDateTime); @Query("select gs from GroupSubject gs " + "join gs.groupSubject g " + @@ -86,7 +85,7 @@ Page findByMemberSubjectUuidOrderByLastModifiedDateTimeAscIdAsc( "where g.subjectType.id = :subjectTypeId " + "and g.registrationDate between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR g.addressLevel.id in :locationIds)") - Stream findAllGroupSubjects(Long subjectTypeId, List locationIds, Instant startDateTime, Instant endDateTime); + Stream findAllGroupSubjects(Long subjectTypeId, List locationIds, LocalDate startDateTime, LocalDate endDateTime); default Specification syncStrategySpecification(SyncParameters syncParameters) { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java index e81aa2952..624876450 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/IdentifierAssignmentRepository.java @@ -9,17 +9,16 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; @Repository @RepositoryRestResource(collectionResourceRel = "identifierAssignment", path = "identifierAssignment") public interface IdentifierAssignmentRepository extends TransactionalDataRepository, FindByLastModifiedDateTime { - Page findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(User currentUser, Instant lastModifiedDateTime, Pageable pageable); + Page findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, Pageable pageable); - Slice findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(User currentUser, Instant lastModifiedDateTime, Pageable pageable); + Slice findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, Pageable pageable); Integer countIdentifierAssignmentByIdentifierSourceEqualsAndAndAssignedToEqualsAndIndividualIsNullAndProgramEnrolmentIsNullAndUsedIsFalse(IdentifierSource identifierSource, User assignedTo); - boolean existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNull(User currentUser, Instant lastModifiedDateTime); + boolean existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNull(User currentUser, Date lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/IdentifierSourceRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/IdentifierSourceRepository.java index 388632db3..19946786a 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/IdentifierSourceRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/IdentifierSourceRepository.java @@ -1,5 +1,4 @@ package org.avni.server.dao; -import java.time.Instant; import java.util.Date; import org.avni.server.domain.Catchment; import org.avni.server.domain.IdentifierSource; @@ -27,13 +26,13 @@ public interface IdentifierSourceRepository extends ReferenceDataRepository getAllAuthorisedIdentifierSources( @Param("catchment") Catchment catchment, - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); @Query("select isource from IdentifierSource isource " + "where isource.isVoided=false and (catchment is null or (:catchment is not null and catchment = :catchment)) ") List getAllAuthorisedIdentifierSources(@Param("catchment") Catchment catchment); - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(Date lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/IndividualRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/IndividualRepository.java index 63b2eca5a..3570479c0 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/IndividualRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/IndividualRepository.java @@ -1,5 +1,6 @@ package org.avni.server.dao; +import jakarta.persistence.criteria.*; import org.avni.server.application.projections.WebSearchResultProjection; import org.avni.server.domain.*; import org.avni.server.framework.security.UserContextHolder; @@ -16,9 +17,6 @@ import org.springframework.stereotype.Repository; import org.springframework.util.StringUtils; -import jakarta.persistence.criteria.*; - -import java.time.Instant; import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -109,13 +107,13 @@ default Specification getFilterSpecForAddress(String locationName) { "and ind.subjectType.id = :subjectTypeId " + "and ind.registrationDate between :startDateTime and :endDateTime " + "and (coalesce(:locationIds,NULL) is null OR ind.addressLevel.id in :locationIds)") - Stream findNonVoidedIndividuals(Long subjectTypeId, List locationIds, Instant startDateTime, Instant endDateTime); + Stream findNonVoidedIndividuals(Long subjectTypeId, List locationIds, LocalDate startDateTime, LocalDate endDateTime); @Query("select ind from Individual ind " + "where ind.subjectType.id = :subjectTypeId " + "and ind.registrationDate between :startDateTime and :endDateTime " + "and (coalesce(:locationIds,NULL) is null OR ind.addressLevel.id in :locationIds)") - Stream findAllIndividuals(Long subjectTypeId, List locationIds, Instant startDateTime, Instant endDateTime); + Stream findAllIndividuals(Long subjectTypeId, List locationIds, LocalDate startDateTime, LocalDate endDateTime); //group by is added for distinct ind records @Query("select i from Individual i " + @@ -126,7 +124,7 @@ default Specification getFilterSpecForAddress(String locationName) { "and coalesce(enc.encounterDateTime, enc.cancelDateTime) between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR i.addressLevel.id in :locationIds)" + "group by i.id") - Stream findNonVoidedEncounters(List locationIds, Instant startDateTime, Instant endDateTime, Long encounterTypeId); + Stream findNonVoidedEncounters(List locationIds, DateTime startDateTime, DateTime endDateTime, Long encounterTypeId); @Query("select i from Individual i " + "join i.encounters enc " + @@ -134,7 +132,7 @@ default Specification getFilterSpecForAddress(String locationName) { "and coalesce(enc.encounterDateTime, enc.cancelDateTime) between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR i.addressLevel.id in :locationIds)" + "group by i.id") - Stream findAllEncounters(List locationIds, Instant startDateTime, Instant endDateTime, Long encounterTypeId); + Stream findAllEncounters(List locationIds, DateTime startDateTime, DateTime endDateTime, Long encounterTypeId); @Query("select i from Individual i where i.uuid =:id or i.legacyId = :id") diff --git a/avni-server-api/src/main/java/org/avni/server/dao/LocationMappingRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/LocationMappingRepository.java index 82ceea4d0..b1a7c0949 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/LocationMappingRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/LocationMappingRepository.java @@ -10,7 +10,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.List; @@ -30,8 +29,8 @@ public interface LocationMappingRepository extends ReferenceDataRepository getSyncResults( long catchmentId, - Instant lastModifiedDateTime, - Instant now, + Date lastModifiedDateTime, + Date now, long organisationId, Pageable pageable ); @@ -44,17 +43,17 @@ Page getSyncResults( " inner join location_location_mapping llm on al1.id = llm.location_id\n" + "where c.id = :catchmentId \n" + " and llm.last_modified_date_time > :lastModifiedDateTime ;", nativeQuery = true) - Long getChangedRowCount(long catchmentId, Instant lastModifiedDateTime); + Long getChangedRowCount(long catchmentId, Date lastModifiedDateTime); @Override default Page getSyncResults(SyncParameters syncParameters) { Long organisationId = UserContextHolder.getOrganisation().getId(); - return getSyncResults(syncParameters.getCatchment().getId(), DateTimeUtil.toInstant(syncParameters.getLastModifiedDateTime()), DateTimeUtil.toInstant(syncParameters.getNow()), organisationId, syncParameters.getPageable()); + return getSyncResults(syncParameters.getCatchment().getId(), syncParameters.getLastModifiedDateTime().toDate(), syncParameters.getNow().toDate(), organisationId, syncParameters.getPageable()); } @Override default boolean isEntityChanged(SyncParameters syncParameters) { - return getChangedRowCount(syncParameters.getCatchment().getId(), DateTimeUtil.toInstant(syncParameters.getLastModifiedDateTime())) > 0; + return getChangedRowCount(syncParameters.getCatchment().getId(), syncParameters.getLastModifiedDateTime().toDate()) > 0; } default ParentLocationMapping findByName(String name) { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/LocationRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/LocationRepository.java index d3e910d9b..edb54dd32 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/LocationRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/LocationRepository.java @@ -20,7 +20,6 @@ import jakarta.persistence.QueryHint; import jakarta.validation.constraints.NotNull; -import java.time.Instant; import java.util.*; @Repository @@ -44,7 +43,7 @@ public interface LocationRepository extends ReferenceDataRepository getSyncResults(long catchmentId, Instant lastModifiedDateTime, Instant now, long organisationId, Pageable pageable); + Page getSyncResults(long catchmentId, Date lastModifiedDateTime, Date now, long organisationId, Pageable pageable); @Query(value = "select count(*)\n" + "from catchment c\n" + @@ -53,7 +52,7 @@ public interface LocationRepository extends ReferenceDataRepository al1.lineage \n" + "where c.id = :catchmentId\n" + " and al1.last_modified_date_time > :lastModifiedDateTime\n", nativeQuery = true) - Long getChangedRowCount(long catchmentId, Instant lastModifiedDateTime); + Long getChangedRowCount(long catchmentId, Date lastModifiedDateTime); AddressLevel findByTitleAndCatchmentsUuid(String title, String uuid); @@ -98,20 +97,19 @@ public interface LocationRepository extends ReferenceDataRepository findByCatchments(Catchment catchment); - Page findByLastModifiedDateTimeAfterAndTypeIn(Instant lastModifiedDateTime, Collection<@NotNull AddressLevelType> type, Pageable pageable); + Page findByLastModifiedDateTimeAfterAndTypeIn(Date lastModifiedDateTime, Collection<@NotNull AddressLevelType> type, Pageable pageable); - boolean existsByLastModifiedDateTimeAfterAndTypeIn(Instant lastModifiedDateTime, Collection<@NotNull AddressLevelType> type); + boolean existsByLastModifiedDateTimeAfterAndTypeIn(Date lastModifiedDateTime, Collection<@NotNull AddressLevelType> type); @Override default Page getSyncResults(SyncParameters syncParameters) { Long organisationId = UserContextHolder.getOrganisation().getId(); - return getSyncResults(syncParameters.getCatchment().getId(), DateTimeUtil.toInstant(syncParameters.getLastModifiedDateTime()), - DateTimeUtil.toInstant(syncParameters.getNow()), organisationId, syncParameters.getPageable()); + return getSyncResults(syncParameters.getCatchment().getId(), syncParameters.getLastModifiedDateTime().toDate(), syncParameters.getNow().toDate(), organisationId, syncParameters.getPageable()); } @Override default boolean isEntityChanged(SyncParameters syncParameters) { - return getChangedRowCount(syncParameters.getCatchment().getId(), DateTimeUtil.toInstant(syncParameters.getLastModifiedDateTime())) > 0; + return getChangedRowCount(syncParameters.getCatchment().getId(), syncParameters.getLastModifiedDateTime().toDate()) > 0; } default AddressLevel findByName(String name) { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/NewsRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/NewsRepository.java index 068d69519..6374095e1 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/NewsRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/NewsRepository.java @@ -7,7 +7,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.List; @@ -19,10 +18,10 @@ public interface NewsRepository extends TransactionalDataRepository, FindB List findByPublishedDateNotNullAndIsVoidedFalse(); - Page findByPublishedDateNotNullAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(Instant lastModifiedDateTime, Instant now, Pageable pageable); + Page findByPublishedDateNotNullAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(Date lastModifiedDateTime, Date now, Pageable pageable); - Slice findSliceByPublishedDateNotNullAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(Instant lastModifiedDateTime, Instant now, Pageable pageable); + Slice findSliceByPublishedDateNotNullAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(Date lastModifiedDateTime, Date now, Pageable pageable); - boolean existsByPublishedDateNotNullAndLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByPublishedDateNotNullAndLastModifiedDateTimeGreaterThan(Date lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/OperatingIndividualScopeAwareRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/OperatingIndividualScopeAwareRepository.java index 4b58e2e62..71c934b0b 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/OperatingIndividualScopeAwareRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/OperatingIndividualScopeAwareRepository.java @@ -18,7 +18,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -64,7 +63,7 @@ default Specification getAuditSpecification(SyncParameters syncParameters) { return (Root root, CriteriaQuery query, CriteriaBuilder cb) -> { List predicates = new ArrayList<>(); if (syncParameters.getSubjectType() == null || !syncParameters.getSubjectType().isDirectlyAssignable()) - predicates.add(cb.between(root.get("lastModifiedDateTime"), cb.literal(DateTimeUtil.toInstant(lastModifiedDateTime)), cb.literal(DateTimeUtil.toInstant(now)))); + predicates.add(cb.between(root.get("lastModifiedDateTime"), cb.literal(lastModifiedDateTime), cb.literal(now))); query.orderBy(cb.asc(root.get("lastModifiedDateTime")), cb.asc(root.get("id"))); return cb.and(predicates.toArray(new Predicate[0])); }; @@ -82,7 +81,7 @@ default Specification syncEntityChangedAuditSpecification(SyncParameters sync Date lastModifiedDateTime = syncParameters.getLastModifiedDateTime().toDate(); return (Root root, CriteriaQuery query, CriteriaBuilder cb) -> { List predicates = new ArrayList<>(); - predicates.add(cb.greaterThan(root.get("lastModifiedDateTime"), cb.literal(DateTimeUtil.toInstant(lastModifiedDateTime)))); + predicates.add(cb.greaterThan(root.get("lastModifiedDateTime"), cb.literal(lastModifiedDateTime))); return cb.and(predicates.toArray(new Predicate[0])); }; } @@ -133,9 +132,9 @@ default void addSyncStrategyPredicate predicates.add(cb.equal(userSubjectAssignmentJoin.get("isVoided"), false)); Date lastModifiedDateTime = syncParameters.getLastModifiedDateTime().toDate(); - Path lastModifiedDateTimePath = userSubjectAssignmentJoin.get("lastModifiedDateTime"); + Path lastModifiedDateTimePath = userSubjectAssignmentJoin.get("lastModifiedDateTime"); Date now = syncParameters.getNow().toDate(); - predicates.add(cb.between(lastModifiedDateTimePath, cb.literal(DateTimeUtil.toInstant(lastModifiedDateTime)), cb.literal(DateTimeUtil.toInstant(now)))); + predicates.add(cb.between(lastModifiedDateTimePath, cb.literal(lastModifiedDateTime), cb.literal(now))); query.orderBy(cb.asc(lastModifiedDateTimePath), cb.asc(userSubjectAssignmentJoin.get("id"))); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/OperationalEncounterTypeRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/OperationalEncounterTypeRepository.java index 46290fdbd..cc056fd27 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/OperationalEncounterTypeRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/OperationalEncounterTypeRepository.java @@ -11,7 +11,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.List; @@ -21,8 +20,8 @@ public interface OperationalEncounterTypeRepository extends ImplReferenceDataRep @RestResource(path = "lastModified", rel = "lastModified") @Query("select oet from OperationalEncounterType oet where oet.lastModifiedDateTime between :lastModifiedDateTime and :now or oet.encounterType.lastModifiedDateTime between :lastModifiedDateTime and :now order by CASE WHEN oet.encounterType.lastModifiedDateTime > oet.lastModifiedDateTime THEN oet.encounterType.lastModifiedDateTime ELSE oet.lastModifiedDateTime END") Page findByLastModifiedDateTimeIsBetweenOrEncounterTypeLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); OperationalEncounterType findByEncounterTypeAndOrganisationId(EncounterType encounterType, long organisationId); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/OperationalProgramRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/OperationalProgramRepository.java index 1cd0ad80d..7193c54a6 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/OperationalProgramRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/OperationalProgramRepository.java @@ -11,7 +11,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.List; @@ -20,7 +19,7 @@ public interface OperationalProgramRepository extends ImplReferenceDataRepository { @RestResource(path = "lastModified", rel = "lastModified") @Query("select op from OperationalProgram op where op.lastModifiedDateTime > :lastModifiedDateTime or op.program.lastModifiedDateTime > :lastModifiedDateTime order by CASE WHEN op.program.lastModifiedDateTime > op.lastModifiedDateTime THEN op.program.lastModifiedDateTime ELSE op.lastModifiedDateTime END") - Page findByLastModifiedDateTimeGreaterThanOrProgramLastModifiedDateTimeGreaterThanOrderByLastModifiedDateTimeAscIdAsc(@Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, Pageable pageable); + Page findByLastModifiedDateTimeGreaterThanOrProgramLastModifiedDateTimeGreaterThanOrderByLastModifiedDateTimeAscIdAsc(@Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, Pageable pageable); OperationalProgram findByProgramAndOrganisationId(Program program, long organisationId); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/OperationalSubjectTypeRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/OperationalSubjectTypeRepository.java index d7dafb10c..a80adaef5 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/OperationalSubjectTypeRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/OperationalSubjectTypeRepository.java @@ -10,7 +10,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.List; import java.util.Date; @@ -20,8 +19,8 @@ public interface OperationalSubjectTypeRepository extends ImplReferenceDataRepos @RestResource(path = "lastModified", rel = "lastModified") @Query("select ost from OperationalSubjectType ost where ost.lastModifiedDateTime between :lastModifiedDateTime and :now or ost.subjectType.lastModifiedDateTime between :lastModifiedDateTime and :now order by CASE WHEN ost.subjectType.lastModifiedDateTime > ost.lastModifiedDateTime THEN ost.subjectType.lastModifiedDateTime ELSE ost.lastModifiedDateTime END") Page findByLastModifiedDateTimeIsBetweenOrSubjectTypeLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); @Query("select s.name from OperationalSubjectType s where s.isVoided = false") diff --git a/avni-server-api/src/main/java/org/avni/server/dao/PlatformTranslationRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/PlatformTranslationRepository.java index 8d9b61407..a274e6e57 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/PlatformTranslationRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/PlatformTranslationRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; @Repository @@ -20,10 +19,10 @@ public interface PlatformTranslationRepository extends CustomCHSJpaRepository findByPlatformAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( Platform platform, - Instant lastModifiedDateTime, - Instant now, + Date lastModifiedDateTime, + Date now, Pageable pageable); - boolean existsByPlatformAndLastModifiedDateTimeGreaterThan(Platform platform, Instant lastModifiedDateTime); + boolean existsByPlatformAndLastModifiedDateTimeGreaterThan(Platform platform, Date lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/PrivilegeRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/PrivilegeRepository.java index 42ff5e2fb..be5799e03 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/PrivilegeRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/PrivilegeRepository.java @@ -12,7 +12,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Collections; import java.util.List; @@ -21,15 +20,15 @@ public interface PrivilegeRepository extends AvniJpaRepository { @RestResource(path = "lastModified", rel = "lastModified") Page findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable); Privilege findByUuid(String uuid); List findAllByIsVoidedFalse(); - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime); Privilege findByType(PrivilegeType privilegeType); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ProgramEncounterRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ProgramEncounterRepository.java index cce1e48c9..1a57458e7 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ProgramEncounterRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ProgramEncounterRepository.java @@ -16,7 +16,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.Date; import java.util.Calendar; import java.util.List; @@ -29,7 +28,7 @@ public interface ProgramEncounterRepository extends TransactionalDataRepository, FindByLastModifiedDateTime, OperatingIndividualScopeAwareRepository, SubjectTreeItemRepository { Page findByProgramEnrolmentIndividualAddressLevelVirtualCatchmentsIdAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - long catchmentId, Instant lastModifiedDateTime, Instant now, Pageable pageable); + long catchmentId, Date lastModifiedDateTime, Date now, Pageable pageable); @Override default Specification syncTypeIdSpecification(Long typeId) { @@ -53,7 +52,7 @@ default boolean isEntityChanged(SyncParameters syncParameters){ "group by enc.program_enrolment_id " + "order by count desc " + "limit 1", nativeQuery = true) - Long getMaxProgramEncounterCountBetween(String programEncounterTypeUUID, Instant startDate, Instant endDate); + Long getMaxProgramEncounterCountBetween(String programEncounterTypeUUID, Calendar startDate, Calendar endDate); @Query(value = "select count(enc.id) as count " + "from program_encounter enc " + @@ -66,7 +65,7 @@ default boolean isEntityChanged(SyncParameters syncParameters){ default Long getMaxProgramEncounterCount(String encounterTypeUUID, Calendar startDate, Calendar endDate) { Long aLong = startDate == null ? getMaxProgramEncounterCount(encounterTypeUUID) : - getMaxProgramEncounterCountBetween(encounterTypeUUID, DateTimeUtil.toInstant(startDate), DateTimeUtil.toInstant(endDate)); + getMaxProgramEncounterCountBetween(encounterTypeUUID, startDate, endDate); return aLong == null ? 0 : aLong; } @@ -85,14 +84,12 @@ default Specification withProgramEncounterId(Long id) { default Specification withProgramEncounterEarliestVisitDateTime(DateTime earliestVisitDateTime) { return (Root root, CriteriaQuery query, CriteriaBuilder cb) -> - earliestVisitDateTime == null ? null : cb.equal(root.get("earliestVisitDateTime").as(Instant.class), - DateTimeUtil.toInstant(earliestVisitDateTime)); + earliestVisitDateTime == null ? null : cb.equal(root.get("earliestVisitDateTime").as(java.sql.Date.class), earliestVisitDateTime.toDate()); } default Specification withProgramEncounterDateTime(DateTime encounterDateTime) { return (Root root, CriteriaQuery query, CriteriaBuilder cb) -> - encounterDateTime == null ? null : cb.equal(root.get("encounterDateTime").as(Instant.class), - DateTimeUtil.toInstant(encounterDateTime)); + encounterDateTime == null ? null : cb.equal(root.get("encounterDateTime").as(java.sql.Date.class), encounterDateTime.toDate()); } default Specification withNotNullEncounterDateTime() { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ProgramEnrolmentRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ProgramEnrolmentRepository.java index 26903a4d1..5494e3a15 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ProgramEnrolmentRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ProgramEnrolmentRepository.java @@ -20,7 +20,6 @@ import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import java.time.Instant; import java.util.Date; import java.util.List; import java.util.stream.Stream; @@ -39,14 +38,14 @@ public interface ProgramEnrolmentRepository extends TransactionalDataRepository< "and i.isVoided = false " + "and coalesce(enl.enrolmentDateTime, enl.programExitDateTime) between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR i.addressLevel.id in :locationIds)") - Stream findNonVoidedEnrolments(Long programId, List locationIds, Instant startDateTime, Instant endDateTime); + Stream findNonVoidedEnrolments(Long programId, List locationIds, DateTime startDateTime, DateTime endDateTime); @Query("select enl from ProgramEnrolment enl " + "join enl.individual i " + "where enl.program.id = :programId " + "and coalesce(enl.enrolmentDateTime, enl.programExitDateTime) between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR i.addressLevel.id in :locationIds)") - Stream findAllEnrolments(Long programId, List locationIds, Instant startDateTime, Instant endDateTime); + Stream findAllEnrolments(Long programId, List locationIds, DateTime startDateTime, DateTime endDateTime); //group by is added for distinct enl records @Query("select enl from ProgramEnrolment enl " + @@ -60,7 +59,7 @@ public interface ProgramEnrolmentRepository extends TransactionalDataRepository< "and coalesce(enc.encounterDateTime, enc.cancelDateTime) between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR i.addressLevel.id in :locationIds) " + "group by enl.id") - Stream findNonVoidedProgramEncounters(List locationIds, Instant startDateTime, Instant endDateTime, Long encounterTypeId, Long programId); + Stream findNonVoidedProgramEncounters(List locationIds, DateTime startDateTime, DateTime endDateTime, Long encounterTypeId, Long programId); @Query("select enl from ProgramEnrolment enl " + "join enl.programEncounters enc " + @@ -70,11 +69,11 @@ public interface ProgramEnrolmentRepository extends TransactionalDataRepository< "and coalesce(enc.encounterDateTime, enc.cancelDateTime) between :startDateTime and :endDateTime " + "and (coalesce(:locationIds, null) is null OR i.addressLevel.id in :locationIds) " + "group by enl.id") - Stream findAllProgramEncounters(List locationIds, Instant startDateTime, Instant endDateTime, Long encounterTypeId, Long programId); + Stream findAllProgramEncounters(List locationIds, DateTime startDateTime, DateTime endDateTime, Long encounterTypeId, Long programId); Page findByLastModifiedDateTimeGreaterThanAndLastModifiedDateTimeLessThanAndProgramNameOrderByLastModifiedDateTimeAscIdAsc( - Instant lastModifiedDateTime, - Instant now, + Date lastModifiedDateTime, + Date now, String program, Pageable pageable); @@ -90,8 +89,8 @@ Page findByProgramNameAndIndividualUuidOrderByLastModifiedDate ProgramEnrolment findByLegacyId(String id); Page findByLastModifiedDateTimeGreaterThanAndLastModifiedDateTimeLessThanOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); @Override diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ResetSyncRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ResetSyncRepository.java index e445eaeca..ada64321b 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ResetSyncRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ResetSyncRepository.java @@ -6,15 +6,15 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; -import java.time.Instant; +import java.util.Date; @Repository public interface ResetSyncRepository extends TransactionalDataRepository { Page findAllByUserIsNullOrUserAndLastModifiedDateTimeBetweenOrderByLastModifiedDateTimeAscIdAsc( User user, - Instant lastModifiedDateTime, - Instant now, + Date lastModifiedDateTime, + Date now, Pageable pageable ); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/RuleDependencyRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/RuleDependencyRepository.java index f8de01154..0031219a7 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/RuleDependencyRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/RuleDependencyRepository.java @@ -9,7 +9,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; @Repository @@ -19,8 +18,8 @@ public interface RuleDependencyRepository extends ImplReferenceDataRepository findByLastModifiedDateTimeIsBetween( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, Pageable pageable); + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date now, Pageable pageable); default RuleDependency findByName(String name) { throw new UnsupportedOperationException("No field 'name' in RuleDependency"); @@ -30,6 +29,6 @@ default RuleDependency findByNameIgnoreCase(String name) { throw new UnsupportedOperationException("No field 'name' in RuleDependency"); } - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(Date lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/StandardReportCardTypeRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/StandardReportCardTypeRepository.java index 89c1da4fd..9c29c4126 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/StandardReportCardTypeRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/StandardReportCardTypeRepository.java @@ -12,7 +12,6 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.List; import java.util.Set; @@ -25,11 +24,11 @@ public interface StandardReportCardTypeRepository extends AvniJpaRepository findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant lastModifiedDateTime, - @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Instant now, + @Param("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, + @Param("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable); - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime); List findAllByTypeIn(Set defaultDashboardStandardCardTypeTypes); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/SyncTelemetryRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/SyncTelemetryRepository.java index 6ed69d9b1..fc2e77654 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/SyncTelemetryRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/SyncTelemetryRepository.java @@ -7,7 +7,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.List; @Repository @@ -17,7 +16,7 @@ public interface SyncTelemetryRepository extends AvniJpaRepository findAllByUserIdInOrderByIdDesc(List userIds, Pageable pageable); - Page findAllBySyncStartTimeBetweenOrderByIdDesc(Instant startDate, Instant endDate, Pageable pageable); + Page findAllBySyncStartTimeBetweenOrderByIdDesc(DateTime startDate, DateTime endDate, Pageable pageable); - Page findAllByUserIdInAndSyncStartTimeBetweenOrderByIdDesc(List userIds, Instant startDate, Instant endDate, Pageable pageable); + Page findAllByUserIdInAndSyncStartTimeBetweenOrderByIdDesc(List userIds, DateTime startDate, DateTime endDate, Pageable pageable); } diff --git a/avni-server-api/src/main/java/org/avni/server/dao/UserGroupRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/UserGroupRepository.java index ebf31a694..d6c14d170 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/UserGroupRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/UserGroupRepository.java @@ -1,6 +1,5 @@ package org.avni.server.dao; -import java.time.Instant; import java.util.Date; import org.avni.server.domain.User; import org.avni.server.domain.Group; @@ -23,8 +22,8 @@ public interface UserGroupRepository extends ReferenceDataRepository Page findByUserIdAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( Long userId, - Instant lastModifiedDateTime, - Instant now, + Date lastModifiedDateTime, + Date now, Pageable pageable); default UserGroup findByName(String name) { @@ -48,7 +47,7 @@ default UserGroup findByNameIgnoreCase(String name) { @Query("DELETE FROM UserGroup ug where ug.group in (:groups)") int deleteAllByGroupIn(List groups); - boolean existsByUserIdAndLastModifiedDateTimeGreaterThan(Long userId, Instant lastModifiedDateTime); + boolean existsByUserIdAndLastModifiedDateTimeGreaterThan(Long userId, Date lastModifiedDateTime); List findByUserAndGroupHasAllPrivilegesTrueAndIsVoidedFalse(User user); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/UserRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/UserRepository.java index 7fda94b9c..e7ac59805 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/UserRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/UserRepository.java @@ -17,7 +17,6 @@ import jakarta.persistence.*; -import java.time.Instant; import java.util.List; import java.util.Optional; @@ -62,7 +61,7 @@ Page findByOrganisationIdAndIsVoidedFalse(@Param("organisationId") Long or "(((:organisationIds) is not null and u.organisationId in (:organisationIds) and u.isOrgAdmin = true) or aa.account.id in (:accountIds))") User getOne(Long id, List accountIds, List organisationIds); - boolean existsByLastModifiedDateTimeGreaterThan(Instant lastModifiedDateTime); + boolean existsByLastModifiedDateTimeGreaterThan(DateTime lastModifiedDateTime); List findByCatchment_IdInAndIsVoidedFalse(List catchmentIds); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/UserSubjectAssignmentRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/UserSubjectAssignmentRepository.java index 7f88f3615..ed6962a3f 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/UserSubjectAssignmentRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/UserSubjectAssignmentRepository.java @@ -9,7 +9,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; import java.util.List; @@ -23,19 +22,19 @@ public interface UserSubjectAssignmentRepository extends ReferenceDataRepository List findUserSubjectAssignmentBySubject_IdIn(List subjectIds); - boolean existsByUserAndIsVoidedTrueAndLastModifiedDateTimeGreaterThan(User user, Instant lastModifiedDateTime); + boolean existsByUserAndIsVoidedTrueAndLastModifiedDateTimeGreaterThan(User user, Date lastModifiedDateTime); Page findByUserAndIsVoidedTrueAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( User user, - Instant lastModifiedDate, - Instant now, + Date lastModifiedDate, + Date now, Pageable pageable ); Slice findSliceByUserAndIsVoidedTrueAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( User user, - Instant lastModifiedDate, - Instant now, + Date lastModifiedDate, + Date now, Pageable pageable ); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/individualRelationship/IndividualRelationshipRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/individualRelationship/IndividualRelationshipRepository.java index 75f962b02..dcb30218f 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/individualRelationship/IndividualRelationshipRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/individualRelationship/IndividualRelationshipRepository.java @@ -18,7 +18,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -30,7 +29,7 @@ @RepositoryRestResource(collectionResourceRel = "individualRelationship", path = "individualRelationship", exported = false) public interface IndividualRelationshipRepository extends TransactionalDataRepository, FindByLastModifiedDateTime, OperatingIndividualScopeAwareRepository, SubjectTreeItemRepository { Page findByIndividualaAddressLevelVirtualCatchmentsIdAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc( - long catchmentId, Instant lastModifiedDateTime, Instant now, Pageable pageable); + long catchmentId, Date lastModifiedDateTime, Date now, Pageable pageable); @Query(value = "select ir from IndividualRelationship ir where ir.individuala = :individual or ir.individualB = :individual") Set findByIndividual(Individual individual); diff --git a/avni-server-api/src/main/java/org/avni/server/dao/task/TaskRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/task/TaskRepository.java index e79273f54..abe2b38c4 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/task/TaskRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/task/TaskRepository.java @@ -18,7 +18,6 @@ import jakarta.persistence.criteria.*; -import java.time.Instant; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -28,11 +27,11 @@ @RepositoryRestResource(collectionResourceRel = "task", path = "task", exported = false) public interface TaskRepository extends TransactionalDataRepository, FindByLastModifiedDateTime { - Page findByAssignedToAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Instant lastModifiedDateTime, Instant now, Pageable pageable); + Page findByAssignedToAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Date lastModifiedDateTime, Date now, Pageable pageable); - Slice findSliceByAssignedToAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Instant lastModifiedDateTime, Instant now, Pageable pageable); + Slice findSliceByAssignedToAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Date lastModifiedDateTime, Date now, Pageable pageable); - boolean existsByAssignedToAndLastModifiedDateTimeGreaterThan(User user, Instant lastModifiedDateTime); + boolean existsByAssignedToAndLastModifiedDateTimeGreaterThan(User user, Date lastModifiedDateTime); default Page search(TaskSearchCriteria searchCriteria, boolean isUnassigned, Pageable pageable) { Specification spec = (Root root, CriteriaQuery query, CriteriaBuilder cb) -> { diff --git a/avni-server-api/src/main/java/org/avni/server/dao/task/TaskUnAssignmentRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/task/TaskUnAssignmentRepository.java index ba40eec3a..8acfcb75a 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/task/TaskUnAssignmentRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/task/TaskUnAssignmentRepository.java @@ -9,15 +9,14 @@ import org.springframework.data.domain.Slice; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.Date; @Repository public interface TaskUnAssignmentRepository extends TransactionalDataRepository, FindByLastModifiedDateTime { - Page findByUnassignedUserAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Instant lastModifiedDateTime, Instant now, Pageable pageable); + Page findByUnassignedUserAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Date lastModifiedDateTime, Date now, Pageable pageable); - Slice findSliceByUnassignedUserAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Instant lastModifiedDateTime, Instant now, Pageable pageable); + Slice findSliceByUnassignedUserAndLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(User user, Date lastModifiedDateTime, Date now, Pageable pageable); - boolean existsByUnassignedUserAndLastModifiedDateTimeGreaterThan(User user, Instant lastModifiedDateTime); + boolean existsByUnassignedUserAndLastModifiedDateTimeGreaterThan(User user, Date lastModifiedDateTime); } diff --git a/avni-server-api/src/main/java/org/avni/server/domain/AbstractEncounter.java b/avni-server-api/src/main/java/org/avni/server/domain/AbstractEncounter.java index 37e1e5fc4..41822dcc0 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/AbstractEncounter.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/AbstractEncounter.java @@ -1,18 +1,16 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import org.avni.server.common.dbSchema.ColumnNames; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.geo.Point; import org.avni.server.geo.PointType; -import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.Instant; import java.util.Objects; @MappedSuperclass @@ -26,20 +24,24 @@ public class AbstractEncounter extends SyncAttributeEntity { private EncounterType encounterType; @Column - private Instant earliestVisitDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime earliestVisitDateTime; @Column - private Instant maxVisitDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime maxVisitDateTime; @Column(name = ColumnNames.EncounterDateTime) - private Instant encounterDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime encounterDateTime; @Column(name = ColumnNames.EncounterObservations) @Type(value = ObservationCollectionUserType.class) private ObservationCollection observations; @Column(name = ColumnNames.EncounterCancelDateTime) - private Instant cancelDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime cancelDateTime; @Column(name = ColumnNames.EncounterCancelObservations) @Type(value = ObservationCollectionUserType.class) @@ -71,14 +73,14 @@ public void setEncounterType(EncounterType encounterType) { } public DateTime getEncounterDateTime() { - return DateTimeUtil.toJodaDateTime(encounterDateTime); + return encounterDateTime; } public void setEncounterDateTime(DateTime encounterDateTime, User currentUser) { if (this.encounterDateTime == null && encounterDateTime != null) { this.filledBy = currentUser; } - this.encounterDateTime = DateTimeUtil.toInstant(encounterDateTime); + this.encounterDateTime = encounterDateTime; } public ObservationCollection getObservations() { @@ -98,23 +100,23 @@ public void setName(String name) { } public DateTime getEarliestVisitDateTime() { - return DateTimeUtil.toJodaDateTime(earliestVisitDateTime); + return earliestVisitDateTime; } public void setEarliestVisitDateTime(DateTime earliestVisitDateTime) { - this.earliestVisitDateTime = DateTimeUtil.toInstant(earliestVisitDateTime); + this.earliestVisitDateTime = earliestVisitDateTime; } public DateTime getMaxVisitDateTime() { - return DateTimeUtil.toJodaDateTime(maxVisitDateTime); + return maxVisitDateTime; } public void setMaxVisitDateTime(DateTime maxVisitDateTime) { - this.maxVisitDateTime = DateTimeUtil.toInstant(maxVisitDateTime); + this.maxVisitDateTime = maxVisitDateTime; } public DateTime getCancelDateTime() { - return DateTimeUtil.toJodaDateTime(cancelDateTime); + return cancelDateTime; } public boolean isCancelled() { @@ -122,7 +124,7 @@ public boolean isCancelled() { } public void setCancelDateTime(DateTime cancelDateTime) { - this.cancelDateTime = DateTimeUtil.toInstant(cancelDateTime); + this.cancelDateTime = cancelDateTime; } public ObservationCollection getCancelObservations() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/ApprovalStatus.java b/avni-server-api/src/main/java/org/avni/server/domain/ApprovalStatus.java index 475d47776..cc167ddb8 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/ApprovalStatus.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/ApprovalStatus.java @@ -1,6 +1,7 @@ package org.avni.server.domain; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; @@ -8,8 +9,6 @@ import jakarta.validation.constraints.NotNull; import org.joda.time.DateTime; -import java.time.Instant; - @Entity @BatchSize(size = 100) public class ApprovalStatus { @@ -28,9 +27,11 @@ public class ApprovalStatus { @Column private boolean isVoided; @Column - private Instant createdDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime createdDateTime; @Column - private Instant lastModifiedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime lastModifiedDateTime; public Long getId() { return id; @@ -65,19 +66,19 @@ public void setVoided(boolean voided) { } public DateTime getCreatedDateTime() { - return DateTimeUtil.toJodaDateTime(createdDateTime); + return createdDateTime; } public void setCreatedDateTime(DateTime createdDateTime) { - this.createdDateTime = DateTimeUtil.toInstant(createdDateTime); + this.createdDateTime = createdDateTime; } public DateTime getLastModifiedDateTime() { - return DateTimeUtil.toJodaDateTime(lastModifiedDateTime); + return lastModifiedDateTime; } public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { - this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime); + this.lastModifiedDateTime = lastModifiedDateTime; } public enum Status { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/CHSEntity.java b/avni-server-api/src/main/java/org/avni/server/domain/CHSEntity.java index d9891abaa..a81404a3d 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/CHSEntity.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/CHSEntity.java @@ -13,7 +13,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import java.time.Instant; import java.util.Date; @MappedSuperclass @@ -29,7 +28,7 @@ public class CHSEntity extends CHSBaseEntity implements Auditable { @CreatedDate @NotNull - private Instant createdDateTime; + private Date createdDateTime; @JsonIgnore @JoinColumn(name = "last_modified_by_id") @@ -40,7 +39,7 @@ public class CHSEntity extends CHSBaseEntity implements Auditable { @LastModifiedDate @NotNull - private Instant lastModifiedDateTime; + private Date lastModifiedDateTime; @JsonIgnore public User getCreatedBy() { @@ -52,11 +51,11 @@ public void setCreatedBy(User createdBy) { } public DateTime getCreatedDateTime() { - return DateTimeUtil.toJodaDateTime(createdDateTime); + return new DateTime(createdDateTime); } public void setCreatedDateTime(DateTime createdDateTime) { - this.createdDateTime = createdDateTime.toDate().toInstant(); + this.createdDateTime = createdDateTime.toDate(); } @JsonIgnore @@ -73,11 +72,11 @@ public DateTime getLastModifiedDateTime() { } private DateTime toJodaDateTime() { - return DateTimeUtil.toJodaDateTime(lastModifiedDateTime); + return new DateTime(lastModifiedDateTime); } public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { - this.lastModifiedDateTime = lastModifiedDateTime.toDate().toInstant(); + this.lastModifiedDateTime = lastModifiedDateTime.toDate(); } @Column(name = "version") @@ -117,15 +116,7 @@ public String getLastModifiedByName() { return getLastModifiedBy().getUsername(); } - public static Instant toDate(DateTime dateTime) { - return DateTimeUtil.toInstant(dateTime); - } - - public static Date toUtilDate(DateTime dateTime) { + public static Date toDate(DateTime dateTime) { return dateTime == null ? null : dateTime.toDate(); } - - public static Date toUtilDate(Instant dateTime) { - return dateTime == null ? null : new Date(dateTime.toEpochMilli()); - } } diff --git a/avni-server-api/src/main/java/org/avni/server/domain/Checklist.java b/avni-server-api/src/main/java/org/avni/server/domain/Checklist.java index 86e8f1590..05e2ebca9 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/Checklist.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/Checklist.java @@ -1,14 +1,13 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import org.avni.server.util.DateTimeUtil; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -32,7 +31,8 @@ public class Checklist extends OrganisationAwareEntity { @NotNull @Column - private Instant baseDate; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime baseDate; public ChecklistDetail getChecklistDetail() { return checklistDetail; @@ -51,11 +51,11 @@ public void setProgramEnrolment(ProgramEnrolment programEnrolment) { } public DateTime getBaseDate() { - return DateTimeUtil.toJodaDateTime(baseDate); + return baseDate; } public void setBaseDate(DateTime baseDate) { - this.baseDate = DateTimeUtil.toInstant(baseDate); + this.baseDate = baseDate; } public List getItems() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/ChecklistItem.java b/avni-server-api/src/main/java/org/avni/server/domain/ChecklistItem.java index ba1255596..49bff561e 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/ChecklistItem.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/ChecklistItem.java @@ -1,6 +1,7 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; @@ -10,15 +11,14 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "checklist_item") @JsonIgnoreProperties({"checklist"}) @BatchSize(size = 100) public class ChecklistItem extends OrganisationAwareEntity { @Column - private Instant completionDate; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime completionDate; @Column @Type(value = ObservationCollectionUserType.class) @@ -34,11 +34,11 @@ public class ChecklistItem extends OrganisationAwareEntity { private Checklist checklist; public DateTime getCompletionDate() { - return DateTimeUtil.toJodaDateTime(completionDate); + return completionDate; } public void setCompletionDate(DateTime completionDate) { - this.completionDate = DateTimeUtil.toInstant(completionDate); + this.completionDate = completionDate; } public Checklist getChecklist() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/CommentThread.java b/avni-server-api/src/main/java/org/avni/server/domain/CommentThread.java index 8518a5bb6..52a973b8f 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/CommentThread.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/CommentThread.java @@ -2,14 +2,13 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import org.avni.server.util.DateTimeUtil; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -26,10 +25,12 @@ public class CommentThread extends OrganisationAwareEntity { @Column @NotNull - private Instant openDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime openDateTime; @Column - private Instant resolvedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime resolvedDateTime; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "commentThread") private Set comments = new HashSet<>(); @@ -43,19 +44,19 @@ public void setStatus(CommentThreadStatus status) { } public DateTime getOpenDateTime() { - return DateTimeUtil.toJodaDateTime(openDateTime); + return openDateTime; } public void setOpenDateTime(DateTime openDateTime) { - this.openDateTime = DateTimeUtil.toInstant(openDateTime); + this.openDateTime = openDateTime; } public DateTime getResolvedDateTime() { - return DateTimeUtil.toJodaDateTime(resolvedDateTime); + return resolvedDateTime; } public void setResolvedDateTime(DateTime resolvedDateTime) { - this.resolvedDateTime = DateTimeUtil.toInstant(resolvedDateTime); + this.resolvedDateTime = resolvedDateTime; } public Set getComments() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/EntityApprovalStatus.java b/avni-server-api/src/main/java/org/avni/server/domain/EntityApprovalStatus.java index 68ab2b622..17ec9ddb8 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/EntityApprovalStatus.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/EntityApprovalStatus.java @@ -1,6 +1,7 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; @@ -8,8 +9,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @BatchSize(size = 100) @JsonIgnoreProperties({"approvalStatus"}) @@ -42,7 +41,8 @@ public class EntityApprovalStatus extends SyncAttributeEntity { @Column @NotNull - private Instant statusDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime statusDateTime; @Column(name = "address_id") private Long addressId; @@ -104,11 +104,11 @@ public void setAutoApproved(Boolean autoApproved) { } public DateTime getStatusDateTime() { - return DateTimeUtil.toJodaDateTime(statusDateTime); + return statusDateTime; } public void setStatusDateTime(DateTime statusDateTime) { - this.statusDateTime = DateTimeUtil.toInstant(statusDateTime); + this.statusDateTime = statusDateTime; } public String getEntityTypeUuid() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/GroupSubject.java b/avni-server-api/src/main/java/org/avni/server/domain/GroupSubject.java index 11c47bc96..46358ec3f 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/GroupSubject.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/GroupSubject.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; @@ -9,8 +10,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "group_subject") @JsonIgnoreProperties({"groupSubject", "memberSubject", "groupRole"}) @@ -33,10 +32,12 @@ public class GroupSubject extends OrganisationAwareEntity { private GroupRole groupRole; @Column - private Instant membershipStartDate; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime membershipStartDate; @Column - private Instant membershipEndDate; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime membershipEndDate; @Column(name = "member_subject_address_id") private Long memberSubjectAddressId; @@ -75,19 +76,19 @@ public void setGroupRole(GroupRole groupRole) { } public DateTime getMembershipStartDate() { - return DateTimeUtil.toJodaDateTime(membershipStartDate); + return membershipStartDate; } public void setMembershipStartDate(DateTime membershipStartDate) { - this.membershipStartDate = DateTimeUtil.toInstant(membershipStartDate); + this.membershipStartDate = membershipStartDate; } public DateTime getMembershipEndDate() { - return DateTimeUtil.toJodaDateTime(membershipEndDate); + return membershipEndDate; } public void setMembershipEndDate(DateTime membershipEndDate) { - this.membershipEndDate = DateTimeUtil.toInstant(membershipEndDate); + this.membershipEndDate = membershipEndDate; } public String getGroupSubjectUUID() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/Individual.java b/avni-server-api/src/main/java/org/avni/server/domain/Individual.java index 6fa464f06..6c8d0d493 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/Individual.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/Individual.java @@ -2,21 +2,19 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import org.avni.server.common.dbSchema.ColumnNames; import org.avni.server.common.dbSchema.TableNames; import org.avni.server.domain.individualRelationship.IndividualRelationship; +import org.avni.server.framework.hibernate.JodaLocalDateConverter; import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.geo.Point; import org.avni.server.geo.PointType; -import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Type; import org.joda.time.LocalDate; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.Instant; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -44,7 +42,8 @@ public class Individual extends SyncAttributeEntity implements MessageableEntity private String profilePicture; - private Instant dateOfBirth; + @Convert(converter = JodaLocalDateConverter.class) + private LocalDate dateOfBirth; private boolean dateOfBirthVerified; @@ -62,7 +61,7 @@ public class Individual extends SyncAttributeEntity implements MessageableEntity @NotNull @Column(name = ColumnNames.RegistrationDate) - private Instant registrationDate; + private LocalDate registrationDate; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "gender_id") @@ -97,20 +96,20 @@ public static Individual create(String firstName, String lastName, String profil individual.firstName = firstName; individual.lastName = lastName; individual.profilePicture = profilePicture; - individual.dateOfBirth = DateTimeUtil.toInstant(dateOfBirth); + individual.dateOfBirth = dateOfBirth; individual.dateOfBirthVerified = dateOfBirthVerified; individual.gender = gender; individual.addressLevel = address; - individual.registrationDate = DateTimeUtil.toInstant(registrationDate); + individual.registrationDate = registrationDate; return individual; } public LocalDate getDateOfBirth() { - return DateTimeUtil.toJodaDate(dateOfBirth); + return dateOfBirth; } public void setDateOfBirth(LocalDate dateOfBirth) { - this.dateOfBirth = DateTimeUtil.toInstant(dateOfBirth); + this.dateOfBirth = dateOfBirth; } public boolean isDateOfBirthVerified() { @@ -174,11 +173,11 @@ public void setObservations(ObservationCollection observations) { } public LocalDate getRegistrationDate() { - return DateTimeUtil.toJodaDate(registrationDate); + return registrationDate; } public void setRegistrationDate(LocalDate registrationDate) { - this.registrationDate = DateTimeUtil.toInstant(registrationDate); + this.registrationDate = registrationDate; } public void addEnrolment(ProgramEnrolment programEnrolment) { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/News.java b/avni-server-api/src/main/java/org/avni/server/domain/News.java index a6996d874..04c272739 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/News.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/News.java @@ -8,15 +8,13 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "news") @BatchSize(size = 100) public class News extends OrganisationAwareEntity { @NotNull private String title; - private Instant publishedDate; + private DateTime publishedDate; private String heroImage; private String content; @Column(name = "contenthtml") @@ -31,11 +29,11 @@ public void setTitle(String title) { } public DateTime getPublishedDate() { - return DateTimeUtil.toJodaDateTime(publishedDate); + return publishedDate; } public void setPublishedDate(DateTime publishedDate) { - this.publishedDate = DateTimeUtil.toInstant(publishedDate); + this.publishedDate = publishedDate; } public String getHeroImage() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/ProgramEnrolment.java b/avni-server-api/src/main/java/org/avni/server/domain/ProgramEnrolment.java index c005d03d9..496938e58 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/ProgramEnrolment.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/ProgramEnrolment.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.avni.server.common.dbSchema.ColumnNames; import org.avni.server.common.dbSchema.TableNames; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.geo.PointType; import org.avni.server.util.DateTimeUtil; @@ -15,7 +16,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; @@ -43,14 +43,16 @@ public class ProgramEnrolment extends SyncAttributeEntity implements Messageable @Column(name = ColumnNames.EnrolmentDateTime) @NotNull - private Instant enrolmentDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime enrolmentDateTime; @Column(name = ProgramEnrolmentObservations) @Type(value = ObservationCollectionUserType.class) private ObservationCollection observations; @Column(name = ColumnNames.ProgramExitDateTime) - private Instant programExitDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime programExitDateTime; @Type(value = PointType.class) @Column @@ -127,11 +129,11 @@ public void setProgramEncounters(Set programEncounters) { } public DateTime getEnrolmentDateTime() { - return DateTimeUtil.toJodaDateTime(enrolmentDateTime); + return enrolmentDateTime; } public void setEnrolmentDateTime(DateTime enrolmentDateTime) { - this.enrolmentDateTime = DateTimeUtil.toInstant(enrolmentDateTime); + this.enrolmentDateTime = enrolmentDateTime; } public ObservationCollection getObservations() { @@ -143,11 +145,11 @@ public void setObservations(ObservationCollection observations) { } public DateTime getProgramExitDateTime() { - return DateTimeUtil.toJodaDateTime(programExitDateTime); + return programExitDateTime; } public void setProgramExitDateTime(DateTime programExitDateTime) { - this.programExitDateTime = DateTimeUtil.toInstant(programExitDateTime); + this.programExitDateTime = programExitDateTime; } public ObservationCollection getProgramExitObservations() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java b/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java index 1424aa1f5..338de34d5 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java @@ -6,6 +6,7 @@ import org.avni.server.domain.enums.ruleFailure.AppType; import org.avni.server.domain.enums.ruleFailure.EntityType; import org.avni.server.domain.enums.ruleFailure.SourceType; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Fetch; @@ -17,7 +18,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import java.time.Instant; import java.util.Date; @Entity @@ -66,10 +66,12 @@ public class RuleFailureTelemetry { private String stacktrace; @Column - private Instant closedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime closedDateTime; @Column - private Instant errorDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime errorDateTime; @Column private Boolean isClosed; @@ -86,7 +88,8 @@ public class RuleFailureTelemetry { private User createdBy; @CreatedDate - private Instant createdDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private Date createdDateTime; @JsonIgnore @JoinColumn(name = "last_modified_by_id") @@ -97,7 +100,8 @@ public class RuleFailureTelemetry { private User lastModifiedBy; @LastModifiedDate - private Instant lastModifiedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private Date lastModifiedDateTime; @Column(name = "version") private int version; @@ -107,7 +111,7 @@ public User getCreatedBy() { } public DateTime getCreatedDateTime() { - return DateTimeUtil.toJodaDateTime(createdDateTime); + return new DateTime(createdDateTime); } public User getLastModifiedBy() { @@ -215,19 +219,19 @@ public void setStacktrace(String stacktrace) { } public DateTime getClosedDateTime() { - return DateTimeUtil.toJodaDateTime(closedDateTime); + return closedDateTime; } public void setClosedDateTime(DateTime closedDateTime) { - this.closedDateTime = DateTimeUtil.toInstant(closedDateTime); + this.closedDateTime = closedDateTime; } public DateTime getErrorDateTime() { - return DateTimeUtil.toJodaDateTime(errorDateTime); + return errorDateTime; } public void setErrorDateTime(DateTime errorDateTime) { - this.errorDateTime = DateTimeUtil.toInstant(errorDateTime); + this.errorDateTime = errorDateTime; } public Boolean getClosed() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/StandardReportCardType.java b/avni-server-api/src/main/java/org/avni/server/domain/StandardReportCardType.java index df28c0a28..6b32658e9 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/StandardReportCardType.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/StandardReportCardType.java @@ -1,5 +1,6 @@ package org.avni.server.domain; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; @@ -7,8 +8,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @BatchSize(size = 100) public class StandardReportCardType { @@ -28,9 +27,11 @@ public class StandardReportCardType { @Column private boolean isVoided; @Column - private Instant createdDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime createdDateTime; @Column - private Instant lastModifiedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime lastModifiedDateTime; @Column @NotNull @Enumerated(EnumType.STRING) @@ -77,19 +78,19 @@ public void setVoided(boolean voided) { } public DateTime getCreatedDateTime() { - return DateTimeUtil.toJodaDateTime(createdDateTime); + return createdDateTime; } public void setCreatedDateTime(DateTime createdDateTime) { - this.createdDateTime = DateTimeUtil.toInstant(createdDateTime); + this.createdDateTime = createdDateTime; } public DateTime getLastModifiedDateTime() { - return DateTimeUtil.toJodaDateTime(lastModifiedDateTime); + return lastModifiedDateTime; } public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { - this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime); + this.lastModifiedDateTime = lastModifiedDateTime; } public @NotNull StandardReportCardTypeType getType() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/SyncTelemetry.java b/avni-server-api/src/main/java/org/avni/server/domain/SyncTelemetry.java index 8299607d7..7a3d385a0 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/SyncTelemetry.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/SyncTelemetry.java @@ -1,6 +1,7 @@ package org.avni.server.domain; import org.avni.server.framework.hibernate.JSONObjectUserType; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Type; @@ -9,8 +10,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "sync_telemetry") @BatchSize(size = 100) @@ -29,10 +28,12 @@ public class SyncTelemetry extends OrganisationAwareEntity{ private JsonObject entityStatus; @Column - private Instant syncStartTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime syncStartTime; @Column - private Instant syncEndTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime syncEndTime; @Column private String appVersion; @@ -83,19 +84,19 @@ public void setEntityStatus(JsonObject entityStatus) { } public DateTime getSyncStartTime() { - return DateTimeUtil.toJodaDateTime(syncStartTime); + return syncStartTime; } public void setSyncStartTime(DateTime syncStartTime) { - this.syncStartTime = DateTimeUtil.toInstant(syncStartTime); + this.syncStartTime = syncStartTime; } public DateTime getSyncEndTime() { - return DateTimeUtil.toJodaDateTime(syncEndTime); + return syncEndTime; } public void setSyncEndTime(DateTime syncEndTime) { - this.syncEndTime = DateTimeUtil.toInstant(syncEndTime); + this.syncEndTime = syncEndTime; } public String getAppVersion() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/User.java b/avni-server-api/src/main/java/org/avni/server/domain/User.java index 426802148..ac84bfe19 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/User.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/User.java @@ -7,6 +7,7 @@ import org.apache.commons.validator.routines.EmailValidator; import org.avni.server.domain.framework.IdHolder; import org.avni.server.framework.hibernate.JSONObjectUserType; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.avni.server.util.ObjectMapperSingleton; import org.avni.server.util.ValidationUtil; @@ -17,7 +18,6 @@ import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import java.time.Instant; import java.util.*; import java.util.stream.Collectors; @@ -63,15 +63,16 @@ public class User implements IdHolder { @ManyToOne(targetEntity = User.class) private User createdBy; - @Column - private Instant createdDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime createdDateTime; @JsonIgnore @JoinColumn(name = "last_modified_by_id") @ManyToOne(targetEntity = User.class) private User lastModifiedBy; - private Instant lastModifiedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime lastModifiedDateTime; @Column private boolean isVoided; @@ -258,7 +259,7 @@ public void setCreatedBy(User createdBy) { } public void setCreatedDateTime(DateTime createdDateTime) { - this.createdDateTime = DateTimeUtil.toInstant(createdDateTime); + this.createdDateTime = createdDateTime; } public void setLastModifiedBy(User lastModifiedBy) { @@ -266,7 +267,7 @@ public void setLastModifiedBy(User lastModifiedBy) { } public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { - this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime); + this.lastModifiedDateTime = lastModifiedDateTime; } public User getCreatedBy() { @@ -282,7 +283,7 @@ public String getLastModifiedByUserName() { } public DateTime getCreatedDateTime() { - return DateTimeUtil.toJodaDateTime(createdDateTime); + return createdDateTime; } public User getLastModifiedBy() { @@ -290,7 +291,7 @@ public User getLastModifiedBy() { } public DateTime getLastModifiedDateTime() { - return DateTimeUtil.toJodaDateTime(lastModifiedDateTime); + return lastModifiedDateTime; } public JsonObject getSyncSettings() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/VideoTelemetric.java b/avni-server-api/src/main/java/org/avni/server/domain/VideoTelemetric.java index d6712923d..ef9a8d60c 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/VideoTelemetric.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/VideoTelemetric.java @@ -1,5 +1,6 @@ package org.avni.server.domain; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; @@ -7,8 +8,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "video_telemetric") @BatchSize(size = 100) @@ -25,10 +24,12 @@ public class VideoTelemetric extends CHSBaseEntity { private Double videoEndTime; @Column(name = "player_close_time") - private Instant playerCloseTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime playerCloseTime; @Column(name = "player_open_time") - private Instant playerOpenTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime playerOpenTime; @ManyToOne(fetch = FetchType.LAZY) @NotNull @@ -44,7 +45,8 @@ public class VideoTelemetric extends CHSBaseEntity { private Long organisationId; @Column(name="created_datetime") - private Instant createdDatetime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime createdDatetime; public Double getVideoStartTime() { return videoStartTime; @@ -63,19 +65,19 @@ public void setVideoEndTime(Double videoEndTime) { } public DateTime getPlayerCloseTime() { - return DateTimeUtil.toJodaDateTime(playerCloseTime); + return playerCloseTime; } public void setPlayerCloseTime(DateTime playerCloseTime) { - this.playerCloseTime = DateTimeUtil.toInstant(playerCloseTime); + this.playerCloseTime = playerCloseTime; } public DateTime getPlayerOpenTime() { - return DateTimeUtil.toJodaDateTime(playerOpenTime); + return playerOpenTime; } public void setPlayerOpenTime(DateTime playerOpenTime) { - this.playerOpenTime = DateTimeUtil.toInstant(playerOpenTime); + this.playerOpenTime = playerOpenTime; } public Video getVideo() { @@ -103,10 +105,10 @@ public void setOrganisationId(Long organisationId) { } public DateTime getCreatedDatetime() { - return DateTimeUtil.toJodaDateTime(createdDatetime); + return createdDatetime; } public void setCreatedDatetime(DateTime createdDatetime) { - this.createdDatetime = DateTimeUtil.toInstant(createdDatetime); + this.createdDatetime = createdDatetime; } } diff --git a/avni-server-api/src/main/java/org/avni/server/domain/accessControl/Privilege.java b/avni-server-api/src/main/java/org/avni/server/domain/accessControl/Privilege.java index 738c959e5..ead1647d3 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/accessControl/Privilege.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/accessControl/Privilege.java @@ -5,12 +5,11 @@ import org.avni.server.domain.CHSBaseEntity; import org.avni.server.domain.PrivilegeEntityType; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; -import java.time.Instant; - @Entity @Table(name = "privilege") @BatchSize(size = 100) @@ -32,25 +31,27 @@ public class Privilege extends CHSBaseEntity { private PrivilegeEntityType entityType; @Column - private Instant createdDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime createdDateTime; @Column - private Instant lastModifiedDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime lastModifiedDateTime; public DateTime getCreatedDateTime() { - return DateTimeUtil.toJodaDateTime(createdDateTime); + return createdDateTime; } public void setCreatedDateTime(DateTime createdDateTime) { - this.createdDateTime = DateTimeUtil.toInstant(createdDateTime); + this.createdDateTime = createdDateTime; } public DateTime getLastModifiedDateTime() { - return DateTimeUtil.toJodaDateTime(lastModifiedDateTime); + return lastModifiedDateTime; } public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { - this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime); + this.lastModifiedDateTime = lastModifiedDateTime; } public String getName() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/individualRelationship/IndividualRelationship.java b/avni-server-api/src/main/java/org/avni/server/domain/individualRelationship/IndividualRelationship.java index 89775a07c..9e3677a08 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/individualRelationship/IndividualRelationship.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/individualRelationship/IndividualRelationship.java @@ -1,6 +1,7 @@ package org.avni.server.domain.individualRelationship; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; @@ -13,8 +14,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "individual_relationship") @JsonIgnoreProperties({"individuala", "individualB"}) @@ -37,10 +36,12 @@ public class IndividualRelationship extends OrganisationAwareEntity { private Individual individualB; @Column - private Instant enterDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime enterDateTime; @Column - private Instant exitDateTime; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime exitDateTime; @Column @Type(value = ObservationCollectionUserType.class) @@ -71,19 +72,19 @@ public void setIndividualB(Individual individualB) { } public DateTime getEnterDateTime() { - return DateTimeUtil.toJodaDateTime(enterDateTime); + return enterDateTime; } public void setEnterDateTime(DateTime enterDateTime) { - this.enterDateTime = DateTimeUtil.toInstant(enterDateTime); + this.enterDateTime = enterDateTime; } public DateTime getExitDateTime() { - return DateTimeUtil.toJodaDateTime(exitDateTime); + return exitDateTime; } public void setExitDateTime(DateTime exitDateTime) { - this.exitDateTime = DateTimeUtil.toInstant(exitDateTime); + this.exitDateTime = exitDateTime; } public ObservationCollection getExitObservations() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/program/SubjectProgramEligibility.java b/avni-server-api/src/main/java/org/avni/server/domain/program/SubjectProgramEligibility.java index 2298fce08..9adba761c 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/program/SubjectProgramEligibility.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/program/SubjectProgramEligibility.java @@ -12,8 +12,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity(name = "subject_program_eligibility") public class SubjectProgramEligibility extends OrganisationAwareEntity { @ManyToOne(targetEntity = Individual.class, fetch = FetchType.LAZY) @@ -30,7 +28,7 @@ public class SubjectProgramEligibility extends OrganisationAwareEntity { private boolean isEligible; @Column - private Instant checkDate; + private DateTime checkDate; @Column @Type(value = ObservationCollectionUserType.class) @@ -61,11 +59,11 @@ public void setEligible(boolean eligible) { } public DateTime getCheckDate() { - return DateTimeUtil.toJodaDateTime(checkDate); + return checkDate; } public void setCheckDate(DateTime checkDate) { - this.checkDate = DateTimeUtil.toInstant(checkDate); + this.checkDate = checkDate; } public ObservationCollection getObservations() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/task/Task.java b/avni-server-api/src/main/java/org/avni/server/domain/task/Task.java index 304cf6cb8..25d456112 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/task/Task.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/task/Task.java @@ -4,6 +4,7 @@ import org.avni.server.domain.ObservationCollection; import org.avni.server.domain.OrganisationAwareEntity; import org.avni.server.domain.User; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; @@ -13,8 +14,6 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import java.time.Instant; - @Entity @Table(name = "task") @BatchSize(size = 100) @@ -34,10 +33,12 @@ public class Task extends OrganisationAwareEntity { private TaskStatus taskStatus; @Column - private Instant scheduledOn; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime scheduledOn; @Column - private Instant completedOn; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime completedOn; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "assigned_user_id") @@ -89,19 +90,19 @@ public void updateTaskStatus(TaskStatus taskStatus) { } public DateTime getScheduledOn() { - return DateTimeUtil.toJodaDateTime(scheduledOn); + return scheduledOn; } public void setScheduledOn(DateTime scheduledOn) { - this.scheduledOn = DateTimeUtil.toInstant(scheduledOn); + this.scheduledOn = scheduledOn; } public DateTime getCompletedOn() { - return DateTimeUtil.toJodaDateTime(completedOn); + return completedOn; } public void setCompletedOn(DateTime completedOn) { - this.completedOn = DateTimeUtil.toInstant(completedOn); + this.completedOn = completedOn; } public User getAssignedTo() { diff --git a/avni-server-api/src/main/java/org/avni/server/exporter/ExportBatchConfiguration.java b/avni-server-api/src/main/java/org/avni/server/exporter/ExportBatchConfiguration.java index a6ac80787..9ce4fe282 100644 --- a/avni-server-api/src/main/java/org/avni/server/exporter/ExportBatchConfiguration.java +++ b/avni-server-api/src/main/java/org/avni/server/exporter/ExportBatchConfiguration.java @@ -205,32 +205,32 @@ public Tasklet tasklet(@Value("#{jobParameters['uuid']}") String uuid, private Stream getGroupSubjectStream(String subjectTypeUUID, List addressParam, LocalDate startDate, LocalDate endDate, Map sorts, boolean isVoidedIncluded) { SubjectType subjectType = subjectTypeRepository.findByUuid(subjectTypeUUID); - return isVoidedIncluded ? groupSubjectRepository.findAllGroupSubjects(subjectType.getId(), addressParam, DateTimeUtil.toInstant(startDate), DateTimeUtil.toInstant(endDate)) : - groupSubjectRepository.findNonVoidedGroupSubjects(subjectType.getId(), addressParam, DateTimeUtil.toInstant(startDate), DateTimeUtil.toInstant(endDate)); + return isVoidedIncluded ? groupSubjectRepository.findAllGroupSubjects(subjectType.getId(), addressParam, startDate, endDate) : + groupSubjectRepository.findNonVoidedGroupSubjects(subjectType.getId(), addressParam, startDate, endDate); } private Stream getEncounterStream(String programUUID, String encounterTypeUUID, List addressParam, DateTime startDateTime, DateTime endDateTime, boolean isVoidedIncluded) { EncounterType encounterType = encounterTypeRepository.findByUuid(encounterTypeUUID); if (programUUID == null) { - return isVoidedIncluded ? individualRepository.findAllEncounters(addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime), encounterType.getId()) : - individualRepository.findNonVoidedEncounters(addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime), encounterType.getId()); + return isVoidedIncluded ? individualRepository.findAllEncounters(addressParam, startDateTime, endDateTime, encounterType.getId()) : + individualRepository.findNonVoidedEncounters(addressParam, startDateTime, endDateTime, encounterType.getId()); } else { Program program = programRepository.findByUuid(programUUID); - return isVoidedIncluded ? programEnrolmentRepository.findAllProgramEncounters(addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime), encounterType.getId(), program.getId()) : - programEnrolmentRepository.findNonVoidedProgramEncounters(addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime), encounterType.getId(), program.getId()); + return isVoidedIncluded ? programEnrolmentRepository.findAllProgramEncounters(addressParam, startDateTime, endDateTime, encounterType.getId(), program.getId()) : + programEnrolmentRepository.findNonVoidedProgramEncounters(addressParam, startDateTime, endDateTime, encounterType.getId(), program.getId()); } } private Stream getEnrolmentStream(String programUUID, List addressParam, DateTime startDateTime, DateTime endDateTime, boolean isVoidedIncluded) { Program program = programRepository.findByUuid(programUUID); - return isVoidedIncluded ? programEnrolmentRepository.findAllEnrolments(program.getId(), addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime)) : - programEnrolmentRepository.findNonVoidedEnrolments(program.getId(), addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime)); + return isVoidedIncluded ? programEnrolmentRepository.findAllEnrolments(program.getId(), addressParam, startDateTime, endDateTime) : + programEnrolmentRepository.findNonVoidedEnrolments(program.getId(), addressParam, startDateTime, endDateTime); } private Stream getRegistrationStream(String subjectTypeUUID, List addressParam, LocalDate startDateTime, LocalDate endDateTime, boolean includeVoided) { SubjectType subjectType = subjectTypeRepository.findByUuid(subjectTypeUUID); - return includeVoided ? individualRepository.findAllIndividuals(subjectType.getId(), addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime)) : - individualRepository.findNonVoidedIndividuals(subjectType.getId(), addressParam, DateTimeUtil.toInstant(startDateTime), DateTimeUtil.toInstant(endDateTime)); + return includeVoided ? individualRepository.findAllIndividuals(subjectType.getId(), addressParam, startDateTime, endDateTime) : + individualRepository.findNonVoidedIndividuals(subjectType.getId(), addressParam, startDateTime, endDateTime); } private List getLocations(List locationIds) { diff --git a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaDateTimeConverter.java b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaDateTimeConverter.java new file mode 100644 index 000000000..59d4b7f94 --- /dev/null +++ b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaDateTimeConverter.java @@ -0,0 +1,28 @@ +package org.avni.server.framework.hibernate; + +import java.sql.Timestamp; +import org.joda.time.DateTime; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter(autoApply = true) +public class JodaDateTimeConverter implements AttributeConverter { + + @Override + public Timestamp convertToDatabaseColumn(DateTime attribute) { + if (attribute == null) { + return null; + } else { + return new Timestamp(attribute.getMillis()); + } + } + + @Override + public DateTime convertToEntityAttribute(Timestamp data) { + if (data == null) { + return null; + } else { + return new DateTime(data.getTime()); + } + } +} diff --git a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaLocalDateConverter.java b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaLocalDateConverter.java new file mode 100644 index 000000000..c3c1faecb --- /dev/null +++ b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/JodaLocalDateConverter.java @@ -0,0 +1,29 @@ +package org.avni.server.framework.hibernate; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; +import org.joda.time.DateTime; +import org.joda.time.LocalDate; + +import java.sql.Timestamp; + +@Converter(autoApply = true) +public class JodaLocalDateConverter implements AttributeConverter { + @Override + public Timestamp convertToDatabaseColumn(LocalDate attribute) { + if (attribute == null) { + return null; + } else { + return new Timestamp(attribute.toDate().getTime()); + } + } + + @Override + public LocalDate convertToEntityAttribute(Timestamp data) { + if (data == null) { + return null; + } else { + return new LocalDate(data.getTime()); + } + } +} diff --git a/avni-server-api/src/main/java/org/avni/server/service/ApprovalStatusService.java b/avni-server-api/src/main/java/org/avni/server/service/ApprovalStatusService.java index bc6390560..8982c9fa2 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/ApprovalStatusService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/ApprovalStatusService.java @@ -18,7 +18,7 @@ public ApprovalStatusService(ApprovalStatusRepository approvalStatusRepository) @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return approvalStatusRepository.existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return approvalStatusRepository.existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java b/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java index 642bd71d1..a3c3095ae 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/IdentifierAssignmentService.java @@ -75,6 +75,6 @@ private boolean shouldGenerateIdentifiers(User user, IdentifierSource identifier public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { User user = UserContextHolder.getUserContext().getUser(); this.generateIdentifiersIfNecessary(user); - return identifierAssignmentRepository.existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNull(user, DateTimeUtil.toInstant(lastModifiedDateTime)); + return identifierAssignmentRepository.existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNull(user, CHSEntity.toDate(lastModifiedDateTime)); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/IdentifierSourceService.java b/avni-server-api/src/main/java/org/avni/server/service/IdentifierSourceService.java index 48102c6e8..df5d71aa1 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/IdentifierSourceService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/IdentifierSourceService.java @@ -62,7 +62,7 @@ private Catchment getCatchment(Long catchmentId, String catchmentUUID) { @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return identifierSourceRepository.existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return identifierSourceRepository.existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime); } public void saveIdSources(IdentifierSourceContractWeb[] identifierSourceContractWebs) { diff --git a/avni-server-api/src/main/java/org/avni/server/service/LocationHierarchyService.java b/avni-server-api/src/main/java/org/avni/server/service/LocationHierarchyService.java index 6cee55870..d3462abe6 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/LocationHierarchyService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/LocationHierarchyService.java @@ -128,7 +128,7 @@ public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { ArrayList addressLevelTypeIds = (ArrayList) this.getLowestAddressLevelTypeHierarchiesForOrganisation(); if (addressLevelTypeIds != null) { List addressLevelTypes = addressLevelTypeRepository.findAllByIdIn(addressLevelTypeIds); - return locationRepository.existsByLastModifiedDateTimeAfterAndTypeIn(DateTimeUtil.toInstant(lastModifiedDateTime), addressLevelTypes); + return locationRepository.existsByLastModifiedDateTimeAfterAndTypeIn(CHSEntity.toDate(lastModifiedDateTime), addressLevelTypes); } return false; } diff --git a/avni-server-api/src/main/java/org/avni/server/service/NewsService.java b/avni-server-api/src/main/java/org/avni/server/service/NewsService.java index 511541298..0eec3a15f 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/NewsService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/NewsService.java @@ -64,6 +64,6 @@ private void assertNewTitleIsUnique(String newTitle, String oldTitle) { @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return newsRepository.existsByPublishedDateNotNullAndLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return newsRepository.existsByPublishedDateNotNullAndLastModifiedDateTimeGreaterThan(CHSEntity.toDate(lastModifiedDateTime)); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/PlatformTranslationService.java b/avni-server-api/src/main/java/org/avni/server/service/PlatformTranslationService.java index 4160d4777..1d6a21282 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/PlatformTranslationService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/PlatformTranslationService.java @@ -21,7 +21,7 @@ public PlatformTranslationService(PlatformTranslationRepository platformTranslat @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return platformTranslationRepository.existsByPlatformAndLastModifiedDateTimeGreaterThan(Platform.Android, DateTimeUtil.toInstant(lastModifiedDateTime)); + return platformTranslationRepository.existsByPlatformAndLastModifiedDateTimeGreaterThan(Platform.Android, CHSEntity.toDate(lastModifiedDateTime)); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/ResetSyncService.java b/avni-server-api/src/main/java/org/avni/server/service/ResetSyncService.java index 5c07eb404..ff4a5d185 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/ResetSyncService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/ResetSyncService.java @@ -164,6 +164,6 @@ private boolean isChanged(Object str1, Object str2) { } public Page getByLastModifiedForUser(DateTime lastModifiedDateTime, DateTime now, User user, Pageable pageable) { - return resetSyncRepository.findAllByUserIsNullOrUserAndLastModifiedDateTimeBetweenOrderByLastModifiedDateTimeAscIdAsc(user, DateTimeUtil.toInstant(lastModifiedDateTime), DateTimeUtil.toInstant(now), pageable); + return resetSyncRepository.findAllByUserIsNullOrUserAndLastModifiedDateTimeBetweenOrderByLastModifiedDateTimeAscIdAsc(user, lastModifiedDateTime.toDate(), now.toDate(), pageable); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/RuleDependencyService.java b/avni-server-api/src/main/java/org/avni/server/service/RuleDependencyService.java index 2ee8fb565..bdcd67292 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/RuleDependencyService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/RuleDependencyService.java @@ -33,6 +33,6 @@ public RuleDependencyService(RuleDependencyRepository ruleDependencyRepository) @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return ruleDependencyRepository.existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return ruleDependencyRepository.existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/StandardReportCardTypeService.java b/avni-server-api/src/main/java/org/avni/server/service/StandardReportCardTypeService.java index 4054f78ed..d79adf125 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/StandardReportCardTypeService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/StandardReportCardTypeService.java @@ -19,6 +19,6 @@ public StandardReportCardTypeService(StandardReportCardTypeRepository standardRe @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return standardReportCardTypeRepository.existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return standardReportCardTypeRepository.existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime); } } diff --git a/avni-server-api/src/main/java/org/avni/server/service/UserService.java b/avni-server-api/src/main/java/org/avni/server/service/UserService.java index af34dae7e..b160cda43 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/UserService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/UserService.java @@ -126,7 +126,7 @@ public void associateUserToGroups(User user, List associatedGroupIds) { @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return userRepository.existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return userRepository.existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime); } public User findByUuid(String uuid) { diff --git a/avni-server-api/src/main/java/org/avni/server/service/accessControl/PrivilegeService.java b/avni-server-api/src/main/java/org/avni/server/service/accessControl/PrivilegeService.java index 847e6f199..029e49357 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/accessControl/PrivilegeService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/accessControl/PrivilegeService.java @@ -20,6 +20,6 @@ public PrivilegeService(PrivilegeRepository privilegeRepository) { @Override public boolean isNonScopeEntityChanged(DateTime lastModifiedDateTime) { - return privilegeRepository.existsByLastModifiedDateTimeGreaterThan(DateTimeUtil.toInstant(lastModifiedDateTime)); + return privilegeRepository.existsByLastModifiedDateTimeGreaterThan(lastModifiedDateTime); } } diff --git a/avni-server-api/src/main/java/org/avni/server/util/DateTimeUtil.java b/avni-server-api/src/main/java/org/avni/server/util/DateTimeUtil.java index 5d33f01f4..94407f2ef 100644 --- a/avni-server-api/src/main/java/org/avni/server/util/DateTimeUtil.java +++ b/avni-server-api/src/main/java/org/avni/server/util/DateTimeUtil.java @@ -6,9 +6,7 @@ import org.joda.time.LocalDate; import java.time.LocalDateTime; -import java.time.ZonedDateTime; import java.util.Calendar; -import java.util.Date; import java.util.TimeZone; public class DateTimeUtil { @@ -50,49 +48,4 @@ public static long getMilliSecondsDuration(LocalDateTime start, LocalDateTime en return java.time.Duration.between(start, end).toMillis(); } - public static LocalDate toJodaDate(java.time.Instant instant) { - if (instant == null) { - return null; - } - return DateTimeUtil.toJodaDateTime(instant).toLocalDate(); - } - - public static java.time.Instant toInstant(LocalDate localDate) { - if (localDate == null) { - return null; - } - return localDate.toDate().toInstant(); - } - - public static java.time.Instant toInstant(DateTime createdDateTime) { - if (createdDateTime == null) { - return null; - } - return createdDateTime.toDate().toInstant(); - } - - public static DateTime toJodaDateTime(java.time.Instant instant) { - if (instant == null) { - return null; - } - return new DateTime(instant.toEpochMilli()); - } - - public static DateTime toJodaDateTime(ZonedDateTime zonedDateTime) { - if (zonedDateTime == null) { - return null; - } - return new DateTime(zonedDateTime.toInstant().toEpochMilli()); - } - - public static java.time.Instant toInstant(Date date) { - if (date == null) { - return null; - } - return date.toInstant(); - } - - public static java.time.Instant toInstant(Calendar calendar) { - return calendar == null ? null : calendar.toInstant(); - } } diff --git a/avni-server-api/src/main/java/org/avni/server/web/DashboardController.java b/avni-server-api/src/main/java/org/avni/server/web/DashboardController.java index 97ccf9f3b..ba3d196a6 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/DashboardController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/DashboardController.java @@ -128,7 +128,7 @@ public CollectionModel> getDashboards(@RequestParam("last @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(dashboardRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), + return wrap(dashboardRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime.toDate(), CHSEntity.toDate(now), pageable)); } } diff --git a/avni-server-api/src/main/java/org/avni/server/web/DashboardFilterController.java b/avni-server-api/src/main/java/org/avni/server/web/DashboardFilterController.java index 8ef77557f..73af523b6 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/DashboardFilterController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/DashboardFilterController.java @@ -31,7 +31,7 @@ public CollectionModel> getDashboardFilters(@Reques @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(dashboardFilterRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), + return wrap(dashboardFilterRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime.toDate(), CHSEntity.toDate(now), pageable)); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionCardMappingController.java b/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionCardMappingController.java index 6051b1bb1..21e7a7c6f 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionCardMappingController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionCardMappingController.java @@ -31,7 +31,7 @@ public CollectionModel> getDashboardSec @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(dashboardSectionCardMappingRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), + return wrap(dashboardSectionCardMappingRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime.toDate(), CHSEntity.toDate(now), pageable)); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionController.java b/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionController.java index 5415337ae..592fc6b85 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/DashboardSectionController.java @@ -31,7 +31,7 @@ public CollectionModel> getDashboardSection(@Reque @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(dashboardSectionRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), + return wrap(dashboardSectionRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime.toDate(), CHSEntity.toDate(now), pageable)); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/GroupDashboardController.java b/avni-server-api/src/main/java/org/avni/server/web/GroupDashboardController.java index 6cda69d27..04225bf66 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/GroupDashboardController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/GroupDashboardController.java @@ -104,7 +104,7 @@ public CollectionModel> getDashboardFilters(@Request @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(groupDashboardRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), + return wrap(groupDashboardRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime.toDate(), CHSEntity.toDate(now), pageable)); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/IndividualRelationshipController.java b/avni-server-api/src/main/java/org/avni/server/web/IndividualRelationshipController.java index b79063c37..80d94ce4f 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/IndividualRelationshipController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/IndividualRelationshipController.java @@ -91,7 +91,7 @@ public CollectionModel> getByLastModified( @RequestParam("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(individualRelationshipRepository.findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), DateTimeUtil.toInstant(now), pageable)); + return wrap(individualRelationshipRepository.findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime, now, pageable)); } @RequestMapping(value = "/individualRelationship/v2", method = RequestMethod.GET) diff --git a/avni-server-api/src/main/java/org/avni/server/web/ProgramEncounterController.java b/avni-server-api/src/main/java/org/avni/server/web/ProgramEncounterController.java index 701889058..d7a54f020 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/ProgramEncounterController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/ProgramEncounterController.java @@ -120,7 +120,7 @@ public CollectionModel> getByLastModified( @RequestParam("lastModifiedDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(programEncounterRepository.findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), DateTimeUtil.toInstant(now), pageable)); + return wrap(programEncounterRepository.findByLastModifiedDateTimeIsBetweenOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime, now, pageable)); } @RequestMapping(value = "/programEncounter/v2", method = RequestMethod.GET) diff --git a/avni-server-api/src/main/java/org/avni/server/web/ReportCardController.java b/avni-server-api/src/main/java/org/avni/server/web/ReportCardController.java index abd02f86a..cadcc37e1 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/ReportCardController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/ReportCardController.java @@ -100,7 +100,7 @@ public CollectionModel> getReportCards(@RequestParam("la @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime lastModifiedDateTime, @RequestParam("now") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime now, Pageable pageable) { - return wrap(cardRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(DateTimeUtil.toInstant(lastModifiedDateTime), + return wrap(cardRepository.findByLastModifiedDateTimeIsGreaterThanEqualAndLastModifiedDateTimeLessThanEqualOrderByLastModifiedDateTimeAscIdAsc(lastModifiedDateTime.toDate(), CHSEntity.toDate(now), pageable)); } diff --git a/avni-server-api/src/main/java/org/avni/server/web/SyncTelemetryController.java b/avni-server-api/src/main/java/org/avni/server/web/SyncTelemetryController.java index f1b97a9a1..e72437a27 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/SyncTelemetryController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/SyncTelemetryController.java @@ -59,12 +59,11 @@ public CollectionModel> getAll(@RequestParam(value = if (startDate == null && userIds.isEmpty()) { return wrap(syncTelemetryRepository.findAllByOrderByIdDesc(pageable)); } else if (startDate != null && !userIds.isEmpty()) { - return wrap(syncTelemetryRepository.findAllByUserIdInAndSyncStartTimeBetweenOrderByIdDesc(userIds, DateTimeUtil.toInstant(startDate), - DateTimeUtil.toInstant(endDate), pageable)); + return wrap(syncTelemetryRepository.findAllByUserIdInAndSyncStartTimeBetweenOrderByIdDesc(userIds, startDate, endDate, pageable)); } else if (!userIds.isEmpty()) { return wrap(syncTelemetryRepository.findAllByUserIdInOrderByIdDesc(userIds, pageable)); } else { - return wrap(syncTelemetryRepository.findAllBySyncStartTimeBetweenOrderByIdDesc(DateTimeUtil.toInstant(startDate), DateTimeUtil.toInstant(endDate), pageable)); + return wrap(syncTelemetryRepository.findAllBySyncStartTimeBetweenOrderByIdDesc(startDate, endDate, pageable)); } } diff --git a/avni-server-api/src/main/java/org/avni/server/web/api/GeneralEncounterApiController.java b/avni-server-api/src/main/java/org/avni/server/web/api/GeneralEncounterApiController.java index 79f550b38..dd2c83f88 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/api/GeneralEncounterApiController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/api/GeneralEncounterApiController.java @@ -77,7 +77,7 @@ public ResponsePage getEncounters(@RequestParam(value = "lastModifiedDateTime", Page encounters; Map conceptsMap = conceptService.readConceptsFromJsonObject(concepts); - EncounterSearchRequest encounterSearchRequest = new EncounterSearchRequest(CHSEntity.toUtilDate(lastModifiedDateTime), CHSEntity.toUtilDate(now), encounterType, subjectUUID, conceptsMap, pageable); + EncounterSearchRequest encounterSearchRequest = new EncounterSearchRequest(CHSEntity.toDate(lastModifiedDateTime), CHSEntity.toDate(now), encounterType, subjectUUID, conceptsMap, pageable); TimeTakenLogger timeTakenLogger = new TimeTakenLogger("Search encounters", logger); encounters = encounterService.search(encounterSearchRequest); timeTakenLogger.logInfo(); diff --git a/avni-server-api/src/main/java/org/avni/server/web/api/ProgramEncounterApiController.java b/avni-server-api/src/main/java/org/avni/server/web/api/ProgramEncounterApiController.java index 169ad28e8..cc93ae45f 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/api/ProgramEncounterApiController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/api/ProgramEncounterApiController.java @@ -95,7 +95,7 @@ public ProgramEncounterRepository.SearchParams createSearchParams(DateTime lastM programEnrolment = programEnrolmentRepository.findByUuid(programEnrolmentUuid); } - return new ProgramEncounterRepository.SearchParams(CHSEntity.toUtilDate(lastModifiedDateTime), CHSEntity.toUtilDate(now), conceptsMap, encounterType, programEnrolment); + return new ProgramEncounterRepository.SearchParams(CHSEntity.toDate(lastModifiedDateTime), CHSEntity.toDate(now), conceptsMap, encounterType, programEnrolment); } @GetMapping(value = "/api/programEncounter/{id}") diff --git a/avni-server-api/src/test/java/org/avni/server/util/DateTimeUtilTest.java b/avni-server-api/src/test/java/org/avni/server/util/DateTimeUtilTest.java index 9d825ecb2..763997663 100644 --- a/avni-server-api/src/test/java/org/avni/server/util/DateTimeUtilTest.java +++ b/avni-server-api/src/test/java/org/avni/server/util/DateTimeUtilTest.java @@ -1,7 +1,5 @@ package org.avni.server.util; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -12,11 +10,4 @@ public void shouldGetTheRightDateForDateTimeString() { String aDateString = "2020-01-31T18:30:00.000+00:00"; assertThat(DateTimeUtil.toDateString(aDateString)).isEqualTo("2020-02-01"); } - - @Test - public void jodaConversions() { - DateTimeUtil.toJodaDateTime(java.time.Instant.now()); - DateTimeUtil.toInstant(LocalDate.now()); - DateTimeUtil.toInstant(LocalDateTime.now().toDateTime()); - } } From 21b5b8f89df441e0a7d8f0f357a7958a332af10d Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Mon, 18 Nov 2024 15:11:25 +0530 Subject: [PATCH 2/5] #813 - need to register converter explicity for RestRepository --- .../org/avni/server/framework/rest/RepositoryConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/avni-server-api/src/main/java/org/avni/server/framework/rest/RepositoryConfig.java b/avni-server-api/src/main/java/org/avni/server/framework/rest/RepositoryConfig.java index 314473d93..f367c250d 100644 --- a/avni-server-api/src/main/java/org/avni/server/framework/rest/RepositoryConfig.java +++ b/avni-server-api/src/main/java/org/avni/server/framework/rest/RepositoryConfig.java @@ -1,17 +1,24 @@ package org.avni.server.framework.rest; +import org.avni.server.StringToJodaDateTimeConverter; import org.avni.server.domain.*; import org.avni.server.domain.accessControl.GroupPrivilege; import org.avni.server.domain.accessControl.Privilege; import org.avni.server.domain.organisation.OrganisationCategory; import org.avni.server.domain.organisation.OrganisationStatus; import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.support.ConfigurableConversionService; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer; import org.springframework.web.servlet.config.annotation.CorsRegistry; @Configuration public class RepositoryConfig implements RepositoryRestConfigurer { + @Override + public void configureConversionService(ConfigurableConversionService conversionService) { + conversionService.addConverter(new StringToJodaDateTimeConverter()); + } + @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) { config.exposeIdsFor(User.class); @@ -60,4 +67,6 @@ public void configureRepositoryRestConfiguration(RepositoryRestConfiguration con httpMethods.disable(HttpMethod.PATCH)); */ } + + } From af8296608a350427de3d4769654fd4f3f40ba4c6 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 21 Nov 2024 16:25:50 +0530 Subject: [PATCH 3/5] #813 - upgraded 2nd level ehcache based hibernate configuration --- Makefile | 1 + avni-server-api/build.gradle | 24 +++-- .../AvniCacheEventListenerFactory.java | 13 --- .../framework/hibernate/CacheEventLogger.java | 60 +------------ .../src/main/resources/application.properties | 6 +- .../src/main/resources/ehcache.xml | 87 +++++++++++------- .../src/test/resources/application.properties | 7 +- .../src/test/resources/ehcache.xml | 89 +++++++++++-------- makefiles/gradle.mk | 2 + 9 files changed, 134 insertions(+), 155 deletions(-) delete mode 100644 avni-server-api/src/main/java/org/avni/server/framework/hibernate/AvniCacheEventListenerFactory.java create mode 100644 makefiles/gradle.mk diff --git a/Makefile b/Makefile index 0d196e7ac..3c40d8ce4 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ include makefiles/externalDB.mk include makefiles/prod.mk include makefiles/api-test-data.mk include makefiles/lfe.mk +include makefiles/gradle.mk help: @IFS=$$'\n' ; \ diff --git a/avni-server-api/build.gradle b/avni-server-api/build.gradle index 425e2bfa1..a37f6c981 100644 --- a/avni-server-api/build.gradle +++ b/avni-server-api/build.gradle @@ -17,7 +17,6 @@ plugins { id 'java' } -ext { springBootVersion = '3.3.5' } //todo: Remove when upgrading Spring version. This was introduced to use SameSiteCookies //ext['tomcat.version'] = '9.0.80' @@ -48,7 +47,7 @@ configurations { dependencies { implementation group: 'org.apache.tomcat', name: 'tomcat-jdbc' implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") - implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}" + implementation("org.springframework.boot:spring-boot-starter-cache:${springBootVersion}") testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" implementation "org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}" implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}") @@ -61,9 +60,6 @@ dependencies { exclude(group: 'org.hibernate', module: 'hibernate-core') } runtimeOnly("javax.transaction:jta:1.1") -// implementation(group: 'org.jadira.usertype', name: 'usertype.core', version: '7.0.0.CR1') { -// exclude(group: 'org.hibernate', module: 'hibernate-core') -// } implementation "org.flywaydb:flyway-core:10.20.1" runtimeOnly("org.flywaydb:flyway-database-postgresql:10.20.1") implementation "org.flywaydb.flyway-test-extensions:flyway-spring6-test:10.0.0" @@ -73,15 +69,11 @@ dependencies { implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.3' implementation 'com.auth0:jwks-rsa:0.3.0' implementation 'com.auth0:java-jwt:3.3.0' -// implementation(group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.9.2.Final') { -// exclude(group: 'org.hibernate', module: 'hibernate-core') -// } implementation 'com.bugsnag:bugsnag:3.+' implementation 'com.amazonaws:aws-java-sdk-s3' implementation 'com.amazonaws:aws-java-sdk-cognitoidp' implementation 'commons-validator:commons-validator:1.4.1' implementation 'org.passay:passay:1.6.3' - implementation 'org.springframework.boot:spring-boot-starter-cache' implementation 'org.keycloak:keycloak-spring-boot-starter:24.0.4' implementation 'org.keycloak:keycloak-admin-client:24.0.2' implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.4' @@ -89,13 +81,19 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-annotations:2.15.4' implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.15.2' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.15.4' - implementation('org.hibernate:hibernate-ehcache:5.6.15.Final') { + + implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}" + implementation 'javax.cache:cache-api:1.1.1' + implementation("org.hibernate.orm:hibernate-jcache:6.5.2.Final") { + exclude(group: "org.hibernate.orm", module: "hibernate-core") + } + runtimeOnly('org.hibernate:hibernate-ehcache:5.6.15.Final') { exclude(group: 'org.hibernate', module: 'hibernate-core') } + + implementation('org.ehcache:ehcache:3.10.8:jakarta') + runtimeOnly("javax.xml.bind:jaxb-api:2.3.1") - runtimeOnly('org.ehcache:ehcache:3.10.8') - runtimeOnly("org.hibernate:hibernate-jcache:6.5.1.Final") - implementation 'javax.cache:cache-api:1.1.1' dev "org.springframework.boot:spring-boot-devtools:${springBootVersion}" testImplementation "org.mockito:mockito-core:3.12.4" testImplementation 'org.powermock:powermock-core:2.0.9' diff --git a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/AvniCacheEventListenerFactory.java b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/AvniCacheEventListenerFactory.java deleted file mode 100644 index 9c526a4c6..000000000 --- a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/AvniCacheEventListenerFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.avni.server.framework.hibernate; - -import net.sf.ehcache.event.CacheEventListener; -import net.sf.ehcache.event.CacheEventListenerFactory; - -import java.util.Properties; - -public class AvniCacheEventListenerFactory extends CacheEventListenerFactory { - @Override - public CacheEventListener createCacheEventListener(Properties properties) { - return new CacheEventLogger(); - } -} diff --git a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/CacheEventLogger.java b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/CacheEventLogger.java index 1bd75e7d0..f03388425 100644 --- a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/CacheEventLogger.java +++ b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/CacheEventLogger.java @@ -1,66 +1,14 @@ package org.avni.server.framework.hibernate; -import net.sf.ehcache.CacheException; -import net.sf.ehcache.Ehcache; -import net.sf.ehcache.Element; -import net.sf.ehcache.event.CacheEventListener; -import org.avni.server.framework.security.UserContextHolder; +import org.ehcache.event.CacheEvent; +import org.ehcache.event.CacheEventListener; import org.slf4j.LoggerFactory; public class CacheEventLogger implements CacheEventListener { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CacheEventLogger.class); - private String getCacheInfo(Ehcache ehcache) { - return String.format("Cache name: %s, Cache size: %d", ehcache.getName(), ehcache.getSize()); - } - - private String getElementInfo(Element element) { - return String.format("Element: %s", element.getObjectKey().toString()); - } - - private void log(String action, Ehcache cache, Element element) { - if (logger.isTraceEnabled()) { - logger.trace("{} -> {}, {}, User: {}", action, getCacheInfo(cache), getElementInfo(element), UserContextHolder.getUserName()); - } - } - - @Override - public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException { - this.log("Removed", cache, element); - } - - @Override - public void notifyElementPut(Ehcache cache, Element element) throws CacheException { - this.log("Put", cache, element); - } - - @Override - public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException { - this.log("Updated", cache, element); - } - - @Override - public void notifyElementExpired(Ehcache cache, Element element) { - this.log("Expired", cache, element); - } - - @Override - public void notifyElementEvicted(Ehcache cache, Element element) { - logger.debug("Evicted -> {}, {}, User: {}", getCacheInfo(cache), getElementInfo(element), UserContextHolder.getUserName()); - } - - @Override - public void notifyRemoveAll(Ehcache cache) { - logger.debug("All removed. {}", getCacheInfo(cache)); - } - - @Override - public Object clone() { - return null; - } - @Override - public void dispose() { - logger.info("Dispose called."); + public void onEvent(CacheEvent event) { + logger.info("Event: {}", event); } } diff --git a/avni-server-api/src/main/resources/application.properties b/avni-server-api/src/main/resources/application.properties index a51cf7803..ecd1a07d6 100644 --- a/avni-server-api/src/main/resources/application.properties +++ b/avni-server-api/src/main/resources/application.properties @@ -44,9 +44,13 @@ avni.legacy.longitudinal.export.limit=${AVNI_LEGACY_LONGITUDINAL_EXPORT_LIMIT:10 spring.main.allow-bean-definition-overriding=true # Second level and Query cache. Also check ehcache.xml file. +#https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#caching-provider-jcache +#spring.cache.jcache.config=${AVNI_EHCACHE_FILE:classpath:ehcache.xml} spring.jpa.properties.hibernate.cache.use_second_level_cache=true spring.jpa.properties.hibernate.cache.use_query_cache=true -spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.jcache.JCacheRegionFactory +spring.jpa.properties.hibernate.cache.region.factory_class=jcache +spring.jpa.properties.hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider +spring.jpa.properties.hibernate.javax.cache.uri=${AVNI_EHCACHE_FILE:classpath://ehcache.xml} # Hibernate Search spring.jpa.properties.hibernate.search.default.directory_provider=local-heap diff --git a/avni-server-api/src/main/resources/ehcache.xml b/avni-server-api/src/main/resources/ehcache.xml index 8521cb547..334fde37c 100644 --- a/avni-server-api/src/main/resources/ehcache.xml +++ b/avni-server-api/src/main/resources/ehcache.xml @@ -1,41 +1,60 @@ - - - - - - - + + + + + + 86400 + + + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - + + + + 86400 + + 1000 - - - + + + + 86400 + + 1000 - - + + + + 86400 + + 1000 - - + + + + 86400 + + 1000 - - - + + + + 86400 + + 1000 - - - - + diff --git a/avni-server-api/src/test/resources/application.properties b/avni-server-api/src/test/resources/application.properties index f832fa915..a0ca1f2a4 100644 --- a/avni-server-api/src/test/resources/application.properties +++ b/avni-server-api/src/test/resources/application.properties @@ -31,8 +31,11 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.session_factory.interceptor=org.avni.server.framework.hibernate.UpdateOrganisationHibernateInterceptor spring.jpa.properties.hibernate.cache.use_second_level_cache=true spring.jpa.properties.hibernate.cache.use_query_cache=true -spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.jcache.JCacheRegionFactory -spring.cache.jcache.config=${AVNI_EHCACHE_FILE:classpath:ehcache.xml} + +spring.jpa.properties.hibernate.cache.region.factory_class=jcache +spring.jpa.properties.hibernate.javax.cache.provider=org.ehcache.jsr107.EhcacheCachingProvider +spring.jpa.properties.hibernate.javax.cache.uri=classpath://ehcache.xml +#spring.cache.jcache.config=${AVNI_EHCACHE_FILE:classpath:ehcache.xml} #spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL10Dialect spring.profiles.active=${OPENCHS_MODE:test} spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false diff --git a/avni-server-api/src/test/resources/ehcache.xml b/avni-server-api/src/test/resources/ehcache.xml index 0566e6e14..756663968 100644 --- a/avni-server-api/src/test/resources/ehcache.xml +++ b/avni-server-api/src/test/resources/ehcache.xml @@ -1,43 +1,60 @@ - - - - - - + + + + + + 86400 + + + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - + + + + 86400 + + 10000 - - - - - + diff --git a/makefiles/gradle.mk b/makefiles/gradle.mk new file mode 100644 index 000000000..311cd2bdb --- /dev/null +++ b/makefiles/gradle.mk @@ -0,0 +1,2 @@ +dependency-tree-compile-classpath: + cd avni-server-api && ../gradlew dependencies --configuration compileClasspath From 6067970a3e6a63dfa1017ac0346b19c446e1c562 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 21 Nov 2024 16:30:15 +0530 Subject: [PATCH 4/5] #813 - post merge removal of jadira usage --- .../server/importer/batch/csv/creator/AddressLevelCreator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avni-server-api/src/main/java/org/avni/server/importer/batch/csv/creator/AddressLevelCreator.java b/avni-server-api/src/main/java/org/avni/server/importer/batch/csv/creator/AddressLevelCreator.java index 1146fff3d..4174ed43b 100644 --- a/avni-server-api/src/main/java/org/avni/server/importer/batch/csv/creator/AddressLevelCreator.java +++ b/avni-server-api/src/main/java/org/avni/server/importer/batch/csv/creator/AddressLevelCreator.java @@ -5,10 +5,10 @@ import org.avni.server.domain.AddressLevelType; import org.avni.server.domain.AddressLevelTypes; import org.avni.server.importer.batch.model.Row; -import org.jadira.usertype.spi.utils.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; From c08c11e636f3fb19901aaac23e48dcae5664a7bb Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 21 Nov 2024 18:44:19 +0530 Subject: [PATCH 5/5] #813 - fixed ignored test --- .../avni/server/dao/GeneralRepository.java | 23 +++++++++++++++++++ .../server/web/TransactionDataSyncTest.java | 13 +++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java diff --git a/avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java b/avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java new file mode 100644 index 000000000..7d1ad53f6 --- /dev/null +++ b/avni-server-api/src/test/java/org/avni/server/dao/GeneralRepository.java @@ -0,0 +1,23 @@ +package org.avni.server.dao; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.Query; +import org.hibernate.query.sql.internal.NativeQueryImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class GeneralRepository { + private final EntityManager entityManager; + + @Autowired + public GeneralRepository(EntityManager entityManager) { + this.entityManager = entityManager; + } + + public long execute(String sql) { + Query query = entityManager.createNativeQuery(sql); + NativeQueryImpl nativeQuery = (NativeQueryImpl) query; + return nativeQuery.getResultCount(); + } +} diff --git a/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java b/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java index 003d71a7e..3f017c4a2 100644 --- a/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java +++ b/avni-server-api/src/test/java/org/avni/server/web/TransactionDataSyncTest.java @@ -65,6 +65,8 @@ public class TransactionDataSyncTest extends AbstractControllerIntegrationTest { private TestDataSetupService testDataSetupService; @Autowired private UserSubjectAssignmentService userSubjectAssignmentService; + @Autowired + private GeneralRepository generalRepository; private TestDataSetupService.TestOrganisationData organisationData; private TestDataSetupService.TestCatchmentData catchmentData; @@ -74,6 +76,7 @@ public class TransactionDataSyncTest extends AbstractControllerIntegrationTest { private SubjectType subjectTypeWithNoAccess; private Program programWithNoAccess; private GroupRole groupRoleForGroupSubjectTypeWithCatchmentBasedSync; + private GroupRole groupRoleForGroupSubjectTypeWithDirectAssignment; private Concept conceptForAttributeBasedSync; private SubjectType subjectTypeWithSyncAttributeBasedSync; private SubjectType groupSubjectTypeWithSyncAttributeBasedSync; @@ -167,6 +170,13 @@ public void setup() { groupRoleRepository.save(new TestGroupRoleBuilder().withMandatoryFieldsForNewEntity().withGroupSubjectType(groupSubjectTypeForDirectAssignment).withMemberSubjectType(subjectTypeForDirectAssignment).build()); + groupRoleForGroupSubjectTypeWithDirectAssignment = groupRoleRepository.save( + new TestGroupRoleBuilder() + .withMandatoryFieldsForNewEntity() + .withGroupSubjectType(groupSubjectTypeForDirectAssignment) + .withMemberSubjectType(subjectTypeForDirectAssignment) + .build()); + testGroupService.giveViewSubjectPrivilegeTo(organisationData.getGroup(), subjectTypeWithCatchmentBasedSync, subjectTypeForDirectAssignment, subjectTypeWithSyncAttributeBasedSync, groupSubjectTypeWithSyncAttributeBasedSync, groupSubjectTypeForCatchmentBasedSync, groupSubjectTypeForDirectAssignment); testGroupService.giveViewProgramPrivilegeTo(organisationData.getGroup(), subjectTypeWithCatchmentBasedSync, programWithCatchmentBasedSync); testGroupService.giveViewProgramPrivilegeTo(organisationData.getGroup(), subjectTypeForDirectAssignment, programForDirectAssignment); @@ -175,7 +185,6 @@ public void setup() { @Test @Transactional - @Ignore public void sync() throws Exception { // Catchment tx entities Individual inTheCatchment = testSubjectService.save(new SubjectBuilder().withMandatoryFieldsForNewEntity().withSubjectType(subjectTypeWithCatchmentBasedSync).withLocation(catchmentData.getAddressLevel1()).build()); @@ -282,7 +291,7 @@ public void sync() throws Exception { assertTrue(hasEntity(enrolmentAssignedNow, enrolments)); // Group Subject Individual assignedGroupSubject = testSubjectService.save(new SubjectBuilder().withMandatoryFieldsForNewEntity().withSubjectType(groupSubjectTypeForDirectAssignment).withLocation(catchmentData.getAddressLevel1()).build()); - GroupSubject groupSubjectInDirectAssignment = testGroupSubjectService.save(new TestGroupSubjectBuilder().withGroupRole(groupRoleForGroupSubjectTypeWithCatchmentBasedSync).withMember(assigned).withGroup(assignedGroupSubject).build()); + GroupSubject groupSubjectInDirectAssignment = testGroupSubjectService.save(new TestGroupSubjectBuilder().withGroupRole(groupRoleForGroupSubjectTypeWithDirectAssignment).withMember(assigned).withGroup(assignedGroupSubject).build()); userSubjectAssignmentService.assignSubjects(organisationData.getUser(), Collections.singletonList(assignedGroupSubject), false); groupSubjects = getGroupSubjects(groupSubjectTypeForDirectAssignment);