diff --git a/Makefile b/Makefile index 2d247eaa6..3997a05ad 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 593c69c4b..e3414cf20 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' @@ -49,7 +48,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}") @@ -62,9 +61,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" @@ -74,15 +70,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' @@ -90,13 +82,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/messaging/domain/MessageRequest.java b/avni-server-api/src/main/java/org/avni/messaging/domain/MessageRequest.java index 53b9e6ddd..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 @@ -3,11 +3,8 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import org.avni.server.domain.OrganisationAwareEntity; -import org.avni.server.util.DateTimeUtil; import org.joda.time.DateTime; -import java.time.Instant; - @Entity @Table(name = "message_request_queue") public class MessageRequest extends OrganisationAwareEntity { @@ -30,7 +27,7 @@ public class MessageRequest extends OrganisationAwareEntity { @Column @NotNull - private Instant scheduledDateTime; + private DateTime scheduledDateTime; @Column @NotNull @@ -38,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; @@ -53,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) { @@ -61,7 +58,7 @@ public void setDeliveryStatus(MessageDeliveryStatus deliveryStatus) { } public void setDeliveredDateTime(DateTime deliveredDateTime) { - this.deliveredDateTime = DateTimeUtil.toInstant(deliveredDateTime); + this.deliveredDateTime = deliveredDateTime; } public MessageRequest() { @@ -71,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() { @@ -100,7 +97,7 @@ public Long getEntityId() { } public DateTime getScheduledDateTime() { - return DateTimeUtil.toJodaDateTime(scheduledDateTime); + return scheduledDateTime; } public MessageDeliveryStatus getDeliveryStatus() { @@ -108,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 f3d8b6fce..97a4f23cf 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 @@ -9,20 +9,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 1c30501a6..89e745a23 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 @@ -3,12 +3,12 @@ import jakarta.persistence.criteria.*; 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 java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -47,7 +47,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<>(); @@ -62,10 +62,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<>(); @@ -84,9 +80,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 ce6310339..53aa7469b 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 @@ -11,6 +11,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; +import jakarta.persistence.criteria.*; + import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -21,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 55375f406..2852108aa 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 @@ -11,7 +11,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -21,7 +22,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 a077ef3e6..c33275b7c 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 @@ -13,7 +13,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.Calendar; import java.util.Date; import java.util.List; @@ -23,10 +24,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) { @@ -82,13 +83,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 52c645528..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,7 @@ import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.format.annotation.DateTimeFormat; -import java.time.Instant; +import java.util.Date; /* * This is a marker interface for all the repositories that are used to fetch entities with old endpoints that do not serve new data after configured date. @@ -20,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 80fce3f50..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,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; +import java.util.Date; import java.util.List; @Repository @@ -41,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 e3992ed11..3a540c8e1 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 @@ -16,7 +16,8 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Repository; -import java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -27,8 +28,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) { @@ -75,7 +76,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 " + @@ -83,7 +84,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 f70815a05..a225fcc5b 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,16 +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 findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(User currentUser, Instant lastModifiedDateTime, String deviceId, Pageable pageable); + Page findByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, String deviceId, Pageable pageable); - Slice findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(User currentUser, Instant lastModifiedDateTime, String deviceId, Pageable pageable); + Slice findSliceByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEqualsOrderByAssignmentOrderAsc(User currentUser, Date lastModifiedDateTime, String deviceId, Pageable pageable); Integer countIdentifierAssignmentByIdentifierSourceEqualsAndAssignedToEqualsAndIndividualIsNullAndProgramEnrolmentIsNullAndUsedIsFalseAndDeviceIdEquals(IdentifierSource identifierSource, User assignedTo, String deviceId); - boolean existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEquals(User currentUser, Instant lastModifiedDateTime, String deviceId); + boolean existsByAssignedToAndLastModifiedDateTimeGreaterThanAndIsVoidedFalseAndIndividualIsNullAndProgramEnrolmentIsNullAndDeviceIdEquals(User currentUser, Date lastModifiedDateTime, String deviceId); } 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 d750cf15d..8dbb321a0 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,6 @@ 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; import org.springframework.data.domain.Page; @@ -27,13 +28,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 d508e1abf..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 @@ -6,6 +6,8 @@ import org.avni.server.framework.security.UserContextHolder; import org.avni.server.projection.IndividualWebProjection; import org.avni.server.util.S; +import org.joda.time.DateTime; +import org.joda.time.LocalDate; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -15,7 +17,6 @@ import org.springframework.stereotype.Repository; import org.springframework.util.StringUtils; -import java.time.Instant; import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -106,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 " + @@ -123,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 " + @@ -131,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 271877a38..3ae1f6670 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,7 @@ 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; @Repository @@ -29,8 +29,8 @@ public interface LocationMappingRepository extends ReferenceDataRepository getSyncResults( long catchmentId, - Instant lastModifiedDateTime, - Instant now, + Date lastModifiedDateTime, + Date now, long organisationId, Pageable pageable ); @@ -43,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 6da75643f..80dad3f8f 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 @@ -19,10 +19,10 @@ import org.springframework.stereotype.Repository; import org.springframework.util.StringUtils; -import java.time.Instant; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import jakarta.persistence.QueryHint; +import jakarta.validation.constraints.NotNull; + +import java.util.*; @Repository @RepositoryRestResource(collectionResourceRel = "locations", path = "locations") @@ -45,7 +45,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" + @@ -54,7 +54,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); @@ -99,20 +99,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 66fe2a8bb..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,7 @@ 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; @Repository @@ -18,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 d9abb99ab..716b052a7 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 @@ -20,7 +20,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.NoRepositoryBean; -import java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -66,7 +67,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])); }; @@ -84,7 +85,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])); }; } @@ -135,9 +136,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 76abbd99a..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,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; +import java.util.Date; import java.util.List; @Repository @@ -20,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 b0ed0a533..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,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; +import java.util.Date; import java.util.List; @Repository @@ -19,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 a079f1f37..3eff684ac 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; @Repository @@ -19,8 +18,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 82606231a..ece979e00 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 @@ -17,7 +17,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; +import java.util.Date; import java.util.List; import java.util.stream.Stream; @@ -35,14 +35,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 " + @@ -56,7 +56,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 " + @@ -66,11 +66,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); @@ -86,8 +86,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 50d52d116..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,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.stereotype.Repository; -import java.time.Instant; +import java.util.Date; @Repository @RepositoryRestResource(collectionResourceRel = "ruleDependency", path = "ruleDependency") @@ -18,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"); @@ -29,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 b29f7f0e9..99caab747 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 @@ -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.Set; @@ -23,11 +22,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 188c6ce3a..e1bb31950 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 @@ -6,7 +6,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; -import java.time.Instant; import java.util.List; @Repository @@ -16,7 +15,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 b3e914a21..70f1e0cd2 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,5 +1,7 @@ package org.avni.server.dao; +import java.util.Date; +import org.avni.server.domain.User; import org.avni.server.domain.Group; import org.avni.server.domain.User; import org.avni.server.domain.UserGroup; @@ -21,8 +23,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) { @@ -46,7 +48,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 467ccda3f..6227bec8b 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 @@ -16,7 +16,8 @@ import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; +import jakarta.persistence.*; + import java.util.List; import java.util.Optional; @@ -61,7 +62,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 dc318f8ad..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,7 @@ 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; @Repository @@ -22,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 96a47fd2d..20d5b0de9 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 @@ -16,7 +16,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -27,7 +28,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 f355048de..5ff2a4de4 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 @@ -17,7 +17,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -import java.time.Instant; +import jakarta.persistence.criteria.*; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -26,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 2540471ac..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,14 +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 f562a16fe..278ea5436 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 @@ -4,10 +4,10 @@ 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; @@ -25,20 +25,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) @@ -70,14 +74,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() { @@ -97,23 +101,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() { @@ -121,7 +125,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 1c3de2ea9..f9b9b1ad4 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,14 +1,16 @@ package org.avni.server.domain; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; +import org.avni.server.util.DateTimeUtil; +import org.hibernate.annotations.BatchSize; + import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; -import java.time.Instant; - @Entity @BatchSize(size = 100) public class ApprovalStatus { @@ -27,9 +29,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; @@ -64,19 +68,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 9476a4150..d95812977 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 @@ -3,11 +3,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import org.avni.server.util.DateTimeUtil; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + import java.util.ArrayList; import java.util.List; @@ -31,7 +33,8 @@ public class Checklist extends OrganisationAwareEntity { @NotNull @Column - private Instant baseDate; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime baseDate; public ChecklistDetail getChecklistDetail() { return checklistDetail; @@ -50,11 +53,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 6803034c4..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,15 +1,15 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; +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; import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @Table(name = "checklist_item") @@ -17,7 +17,8 @@ @BatchSize(size = 100) public class ChecklistItem extends OrganisationAwareEntity { @Column - private Instant completionDate; + @Convert(converter = JodaDateTimeConverter.class) + private DateTime completionDate; @Column @Type(value = ObservationCollectionUserType.class) @@ -33,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 af92c8f1f..d75dc9abb 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 @@ -4,11 +4,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import org.avni.server.util.DateTimeUtil; +import org.avni.server.framework.hibernate.JodaDateTimeConverter; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -25,10 +27,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<>(); @@ -42,19 +46,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 ab81aca79..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,13 +1,13 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; +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; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @BatchSize(size = 100) @@ -41,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; @@ -103,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 8af373b3a..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,13 +2,13 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; +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; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @Table(name = "group_subject") @@ -32,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; @@ -74,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 f94033a81..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 @@ -7,15 +7,14 @@ 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 java.time.Instant; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -43,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; @@ -61,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") @@ -96,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() { @@ -173,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 dacb5307f..feb791577 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,7 +8,9 @@ import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.Column; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @Table(name = "news") @@ -16,7 +18,7 @@ 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 +33,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 083d14c44..ea838c136 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 @@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotNull; 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.Point; import org.avni.server.geo.PointType; @@ -14,7 +15,6 @@ import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; @@ -42,14 +42,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 @@ -126,11 +128,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() { @@ -142,11 +144,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/StandardReportCardType.java b/avni-server-api/src/main/java/org/avni/server/domain/StandardReportCardType.java index c472ad816..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,12 +1,12 @@ package org.avni.server.domain; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; +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; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @BatchSize(size = 100) @@ -27,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) @@ -76,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 45a0b27f4..3a871869f 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 @@ -3,12 +3,14 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; 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; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @Table(name = "sync_telemetry") @@ -28,10 +30,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; @@ -82,19 +86,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 7dba9c4fe..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,12 +1,12 @@ package org.avni.server.domain; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; +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; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @Table(name = "video_telemetric") @@ -24,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 @@ -43,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; @@ -62,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() { @@ -102,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 f1e4ff5d1..a5676ef0a 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,19 +1,13 @@ package org.avni.server.domain.individualRelationship; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; -import org.avni.server.domain.Individual; -import org.avni.server.domain.ObservationCollection; -import org.avni.server.domain.OrganisationAwareEntity; +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; import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import java.time.Instant; - @Entity @Table(name = "individual_relationship") @JsonIgnoreProperties({"individuala", "individualB"}) @@ -36,10 +30,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) @@ -70,19 +66,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 072642c94..a242a8e61 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 @@ -11,7 +11,8 @@ import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity(name = "subject_program_eligibility") public class SubjectProgramEligibility extends OrganisationAwareEntity { @@ -29,7 +30,7 @@ public class SubjectProgramEligibility extends OrganisationAwareEntity { private boolean isEligible; @Column - private Instant checkDate; + private DateTime checkDate; @Column @Type(value = ObservationCollectionUserType.class) @@ -60,11 +61,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 375a8975a..8be045b33 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 @@ -6,13 +6,15 @@ 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; import org.hibernate.annotations.Type; import org.joda.time.DateTime; -import java.time.Instant; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; @Entity @Table(name = "task") @@ -33,10 +35,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") @@ -88,19 +92,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/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/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/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)); */ } + + } 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 cddba68a4..2a4dd5b97 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 @@ -17,7 +17,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/IdentifierSourceService.java b/avni-server-api/src/main/java/org/avni/server/service/IdentifierSourceService.java index b9f8f2975..450c429f6 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 @@ -61,7 +61,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 515057db5..f91e27547 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 @@ -127,7 +127,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 6c50634c9..a3a8c6367 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 @@ -62,6 +62,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 d2f6ee433..12dffd088 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 @@ -32,6 +32,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 518353096..f669e28f2 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 @@ -18,6 +18,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 8b6335a75..a140a0b9d 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 @@ -125,7 +125,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 86c6b7aa4..8a7563a16 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 @@ -127,7 +127,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 b1c07f767..be33d8dc4 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 e833b3113..745422e56 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 b6e8ea9ca..aa273ba06 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 134e3f96b..abdc1fda5 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 @@ -103,7 +103,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 88629233d..71a84afe1 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 547473f19..42aa0d3f7 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 ec5e58415..8c4f9b777 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 @@ -60,12 +60,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/main/resources/application.properties b/avni-server-api/src/main/resources/application.properties index 9fddb7c34..6d4643bfd 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/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/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()); - } } 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 606fd0564..949ee803d 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 @@ -67,6 +67,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; @@ -76,6 +78,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; @@ -169,6 +172,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); @@ -177,7 +187,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()); @@ -284,7 +293,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); diff --git a/avni-server-api/src/test/resources/application.properties b/avni-server-api/src/test/resources/application.properties index 78388e6ec..b0f1b7515 100644 --- a/avni-server-api/src/test/resources/application.properties +++ b/avni-server-api/src/test/resources/application.properties @@ -30,8 +30,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