Skip to content

Commit

Permalink
#813 - changed all joda date time types to Instant
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 5, 2024
1 parent b4d93c5 commit 31c30dc
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Comment> comments = new HashSet<>();
Expand All @@ -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<Comment> getComments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
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;
import org.avni.server.geo.Point;

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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -124,11 +127,11 @@ public void setProgramEncounters(Set<ProgramEncounter> 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

import java.time.Instant;

@Entity
@Table(name = "sync_telemetry")
@BatchSize(size = 100)
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 31c30dc

Please sign in to comment.