From 34da9f9b0e1160dc7d8800ba3e0d7d6c5be25d4b Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Wed, 10 Jan 2024 13:55:23 +0100 Subject: [PATCH] tech: renames audit to changeLog [ TECH-1659 ] (#16096) * tech: renames trackedEntityDataValueAudit to trackedEntityDataValueChangeLog * tech: renames trackedEntityAttributeValueAudit to trackedEntityAttributeValueChangeLog * tech: renames trackedEntityAudit to trackedEntityChangeLog * tech: separate audit and change log in api * tech: rename audittype to changelogtype * tech: rename controller * fix: clean doc --- .../ChangeLogType.java} | 7 +- .../hisp/dhis/datavalue/DataValueAudit.java | 13 +- .../datavalue/DataValueAuditQueryParams.java | 4 +- .../TrackedEntityChangeLog.java} | 28 +- ...=> TrackedEntityChangeLogQueryParams.java} | 6 +- ...ava => TrackedEntityChangeLogService.java} | 22 +- ....java => TrackedEntityChangeLogStore.java} | 28 +- ...dEntityDataValueChangeLogQueryParams.java} | 6 +- ...TrackedEntityAttributeValueChangeLog.java} | 18 +- ...tyAttributeValueChangeLogQueryParams.java} | 6 +- ...EntityAttributeValueChangeLogService.java} | 15 +- ...edEntityAttributeValueChangeLogStore.java} | 15 +- ...a => TrackedEntityDataValueChangeLog.java} | 18 +- ...ackedEntityDataValueChangeLogService.java} | 17 +- ...TrackedEntityDataValueChangeLogStore.java} | 17 +- .../DefaultMaintenanceService.java | 6 +- .../DefaultDataValueAuditService.java | 12 +- .../datavalue/DefaultDataValueService.java | 11 +- .../HibernatePotentialDuplicateStore.java | 43 +- .../dhis/program/DefaultEventService.java | 20 +- ...ityDataValueChangeLogDeletionHandler.java} | 10 +- ...DefaultTrackedEntityChangeLogService.java} | 30 +- .../DefaultTrackedEntityService.java | 42 +- ...HibernateTrackedEntityChangeLogStore.java} | 50 +- ...EntityAttributeValueChangeLogService.java} | 38 +- ...ultTrackedEntityAttributeValueService.java | 25 +- ...edEntityAttributeValueChangeLogStore.java} | 56 +-- ...ackedEntityDataValueChangeLogService.java} | 48 +- ...TrackedEntityDataValueChangeLogStore.java} | 74 +-- .../hibernate/DataValueAudit.hbm.xml | 2 +- ...hbm.xml => TrackedEntityChangeLog.hbm.xml} | 4 +- ...ckedEntityAttributeValueChangeLog.hbm.xml} | 4 +- ...> TrackedEntityDataValueChangeLog.hbm.xml} | 4 +- .../DefaultTrackedEntityServiceTest.java | 8 +- .../DefaultDataValueSetService.java | 15 +- .../tracker/importer/EventManager.java | 22 +- .../AbstractTrackedEntityInstanceService.java | 16 +- .../JacksonTrackedEntityInstanceService.java | 6 +- .../DefaultTrackedEntityService.java | 20 +- .../persister/AbstractTrackerPersister.java | 32 +- .../bundle/persister/EnrollmentPersister.java | 6 +- .../bundle/persister/EventPersister.java | 40 +- .../persister/RelationshipPersister.java | 6 +- .../persister/TrackedEntityPersister.java | 6 +- .../DataValueAuditBatchHandler.java | 4 +- .../datavalue/DataValueAuditServiceTest.java | 91 ++-- .../DataValueSetServiceIntegrationTest.java | 4 +- .../DataValueAuditBatchHandlerTest.java | 10 +- .../maintenance/MaintenanceServiceTest.java | 21 +- ...a => TrackedEntityChangeLogStoreTest.java} | 74 +-- .../TrackedEntityDataValueAuditStoreTest.java | 368 -------------- ...ckedEntityDataValueChangeLogStoreTest.java | 469 ++++++++++++++++++ .../TrackedEntityAttributeValueStoreTest.java | 63 +-- ...kedEntityAttributeValueChangeLogTest.java} | 34 +- ... TrackedEntityDataValueChangeLogTest.java} | 50 +- ...Test.java => ChangeLogControllerTest.java} | 2 +- ...ntroller.java => ChangeLogController.java} | 159 +++--- .../datavalue/DataValueAuditDto.java | 4 +- 58 files changed, 1166 insertions(+), 1063 deletions(-) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/{common/AuditType.java => changelog/ChangeLogType.java} (92%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/{audit/payloads/TrackedEntityAudit.java => trackedentity/TrackedEntityChangeLog.java} (86%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/{TrackedEntityAuditQueryParams.java => TrackedEntityChangeLogQueryParams.java} (94%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/{TrackedEntityAuditService.java => TrackedEntityChangeLogService.java} (75%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/{TrackedEntityAuditStore.java => TrackedEntityChangeLogStore.java} (69%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/{TrackedEntityDataValueAuditQueryParams.java => TrackedEntityDataValueChangeLogQueryParams.java} (94%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/{TrackedEntityAttributeValueAudit.java => TrackedEntityAttributeValueChangeLog.java} (92%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/{TrackedEntityAttributeValueAuditQueryParams.java => TrackedEntityAttributeValueChangeLogQueryParams.java} (92%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/{TrackedEntityAttributeValueAuditService.java => TrackedEntityAttributeValueChangeLogService.java} (76%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/{TrackedEntityAttributeValueAuditStore.java => TrackedEntityAttributeValueChangeLogStore.java} (76%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/{TrackedEntityDataValueAudit.java => TrackedEntityDataValueChangeLog.java} (92%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/{TrackedEntityDataValueAuditStore.java => TrackedEntityDataValueChangeLogService.java} (74%) rename dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/{TrackedEntityDataValueAuditService.java => TrackedEntityDataValueChangeLogStore.java} (74%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/{TrackedEntityDataValueAuditDeletionHandler.java => TrackedEntityDataValueChangeLogDeletionHandler.java} (90%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/{DefaultTrackedEntityAuditService.java => DefaultTrackedEntityChangeLogService.java} (72%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/{HibernateTrackedEntityAuditStore.java => HibernateTrackedEntityChangeLogStore.java} (74%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/{DefaultTrackedEntityAttributeValueAuditService.java => DefaultTrackedEntityAttributeValueChangeLogService.java} (69%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/{HibernateTrackedEntityAttributeValueAuditStore.java => HibernateTrackedEntityAttributeValueChangeLogStore.java} (69%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/{DefaultTrackedEntityDataValueAuditService.java => DefaultTrackedEntityDataValueChangeLogService.java} (64%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/{HibernateTrackedEntityDataValueAuditStore.java => HibernateTrackedEntityDataValueChangeLogStore.java} (70%) rename dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/{TrackedEntityAudit.hbm.xml => TrackedEntityChangeLog.hbm.xml} (83%) rename dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/{TrackedEntityAttributeValueAudit.hbm.xml => TrackedEntityAttributeValueChangeLog.hbm.xml} (92%) rename dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/{TrackedEntityDataValueAudit.hbm.xml => TrackedEntityDataValueChangeLog.hbm.xml} (90%) rename dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/{TrackedEntityAuditStoreTest.java => TrackedEntityChangeLogStoreTest.java} (57%) delete mode 100644 dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditStoreTest.java create mode 100644 dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java rename dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/{TrackedEntityAttributeValueAuditTest.java => TrackedEntityAttributeValueChangeLogTest.java} (86%) rename dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/{TrackedEntityDataValueAuditTest.java => TrackedEntityDataValueChangeLogTest.java} (78%) rename dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/{AuditControllerTest.java => ChangeLogControllerTest.java} (99%) rename dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/{AuditController.java => ChangeLogController.java} (82%) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AuditType.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java similarity index 92% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AuditType.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java index 4d4d3722cbfb..7236761f47fe 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AuditType.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java @@ -25,14 +25,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.common; +package org.hisp.dhis.changelog; /** - * This class is deprecated in favor of new async auditing solution, do not use. - * * @author Halvdan Hoem Grelland + * @author Luca Cambi split Changelog from Audit */ -public enum AuditType { +public enum ChangeLogType { CREATE, UPDATE, DELETE, diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAudit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAudit.java index a0d0eeb8f599..91af859ab1f3 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAudit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAudit.java @@ -33,7 +33,7 @@ import java.util.Date; import java.util.Objects; import org.hisp.dhis.category.CategoryOptionCombo; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -62,7 +62,7 @@ public class DataValueAudit { private Date created; - private AuditType auditType; + private ChangeLogType auditType; // ------------------------------------------------------------------------- // Constructors @@ -70,7 +70,8 @@ public class DataValueAudit { public DataValueAudit() {} - public DataValueAudit(DataValue dataValue, String value, String modifiedBy, AuditType auditType) { + public DataValueAudit( + DataValue dataValue, String value, String modifiedBy, ChangeLogType auditType) { this.dataElement = dataValue.getDataElement(); this.period = dataValue.getPeriod(); this.organisationUnit = dataValue.getSource(); @@ -90,7 +91,7 @@ public DataValueAudit( CategoryOptionCombo attributeOptionCombo, String value, String modifiedBy, - AuditType auditType) { + ChangeLogType auditType) { this.dataElement = dataElement; this.period = period; this.organisationUnit = organisationUnit; @@ -276,11 +277,11 @@ public void setCreated(Date created) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public AuditType getAuditType() { + public ChangeLogType getAuditType() { return auditType; } - public void setAuditType(AuditType auditType) { + public void setAuditType(ChangeLogType auditType) { this.auditType = auditType; } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditQueryParams.java index 39669365cf3f..100a4e918db7 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditQueryParams.java @@ -32,7 +32,7 @@ import lombok.Data; import lombok.experimental.Accessors; import org.hisp.dhis.category.CategoryOptionCombo; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.Pager; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -56,7 +56,7 @@ public class DataValueAuditQueryParams { private CategoryOptionCombo attributeOptionCombo; - private List auditTypes = new ArrayList<>(); + private List auditTypes = new ArrayList<>(); private Pager pager; diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/audit/payloads/TrackedEntityAudit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLog.java similarity index 86% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/audit/payloads/TrackedEntityAudit.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLog.java index 975b89f77c35..b3e2710339c0 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/audit/payloads/TrackedEntityAudit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLog.java @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.audit.payloads; +package org.hisp.dhis.trackedentity; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @@ -33,7 +33,7 @@ import java.io.Serializable; import java.util.Date; import java.util.Objects; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DxfNamespaces; /** @@ -42,7 +42,7 @@ * @author Abyot Asalefew Gizaw abyota@gmail.com */ @JacksonXmlRootElement(localName = "trackedEntityInstanceAudit", namespace = DxfNamespaces.DXF_2_0) -public class TrackedEntityAudit implements Serializable { +public class TrackedEntityChangeLog implements Serializable { private static final long serialVersionUID = 4260110537887403524L; private long id; @@ -55,24 +55,28 @@ public class TrackedEntityAudit implements Serializable { private String accessedBy; - private AuditType auditType; + private ChangeLogType auditType; // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- - public TrackedEntityAudit() {} + public TrackedEntityChangeLog() {} - public TrackedEntityAudit(String trackedEntity, String accessedBy, AuditType auditType) { + public TrackedEntityChangeLog(String trackedEntity, String accessedBy, ChangeLogType auditType) { this.trackedEntity = trackedEntity; this.accessedBy = accessedBy; this.created = new Date(); this.auditType = auditType; } - public TrackedEntityAudit( - String trackedEntity, String comment, Date created, String accessedBy, AuditType auditType) { - this(trackedEntity, accessedBy, auditType); + public TrackedEntityChangeLog( + String trackedEntity, + String comment, + Date created, + String accessedBy, + ChangeLogType changeLogType) { + this(trackedEntity, accessedBy, changeLogType); this.comment = comment; this.created = created; } @@ -92,7 +96,7 @@ public boolean equals(Object obj) { return false; } - final TrackedEntityAudit other = (TrackedEntityAudit) obj; + final TrackedEntityChangeLog other = (TrackedEntityChangeLog) obj; return Objects.equals(this.trackedEntity, other.trackedEntity) && Objects.equals(this.comment, other.comment) @@ -155,11 +159,11 @@ public void setAccessedBy(String accessedBy) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public AuditType getAuditType() { + public ChangeLogType getAuditType() { return auditType; } - public void setAuditType(AuditType auditType) { + public void setAuditType(ChangeLogType auditType) { this.auditType = auditType; } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogQueryParams.java similarity index 94% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditQueryParams.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogQueryParams.java index e07e5a0cc13c..71c3d46b1a58 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogQueryParams.java @@ -32,7 +32,7 @@ import java.util.List; import lombok.Data; import lombok.experimental.Accessors; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.Pager; /** @@ -40,12 +40,12 @@ */ @Data @Accessors(chain = true) -public class TrackedEntityAuditQueryParams { +public class TrackedEntityChangeLogQueryParams { private List trackedEntities = new ArrayList<>(); private List users = new ArrayList<>(); - private List auditTypes = new ArrayList<>(); + private List auditTypes = new ArrayList<>(); private Date startDate = null; diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogService.java similarity index 75% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditService.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogService.java index e8748ac3f232..f73c396e935b 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogService.java @@ -28,31 +28,23 @@ package org.hisp.dhis.trackedentity; import java.util.List; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; /** * @author Abyot Asalefew Gizaw abyota@gmail.com */ -public interface TrackedEntityAuditService { +public interface TrackedEntityChangeLogService { - String ID = TrackedEntityAuditService.class.getName(); + String ID = TrackedEntityChangeLogService.class.getName(); /** * Adds tracked entity audit * - * @param trackedEntityAudit the audit to add + * @param trackedEntityChangeLog the audit to add */ - void addTrackedEntityAudit(TrackedEntityAudit trackedEntityAudit); + void addTrackedEntityChangeLog(TrackedEntityChangeLog trackedEntityChangeLog); /** Adds multiple tracked entity audit */ - void addTrackedEntityAudit(List trackedEntityAudits); - - /** - * Deletes tracked entity audit for the given tracked entity - * - * @param trackedEntity the tracked entity - */ - void deleteTrackedEntityAudit(TrackedEntity trackedEntity); + void addTrackedEntityChangeLog(List trackedEntityChangeLogs); /** * Returns tracked entity audits matching query params @@ -60,7 +52,7 @@ public interface TrackedEntityAuditService { * @param params tracked entity audit query params * @return matching TrackedEntityAudits */ - List getTrackedEntityAudits(TrackedEntityAuditQueryParams params); + List getTrackedEntityChangeLogs(TrackedEntityChangeLogQueryParams params); /** * Returns count of tracked entity audits matching query params @@ -68,5 +60,5 @@ public interface TrackedEntityAuditService { * @param params tracked entity audit query params * @return count of TrackedEntityAudits */ - int getTrackedEntityAuditsCount(TrackedEntityAuditQueryParams params); + int getTrackedEntityChangeLogsCount(TrackedEntityChangeLogQueryParams params); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogStore.java similarity index 69% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStore.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogStore.java index cf0cf399b9a6..b470781600fa 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogStore.java @@ -28,42 +28,34 @@ package org.hisp.dhis.trackedentity; import java.util.List; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; /** * @author Abyot Asalefew Gizaw abyota@gmail.com */ -public interface TrackedEntityAuditStore { - String ID = TrackedEntityAuditStore.class.getName(); +public interface TrackedEntityChangeLogStore { + String ID = TrackedEntityChangeLogStore.class.getName(); /** * Adds the given tracked entity audit. * - * @param trackedEntityAudit the {@link TrackedEntityAudit} to add. + * @param trackedEntityChangeLog the {@link TrackedEntityChangeLog} to add. */ - void addTrackedEntityAudit(TrackedEntityAudit trackedEntityAudit); + void addTrackedEntityChangeLog(TrackedEntityChangeLog trackedEntityChangeLog); /** - * Adds the given {@link TrackedEntityAudit}s. + * Adds the given {@link TrackedEntityChangeLog}s. * - * @param trackedEntityAudit the list of {@link TrackedEntityAudit}. + * @param trackedEntityChangeLog the list of {@link TrackedEntityChangeLog}. */ - void addTrackedEntityAudit(List trackedEntityAudit); - - /** - * Deletes tracked entity audit for the given tracked entity. - * - * @param trackedEntity the {@link TrackedEntity}. - */ - void deleteTrackedEntityAudit(TrackedEntity trackedEntity); + void addTrackedEntityChangeLog(List trackedEntityChangeLog); /** * Returns tracked entity audits matching query params * * @param params tracked entity audit query params - * @return a list of {@link TrackedEntityAudit}. + * @return a list of {@link TrackedEntityChangeLog}. */ - List getTrackedEntityAudits(TrackedEntityAuditQueryParams params); + List getTrackedEntityChangeLogs(TrackedEntityChangeLogQueryParams params); /** * Returns count of tracked entity audits matching query params @@ -71,5 +63,5 @@ public interface TrackedEntityAuditStore { * @param params tracked entity audit query params * @return count of audits. */ - int getTrackedEntityAuditsCount(TrackedEntityAuditQueryParams params); + int getTrackedEntityChangeLogsCount(TrackedEntityChangeLogQueryParams params); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogQueryParams.java similarity index 94% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditQueryParams.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogQueryParams.java index 9819bfefd3d1..f9de606352fd 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogQueryParams.java @@ -32,7 +32,7 @@ import java.util.List; import lombok.Data; import lombok.experimental.Accessors; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.OrganisationUnitSelectionMode; import org.hisp.dhis.common.Pager; import org.hisp.dhis.dataelement.DataElement; @@ -47,7 +47,7 @@ */ @Data @Accessors(chain = true) -public class TrackedEntityDataValueAuditQueryParams { +public class TrackedEntityDataValueChangeLogQueryParams { private List dataElements = new ArrayList<>(); private List orgUnits = new ArrayList<>(); @@ -62,7 +62,7 @@ public class TrackedEntityDataValueAuditQueryParams { private OrganisationUnitSelectionMode ouMode; - private List auditTypes = new ArrayList<>(); + private List auditTypes = new ArrayList<>(); private Pager pager; diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLog.java similarity index 92% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLog.java index c6efee1cf536..3a5242351b93 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAudit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLog.java @@ -33,7 +33,7 @@ import java.io.Serializable; import java.util.Date; import java.util.Objects; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; @@ -44,7 +44,7 @@ @JacksonXmlRootElement( localName = "trackedEntityAttributeValueAudit", namespace = DxfNamespaces.DXF_2_0) -public class TrackedEntityAttributeValueAudit implements Serializable { +public class TrackedEntityAttributeValueChangeLog implements Serializable { private long id; private TrackedEntityAttribute attribute; @@ -59,7 +59,7 @@ public class TrackedEntityAttributeValueAudit implements Serializable { private String modifiedBy; - private AuditType auditType; + private ChangeLogType auditType; /** * This value is only used to store values from setValue when we don't know if attribute is set or @@ -67,13 +67,13 @@ public class TrackedEntityAttributeValueAudit implements Serializable { */ private String value; - public TrackedEntityAttributeValueAudit() {} + public TrackedEntityAttributeValueChangeLog() {} - public TrackedEntityAttributeValueAudit( + public TrackedEntityAttributeValueChangeLog( TrackedEntityAttributeValue trackedEntityAttributeValue, String value, String modifiedBy, - AuditType auditType) { + ChangeLogType auditType) { this.attribute = trackedEntityAttributeValue.getAttribute(); this.trackedEntity = trackedEntityAttributeValue.getTrackedEntity(); @@ -98,7 +98,7 @@ public boolean equals(Object obj) { return false; } - final TrackedEntityAttributeValueAudit other = (TrackedEntityAttributeValueAudit) obj; + final TrackedEntityAttributeValueChangeLog other = (TrackedEntityAttributeValueChangeLog) obj; return Objects.equals(this.attribute, other.attribute) && Objects.equals(this.trackedEntity, other.trackedEntity) @@ -192,11 +192,11 @@ public void setModifiedBy(String modifiedBy) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public AuditType getAuditType() { + public ChangeLogType getAuditType() { return auditType; } - public void setAuditType(AuditType auditType) { + public void setAuditType(ChangeLogType auditType) { this.auditType = auditType; } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogQueryParams.java similarity index 92% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditQueryParams.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogQueryParams.java index d1a7e6a4b1f5..10683e51f54f 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogQueryParams.java @@ -31,7 +31,7 @@ import java.util.List; import lombok.Data; import lombok.experimental.Accessors; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.Pager; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; @@ -43,12 +43,12 @@ */ @Data @Accessors(chain = true) -public class TrackedEntityAttributeValueAuditQueryParams { +public class TrackedEntityAttributeValueChangeLogQueryParams { private List trackedEntityAttributes = new ArrayList<>(); private List trackedEntities = new ArrayList<>(); - private List auditTypes = new ArrayList<>(); + private List auditTypes = new ArrayList<>(); private Pager pager; diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogService.java similarity index 76% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogService.java index 03672b4e0316..e2bb3bc016bc 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogService.java @@ -33,14 +33,15 @@ /** * @author Morten Olav Hansen */ -public interface TrackedEntityAttributeValueAuditService { - void addTrackedEntityAttributeValueAudit( - TrackedEntityAttributeValueAudit trackedEntityAttributeValueAudit); +public interface TrackedEntityAttributeValueChangeLogService { + void addTrackedEntityAttributeValueChangLog( + TrackedEntityAttributeValueChangeLog trackedEntityAttributeValueChangeLog); - List getTrackedEntityAttributeValueAudits( - TrackedEntityAttributeValueAuditQueryParams params); + List getTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params); - int countTrackedEntityAttributeValueAudits(TrackedEntityAttributeValueAuditQueryParams params); + int countTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params); - void deleteTrackedEntityAttributeValueAudits(TrackedEntity trackedEntity); + void deleteTrackedEntityAttributeValueChangeLogs(TrackedEntity trackedEntity); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogStore.java similarity index 76% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogStore.java index 5b86972c9efe..183d1c3d519e 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueChangeLogStore.java @@ -33,14 +33,15 @@ /** * @author Morten Olav Hansen */ -public interface TrackedEntityAttributeValueAuditStore { - void addTrackedEntityAttributeValueAudit( - TrackedEntityAttributeValueAudit trackedEntityAttributeValueAudit); +public interface TrackedEntityAttributeValueChangeLogStore { + void addTrackedEntityAttributeValueChangeLog( + TrackedEntityAttributeValueChangeLog attributeValueChangeLog); - List getTrackedEntityAttributeValueAudits( - TrackedEntityAttributeValueAuditQueryParams params); + List getTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params); - int countTrackedEntityAttributeValueAudits(TrackedEntityAttributeValueAuditQueryParams params); + int countTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params); - void deleteTrackedEntityAttributeValueAudits(TrackedEntity trackedEntity); + void deleteTrackedEntityAttributeValueChangeLogs(TrackedEntity trackedEntity); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAudit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLog.java similarity index 92% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAudit.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLog.java index 0930573354c7..44f4ef8ad18d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAudit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLog.java @@ -33,7 +33,7 @@ import java.io.Serializable; import java.util.Date; import java.util.Objects; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.program.Event; @@ -42,7 +42,7 @@ * @author Morten Olav Hansen */ @JacksonXmlRootElement(localName = "trackedEntityDataValueAudit", namespace = DxfNamespaces.DXF_2_0) -public class TrackedEntityDataValueAudit implements Serializable { +public class TrackedEntityDataValueChangeLog implements Serializable { private long id; private DataElement dataElement; @@ -57,21 +57,21 @@ public class TrackedEntityDataValueAudit implements Serializable { private String modifiedBy; - private AuditType auditType; + private ChangeLogType auditType; // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- - public TrackedEntityDataValueAudit() {} + public TrackedEntityDataValueChangeLog() {} - public TrackedEntityDataValueAudit( + public TrackedEntityDataValueChangeLog( DataElement dataElement, Event event, String value, String modifiedBy, boolean providedElsewhere, - AuditType auditType) { + ChangeLogType auditType) { this.dataElement = dataElement; this.event = event; this.providedElsewhere = providedElsewhere; @@ -97,7 +97,7 @@ public boolean equals(Object obj) { return false; } - final TrackedEntityDataValueAudit other = (TrackedEntityDataValueAudit) obj; + final TrackedEntityDataValueChangeLog other = (TrackedEntityDataValueChangeLog) obj; return Objects.equals(this.dataElement, other.dataElement) && Objects.equals(this.event, other.event) @@ -195,11 +195,11 @@ public void setModifiedBy(String modifiedBy) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public AuditType getAuditType() { + public ChangeLogType getAuditType() { return auditType; } - public void setAuditType(AuditType auditType) { + public void setAuditType(ChangeLogType auditType) { this.auditType = auditType; } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLogService.java similarity index 74% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLogService.java index e638f70e5316..013d22bfec27 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLogService.java @@ -30,20 +30,21 @@ import java.util.List; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.program.Event; -import org.hisp.dhis.trackedentity.TrackedEntityDataValueAuditQueryParams; +import org.hisp.dhis.trackedentity.TrackedEntityDataValueChangeLogQueryParams; /** * @author Morten Olav Hansen */ -public interface TrackedEntityDataValueAuditStore { - void addTrackedEntityDataValueAudit(TrackedEntityDataValueAudit trackedEntityDataValueAudit); +public interface TrackedEntityDataValueChangeLogService { + void addTrackedEntityDataValueChangeLog( + TrackedEntityDataValueChangeLog trackedEntityDataValueChangeLog); - List getTrackedEntityDataValueAudits( - TrackedEntityDataValueAuditQueryParams params); + List getTrackedEntityDataValueChangeLogs( + TrackedEntityDataValueChangeLogQueryParams params); - int countTrackedEntityDataValueAudits(TrackedEntityDataValueAuditQueryParams params); + int countTrackedEntityDataValueChangeLogs(TrackedEntityDataValueChangeLogQueryParams params); - void deleteTrackedEntityDataValueAudit(DataElement dataElement); + void deleteTrackedEntityDataValueChangeLog(DataElement dataElement); - void deleteTrackedEntityDataValueAudit(Event event); + void deleteTrackedEntityDataValueChangeLog(Event event); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLogStore.java similarity index 74% rename from dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLogStore.java index 9cea26fe0986..ada4de2d97a2 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueChangeLogStore.java @@ -30,20 +30,21 @@ import java.util.List; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.program.Event; -import org.hisp.dhis.trackedentity.TrackedEntityDataValueAuditQueryParams; +import org.hisp.dhis.trackedentity.TrackedEntityDataValueChangeLogQueryParams; /** * @author Morten Olav Hansen */ -public interface TrackedEntityDataValueAuditService { - void addTrackedEntityDataValueAudit(TrackedEntityDataValueAudit trackedEntityDataValueAudit); +public interface TrackedEntityDataValueChangeLogStore { + void addTrackedEntityDataValueChangeLog( + TrackedEntityDataValueChangeLog trackedEntityDataValueChangeLog); - List getTrackedEntityDataValueAudits( - TrackedEntityDataValueAuditQueryParams params); + List getTrackedEntityDataValueChangeLogs( + TrackedEntityDataValueChangeLogQueryParams params); - int countTrackedEntityDataValueAudits(TrackedEntityDataValueAuditQueryParams params); + int countTrackedEntityDataValueChangeLogs(TrackedEntityDataValueChangeLogQueryParams params); - void deleteTrackedEntityDataValueAudit(DataElement dataElement); + void deleteTrackedEntityDataValueChangeLog(DataElement dataElement); - void deleteTrackedEntityDataValueAudit(Event event); + void deleteTrackedEntityDataValueChangeLog(Event event); } diff --git a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java index b4695208eaf1..7996c1813ba5 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/maintenance/DefaultMaintenanceService.java @@ -41,7 +41,7 @@ import org.hisp.dhis.datavalue.DataValueAuditService; import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserInvitationStatus; @@ -80,7 +80,7 @@ public class DefaultMaintenanceService implements MaintenanceService { private final ApplicationEventPublisher eventPublisher; - private final TrackedEntityDataValueAuditService trackedEntityDataValueAuditService; + private final TrackedEntityDataValueChangeLogService trackedEntityDataValueAuditService; // ------------------------------------------------------------------------- // MaintenanceService implementation @@ -175,7 +175,7 @@ public boolean pruneData(DataElement dataElement) { return false; } - trackedEntityDataValueAuditService.deleteTrackedEntityDataValueAudit(dataElement); + trackedEntityDataValueAuditService.deleteTrackedEntityDataValueChangeLog(dataElement); dataValueAuditService.deleteDataValueAudits(dataElement); dataValueService.deleteDataValues(dataElement); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java index 550a9e782da6..4a8c35fdb85d 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java @@ -33,7 +33,7 @@ import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryOptionComboStore; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; @@ -134,21 +134,21 @@ public List getDataValueAudits( } // case if the audit trail started out with DELETE - if (dataValueAudits.get(dataValueAudits.size() - 1).getAuditType() == AuditType.DELETE) { + if (dataValueAudits.get(dataValueAudits.size() - 1).getAuditType() == ChangeLogType.DELETE) { DataValueAudit valueAudit = createDataValueAudit(dataValue); valueAudit.setValue(dataValueAudits.get(dataValueAudits.size() - 1).getValue()); dataValueAudits.add(valueAudit); } // unless top is CREATE, inject current DV as audit on top - if (!dataValue.isDeleted() && dataValueAudits.get(0).getAuditType() != AuditType.CREATE) { + if (!dataValue.isDeleted() && dataValueAudits.get(0).getAuditType() != ChangeLogType.CREATE) { DataValueAudit dataValueAudit = createDataValueAudit(dataValue); - dataValueAudit.setAuditType(AuditType.UPDATE); + dataValueAudit.setAuditType(ChangeLogType.UPDATE); dataValueAudit.setCreated(dataValue.getLastUpdated()); dataValueAudits.add(0, dataValueAudit); } - dataValueAudits.get(dataValueAudits.size() - 1).setAuditType(AuditType.CREATE); + dataValueAudits.get(dataValueAudits.size() - 1).setAuditType(ChangeLogType.CREATE); return dataValueAudits; } @@ -156,7 +156,7 @@ public List getDataValueAudits( private static DataValueAudit createDataValueAudit(DataValue dataValue) { DataValueAudit dataValueAudit = new DataValueAudit( - dataValue, dataValue.getValue(), dataValue.getStoredBy(), AuditType.CREATE); + dataValue, dataValue.getValue(), dataValue.getStoredBy(), ChangeLogType.CREATE); dataValueAudit.setCreated(dataValue.getCreated()); return dataValueAudit; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java index e293e0665b43..50f336ece2f0 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java @@ -40,7 +40,7 @@ import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.external.conf.DhisConfigurationProvider; @@ -143,7 +143,7 @@ public boolean addDataValue(DataValue dataValue) { if (config.isEnabled(CHANGELOG_AGGREGATE)) { DataValueAudit dataValueAudit = new DataValueAudit( - dataValue, dataValue.getValue(), dataValue.getStoredBy(), AuditType.CREATE); + dataValue, dataValue.getValue(), dataValue.getStoredBy(), ChangeLogType.CREATE); dataValueAuditService.addDataValueAudit(dataValueAudit); } @@ -165,7 +165,10 @@ public void updateDataValue(DataValue dataValue) { && !Objects.equals(dataValue.getAuditValue(), dataValue.getValue())) { DataValueAudit dataValueAudit = new DataValueAudit( - dataValue, dataValue.getAuditValue(), dataValue.getStoredBy(), AuditType.UPDATE); + dataValue, + dataValue.getAuditValue(), + dataValue.getStoredBy(), + ChangeLogType.UPDATE); dataValueAuditService.addDataValueAudit(dataValueAudit); } @@ -193,7 +196,7 @@ public void deleteDataValue(DataValue dataValue) { dataValue, dataValue.getAuditValue(), currentUserService.getCurrentUsername(), - AuditType.DELETE); + ChangeLogType.DELETE); dataValueAuditService.addDataValueAudit(dataValueAudit); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/deduplication/hibernate/HibernatePotentialDuplicateStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/deduplication/hibernate/HibernatePotentialDuplicateStore.java index 553891bc09a9..ed007ecbc1fb 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/deduplication/hibernate/HibernatePotentialDuplicateStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/deduplication/hibernate/HibernatePotentialDuplicateStore.java @@ -27,9 +27,9 @@ */ package org.hisp.dhis.deduplication.hibernate; -import static org.hisp.dhis.common.AuditType.CREATE; -import static org.hisp.dhis.common.AuditType.DELETE; -import static org.hisp.dhis.common.AuditType.UPDATE; +import static org.hisp.dhis.changelog.ChangeLogType.CREATE; +import static org.hisp.dhis.changelog.ChangeLogType.DELETE; +import static org.hisp.dhis.changelog.ChangeLogType.UPDATE; import static org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER; import java.math.BigInteger; @@ -54,6 +54,7 @@ import org.hisp.dhis.artemis.audit.AuditableEntity; import org.hisp.dhis.audit.AuditScope; import org.hisp.dhis.audit.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.deduplication.DeduplicationMergeParams; import org.hisp.dhis.deduplication.DeduplicationStatus; @@ -72,8 +73,8 @@ import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityStore; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditStore; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLog; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogStore; import org.hisp.dhis.user.CurrentUserService; import org.springframework.context.ApplicationEventPublisher; import org.springframework.jdbc.core.JdbcTemplate; @@ -87,7 +88,7 @@ public class HibernatePotentialDuplicateStore private final TrackedEntityStore trackedEntityStore; - private final TrackedEntityAttributeValueAuditStore trackedEntityAttributeValueAuditStore; + private final TrackedEntityAttributeValueChangeLogStore trackedEntityAttributeValueChangeLogStore; private final DhisConfigurationProvider config; @@ -99,7 +100,7 @@ public HibernatePotentialDuplicateStore( AclService aclService, TrackedEntityStore trackedEntityStore, AuditManager auditManager, - TrackedEntityAttributeValueAuditStore trackedEntityAttributeValueAuditStore, + TrackedEntityAttributeValueChangeLogStore trackedEntityAttributeValueChangeLogStore, DhisConfigurationProvider config) { super( entityManager, @@ -111,7 +112,7 @@ public HibernatePotentialDuplicateStore( false); this.trackedEntityStore = trackedEntityStore; this.auditManager = auditManager; - this.trackedEntityAttributeValueAuditStore = trackedEntityAttributeValueAuditStore; + this.trackedEntityAttributeValueChangeLogStore = trackedEntityAttributeValueChangeLogStore; this.config = config; } @@ -225,12 +226,12 @@ public void moveTrackedEntityAttributeValues( .forEach( av -> { TrackedEntityAttributeValue updatedTeav; - org.hisp.dhis.common.AuditType auditType; + ChangeLogType changeLogType; if (originalAttributeValueMap.containsKey(av.getAttribute().getUid())) { // Teav exists in original, overwrite the value updatedTeav = originalAttributeValueMap.get(av.getAttribute().getUid()); updatedTeav.setValue(av.getValue()); - auditType = UPDATE; + changeLogType = UPDATE; } else { // teav does not exist in original, so create new and attach // it to original @@ -238,7 +239,7 @@ public void moveTrackedEntityAttributeValues( updatedTeav.setAttribute(av.getAttribute()); updatedTeav.setTrackedEntity(original); updatedTeav.setValue(av.getValue()); - auditType = CREATE; + changeLogType = CREATE; } getSession().delete(av); // We need to flush to make sure the previous teav is @@ -249,25 +250,27 @@ public void moveTrackedEntityAttributeValues( getSession().saveOrUpdate(updatedTeav); - auditTeav(av, updatedTeav, auditType); + auditTeav(av, updatedTeav, changeLogType); }); } private void auditTeav( TrackedEntityAttributeValue av, TrackedEntityAttributeValue createOrUpdateTeav, - org.hisp.dhis.common.AuditType auditType) { + ChangeLogType changeLogType) { String currentUsername = currentUserService.getCurrentUsername(); - TrackedEntityAttributeValueAudit deleteTeavAudit = - new TrackedEntityAttributeValueAudit(av, av.getAuditValue(), currentUsername, DELETE); - TrackedEntityAttributeValueAudit updatedTeavAudit = - new TrackedEntityAttributeValueAudit( - createOrUpdateTeav, createOrUpdateTeav.getValue(), currentUsername, auditType); + TrackedEntityAttributeValueChangeLog deleteTeavAudit = + new TrackedEntityAttributeValueChangeLog(av, av.getAuditValue(), currentUsername, DELETE); + TrackedEntityAttributeValueChangeLog updatedTeavAudit = + new TrackedEntityAttributeValueChangeLog( + createOrUpdateTeav, createOrUpdateTeav.getValue(), currentUsername, changeLogType); if (config.isEnabled(CHANGELOG_TRACKER)) { - trackedEntityAttributeValueAuditStore.addTrackedEntityAttributeValueAudit(deleteTeavAudit); - trackedEntityAttributeValueAuditStore.addTrackedEntityAttributeValueAudit(updatedTeavAudit); + trackedEntityAttributeValueChangeLogStore.addTrackedEntityAttributeValueChangeLog( + deleteTeavAudit); + trackedEntityAttributeValueChangeLogStore.addTrackedEntityAttributeValueChangeLog( + updatedTeavAudit); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEventService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEventService.java index 24b81478f36b..a00e2eb1df40 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEventService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEventService.java @@ -37,7 +37,7 @@ import java.util.Set; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.event.EventStatus; @@ -48,8 +48,8 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.system.util.ValidationUtils; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.hisp.dhis.user.User; import org.hisp.dhis.util.DateUtils; import org.springframework.stereotype.Service; @@ -63,7 +63,7 @@ public class DefaultEventService implements EventService { private final EventStore eventStore; - private final TrackedEntityDataValueAuditService dataValueAuditService; + private final TrackedEntityDataValueChangeLogService dataValueAuditService; private final FileResourceService fileResourceService; @@ -206,7 +206,7 @@ public void saveEventDataValuesAndSaveEvent( for (Map.Entry entry : dataElementEventDataValueMap.entrySet()) { entry.getValue().setAutoFields(); - createAndAddAudit(entry.getValue(), entry.getKey(), event, AuditType.CREATE); + createAndAddAudit(entry.getValue(), entry.getKey(), event, ChangeLogType.CREATE); handleFileDataValueSave(entry.getValue(), entry.getKey()); } } @@ -259,21 +259,21 @@ private void validateEventDataValues( // ------------------------------------------------------------------------- private void createAndAddAudit( - EventDataValue dataValue, DataElement dataElement, Event event, AuditType auditType) { + EventDataValue dataValue, DataElement dataElement, Event event, ChangeLogType changeLogType) { if (!config.isEnabled(CHANGELOG_TRACKER) || dataElement == null) { return; } - TrackedEntityDataValueAudit dataValueAudit = - new TrackedEntityDataValueAudit( + TrackedEntityDataValueChangeLog dataValueAudit = + new TrackedEntityDataValueChangeLog( dataElement, event, dataValue.getValue(), dataValue.getStoredBy(), dataValue.getProvidedElsewhere(), - auditType); + changeLogType); - dataValueAuditService.addTrackedEntityDataValueAudit(dataValueAudit); + dataValueAuditService.addTrackedEntityDataValueChangeLog(dataValueAudit); } // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueAuditDeletionHandler.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueChangeLogDeletionHandler.java similarity index 90% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueAuditDeletionHandler.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueChangeLogDeletionHandler.java index 9831703513d1..e978ed596550 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueAuditDeletionHandler.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueChangeLogDeletionHandler.java @@ -30,7 +30,7 @@ import lombok.RequiredArgsConstructor; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.system.deletion.DeletionHandler; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.springframework.stereotype.Component; /** @@ -38,8 +38,8 @@ */ @Component @RequiredArgsConstructor -public class TrackedEntityDataValueAuditDeletionHandler extends DeletionHandler { - private final TrackedEntityDataValueAuditService trackedEntityDataValueAuditService; +public class TrackedEntityDataValueChangeLogDeletionHandler extends DeletionHandler { + private final TrackedEntityDataValueChangeLogService trackedEntityDataValueAuditService; @Override protected void register() { @@ -48,10 +48,10 @@ protected void register() { } private void deleteDataElement(DataElement dataElement) { - trackedEntityDataValueAuditService.deleteTrackedEntityDataValueAudit(dataElement); + trackedEntityDataValueAuditService.deleteTrackedEntityDataValueChangeLog(dataElement); } private void deleteEvent(Event event) { - trackedEntityDataValueAuditService.deleteTrackedEntityDataValueAudit(event); + trackedEntityDataValueAuditService.deleteTrackedEntityDataValueChangeLog(event); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAuditService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityChangeLogService.java similarity index 72% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAuditService.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityChangeLogService.java index 866bcdd2f8b7..6d0f9955036e 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAuditService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityChangeLogService.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; import org.hisp.dhis.user.CurrentUserService; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -40,9 +39,9 @@ * @author Abyot Asalefew Gizaw abyota@gmail.com */ @RequiredArgsConstructor -@Service("org.hisp.dhis.trackedentity.TrackedEntityAuditService") -public class DefaultTrackedEntityAuditService implements TrackedEntityAuditService { - private final TrackedEntityAuditStore trackedEntityAuditStore; +@Service("org.hisp.dhis.trackedentity.TrackedEntityChangeLogService") +public class DefaultTrackedEntityChangeLogService implements TrackedEntityChangeLogService { + private final TrackedEntityChangeLogStore trackedEntityChangeLogStore; private final TrackedEntityStore trackedEntityStore; @@ -57,27 +56,22 @@ public class DefaultTrackedEntityAuditService implements TrackedEntityAuditServi @Override @Async @Transactional - public void addTrackedEntityAudit(TrackedEntityAudit trackedEntityAudit) { - trackedEntityAuditStore.addTrackedEntityAudit(trackedEntityAudit); + public void addTrackedEntityChangeLog(TrackedEntityChangeLog trackedEntityChangeLog) { + trackedEntityChangeLogStore.addTrackedEntityChangeLog(trackedEntityChangeLog); } @Override @Async @Transactional - public void addTrackedEntityAudit(List trackedEntityAudits) { - trackedEntityAuditStore.addTrackedEntityAudit(trackedEntityAudits); - } - - @Override - @Transactional - public void deleteTrackedEntityAudit(TrackedEntity trackedEntity) { - trackedEntityAuditStore.deleteTrackedEntityAudit(trackedEntity); + public void addTrackedEntityChangeLog(List trackedEntityChangeLogs) { + trackedEntityChangeLogStore.addTrackedEntityChangeLog(trackedEntityChangeLogs); } @Override @Transactional(readOnly = true) - public List getTrackedEntityAudits(TrackedEntityAuditQueryParams params) { - return trackedEntityAuditStore.getTrackedEntityAudits(params).stream() + public List getTrackedEntityChangeLogs( + TrackedEntityChangeLogQueryParams params) { + return trackedEntityChangeLogStore.getTrackedEntityChangeLogs(params).stream() .filter( a -> trackerAccessManager @@ -90,7 +84,7 @@ public List getTrackedEntityAudits(TrackedEntityAuditQueryPa @Override @Transactional(readOnly = true) - public int getTrackedEntityAuditsCount(TrackedEntityAuditQueryParams params) { - return trackedEntityAuditStore.getTrackedEntityAuditsCount(params); + public int getTrackedEntityChangeLogsCount(TrackedEntityChangeLogQueryParams params) { + return trackedEntityChangeLogStore.getTrackedEntityChangeLogsCount(params); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java index 2aabe00c9230..fd1851f8f820 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityService.java @@ -58,9 +58,8 @@ import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.AccessLevel; -import org.hisp.dhis.common.AuditType; import org.hisp.dhis.common.Grid; import org.hisp.dhis.common.GridHeader; import org.hisp.dhis.common.IllegalQueryException; @@ -73,7 +72,7 @@ import org.hisp.dhis.security.acl.AclService; import org.hisp.dhis.system.grid.ListGrid; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; @@ -109,9 +108,9 @@ public class DefaultTrackedEntityService implements TrackedEntityService { private final TrackerOwnershipManager trackerOwnershipAccessManager; - private final TrackedEntityAuditService trackedEntityAuditService; + private final TrackedEntityChangeLogService trackedEntityChangeLogService; - private final TrackedEntityAttributeValueAuditService attributeValueAuditService; + private final TrackedEntityAttributeValueChangeLogService attributeValueAuditService; // TODO: FIXME luciano using @Lazy here because we have circular // dependencies: @@ -126,8 +125,8 @@ public DefaultTrackedEntityService( CurrentUserService currentUserService, AclService aclService, @Lazy TrackerOwnershipManager trackerOwnershipAccessManager, - @Lazy TrackedEntityAuditService trackedEntityAuditService, - @Lazy TrackedEntityAttributeValueAuditService attributeValueAuditService) { + @Lazy TrackedEntityChangeLogService trackedEntityChangeLogService, + @Lazy TrackedEntityAttributeValueChangeLogService attributeValueAuditService) { checkNotNull(trackedEntityStore); checkNotNull(attributeValueService); checkNotNull(attributeService); @@ -136,7 +135,7 @@ public DefaultTrackedEntityService( checkNotNull(currentUserService); checkNotNull(aclService); checkNotNull(trackerOwnershipAccessManager); - checkNotNull(trackedEntityAuditService); + checkNotNull(trackedEntityChangeLogService); checkNotNull(attributeValueAuditService); this.trackedEntityStore = trackedEntityStore; @@ -147,7 +146,7 @@ public DefaultTrackedEntityService( this.currentUserService = currentUserService; this.aclService = aclService; this.trackerOwnershipAccessManager = trackerOwnershipAccessManager; - this.trackedEntityAuditService = trackedEntityAuditService; + this.trackedEntityChangeLogService = trackedEntityChangeLogService; this.attributeValueAuditService = attributeValueAuditService; } @@ -191,7 +190,7 @@ public List getTrackedEntities( String accessedBy = user != null ? user.getUsername() : currentUserService.getCurrentUsername(); for (TrackedEntity te : trackedEntities) { - addTrackedEntityAudit(te, accessedBy, AuditType.SEARCH); + addTrackedEntityAudit(te, accessedBy, ChangeLogType.SEARCH); } return trackedEntities; @@ -374,9 +373,10 @@ public Grid getTrackedEntitiesGrid(TrackedEntityQueryParams params) { } if (te != null && te.isAllowAuditLog() && accessedBy != null) { - TrackedEntityAudit trackedEntityAudit = - new TrackedEntityAudit(entity.get(TRACKED_ENTITY_ID), accessedBy, AuditType.SEARCH); - trackedEntityAuditService.addTrackedEntityAudit(trackedEntityAudit); + TrackedEntityChangeLog trackedEntityChangeLog = + new TrackedEntityChangeLog( + entity.get(TRACKED_ENTITY_ID), accessedBy, ChangeLogType.SEARCH); + trackedEntityChangeLogService.addTrackedEntityChangeLog(trackedEntityChangeLog); } for (QueryItem item : params.getAttributes()) { @@ -783,7 +783,7 @@ public void updateTrackedEntityLastUpdated(Set trackedEntityUIDs, Date l @Override @Transactional public void deleteTrackedEntity(TrackedEntity trackedEntity) { - attributeValueAuditService.deleteTrackedEntityAttributeValueAudits(trackedEntity); + attributeValueAuditService.deleteTrackedEntityAttributeValueChangeLogs(trackedEntity); trackedEntityStore.delete(trackedEntity); } @@ -792,7 +792,7 @@ public void deleteTrackedEntity(TrackedEntity trackedEntity) { public TrackedEntity getTrackedEntity(long id) { TrackedEntity te = trackedEntityStore.get(id); - addTrackedEntityAudit(te, currentUserService.getCurrentUsername(), AuditType.READ); + addTrackedEntityAudit(te, currentUserService.getCurrentUsername(), ChangeLogType.READ); return te; } @@ -801,7 +801,7 @@ public TrackedEntity getTrackedEntity(long id) { @Transactional public TrackedEntity getTrackedEntity(String uid) { TrackedEntity te = trackedEntityStore.getByUid(uid); - addTrackedEntityAudit(te, currentUserService.getCurrentUsername(), AuditType.READ); + addTrackedEntityAudit(te, currentUserService.getCurrentUsername(), ChangeLogType.READ); return te; } @@ -809,7 +809,7 @@ public TrackedEntity getTrackedEntity(String uid) { @Override public TrackedEntity getTrackedEntity(String uid, User user) { TrackedEntity te = trackedEntityStore.getByUid(uid); - addTrackedEntityAudit(te, User.username(user), AuditType.READ); + addTrackedEntityAudit(te, User.username(user), ChangeLogType.READ); return te; } @@ -859,14 +859,14 @@ private boolean isLocalSearch(TrackedEntityQueryParams params, User user) { } private void addTrackedEntityAudit( - TrackedEntity trackedEntity, String user, AuditType auditType) { + TrackedEntity trackedEntity, String user, ChangeLogType changeLogType) { if (user != null && trackedEntity != null && trackedEntity.getTrackedEntityType() != null && trackedEntity.getTrackedEntityType().isAllowAuditLog()) { - TrackedEntityAudit trackedEntityAudit = - new TrackedEntityAudit(trackedEntity.getUid(), user, auditType); - trackedEntityAuditService.addTrackedEntityAudit(trackedEntityAudit); + TrackedEntityChangeLog trackedEntityChangeLog = + new TrackedEntityChangeLog(trackedEntity.getUid(), user, changeLogType); + trackedEntityChangeLogService.addTrackedEntityChangeLog(trackedEntityChangeLog); } } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAuditStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityChangeLogStore.java similarity index 74% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAuditStore.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityChangeLogStore.java index a37502b2bbbf..d1994536694f 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityAuditStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityChangeLogStore.java @@ -38,13 +38,12 @@ import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; import org.hisp.dhis.hibernate.HibernateGenericStore; import org.hisp.dhis.hibernate.JpaQueryParameters; import org.hisp.dhis.jdbc.StatementBuilder; -import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentity.TrackedEntityAuditQueryParams; -import org.hisp.dhis.trackedentity.TrackedEntityAuditStore; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLog; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogQueryParams; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogStore; import org.springframework.context.ApplicationEventPublisher; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -52,18 +51,18 @@ /** * @author Abyot Asalefew Gizaw abyota@gmail.com */ -@Repository("org.hisp.dhis.trackedentity.TrackedEntityAuditStore") -public class HibernateTrackedEntityAuditStore extends HibernateGenericStore - implements TrackedEntityAuditStore { +@Repository("org.hisp.dhis.trackedentity.TrackedEntityChangeLogStore") +public class HibernateTrackedEntityChangeLogStore + extends HibernateGenericStore implements TrackedEntityChangeLogStore { private final StatementBuilder statementBuilder; - public HibernateTrackedEntityAuditStore( + public HibernateTrackedEntityChangeLogStore( EntityManager entityManager, JdbcTemplate jdbcTemplate, ApplicationEventPublisher publisher, StatementBuilder statementBuilder) { - super(entityManager, jdbcTemplate, publisher, TrackedEntityAudit.class, false); + super(entityManager, jdbcTemplate, publisher, TrackedEntityChangeLog.class, false); this.statementBuilder = statementBuilder; } @@ -72,12 +71,12 @@ public HibernateTrackedEntityAuditStore( // ------------------------------------------------------------------------- @Override - public void addTrackedEntityAudit(TrackedEntityAudit trackedEntityAudit) { - getSession().save(trackedEntityAudit); + public void addTrackedEntityChangeLog(TrackedEntityChangeLog trackedEntityChangeLog) { + getSession().save(trackedEntityChangeLog); } @Override - public void addTrackedEntityAudit(List trackedEntityAudit) { + public void addTrackedEntityChangeLog(List trackedEntityChangeLog) { final String sql = "INSERT INTO trackedentityaudit (" + "trackedentityauditid, " @@ -87,7 +86,7 @@ public void addTrackedEntityAudit(List trackedEntityAudit) { + "audittype, " + "comment ) VALUES "; - Function mapToString = + Function mapToString = audit -> { StringBuilder sb = new StringBuilder(); sb.append("("); @@ -105,24 +104,19 @@ public void addTrackedEntityAudit(List trackedEntityAudit) { }; final String values = - trackedEntityAudit.stream().map(mapToString).collect(Collectors.joining(",")); + trackedEntityChangeLog.stream().map(mapToString).collect(Collectors.joining(",")); getSession().createNativeQuery(sql + values).executeUpdate(); } @Override - public void deleteTrackedEntityAudit(TrackedEntity trackedEntity) { - String hql = "delete TrackedEntityAudit where trackedEntity = :trackedEntity"; - getSession().createQuery(hql).setParameter("trackedEntity", trackedEntity).executeUpdate(); - } - - @Override - public List getTrackedEntityAudits(TrackedEntityAuditQueryParams params) { + public List getTrackedEntityChangeLogs( + TrackedEntityChangeLogQueryParams params) { CriteriaBuilder builder = getCriteriaBuilder(); - JpaQueryParameters jpaParameters = + JpaQueryParameters jpaParameters = newJpaParameters() - .addPredicates(getTrackedEntityAuditPredicates(params, builder)) + .addPredicates(getTrackedEntityPredicates(params, builder)) .addOrder(root -> builder.desc(root.get("created"))); if (params.hasPaging()) { @@ -135,20 +129,20 @@ public List getTrackedEntityAudits(TrackedEntityAuditQueryPa } @Override - public int getTrackedEntityAuditsCount(TrackedEntityAuditQueryParams params) { + public int getTrackedEntityChangeLogsCount(TrackedEntityChangeLogQueryParams params) { CriteriaBuilder builder = getCriteriaBuilder(); return getCount( builder, newJpaParameters() - .addPredicates(getTrackedEntityAuditPredicates(params, builder)) + .addPredicates(getTrackedEntityPredicates(params, builder)) .count(root -> builder.countDistinct(root.get("id")))) .intValue(); } - private List, Predicate>> getTrackedEntityAuditPredicates( - TrackedEntityAuditQueryParams params, CriteriaBuilder builder) { - List, Predicate>> predicates = new ArrayList<>(); + private List, Predicate>> getTrackedEntityPredicates( + TrackedEntityChangeLogQueryParams params, CriteriaBuilder builder) { + List, Predicate>> predicates = new ArrayList<>(); if (params.hasTrackedEntities()) { predicates.add(root -> root.get("trackedEntity").in(params.getTrackedEntities())); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueChangeLogService.java similarity index 69% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueChangeLogService.java index 859efe277896..96d2eca13b09 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueChangeLogService.java @@ -41,31 +41,29 @@ * @author Morten Olav Hansen */ @RequiredArgsConstructor -@Service("org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService") -public class DefaultTrackedEntityAttributeValueAuditService - implements TrackedEntityAttributeValueAuditService { - private final TrackedEntityAttributeValueAuditStore trackedEntityAttributeValueAuditStore; +@Service("org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService") +public class DefaultTrackedEntityAttributeValueChangeLogService + implements TrackedEntityAttributeValueChangeLogService { + private final TrackedEntityAttributeValueChangeLogStore attributeValueChangeLogStore; private final TrackedEntityAttributeService trackedEntityAttributeService; private final CurrentUserService currentUserService; @Override - public void addTrackedEntityAttributeValueAudit( - TrackedEntityAttributeValueAudit trackedEntityAttributeValueAudit) { - trackedEntityAttributeValueAuditStore.addTrackedEntityAttributeValueAudit( - trackedEntityAttributeValueAudit); + public void addTrackedEntityAttributeValueChangLog( + TrackedEntityAttributeValueChangeLog attributeValueChangeLog) { + attributeValueChangeLogStore.addTrackedEntityAttributeValueChangeLog(attributeValueChangeLog); } @Override - public List getTrackedEntityAttributeValueAudits( - TrackedEntityAttributeValueAuditQueryParams params) { - return aclFilter( - trackedEntityAttributeValueAuditStore.getTrackedEntityAttributeValueAudits(params)); + public List getTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params) { + return aclFilter(attributeValueChangeLogStore.getTrackedEntityAttributeValueChangeLogs(params)); } - private List aclFilter( - List trackedEntityAttributeValueAudits) { + private List aclFilter( + List attributeValueChangeLogs) { // Fetch all the Tracked Entity Attributes this user has access // to (only store UIDs). Not a very efficient solution, but at the // moment @@ -78,20 +76,20 @@ private List aclFilter( .map(IdentifiableObject::getUid) .collect(Collectors.toSet()); - return trackedEntityAttributeValueAudits.stream() + return attributeValueChangeLogs.stream() .filter( audit -> allUserReadableTrackedEntityAttributes.contains(audit.getAttribute().getUid())) .collect(Collectors.toList()); } @Override - public int countTrackedEntityAttributeValueAudits( - TrackedEntityAttributeValueAuditQueryParams params) { - return trackedEntityAttributeValueAuditStore.countTrackedEntityAttributeValueAudits(params); + public int countTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params) { + return attributeValueChangeLogStore.countTrackedEntityAttributeValueChangeLogs(params); } @Override - public void deleteTrackedEntityAttributeValueAudits(TrackedEntity trackedEntity) { - trackedEntityAttributeValueAuditStore.deleteTrackedEntityAttributeValueAudits(trackedEntity); + public void deleteTrackedEntityAttributeValueChangeLogs(TrackedEntity trackedEntity) { + attributeValueChangeLogStore.deleteTrackedEntityAttributeValueChangeLogs(trackedEntity); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java index 17fdcc628107..23119efc0aed 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java @@ -35,7 +35,7 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.external.conf.DhisConfigurationProvider; import org.hisp.dhis.fileresource.FileResource; @@ -59,7 +59,8 @@ public class DefaultTrackedEntityAttributeValueService private final FileResourceService fileResourceService; - private final TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService; + private final TrackedEntityAttributeValueChangeLogService + trackedEntityAttributeValueChangeLogService; private final ReservedValueService reservedValueService; @@ -74,16 +75,16 @@ public class DefaultTrackedEntityAttributeValueService @Override @Transactional public void deleteTrackedEntityAttributeValue(TrackedEntityAttributeValue attributeValue) { - TrackedEntityAttributeValueAudit trackedEntityAttributeValueAudit = - new TrackedEntityAttributeValueAudit( + TrackedEntityAttributeValueChangeLog trackedEntityAttributeValueChangeLog = + new TrackedEntityAttributeValueChangeLog( attributeValue, attributeValue.getAuditValue(), currentUserService.getCurrentUsername(), - AuditType.DELETE); + ChangeLogType.DELETE); if (config.isEnabled(CHANGELOG_TRACKER)) { - trackedEntityAttributeValueAuditService.addTrackedEntityAttributeValueAudit( - trackedEntityAttributeValueAudit); + trackedEntityAttributeValueChangeLogService.addTrackedEntityAttributeValueChangLog( + trackedEntityAttributeValueChangeLog); } deleteFileValue(attributeValue); @@ -188,16 +189,16 @@ public void updateTrackedEntityAttributeValue( throw new IllegalQueryException("Value is not valid: " + result); } - TrackedEntityAttributeValueAudit trackedEntityAttributeValueAudit = - new TrackedEntityAttributeValueAudit( + TrackedEntityAttributeValueChangeLog trackedEntityAttributeValueChangeLog = + new TrackedEntityAttributeValueChangeLog( attributeValue, attributeValue.getAuditValue(), User.username(user), - AuditType.UPDATE); + ChangeLogType.UPDATE); if (config.isEnabled(CHANGELOG_TRACKER)) { - trackedEntityAttributeValueAuditService.addTrackedEntityAttributeValueAudit( - trackedEntityAttributeValueAudit); + trackedEntityAttributeValueChangeLogService.addTrackedEntityAttributeValueChangLog( + trackedEntityAttributeValueChangeLog); } attributeValueStore.update(attributeValue); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueChangeLogStore.java similarity index 69% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueChangeLogStore.java index 8ee71ff1bc1c..6f9fcf34d650 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueChangeLogStore.java @@ -37,21 +37,21 @@ import org.hibernate.Session; import org.hibernate.query.Query; import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditQueryParams; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditStore; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLog; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogQueryParams; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogStore; import org.springframework.stereotype.Repository; /** * @author Morten Olav Hansen */ -@Repository("org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditStore") -public class HibernateTrackedEntityAttributeValueAuditStore - implements TrackedEntityAttributeValueAuditStore { +@Repository("org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogStore") +public class HibernateTrackedEntityAttributeValueChangeLogStore + implements TrackedEntityAttributeValueChangeLogStore { private EntityManager entityManager; private Session session; - public HibernateTrackedEntityAttributeValueAuditStore(EntityManager entityManager) { + public HibernateTrackedEntityAttributeValueChangeLogStore(EntityManager entityManager) { this.entityManager = entityManager; this.session = entityManager.unwrap(Session.class); } @@ -61,27 +61,27 @@ public HibernateTrackedEntityAttributeValueAuditStore(EntityManager entityManage // ------------------------------------------------------------------------- @Override - public void addTrackedEntityAttributeValueAudit( - TrackedEntityAttributeValueAudit trackedEntityAttributeValueAudit) { - session.save(trackedEntityAttributeValueAudit); + public void addTrackedEntityAttributeValueChangeLog( + TrackedEntityAttributeValueChangeLog attributeValueChangeLog) { + session.save(attributeValueChangeLog); } @Override - public List getTrackedEntityAttributeValueAudits( - TrackedEntityAttributeValueAuditQueryParams params) { + public List getTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - CriteriaQuery criteria = - builder.createQuery(TrackedEntityAttributeValueAudit.class); + CriteriaQuery criteria = + builder.createQuery(TrackedEntityAttributeValueChangeLog.class); - Root root = - criteria.from(TrackedEntityAttributeValueAudit.class); + Root root = + criteria.from(TrackedEntityAttributeValueChangeLog.class); - List predicates = getTrackedEntityAttributeValueAuditCriteria(root, params); + List predicates = getTrackedEntityAttributeValueCriteria(root, params); criteria.where(predicates.toArray(new Predicate[0])).orderBy(builder.desc(root.get("created"))); - Query query = session.createQuery(criteria); + Query query = session.createQuery(criteria); if (params.hasPager()) { query @@ -93,16 +93,16 @@ public List getTrackedEntityAttributeValueAudi } @Override - public int countTrackedEntityAttributeValueAudits( - TrackedEntityAttributeValueAuditQueryParams params) { + public int countTrackedEntityAttributeValueChangeLogs( + TrackedEntityAttributeValueChangeLogQueryParams params) { CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(Long.class); - Root root = - query.from(TrackedEntityAttributeValueAudit.class); + Root root = + query.from(TrackedEntityAttributeValueChangeLog.class); - List predicates = getTrackedEntityAttributeValueAuditCriteria(root, params); + List predicates = getTrackedEntityAttributeValueCriteria(root, params); query.select(builder.countDistinct(root.get("id"))).where(predicates.toArray(new Predicate[0])); @@ -110,17 +110,17 @@ public int countTrackedEntityAttributeValueAudits( } @Override - public void deleteTrackedEntityAttributeValueAudits(TrackedEntity trackedEntity) { + public void deleteTrackedEntityAttributeValueChangeLogs(TrackedEntity trackedEntity) { Query query = session.createQuery( - "delete TrackedEntityAttributeValueAudit where trackedEntity = :trackedEntity"); + "delete TrackedEntityAttributeValueChangeLog where trackedEntity = :trackedEntity"); query.setParameter("trackedEntity", trackedEntity); query.executeUpdate(); } - private List getTrackedEntityAttributeValueAuditCriteria( - Root root, - TrackedEntityAttributeValueAuditQueryParams params) { + private List getTrackedEntityAttributeValueCriteria( + Root root, + TrackedEntityAttributeValueChangeLogQueryParams params) { List predicates = new ArrayList<>(); if (!params.getTrackedEntityAttributes().isEmpty()) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueChangeLogService.java similarity index 64% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueChangeLogService.java index 6abf6b1baa11..4d4bc733dcde 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueChangeLogService.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.program.Event; -import org.hisp.dhis.trackedentity.TrackedEntityDataValueAuditQueryParams; +import org.hisp.dhis.trackedentity.TrackedEntityDataValueChangeLogQueryParams; import org.hisp.dhis.trackedentity.TrackerAccessManager; import org.hisp.dhis.user.CurrentUserService; import org.springframework.stereotype.Service; @@ -43,25 +43,25 @@ /** * @author Morten Olav Hansen */ -@Service("org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService") -public class DefaultTrackedEntityDataValueAuditService - implements TrackedEntityDataValueAuditService { - private final TrackedEntityDataValueAuditStore trackedEntityDataValueAuditStore; +@Service("org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService") +public class DefaultTrackedEntityDataValueChangeLogService + implements TrackedEntityDataValueChangeLogService { + private final TrackedEntityDataValueChangeLogStore trackedEntityDataValueChangeLogStore; - private final Predicate aclFilter; + private final Predicate aclFilter; - public DefaultTrackedEntityDataValueAuditService( - TrackedEntityDataValueAuditStore trackedEntityDataValueAuditStore, + public DefaultTrackedEntityDataValueChangeLogService( + TrackedEntityDataValueChangeLogStore trackedEntityDataValueChangeLogStore, TrackerAccessManager trackerAccessManager, CurrentUserService currentUserService) { - checkNotNull(trackedEntityDataValueAuditStore); + checkNotNull(trackedEntityDataValueChangeLogStore); checkNotNull(trackerAccessManager); checkNotNull(currentUserService); - this.trackedEntityDataValueAuditStore = trackedEntityDataValueAuditStore; + this.trackedEntityDataValueChangeLogStore = trackedEntityDataValueChangeLogStore; aclFilter = - (audit) -> + audit -> trackerAccessManager .canRead( currentUserService.getCurrentUser(), @@ -77,35 +77,37 @@ public DefaultTrackedEntityDataValueAuditService( @Override @Transactional - public void addTrackedEntityDataValueAudit( - TrackedEntityDataValueAudit trackedEntityDataValueAudit) { - trackedEntityDataValueAuditStore.addTrackedEntityDataValueAudit(trackedEntityDataValueAudit); + public void addTrackedEntityDataValueChangeLog( + TrackedEntityDataValueChangeLog trackedEntityDataValueChangeLog) { + trackedEntityDataValueChangeLogStore.addTrackedEntityDataValueChangeLog( + trackedEntityDataValueChangeLog); } @Override @Transactional(readOnly = true) - public List getTrackedEntityDataValueAudits( - TrackedEntityDataValueAuditQueryParams params) { - return trackedEntityDataValueAuditStore.getTrackedEntityDataValueAudits(params).stream() + public List getTrackedEntityDataValueChangeLogs( + TrackedEntityDataValueChangeLogQueryParams params) { + return trackedEntityDataValueChangeLogStore.getTrackedEntityDataValueChangeLogs(params).stream() .filter(aclFilter) .collect(Collectors.toList()); } @Override @Transactional(readOnly = true) - public int countTrackedEntityDataValueAudits(TrackedEntityDataValueAuditQueryParams params) { - return trackedEntityDataValueAuditStore.countTrackedEntityDataValueAudits(params); + public int countTrackedEntityDataValueChangeLogs( + TrackedEntityDataValueChangeLogQueryParams params) { + return trackedEntityDataValueChangeLogStore.countTrackedEntityDataValueChangeLogs(params); } @Override @Transactional - public void deleteTrackedEntityDataValueAudit(DataElement dataElement) { - trackedEntityDataValueAuditStore.deleteTrackedEntityDataValueAudit(dataElement); + public void deleteTrackedEntityDataValueChangeLog(DataElement dataElement) { + trackedEntityDataValueChangeLogStore.deleteTrackedEntityDataValueChangeLog(dataElement); } @Override @Transactional - public void deleteTrackedEntityDataValueAudit(Event event) { - trackedEntityDataValueAuditStore.deleteTrackedEntityDataValueAudit(event); + public void deleteTrackedEntityDataValueChangeLog(Event event) { + trackedEntityDataValueChangeLogStore.deleteTrackedEntityDataValueChangeLog(event); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueChangeLogStore.java similarity index 70% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueChangeLogStore.java index 18a347cd2a53..efe1553e3d06 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueChangeLogStore.java @@ -43,16 +43,17 @@ import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.program.Event; -import org.hisp.dhis.trackedentity.TrackedEntityDataValueAuditQueryParams; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditStore; +import org.hisp.dhis.trackedentity.TrackedEntityDataValueChangeLogQueryParams; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogStore; import org.springframework.stereotype.Repository; /** * @author Morten Olav Hansen */ -@Repository("org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditStore") -public class HibernateTrackedEntityDataValueAuditStore implements TrackedEntityDataValueAuditStore { +@Repository("org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogStore") +public class HibernateTrackedEntityDataValueChangeLogStore + implements TrackedEntityDataValueChangeLogStore { private static final String PROP_PSI = "event"; private static final String PROP_ORGANISATION_UNIT = "organisationUnit"; @@ -65,7 +66,7 @@ public class HibernateTrackedEntityDataValueAuditStore implements TrackedEntityD private EntityManager entityManager; - public HibernateTrackedEntityDataValueAuditStore(EntityManager entityManager) { + public HibernateTrackedEntityDataValueChangeLogStore(EntityManager entityManager) { this.entityManager = entityManager; } @@ -74,27 +75,28 @@ public HibernateTrackedEntityDataValueAuditStore(EntityManager entityManager) { // ------------------------------------------------------------------------- @Override - public void addTrackedEntityDataValueAudit( - TrackedEntityDataValueAudit trackedEntityDataValueAudit) { - entityManager.unwrap(Session.class).save(trackedEntityDataValueAudit); + public void addTrackedEntityDataValueChangeLog( + TrackedEntityDataValueChangeLog trackedEntityDataValueChangeLog) { + entityManager.unwrap(Session.class).save(trackedEntityDataValueChangeLog); } @Override @SuppressWarnings("unchecked") - public List getTrackedEntityDataValueAudits( - TrackedEntityDataValueAuditQueryParams params) { + public List getTrackedEntityDataValueChangeLogs( + TrackedEntityDataValueChangeLogQueryParams params) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - CriteriaQuery criteria = - builder.createQuery(TrackedEntityDataValueAudit.class); - Root tedva = criteria.from(TrackedEntityDataValueAudit.class); - Join event = tedva.join(PROP_PSI); + CriteriaQuery criteria = + builder.createQuery(TrackedEntityDataValueChangeLog.class); + Root tedvcl = + criteria.from(TrackedEntityDataValueChangeLog.class); + Join event = tedvcl.join(PROP_PSI); Join ou = event.join(PROP_ORGANISATION_UNIT); - criteria.select(tedva); + criteria.select(tedvcl); List predicates = - getTrackedEntityDataValueAuditCriteria(params, builder, tedva, event, ou); + getTrackedEntityDataValueAuditCriteria(params, builder, tedvcl, event, ou); criteria.where(predicates.toArray(Predicate[]::new)); - criteria.orderBy(builder.desc(tedva.get(PROP_CREATED))); + criteria.orderBy(builder.desc(tedvcl.get(PROP_CREATED))); Query query = entityManager.createQuery(criteria); @@ -108,45 +110,47 @@ public List getTrackedEntityDataValueAudits( } @Override - public int countTrackedEntityDataValueAudits(TrackedEntityDataValueAuditQueryParams params) { + public int countTrackedEntityDataValueChangeLogs( + TrackedEntityDataValueChangeLogQueryParams params) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Long.class); - Root tedva = criteria.from(TrackedEntityDataValueAudit.class); - Join event = tedva.join(PROP_PSI); + Root tedvcl = + criteria.from(TrackedEntityDataValueChangeLog.class); + Join event = tedvcl.join(PROP_PSI); Join ou = event.join(PROP_ORGANISATION_UNIT); - criteria.select(builder.countDistinct(tedva.get("id"))); + criteria.select(builder.countDistinct(tedvcl.get("id"))); List predicates = - getTrackedEntityDataValueAuditCriteria(params, builder, tedva, event, ou); + getTrackedEntityDataValueAuditCriteria(params, builder, tedvcl, event, ou); criteria.where(predicates.toArray(Predicate[]::new)); return entityManager.createQuery(criteria).getSingleResult().intValue(); } @Override - public void deleteTrackedEntityDataValueAudit(DataElement dataElement) { - String hql = "delete from TrackedEntityDataValueAudit d where d.dataElement = :de"; + public void deleteTrackedEntityDataValueChangeLog(DataElement dataElement) { + String hql = "delete from TrackedEntityDataValueChangeLog d where d.dataElement = :de"; entityManager.createQuery(hql).setParameter("de", dataElement).executeUpdate(); } @Override - public void deleteTrackedEntityDataValueAudit(Event event) { - String hql = "delete from TrackedEntityDataValueAudit d where d.event = :event"; + public void deleteTrackedEntityDataValueChangeLog(Event event) { + String hql = "delete from TrackedEntityDataValueChangeLog d where d.event = :event"; entityManager.createQuery(hql).setParameter("event", event).executeUpdate(); } private List getTrackedEntityDataValueAuditCriteria( - TrackedEntityDataValueAuditQueryParams params, + TrackedEntityDataValueChangeLogQueryParams params, CriteriaBuilder builder, - Root tedva, - Join event, + Root tedvcl, + Join event, Join ou) { List predicates = new ArrayList<>(); if (!params.getDataElements().isEmpty()) { - predicates.add(tedva.get("dataElement").in(params.getDataElements())); + predicates.add(tedvcl.get("dataElement").in(params.getDataElements())); } if (!params.getOrgUnits().isEmpty()) { @@ -164,7 +168,7 @@ private List getTrackedEntityDataValueAuditCriteria( } if (!params.getEvents().isEmpty()) { - predicates.add(tedva.get(PROP_PSI).in(params.getEvents())); + predicates.add(tedvcl.get(PROP_PSI).in(params.getEvents())); } if (!params.getProgramStages().isEmpty()) { @@ -172,15 +176,15 @@ private List getTrackedEntityDataValueAuditCriteria( } if (params.getStartDate() != null) { - predicates.add(builder.greaterThanOrEqualTo(tedva.get(PROP_CREATED), params.getStartDate())); + predicates.add(builder.greaterThanOrEqualTo(tedvcl.get(PROP_CREATED), params.getStartDate())); } if (params.getEndDate() != null) { - predicates.add(builder.lessThanOrEqualTo(tedva.get(PROP_CREATED), params.getEndDate())); + predicates.add(builder.lessThanOrEqualTo(tedvcl.get(PROP_CREATED), params.getEndDate())); } if (!params.getAuditTypes().isEmpty()) { - predicates.add(tedva.get("auditType").in(params.getAuditTypes())); + predicates.add(tedvcl.get("auditType").in(params.getAuditTypes())); } return predicates; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/datavalue/hibernate/DataValueAudit.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/datavalue/hibernate/DataValueAudit.hbm.xml index 4974a190e4a4..a0358b2e5eeb 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/datavalue/hibernate/DataValueAudit.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/datavalue/hibernate/DataValueAudit.hbm.xml @@ -35,7 +35,7 @@ - org.hisp.dhis.common.AuditType + org.hisp.dhis.changelog.ChangeLogType true 12 diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAudit.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityChangeLog.hbm.xml similarity index 83% rename from dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAudit.hbm.xml rename to dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityChangeLog.hbm.xml index 3d859c21578b..0b8808ccc0f2 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityAudit.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentity/hibernate/TrackedEntityChangeLog.hbm.xml @@ -4,7 +4,7 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + trackedentityinstanceaudit_sequence @@ -19,7 +19,7 @@ - org.hisp.dhis.common.AuditType + org.hisp.dhis.changelog.ChangeLogType true 12 diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml similarity index 92% rename from dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml rename to dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml index 9c619a47a37e..fc26babebfc1 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueAudit.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml @@ -4,7 +4,7 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - @@ -30,7 +30,7 @@ - org.hisp.dhis.common.AuditType + org.hisp.dhis.changelog.ChangeLogType true 12 diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueAudit.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueChangeLog.hbm.xml similarity index 90% rename from dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueAudit.hbm.xml rename to dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueChangeLog.hbm.xml index e6b6ee5340cf..a3d638c2bb6f 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueAudit.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueChangeLog.hbm.xml @@ -4,7 +4,7 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + @@ -28,7 +28,7 @@ - org.hisp.dhis.common.AuditType + org.hisp.dhis.changelog.ChangeLogType true 12 diff --git a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityServiceTest.java b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityServiceTest.java index 880f89bc431d..bb42944a9431 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityServiceTest.java +++ b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityServiceTest.java @@ -39,7 +39,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.program.Program; import org.hisp.dhis.security.acl.AclService; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; @@ -68,9 +68,9 @@ class DefaultTrackedEntityServiceTest { @Mock private TrackerOwnershipManager trackerOwnershipAccessManager; - @Mock private TrackedEntityAuditService trackedEntityAuditService; + @Mock private TrackedEntityChangeLogService trackedEntityChangeLogService; - @Mock private TrackedEntityAttributeValueAuditService attributeValueAuditService; + @Mock private TrackedEntityAttributeValueChangeLogService attributeValueAuditService; private TrackedEntityQueryParams params; @@ -88,7 +88,7 @@ void setup() { currentUserService, aclService, trackerOwnershipAccessManager, - trackedEntityAuditService, + trackedEntityChangeLogService, attributeValueAuditService); User user = new User(); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java index 88e6d0161426..9178ae8e9842 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java @@ -56,7 +56,7 @@ import org.hisp.dhis.calendar.CalendarService; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.IdScheme; import org.hisp.dhis.common.IdSchemes; @@ -929,7 +929,7 @@ private void saveDataValueDelete( internalValue, existingValue.getValue(), context.getStoredBy(dataValue), - AuditType.DELETE); + ChangeLogType.DELETE); context.getAuditBatchHandler().addObject(auditValue); } @@ -943,13 +943,13 @@ private void saveDataValueUpdate( ImportContext.DataValueContext valueContext, DataValue internalValue, DataValue existingValue) { - AuditType auditType = AuditType.UPDATE; + ChangeLogType changeLogType = ChangeLogType.UPDATE; if (internalValue.isNullValue() || internalValue.isDeleted() || dataValueIsZeroAndInsignificant(dataValue.getValue(), valueContext.getDataElement())) { internalValue.setDeleted(true); - auditType = AuditType.DELETE; + changeLogType = ChangeLogType.DELETE; importCount.incrementDeleted(); } else { @@ -965,14 +965,17 @@ private void saveDataValueUpdate( && !Objects.equals(existingValue.getValue(), internalValue.getValue())) { DataValueAudit auditValue = new DataValueAudit( - internalValue, existingValue.getValue(), context.getStoredBy(dataValue), auditType); + internalValue, + existingValue.getValue(), + context.getStoredBy(dataValue), + changeLogType); context.getAuditBatchHandler().addObject(auditValue); } if (valueContext.getDataElement().isFileType()) { FileResource fr = fileResourceService.getFileResource(existingValue.getValue()); - if (auditType == AuditType.DELETE) { + if (changeLogType == ChangeLogType.DELETE) { fileResourceService.deleteFileResource(fr); } else { if (fr != null && !fr.isAssigned()) { diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/EventManager.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/EventManager.java index a3d1762d0f3c..959ba0af37fb 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/EventManager.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/EventManager.java @@ -55,7 +55,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IdScheme; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dxf2.deprecated.tracker.event.DataValue; @@ -69,8 +69,8 @@ import org.hisp.dhis.program.Event; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramStage; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.hisp.dhis.user.CurrentUserService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -95,7 +95,7 @@ public class EventManager { @Nonnull private final EventPersistenceService eventPersistenceService; - @Nonnull private final TrackedEntityDataValueAuditService entityDataValueAuditService; + @Nonnull private final TrackedEntityDataValueChangeLogService entityDataValueAuditService; @Nonnull private final CurrentUserService currentUserService; @@ -368,7 +368,7 @@ private void auditTrackedEntityDataValueHistory( .orElse(new HashMap<>()); for (DataValue dv : event.getDataValues()) { - AuditType auditType = AuditType.READ; + ChangeLogType changeLogType = ChangeLogType.READ; DataElement dateElement = workContext.getDataElementMap().get(dv.getDataElement()); @@ -379,26 +379,26 @@ private void auditTrackedEntityDataValueHistory( EventDataValue eventDataValue = dataValueDBMap.get(dv.getDataElement()); if (eventDataValue == null) { - auditType = AuditType.CREATE; + changeLogType = ChangeLogType.CREATE; persistedDataValue = dv.getValue(); } else if (StringUtils.isEmpty(dv.getValue())) { - auditType = AuditType.DELETE; + changeLogType = ChangeLogType.DELETE; persistedDataValue = eventDataValue.getValue(); } else if (!dv.getValue().equals(eventDataValue.getValue())) { - auditType = AuditType.UPDATE; + changeLogType = ChangeLogType.UPDATE; persistedDataValue = eventDataValue.getValue(); } - TrackedEntityDataValueAudit audit = new TrackedEntityDataValueAudit(); + TrackedEntityDataValueChangeLog audit = new TrackedEntityDataValueChangeLog(); audit.setCreated(today); - audit.setAuditType(auditType); + audit.setAuditType(changeLogType); audit.setProvidedElsewhere(dv.getProvidedElsewhere()); audit.setEvent(psi); audit.setValue(persistedDataValue != null ? persistedDataValue : dv.getValue()); audit.setDataElement(workContext.getDataElementMap().get(dv.getDataElement())); audit.setModifiedBy(currentUserService.getCurrentUsername()); - entityDataValueAuditService.addTrackedEntityDataValueAudit(audit); + entityDataValueAuditService.addTrackedEntityDataValueChangeLog(audit); } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/AbstractTrackedEntityInstanceService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/AbstractTrackedEntityInstanceService.java index 0e446828a0c5..3808bb69d4d0 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/AbstractTrackedEntityInstanceService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/AbstractTrackedEntityInstanceService.java @@ -46,8 +46,7 @@ import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdSchemes; import org.hisp.dhis.common.IdentifiableObjectManager; @@ -91,7 +90,8 @@ import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; import org.hisp.dhis.trackedentity.TrackedEntityAttributeStore; -import org.hisp.dhis.trackedentity.TrackedEntityAuditService; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLog; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogService; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwner; import org.hisp.dhis.trackedentity.TrackedEntityQueryParams; import org.hisp.dhis.trackedentity.TrackedEntityService; @@ -142,7 +142,7 @@ public abstract class AbstractTrackedEntityInstanceService implements TrackedEnt protected EnrollmentService programInstanceService; - protected TrackedEntityAuditService trackedEntityAuditService; + protected TrackedEntityChangeLogService trackedEntityChangeLogService; protected CurrentUserService currentUserService; @@ -218,19 +218,19 @@ private void addSearchAudit(List trackedEntityInstances, trackedEntityTypeService.getAllTrackedEntityType().stream() .collect(Collectors.toMap(TrackedEntityType::getUid, t -> t)); - List auditable = + List auditable = trackedEntityInstances.stream() .filter(Objects::nonNull) .filter(tei -> tei.getTrackedEntityType() != null) .filter(tei -> tetMap.get(tei.getTrackedEntityType()).isAllowAuditLog()) .map( tei -> - new TrackedEntityAudit( - tei.getTrackedEntityInstance(), accessedBy, AuditType.SEARCH)) + new TrackedEntityChangeLog( + tei.getTrackedEntityInstance(), accessedBy, ChangeLogType.SEARCH)) .collect(Collectors.toList()); if (!auditable.isEmpty()) { - trackedEntityAuditService.addTrackedEntityAudit(auditable); + trackedEntityChangeLogService.addTrackedEntityChangeLog(auditable); } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/JacksonTrackedEntityInstanceService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/JacksonTrackedEntityInstanceService.java index 704b759806e2..d86e38c59622 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/JacksonTrackedEntityInstanceService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/JacksonTrackedEntityInstanceService.java @@ -54,7 +54,7 @@ import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; import org.hisp.dhis.trackedentity.TrackedEntityAttributeStore; -import org.hisp.dhis.trackedentity.TrackedEntityAuditService; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogService; import org.hisp.dhis.trackedentity.TrackedEntityService; import org.hisp.dhis.trackedentity.TrackedEntityTypeService; import org.hisp.dhis.trackedentity.TrackerAccessManager; @@ -100,7 +100,7 @@ public JacksonTrackedEntityInstanceService( TrackerOwnershipManager trackerOwnershipAccessManager, TrackedEntityInstanceAggregate trackedEntityInstanceAggregate, TrackedEntityAttributeStore trackedEntityAttributeStore, - TrackedEntityAuditService trackedEntityAuditService, + TrackedEntityChangeLogService trackedEntityChangeLogService, TrackedEntityTypeService trackedEntityTypeService, Notifier notifier, ObjectMapper jsonMapper, @@ -151,7 +151,7 @@ public JacksonTrackedEntityInstanceService( this.trackerOwnershipAccessManager = trackerOwnershipAccessManager; this.trackedEntityInstanceAggregate = trackedEntityInstanceAggregate; this.trackedEntityAttributeStore = trackedEntityAttributeStore; - this.trackedEntityAuditService = trackedEntityAuditService; + this.trackedEntityChangeLogService = trackedEntityChangeLogService; this.trackedEntityTypeService = trackedEntityTypeService; this.notifier = notifier; this.jsonMapper = jsonMapper; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java index ad18a1d2d406..facbde8724d7 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/DefaultTrackedEntityService.java @@ -37,9 +37,8 @@ import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.AccessLevel; -import org.hisp.dhis.common.AuditType; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.feedback.BadRequestException; import org.hisp.dhis.feedback.ForbiddenException; @@ -53,7 +52,8 @@ import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; -import org.hisp.dhis.trackedentity.TrackedEntityAuditService; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLog; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogService; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwner; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.trackedentity.TrackedEntityTypeService; @@ -83,7 +83,7 @@ class DefaultTrackedEntityService implements TrackedEntityService { private final TrackedEntityTypeService trackedEntityTypeService; - private final TrackedEntityAuditService trackedEntityAuditService; + private final TrackedEntityChangeLogService trackedEntityChangeLogService; private final CurrentUserService currentUserService; @@ -436,16 +436,16 @@ private void addSearchAudit(List trackedEntities, User user) { trackedEntityTypeService.getAllTrackedEntityType().stream() .collect(Collectors.toMap(TrackedEntityType::getUid, t -> t)); - List auditable = + List auditable = trackedEntities.stream() .filter(Objects::nonNull) .filter(te -> te.getTrackedEntityType() != null) .filter(te -> tetMap.get(te.getTrackedEntityType().getUid()).isAllowAuditLog()) - .map(te -> new TrackedEntityAudit(te.getUid(), accessedBy, AuditType.SEARCH)) + .map(te -> new TrackedEntityChangeLog(te.getUid(), accessedBy, ChangeLogType.SEARCH)) .toList(); if (!auditable.isEmpty()) { - trackedEntityAuditService.addTrackedEntityAudit(auditable); + trackedEntityChangeLogService.addTrackedEntityChangeLog(auditable); } } @@ -454,9 +454,9 @@ private void addTrackedEntityAudit(TrackedEntity trackedEntity, String user) { && trackedEntity != null && trackedEntity.getTrackedEntityType() != null && trackedEntity.getTrackedEntityType().isAllowAuditLog()) { - TrackedEntityAudit trackedEntityAudit = - new TrackedEntityAudit(trackedEntity.getUid(), user, AuditType.READ); - trackedEntityAuditService.addTrackedEntityAudit(trackedEntityAudit); + TrackedEntityChangeLog trackedEntityChangeLog = + new TrackedEntityChangeLog(trackedEntity.getUid(), user, ChangeLogType.READ); + trackedEntityChangeLogService.addTrackedEntityChangeLog(trackedEntityChangeLog); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java index 5285fb71f4c6..15d2c769d3d2 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/AbstractTrackerPersister.java @@ -42,7 +42,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.fileresource.FileResource; @@ -50,8 +50,8 @@ import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLog; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.AtomicMode; import org.hisp.dhis.tracker.imports.FlushMode; @@ -75,7 +75,8 @@ public abstract class AbstractTrackerPersister< implements TrackerPersister { protected final ReservedValueService reservedValueService; - protected final TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService; + protected final TrackedEntityAttributeValueChangeLogService + trackedEntityAttributeValueChangeLogService; /** * Template method that can be used by classes extending this class to execute the persistence @@ -371,7 +372,7 @@ private void delete( : entityManager.merge(trackedEntityAttributeValue)); logTrackedEntityAttributeValueHistory( - preheat.getUsername(), trackedEntityAttributeValue, trackedEntity, AuditType.DELETE); + preheat.getUsername(), trackedEntityAttributeValue, trackedEntity, ChangeLogType.DELETE); } private void saveOrUpdate( @@ -386,24 +387,24 @@ private void saveOrUpdate( entityManager, preheat, trackedEntity.getUid(), trackedEntityAttributeValue.getValue()); } - AuditType auditType = null; + ChangeLogType changeLogType = null; if (isNew) { entityManager.persist(trackedEntityAttributeValue); // In case it's a newly created attribute we'll add it back to TE, // so it can end up in preheat trackedEntity.getTrackedEntityAttributeValues().add(trackedEntityAttributeValue); - auditType = AuditType.CREATE; + changeLogType = ChangeLogType.CREATE; } else { entityManager.merge(trackedEntityAttributeValue); if (isUpdated) { - auditType = AuditType.UPDATE; + changeLogType = ChangeLogType.UPDATE; } } logTrackedEntityAttributeValueHistory( - preheat.getUsername(), trackedEntityAttributeValue, trackedEntity, auditType); + preheat.getUsername(), trackedEntityAttributeValue, trackedEntity, changeLogType); } private static boolean isFileResource(TrackedEntityAttributeValue trackedEntityAttributeValue) { @@ -435,16 +436,17 @@ private void logTrackedEntityAttributeValueHistory( String userName, TrackedEntityAttributeValue attributeValue, TrackedEntity trackedEntity, - AuditType auditType) { + ChangeLogType changeLogType) { boolean allowAuditLog = trackedEntity.getTrackedEntityType().isAllowAuditLog(); // create log entry only for updated, created and deleted attributes - if (allowAuditLog && auditType != null) { - TrackedEntityAttributeValueAudit valueAudit = - new TrackedEntityAttributeValueAudit( - attributeValue, attributeValue.getValue(), userName, auditType); + if (allowAuditLog && changeLogType != null) { + TrackedEntityAttributeValueChangeLog valueAudit = + new TrackedEntityAttributeValueChangeLog( + attributeValue, attributeValue.getValue(), userName, changeLogType); valueAudit.setTrackedEntity(trackedEntity); - trackedEntityAttributeValueAuditService.addTrackedEntityAttributeValueAudit(valueAudit); + trackedEntityAttributeValueChangeLogService.addTrackedEntityAttributeValueChangLog( + valueAudit); } } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java index 40ab40a3b245..336d41b6018c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EnrollmentPersister.java @@ -35,7 +35,7 @@ import org.hisp.dhis.program.Enrollment; import org.hisp.dhis.reservedvalue.ReservedValueService; import org.hisp.dhis.trackedentity.TrackedEntityProgramOwnerService; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.converter.TrackerConverterService; @@ -59,8 +59,8 @@ public EnrollmentPersister( TrackerConverterService enrollmentConverter, TrackedEntityProgramOwnerService trackedEntityProgramOwnerService, - TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService) { - super(reservedValueService, trackedEntityAttributeValueAuditService); + TrackedEntityAttributeValueChangeLogService trackedEntityAttributeValueChangeLogService) { + super(reservedValueService, trackedEntityAttributeValueChangeLogService); this.enrollmentConverter = enrollmentConverter; this.trackedEntityProgramOwnerService = trackedEntityProgramOwnerService; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java index eddfee32a5cc..0260033be2a1 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/EventPersister.java @@ -43,15 +43,15 @@ import lombok.Builder; import lombok.Data; import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.eventdatavalue.EventDataValue; import org.hisp.dhis.note.Note; import org.hisp.dhis.program.Event; import org.hisp.dhis.reservedvalue.ReservedValueService; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.converter.TrackerConverterService; @@ -70,16 +70,16 @@ public class EventPersister private final TrackerConverterService eventConverter; - private final TrackedEntityDataValueAuditService trackedEntityDataValueAuditService; + private final TrackedEntityDataValueChangeLogService trackedEntityDataValueAuditService; public EventPersister( ReservedValueService reservedValueService, TrackerConverterService eventConverter, - TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService, - TrackedEntityDataValueAuditService trackedEntityDataValueAuditService) { - super(reservedValueService, trackedEntityAttributeValueAuditService); + TrackedEntityAttributeValueChangeLogService trackedEntityAttributeValueChangeLogService, + TrackedEntityDataValueChangeLogService trackedEntityDataValueChangeLogService) { + super(reservedValueService, trackedEntityAttributeValueChangeLogService); this.eventConverter = eventConverter; - this.trackedEntityDataValueAuditService = trackedEntityDataValueAuditService; + this.trackedEntityDataValueAuditService = trackedEntityDataValueChangeLogService; } @Override @@ -205,19 +205,19 @@ private Date getFromOrNewDate(DataValue dv, Function dateGet private void logTrackedEntityDataValueHistory( String userName, DataElement de, Event event, Date created, ValuesHolder valuesHolder) { - AuditType auditType = valuesHolder.getAuditType(); + ChangeLogType changeLogType = valuesHolder.getChangeLogType(); - if (auditType != null) { - TrackedEntityDataValueAudit valueAudit = new TrackedEntityDataValueAudit(); + if (changeLogType != null) { + TrackedEntityDataValueChangeLog valueAudit = new TrackedEntityDataValueChangeLog(); valueAudit.setEvent(event); valueAudit.setValue(valuesHolder.getValue()); - valueAudit.setAuditType(auditType); + valueAudit.setAuditType(changeLogType); valueAudit.setDataElement(de); valueAudit.setModifiedBy(userName); valueAudit.setProvidedElsewhere(valuesHolder.isProvidedElseWhere()); valueAudit.setCreated(created); - trackedEntityDataValueAuditService.addTrackedEntityDataValueAudit(valueAudit); + trackedEntityDataValueAuditService.addTrackedEntityDataValueChangeLog(valueAudit); } } @@ -250,24 +250,24 @@ private boolean isUpdate(EventDataValue eventDataValue, DataValue dv) { private ValuesHolder getAuditAndDateParameters(EventDataValue eventDataValue, DataValue dv) { String persistedValue; - AuditType auditType = null; + ChangeLogType changeLogType = null; if (isNewDataValue(eventDataValue, dv)) { eventDataValue = new EventDataValue(); eventDataValue.setCreated(getFromOrNewDate(dv, DataValue::getCreatedAt)); eventDataValue.setLastUpdated(getFromOrNewDate(dv, DataValue::getUpdatedAt)); persistedValue = dv.getValue(); - auditType = AuditType.CREATE; + changeLogType = ChangeLogType.CREATE; } else { persistedValue = eventDataValue.getValue(); if (isUpdate(eventDataValue, dv)) { - auditType = AuditType.UPDATE; + changeLogType = ChangeLogType.UPDATE; eventDataValue.setLastUpdated(getFromOrNewDate(dv, DataValue::getUpdatedAt)); } if (isDeletion(eventDataValue, dv)) { - auditType = AuditType.DELETE; + changeLogType = ChangeLogType.DELETE; eventDataValue.setLastUpdated(getFromOrNewDate(dv, DataValue::getUpdatedAt)); } } @@ -275,7 +275,7 @@ private ValuesHolder getAuditAndDateParameters(EventDataValue eventDataValue, Da return ValuesHolder.builder() .value(persistedValue) .providedElseWhere(dv.isProvidedElsewhere()) - .auditType(auditType) + .changeLogType(changeLogType) .eventDataValue(eventDataValue) .build(); } @@ -287,7 +287,7 @@ static class ValuesHolder { private final boolean providedElseWhere; - private final AuditType auditType; + private final ChangeLogType changeLogType; private final EventDataValue eventDataValue; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/RelationshipPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/RelationshipPersister.java index 0a663fbbbfd4..50b9afd4b871 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/RelationshipPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/RelationshipPersister.java @@ -29,7 +29,7 @@ import javax.persistence.EntityManager; import org.hisp.dhis.reservedvalue.ReservedValueService; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.converter.TrackerConverterService; @@ -51,9 +51,9 @@ public RelationshipPersister( ReservedValueService reservedValueService, TrackerConverterService relationshipConverter, - TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService) { + TrackedEntityAttributeValueChangeLogService trackedEntityAttributeValueChangeLogService) { - super(reservedValueService, trackedEntityAttributeValueAuditService); + super(reservedValueService, trackedEntityAttributeValueChangeLogService); this.relationshipConverter = relationshipConverter; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackedEntityPersister.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackedEntityPersister.java index 4d9da077085d..8685a3049b7d 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackedEntityPersister.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/TrackedEntityPersister.java @@ -32,7 +32,7 @@ import javax.persistence.EntityManager; import org.hisp.dhis.reservedvalue.ReservedValueService; import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.tracker.TrackerType; import org.hisp.dhis.tracker.imports.bundle.TrackerBundle; import org.hisp.dhis.tracker.imports.converter.TrackerConverterService; @@ -56,8 +56,8 @@ public TrackedEntityPersister( ReservedValueService reservedValueService, TrackerConverterService teConverter, - TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService) { - super(reservedValueService, trackedEntityAttributeValueAuditService); + TrackedEntityAttributeValueChangeLogService trackedEntityAttributeValueChangeLogService) { + super(reservedValueService, trackedEntityAttributeValueChangeLogService); this.teConverter = teConverter; } diff --git a/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandler.java b/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandler.java index a7e424e3535c..b07293397419 100644 --- a/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandler.java +++ b/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandler.java @@ -32,7 +32,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.datavalue.DataValueAudit; import org.hisp.quick.JdbcConfiguration; import org.hisp.quick.batchhandler.AbstractBatchHandler; @@ -123,7 +123,7 @@ public DataValueAudit mapRow(ResultSet resultSet) throws SQLException { dva.setValue(resultSet.getString("value")); dva.setModifiedBy(resultSet.getString("modifiedby")); dva.setCreated(resultSet.getDate("created")); - dva.setAuditType(AuditType.valueOf(resultSet.getString("audittype"))); + dva.setAuditType(ChangeLogType.valueOf(resultSet.getString("audittype"))); return dva; } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/datavalue/DataValueAuditServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/datavalue/DataValueAuditServiceTest.java index 38c4752408f7..e469afaead6b 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/datavalue/DataValueAuditServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/datavalue/DataValueAuditServiceTest.java @@ -33,7 +33,7 @@ import java.util.List; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -135,10 +135,10 @@ public void setUpTest() throws Exception { void testAddGetDataValueAuditFromDataValue() { DataValueAudit dataValueAuditA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); DataValueAudit dataValueAuditB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); dataValueAuditService.addDataValueAudit(dataValueAuditA); dataValueAuditService.addDataValueAudit(dataValueAuditB); @@ -150,10 +150,10 @@ void testAddGetDataValueAuditFromDataValue() { void testAddGetDataValueAuditSingleRecord() { DataValueAudit dataValueAuditA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); DataValueAudit dataValueAuditB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); dataValueAuditService.addDataValueAudit(dataValueAuditA); dataValueAuditService.addDataValueAudit(dataValueAuditB); @@ -173,16 +173,16 @@ void testAddGetDataValueAuditSingleRecord() { void testGetDataValueAudit() { DataValueAudit dvaA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); DataValueAudit dvaB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); DataValueAudit dvaC = new DataValueAudit( - dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), AuditType.CREATE); + dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), ChangeLogType.CREATE); DataValueAudit dvaD = new DataValueAudit( - dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), AuditType.DELETE); + dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), ChangeLogType.DELETE); dataValueAuditService.addDataValueAudit(dvaA); dataValueAuditService.addDataValueAudit(dvaB); dataValueAuditService.addDataValueAudit(dvaC); @@ -194,7 +194,7 @@ void testGetDataValueAudit() { .setPeriods(List.of(periodA)) .setOrgUnits(List.of(orgUnitA)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(AuditType.UPDATE)); + .setAuditTypes(List.of(ChangeLogType.UPDATE)); assertContainsOnly(List.of(dvaA), dataValueAuditService.getDataValueAudits(params)); @@ -204,16 +204,17 @@ void testGetDataValueAudit() { .setPeriods(List.of(periodA, periodB)) .setOrgUnits(List.of(orgUnitA, orgUnitB)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(AuditType.UPDATE)); + .setAuditTypes(List.of(ChangeLogType.UPDATE)); assertContainsOnly(List.of(dvaA, dvaB), dataValueAuditService.getDataValueAudits(params)); - params = new DataValueAuditQueryParams().setAuditTypes(List.of(AuditType.CREATE)); + params = new DataValueAuditQueryParams().setAuditTypes(List.of(ChangeLogType.CREATE)); assertContainsOnly(List.of(dvaC), dataValueAuditService.getDataValueAudits(params)); params = - new DataValueAuditQueryParams().setAuditTypes(List.of(AuditType.CREATE, AuditType.DELETE)); + new DataValueAuditQueryParams() + .setAuditTypes(List.of(ChangeLogType.CREATE, ChangeLogType.DELETE)); assertContainsOnly(List.of(dvaC, dvaD), dataValueAuditService.getDataValueAudits(params)); } @@ -222,16 +223,16 @@ void testGetDataValueAudit() { void testGetDataValueAuditNoResult() { DataValueAudit dvaA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); DataValueAudit dvaB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); DataValueAudit dvaC = new DataValueAudit( - dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), AuditType.CREATE); + dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), ChangeLogType.CREATE); DataValueAudit dvaD = new DataValueAudit( - dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), AuditType.DELETE); + dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), ChangeLogType.DELETE); dataValueAuditService.addDataValueAudit(dvaA); dataValueAuditService.addDataValueAudit(dvaB); dataValueAuditService.addDataValueAudit(dvaC); @@ -243,7 +244,7 @@ void testGetDataValueAuditNoResult() { .setPeriods(List.of(periodD)) .setOrgUnits(List.of(orgUnitA)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(AuditType.UPDATE)); + .setAuditTypes(List.of(ChangeLogType.UPDATE)); assertEquals(0, dataValueAuditService.getDataValueAudits(params).size()); } @@ -256,7 +257,7 @@ void testGetDataValueAuditWithFakeCreate() { .setPeriods(List.of(periodD)) .setOrgUnits(List.of(orgUnitA)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(AuditType.UPDATE)); + .setAuditTypes(List.of(ChangeLogType.UPDATE)); assertEquals(0, dataValueAuditService.getDataValueAudits(params).size()); @@ -265,7 +266,7 @@ void testGetDataValueAuditWithFakeCreate() { dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(1, audits.size()); - assertEquals(AuditType.CREATE, audits.get(0).getAuditType()); + assertEquals(ChangeLogType.CREATE, audits.get(0).getAuditType()); } @Test @@ -278,43 +279,43 @@ void testGetDataValueAuditWithFakeCreate2() { dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(2, audits.size()); - assertEquals(AuditType.UPDATE, audits.get(0).getAuditType()); - assertEquals(AuditType.CREATE, audits.get(1).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(0).getAuditType()); + assertEquals(ChangeLogType.CREATE, audits.get(1).getAuditType()); } @Test void testGetDataValueAuditWithFakeCreateDeleteAndCreate() { dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); List audits = dataValueAuditService.getDataValueAudits( dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(4, audits.size()); - assertEquals(AuditType.CREATE, audits.get(3).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(2).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(1).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(0).getAuditType()); + assertEquals(ChangeLogType.CREATE, audits.get(3).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(2).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(1).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(0).getAuditType()); } @Test @Disabled void testGetDataValueAuditWithFakeCreateDelete2() { dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); dataValueService.deleteDataValue(dataValueA); @@ -323,10 +324,10 @@ void testGetDataValueAuditWithFakeCreateDelete2() { dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(4, audits.size()); - assertEquals(AuditType.CREATE, audits.get(3).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(2).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(1).getAuditType()); - assertEquals(AuditType.DELETE, audits.get(0).getAuditType()); + assertEquals(ChangeLogType.CREATE, audits.get(3).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(2).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(1).getAuditType()); + assertEquals(ChangeLogType.DELETE, audits.get(0).getAuditType()); } @Test @@ -340,13 +341,13 @@ void testGetDataValueAuditWithFakeCreateDeleteAndUndelete() { dataValueService.addDataValue(dataValue); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValue, "10", dataValue.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValue, "10", dataValue.getStoredBy(), ChangeLogType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValue, "20", dataValue.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValue, "20", dataValue.getStoredBy(), ChangeLogType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValue, "30", dataValue.getStoredBy(), AuditType.UPDATE)); + new DataValueAudit(dataValue, "30", dataValue.getStoredBy(), ChangeLogType.UPDATE)); dataValueService.deleteDataValue(dataValue); @@ -363,11 +364,11 @@ void testGetDataValueAuditWithFakeCreateDeleteAndUndelete() { dataElement, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(6, audits.size()); - assertEquals(AuditType.UPDATE, audits.get(0).getAuditType()); - assertEquals(AuditType.CREATE, audits.get(1).getAuditType()); - assertEquals(AuditType.DELETE, audits.get(2).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(3).getAuditType()); - assertEquals(AuditType.UPDATE, audits.get(4).getAuditType()); - assertEquals(AuditType.CREATE, audits.get(5).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(0).getAuditType()); + assertEquals(ChangeLogType.CREATE, audits.get(1).getAuditType()); + assertEquals(ChangeLogType.DELETE, audits.get(2).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(3).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(4).getAuditType()); + assertEquals(ChangeLogType.CREATE, audits.get(5).getAuditType()); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceIntegrationTest.java index 74f4225e9db5..8d64747df0cc 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceIntegrationTest.java @@ -60,7 +60,7 @@ import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IdScheme; import org.hisp.dhis.common.IdSchemes; import org.hisp.dhis.common.IdentifiableObjectManager; @@ -1321,7 +1321,7 @@ void testImportDataValuesUpdatedAudit() { () -> String.format( "expected change to dataValue %s to be audited once", dv)); - assertEquals(AuditType.UPDATE, audits.get(0).getAuditType()); + assertEquals(ChangeLogType.UPDATE, audits.get(0).getAuditType()); }) .collect(Collectors.toList())); } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java index 1e6ac8f700db..ddf0c215791a 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/jdbc/batchhandler/DataValueAuditBatchHandlerTest.java @@ -34,7 +34,7 @@ import java.util.List; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.datavalue.DataValue; @@ -126,10 +126,10 @@ public void setUpTest() { dataElementA, periodA, unitB, categoryOptionComboA, categoryOptionComboA, "10"); dataValueService.addDataValue(dataValueA); dataValueService.addDataValue(dataValueB); - auditA = new DataValueAudit(dataValueA, "11", storedBy, AuditType.UPDATE); - auditB = new DataValueAudit(dataValueA, "12", storedBy, AuditType.UPDATE); - auditC = new DataValueAudit(dataValueB, "21", storedBy, AuditType.UPDATE); - auditD = new DataValueAudit(dataValueB, "22", storedBy, AuditType.UPDATE); + auditA = new DataValueAudit(dataValueA, "11", storedBy, ChangeLogType.UPDATE); + auditB = new DataValueAudit(dataValueA, "12", storedBy, ChangeLogType.UPDATE); + auditC = new DataValueAudit(dataValueB, "21", storedBy, ChangeLogType.UPDATE); + auditD = new DataValueAudit(dataValueB, "22", storedBy, ChangeLogType.UPDATE); } @Override diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java index 6619ff554abb..7697e3ccbe4d 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/maintenance/MaintenanceServiceTest.java @@ -44,6 +44,7 @@ import org.hisp.dhis.audit.AuditScope; import org.hisp.dhis.audit.AuditService; import org.hisp.dhis.audit.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DeliveryChannel; import org.hisp.dhis.commons.util.RelationshipUtils; import org.hisp.dhis.dataelement.DataElement; @@ -72,8 +73,8 @@ import org.hisp.dhis.trackedentity.TrackedEntityService; import org.hisp.dhis.trackedentity.TrackedEntityType; import org.hisp.dhis.trackedentity.TrackedEntityTypeService; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.joda.time.DateTime; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -89,7 +90,7 @@ class MaintenanceServiceTest extends IntegrationTestBase { @Autowired private TrackedEntityService entityInstanceService; - @Autowired private TrackedEntityDataValueAuditService trackedEntityDataValueAuditService; + @Autowired private TrackedEntityDataValueChangeLogService trackedEntityDataValueAuditService; @Autowired private DataElementService dataElementService; @@ -314,15 +315,11 @@ void testDeleteSoftDeletedEnrollmentLinkedToATrackedEntityDataValueAudit() { eventA.setScheduledDate(enrollmentDate); eventA.setUid("UID-A"); eventService.addEvent(eventA); - TrackedEntityDataValueAudit trackedEntityDataValueAudit = - new TrackedEntityDataValueAudit( - dataElement, - eventA, - "value", - "modifiedBy", - false, - org.hisp.dhis.common.AuditType.UPDATE); - trackedEntityDataValueAuditService.addTrackedEntityDataValueAudit(trackedEntityDataValueAudit); + TrackedEntityDataValueChangeLog trackedEntityDataValueChangeLog = + new TrackedEntityDataValueChangeLog( + dataElement, eventA, "value", "modifiedBy", false, ChangeLogType.UPDATE); + trackedEntityDataValueAuditService.addTrackedEntityDataValueChangeLog( + trackedEntityDataValueChangeLog); long idA = enrollmentService.addEnrollment(enrollment); assertNotNull(enrollmentService.getEnrollment(idA)); enrollmentService.deleteEnrollment(enrollment); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogStoreTest.java similarity index 57% rename from dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java rename to dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogStoreTest.java index 3fce5282c839..f222e4146d48 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityChangeLogStoreTest.java @@ -33,8 +33,7 @@ import java.util.Date; import java.util.List; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.test.integration.SingleSetupIntegrationTestBase; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -45,46 +44,47 @@ class TrackedEntityAuditStoreTest extends SingleSetupIntegrationTestBase { private final Date CREATED = getDate(2022, 3, 1); - @Autowired private TrackedEntityAuditStore store; + @Autowired private TrackedEntityChangeLogStore store; - private final TrackedEntityAudit auditA = - new TrackedEntityAudit("WGW7UnVcIIb", "Access", CREATED, "userA", AuditType.CREATE); - private final TrackedEntityAudit auditB = - new TrackedEntityAudit("WGW7UnVcIIb", "Access", CREATED, "userB", AuditType.UPDATE); - private final TrackedEntityAudit auditC = - new TrackedEntityAudit("zIAwTY3Drrn", "Access", CREATED, "userA", AuditType.UPDATE); - private final TrackedEntityAudit auditD = - new TrackedEntityAudit("zIAwTY3Drrn", "Access", CREATED, "userB", AuditType.DELETE); + private final TrackedEntityChangeLog auditA = + new TrackedEntityChangeLog("WGW7UnVcIIb", "Access", CREATED, "userA", ChangeLogType.CREATE); + private final TrackedEntityChangeLog auditB = + new TrackedEntityChangeLog("WGW7UnVcIIb", "Access", CREATED, "userB", ChangeLogType.UPDATE); + private final TrackedEntityChangeLog auditC = + new TrackedEntityChangeLog("zIAwTY3Drrn", "Access", CREATED, "userA", ChangeLogType.UPDATE); + private final TrackedEntityChangeLog auditD = + new TrackedEntityChangeLog("zIAwTY3Drrn", "Access", CREATED, "userB", ChangeLogType.DELETE); @Test void shouldAuditTrackedEntity_whenAddAuditList() { - List trackedEntityAuditInput = List.of(auditA, auditB); + List trackedEntityAuditInput = List.of(auditA, auditB); - store.addTrackedEntityAudit(trackedEntityAuditInput); + store.addTrackedEntityChangeLog(trackedEntityAuditInput); - TrackedEntityAuditQueryParams params = - new TrackedEntityAuditQueryParams().setTrackedEntities(List.of("WGW7UnVcIIb")); + TrackedEntityChangeLogQueryParams params = + new TrackedEntityChangeLogQueryParams().setTrackedEntities(List.of("WGW7UnVcIIb")); - List trackedEntityAudits = store.getTrackedEntityAudits(params); + List trackedEntityAudits = store.getTrackedEntityChangeLogs(params); assertEquals(trackedEntityAuditInput.size(), trackedEntityAudits.size()); - TrackedEntityAudit entityAudit = filterByAuditType(trackedEntityAudits, AuditType.CREATE); + TrackedEntityChangeLog entityAudit = + filterByAuditType(trackedEntityAudits, ChangeLogType.CREATE); assertNotNull(entityAudit); assertEquals("userA", entityAudit.getAccessedBy()); assertEquals("WGW7UnVcIIb", entityAudit.getTrackedEntity()); - entityAudit = filterByAuditType(trackedEntityAudits, AuditType.UPDATE); + entityAudit = filterByAuditType(trackedEntityAudits, ChangeLogType.UPDATE); assertNotNull(entityAudit); assertEquals("userB", entityAudit.getAccessedBy()); assertEquals("WGW7UnVcIIb", entityAudit.getTrackedEntity()); } - private static TrackedEntityAudit filterByAuditType( - List trackedEntityAuditsStore, AuditType auditType) { + private static TrackedEntityChangeLog filterByAuditType( + List trackedEntityAuditsStore, ChangeLogType changeLogType) { return trackedEntityAuditsStore.stream() - .filter(a -> a.getAuditType() == auditType) + .filter(a -> a.getAuditType() == changeLogType) .findFirst() .orElse(null); } @@ -92,35 +92,35 @@ private static TrackedEntityAudit filterByAuditType( @Test void testGetAuditsByParams() { - store.addTrackedEntityAudit(auditA); - store.addTrackedEntityAudit(auditB); - store.addTrackedEntityAudit(auditC); - store.addTrackedEntityAudit(auditD); + store.addTrackedEntityChangeLog(auditA); + store.addTrackedEntityChangeLog(auditB); + store.addTrackedEntityChangeLog(auditC); + store.addTrackedEntityChangeLog(auditD); - TrackedEntityAuditQueryParams params = - new TrackedEntityAuditQueryParams().setTrackedEntities(List.of("WGW7UnVcIIb")); + TrackedEntityChangeLogQueryParams params = + new TrackedEntityChangeLogQueryParams().setTrackedEntities(List.of("WGW7UnVcIIb")); - assertContainsOnly(List.of(auditA, auditB), store.getTrackedEntityAudits(params)); + assertContainsOnly(List.of(auditA, auditB), store.getTrackedEntityChangeLogs(params)); - params = new TrackedEntityAuditQueryParams().setUsers(List.of("userA")); + params = new TrackedEntityChangeLogQueryParams().setUsers(List.of("userA")); - assertContainsOnly(List.of(auditA, auditC), store.getTrackedEntityAudits(params)); + assertContainsOnly(List.of(auditA, auditC), store.getTrackedEntityChangeLogs(params)); - params = new TrackedEntityAuditQueryParams().setAuditTypes(List.of(AuditType.UPDATE)); + params = new TrackedEntityChangeLogQueryParams().setAuditTypes(List.of(ChangeLogType.UPDATE)); - assertContainsOnly(List.of(auditB, auditC), store.getTrackedEntityAudits(params)); + assertContainsOnly(List.of(auditB, auditC), store.getTrackedEntityChangeLogs(params)); params = - new TrackedEntityAuditQueryParams() - .setAuditTypes(List.of(AuditType.CREATE, AuditType.DELETE)); + new TrackedEntityChangeLogQueryParams() + .setAuditTypes(List.of(ChangeLogType.CREATE, ChangeLogType.DELETE)); - assertContainsOnly(List.of(auditA, auditD), store.getTrackedEntityAudits(params)); + assertContainsOnly(List.of(auditA, auditD), store.getTrackedEntityChangeLogs(params)); params = - new TrackedEntityAuditQueryParams() + new TrackedEntityChangeLogQueryParams() .setTrackedEntities(List.of("WGW7UnVcIIb")) .setUsers(List.of("userA")); - assertContainsOnly(List.of(auditA), store.getTrackedEntityAudits(params)); + assertContainsOnly(List.of(auditA), store.getTrackedEntityChangeLogs(params)); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditStoreTest.java deleted file mode 100644 index e6d57d309990..000000000000 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueAuditStoreTest.java +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.trackedentity; - -import static org.hisp.dhis.utils.Assertions.assertContainsOnly; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.hisp.dhis.audit.UserInfoTestHelper; -import org.hisp.dhis.common.AuditType; -import org.hisp.dhis.common.OrganisationUnitSelectionMode; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.eventdatavalue.EventDataValue; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.program.Enrollment; -import org.hisp.dhis.program.EnrollmentService; -import org.hisp.dhis.program.Event; -import org.hisp.dhis.program.EventService; -import org.hisp.dhis.program.Program; -import org.hisp.dhis.program.ProgramService; -import org.hisp.dhis.program.ProgramStage; -import org.hisp.dhis.program.ProgramStageService; -import org.hisp.dhis.program.UserInfoSnapshot; -import org.hisp.dhis.test.integration.SingleSetupIntegrationTestBase; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditStore; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * @author Viet Nguyen - */ -class TrackedEntityDataValueAuditStoreTest extends SingleSetupIntegrationTestBase { - private static final String USER_A = "userA"; - - private static final UserInfoSnapshot USER_SNAP_A = UserInfoTestHelper.testUserInfo(USER_A); - - @Autowired private TrackedEntityDataValueAuditStore auditStore; - - @Autowired private TrackedEntityService entityInstanceService; - - @Autowired private OrganisationUnitService organisationUnitService; - - @Autowired private DataElementService dataElementService; - - @Autowired private ProgramService programService; - - @Autowired private ProgramStageService programStageService; - - @Autowired private EnrollmentService enrollmentService; - - @Autowired private EventService eventService; - - private OrganisationUnit ouA; - - private OrganisationUnit ouB; - - private OrganisationUnit ouC; - - private OrganisationUnit ouD; - - private OrganisationUnit ouE; - - private Program pA; - - private ProgramStage psA; - - private ProgramStage psB; - - private DataElement deA; - - private DataElement deB; - - private Event eventA; - - private Event eventB; - - private Event eventC; - - private Event eventD; - - private Event eventE; - - private EventDataValue dvA; - - private EventDataValue dvB; - - private EventDataValue dvC; - - private EventDataValue dvD; - - private EventDataValue dvE; - - @Override - public void setUpTest() { - ouA = createOrganisationUnit('A'); - ouB = createOrganisationUnit('B', ouA); - ouC = createOrganisationUnit('C', ouA); - ouD = createOrganisationUnit('D', ouB); - ouE = createOrganisationUnit('E', ouD); - organisationUnitService.addOrganisationUnit(ouA); - organisationUnitService.addOrganisationUnit(ouB); - organisationUnitService.addOrganisationUnit(ouC); - organisationUnitService.addOrganisationUnit(ouD); - organisationUnitService.addOrganisationUnit(ouE); - - pA = createProgram('A', new HashSet<>(), ouA); - programService.addProgram(pA); - - psA = new ProgramStage("StageA", pA); - psA.setSortOrder(1); - programStageService.saveProgramStage(psA); - psB = new ProgramStage("StageB", pA); - psB.setSortOrder(2); - programStageService.saveProgramStage(psB); - pA.setProgramStages(Set.of(psA, psB)); - programService.updateProgram(pA); - - deA = createDataElement('A'); - deB = createDataElement('B'); - dataElementService.addDataElement(deA); - dataElementService.addDataElement(deB); - - TrackedEntity teiA = createTrackedEntity(ouA); - entityInstanceService.addTrackedEntity(teiA); - - Enrollment enrollmentA = - enrollmentService.enrollTrackedEntity(teiA, pA, new Date(), new Date(), ouA); - - dvA = new EventDataValue(deA.getUid(), "A", USER_SNAP_A); - dvB = new EventDataValue(deB.getUid(), "B", USER_SNAP_A); - dvC = new EventDataValue(deA.getUid(), "C", USER_SNAP_A); - dvD = new EventDataValue(deB.getUid(), "D", USER_SNAP_A); - dvE = new EventDataValue(deB.getUid(), "E", USER_SNAP_A); - - eventA = createEvent(enrollmentA, psA, ouA, Set.of(dvA, dvB)); - eventB = createEvent(enrollmentA, psB, ouB, Set.of(dvC, dvD)); - eventC = createEvent(enrollmentA, psA, ouC, Set.of(dvA, dvB)); - eventD = createEvent(enrollmentA, psB, ouD, Set.of(dvC, dvD)); - eventE = createEvent(enrollmentA, psA, ouE, Set.of(dvA, dvE)); - eventService.addEvent(eventA); - eventService.addEvent(eventB); - eventService.addEvent(eventC); - eventService.addEvent(eventD); - eventService.addEvent(eventE); - } - - @Test - void testGetTrackedEntityDataValueAuditsByDataElement() { - TrackedEntityDataValueAudit dvaA = - new TrackedEntityDataValueAudit( - deA, eventA, dvA.getAuditValue(), USER_A, dvA.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaB = - new TrackedEntityDataValueAudit( - deB, eventA, dvB.getAuditValue(), USER_A, dvB.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaC = - new TrackedEntityDataValueAudit( - deA, eventB, dvC.getAuditValue(), USER_A, dvC.getProvidedElsewhere(), AuditType.UPDATE); - auditStore.addTrackedEntityDataValueAudit(dvaA); - auditStore.addTrackedEntityDataValueAudit(dvaB); - auditStore.addTrackedEntityDataValueAudit(dvaC); - - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() - .setDataElements(List.of(deA, deB)) - .setEvents(List.of(eventA)) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly(List.of(dvaA, dvaB), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(2, auditStore.countTrackedEntityDataValueAudits(params)); - - params = - new TrackedEntityDataValueAuditQueryParams() - .setDataElements(List.of(deA)) - .setEvents(List.of(eventA)) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly(List.of(dvaA), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(1, auditStore.countTrackedEntityDataValueAudits(params)); - } - - @Test - void testGetTrackedEntityDataValueAuditsByOrgUnitSelected() { - TrackedEntityDataValueAudit dvaA = - new TrackedEntityDataValueAudit( - deA, eventA, dvA.getAuditValue(), USER_A, dvA.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaB = - new TrackedEntityDataValueAudit( - deB, eventA, dvB.getAuditValue(), USER_A, dvB.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaC = - new TrackedEntityDataValueAudit( - deA, eventB, dvC.getAuditValue(), USER_A, dvC.getProvidedElsewhere(), AuditType.UPDATE); - auditStore.addTrackedEntityDataValueAudit(dvaA); - auditStore.addTrackedEntityDataValueAudit(dvaB); - auditStore.addTrackedEntityDataValueAudit(dvaC); - - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() - .setOrgUnits(List.of(ouA)) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly(List.of(dvaA, dvaB), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(2, auditStore.countTrackedEntityDataValueAudits(params)); - - params = - new TrackedEntityDataValueAuditQueryParams() - .setOrgUnits(List.of(ouB)) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly(List.of(dvaC), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(1, auditStore.countTrackedEntityDataValueAudits(params)); - } - - @Test - void testGetTrackedEntityDataValueAuditsByOrgUnitDescendants() { - TrackedEntityDataValueAudit dvaA = - new TrackedEntityDataValueAudit( - deA, eventA, dvA.getAuditValue(), USER_A, dvA.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaB = - new TrackedEntityDataValueAudit( - deB, eventB, dvB.getAuditValue(), USER_A, dvB.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaC = - new TrackedEntityDataValueAudit( - deA, eventC, dvC.getAuditValue(), USER_A, dvC.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaD = - new TrackedEntityDataValueAudit( - deB, eventD, dvD.getAuditValue(), USER_A, dvD.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaE = - new TrackedEntityDataValueAudit( - deA, eventE, dvE.getAuditValue(), USER_A, dvE.getProvidedElsewhere(), AuditType.UPDATE); - auditStore.addTrackedEntityDataValueAudit(dvaA); - auditStore.addTrackedEntityDataValueAudit(dvaB); - auditStore.addTrackedEntityDataValueAudit(dvaC); - auditStore.addTrackedEntityDataValueAudit(dvaD); - auditStore.addTrackedEntityDataValueAudit(dvaE); - - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() - .setOrgUnits(List.of(ouB)) - .setOuMode(OrganisationUnitSelectionMode.DESCENDANTS) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly( - List.of(dvaB, dvaD, dvaE), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(3, auditStore.countTrackedEntityDataValueAudits(params)); - - params = - new TrackedEntityDataValueAuditQueryParams() - .setOrgUnits(List.of(ouA)) - .setOuMode(OrganisationUnitSelectionMode.DESCENDANTS) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly( - List.of(dvaA, dvaB, dvaC, dvaD, dvaE), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(5, auditStore.countTrackedEntityDataValueAudits(params)); - } - - @Test - void testGetTrackedEntityDataValueAuditsByProgramStage() { - TrackedEntityDataValueAudit dvaA = - new TrackedEntityDataValueAudit( - deA, eventA, dvA.getAuditValue(), USER_A, dvA.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaB = - new TrackedEntityDataValueAudit( - deB, eventA, dvB.getAuditValue(), USER_A, dvB.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaC = - new TrackedEntityDataValueAudit( - deA, eventB, dvC.getAuditValue(), USER_A, dvC.getProvidedElsewhere(), AuditType.UPDATE); - auditStore.addTrackedEntityDataValueAudit(dvaA); - auditStore.addTrackedEntityDataValueAudit(dvaB); - auditStore.addTrackedEntityDataValueAudit(dvaC); - - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() - .setProgramStages(List.of(psA)) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly(List.of(dvaA, dvaB), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(2, auditStore.countTrackedEntityDataValueAudits(params)); - - params = - new TrackedEntityDataValueAuditQueryParams() - .setProgramStages(List.of(psB)) - .setAuditTypes(List.of(AuditType.UPDATE)); - assertContainsOnly(List.of(dvaC), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(1, auditStore.countTrackedEntityDataValueAudits(params)); - } - - @Test - void testGetTrackedEntityDataValueAuditsByStartEndDate() { - TrackedEntityDataValueAudit dvaA = - new TrackedEntityDataValueAudit( - deA, eventA, dvA.getAuditValue(), USER_A, dvA.getProvidedElsewhere(), AuditType.UPDATE); - dvaA.setCreated(getDate(2021, 6, 1)); - TrackedEntityDataValueAudit dvaB = - new TrackedEntityDataValueAudit( - deB, eventA, dvB.getAuditValue(), USER_A, dvB.getProvidedElsewhere(), AuditType.UPDATE); - dvaB.setCreated(getDate(2021, 7, 1)); - TrackedEntityDataValueAudit dvaC = - new TrackedEntityDataValueAudit( - deA, eventB, dvC.getAuditValue(), USER_A, dvC.getProvidedElsewhere(), AuditType.UPDATE); - dvaC.setCreated(getDate(2021, 8, 1)); - auditStore.addTrackedEntityDataValueAudit(dvaA); - auditStore.addTrackedEntityDataValueAudit(dvaB); - auditStore.addTrackedEntityDataValueAudit(dvaC); - - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() - .setDataElements(List.of(deA, deB)) - .setStartDate(getDate(2021, 6, 15)) - .setEndDate(getDate(2021, 8, 15)); - assertContainsOnly(List.of(dvaB, dvaC), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(2, auditStore.countTrackedEntityDataValueAudits(params)); - - params = - new TrackedEntityDataValueAuditQueryParams() - .setDataElements(List.of(deA, deB)) - .setStartDate(getDate(2021, 6, 15)) - .setEndDate(getDate(2021, 7, 15)); - assertContainsOnly(List.of(dvaB), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(1, auditStore.countTrackedEntityDataValueAudits(params)); - } - - @Test - void testGetTrackedEntityDataValueAuditsByAuditType() { - TrackedEntityDataValueAudit dvaA = - new TrackedEntityDataValueAudit( - deA, eventA, dvA.getAuditValue(), USER_A, dvA.getProvidedElsewhere(), AuditType.CREATE); - TrackedEntityDataValueAudit dvaB = - new TrackedEntityDataValueAudit( - deB, eventA, dvB.getAuditValue(), USER_A, dvB.getProvidedElsewhere(), AuditType.UPDATE); - TrackedEntityDataValueAudit dvaC = - new TrackedEntityDataValueAudit( - deA, eventB, dvC.getAuditValue(), USER_A, dvC.getProvidedElsewhere(), AuditType.DELETE); - auditStore.addTrackedEntityDataValueAudit(dvaA); - auditStore.addTrackedEntityDataValueAudit(dvaB); - auditStore.addTrackedEntityDataValueAudit(dvaC); - - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() - .setAuditTypes(List.of(AuditType.UPDATE, AuditType.DELETE)); - assertContainsOnly(List.of(dvaB, dvaC), auditStore.getTrackedEntityDataValueAudits(params)); - assertEquals(2, auditStore.countTrackedEntityDataValueAudits(params)); - } -} diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java new file mode 100644 index 000000000000..84000f7fd41a --- /dev/null +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityDataValueChangeLogStoreTest.java @@ -0,0 +1,469 @@ +/* + * Copyright (c) 2004-2022, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.trackedentity; + +import static org.hisp.dhis.utils.Assertions.assertContainsOnly; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.hisp.dhis.audit.UserInfoTestHelper; +import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.common.OrganisationUnitSelectionMode; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.eventdatavalue.EventDataValue; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.program.Enrollment; +import org.hisp.dhis.program.EnrollmentService; +import org.hisp.dhis.program.Event; +import org.hisp.dhis.program.EventService; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramService; +import org.hisp.dhis.program.ProgramStage; +import org.hisp.dhis.program.ProgramStageService; +import org.hisp.dhis.program.UserInfoSnapshot; +import org.hisp.dhis.test.integration.SingleSetupIntegrationTestBase; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogStore; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author Viet Nguyen + */ +class TrackedEntityDataValueChangeLogStoreTest extends SingleSetupIntegrationTestBase { + private static final String USER_A = "userA"; + + private static final UserInfoSnapshot USER_SNAP_A = UserInfoTestHelper.testUserInfo(USER_A); + + @Autowired private TrackedEntityDataValueChangeLogStore auditStore; + + @Autowired private TrackedEntityService entityInstanceService; + + @Autowired private OrganisationUnitService organisationUnitService; + + @Autowired private DataElementService dataElementService; + + @Autowired private ProgramService programService; + + @Autowired private ProgramStageService programStageService; + + @Autowired private EnrollmentService enrollmentService; + + @Autowired private EventService eventService; + + private OrganisationUnit ouA; + + private OrganisationUnit ouB; + + private OrganisationUnit ouC; + + private OrganisationUnit ouD; + + private OrganisationUnit ouE; + + private Program pA; + + private ProgramStage psA; + + private ProgramStage psB; + + private DataElement deA; + + private DataElement deB; + + private Event eventA; + + private Event eventB; + + private Event eventC; + + private Event eventD; + + private Event eventE; + + private EventDataValue dvA; + + private EventDataValue dvB; + + private EventDataValue dvC; + + private EventDataValue dvD; + + private EventDataValue dvE; + + @Override + public void setUpTest() { + ouA = createOrganisationUnit('A'); + ouB = createOrganisationUnit('B', ouA); + ouC = createOrganisationUnit('C', ouA); + ouD = createOrganisationUnit('D', ouB); + ouE = createOrganisationUnit('E', ouD); + organisationUnitService.addOrganisationUnit(ouA); + organisationUnitService.addOrganisationUnit(ouB); + organisationUnitService.addOrganisationUnit(ouC); + organisationUnitService.addOrganisationUnit(ouD); + organisationUnitService.addOrganisationUnit(ouE); + + pA = createProgram('A', new HashSet<>(), ouA); + programService.addProgram(pA); + + psA = new ProgramStage("StageA", pA); + psA.setSortOrder(1); + programStageService.saveProgramStage(psA); + psB = new ProgramStage("StageB", pA); + psB.setSortOrder(2); + programStageService.saveProgramStage(psB); + pA.setProgramStages(Set.of(psA, psB)); + programService.updateProgram(pA); + + deA = createDataElement('A'); + deB = createDataElement('B'); + dataElementService.addDataElement(deA); + dataElementService.addDataElement(deB); + + TrackedEntity teiA = createTrackedEntity(ouA); + entityInstanceService.addTrackedEntity(teiA); + + Enrollment enrollmentA = + enrollmentService.enrollTrackedEntity(teiA, pA, new Date(), new Date(), ouA); + + dvA = new EventDataValue(deA.getUid(), "A", USER_SNAP_A); + dvB = new EventDataValue(deB.getUid(), "B", USER_SNAP_A); + dvC = new EventDataValue(deA.getUid(), "C", USER_SNAP_A); + dvD = new EventDataValue(deB.getUid(), "D", USER_SNAP_A); + dvE = new EventDataValue(deB.getUid(), "E", USER_SNAP_A); + + eventA = createEvent(enrollmentA, psA, ouA, Set.of(dvA, dvB)); + eventB = createEvent(enrollmentA, psB, ouB, Set.of(dvC, dvD)); + eventC = createEvent(enrollmentA, psA, ouC, Set.of(dvA, dvB)); + eventD = createEvent(enrollmentA, psB, ouD, Set.of(dvC, dvD)); + eventE = createEvent(enrollmentA, psA, ouE, Set.of(dvA, dvE)); + eventService.addEvent(eventA); + eventService.addEvent(eventB); + eventService.addEvent(eventC); + eventService.addEvent(eventD); + eventService.addEvent(eventE); + } + + @Test + void testGetTrackedEntityDataValueAuditsByDataElement() { + TrackedEntityDataValueChangeLog dvaA = + new TrackedEntityDataValueChangeLog( + deA, + eventA, + dvA.getAuditValue(), + USER_A, + dvA.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaB = + new TrackedEntityDataValueChangeLog( + deB, + eventA, + dvB.getAuditValue(), + USER_A, + dvB.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaC = + new TrackedEntityDataValueChangeLog( + deA, + eventB, + dvC.getAuditValue(), + USER_A, + dvC.getProvidedElsewhere(), + ChangeLogType.UPDATE); + auditStore.addTrackedEntityDataValueChangeLog(dvaA); + auditStore.addTrackedEntityDataValueChangeLog(dvaB); + auditStore.addTrackedEntityDataValueChangeLog(dvaC); + + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() + .setDataElements(List.of(deA, deB)) + .setEvents(List.of(eventA)) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly(List.of(dvaA, dvaB), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(2, auditStore.countTrackedEntityDataValueChangeLogs(params)); + + params = + new TrackedEntityDataValueChangeLogQueryParams() + .setDataElements(List.of(deA)) + .setEvents(List.of(eventA)) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly(List.of(dvaA), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(1, auditStore.countTrackedEntityDataValueChangeLogs(params)); + } + + @Test + void testGetTrackedEntityDataValueAuditsByOrgUnitSelected() { + TrackedEntityDataValueChangeLog dvaA = + new TrackedEntityDataValueChangeLog( + deA, + eventA, + dvA.getAuditValue(), + USER_A, + dvA.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaB = + new TrackedEntityDataValueChangeLog( + deB, + eventA, + dvB.getAuditValue(), + USER_A, + dvB.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaC = + new TrackedEntityDataValueChangeLog( + deA, + eventB, + dvC.getAuditValue(), + USER_A, + dvC.getProvidedElsewhere(), + ChangeLogType.UPDATE); + auditStore.addTrackedEntityDataValueChangeLog(dvaA); + auditStore.addTrackedEntityDataValueChangeLog(dvaB); + auditStore.addTrackedEntityDataValueChangeLog(dvaC); + + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() + .setOrgUnits(List.of(ouA)) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly(List.of(dvaA, dvaB), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(2, auditStore.countTrackedEntityDataValueChangeLogs(params)); + + params = + new TrackedEntityDataValueChangeLogQueryParams() + .setOrgUnits(List.of(ouB)) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly(List.of(dvaC), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(1, auditStore.countTrackedEntityDataValueChangeLogs(params)); + } + + @Test + void testGetTrackedEntityDataValueAuditsByOrgUnitDescendants() { + TrackedEntityDataValueChangeLog dvaA = + new TrackedEntityDataValueChangeLog( + deA, + eventA, + dvA.getAuditValue(), + USER_A, + dvA.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaB = + new TrackedEntityDataValueChangeLog( + deB, + eventB, + dvB.getAuditValue(), + USER_A, + dvB.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaC = + new TrackedEntityDataValueChangeLog( + deA, + eventC, + dvC.getAuditValue(), + USER_A, + dvC.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaD = + new TrackedEntityDataValueChangeLog( + deB, + eventD, + dvD.getAuditValue(), + USER_A, + dvD.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaE = + new TrackedEntityDataValueChangeLog( + deA, + eventE, + dvE.getAuditValue(), + USER_A, + dvE.getProvidedElsewhere(), + ChangeLogType.UPDATE); + auditStore.addTrackedEntityDataValueChangeLog(dvaA); + auditStore.addTrackedEntityDataValueChangeLog(dvaB); + auditStore.addTrackedEntityDataValueChangeLog(dvaC); + auditStore.addTrackedEntityDataValueChangeLog(dvaD); + auditStore.addTrackedEntityDataValueChangeLog(dvaE); + + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() + .setOrgUnits(List.of(ouB)) + .setOuMode(OrganisationUnitSelectionMode.DESCENDANTS) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly( + List.of(dvaB, dvaD, dvaE), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(3, auditStore.countTrackedEntityDataValueChangeLogs(params)); + + params = + new TrackedEntityDataValueChangeLogQueryParams() + .setOrgUnits(List.of(ouA)) + .setOuMode(OrganisationUnitSelectionMode.DESCENDANTS) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly( + List.of(dvaA, dvaB, dvaC, dvaD, dvaE), + auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(5, auditStore.countTrackedEntityDataValueChangeLogs(params)); + } + + @Test + void testGetTrackedEntityDataValueAuditsByProgramStage() { + TrackedEntityDataValueChangeLog dvaA = + new TrackedEntityDataValueChangeLog( + deA, + eventA, + dvA.getAuditValue(), + USER_A, + dvA.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaB = + new TrackedEntityDataValueChangeLog( + deB, + eventA, + dvB.getAuditValue(), + USER_A, + dvB.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaC = + new TrackedEntityDataValueChangeLog( + deA, + eventB, + dvC.getAuditValue(), + USER_A, + dvC.getProvidedElsewhere(), + ChangeLogType.UPDATE); + auditStore.addTrackedEntityDataValueChangeLog(dvaA); + auditStore.addTrackedEntityDataValueChangeLog(dvaB); + auditStore.addTrackedEntityDataValueChangeLog(dvaC); + + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() + .setProgramStages(List.of(psA)) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly(List.of(dvaA, dvaB), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(2, auditStore.countTrackedEntityDataValueChangeLogs(params)); + + params = + new TrackedEntityDataValueChangeLogQueryParams() + .setProgramStages(List.of(psB)) + .setAuditTypes(List.of(ChangeLogType.UPDATE)); + assertContainsOnly(List.of(dvaC), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(1, auditStore.countTrackedEntityDataValueChangeLogs(params)); + } + + @Test + void testGetTrackedEntityDataValueAuditsByStartEndDate() { + TrackedEntityDataValueChangeLog dvaA = + new TrackedEntityDataValueChangeLog( + deA, + eventA, + dvA.getAuditValue(), + USER_A, + dvA.getProvidedElsewhere(), + ChangeLogType.UPDATE); + dvaA.setCreated(getDate(2021, 6, 1)); + TrackedEntityDataValueChangeLog dvaB = + new TrackedEntityDataValueChangeLog( + deB, + eventA, + dvB.getAuditValue(), + USER_A, + dvB.getProvidedElsewhere(), + ChangeLogType.UPDATE); + dvaB.setCreated(getDate(2021, 7, 1)); + TrackedEntityDataValueChangeLog dvaC = + new TrackedEntityDataValueChangeLog( + deA, + eventB, + dvC.getAuditValue(), + USER_A, + dvC.getProvidedElsewhere(), + ChangeLogType.UPDATE); + dvaC.setCreated(getDate(2021, 8, 1)); + auditStore.addTrackedEntityDataValueChangeLog(dvaA); + auditStore.addTrackedEntityDataValueChangeLog(dvaB); + auditStore.addTrackedEntityDataValueChangeLog(dvaC); + + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() + .setDataElements(List.of(deA, deB)) + .setStartDate(getDate(2021, 6, 15)) + .setEndDate(getDate(2021, 8, 15)); + assertContainsOnly(List.of(dvaB, dvaC), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(2, auditStore.countTrackedEntityDataValueChangeLogs(params)); + + params = + new TrackedEntityDataValueChangeLogQueryParams() + .setDataElements(List.of(deA, deB)) + .setStartDate(getDate(2021, 6, 15)) + .setEndDate(getDate(2021, 7, 15)); + assertContainsOnly(List.of(dvaB), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(1, auditStore.countTrackedEntityDataValueChangeLogs(params)); + } + + @Test + void testGetTrackedEntityDataValueAuditsByAuditType() { + TrackedEntityDataValueChangeLog dvaA = + new TrackedEntityDataValueChangeLog( + deA, + eventA, + dvA.getAuditValue(), + USER_A, + dvA.getProvidedElsewhere(), + ChangeLogType.CREATE); + TrackedEntityDataValueChangeLog dvaB = + new TrackedEntityDataValueChangeLog( + deB, + eventA, + dvB.getAuditValue(), + USER_A, + dvB.getProvidedElsewhere(), + ChangeLogType.UPDATE); + TrackedEntityDataValueChangeLog dvaC = + new TrackedEntityDataValueChangeLog( + deA, + eventB, + dvC.getAuditValue(), + USER_A, + dvC.getProvidedElsewhere(), + ChangeLogType.DELETE); + auditStore.addTrackedEntityDataValueChangeLog(dvaA); + auditStore.addTrackedEntityDataValueChangeLog(dvaB); + auditStore.addTrackedEntityDataValueChangeLog(dvaC); + + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() + .setAuditTypes(List.of(ChangeLogType.UPDATE, ChangeLogType.DELETE)); + assertContainsOnly(List.of(dvaB, dvaC), auditStore.getTrackedEntityDataValueChangeLogs(params)); + assertEquals(2, auditStore.countTrackedEntityDataValueChangeLogs(params)); + } +} diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java index 78a4f1a30d64..3799b07b712d 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStoreTest.java @@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import java.util.List; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.render.RenderService; @@ -58,7 +58,7 @@ class TrackedEntityAttributeValueStoreTest extends SingleSetupIntegrationTestBas @Autowired private TrackedEntityAttributeService attributeService; - @Autowired private TrackedEntityAttributeValueAuditStore attributeValueAuditStore; + @Autowired private TrackedEntityAttributeValueChangeLogStore attributeValueAuditStore; @Autowired private RenderService renderService; @@ -167,53 +167,54 @@ void testGetTrackedEntityAttributeValueAudits() { attributeValueStore.saveVoid(avB); attributeValueStore.saveVoid(avC); attributeValueStore.saveVoid(avD); - TrackedEntityAttributeValueAudit auditA = - new TrackedEntityAttributeValueAudit( - avA, renderService.toJsonAsString(avA), "userA", AuditType.UPDATE); - TrackedEntityAttributeValueAudit auditB = - new TrackedEntityAttributeValueAudit( - avB, renderService.toJsonAsString(avB), "userA", AuditType.UPDATE); - TrackedEntityAttributeValueAudit auditC = - new TrackedEntityAttributeValueAudit( - avC, renderService.toJsonAsString(avC), "userA", AuditType.CREATE); - TrackedEntityAttributeValueAudit auditD = - new TrackedEntityAttributeValueAudit( - avD, renderService.toJsonAsString(avD), "userA", AuditType.DELETE); - attributeValueAuditStore.addTrackedEntityAttributeValueAudit(auditA); - attributeValueAuditStore.addTrackedEntityAttributeValueAudit(auditB); - attributeValueAuditStore.addTrackedEntityAttributeValueAudit(auditC); - attributeValueAuditStore.addTrackedEntityAttributeValueAudit(auditD); - - TrackedEntityAttributeValueAuditQueryParams params = - new TrackedEntityAttributeValueAuditQueryParams() + TrackedEntityAttributeValueChangeLog auditA = + new TrackedEntityAttributeValueChangeLog( + avA, renderService.toJsonAsString(avA), "userA", ChangeLogType.UPDATE); + TrackedEntityAttributeValueChangeLog auditB = + new TrackedEntityAttributeValueChangeLog( + avB, renderService.toJsonAsString(avB), "userA", ChangeLogType.UPDATE); + TrackedEntityAttributeValueChangeLog auditC = + new TrackedEntityAttributeValueChangeLog( + avC, renderService.toJsonAsString(avC), "userA", ChangeLogType.CREATE); + TrackedEntityAttributeValueChangeLog auditD = + new TrackedEntityAttributeValueChangeLog( + avD, renderService.toJsonAsString(avD), "userA", ChangeLogType.DELETE); + attributeValueAuditStore.addTrackedEntityAttributeValueChangeLog(auditA); + attributeValueAuditStore.addTrackedEntityAttributeValueChangeLog(auditB); + attributeValueAuditStore.addTrackedEntityAttributeValueChangeLog(auditC); + attributeValueAuditStore.addTrackedEntityAttributeValueChangeLog(auditD); + + TrackedEntityAttributeValueChangeLogQueryParams params = + new TrackedEntityAttributeValueChangeLogQueryParams() .setTrackedEntityAttributes(List.of(atA)) .setTrackedEntities(List.of(teiA)) - .setAuditTypes(List.of(AuditType.UPDATE)); + .setAuditTypes(List.of(ChangeLogType.UPDATE)); assertContainsOnly( - List.of(auditA), attributeValueAuditStore.getTrackedEntityAttributeValueAudits(params)); + List.of(auditA), attributeValueAuditStore.getTrackedEntityAttributeValueChangeLogs(params)); params = - new TrackedEntityAttributeValueAuditQueryParams() + new TrackedEntityAttributeValueChangeLogQueryParams() .setTrackedEntities(List.of(teiA)) - .setAuditTypes(List.of(AuditType.UPDATE)); + .setAuditTypes(List.of(ChangeLogType.UPDATE)); assertContainsOnly( List.of(auditA, auditB), - attributeValueAuditStore.getTrackedEntityAttributeValueAudits(params)); + attributeValueAuditStore.getTrackedEntityAttributeValueChangeLogs(params)); params = - new TrackedEntityAttributeValueAuditQueryParams().setAuditTypes(List.of(AuditType.CREATE)); + new TrackedEntityAttributeValueChangeLogQueryParams() + .setAuditTypes(List.of(ChangeLogType.CREATE)); assertContainsOnly( - List.of(auditC), attributeValueAuditStore.getTrackedEntityAttributeValueAudits(params)); + List.of(auditC), attributeValueAuditStore.getTrackedEntityAttributeValueChangeLogs(params)); params = - new TrackedEntityAttributeValueAuditQueryParams() - .setAuditTypes(List.of(AuditType.CREATE, AuditType.DELETE)); + new TrackedEntityAttributeValueChangeLogQueryParams() + .setAuditTypes(List.of(ChangeLogType.CREATE, ChangeLogType.DELETE)); assertContainsOnly( List.of(auditC, auditD), - attributeValueAuditStore.getTrackedEntityAttributeValueAudits(params)); + attributeValueAuditStore.getTrackedEntityAttributeValueChangeLogs(params)); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueChangeLogTest.java similarity index 86% rename from dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java rename to dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueChangeLogTest.java index dd59653ea493..fc71a778fe7b 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueAuditTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityAttributeValueChangeLogTest.java @@ -33,14 +33,14 @@ import java.io.IOException; import java.util.List; import java.util.stream.Collectors; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditQueryParams; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLog; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogQueryParams; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; @@ -54,14 +54,14 @@ /** * @author Zubair Asghar */ -class TrackedEntityAttributeValueAuditTest extends TrackerTest { +class TrackedEntityAttributeValueChangeLogTest extends TrackerTest { @Autowired private TrackerImportService trackerImportService; @Autowired private TrackedEntityAttributeValueService trackedEntityAttributeValueService; @Autowired private IdentifiableObjectManager manager; - @Autowired private TrackedEntityAttributeValueAuditService attributeValueAuditService; + @Autowired private TrackedEntityAttributeValueChangeLogService attributeValueAuditService; @Override protected void initTest() throws IOException { @@ -86,12 +86,12 @@ void testTrackedEntityAttributeValueAuditCreate() throws IOException { attributeValues.stream() .map(TrackedEntityAttributeValue::getAttribute) .collect(Collectors.toList()); - List attributeValueAudits = - attributeValueAuditService.getTrackedEntityAttributeValueAudits( - new TrackedEntityAttributeValueAuditQueryParams() + List attributeValueAudits = + attributeValueAuditService.getTrackedEntityAttributeValueChangeLogs( + new TrackedEntityAttributeValueChangeLogQueryParams() .setTrackedEntityAttributes(attributes) .setTrackedEntities(trackedEntities) - .setAuditTypes(List.of(AuditType.CREATE))); + .setAuditTypes(List.of(ChangeLogType.CREATE))); assertEquals(5, attributeValueAudits.size()); } @@ -114,20 +114,20 @@ void testTrackedEntityAttributeValueAuditDelete() throws IOException { importReport = trackerImportService.importTracker(params, trackerObjects); assertNoErrors(importReport); List trackedEntities = manager.getAll(TrackedEntity.class); - List attributeValueAudits = - attributeValueAuditService.getTrackedEntityAttributeValueAudits( - new TrackedEntityAttributeValueAuditQueryParams() + List attributeValueAudits = + attributeValueAuditService.getTrackedEntityAttributeValueChangeLogs( + new TrackedEntityAttributeValueChangeLogQueryParams() .setTrackedEntityAttributes(attributes1) .setTrackedEntities(trackedEntities) - .setAuditTypes(List.of(AuditType.DELETE))); + .setAuditTypes(List.of(ChangeLogType.DELETE))); assertEquals(1, attributeValueAudits.size()); attributeValueAudits = - attributeValueAuditService.getTrackedEntityAttributeValueAudits( - new TrackedEntityAttributeValueAuditQueryParams() + attributeValueAuditService.getTrackedEntityAttributeValueChangeLogs( + new TrackedEntityAttributeValueChangeLogQueryParams() .setTrackedEntityAttributes(attributes1) .setTrackedEntities(trackedEntities) - .setAuditTypes(List.of(AuditType.UPDATE))); + .setAuditTypes(List.of(ChangeLogType.UPDATE))); assertEquals(1, attributeValueAudits.size()); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueChangeLogTest.java similarity index 78% rename from dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java rename to dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueChangeLogTest.java index a90f2ee01e9a..bb78897b499e 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueAuditTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/TrackedEntityDataValueChangeLogTest.java @@ -35,13 +35,13 @@ import java.io.IOException; import java.util.List; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.program.Event; -import org.hisp.dhis.trackedentity.TrackedEntityDataValueAuditQueryParams; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentity.TrackedEntityDataValueChangeLogQueryParams; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.hisp.dhis.tracker.TrackerTest; import org.hisp.dhis.tracker.imports.TrackerImportParams; import org.hisp.dhis.tracker.imports.TrackerImportService; @@ -51,7 +51,7 @@ /** * @author Zubair Asghar */ -public class TrackedEntityDataValueAuditTest extends TrackerTest { +public class TrackedEntityDataValueChangeLogTest extends TrackerTest { private static final String ORIGINAL_VALUE = "value1"; private static final String UPDATED_VALUE = "value1-updated"; @@ -64,7 +64,7 @@ public class TrackedEntityDataValueAuditTest extends TrackerTest { @Autowired private IdentifiableObjectManager manager; - @Autowired private TrackedEntityDataValueAuditService dataValueAuditService; + @Autowired private TrackedEntityDataValueChangeLogService dataValueAuditService; private DataElement dataElement; @@ -94,45 +94,47 @@ void testTrackedEntityDataValueAuditCreate() throws IOException { assertNotNull(dataElement); assertNotNull(event); - List createdAudit = - dataValueAuditService.getTrackedEntityDataValueAudits( - new TrackedEntityDataValueAuditQueryParams() + List createdAudit = + dataValueAuditService.getTrackedEntityDataValueChangeLogs( + new TrackedEntityDataValueChangeLogQueryParams() .setDataElements(List.of(dataElement)) .setEvents(List.of(event)) - .setAuditTypes(List.of(AuditType.CREATE))); - List updatedAudit = - dataValueAuditService.getTrackedEntityDataValueAudits( - new TrackedEntityDataValueAuditQueryParams() + .setAuditTypes(List.of(ChangeLogType.CREATE))); + List updatedAudit = + dataValueAuditService.getTrackedEntityDataValueChangeLogs( + new TrackedEntityDataValueChangeLogQueryParams() .setDataElements(List.of(dataElement)) .setEvents(List.of(event)) - .setAuditTypes(List.of(AuditType.UPDATE))); - List deletedAudit = - dataValueAuditService.getTrackedEntityDataValueAudits( - new TrackedEntityDataValueAuditQueryParams() + .setAuditTypes(List.of(ChangeLogType.UPDATE))); + List deletedAudit = + dataValueAuditService.getTrackedEntityDataValueChangeLogs( + new TrackedEntityDataValueChangeLogQueryParams() .setDataElements(List.of(dataElement)) .setEvents(List.of(event)) - .setAuditTypes(List.of(AuditType.DELETE))); + .setAuditTypes(List.of(ChangeLogType.DELETE))); assertAll( () -> assertNotNull(createdAudit), () -> assertNotNull(updatedAudit), () -> assertNotNull(deletedAudit)); - assertAuditCollection(createdAudit, AuditType.CREATE, ORIGINAL_VALUE); - assertAuditCollection(updatedAudit, AuditType.UPDATE, ORIGINAL_VALUE); - assertAuditCollection(deletedAudit, AuditType.DELETE, UPDATED_VALUE); + assertAuditCollection(createdAudit, ChangeLogType.CREATE, ORIGINAL_VALUE); + assertAuditCollection(updatedAudit, ChangeLogType.UPDATE, ORIGINAL_VALUE); + assertAuditCollection(deletedAudit, ChangeLogType.DELETE, UPDATED_VALUE); } private void assertAuditCollection( - List audits, AuditType auditType, String expectedValue) { + List audits, + ChangeLogType changeLogType, + String expectedValue) { assertAll( () -> assertFalse(audits.isEmpty()), () -> assertEquals( - auditType, + changeLogType, audits.get(0).getAuditType(), () -> "Expected audit type is " - + auditType + + changeLogType + " but found " + audits.get(0).getAuditType()), () -> diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java similarity index 99% rename from dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java rename to dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java index 05c5a38c8cc8..6e35550a4470 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/AuditControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ChangeLogControllerTest.java @@ -49,7 +49,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -class AuditControllerTest extends DhisControllerConvenienceTest { +class ChangeLogControllerTest extends DhisControllerConvenienceTest { private static final String DATA_ELEMENT_VALUE = "value"; diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChangeLogController.java similarity index 82% rename from dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java rename to dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChangeLogController.java index bac253b86cb2..463e27d873a9 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChangeLogController.java @@ -43,9 +43,8 @@ import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.audit.payloads.TrackedEntityAudit; import org.hisp.dhis.category.CategoryOptionCombo; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DhisApiVersion; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.OpenApi; @@ -85,14 +84,15 @@ import org.hisp.dhis.program.ProgramStage; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; -import org.hisp.dhis.trackedentity.TrackedEntityAuditQueryParams; -import org.hisp.dhis.trackedentity.TrackedEntityAuditService; -import org.hisp.dhis.trackedentity.TrackedEntityDataValueAuditQueryParams; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditQueryParams; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; -import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLog; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogQueryParams; +import org.hisp.dhis.trackedentity.TrackedEntityChangeLogService; +import org.hisp.dhis.trackedentity.TrackedEntityDataValueChangeLogQueryParams; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLog; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogQueryParams; +import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueChangeLogService; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; +import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLogService; import org.hisp.dhis.user.User; import org.hisp.dhis.webapi.mvc.annotation.ApiVersion; import org.hisp.dhis.webapi.service.ContextService; @@ -112,18 +112,18 @@ @RequiredArgsConstructor @RequestMapping("/audits") @ApiVersion({DhisApiVersion.DEFAULT, DhisApiVersion.ALL}) -public class AuditController { +public class ChangeLogController { private final IdentifiableObjectManager manager; private final DataValueAuditService dataValueAuditService; - private final TrackedEntityDataValueAuditService trackedEntityDataValueAuditService; + private final TrackedEntityDataValueChangeLogService trackedEntityDataValueChangeLogService; - private final TrackedEntityAttributeValueAuditService trackedEntityAttributeValueAuditService; + private final TrackedEntityAttributeValueChangeLogService attributeValueChangeLogService; private final DataApprovalAuditService dataApprovalAuditService; - private final TrackedEntityAuditService trackedEntityAuditService; + private final TrackedEntityChangeLogService trackedEntityChangeLogService; private final FieldFilterService fieldFilterService; @@ -183,7 +183,7 @@ public RootNode getAggregateDataValueAudit( String co, @OpenApi.Param({UID.class, CategoryOptionCombo.class}) @RequestParam(required = false) String cc, - @RequestParam(required = false) List auditType, + @RequestParam(required = false) List auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @@ -203,7 +203,7 @@ public RootNode getAggregateDataValueAudit( List organisationUnits = manager.loadByUid(OrganisationUnit.class, ou); CategoryOptionCombo categoryOptionCombo = manager.get(CategoryOptionCombo.class, co); CategoryOptionCombo attributeOptionCombo = manager.get(CategoryOptionCombo.class, cc); - List auditTypes = emptyIfNull(auditType); + List changeLogTypes = emptyIfNull(auditType); DataValueAuditQueryParams params = new DataValueAuditQueryParams() @@ -212,7 +212,7 @@ public RootNode getAggregateDataValueAudit( .setOrgUnits(organisationUnits) .setCategoryOptionCombo(categoryOptionCombo) .setAttributeOptionCombo(attributeOptionCombo) - .setAuditTypes(auditTypes); + .setAuditTypes(changeLogTypes); List dataValueAudits; Pager pager = null; @@ -232,7 +232,7 @@ public RootNode getAggregateDataValueAudit( .setOrgUnits(organisationUnits) .setCategoryOptionCombo(categoryOptionCombo) .setAttributeOptionCombo(attributeOptionCombo) - .setAuditTypes(auditTypes) + .setAuditTypes(changeLogTypes) .setPager(pager)); } @@ -253,7 +253,7 @@ public RootNode getAggregateDataValueAudit( } @GetMapping("trackedEntityDataValue") - public RootNode getTrackedEntityDataValueAudit( + public RootNode getTrackedEntityDataValueChangeLog( @OpenApi.Param({UID[].class, DataElement.class}) @RequestParam(required = false) List de, @OpenApi.Param({UID[].class, OrganisationUnit.class}) @RequestParam(required = false) @@ -269,7 +269,7 @@ public RootNode getTrackedEntityDataValueAudit( @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, - @RequestParam(required = false) List auditType, + @RequestParam(required = false) List auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @@ -286,13 +286,13 @@ public RootNode getTrackedEntityDataValueAudit( List programStages = manager.loadByUid(ProgramStage.class, ps); Set eventUids = validateDeprecatedUidsParameter("psi", String.join(";", psi), "events", events); - List auditTypes = emptyIfNull(auditType); + List changeLogTypes = emptyIfNull(auditType); - List dataValueAudits; + List dataValueChangeLogs; Pager pager = null; - TrackedEntityDataValueAuditQueryParams params = - new TrackedEntityDataValueAuditQueryParams() + TrackedEntityDataValueChangeLogQueryParams params = + new TrackedEntityDataValueChangeLogQueryParams() .setDataElements(dataElements) .setOrgUnits(orgUnits) .setEvents(manager.loadByUid(Event.class, UID.toValueSet(eventUids))) @@ -300,17 +300,19 @@ public RootNode getTrackedEntityDataValueAudit( .setStartDate(startDate) .setEndDate(endDate) .setOuMode(ouMode) - .setAuditTypes(auditTypes); + .setAuditTypes(changeLogTypes); if (PagerUtils.isSkipPaging(skipPaging, paging)) { - dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(params); + dataValueChangeLogs = + trackedEntityDataValueChangeLogService.getTrackedEntityDataValueChangeLogs(params); } else { - int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(params); + int total = + trackedEntityDataValueChangeLogService.countTrackedEntityDataValueChangeLogs(params); pager = new Pager(page, total, pageSize); - dataValueAudits = - trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits( + dataValueChangeLogs = + trackedEntityDataValueChangeLogService.getTrackedEntityDataValueChangeLogs( params.setPager(pager)); } @@ -320,19 +322,20 @@ public RootNode getTrackedEntityDataValueAudit( rootNode.addChild(NodeUtils.createPager(pager)); } - CollectionNode trackedEntityAttributeValueAudits = + CollectionNode trackedEntityAttributeValueChangeLogs = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true)); - trackedEntityAttributeValueAudits.addChildren( + trackedEntityAttributeValueChangeLogs.addChildren( fieldFilterService .toCollectionNode( - TrackedEntityDataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)) + TrackedEntityDataValueChangeLog.class, + new FieldFilterParams(dataValueChangeLogs, fields)) .getChildren()); return rootNode; } @GetMapping("trackedEntityAttributeValue") - public RootNode getTrackedEntityAttributeValueAudit( + public RootNode getTrackedEntityAttributeValueChangeLog( @OpenApi.Param({UID[].class, TrackedEntityAttribute.class}) @RequestParam(required = false) List tea, @Deprecated(since = "2.41") @@ -342,7 +345,7 @@ public RootNode getTrackedEntityAttributeValueAudit( @OpenApi.Param({UID[].class, TrackedEntity.class}) @RequestParam(required = false, defaultValue = "") Set trackedEntities, - @RequestParam(required = false) List auditType, + @RequestParam(required = false) List auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @@ -355,28 +358,27 @@ public RootNode getTrackedEntityAttributeValueAudit( Set teUids = validateDeprecatedUidsParameter( "tei", String.join(";", tei), "trackedEntities", trackedEntities); - List auditTypes = emptyIfNull(auditType); + List changeLogTypes = emptyIfNull(auditType); - List attributeValueAudits; + List attributeValueChangeLogs; Pager pager = null; - TrackedEntityAttributeValueAuditQueryParams params = - new TrackedEntityAttributeValueAuditQueryParams() + TrackedEntityAttributeValueChangeLogQueryParams params = + new TrackedEntityAttributeValueChangeLogQueryParams() .setTrackedEntityAttributes(trackedEntityAttributes) .setTrackedEntities(manager.loadByUid(TrackedEntity.class, UID.toValueList(teUids))) - .setAuditTypes(auditTypes); + .setAuditTypes(changeLogTypes); if (PagerUtils.isSkipPaging(skipPaging, paging)) { - attributeValueAudits = - trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(params); + attributeValueChangeLogs = + attributeValueChangeLogService.getTrackedEntityAttributeValueChangeLogs(params); } else { - int total = - trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits(params); + int total = attributeValueChangeLogService.countTrackedEntityAttributeValueChangeLogs(params); pager = new Pager(page, total, pageSize); - attributeValueAudits = - trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits( + attributeValueChangeLogs = + attributeValueChangeLogService.getTrackedEntityAttributeValueChangeLogs( params.setPager(pager)); } @@ -386,13 +388,13 @@ public RootNode getTrackedEntityAttributeValueAudit( rootNode.addChild(NodeUtils.createPager(pager)); } - CollectionNode trackedEntityAttributeValueAudits = + CollectionNode changeLogs = rootNode.addChild(new CollectionNode("trackedEntityAttributeValueAudits", true)); - trackedEntityAttributeValueAudits.addChildren( + changeLogs.addChildren( fieldFilterService .toCollectionNode( - TrackedEntityAttributeValueAudit.class, - new FieldFilterParams(attributeValueAudits, fields)) + TrackedEntityAttributeValueChangeLog.class, + new FieldFilterParams(attributeValueChangeLogs, fields)) .getChildren()); return rootNode; @@ -456,11 +458,11 @@ public RootNode getDataApprovalAudit( } /** - * @deprecated use {@link #getTrackedEnityAudit} instead. + * @deprecated use {@link #getTrackedEnityChangeLog} instead. */ @Deprecated(since = "2.41") @GetMapping("trackedEntityInstance") - public RootNode getTrackedEnityInstanceAudit( + public RootNode getTrackedEnityInstanceChangeLog( @Deprecated(since = "2.41") @OpenApi.Param({UID[].class, TrackedEntity.class}) @RequestParam(required = false, defaultValue = "") @@ -469,7 +471,7 @@ public RootNode getTrackedEnityInstanceAudit( @RequestParam(required = false, defaultValue = "") Set trackedEntities, @OpenApi.Param({UID[].class, User.class}) @RequestParam(required = false) List user, - @RequestParam(required = false) List auditType, + @RequestParam(required = false) List auditType, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Boolean skipPaging, @@ -483,31 +485,32 @@ public RootNode getTrackedEnityInstanceAudit( fields.addAll(Preset.ALL.getFields()); } - List auditTypes = emptyIfNull(auditType); + List changeLogTypes = emptyIfNull(auditType); Set teUids = validateDeprecatedUidsParameter( "tei", String.join(";", tei), "trackedEntities", trackedEntities); - TrackedEntityAuditQueryParams params = - new TrackedEntityAuditQueryParams() + TrackedEntityChangeLogQueryParams params = + new TrackedEntityChangeLogQueryParams() .setTrackedEntities(UID.toValueList(teUids)) .setUsers(user) - .setAuditTypes(auditTypes) + .setAuditTypes(changeLogTypes) .setStartDate(startDate) .setEndDate(endDate); - List teiAudits; + List teChangeLogs; Pager pager = null; if (PagerUtils.isSkipPaging(skipPaging, paging)) { - int total = trackedEntityAuditService.getTrackedEntityAuditsCount(params); + int total = trackedEntityChangeLogService.getTrackedEntityChangeLogsCount(params); pager = new Pager(page, total, pageSize); - teiAudits = trackedEntityAuditService.getTrackedEntityAudits(params); + teChangeLogs = trackedEntityChangeLogService.getTrackedEntityChangeLogs(params); } else { - teiAudits = trackedEntityAuditService.getTrackedEntityAudits(params.setPager(pager)); + teChangeLogs = + trackedEntityChangeLogService.getTrackedEntityChangeLogs(params.setPager(pager)); } RootNode rootNode = NodeUtils.createMetadata(); @@ -516,23 +519,24 @@ public RootNode getTrackedEnityInstanceAudit( rootNode.addChild(NodeUtils.createPager(pager)); } - CollectionNode trackedEntityAudits = + CollectionNode changeLogs = rootNode.addChild(new CollectionNode("trackedEntityInstanceAudits", true)); - trackedEntityAudits.addChildren( + changeLogs.addChildren( fieldFilterService - .toCollectionNode(TrackedEntityAudit.class, new FieldFilterParams(teiAudits, fields)) + .toCollectionNode( + TrackedEntityChangeLog.class, new FieldFilterParams(teChangeLogs, fields)) .getChildren()); return rootNode; } @GetMapping("trackedEntity") - public RootNode getTrackedEnityAudit( + public RootNode getTrackedEnityChangeLog( @OpenApi.Param({UID[].class, TrackedEntity.class}) @RequestParam(required = false, defaultValue = "") Set trackedEntities, @OpenApi.Param({UID[].class, User.class}) @RequestParam(required = false) List user, - @RequestParam(required = false) List auditType, + @RequestParam(required = false) List auditType, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Boolean skipPaging, @@ -545,27 +549,28 @@ public RootNode getTrackedEnityAudit( fields.addAll(Preset.ALL.getFields()); } - List auditTypes = emptyIfNull(auditType); + List changeLogTypes = emptyIfNull(auditType); - TrackedEntityAuditQueryParams params = - new TrackedEntityAuditQueryParams() + TrackedEntityChangeLogQueryParams params = + new TrackedEntityChangeLogQueryParams() .setTrackedEntities(UID.toValueList(trackedEntities)) .setUsers(user) - .setAuditTypes(auditTypes) + .setAuditTypes(changeLogTypes) .setStartDate(startDate) .setEndDate(endDate); - List teiAudits; + List teChangeLogs; Pager pager = null; if (PagerUtils.isSkipPaging(skipPaging, paging)) { - int total = trackedEntityAuditService.getTrackedEntityAuditsCount(params); + int total = trackedEntityChangeLogService.getTrackedEntityChangeLogsCount(params); pager = new Pager(page, total, pageSize); - teiAudits = trackedEntityAuditService.getTrackedEntityAudits(params); + teChangeLogs = trackedEntityChangeLogService.getTrackedEntityChangeLogs(params); } else { - teiAudits = trackedEntityAuditService.getTrackedEntityAudits(params.setPager(pager)); + teChangeLogs = + trackedEntityChangeLogService.getTrackedEntityChangeLogs(params.setPager(pager)); } RootNode rootNode = NodeUtils.createMetadata(); @@ -574,11 +579,11 @@ public RootNode getTrackedEnityAudit( rootNode.addChild(NodeUtils.createPager(pager)); } - CollectionNode trackedEntityAudits = - rootNode.addChild(new CollectionNode("trackedEntityAudits", true)); - trackedEntityAudits.addChildren( + CollectionNode changeLogs = rootNode.addChild(new CollectionNode("trackedEntityAudits", true)); + changeLogs.addChildren( fieldFilterService - .toCollectionNode(TrackedEntityAudit.class, new FieldFilterParams(teiAudits, fields)) + .toCollectionNode( + TrackedEntityChangeLog.class, new FieldFilterParams(teChangeLogs, fields)) .getChildren()); return rootNode; diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/datavalue/DataValueAuditDto.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/datavalue/DataValueAuditDto.java index 583a7ed4ec4b..30d2c5eb2897 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/datavalue/DataValueAuditDto.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/datavalue/DataValueAuditDto.java @@ -34,7 +34,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import org.hisp.dhis.category.CategoryOptionCombo; -import org.hisp.dhis.common.AuditType; +import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; @@ -77,5 +77,5 @@ public class DataValueAuditDto { @JsonProperty private Date created; - @JsonProperty private AuditType auditType; + @JsonProperty private ChangeLogType auditType; }