diff --git a/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java b/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java index de37eed6c..4cf4c1e86 100644 --- a/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java +++ b/avni-server-api/src/main/java/org/avni/server/dao/ImplementationRepository.java @@ -10,23 +10,23 @@ @Repository public interface ImplementationRepository extends AvniCrudRepository { - @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 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); /** 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 e7faad534..475d47776 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,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 { @@ -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; @@ -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 { 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 9a475c9f7..8b2fc9a1d 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 @@ -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; @@ -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 @@ -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") @@ -38,7 +39,7 @@ public class CHSEntity extends CHSBaseEntity implements Auditable { @LastModifiedDate @NotNull - private Date lastModifiedDateTime; + private Instant lastModifiedDateTime; @JsonIgnore public User getCreatedBy() { @@ -54,7 +55,7 @@ public DateTime getCreatedDateTime() { } public void setCreatedDateTime(DateTime createdDateTime) { - this.createdDateTime = createdDateTime.toDate(); + this.createdDateTime = createdDateTime.toDate().toInstant(); } @JsonIgnore @@ -75,7 +76,7 @@ private DateTime toJodaDateTime() { } public void setLastModifiedDateTime(DateTime lastModifiedDateTime) { - this.lastModifiedDateTime = lastModifiedDateTime.toDate(); + this.lastModifiedDateTime = lastModifiedDateTime.toDate().toInstant(); } @Column(name = "version") 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 018f13ba4..86e8f1590 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/Checklist.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/Checklist.java @@ -1,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; @@ -29,7 +32,7 @@ public class Checklist extends OrganisationAwareEntity { @NotNull @Column - private DateTime baseDate; + private Instant baseDate; public ChecklistDetail getChecklistDetail() { return checklistDetail; @@ -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 getItems() { 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 3b3394559..6fa464f06 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 @@ -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; @@ -41,7 +44,7 @@ public class Individual extends SyncAttributeEntity implements MessageableEntity private String profilePicture; - private LocalDate dateOfBirth; + private Instant dateOfBirth; private boolean dateOfBirthVerified; @@ -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") @@ -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() { @@ -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) { 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 835767f3b..a6996d874 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 @@ -1,5 +1,6 @@ package org.avni.server.domain; +import org.avni.server.util.DateTimeUtil; import org.hibernate.annotations.BatchSize; import org.joda.time.DateTime; @@ -7,13 +8,15 @@ 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") @@ -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() { 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 e12f0a603..df28c0a28 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,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 { @@ -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) @@ -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() { 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 195f0bd76..738c959e5 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,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) @@ -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() { diff --git a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/UpdateOrganisationHibernateInterceptor.java b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/UpdateOrganisationHibernateInterceptor.java index e4219deed..0edba3d71 100644 --- a/avni-server-api/src/main/java/org/avni/server/framework/hibernate/UpdateOrganisationHibernateInterceptor.java +++ b/avni-server-api/src/main/java/org/avni/server/framework/hibernate/UpdateOrganisationHibernateInterceptor.java @@ -4,6 +4,7 @@ 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; @@ -11,7 +12,7 @@ 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 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 d91112b9e..eb1b38309 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 @@ -8,7 +8,6 @@ import java.time.LocalDateTime; import java.time.ZonedDateTime; import java.util.Calendar; -import java.util.Date; import java.util.TimeZone; public class DateTimeUtil { @@ -54,9 +53,34 @@ public static LocalDate toJodaDate(ZonedDateTime zonedDateTime) { return DateTimeUtil.toJodaDateTime(zonedDateTime).toLocalDate(); } + public static LocalDate toJodaDate(java.time.Instant instant) { + return DateTimeUtil.toJodaDateTime(instant).toLocalDate(); + } + + public static java.time.Instant toInstant(LocalDate localDate) { + if (localDate == null) { + return null; + } + return localDate.toDate().toInstant(); + } + public static DateTime toJodaDateTime(ZonedDateTime zonedDateTime) { return new DateTime( zonedDateTime.toInstant().toEpochMilli(), DateTimeZone.forTimeZone(TimeZone.getTimeZone(zonedDateTime.getZone()))); } + + 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); + } } diff --git a/avni-server-api/src/main/resources/application.properties b/avni-server-api/src/main/resources/application.properties index 0ecc25fc9..80014f06d 100644 --- a/avni-server-api/src/main/resources/application.properties +++ b/avni-server-api/src/main/resources/application.properties @@ -31,7 +31,7 @@ spring.jpa.hibernate.ddl-auto=none #spring.jpa.properties.jadira.usertype.javaZone=jvm #spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -spring.jpa.properties.hibernate.ejb.interceptor=org.avni.server.framework.hibernate.UpdateOrganisationHibernateInterceptor +spring.jpa.properties.hibernate.session_factory.interceptor=org.avni.server.framework.hibernate.UpdateOrganisationHibernateInterceptor #spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL10Dialect spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false avni.custom.query.timeout=${AVNI_CUSTOM_QUERY_TIMEOUT:3} diff --git a/avni-server-api/src/test/resources/application.properties b/avni-server-api/src/test/resources/application.properties index ba9181adf..f832fa915 100644 --- a/avni-server-api/src/test/resources/application.properties +++ b/avni-server-api/src/test/resources/application.properties @@ -28,7 +28,7 @@ spring.jpa.hibernate.ddl-auto=none #spring.jpa.properties.jadira.usertype.javaZone=jvm #spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -spring.jpa.properties.hibernate.ejb.interceptor=org.avni.server.framework.hibernate.UpdateOrganisationHibernateInterceptor +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