From 31c30dc81391ecf1e2a4f83da8a224b075d6ca8b Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Tue, 5 Nov 2024 16:53:50 +0530 Subject: [PATCH] #813 - changed all joda date time types to Instant --- .../avni/server/domain/AbstractEncounter.java | 21 +++++++++++-------- .../org/avni/server/domain/CommentThread.java | 15 +++++++------ .../org/avni/server/domain/GroupSubject.java | 15 +++++++------ .../avni/server/domain/ProgramEnrolment.java | 9 +++++--- .../server/domain/RuleFailureTelemetry.java | 19 +++++++++-------- .../org/avni/server/domain/SyncTelemetry.java | 15 +++++++------ .../avni/server/domain/VideoTelemetric.java | 9 +++++--- .../IndividualRelationship.java | 15 +++++++------ .../program/SubjectProgramEligibility.java | 9 +++++--- .../org/avni/server/domain/task/Task.java | 15 +++++++------ 10 files changed, 85 insertions(+), 57 deletions(-) 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 7ebe662b1..5fb71c95e 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 @@ -5,11 +5,14 @@ import org.avni.server.framework.hibernate.ObservationCollectionUserType; import org.avni.server.geo.Point; import org.avni.server.geo.PointType; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.Type; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; + +import java.time.Instant; import java.util.Objects; @MappedSuperclass @@ -23,13 +26,13 @@ public class AbstractEncounter extends SyncAttributeEntity { private EncounterType encounterType; @Column - private DateTime earliestVisitDateTime; + private Instant earliestVisitDateTime; @Column - private DateTime maxVisitDateTime; + private Instant maxVisitDateTime; @Column(name = ColumnNames.EncounterDateTime) - private DateTime encounterDateTime; + private Instant encounterDateTime; @Column(name = ColumnNames.EncounterObservations) @Type(value = ObservationCollectionUserType.class) @@ -68,14 +71,14 @@ public void setEncounterType(EncounterType encounterType) { } public DateTime getEncounterDateTime() { - return encounterDateTime; + return DateTimeUtil.toJodaDateTime(encounterDateTime); } public void setEncounterDateTime(DateTime encounterDateTime, User currentUser) { if (this.encounterDateTime == null && encounterDateTime != null) { this.filledBy = currentUser; } - this.encounterDateTime = encounterDateTime; + this.encounterDateTime = DateTimeUtil.toInstant(encounterDateTime); } public ObservationCollection getObservations() { @@ -95,19 +98,19 @@ public void setName(String name) { } public DateTime getEarliestVisitDateTime() { - return earliestVisitDateTime; + return DateTimeUtil.toJodaDateTime(earliestVisitDateTime); } public void setEarliestVisitDateTime(DateTime earliestVisitDateTime) { - this.earliestVisitDateTime = earliestVisitDateTime; + this.earliestVisitDateTime = DateTimeUtil.toInstant(earliestVisitDateTime); } public DateTime getMaxVisitDateTime() { - return maxVisitDateTime; + return DateTimeUtil.toJodaDateTime(maxVisitDateTime); } public void setMaxVisitDateTime(DateTime maxVisitDateTime) { - this.maxVisitDateTime = maxVisitDateTime; + this.maxVisitDateTime = DateTimeUtil.toInstant(maxVisitDateTime); } public DateTime getCancelDateTime() { 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 e07bdc3ee..8518a5bb6 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/CommentThread.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/CommentThread.java @@ -2,11 +2,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; + +import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -23,10 +26,10 @@ public class CommentThread extends OrganisationAwareEntity { @Column @NotNull - private DateTime openDateTime; + private Instant openDateTime; @Column - private DateTime resolvedDateTime; + private Instant resolvedDateTime; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "commentThread") private Set comments = new HashSet<>(); @@ -40,19 +43,19 @@ public void setStatus(CommentThreadStatus status) { } public DateTime getOpenDateTime() { - return openDateTime; + return DateTimeUtil.toJodaDateTime(openDateTime); } public void setOpenDateTime(DateTime openDateTime) { - this.openDateTime = openDateTime; + this.openDateTime = DateTimeUtil.toInstant(openDateTime); } public DateTime getResolvedDateTime() { - return resolvedDateTime; + return DateTimeUtil.toJodaDateTime(resolvedDateTime); } public void setResolvedDateTime(DateTime resolvedDateTime) { - this.resolvedDateTime = resolvedDateTime; + this.resolvedDateTime = DateTimeUtil.toInstant(resolvedDateTime); } public Set getComments() { 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 b9ca17683..11c47bc96 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,12 +2,15 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.Instant; + @Entity @Table(name = "group_subject") @JsonIgnoreProperties({"groupSubject", "memberSubject", "groupRole"}) @@ -30,10 +33,10 @@ public class GroupSubject extends OrganisationAwareEntity { private GroupRole groupRole; @Column - private DateTime membershipStartDate; + private Instant membershipStartDate; @Column - private DateTime membershipEndDate; + private Instant membershipEndDate; @Column(name = "member_subject_address_id") private Long memberSubjectAddressId; @@ -72,19 +75,19 @@ public void setGroupRole(GroupRole groupRole) { } public DateTime getMembershipStartDate() { - return membershipStartDate; + return DateTimeUtil.toJodaDateTime(membershipStartDate); } public void setMembershipStartDate(DateTime membershipStartDate) { - this.membershipStartDate = membershipStartDate; + this.membershipStartDate = DateTimeUtil.toInstant(membershipStartDate); } public DateTime getMembershipEndDate() { - return membershipEndDate; + return DateTimeUtil.toJodaDateTime(membershipEndDate); } public void setMembershipEndDate(DateTime membershipEndDate) { - this.membershipEndDate = membershipEndDate; + this.membershipEndDate = DateTimeUtil.toInstant(membershipEndDate); } public String getGroupSubjectUUID() { 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 c0a9df222..bff86951a 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 org.avni.server.common.dbSchema.TableNames; import org.avni.server.framework.hibernate.ObservationCollectionUserType; 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.DateTime; @@ -13,6 +14,8 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; + +import java.time.Instant; import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; @@ -40,7 +43,7 @@ public class ProgramEnrolment extends SyncAttributeEntity implements Messageable @Column(name = ColumnNames.EnrolmentDateTime) @NotNull - private DateTime enrolmentDateTime; + private Instant enrolmentDateTime; @Column(name = ProgramEnrolmentObservations) @Type(value = ObservationCollectionUserType.class) @@ -124,11 +127,11 @@ public void setProgramEncounters(Set programEncounters) { } public DateTime getEnrolmentDateTime() { - return enrolmentDateTime; + return DateTimeUtil.toJodaDateTime(enrolmentDateTime); } public void setEnrolmentDateTime(DateTime enrolmentDateTime) { - this.enrolmentDateTime = enrolmentDateTime; + this.enrolmentDateTime = DateTimeUtil.toInstant(enrolmentDateTime); } public ObservationCollection getObservations() { diff --git a/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java b/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java index 98e265756..2c346f585 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/RuleFailureTelemetry.java @@ -1,9 +1,12 @@ package org.avni.server.domain; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; import org.avni.server.domain.enums.ruleFailure.AppType; import org.avni.server.domain.enums.ruleFailure.EntityType; import org.avni.server.domain.enums.ruleFailure.SourceType; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; @@ -14,9 +17,7 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - +import java.time.Instant; import java.util.Date; @Entity @@ -65,10 +66,10 @@ public class RuleFailureTelemetry { private String stacktrace; @Column - private DateTime closedDateTime; + private Instant closedDateTime; @Column - private DateTime errorDateTime; + private Instant errorDateTime; @Column private Boolean isClosed; @@ -214,19 +215,19 @@ public void setStacktrace(String stacktrace) { } public DateTime getClosedDateTime() { - return closedDateTime; + return DateTimeUtil.toJodaDateTime(closedDateTime); } public void setClosedDateTime(DateTime closedDateTime) { - this.closedDateTime = closedDateTime; + this.closedDateTime = DateTimeUtil.toInstant(closedDateTime); } public DateTime getErrorDateTime() { - return errorDateTime; + return DateTimeUtil.toJodaDateTime(errorDateTime); } public void setErrorDateTime(DateTime errorDateTime) { - this.errorDateTime = errorDateTime; + this.errorDateTime = DateTimeUtil.toInstant(errorDateTime); } public Boolean getClosed() { 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 34bcaca51..8299607d7 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/SyncTelemetry.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/SyncTelemetry.java @@ -1,6 +1,7 @@ package org.avni.server.domain; import org.avni.server.framework.hibernate.JSONObjectUserType; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Type; import org.joda.time.DateTime; @@ -8,6 +9,8 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.Instant; + @Entity @Table(name = "sync_telemetry") @BatchSize(size = 100) @@ -26,10 +29,10 @@ public class SyncTelemetry extends OrganisationAwareEntity{ private JsonObject entityStatus; @Column - private DateTime syncStartTime; + private Instant syncStartTime; @Column - private DateTime syncEndTime; + private Instant syncEndTime; @Column private String appVersion; @@ -80,19 +83,19 @@ public void setEntityStatus(JsonObject entityStatus) { } public DateTime getSyncStartTime() { - return syncStartTime; + return DateTimeUtil.toJodaDateTime(syncStartTime); } public void setSyncStartTime(DateTime syncStartTime) { - this.syncStartTime = syncStartTime; + this.syncStartTime = DateTimeUtil.toInstant(syncStartTime); } public DateTime getSyncEndTime() { - return syncEndTime; + return DateTimeUtil.toJodaDateTime(syncEndTime); } public void setSyncEndTime(DateTime syncEndTime) { - this.syncEndTime = syncEndTime; + this.syncEndTime = DateTimeUtil.toInstant(syncEndTime); } public String getAppVersion() { 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 686a7e154..b702eddc2 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,11 +1,14 @@ package org.avni.server.domain; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.Instant; + @Entity @Table(name = "video_telemetric") @BatchSize(size = 100) @@ -22,7 +25,7 @@ public class VideoTelemetric extends CHSBaseEntity { private Double videoEndTime; @Column(name = "player_close_time") - private DateTime playerCloseTime; + private Instant playerCloseTime; @Column(name = "player_open_time") private DateTime playerOpenTime; @@ -60,11 +63,11 @@ public void setVideoEndTime(Double videoEndTime) { } public DateTime getPlayerCloseTime() { - return playerCloseTime; + return DateTimeUtil.toJodaDateTime(playerCloseTime); } public void setPlayerCloseTime(DateTime playerCloseTime) { - this.playerCloseTime = playerCloseTime; + this.playerCloseTime = DateTimeUtil.toInstant(playerCloseTime); } public DateTime getPlayerOpenTime() { 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 7af252961..89775a07c 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 @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 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; @@ -12,6 +13,8 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.Instant; + @Entity @Table(name = "individual_relationship") @JsonIgnoreProperties({"individuala", "individualB"}) @@ -34,10 +37,10 @@ public class IndividualRelationship extends OrganisationAwareEntity { private Individual individualB; @Column - private DateTime enterDateTime; + private Instant enterDateTime; @Column - private DateTime exitDateTime; + private Instant exitDateTime; @Column @Type(value = ObservationCollectionUserType.class) @@ -68,19 +71,19 @@ public void setIndividualB(Individual individualB) { } public DateTime getEnterDateTime() { - return enterDateTime; + return DateTimeUtil.toJodaDateTime(enterDateTime); } public void setEnterDateTime(DateTime enterDateTime) { - this.enterDateTime = enterDateTime; + this.enterDateTime = DateTimeUtil.toInstant(enterDateTime); } public DateTime getExitDateTime() { - return exitDateTime; + return DateTimeUtil.toJodaDateTime(exitDateTime); } public void setExitDateTime(DateTime exitDateTime) { - this.exitDateTime = exitDateTime; + this.exitDateTime = DateTimeUtil.toInstant(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 4875c6d44..2298fce08 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 @@ -5,12 +5,15 @@ import org.avni.server.domain.OrganisationAwareEntity; import org.avni.server.domain.Program; import org.avni.server.framework.hibernate.ObservationCollectionUserType; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.Type; import org.joda.time.DateTime; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.Instant; + @Entity(name = "subject_program_eligibility") public class SubjectProgramEligibility extends OrganisationAwareEntity { @ManyToOne(targetEntity = Individual.class, fetch = FetchType.LAZY) @@ -27,7 +30,7 @@ public class SubjectProgramEligibility extends OrganisationAwareEntity { private boolean isEligible; @Column - private DateTime checkDate; + private Instant checkDate; @Column @Type(value = ObservationCollectionUserType.class) @@ -58,11 +61,11 @@ public void setEligible(boolean eligible) { } public DateTime getCheckDate() { - return checkDate; + return DateTimeUtil.toJodaDateTime(checkDate); } public void setCheckDate(DateTime checkDate) { - this.checkDate = checkDate; + this.checkDate = DateTimeUtil.toInstant(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 c18e20ff5..304cf6cb8 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 @@ -5,6 +5,7 @@ import org.avni.server.domain.OrganisationAwareEntity; import org.avni.server.domain.User; 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; @@ -12,6 +13,8 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; +import java.time.Instant; + @Entity @Table(name = "task") @BatchSize(size = 100) @@ -31,10 +34,10 @@ public class Task extends OrganisationAwareEntity { private TaskStatus taskStatus; @Column - private DateTime scheduledOn; + private Instant scheduledOn; @Column - private DateTime completedOn; + private Instant completedOn; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "assigned_user_id") @@ -86,19 +89,19 @@ public void updateTaskStatus(TaskStatus taskStatus) { } public DateTime getScheduledOn() { - return scheduledOn; + return DateTimeUtil.toJodaDateTime(scheduledOn); } public void setScheduledOn(DateTime scheduledOn) { - this.scheduledOn = scheduledOn; + this.scheduledOn = DateTimeUtil.toInstant(scheduledOn); } public DateTime getCompletedOn() { - return completedOn; + return DateTimeUtil.toJodaDateTime(completedOn); } public void setCompletedOn(DateTime completedOn) { - this.completedOn = completedOn; + this.completedOn = DateTimeUtil.toInstant(completedOn); } public User getAssignedTo() {