From 72ce516f02420117779f006a3dd0b64f4d438224 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 05:50:51 -0300 Subject: [PATCH 1/5] chore(deps): bump micrometer.version from 1.14.0 to 1.14.2 in /dhis-2 (#19431) Bumps `micrometer.version` from 1.14.0 to 1.14.2. Updates `io.micrometer:micrometer-registry-prometheus` from 1.14.0 to 1.14.2 - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.14.0...v1.14.2) Updates `io.micrometer:micrometer-registry-prometheus-simpleclient` from 1.14.0 to 1.14.2 - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.14.0...v1.14.2) Updates `io.micrometer:micrometer-jakarta9` from 1.14.0 to 1.14.2 - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.14.0...v1.14.2) Updates `io.micrometer:micrometer-core` from 1.14.0 to 1.14.2 - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.14.0...v1.14.2) --- updated-dependencies: - dependency-name: io.micrometer:micrometer-registry-prometheus dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.micrometer:micrometer-registry-prometheus-simpleclient dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.micrometer:micrometer-jakarta9 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.micrometer:micrometer-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dhis-2/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/pom.xml b/dhis-2/pom.xml index 7c62f28ec858..65d82d92c00e 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -205,7 +205,7 @@ 1.3.20 - 1.14.0 + 1.14.2 1.3.1 From dccfea5d7f3a864e5d7af7898da6ff1d3a20a72e Mon Sep 17 00:00:00 2001 From: David Mackessy <131455290+david-mackessy@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:54:06 +0000 Subject: [PATCH 2/5] chore: Disable failing test on GitHub (#19440) --- .../test/java/org/hisp/dhis/merge/CategoryOptionMergeTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/merge/CategoryOptionMergeTest.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/merge/CategoryOptionMergeTest.java index db7ad8e0972b..ef31d1cdb97a 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/merge/CategoryOptionMergeTest.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/merge/CategoryOptionMergeTest.java @@ -45,6 +45,7 @@ import org.hisp.dhis.test.e2e.dto.ApiResponse; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -84,6 +85,7 @@ public void setup() { } @Test + @Disabled("Started failing in GitHub (Not Jenkins) for no obvious reason") @DisplayName( "Valid CategoryOption merge completes successfully with all source CategoryOption refs replaced with target CategoryOption") void validDataElementMergeTest() { @@ -155,6 +157,7 @@ private void setupMetadata() { } @Test + @Disabled("Started failing in GitHub (Not Jenkins) for no obvious reason") @DisplayName("CategoryOption merge fails when user has not got the required authority") void testDataElementMergeNoRequiredAuth() { userActions.addUserFull("basic", "User", "basicUser", "Test1234!", "NO_AUTH"); From d3f466e3b3006b8d4269d41302390aa07f90cd87 Mon Sep 17 00:00:00 2001 From: marc Date: Wed, 11 Dec 2024 09:59:52 +0100 Subject: [PATCH 3/5] feat: Separate ChangeLogType between audit and changelog [DHIS2-18583] (#19399) * feat: Remove old TEA change log [DHIS2-18477] * feat: Remove unused tests [DHIS2-18477] * feat: Remove delete old table change log method [DHIS2-18477] * feat: Remove unused imports [DHIS2-18477] * feat: Remove incorrect deprecated annotation [DHIS2-18477] * feat: Move audit services and stores to regular package [DHIS2-18477] * feat: Separate ChangeLogType between audit and changelog [DHIS2-18583] * Merge remote-tracking branch 'origin/master' into DHIS2-18583 * feat: Rename TrackerAuditType to AuditOperationType [DHIS2-18583] --- .../hisp/dhis/audit/AuditOperationType.java} | 36 +-- .../hisp/dhis/changelog/ChangeLogType.java | 10 +- .../hisp/dhis/datavalue/DataValueAudit.java | 12 +- .../datavalue/DataValueAuditQueryParams.java | 4 +- .../ApiTrackedEntityAuditService.java | 4 +- .../trackedentity/TrackedEntityAudit.java | 14 +- .../TrackedEntityAuditQueryParams.java | 4 +- .../dataelement/DataElementMergeService.java | 2 +- .../TrackerDataElementMergeHandler.java | 8 +- .../DefaultDataValueAuditService.java | 14 +- .../datavalue/DefaultDataValueService.java | 11 +- ...ava => EventChangeLogDeletionHandler.java} | 7 +- .../message/DefaultProgramMessageService.java | 2 +- .../message/DeliveryChannelStrategy.java | 2 +- .../DefaultApiTrackedEntityAuditService.java | 6 +- .../hibernate/DataValueAudit.hbm.xml | 2 +- .../hibernate/TrackedEntityAudit.hbm.xml | 2 +- ...ackedEntityAttributeValueChangeLog.hbm.xml | 40 ---- .../TrackedEntityDataValueChangeLog.hbm.xml | 38 ---- .../DefaultDataValueSetService.java | 12 +- .../DefaultTrackedEntityAuditService.java | 6 +- .../audit/TrackedEntityAuditService.java | 4 +- .../export/OperationsParamsValidator.java | 2 +- .../event/DefaultEventChangeLogService.java | 10 +- .../TrackedEntityDataValueChangeLog.java | 205 ----------------- ...edEntityDataValueChangeLogQueryParams.java | 74 ------- .../DefaultTrackedEntityService.java | 6 +- .../TrackedEntityAttributeValueChangeLog.java | 207 ------------------ .../persister/AbstractTrackerPersister.java | 15 +- .../DefaultTrackerObjectsDeletionService.java | 2 +- ...ultTrackedEntityAttributeValueService.java | 4 +- .../DataValueAuditBatchHandler.java | 4 +- .../datavalue/DataValueAuditServiceTest.java | 90 ++++---- .../DataValueSetServiceIntegrationTest.java | 4 +- .../DataValueAuditBatchHandlerTest.java | 10 +- .../maintenance/MaintenanceServiceTest.java | 4 +- .../DataElementMergeServiceTest.java | 5 +- .../TrackedEntityAuditStoreTest.java | 23 +- ...uplicationServiceMergeIntegrationTest.java | 4 +- .../webapi/controller/AuditController.java | 22 +- .../export/event/EventsExportController.java | 1 + .../TrackedEntitiesExportController.java | 3 +- .../datavalue/DataValueAuditDto.java | 4 +- 43 files changed, 178 insertions(+), 761 deletions(-) rename dhis-2/{dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLogQueryParams.java => dhis-api/src/main/java/org/hisp/dhis/audit/AuditOperationType.java} (64%) rename dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/{TrackedEntityDataValueChangeLogDeletionHandler.java => EventChangeLogDeletionHandler.java} (88%) delete mode 100644 dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml delete mode 100644 dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueChangeLog.hbm.xml delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLog.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLogQueryParams.java delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLog.java diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLogQueryParams.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/audit/AuditOperationType.java similarity index 64% rename from dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLogQueryParams.java rename to dhis-2/dhis-api/src/main/java/org/hisp/dhis/audit/AuditOperationType.java index db704216f83e..c4d2bbfc0e18 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLogQueryParams.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/audit/AuditOperationType.java @@ -25,34 +25,16 @@ * (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.tracker.export.trackedentity; - -import java.util.ArrayList; -import java.util.List; -import lombok.Data; -import lombok.experimental.Accessors; -import org.hisp.dhis.changelog.ChangeLogType; -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentity.TrackedEntityAttribute; +package org.hisp.dhis.audit; /** - * Encapsulation of a web API request for tracked entity data value audit records. - * - * @author Lars Helge Overland + * @author Halvdan Hoem Grelland + * @author Luca Cambi split Changelog from Audit */ -@Data -@Accessors(chain = true) -public class TrackedEntityAttributeValueChangeLogQueryParams { - private List trackedEntityAttributes = new ArrayList<>(); - - private List trackedEntities = new ArrayList<>(); - - private List auditTypes = new ArrayList<>(); - - private Pager pager; - - public boolean hasPager() { - return pager != null; - } +public enum AuditOperationType { + CREATE, + UPDATE, + DELETE, + READ, + SEARCH } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java index 7236761f47fe..5ce80dd99e3d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/changelog/ChangeLogType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,14 +27,8 @@ */ package org.hisp.dhis.changelog; -/** - * @author Halvdan Hoem Grelland - * @author Luca Cambi split Changelog from Audit - */ public enum ChangeLogType { CREATE, UPDATE, - DELETE, - READ, - SEARCH + 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 91af859ab1f3..f18f767f9474 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 @@ -32,8 +32,8 @@ import com.google.common.base.MoreObjects; import java.util.Date; import java.util.Objects; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; -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 ChangeLogType auditType; + private AuditOperationType auditType; // ------------------------------------------------------------------------- // Constructors @@ -71,7 +71,7 @@ public class DataValueAudit { public DataValueAudit() {} public DataValueAudit( - DataValue dataValue, String value, String modifiedBy, ChangeLogType auditType) { + DataValue dataValue, String value, String modifiedBy, AuditOperationType auditType) { this.dataElement = dataValue.getDataElement(); this.period = dataValue.getPeriod(); this.organisationUnit = dataValue.getSource(); @@ -91,7 +91,7 @@ public DataValueAudit( CategoryOptionCombo attributeOptionCombo, String value, String modifiedBy, - ChangeLogType auditType) { + AuditOperationType auditType) { this.dataElement = dataElement; this.period = period; this.organisationUnit = organisationUnit; @@ -277,11 +277,11 @@ public void setCreated(Date created) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public ChangeLogType getAuditType() { + public AuditOperationType getAuditType() { return auditType; } - public void setAuditType(ChangeLogType auditType) { + public void setAuditType(AuditOperationType 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 100a4e918db7..12a7e42bf702 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 @@ -31,8 +31,8 @@ import java.util.List; import lombok.Data; import lombok.experimental.Accessors; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; -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/trackedentity/ApiTrackedEntityAuditService.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/ApiTrackedEntityAuditService.java index 557ee46f032d..936cc9824781 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/ApiTrackedEntityAuditService.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/ApiTrackedEntityAuditService.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.trackedentity; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; /** * @author Abyot Asalefew Gizaw abyota@gmail.com @@ -38,5 +38,5 @@ public interface ApiTrackedEntityAuditService { String ID = ApiTrackedEntityAuditService.class.getName(); void addTrackedEntityAudit( - TrackedEntity trackedEntity, String username, ChangeLogType changeLogType); + TrackedEntity trackedEntity, String username, AuditOperationType auditOperationType); } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAudit.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAudit.java index fe26c591e755..d97d2533b934 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAudit.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAudit.java @@ -33,7 +33,7 @@ import java.io.Serializable; import java.util.Date; import java.util.Objects; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.common.DxfNamespaces; /** @@ -55,7 +55,7 @@ public class TrackedEntityAudit implements Serializable { private String accessedBy; - private ChangeLogType auditType; + private AuditOperationType auditType; // ------------------------------------------------------------------------- // Constructors @@ -63,7 +63,7 @@ public class TrackedEntityAudit implements Serializable { public TrackedEntityAudit() {} - public TrackedEntityAudit(String trackedEntity, String accessedBy, ChangeLogType auditType) { + public TrackedEntityAudit(String trackedEntity, String accessedBy, AuditOperationType auditType) { this.trackedEntity = trackedEntity; this.accessedBy = accessedBy; this.created = new Date(); @@ -75,8 +75,8 @@ public TrackedEntityAudit( String comment, Date created, String accessedBy, - ChangeLogType changeLogType) { - this(trackedEntity, accessedBy, changeLogType); + AuditOperationType auditOperationType) { + this(trackedEntity, accessedBy, auditOperationType); this.comment = comment; this.created = created; } @@ -159,11 +159,11 @@ public void setAccessedBy(String accessedBy) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public ChangeLogType getAuditType() { + public AuditOperationType getAuditType() { return auditType; } - public void setAuditType(ChangeLogType auditType) { + public void setAuditType(AuditOperationType 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/TrackedEntityAuditQueryParams.java index c06962766b81..e05f52ee7cb5 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/TrackedEntityAuditQueryParams.java @@ -32,7 +32,7 @@ import java.util.List; import lombok.Data; import lombok.experimental.Accessors; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.common.Pager; /** @@ -45,7 +45,7 @@ public class TrackedEntityAuditQueryParams { 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-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/DataElementMergeService.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/DataElementMergeService.java index 1e6b29f801d9..af91e8c5dac4 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/DataElementMergeService.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/DataElementMergeService.java @@ -169,7 +169,7 @@ private void initMergeHandlers() { auditMergeHandlers = ImmutableList.builder() - .add(trackerMergeHandler::handleTrackedEntityDataValueChangelog) + .add(trackerMergeHandler::handleEventChangeLogs) .add(dataDataElementMergeHandler::handleDataValueAuditDataElement) .build(); diff --git a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/handler/TrackerDataElementMergeHandler.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/handler/TrackerDataElementMergeHandler.java index 986dff017c60..f8ab8f8ab623 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/handler/TrackerDataElementMergeHandler.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/merge/dataelement/handler/TrackerDataElementMergeHandler.java @@ -57,7 +57,6 @@ import org.hisp.dhis.programrule.ProgramRuleVariableStore; import org.hisp.dhis.tracker.export.event.EventChangeLog; import org.hisp.dhis.tracker.export.event.EventChangeLogService; -import org.hisp.dhis.tracker.export.event.TrackedEntityDataValueChangeLog; import org.springframework.stereotype.Component; /** @@ -275,14 +274,13 @@ private void setLastUpdatedAsTargetAndRemoveRemaining( } /** - * Method handling {@link TrackedEntityDataValueChangeLog}s and {@link EventChangeLog}s. Both of - * them will either be deleted or left as is, based on whether the source {@link DataElement}s are - * being deleted or not. + * Method handling {@link EventChangeLog}s. They will either be deleted or left as is, based on + * whether the source {@link DataElement}s are being deleted or not. * * @param sources source {@link DataElement}s used to retrieve {@link DataValueAudit}s * @param mergeRequest merge request */ - public void handleTrackedEntityDataValueChangelog( + public void handleEventChangeLogs( @Nonnull List sources, @Nonnull MergeRequest mergeRequest) { if (mergeRequest.isDeleteSources()) { log.info("Deleting source event change log records as source DataElements are being deleted"); 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 4a8c35fdb85d..160040e2ab88 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 @@ -30,10 +30,10 @@ import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryOptionComboStore; -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,23 @@ public List getDataValueAudits( } // case if the audit trail started out with DELETE - if (dataValueAudits.get(dataValueAudits.size() - 1).getAuditType() == ChangeLogType.DELETE) { + if (dataValueAudits.get(dataValueAudits.size() - 1).getAuditType() + == AuditOperationType.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() != ChangeLogType.CREATE) { + if (!dataValue.isDeleted() + && dataValueAudits.get(0).getAuditType() != AuditOperationType.CREATE) { DataValueAudit dataValueAudit = createDataValueAudit(dataValue); - dataValueAudit.setAuditType(ChangeLogType.UPDATE); + dataValueAudit.setAuditType(AuditOperationType.UPDATE); dataValueAudit.setCreated(dataValue.getLastUpdated()); dataValueAudits.add(0, dataValueAudit); } - dataValueAudits.get(dataValueAudits.size() - 1).setAuditType(ChangeLogType.CREATE); + dataValueAudits.get(dataValueAudits.size() - 1).setAuditType(AuditOperationType.CREATE); return dataValueAudits; } @@ -156,7 +158,7 @@ public List getDataValueAudits( private static DataValueAudit createDataValueAudit(DataValue dataValue) { DataValueAudit dataValueAudit = new DataValueAudit( - dataValue, dataValue.getValue(), dataValue.getStoredBy(), ChangeLogType.CREATE); + dataValue, dataValue.getValue(), dataValue.getStoredBy(), AuditOperationType.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 1c733e2dd0af..eb5138b0b2d5 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 @@ -38,10 +38,10 @@ import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IllegalQueryException; import org.hisp.dhis.common.UID; import org.hisp.dhis.dataelement.DataElement; @@ -143,7 +143,10 @@ public boolean addDataValue(DataValue dataValue) { if (config.isEnabled(CHANGELOG_AGGREGATE)) { DataValueAudit dataValueAudit = new DataValueAudit( - dataValue, dataValue.getValue(), dataValue.getStoredBy(), ChangeLogType.CREATE); + dataValue, + dataValue.getValue(), + dataValue.getStoredBy(), + AuditOperationType.CREATE); dataValueAuditService.addDataValueAudit(dataValueAudit); } @@ -168,7 +171,7 @@ public void updateDataValue(DataValue dataValue) { dataValue, dataValue.getAuditValue(), dataValue.getStoredBy(), - ChangeLogType.UPDATE); + AuditOperationType.UPDATE); dataValueAuditService.addDataValueAudit(dataValueAudit); } @@ -196,7 +199,7 @@ public void deleteDataValue(DataValue dataValue) { dataValue, dataValue.getAuditValue(), CurrentUserUtil.getCurrentUsername(), - ChangeLogType.DELETE); + AuditOperationType.DELETE); dataValueAuditService.addDataValueAudit(dataValueAudit); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueChangeLogDeletionHandler.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/EventChangeLogDeletionHandler.java similarity index 88% rename from dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueChangeLogDeletionHandler.java rename to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/EventChangeLogDeletionHandler.java index 11a6b0e7d97e..e7320c4d48e0 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/TrackedEntityDataValueChangeLogDeletionHandler.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/EventChangeLogDeletionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2022, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,7 +38,7 @@ */ @Component @RequiredArgsConstructor -public class TrackedEntityDataValueChangeLogDeletionHandler extends JdbcDeletionHandler { +public class EventChangeLogDeletionHandler extends JdbcDeletionHandler { @Override protected void register() { @@ -46,9 +46,6 @@ protected void register() { } private void deleteDataElement(DataElement dataElement) { - delete( - "delete from trackedentitydatavalueaudit where dataelementid = :id", - Map.of("id", dataElement.getId())); delete( "delete from eventchangelog where dataelementid = :id", Map.of("id", dataElement.getId())); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DefaultProgramMessageService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DefaultProgramMessageService.java index f521456e605b..4853a23a6624 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DefaultProgramMessageService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DefaultProgramMessageService.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.program.message; -import static org.hisp.dhis.changelog.ChangeLogType.READ; +import static org.hisp.dhis.audit.AuditOperationType.READ; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername; import java.util.ArrayList; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DeliveryChannelStrategy.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DeliveryChannelStrategy.java index 368a9c2a30fc..2f6fda80b648 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DeliveryChannelStrategy.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/message/DeliveryChannelStrategy.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.program.message; -import static org.hisp.dhis.changelog.ChangeLogType.READ; +import static org.hisp.dhis.audit.AuditOperationType.READ; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername; import java.util.Set; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultApiTrackedEntityAuditService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultApiTrackedEntityAuditService.java index 024c36c96caf..b68ef567ac7b 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultApiTrackedEntityAuditService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultApiTrackedEntityAuditService.java @@ -28,7 +28,7 @@ package org.hisp.dhis.trackedentity; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -45,13 +45,13 @@ public class DefaultApiTrackedEntityAuditService implements ApiTrackedEntityAudi @Async @Transactional public void addTrackedEntityAudit( - TrackedEntity trackedEntity, String username, ChangeLogType changeLogType) { + TrackedEntity trackedEntity, String username, AuditOperationType auditOperationType) { if (username != null && trackedEntity != null && trackedEntity.getTrackedEntityType() != null && trackedEntity.getTrackedEntityType().isAllowAuditLog()) { TrackedEntityAudit trackedEntityAudit = - new TrackedEntityAudit(trackedEntity.getUid(), username, changeLogType); + new TrackedEntityAudit(trackedEntity.getUid(), username, auditOperationType); apiTrackedEntityAuditStore.addTrackedEntityAudit(trackedEntityAudit); } } 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 a0358b2e5eeb..b316a01aa4a3 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.changelog.ChangeLogType + org.hisp.dhis.audit.AuditOperationType 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/TrackedEntityAudit.hbm.xml index 6778f22e8dca..b10aafe0aa14 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/TrackedEntityAudit.hbm.xml @@ -19,7 +19,7 @@ - org.hisp.dhis.changelog.ChangeLogType + org.hisp.dhis.audit.AuditOperationType true 12 diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml deleted file mode 100644 index 4a25ce8de9bf..000000000000 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentityattributevalue/hibernate/TrackedEntityAttributeValueChangeLog.hbm.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 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/TrackedEntityDataValueChangeLog.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueChangeLog.hbm.xml deleted file mode 100644 index 34fbecd51dda..000000000000 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/trackedentitydatavalue/hibernate/TrackedEntityDataValueChangeLog.hbm.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - trackedentitydatavalueaudit_sequence - - - - - - - - - - - - - - - - - - org.hisp.dhis.changelog.ChangeLogType - true - 12 - - - - - 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 5105bda60b0a..ff6497632025 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 @@ -54,10 +54,10 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.BooleanUtils; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.calendar.CalendarService; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.IdScheme; import org.hisp.dhis.common.IdSchemes; @@ -933,7 +933,7 @@ private void saveDataValueDelete( internalValue, existingValue.getValue(), context.getStoredBy(dataValue), - ChangeLogType.DELETE); + AuditOperationType.DELETE); context.getAuditBatchHandler().addObject(auditValue); } @@ -947,13 +947,13 @@ private void saveDataValueUpdate( ImportContext.DataValueContext valueContext, DataValue internalValue, DataValue existingValue) { - ChangeLogType changeLogType = ChangeLogType.UPDATE; + AuditOperationType auditOperationType = AuditOperationType.UPDATE; if (internalValue.isNullValue() || internalValue.isDeleted() || dataValueIsZeroAndInsignificant(dataValue.getValue(), valueContext.getDataElement())) { internalValue.setDeleted(true); - changeLogType = ChangeLogType.DELETE; + auditOperationType = AuditOperationType.DELETE; importCount.incrementDeleted(); } else { @@ -972,14 +972,14 @@ private void saveDataValueUpdate( internalValue, existingValue.getValue(), context.getStoredBy(dataValue), - changeLogType); + auditOperationType); context.getAuditBatchHandler().addObject(auditValue); } if (valueContext.getDataElement().isFileType()) { FileResource fr = fileResourceService.getFileResource(existingValue.getValue()); - if (changeLogType == ChangeLogType.DELETE) { + if (auditOperationType == AuditOperationType.DELETE) { fileResourceService.deleteFileResource(fr); } else { if (fr != null && !fr.isAssigned()) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java index 2b26663a9de9..ac78c77f92c5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/DefaultTrackedEntityAuditService.java @@ -29,7 +29,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAudit; @@ -57,13 +57,13 @@ public class DefaultTrackedEntityAuditService implements TrackedEntityAuditServi @Async @Transactional public void addTrackedEntityAudit( - TrackedEntity trackedEntity, String username, ChangeLogType changeLogType) { + TrackedEntity trackedEntity, String username, AuditOperationType auditOperationType) { if (username != null && trackedEntity != null && trackedEntity.getTrackedEntityType() != null && trackedEntity.getTrackedEntityType().isAllowAuditLog()) { TrackedEntityAudit trackedEntityAudit = - new TrackedEntityAudit(trackedEntity.getUid(), username, changeLogType); + new TrackedEntityAudit(trackedEntity.getUid(), username, auditOperationType); trackedEntityAuditStore.addTrackedEntityAudit(trackedEntityAudit); } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/TrackedEntityAuditService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/TrackedEntityAuditService.java index a789b550fa5d..b8ae73a1983e 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/TrackedEntityAuditService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/audit/TrackedEntityAuditService.java @@ -28,7 +28,7 @@ package org.hisp.dhis.tracker.audit; import java.util.List; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAudit; import org.hisp.dhis.trackedentity.TrackedEntityAuditQueryParams; @@ -41,7 +41,7 @@ public interface TrackedEntityAuditService { String ID = TrackedEntityAuditService.class.getName(); void addTrackedEntityAudit( - TrackedEntity trackedEntity, String username, ChangeLogType changeLogType); + TrackedEntity trackedEntity, String username, AuditOperationType auditOperationType); /** Adds multiple tracked entity audit */ void addTrackedEntityAudit(List trackedEntityAudits); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/OperationsParamsValidator.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/OperationsParamsValidator.java index 9fc3c83f4a5c..26ef82f9ee46 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/OperationsParamsValidator.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/OperationsParamsValidator.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.tracker.export; -import static org.hisp.dhis.changelog.ChangeLogType.READ; +import static org.hisp.dhis.audit.AuditOperationType.READ; import static org.hisp.dhis.security.Authorities.F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS; import java.util.HashSet; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventChangeLogService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventChangeLogService.java index e61d98e503e2..3a9d0f77b023 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventChangeLogService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/DefaultEventChangeLogService.java @@ -27,6 +27,10 @@ */ package org.hisp.dhis.tracker.export.event; +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 java.text.SimpleDateFormat; import java.util.Date; import java.util.Objects; @@ -143,11 +147,11 @@ private void logIfChanged( private ChangeLogType getChangeLogType(String oldValue, String newValue) { if (isFieldCreated(oldValue, newValue)) { - return ChangeLogType.CREATE; + return CREATE; } else if (isFieldUpdated(oldValue, newValue)) { - return ChangeLogType.UPDATE; + return UPDATE; } else { - return ChangeLogType.DELETE; + return DELETE; } } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLog.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLog.java deleted file mode 100644 index e168a78e79bd..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLog.java +++ /dev/null @@ -1,205 +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.tracker.export.event; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import java.io.Serializable; -import java.util.Date; -import java.util.Objects; -import org.hisp.dhis.changelog.ChangeLogType; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.program.Event; - -/** - * @author Morten Olav Hansen - */ -@JacksonXmlRootElement(localName = "trackedEntityDataValueAudit", namespace = DxfNamespaces.DXF_2_0) -public class TrackedEntityDataValueChangeLog implements Serializable { - private long id; - - private DataElement dataElement; - - private Event event; - - private Date created; - - private String value; - - private Boolean providedElsewhere; - - private String modifiedBy; - - private ChangeLogType auditType; - - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - public TrackedEntityDataValueChangeLog() {} - - public TrackedEntityDataValueChangeLog( - DataElement dataElement, - Event event, - String value, - String modifiedBy, - boolean providedElsewhere, - ChangeLogType auditType) { - this.dataElement = dataElement; - this.event = event; - this.providedElsewhere = providedElsewhere; - this.created = new Date(); - this.value = value; - this.modifiedBy = modifiedBy; - this.auditType = auditType; - } - - @Override - public int hashCode() { - return Objects.hash( - dataElement, event, created, value, providedElsewhere, modifiedBy, auditType); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - final TrackedEntityDataValueChangeLog other = (TrackedEntityDataValueChangeLog) obj; - - return Objects.equals(this.dataElement, other.dataElement) - && Objects.equals(this.event, other.event) - && Objects.equals(this.created, other.created) - && Objects.equals(this.value, other.value) - && Objects.equals(this.providedElsewhere, other.providedElsewhere) - && Objects.equals(this.modifiedBy, other.modifiedBy) - && Objects.equals(this.auditType, other.auditType); - } - - @Override - public String toString() { - return "[dataElement: '" - + dataElement.getUid() - + "', " - + "event: '" - + event.getUid() - + "', " - + "value: '" - + value - + "']"; - } - - // ------------------------------------------------------------------------- - // Getters and setters - // ------------------------------------------------------------------------- - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public Event getEvent() { - return event; - } - - public void setEvent(Event event) { - this.event = event; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public DataElement getDataElement() { - return dataElement; - } - - public void setDataElement(DataElement dataElement) { - this.dataElement = dataElement; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public Date getCreated() { - return created; - } - - public void setCreated(Date created) { - this.created = created; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public boolean getProvidedElsewhere() { - return providedElsewhere; - } - - public void setProvidedElsewhere(boolean providedElsewhere) { - this.providedElsewhere = providedElsewhere; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public String getModifiedBy() { - return modifiedBy; - } - - public void setModifiedBy(String modifiedBy) { - this.modifiedBy = modifiedBy; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public ChangeLogType getAuditType() { - return auditType; - } - - public void setAuditType(ChangeLogType auditType) { - this.auditType = auditType; - } -} diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLogQueryParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLogQueryParams.java deleted file mode 100644 index db22ad67027e..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/TrackedEntityDataValueChangeLogQueryParams.java +++ /dev/null @@ -1,74 +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.tracker.export.event; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import lombok.Data; -import lombok.experimental.Accessors; -import org.hisp.dhis.changelog.ChangeLogType; -import org.hisp.dhis.common.OrganisationUnitSelectionMode; -import org.hisp.dhis.common.Pager; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.program.Event; -import org.hisp.dhis.program.ProgramStage; - -/** - * @author Lars Helge Overland - */ -@Data -@Accessors(chain = true) -public class TrackedEntityDataValueChangeLogQueryParams { - private List dataElements = new ArrayList<>(); - - private List orgUnits = new ArrayList<>(); - - private List events = new ArrayList<>(); - - private List programStages = new ArrayList<>(); - - private Date startDate; - - private Date endDate; - - private OrganisationUnitSelectionMode ouMode; - - private List auditTypes = new ArrayList<>(); - - private Pager pager; - - public boolean hasOuMode() { - return ouMode != null; - } - - public boolean hasPaging() { - return pager != null; - } -} 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 8f04cc214766..7932f4a7510e 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 @@ -27,7 +27,8 @@ */ package org.hisp.dhis.tracker.export.trackedentity; -import static org.hisp.dhis.changelog.ChangeLogType.READ; +import static org.hisp.dhis.audit.AuditOperationType.READ; +import static org.hisp.dhis.audit.AuditOperationType.SEARCH; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUserDetails; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername; @@ -41,7 +42,6 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.UID; @@ -654,7 +654,7 @@ private void addSearchAudit(List trackedEntities) { .map( te -> new TrackedEntityAudit( - te.getUid(), CurrentUserUtil.getCurrentUsername(), ChangeLogType.SEARCH)) + te.getUid(), CurrentUserUtil.getCurrentUsername(), SEARCH)) .toList(); if (!auditable.isEmpty()) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLog.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLog.java deleted file mode 100644 index ac07c8574644..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityAttributeValueChangeLog.java +++ /dev/null @@ -1,207 +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.tracker.export.trackedentity; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import java.io.Serializable; -import java.util.Date; -import java.util.Objects; -import org.hisp.dhis.changelog.ChangeLogType; -import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentity.TrackedEntityAttribute; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; - -/** - * @author Morten Olav Hansen - */ -@JacksonXmlRootElement( - localName = "trackedEntityAttributeValueAudit", - namespace = DxfNamespaces.DXF_2_0) -public class TrackedEntityAttributeValueChangeLog implements Serializable { - private long id; - - private TrackedEntityAttribute attribute; - - private TrackedEntity trackedEntity; - - private Date created; - - private String plainValue; - - private String encryptedValue; - - private String modifiedBy; - - private ChangeLogType auditType; - - /** - * This value is only used to store values from setValue when we don't know if attribute is set or - * not. - */ - private String value; - - public TrackedEntityAttributeValueChangeLog() {} - - public TrackedEntityAttributeValueChangeLog( - TrackedEntityAttributeValue trackedEntityAttributeValue, - String value, - String modifiedBy, - ChangeLogType auditType) { - this.attribute = trackedEntityAttributeValue.getAttribute(); - this.trackedEntity = trackedEntityAttributeValue.getTrackedEntity(); - - this.created = new Date(); - this.value = value; - this.modifiedBy = modifiedBy; - this.auditType = auditType; - } - - @Override - public int hashCode() { - return Objects.hash(attribute, trackedEntity, created, getValue(), modifiedBy, auditType); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - final TrackedEntityAttributeValueChangeLog other = (TrackedEntityAttributeValueChangeLog) obj; - - return Objects.equals(this.attribute, other.attribute) - && Objects.equals(this.trackedEntity, other.trackedEntity) - && Objects.equals(this.created, other.created) - && Objects.equals(this.getValue(), other.getValue()) - && Objects.equals(this.modifiedBy, other.modifiedBy) - && Objects.equals(this.auditType, other.auditType); - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getPlainValue() { - return (Boolean.FALSE.equals(getAttribute().getConfidential()) && this.value != null - ? this.value - : this.plainValue); - } - - public void setPlainValue(String plainValue) { - this.plainValue = plainValue; - } - - public String getEncryptedValue() { - return (Boolean.TRUE.equals(getAttribute().getConfidential()) && this.value != null - ? this.value - : this.encryptedValue); - } - - public void setEncryptedValue(String encryptedValue) { - this.encryptedValue = encryptedValue; - } - - @JsonProperty("trackedEntityAttribute") - @JacksonXmlProperty(localName = "trackedEntityAttribute", namespace = DxfNamespaces.DXF_2_0) - public TrackedEntityAttribute getAttribute() { - return attribute; - } - - public void setAttribute(TrackedEntityAttribute attribute) { - this.attribute = attribute; - } - - @JsonProperty("trackedEntityInstance") - @JacksonXmlProperty(localName = "trackedEntityInstance", namespace = DxfNamespaces.DXF_2_0) - public TrackedEntity getTrackedEntity() { - return trackedEntity; - } - - public void setTrackedEntity(TrackedEntity trackedEntity) { - this.trackedEntity = trackedEntity; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public Date getCreated() { - return created; - } - - public void setCreated(Date created) { - this.created = created; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public String getValue() { - return (Boolean.TRUE.equals(getAttribute().getConfidential()) - ? this.getEncryptedValue() - : this.getPlainValue()); - } - - /** - * Property which temporarily stores the attribute value. The {@link #getEncryptedValue} and - * {@link #getPlainValue} methods handle the value when requested. - * - * @param value the value to be stored. - */ - public void setValue(String value) { - this.value = value; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public String getModifiedBy() { - return modifiedBy; - } - - public void setModifiedBy(String modifiedBy) { - this.modifiedBy = modifiedBy; - } - - @JsonProperty - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public ChangeLogType getAuditType() { - return auditType; - } - - public void setAuditType(ChangeLogType auditType) { - this.auditType = auditType; - } -} 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 7c74fb2ed93b..22862bf9d037 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 @@ -28,6 +28,9 @@ package org.hisp.dhis.tracker.imports.bundle.persister; import static com.google.common.base.Preconditions.checkNotNull; +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 jakarta.persistence.EntityManager; import java.util.ArrayList; @@ -53,7 +56,6 @@ import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; import org.hisp.dhis.tracker.TrackerIdSchemeParams; import org.hisp.dhis.tracker.TrackerType; -import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityAttributeValueChangeLog; import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityChangeLogService; import org.hisp.dhis.tracker.imports.AtomicMode; import org.hisp.dhis.tracker.imports.FlushMode; @@ -409,7 +411,7 @@ private void delete( trackedEntityAttributeValue.getPlainValue(), null, trackedEntity, - ChangeLogType.DELETE); + DELETE); } private void saveOrUpdate( @@ -433,12 +435,12 @@ private void saveOrUpdate( // 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); - changeLogType = ChangeLogType.CREATE; + changeLogType = CREATE; } else { entityManager.merge(trackedEntityAttributeValue); if (isUpdated) { - changeLogType = ChangeLogType.UPDATE; + changeLogType = UPDATE; } } @@ -486,11 +488,6 @@ private void addTrackedEntityChangeLog( boolean allowAuditLog = trackedEntity.getTrackedEntityType().isAllowAuditLog(); if (allowAuditLog && changeLogType != null) { - TrackedEntityAttributeValueChangeLog valueAudit = - new TrackedEntityAttributeValueChangeLog( - attributeValue, attributeValue.getPlainValue(), userName, changeLogType); - valueAudit.setTrackedEntity(trackedEntity); - trackedEntityChangeLogService.addTrackedEntityChangeLog( trackedEntity, attributeValue.getAttribute(), diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java index f93c8fcf41ba..4132fc0fbe86 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/bundle/persister/DefaultTrackerObjectsDeletionService.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.tracker.imports.bundle.persister; -import static org.hisp.dhis.changelog.ChangeLogType.READ; +import static org.hisp.dhis.audit.AuditOperationType.READ; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUserDetails; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername; diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java index 3ce4fd0d872d..3738462d28d5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/trackedentityattributevalue/DefaultTrackedEntityAttributeValueService.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.trackedentityattributevalue; +import static org.hisp.dhis.changelog.ChangeLogType.DELETE; import static org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER; import static org.hisp.dhis.system.util.ValidationUtils.valueIsValid; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername; @@ -35,7 +36,6 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -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; @@ -71,7 +71,7 @@ public void deleteTrackedEntityAttributeValue(TrackedEntityAttributeValue attrib attributeValue.getAttribute(), attributeValue.getPlainValue(), null, - ChangeLogType.DELETE, + DELETE, getCurrentUsername()); } 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 d9a7e120566a..3538b406168c 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.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; 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(ChangeLogType.valueOf(resultSet.getString("audittype"))); + dva.setAuditType(AuditOperationType.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 0b926565888b..b3ecc9bae3a2 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 @@ -31,9 +31,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -141,10 +141,10 @@ void setUp() { void testAddGetDataValueAuditFromDataValue() { DataValueAudit dataValueAuditA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditOperationType.UPDATE); DataValueAudit dataValueAuditB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditOperationType.UPDATE); dataValueAuditService.addDataValueAudit(dataValueAuditA); dataValueAuditService.addDataValueAudit(dataValueAuditB); @@ -156,10 +156,10 @@ void testAddGetDataValueAuditFromDataValue() { void testAddGetDataValueAuditSingleRecord() { DataValueAudit dataValueAuditA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditOperationType.UPDATE); DataValueAudit dataValueAuditB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditOperationType.UPDATE); dataValueAuditService.addDataValueAudit(dataValueAuditA); dataValueAuditService.addDataValueAudit(dataValueAuditB); @@ -179,16 +179,16 @@ void testAddGetDataValueAuditSingleRecord() { void testGetDataValueAudit() { DataValueAudit dvaA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditOperationType.UPDATE); DataValueAudit dvaB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditOperationType.UPDATE); DataValueAudit dvaC = new DataValueAudit( - dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), ChangeLogType.CREATE); + dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), AuditOperationType.CREATE); DataValueAudit dvaD = new DataValueAudit( - dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), ChangeLogType.DELETE); + dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), AuditOperationType.DELETE); dataValueAuditService.addDataValueAudit(dvaA); dataValueAuditService.addDataValueAudit(dvaB); dataValueAuditService.addDataValueAudit(dvaC); @@ -200,7 +200,7 @@ void testGetDataValueAudit() { .setPeriods(List.of(periodA)) .setOrgUnits(List.of(orgUnitA)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(ChangeLogType.UPDATE)); + .setAuditTypes(List.of(AuditOperationType.UPDATE)); assertContainsOnly(List.of(dvaA), dataValueAuditService.getDataValueAudits(params)); @@ -210,17 +210,17 @@ void testGetDataValueAudit() { .setPeriods(List.of(periodA, periodB)) .setOrgUnits(List.of(orgUnitA, orgUnitB)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(ChangeLogType.UPDATE)); + .setAuditTypes(List.of(AuditOperationType.UPDATE)); assertContainsOnly(List.of(dvaA, dvaB), dataValueAuditService.getDataValueAudits(params)); - params = new DataValueAuditQueryParams().setAuditTypes(List.of(ChangeLogType.CREATE)); + params = new DataValueAuditQueryParams().setAuditTypes(List.of(AuditOperationType.CREATE)); assertContainsOnly(List.of(dvaC), dataValueAuditService.getDataValueAudits(params)); params = new DataValueAuditQueryParams() - .setAuditTypes(List.of(ChangeLogType.CREATE, ChangeLogType.DELETE)); + .setAuditTypes(List.of(AuditOperationType.CREATE, AuditOperationType.DELETE)); assertContainsOnly(List.of(dvaC, dvaD), dataValueAuditService.getDataValueAudits(params)); } @@ -229,16 +229,16 @@ void testGetDataValueAudit() { void testGetDataValueAuditNoResult() { DataValueAudit dvaA = new DataValueAudit( - dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), ChangeLogType.UPDATE); + dataValueA, dataValueA.getValue(), dataValueA.getStoredBy(), AuditOperationType.UPDATE); DataValueAudit dvaB = new DataValueAudit( - dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), ChangeLogType.UPDATE); + dataValueB, dataValueB.getValue(), dataValueB.getStoredBy(), AuditOperationType.UPDATE); DataValueAudit dvaC = new DataValueAudit( - dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), ChangeLogType.CREATE); + dataValueC, dataValueC.getValue(), dataValueC.getStoredBy(), AuditOperationType.CREATE); DataValueAudit dvaD = new DataValueAudit( - dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), ChangeLogType.DELETE); + dataValueD, dataValueD.getValue(), dataValueD.getStoredBy(), AuditOperationType.DELETE); dataValueAuditService.addDataValueAudit(dvaA); dataValueAuditService.addDataValueAudit(dvaB); dataValueAuditService.addDataValueAudit(dvaC); @@ -250,7 +250,7 @@ void testGetDataValueAuditNoResult() { .setPeriods(List.of(periodD)) .setOrgUnits(List.of(orgUnitA)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(ChangeLogType.UPDATE)); + .setAuditTypes(List.of(AuditOperationType.UPDATE)); assertEquals(0, dataValueAuditService.getDataValueAudits(params).size()); } @@ -263,7 +263,7 @@ void testGetDataValueAuditWithFakeCreate() { .setPeriods(List.of(periodD)) .setOrgUnits(List.of(orgUnitA)) .setCategoryOptionCombo(optionCombo) - .setAuditTypes(List.of(ChangeLogType.UPDATE)); + .setAuditTypes(List.of(AuditOperationType.UPDATE)); assertEquals(0, dataValueAuditService.getDataValueAudits(params).size()); @@ -272,7 +272,7 @@ void testGetDataValueAuditWithFakeCreate() { dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(1, audits.size()); - assertEquals(ChangeLogType.CREATE, audits.get(0).getAuditType()); + assertEquals(AuditOperationType.CREATE, audits.get(0).getAuditType()); } @Test @@ -285,43 +285,43 @@ void testGetDataValueAuditWithFakeCreate2() { dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(2, audits.size()); - assertEquals(ChangeLogType.UPDATE, audits.get(0).getAuditType()); - assertEquals(ChangeLogType.CREATE, audits.get(1).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(0).getAuditType()); + assertEquals(AuditOperationType.CREATE, audits.get(1).getAuditType()); } @Test void testGetDataValueAuditWithFakeCreateDeleteAndCreate() { dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), AuditOperationType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), AuditOperationType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), AuditOperationType.UPDATE)); List audits = dataValueAuditService.getDataValueAudits( dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(4, audits.size()); - 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()); + assertEquals(AuditOperationType.CREATE, audits.get(3).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(2).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(1).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(0).getAuditType()); } @Test @Disabled void testGetDataValueAuditWithFakeCreateDelete2() { dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValueA, "10", dataValueA.getStoredBy(), AuditOperationType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValueA, "20", dataValueA.getStoredBy(), AuditOperationType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValueA, "30", dataValueA.getStoredBy(), AuditOperationType.UPDATE)); dataValueService.deleteDataValue(dataValueA); @@ -330,10 +330,10 @@ void testGetDataValueAuditWithFakeCreateDelete2() { dataElementA, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(4, audits.size()); - 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()); + assertEquals(AuditOperationType.CREATE, audits.get(3).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(2).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(1).getAuditType()); + assertEquals(AuditOperationType.DELETE, audits.get(0).getAuditType()); } @Test @@ -347,13 +347,13 @@ void testGetDataValueAuditWithFakeCreateDeleteAndUndelete() { dataValueService.addDataValue(dataValue); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValue, "10", dataValue.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValue, "10", dataValue.getStoredBy(), AuditOperationType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValue, "20", dataValue.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValue, "20", dataValue.getStoredBy(), AuditOperationType.UPDATE)); dataValueAuditService.addDataValueAudit( - new DataValueAudit(dataValue, "30", dataValue.getStoredBy(), ChangeLogType.UPDATE)); + new DataValueAudit(dataValue, "30", dataValue.getStoredBy(), AuditOperationType.UPDATE)); dataValueService.deleteDataValue(dataValue); @@ -370,11 +370,11 @@ void testGetDataValueAuditWithFakeCreateDeleteAndUndelete() { dataElement, periodA, orgUnitA, optionCombo, optionCombo); assertEquals(6, audits.size()); - 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()); + assertEquals(AuditOperationType.UPDATE, audits.get(0).getAuditType()); + assertEquals(AuditOperationType.CREATE, audits.get(1).getAuditType()); + assertEquals(AuditOperationType.DELETE, audits.get(2).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(3).getAuditType()); + assertEquals(AuditOperationType.UPDATE, audits.get(4).getAuditType()); + assertEquals(AuditOperationType.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 076676ed5c59..4986a10eeda2 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 @@ -54,12 +54,12 @@ import org.awaitility.Awaitility; import org.hisp.dhis.attribute.Attribute; import org.hisp.dhis.attribute.AttributeService; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.Category; import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IdScheme; import org.hisp.dhis.common.IdSchemes; import org.hisp.dhis.common.IdentifiableObjectManager; @@ -1314,7 +1314,7 @@ void testImportDataValuesUpdatedAudit() { () -> String.format( "expected change to dataValue %s to be audited once", dv)); - assertEquals(ChangeLogType.UPDATE, audits.get(0).getAuditType()); + assertEquals(AuditOperationType.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 bf9b88daf765..6982b81665b2 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 @@ -32,9 +32,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.datavalue.DataValue; @@ -128,10 +128,10 @@ void setUp() { dataElementA, periodA, unitB, categoryOptionComboA, categoryOptionComboA, "10"); dataValueService.addDataValue(dataValueA); dataValueService.addDataValue(dataValueB); - 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); + auditA = new DataValueAudit(dataValueA, "11", storedBy, AuditOperationType.UPDATE); + auditB = new DataValueAudit(dataValueA, "12", storedBy, AuditOperationType.UPDATE); + auditC = new DataValueAudit(dataValueB, "21", storedBy, AuditOperationType.UPDATE); + auditD = new DataValueAudit(dataValueB, "22", storedBy, AuditOperationType.UPDATE); } @Test 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 34f4fc2c6326..c9d7ad93069d 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 @@ -27,6 +27,7 @@ */ package org.hisp.dhis.maintenance; +import static org.hisp.dhis.changelog.ChangeLogType.UPDATE; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.ALL; import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -48,7 +49,6 @@ import org.hisp.dhis.audit.AuditType; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.DeliveryChannel; import org.hisp.dhis.common.IdentifiableObjectManager; @@ -338,7 +338,7 @@ void testDeleteSoftDeletedEnrollmentLinkedToAnEventDataValueChangeLog() eventA.setOrganisationUnit(organisationUnit); manager.save(eventA); eventChangeLogService.addEventChangeLog( - eventA, dataElement, "", "value", ChangeLogType.UPDATE, getCurrentUsername()); + eventA, dataElement, "", "value", UPDATE, getCurrentUsername()); manager.save(enrollment); assertNotNull(manager.get(Enrollment.class, enrollment.getUid())); manager.delete(enrollment); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java index 40e62aeb3201..6404405df508 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/merge/dataelement/DataElementMergeServiceTest.java @@ -40,6 +40,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.AnalyticalObjectStore; @@ -2551,7 +2552,7 @@ void dataValueAuditMergeDeleteTest() throws ConflictException { } // -------------------------------------- - // -- TrackedEntityDataValueChangeLog -- + // -- EventChangeLog -- // -------------------------------------- @Test @DisplayName( @@ -2671,7 +2672,7 @@ private DataValueAudit createDataValueAudit(DataElement de, String value, Period DataValueAudit dva = new DataValueAudit(); dva.setDataElement(de); dva.setValue(value); - dva.setAuditType(CREATE); + dva.setAuditType(AuditOperationType.CREATE); dva.setCreated(new Date()); dva.setCategoryOptionCombo(coc1); dva.setAttributeOptionCombo(coc1); 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/TrackedEntityAuditStoreTest.java index 7091e82c6703..7cbbf31028aa 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/TrackedEntityAuditStoreTest.java @@ -33,7 +33,7 @@ import java.util.Date; import java.util.List; -import org.hisp.dhis.changelog.ChangeLogType; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.test.integration.PostgresIntegrationTestBase; import org.hisp.dhis.tracker.audit.TrackedEntityAuditStore; import org.junit.jupiter.api.Test; @@ -53,13 +53,13 @@ class TrackedEntityAuditStoreTest extends PostgresIntegrationTestBase { @Autowired private TrackedEntityAuditStore store; private final TrackedEntityAudit auditA = - new TrackedEntityAudit("WGW7UnVcIIb", "Access", created, "userA", ChangeLogType.CREATE); + new TrackedEntityAudit("WGW7UnVcIIb", "Access", created, "userA", AuditOperationType.CREATE); private final TrackedEntityAudit auditB = - new TrackedEntityAudit("WGW7UnVcIIb", "Access", created, "userB", ChangeLogType.UPDATE); + new TrackedEntityAudit("WGW7UnVcIIb", "Access", created, "userB", AuditOperationType.UPDATE); private final TrackedEntityAudit auditC = - new TrackedEntityAudit("zIAwTY3Drrn", "Access", created, "userA", ChangeLogType.UPDATE); + new TrackedEntityAudit("zIAwTY3Drrn", "Access", created, "userA", AuditOperationType.UPDATE); private final TrackedEntityAudit auditD = - new TrackedEntityAudit("zIAwTY3Drrn", "Access", created, "userB", ChangeLogType.DELETE); + new TrackedEntityAudit("zIAwTY3Drrn", "Access", created, "userB", AuditOperationType.DELETE); @Test void shouldAuditTrackedEntity_whenAddAuditList() { @@ -73,13 +73,14 @@ void shouldAuditTrackedEntity_whenAddAuditList() { List trackedEntityAudits = store.getTrackedEntityAudit(params); assertEquals(trackedEntityAuditInput.size(), trackedEntityAudits.size()); - TrackedEntityAudit entityAudit = filterByAuditType(trackedEntityAudits, ChangeLogType.CREATE); + TrackedEntityAudit entityAudit = + filterByAuditType(trackedEntityAudits, AuditOperationType.CREATE); assertNotNull(entityAudit); assertEquals("userA", entityAudit.getAccessedBy()); assertEquals("WGW7UnVcIIb", entityAudit.getTrackedEntity()); - entityAudit = filterByAuditType(trackedEntityAudits, ChangeLogType.UPDATE); + entityAudit = filterByAuditType(trackedEntityAudits, AuditOperationType.UPDATE); assertNotNull(entityAudit); assertEquals("userB", entityAudit.getAccessedBy()); @@ -87,9 +88,9 @@ void shouldAuditTrackedEntity_whenAddAuditList() { } private static TrackedEntityAudit filterByAuditType( - List trackedEntityAuditsStore, ChangeLogType changeLogType) { + List trackedEntityAuditsStore, AuditOperationType auditOperationType) { return trackedEntityAuditsStore.stream() - .filter(a -> a.getAuditType() == changeLogType) + .filter(a -> a.getAuditType() == auditOperationType) .findFirst() .orElse(null); } @@ -111,13 +112,13 @@ void testGetAuditsByParams() { assertContainsOnly(List.of(auditA, auditC), store.getTrackedEntityAudit(params)); - params = new TrackedEntityAuditQueryParams().setAuditTypes(List.of(ChangeLogType.UPDATE)); + params = new TrackedEntityAuditQueryParams().setAuditTypes(List.of(AuditOperationType.UPDATE)); assertContainsOnly(List.of(auditB, auditC), store.getTrackedEntityAudit(params)); params = new TrackedEntityAuditQueryParams() - .setAuditTypes(List.of(ChangeLogType.CREATE, ChangeLogType.DELETE)); + .setAuditTypes(List.of(AuditOperationType.CREATE, AuditOperationType.DELETE)); assertContainsOnly(List.of(auditA, auditD), store.getTrackedEntityAudit(params)); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java index be754024a34a..7c68b06d6797 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/deduplication/DeduplicationServiceMergeIntegrationTest.java @@ -28,6 +28,7 @@ package org.hisp.dhis.tracker.deduplication; import static java.util.Objects.requireNonNull; +import static org.hisp.dhis.changelog.ChangeLogType.CREATE; import static org.hisp.dhis.changelog.ChangeLogType.UPDATE; import static org.hisp.dhis.security.Authorities.ALL; import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty; @@ -43,7 +44,6 @@ import java.util.Map; import java.util.Set; import org.hisp.dhis.analytics.AggregationType; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.UID; import org.hisp.dhis.common.ValueType; @@ -384,7 +384,7 @@ private void assertChangeLogCreate(List trackedEntityCha assertNotEmpty(trackedEntityChangeLogs); assertEquals(original.getUid(), trackedEntityChangeLogs.get(0).getTrackedEntity().getUid()); assertEquals("value", trackedEntityChangeLogs.get(0).getCurrentValue()); - assertEquals(ChangeLogType.CREATE, trackedEntityChangeLogs.get(0).getChangeLogType()); + assertEquals(CREATE, trackedEntityChangeLogs.get(0).getChangeLogType()); } private void assertChangeLogUpdate( 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/AuditController.java index cff31f133131..dcbe7d2fd270 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/AuditController.java @@ -43,8 +43,8 @@ import java.util.Set; import lombok.RequiredArgsConstructor; import org.hisp.dhis.audit.Audit; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; -import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.DhisApiVersion; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.OpenApi; @@ -174,7 +174,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, @@ -194,7 +194,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 changeLogTypes = emptyIfNull(auditType); + List auditOperationTypes = emptyIfNull(auditType); DataValueAuditQueryParams params = new DataValueAuditQueryParams() @@ -203,7 +203,7 @@ public RootNode getAggregateDataValueAudit( .setOrgUnits(organisationUnits) .setCategoryOptionCombo(categoryOptionCombo) .setAttributeOptionCombo(attributeOptionCombo) - .setAuditTypes(changeLogTypes); + .setAuditTypes(auditOperationTypes); List dataValueAudits; Pager pager = null; @@ -223,7 +223,7 @@ public RootNode getAggregateDataValueAudit( .setOrgUnits(organisationUnits) .setCategoryOptionCombo(categoryOptionCombo) .setAttributeOptionCombo(attributeOptionCombo) - .setAuditTypes(changeLogTypes) + .setAuditTypes(auditOperationTypes) .setPager(pager)); } @@ -314,7 +314,7 @@ public RootNode getTrackedEntityInstanceAudit( @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, @@ -328,7 +328,7 @@ public RootNode getTrackedEntityInstanceAudit( fields.addAll(FieldPreset.ALL.getFields()); } - List changeLogTypes = emptyIfNull(auditType); + List auditOperationTypes = emptyIfNull(auditType); Set teUids = validateDeprecatedUidsParameter( @@ -338,7 +338,7 @@ public RootNode getTrackedEntityInstanceAudit( new TrackedEntityAuditQueryParams() .setTrackedEntities(UID.toValueList(teUids)) .setUsers(user) - .setAuditTypes(changeLogTypes) + .setAuditTypes(auditOperationTypes) .setStartDate(startDate) .setEndDate(endDate); @@ -377,7 +377,7 @@ public RootNode getTrackedEntityAudit( @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, @@ -390,13 +390,13 @@ public RootNode getTrackedEntityAudit( fields.addAll(FieldPreset.ALL.getFields()); } - List changeLogTypes = emptyIfNull(auditType); + List auditOperationTypes = emptyIfNull(auditType); TrackedEntityAuditQueryParams params = new TrackedEntityAuditQueryParams() .setTrackedEntities(UID.toValueList(trackedEntities)) .setUsers(user) - .setAuditTypes(changeLogTypes) + .setAuditTypes(auditOperationTypes) .setStartDate(startDate) .setEndDate(endDate); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportController.java index 10e2b59cf7c4..22587faa0276 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportController.java @@ -363,6 +363,7 @@ ResponseEntity getEventDataValueImage( request, eventService.getFileResourceImage(event, dataElement, dimension)); } + @OpenApi.Response(status = Status.OK, value = Page.class) @GetMapping("/{event}/changeLogs") ResponseEntity> getEventChangeLogsByUid( @OpenApi.Param({UID.class, Event.class}) @PathVariable UID event, diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java index e57977c33f59..182c73e63a3b 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/trackedentity/TrackedEntitiesExportController.java @@ -351,8 +351,9 @@ ResponseEntity getAttributeValueImage( trackedEntityService.getFileResourceImage(trackedEntity, attribute, program, dimension)); } + @OpenApi.Response(status = Status.OK, value = Page.class) @GetMapping("/{trackedEntity}/changeLogs") - ResponseEntity> getTrackedEntityAttributeChangeLog( + ResponseEntity> getTrackedEntityChangeLog( @OpenApi.Param({UID.class, org.hisp.dhis.trackedentity.TrackedEntity.class}) @PathVariable UID trackedEntity, @OpenApi.Param({UID.class, Program.class}) @RequestParam(required = false) UID program, 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 30d2c5eb2897..d48c386d3a82 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 @@ -33,8 +33,8 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; +import org.hisp.dhis.audit.AuditOperationType; import org.hisp.dhis.category.CategoryOptionCombo; -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 ChangeLogType auditType; + @JsonProperty private AuditOperationType auditType; } From f4f2aca67f194d6780242adbadd6305513f4ad10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 11 Dec 2024 10:15:44 +0100 Subject: [PATCH 4/5] fix: Use dynamic org unit level analytics table columns [DHIS2-18417] (#19439) --- ...dbcTrackedEntityAnalyticsTableManager.java | 41 +------------------ ...ntityEnrollmentsAnalyticsTableManager.java | 25 +---------- ...ckedEntityEventsAnalyticsTableManager.java | 25 +---------- .../dhis/analytics/util/AnalyticsUtils.java | 30 -------------- ...EntityEventsAnalyticsTableManagerTest.java | 4 +- .../analytics/util/AnalyticsUtilsTest.java | 8 ---- .../dhis/db/sql/ClickHouseSqlBuilder.java | 5 +++ .../org/hisp/dhis/db/sql/DorisSqlBuilder.java | 5 +++ .../hisp/dhis/db/sql/PostgreSqlBuilder.java | 5 +++ .../java/org/hisp/dhis/db/sql/SqlBuilder.java | 5 +++ 10 files changed, 26 insertions(+), 127 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java index 4a483d156d37..5ef9f9a562d4 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java @@ -35,7 +35,6 @@ import static org.hisp.dhis.analytics.util.AnalyticsUtils.getColumnType; import static org.hisp.dhis.analytics.util.DisplayNameUtils.getDisplayName; import static org.hisp.dhis.commons.util.TextUtils.removeLastComma; -import static org.hisp.dhis.commons.util.TextUtils.replace; import static org.hisp.dhis.db.model.DataType.BOOLEAN; import static org.hisp.dhis.db.model.DataType.CHARACTER_11; import static org.hisp.dhis.db.model.DataType.DOUBLE; @@ -65,7 +64,6 @@ import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.common.ValueType; import org.hisp.dhis.dataapproval.DataApprovalLevelService; import org.hisp.dhis.db.model.IndexType; import org.hisp.dhis.db.model.Logged; @@ -85,7 +83,7 @@ import org.springframework.transaction.annotation.Transactional; @Component("org.hisp.dhis.analytics.TrackedEntityAnalyticsTableManager") -public class JdbcTrackedEntityAnalyticsTableManager extends AbstractJdbcTableManager { +public class JdbcTrackedEntityAnalyticsTableManager extends AbstractEventJdbcTableManager { private static final String PROGRAMS_BY_TET_KEY = "programsByTetUid"; private static final String ALL_NON_CONFIDENTIAL_TET_ATTRIBUTES = @@ -215,7 +213,7 @@ private List getColumns( .name(tea.getUid()) .dataType(getColumnType(tea.getValueType(), isSpatialSupport())) .selectExpression( - castBasedOnType(tea.getValueType(), quote(tea.getUid()) + ".value")) + getColumnExpression(tea.getValueType(), quote(tea.getUid()) + ".value")) .build()) .toList()); @@ -242,41 +240,6 @@ private Stream getAllTrackedEntityAttributes( return getAllTrackedEntityAttributesByEntityType(trackedEntityType); } - /** - * Returns the select clause, potentially with a cast statement, based on the given value type. - * - * @param valueType the value type to represent as database column type. - */ - private String castBasedOnType(ValueType valueType, String columnName) { - if (valueType.isDecimal()) { - - return replace( - " cast(${columnName} as ${type})", - Map.of("columnName", columnName, "type", sqlBuilder.dataTypeDouble())); - } - if (valueType.isInteger()) { - return replace(" cast(${columnName} as bigint)", Map.of("columnName", columnName)); - } - if (valueType.isBoolean()) { - return replace( - " case when ${columnName} = 'true' then 1 when ${columnName} = 'false' then 0 end ", - Map.of("columnName", columnName)); - } - if (valueType.isDate()) { - return replace( - " cast(${columnName} as ${type})", - Map.of("columnName", columnName, "type", sqlBuilder.dataTypeTimestamp())); - } - if (valueType.isGeo() && isSpatialSupport() && sqlBuilder.supportsGeospatialData()) { - return replace( - """ - \s ST_GeomFromGeoJSON('{"type":"Point", "coordinates":' || (${columnName}) || ', - "crs":{"type":"name", "properties":{"name":"EPSG:4326"}}}')""", - Map.of("columnName", columnName)); - } - return columnName; - } - /** * Returns all {@link TrackedEntityAttribute} for the given {@link TrackedEntityType} and * programs. diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java index 70428872148d..a00e34eb392b 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java @@ -115,30 +115,6 @@ public class JdbcTrackedEntityEnrollmentsAnalyticsTableManager extends AbstractJ .dataType(VARCHAR_50) .selectExpression("en.status") .build(), - AnalyticsTableColumn.builder() - .name("uidlevel1") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel1") - .build(), - AnalyticsTableColumn.builder() - .name("uidlevel2") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel2") - .build(), - AnalyticsTableColumn.builder() - .name("uidlevel3") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel3") - .build(), - AnalyticsTableColumn.builder() - .name("uidlevel4") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel4") - .build(), AnalyticsTableColumn.builder() .name("ou") .dataType(CHARACTER_11) @@ -225,6 +201,7 @@ private List getColumns() { List columns = new ArrayList<>(); columns.addAll(getFixedCols()); columns.add(getOrganisationUnitNameHierarchyColumn()); + columns.addAll(getOrganisationUnitLevelColumns()); if (sqlBuilder.supportsDeclarativePartitioning()) { columns.add(getPartitionColumn()); } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java index a89213becd23..b3968442378b 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java @@ -143,30 +143,6 @@ public class JdbcTrackedEntityEventsAnalyticsTableManager extends AbstractJdbcTa .dataType(VARCHAR_50) .selectExpression("ev.status") .build(), - AnalyticsTableColumn.builder() - .name("uidlevel1") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel1") - .build(), - AnalyticsTableColumn.builder() - .name("uidlevel2") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel2") - .build(), - AnalyticsTableColumn.builder() - .name("uidlevel3") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel3") - .build(), - AnalyticsTableColumn.builder() - .name("uidlevel4") - .dataType(CHARACTER_11) - .nullable(NULL) - .selectExpression("ous.uidlevel4") - .build(), AnalyticsTableColumn.builder() .name("ou") .dataType(CHARACTER_11) @@ -367,6 +343,7 @@ private List getColumns() { } columns.add(getOrganisationUnitNameHierarchyColumn()); + columns.addAll(getOrganisationUnitLevelColumns()); return columns; } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsUtils.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsUtils.java index cf73c25f349d..b61b7a82bbaa 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsUtils.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/util/AnalyticsUtils.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.analytics.util; -import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.hisp.dhis.common.DataDimensionItem.DATA_DIM_TYPE_CLASS_MAP; import static org.hisp.dhis.common.DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID; import static org.hisp.dhis.common.DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID; @@ -1202,33 +1201,4 @@ public static String replaceStringBetween( Matcher matcher = pattern.matcher(original); return matcher.replaceAll(startToken + replacement + endToken); } - - /** - * Returns a string containing closing parenthesis. The number of parenthesis is based on the - * number of missing closing parenthesis in the argument string. - * - *

Example: - * - *

{@code} input: "((( ))" -> output: ")" {@code} - * - * @param str a string. - * @return a String containing 0 or more "closing" parenthesis - */ - public static String getClosingParentheses(String str) { - if (StringUtils.isEmpty(str)) { - return EMPTY; - } - - int open = 0; - - for (int i = 0; i < str.length(); i++) { - if (str.charAt(i) == '(') { - open++; - } else if ((str.charAt(i) == ')') && open >= 1) { - open--; - } - } - - return StringUtils.repeat(")", open); - } } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManagerTest.java index 4cb4bdf9f195..57fce6c172ac 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManagerTest.java @@ -160,9 +160,9 @@ void testPopulateTable() { String expectedSql = """ insert into analytics_te_event_tetuid_temp ("trackedentity","program","enrollment","programstage","event","occurreddate","lastupdated","created", - "scheduleddate","status","uidlevel1","uidlevel2","uidlevel3","uidlevel4","ou","ouname","oucode","oulevel","eventdatavalues","eventgeometry", + "scheduleddate","status","ou","ouname","oucode","oulevel","eventdatavalues","eventgeometry", "evlongitude","evlatitude","ounamehierarchy") select distinct te.uid,p.uid,en.uid,ps.uid,ev.uid,ev.occurreddate,ev.lastupdated, - ev.created,ev.scheduleddate,ev.status,ous.uidlevel1,ous.uidlevel2,ous.uidlevel3,ous.uidlevel4,ous.organisationunituid,ous.name,ous.code,ous.level, + ev.created,ev.scheduleddate,ev.status,ous.organisationunituid,ous.name,ous.code,ous.level, %s, ev.geometry,case when 'POINT' = GeometryType(ev.geometry) then ST_X(ev.geometry) end,case when 'POINT' = GeometryType(ev.geometry) then ST_Y(ev.geometry) end,concat_ws(' / ',) as ounamehierarchy from "event" ev inner join "enrollment" en on en.enrollmentid=ev.enrollmentid diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsUtilsTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsUtilsTest.java index dbbb563aa2ac..d2b77d2fecbf 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsUtilsTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/util/AnalyticsUtilsTest.java @@ -739,14 +739,6 @@ void testGetEnumCaseSensitivity() { assertNull(EnumUtils.getEnum(Database.class, "postgresql")); } - @Test - void testGetClosingParentheses() { - assertEquals("", AnalyticsUtils.getClosingParentheses(null)); - assertEquals("", AnalyticsUtils.getClosingParentheses("")); - assertEquals(")", AnalyticsUtils.getClosingParentheses("from(select(select (*))")); - assertEquals("))", AnalyticsUtils.getClosingParentheses("((")); - } - @Test void whenUncategorizedSQLException_withTableNotExisting_thenThrowException() { SQLException sqlException = new SQLException("relation does not exist", "42P01"); diff --git a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java index f763eace89e7..6381be607075 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/ClickHouseSqlBuilder.java @@ -164,6 +164,11 @@ public boolean supportsVacuum() { return false; } + @Override + public boolean supportsCorrelatedSubquery() { + return false; + } + @Override public boolean requiresIndexesForAnalytics() { return false; diff --git a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java index e4414841175f..48bfe6bc31b8 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java @@ -166,6 +166,11 @@ public boolean supportsVacuum() { return false; } + @Override + public boolean supportsCorrelatedSubquery() { + return true; + } + @Override public boolean requiresIndexesForAnalytics() { return false; diff --git a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java index f28259ce271b..92a14270f8cc 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java @@ -185,6 +185,11 @@ public boolean supportsVacuum() { return true; } + @Override + public boolean supportsCorrelatedSubquery() { + return true; + } + @Override public boolean requiresIndexesForAnalytics() { return true; diff --git a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/SqlBuilder.java b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/SqlBuilder.java index 78bbd2d866a4..07016f4c6e8d 100644 --- a/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/SqlBuilder.java +++ b/dhis-2/dhis-support/dhis-support-sql/src/main/java/org/hisp/dhis/db/sql/SqlBuilder.java @@ -174,6 +174,11 @@ public interface SqlBuilder { */ boolean supportsVacuum(); + /** + * @return true if the DBMS supports corrected subqueries. + */ + boolean supportsCorrelatedSubquery(); + /** * @return true if the DBMS requires indexes for analytics tables for performance. */ From 067112fd1f4c53c3ffdbc8110b23a602ed22f235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 11 Dec 2024 11:16:57 +0100 Subject: [PATCH 5/5] refactor: Use util method for SQL generation [DHIS2-16705] (#19441) --- .../table/JdbcAnalyticsTableManager.java | 47 ++++++++-------- .../table/JdbcCompletenessTableManager.java | 31 ++++------- .../JdbcCompletenessTargetTableManager.java | 19 ++----- .../table/JdbcOrgUnitTargetTableManager.java | 19 ++----- .../JdbcOwnershipAnalyticsTableManager.java | 13 ++--- ...dbcTrackedEntityAnalyticsTableManager.java | 29 ++++------ ...ntityEnrollmentsAnalyticsTableManager.java | 53 ++++++++----------- ...ckedEntityEventsAnalyticsTableManager.java | 53 ++++++++----------- .../JdbcValidationResultTableManager.java | 19 ++----- 9 files changed, 106 insertions(+), 177 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java index 359bba2ce1d2..31d587e51392 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java @@ -340,38 +340,33 @@ private void populateTable( StringBuilder sql = new StringBuilder(replace("insert into ${tableName} (", Map.of("tableName", tableName))); - List dimensions = partition.getMasterTable().getDimensionColumns(); List columns = partition.getMasterTable().getAnalyticsTableColumns(); + List dimensions = partition.getMasterTable().getDimensionColumns(); - for (AnalyticsTableColumn col : columns) { - sql.append(quote(col.getName()) + ","); - } - - sql = TextUtils.removeLastComma(sql).append(") select "); - - for (AnalyticsTableColumn col : dimensions) { - sql.append(col.getSelectExpression() + ","); - } + sql.append(toCommaSeparated(columns, col -> quote(col.getName()))); + sql.append(") select "); + sql.append(toCommaSeparated(dimensions, AnalyticsTableColumn::getSelectExpression)); + sql.append(","); sql.append( replaceQualify( """ - ${approvalSelectExpression} \ - as approvallevel, \ - ${valueExpression} * ps.daysno as daysxvalue, \ - ps.daysno as daysno, \ - ${valueExpression} as value, \ - ${textValueExpression} as textvalue \ - from ${datavalue} dv \ - inner join analytics_rs_periodstructure ps on dv.periodid=ps.periodid \ - inner join analytics_rs_dataelementstructure des on dv.dataelementid=des.dataelementid \ - inner join analytics_rs_dataelementgroupsetstructure degs on dv.dataelementid=degs.dataelementid \ - inner join analytics_rs_orgunitstructure ous on dv.sourceid=ous.organisationunitid \ - inner join analytics_rs_organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid \ - inner join analytics_rs_categorystructure dcs on dv.categoryoptioncomboid=dcs.categoryoptioncomboid \ - inner join analytics_rs_categorystructure acs on dv.attributeoptioncomboid=acs.categoryoptioncomboid \ - inner join analytics_rs_categoryoptioncomboname aon on dv.attributeoptioncomboid=aon.categoryoptioncomboid \ - inner join analytics_rs_categoryoptioncomboname con on dv.categoryoptioncomboid=con.categoryoptioncomboid\s""", + ${approvalSelectExpression} \ + as approvallevel, \ + ${valueExpression} * ps.daysno as daysxvalue, \ + ps.daysno as daysno, \ + ${valueExpression} as value, \ + ${textValueExpression} as textvalue \ + from ${datavalue} dv \ + inner join analytics_rs_periodstructure ps on dv.periodid=ps.periodid \ + inner join analytics_rs_dataelementstructure des on dv.dataelementid=des.dataelementid \ + inner join analytics_rs_dataelementgroupsetstructure degs on dv.dataelementid=degs.dataelementid \ + inner join analytics_rs_orgunitstructure ous on dv.sourceid=ous.organisationunitid \ + inner join analytics_rs_organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid \ + inner join analytics_rs_categorystructure dcs on dv.categoryoptioncomboid=dcs.categoryoptioncomboid \ + inner join analytics_rs_categorystructure acs on dv.attributeoptioncomboid=acs.categoryoptioncomboid \ + inner join analytics_rs_categoryoptioncomboname aon on dv.attributeoptioncomboid=aon.categoryoptioncomboid \ + inner join analytics_rs_categoryoptioncomboname con on dv.categoryoptioncomboid=con.categoryoptioncomboid\s""", Map.of( "approvalSelectExpression", approvalSelectExpression, "valueExpression", valueExpression, diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java index fe98336a13f9..ba1d569a99b7 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java @@ -57,7 +57,6 @@ import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.commons.util.TextUtils; import org.hisp.dhis.dataapproval.DataApprovalLevelService; import org.hisp.dhis.db.sql.SqlBuilder; import org.hisp.dhis.organisationunit.OrganisationUnitService; @@ -151,11 +150,11 @@ public boolean hasUpdatedLatestData(Date startDate, Date endDate) { String sql = replaceQualify( """ - select cdr.datasetid \ - from ${completedatasetregistration} cdr \ - where cdr.lastupdated >= '${startDate}' \ - and cdr.lastupdated < '${endDate}' \ - limit 1;""", + select cdr.datasetid \ + from ${completedatasetregistration} cdr \ + where cdr.lastupdated >= '${startDate}' \ + and cdr.lastupdated < '${endDate}' \ + limit 1;""", Map.of("startDate", toLongDate(startDate), "endDate", toLongDate(endDate))); return !jdbcTemplate.queryForList(sql).isEmpty(); @@ -196,24 +195,14 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti String tableName = partition.getName(); String partitionClause = getPartitionClause(partition); - String sql = "insert into " + tableName + " ("; - List columns = partition.getMasterTable().getAnalyticsTableColumns(); - for (AnalyticsTableColumn col : columns) { - sql += quote(col.getName()) + ","; - } - - sql = TextUtils.removeLastComma(sql) + ") select "; - - for (AnalyticsTableColumn col : columns) { - sql += col.getSelectExpression() + ","; - } - - sql = TextUtils.removeLastComma(sql) + " "; - + String sql = "insert into " + tableName + " ("; + sql += toCommaSeparated(columns, col -> quote(col.getName())); + sql += ") select "; + sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression); + sql += " "; // Database legacy fix - sql = sql.replace("organisationunitid", "sourceid"); sql += diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java index 4b74d8ccee2a..ed32291a7083 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java @@ -48,7 +48,6 @@ import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.commons.util.TextUtils; import org.hisp.dhis.dataapproval.DataApprovalLevelService; import org.hisp.dhis.db.model.Logged; import org.hisp.dhis.db.sql.SqlBuilder; @@ -159,21 +158,13 @@ protected List getPartitionChecks(Integer year, Date endDate) { public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) { String tableName = partition.getName(); - String sql = "insert into " + tableName + " ("; - List columns = partition.getMasterTable().getAnalyticsTableColumns(); - for (AnalyticsTableColumn col : columns) { - sql += quote(col.getName()) + ","; - } - - sql = TextUtils.removeLastComma(sql) + ") select "; - - for (AnalyticsTableColumn col : columns) { - sql += col.getSelectExpression() + ","; - } - - sql = TextUtils.removeLastComma(sql) + " "; + String sql = "insert into " + tableName + " ("; + sql += toCommaSeparated(columns, col -> quote(col.getName())); + sql += ") select "; + sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression); + sql += " "; sql += qualifyVariables( diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java index 5874ec70477f..9515e9eac449 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOrgUnitTargetTableManager.java @@ -49,7 +49,6 @@ import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.IdentifiableObjectManager; -import org.hisp.dhis.commons.util.TextUtils; import org.hisp.dhis.dataapproval.DataApprovalLevelService; import org.hisp.dhis.db.model.Logged; import org.hisp.dhis.db.sql.SqlBuilder; @@ -134,21 +133,13 @@ protected List getPartitionChecks(Integer year, Date endDate) { public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) { String tableName = partition.getName(); - String sql = replace("insert into ${tableName} (", Map.of("tableName", quote(tableName))); - List columns = partition.getMasterTable().getAnalyticsTableColumns(); - for (AnalyticsTableColumn col : columns) { - sql += quote(col.getName()) + ","; - } - - sql = TextUtils.removeLastComma(sql) + ") select "; - - for (AnalyticsTableColumn col : columns) { - sql += col.getSelectExpression() + ","; - } - - sql = TextUtils.removeLastComma(sql) + " "; + String sql = replace("insert into ${tableName} (", Map.of("tableName", quote(tableName))); + sql += toCommaSeparated(columns, col -> quote(col.getName())); + sql += ") select "; + sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression); + sql += " "; sql += qualifyVariables( diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java index 2d3b77847e19..50bf484bddb9 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcOwnershipAnalyticsTableManager.java @@ -239,15 +239,12 @@ private void populateOwnershipTableInternal(AnalyticsTablePartition partition, S * @return a SQL select query. */ private String getInputSql(Program program) { - StringBuilder sb = new StringBuilder("select "); + List columns = getColumns(); - for (AnalyticsTableColumn col : getColumns()) { - sb.append(col.getSelectExpression()).append(","); - } - - sb.deleteCharAt(sb.length() - 1); // Remove the final ','. + StringBuilder sql = new StringBuilder("select "); + sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression)); - sb.append( + sql.append( replaceQualify( """ \sfrom (\ @@ -272,7 +269,7 @@ and exists (\ "historyTableId", HISTORY_TABLE_ID, "trackedEntityOwnTableId", TRACKED_ENTITY_OWN_TABLE_ID, "programId", String.valueOf(program.getId())))); - return sb.toString(); + return sql.toString(); } private Map getRowMap(List columnNames, ResultSet resultSet) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java index 5ef9f9a562d4..dc0e4030bcf0 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityAnalyticsTableManager.java @@ -34,7 +34,6 @@ import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.EXPORTABLE_EVENT_STATUSES; import static org.hisp.dhis.analytics.util.AnalyticsUtils.getColumnType; import static org.hisp.dhis.analytics.util.DisplayNameUtils.getDisplayName; -import static org.hisp.dhis.commons.util.TextUtils.removeLastComma; import static org.hisp.dhis.db.model.DataType.BOOLEAN; import static org.hisp.dhis.db.model.DataType.CHARACTER_11; import static org.hisp.dhis.db.model.DataType.DOUBLE; @@ -295,27 +294,19 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti List columns = partition.getMasterTable().getAnalyticsTableColumns(); StringBuilder sql = new StringBuilder("insert into " + tableName + " ("); - - for (AnalyticsTableColumn col : columns) { - sql.append(quote(col.getName()) + ","); - } - - removeLastComma(sql).append(") select "); - - for (AnalyticsTableColumn col : columns) { - sql.append(col.getSelectExpression() + ","); - } + sql.append(toCommaSeparated(columns, col -> quote(col.getName()))); + sql.append(") select "); + sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression)); TrackedEntityType trackedEntityType = partition.getMasterTable().getTrackedEntityType(); - removeLastComma(sql) - .append( - replaceQualify( - """ - \sfrom ${trackedentity} te \ - left join analytics_rs_orgunitstructure ous on te.organisationunitid=ous.organisationunitid \ - left join analytics_rs_organisationunitgroupsetstructure ougs on te.organisationunitid=ougs.organisationunitid""", - Map.of())); + sql.append( + replaceQualify( + """ + \sfrom ${trackedentity} te \ + left join analytics_rs_orgunitstructure ous on te.organisationunitid=ous.organisationunitid \ + left join analytics_rs_organisationunitgroupsetstructure ougs on te.organisationunitid=ougs.organisationunitid""", + Map.of())); ((List) params.getExtraParam(trackedEntityType.getUid(), ALL_NON_CONFIDENTIAL_TET_ATTRIBUTES)) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java index a00e34eb392b..31d7c936eda9 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEnrollmentsAnalyticsTableManager.java @@ -31,7 +31,6 @@ import static java.lang.String.valueOf; import static org.hisp.dhis.analytics.AnalyticsTableType.TRACKED_ENTITY_INSTANCE_ENROLLMENTS; import static org.hisp.dhis.analytics.table.JdbcEventAnalyticsTableManager.EXPORTABLE_EVENT_STATUSES; -import static org.hisp.dhis.commons.util.TextUtils.removeLastComma; import static org.hisp.dhis.db.model.DataType.CHARACTER_11; import static org.hisp.dhis.db.model.DataType.DOUBLE; import static org.hisp.dhis.db.model.DataType.GEOMETRY; @@ -222,41 +221,33 @@ protected List getPartitionChecks(Integer year, Date endDate) { @Override public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) { String tableName = partition.getName(); + long tetId = partition.getMasterTable().getTrackedEntityType().getId(); List columns = partition.getMasterTable().getAnalyticsTableColumns(); StringBuilder sql = new StringBuilder("insert into " + tableName + " ("); + sql.append(toCommaSeparated(columns, col -> quote(col.getName()))); + sql.append(") select "); + sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression)); - for (AnalyticsTableColumn col : columns) { - sql.append(quote(col.getName()) + ","); - } - - removeLastComma(sql).append(") select "); - - for (AnalyticsTableColumn col : columns) { - sql.append(col.getSelectExpression() + ","); - } - - removeLastComma(sql) - .append( - replaceQualify( - """ - \sfrom ${enrollment} en \ - inner join ${trackedentity} te on en.trackedentityid=te.trackedentityid \ - and te.deleted = false and te.trackedentitytypeid = ${trackedEntityTypeId} \ - and te.lastupdated < '${startTime}' \ - left join ${program} p on en.programid=p.programid \ - left join analytics_rs_orgunitstructure ous on en.organisationunitid=ous.organisationunitid \ - where exists (select 1 from ${event} ev where ev.deleted = false \ - and ev.enrollmentid = en.enrollmentid \ - and ev.status in (${statuses})) \ - and en.occurreddate is not null \ - and en.deleted = false\s""", - Map.of( - "trackedEntityTypeId", - valueOf(partition.getMasterTable().getTrackedEntityType().getId()), - "startTime", toLongDate(params.getStartTime()), - "statuses", join(",", EXPORTABLE_EVENT_STATUSES)))); + sql.append( + replaceQualify( + """ + \sfrom ${enrollment} en \ + inner join ${trackedentity} te on en.trackedentityid=te.trackedentityid \ + and te.deleted = false and te.trackedentitytypeid = ${trackedEntityTypeId} \ + and te.lastupdated < '${startTime}' \ + left join ${program} p on en.programid=p.programid \ + left join analytics_rs_orgunitstructure ous on en.organisationunitid=ous.organisationunitid \ + where exists (select 1 from ${event} ev where ev.deleted = false \ + and ev.enrollmentid = en.enrollmentid \ + and ev.status in (${statuses})) \ + and en.occurreddate is not null \ + and en.deleted = false\s""", + Map.of( + "trackedEntityTypeId", valueOf(tetId), + "startTime", toLongDate(params.getStartTime()), + "statuses", join(",", EXPORTABLE_EVENT_STATUSES)))); invokeTimeAndLog(sql.toString(), "Populating table: '{}'", tableName); } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java index b3968442378b..7f9aed298e6a 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTrackedEntityEventsAnalyticsTableManager.java @@ -34,7 +34,6 @@ import static org.hisp.dhis.analytics.table.util.PartitionUtils.getStartDate; import static org.hisp.dhis.commons.util.TextUtils.emptyIfTrue; import static org.hisp.dhis.commons.util.TextUtils.format; -import static org.hisp.dhis.commons.util.TextUtils.removeLastComma; import static org.hisp.dhis.commons.util.TextUtils.replace; import static org.hisp.dhis.db.model.DataType.CHARACTER_11; import static org.hisp.dhis.db.model.DataType.DOUBLE; @@ -363,41 +362,35 @@ protected List getPartitionChecks(Integer year, Date endDate) { public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTablePartition partition) { AnalyticsTable masterTable = partition.getMasterTable(); String tableName = partition.getName(); + long tetId = masterTable.getTrackedEntityType().getId(); List columns = partition.getMasterTable().getAnalyticsTableColumns(); String partitionClause = sqlBuilder.supportsDeclarativePartitioning() ? "" : getPartitionClause(partition); StringBuilder sql = new StringBuilder("insert into " + tableName + " ("); + sql.append(toCommaSeparated(columns, col -> quote(col.getName()))); + sql.append(") select distinct "); + sql.append(toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression)); + sql.append(" "); - for (AnalyticsTableColumn col : columns) { - sql.append(quote(col.getName()) + ","); - } - - removeLastComma(sql).append(") select distinct "); - - for (AnalyticsTableColumn col : columns) { - sql.append(col.getSelectExpression() + ","); - } - - removeLastComma(sql) - .append( - replaceQualify( - """ - \s from ${event} ev \ - inner join ${enrollment} en on en.enrollmentid=ev.enrollmentid and en.deleted = false \ - inner join ${trackedentity} te on te.trackedentityid=en.trackedentityid \ - and te.deleted = false and te.trackedentitytypeid = ${tetId} and te.lastupdated < '${startTime}' \ - left join ${programstage} ps on ev.programstageid=ps.programstageid \ - left join ${program} p on ps.programid=p.programid \ - left join analytics_rs_orgunitstructure ous on ev.organisationunitid=ous.organisationunitid \ - where ev.status in (${statuses}) \ - ${partitionClause} \ - and ev.deleted = false\s""", - Map.of( - "tetId", String.valueOf(masterTable.getTrackedEntityType().getId()), - "startTime", toLongDate(params.getStartTime()), - "statuses", join(",", EXPORTABLE_EVENT_STATUSES), - "partitionClause", partitionClause))); + sql.append( + replaceQualify( + """ + from ${event} ev \ + inner join ${enrollment} en on en.enrollmentid=ev.enrollmentid and en.deleted = false \ + inner join ${trackedentity} te on te.trackedentityid=en.trackedentityid \ + and te.deleted = false and te.trackedentitytypeid = ${tetId} and te.lastupdated < '${startTime}' \ + left join ${programstage} ps on ev.programstageid=ps.programstageid \ + left join ${program} p on ps.programid=p.programid \ + left join analytics_rs_orgunitstructure ous on ev.organisationunitid=ous.organisationunitid \ + where ev.status in (${statuses}) \ + ${partitionClause} \ + and ev.deleted = false\s""", + Map.of( + "tetId", String.valueOf(tetId), + "startTime", toLongDate(params.getStartTime()), + "statuses", join(",", EXPORTABLE_EVENT_STATUSES), + "partitionClause", partitionClause))); invokeTimeAndLog(sql.toString(), "Populating table: '{}'", tableName); } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java index 26614fdc3c12..e6409edcd11f 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcValidationResultTableManager.java @@ -30,7 +30,6 @@ import static org.hisp.dhis.analytics.table.model.AnalyticsValueType.FACT; import static org.hisp.dhis.commons.util.TextUtils.emptyIfTrue; import static org.hisp.dhis.commons.util.TextUtils.format; -import static org.hisp.dhis.commons.util.TextUtils.removeLastComma; import static org.hisp.dhis.db.model.DataType.CHARACTER_11; import static org.hisp.dhis.db.model.DataType.DATE; import static org.hisp.dhis.db.model.DataType.INTEGER; @@ -164,21 +163,13 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti String tableName = partition.getName(); String partitionClause = getPartitionClause(partition); - String sql = "insert into " + tableName + " ("; - List columns = partition.getMasterTable().getAnalyticsTableColumns(); - for (AnalyticsTableColumn col : columns) { - sql += quote(col.getName()) + ","; - } - - sql = removeLastComma(sql) + ") select "; - - for (AnalyticsTableColumn col : columns) { - sql += col.getSelectExpression() + ","; - } - - sql = removeLastComma(sql) + " "; + String sql = "insert into " + tableName + " ("; + sql += toCommaSeparated(columns, col -> quote(col.getName())); + sql += ") select "; + sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression); + sql += " "; // Database legacy fix