Skip to content

Commit

Permalink
#813 - changed all joda date types to Instant
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 5, 2024
1 parent 9779b52 commit b4d93c5
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

@Repository
public interface ImplementationRepository extends AvniCrudRepository<Organisation, Long> {
@Procedure(value = "create_view")
@Query(value = "select create_view(:schemaName, :viewName, :sqlQuery)", nativeQuery = true)
void createView(String schemaName, String viewName, String sqlQuery);

@Query(value = "select viewname, definition from pg_views where schemaname = :schemaName", nativeQuery = true)
List<ReportingViewProjection> getAllViewsInSchema(String schemaName);

@Procedure(value = "drop_view")
@Query(value = "select drop_view(:viewName, :schemaName)", nativeQuery = true)
void dropView(String viewName, String schemaName);

@Procedure(value = "create_db_user")
@Query(value = "select create_db_user(:name, :pass)", nativeQuery = true)
void createDBUser(String name, String pass);

default void createDBUser(Organisation organisation) {
this.createDBUser(organisation.getDbUser(), "password");
}

@Procedure(value = "create_implementation_schema")
@Query(value = "select create_implementation_schema(:schemaName, :dbUser)", nativeQuery = true)
void createImplementationSchema(String schemaName, String dbUser);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.avni.server.domain;


import org.avni.server.util.DateTimeUtil;
import org.hibernate.annotations.BatchSize;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import org.joda.time.DateTime;

import java.time.Instant;

@Entity
@BatchSize(size = 100)
public class ApprovalStatus {
Expand All @@ -25,9 +28,9 @@ public class ApprovalStatus {
@Column
private boolean isVoided;
@Column
private DateTime createdDateTime;
private Instant createdDateTime;
@Column
private DateTime lastModifiedDateTime;
private Instant lastModifiedDateTime;

public Long getId() {
return id;
Expand Down Expand Up @@ -62,19 +65,19 @@ public void setVoided(boolean voided) {
}

public DateTime getCreatedDateTime() {
return createdDateTime;
return DateTimeUtil.toJodaDateTime(createdDateTime);
}

public void setCreatedDateTime(DateTime createdDateTime) {
this.createdDateTime = createdDateTime;
this.createdDateTime = DateTimeUtil.toInstant(createdDateTime);
}

public DateTime getLastModifiedDateTime() {
return lastModifiedDateTime;
return DateTimeUtil.toJodaDateTime(lastModifiedDateTime);
}

public void setLastModifiedDateTime(DateTime lastModifiedDateTime) {
this.lastModifiedDateTime = lastModifiedDateTime;
this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime);
}

public enum Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import org.avni.server.framework.security.UserContextHolder;
import org.joda.time.DateTime;
Expand All @@ -11,7 +12,7 @@
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import java.time.Instant;
import java.util.Date;

@MappedSuperclass
Expand All @@ -27,7 +28,7 @@ public class CHSEntity extends CHSBaseEntity implements Auditable {

@CreatedDate
@NotNull
private Date createdDateTime;
private Instant createdDateTime;

@JsonIgnore
@JoinColumn(name = "last_modified_by_id")
Expand All @@ -38,7 +39,7 @@ public class CHSEntity extends CHSBaseEntity implements Auditable {

@LastModifiedDate
@NotNull
private Date lastModifiedDateTime;
private Instant lastModifiedDateTime;

@JsonIgnore
public User getCreatedBy() {
Expand All @@ -54,7 +55,7 @@ public DateTime getCreatedDateTime() {
}

public void setCreatedDateTime(DateTime createdDateTime) {
this.createdDateTime = createdDateTime.toDate();
this.createdDateTime = createdDateTime.toDate().toInstant();
}

@JsonIgnore
Expand All @@ -75,7 +76,7 @@ private DateTime toJodaDateTime() {
}

public void setLastModifiedDateTime(DateTime lastModifiedDateTime) {
this.lastModifiedDateTime = lastModifiedDateTime.toDate();
this.lastModifiedDateTime = lastModifiedDateTime.toDate().toInstant();
}

@Column(name = "version")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.avni.server.domain;

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.ArrayList;
import java.util.List;

Expand All @@ -29,7 +32,7 @@ public class Checklist extends OrganisationAwareEntity {

@NotNull
@Column
private DateTime baseDate;
private Instant baseDate;

public ChecklistDetail getChecklistDetail() {
return checklistDetail;
Expand All @@ -48,11 +51,11 @@ public void setProgramEnrolment(ProgramEnrolment programEnrolment) {
}

public DateTime getBaseDate() {
return baseDate;
return DateTimeUtil.toJodaDateTime(baseDate);
}

public void setBaseDate(DateTime baseDate) {
this.baseDate = baseDate;
this.baseDate = DateTimeUtil.toInstant(baseDate);
}

public List<ChecklistItem> getItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import org.avni.server.framework.hibernate.ObservationCollectionUserType;
import org.avni.server.geo.Point;
import org.avni.server.geo.PointType;
import org.avni.server.util.DateTimeUtil;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;

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

import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -41,7 +44,7 @@ public class Individual extends SyncAttributeEntity implements MessageableEntity

private String profilePicture;

private LocalDate dateOfBirth;
private Instant dateOfBirth;

private boolean dateOfBirthVerified;

Expand All @@ -59,7 +62,7 @@ public class Individual extends SyncAttributeEntity implements MessageableEntity

@NotNull
@Column(name = ColumnNames.RegistrationDate)
private LocalDate registrationDate;
private Instant registrationDate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "gender_id")
Expand Down Expand Up @@ -94,20 +97,20 @@ public static Individual create(String firstName, String lastName, String profil
individual.firstName = firstName;
individual.lastName = lastName;
individual.profilePicture = profilePicture;
individual.dateOfBirth = dateOfBirth;
individual.dateOfBirth = DateTimeUtil.toInstant(dateOfBirth);
individual.dateOfBirthVerified = dateOfBirthVerified;
individual.gender = gender;
individual.addressLevel = address;
individual.registrationDate = registrationDate;
individual.registrationDate = DateTimeUtil.toInstant(registrationDate);
return individual;
}

public LocalDate getDateOfBirth() {
return dateOfBirth;
return DateTimeUtil.toJodaDate(dateOfBirth);
}

public void setDateOfBirth(LocalDate dateOfBirth) {
this.dateOfBirth = dateOfBirth;
this.dateOfBirth = DateTimeUtil.toInstant(dateOfBirth);
}

public boolean isDateOfBirthVerified() {
Expand Down Expand Up @@ -171,11 +174,11 @@ public void setObservations(ObservationCollection observations) {
}

public LocalDate getRegistrationDate() {
return registrationDate;
return DateTimeUtil.toJodaDate(registrationDate);
}

public void setRegistrationDate(LocalDate registrationDate) {
this.registrationDate = registrationDate;
this.registrationDate = DateTimeUtil.toInstant(registrationDate);
}

public void addEnrolment(ProgramEnrolment programEnrolment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package org.avni.server.domain;

import org.avni.server.util.DateTimeUtil;
import org.hibernate.annotations.BatchSize;
import org.joda.time.DateTime;

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

import java.time.Instant;

@Entity
@Table(name = "news")
@BatchSize(size = 100)
public class News extends OrganisationAwareEntity {
@NotNull
private String title;
private DateTime publishedDate;
private Instant publishedDate;
private String heroImage;
private String content;
@Column(name = "contenthtml")
Expand All @@ -28,11 +31,11 @@ public void setTitle(String title) {
}

public DateTime getPublishedDate() {
return publishedDate;
return DateTimeUtil.toJodaDateTime(publishedDate);
}

public void setPublishedDate(DateTime publishedDate) {
this.publishedDate = publishedDate;
this.publishedDate = DateTimeUtil.toInstant(publishedDate);
}

public String getHeroImage() {
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
@BatchSize(size = 100)
public class StandardReportCardType {
Expand All @@ -25,9 +28,9 @@ public class StandardReportCardType {
@Column
private boolean isVoided;
@Column
private DateTime createdDateTime;
private Instant createdDateTime;
@Column
private DateTime lastModifiedDateTime;
private Instant lastModifiedDateTime;
@Column
@NotNull
@Enumerated(EnumType.STRING)
Expand Down Expand Up @@ -74,19 +77,19 @@ public void setVoided(boolean voided) {
}

public DateTime getCreatedDateTime() {
return createdDateTime;
return DateTimeUtil.toJodaDateTime(createdDateTime);
}

public void setCreatedDateTime(DateTime createdDateTime) {
this.createdDateTime = createdDateTime;
this.createdDateTime = DateTimeUtil.toInstant(createdDateTime);
}

public DateTime getLastModifiedDateTime() {
return lastModifiedDateTime;
return DateTimeUtil.toJodaDateTime(lastModifiedDateTime);
}

public void setLastModifiedDateTime(DateTime lastModifiedDateTime) {
this.lastModifiedDateTime = lastModifiedDateTime;
this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime);
}

public @NotNull StandardReportCardTypeType getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import org.avni.server.domain.CHSBaseEntity;
import org.avni.server.domain.PrivilegeEntityType;
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)
Expand All @@ -29,25 +32,25 @@ public class Privilege extends CHSBaseEntity {
private PrivilegeEntityType entityType;

@Column
private DateTime createdDateTime;
private Instant createdDateTime;

@Column
private DateTime lastModifiedDateTime;
private Instant lastModifiedDateTime;

public DateTime getCreatedDateTime() {
return createdDateTime;
return DateTimeUtil.toJodaDateTime(createdDateTime);
}

public void setCreatedDateTime(DateTime createdDateTime) {
this.createdDateTime = createdDateTime;
this.createdDateTime = DateTimeUtil.toInstant(createdDateTime);
}

public DateTime getLastModifiedDateTime() {
return lastModifiedDateTime;
return DateTimeUtil.toJodaDateTime(lastModifiedDateTime);
}

public void setLastModifiedDateTime(DateTime lastModifiedDateTime) {
this.lastModifiedDateTime = lastModifiedDateTime;
this.lastModifiedDateTime = DateTimeUtil.toInstant(lastModifiedDateTime);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import org.avni.server.domain.OrganisationAwareEntity;
import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Interceptor;
import org.hibernate.type.Type;
import org.avni.server.framework.security.UserContextHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

public class UpdateOrganisationHibernateInterceptor extends EmptyInterceptor {
public class UpdateOrganisationHibernateInterceptor implements Interceptor, Serializable {
private static final Logger logger = LoggerFactory.getLogger(UpdateOrganisationHibernateInterceptor.class.getName());

@Override
Expand Down
Loading

0 comments on commit b4d93c5

Please sign in to comment.