From 049e0408e58a8c64e254c019ecf285177013cd2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Nov 2023 08:28:53 +0100 Subject: [PATCH 01/12] chore(deps-dev): bump com.nimbusds:nimbus-jose-jwt in /dhis-2 (#15631) Bumps [com.nimbusds:nimbus-jose-jwt](https://bitbucket.org/connect2id/nimbus-jose-jwt) from 9.37 to 9.37.1. - [Changelog](https://bitbucket.org/connect2id/nimbus-jose-jwt/src/master/CHANGELOG.txt) - [Commits](https://bitbucket.org/connect2id/nimbus-jose-jwt/branches/compare/9.37.1..9.37) --- updated-dependencies: - dependency-name: com.nimbusds:nimbus-jose-jwt dependency-type: direct:development 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 12b1d78e0732..70d76d80b90a 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -99,7 +99,7 @@ 1.1.1.RELEASE 1.70 1.9.3 - 9.37 + 9.37.1 3.5.2 3.5.2 From 7ade8c772eedb09cdaa96cdc765457f21aba4d9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:34:32 +0100 Subject: [PATCH 02/12] chore(deps): bump com.github.spotbugs:spotbugs in /dhis-2 (#15632) Bumps [com.github.spotbugs:spotbugs](https://github.com/spotbugs/spotbugs) from 4.8.0 to 4.8.1. - [Release notes](https://github.com/spotbugs/spotbugs/releases) - [Changelog](https://github.com/spotbugs/spotbugs/blob/master/CHANGELOG.md) - [Commits](https://github.com/spotbugs/spotbugs/compare/4.8.0...4.8.1) --- updated-dependencies: - dependency-name: com.github.spotbugs:spotbugs 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 70d76d80b90a..ac33d71dda78 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -1901,7 +1901,7 @@ com.github.spotbugs spotbugs - 4.8.0 + 4.8.1 From dabf2c90addca726ac8b4581a7b36b23978d7066 Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Thu, 9 Nov 2023 12:04:43 +0100 Subject: [PATCH 03/12] fix: data_elements should be repeated for different stages [DHIS2-13779] (#15629) * fix: data_elements should be repeated for differente stages [DHIS2-13779] * test: test added [DHIS2-13779] * fix: e2e test [DHIS2-13779] * fix: e2e test [DHIS2-13779] --- .../src/main/resources/config.properties | 10 +-- .../analytics/AnalyticsDimensionsTest.java | 2 +- .../dimension/DimensionMapperService.java | 33 ++++++++- .../dimension/DimensionMapperServiceTest.java | 73 ++++++++++++++++--- 4 files changed, 97 insertions(+), 21 deletions(-) diff --git a/dhis-2/dhis-test-e2e/src/main/resources/config.properties b/dhis-2/dhis-test-e2e/src/main/resources/config.properties index 501690b5677c..3b92541dfef3 100644 --- a/dhis-2/dhis-test-e2e/src/main/resources/config.properties +++ b/dhis-2/dhis-test-e2e/src/main/resources/config.properties @@ -1,10 +1,10 @@ # property pointing to running DHIS2 instance. # must include /api -instance.url=http://localhost:8080/api +instance.url=http://localhost:8080/dhis/api # properties for user set up on the instance. # user must be able to import metadata. -user.default.username=system -user.default.password=System123 +user.default.username=admin +user.default.password=district # properties for super user set up on the instance. # default: user that has been set up when running tests user.super.username=tasuperadmin @@ -12,7 +12,7 @@ user.super.password=Test1212? user.admin.username=taadmin user.admin.password=Test1212? -test.cleanup=false -test.track_called_endpoints=false +test.cleanup=true +test.track_called_endpoints=true selenium.url=http://selenium:4444 diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java index 2a24c5e97e46..c4f22d7960d6 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/AnalyticsDimensionsTest.java @@ -319,7 +319,7 @@ public void shouldReturnAllDataElements() { new QueryParamsBuilder().add("filter", "dimensionType:eq:DATA_ELEMENT")) .validate() .statusCode(200) - .body("dimensions", hasSize(equalTo(distinctDataElements.size()))) + .body("dimensions", hasSize(equalTo(dataElements.size()))) .body("dimensions.uid", everyItem(in(distinctDataElements))); } } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/DimensionMapperService.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/DimensionMapperService.java index 6fb1adbafa31..e917ebc37d8a 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/DimensionMapperService.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/dimension/DimensionMapperService.java @@ -32,11 +32,14 @@ import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.PrefixedDimension; import org.springframework.stereotype.Service; @@ -44,6 +47,8 @@ @Service @RequiredArgsConstructor public class DimensionMapperService { + + private static final String PROGRAM_ATTRIBUTE = "PROGRAM_ATTRIBUTE"; private final Collection mappers; public List toDimensionResponse( @@ -55,7 +60,7 @@ public List toDimensionResponse( Collection dimensions, PrefixStrategy prefixStrategy, boolean distinct) { UnaryOperator> distinctFunction = - distinct ? this::distinctByUid : UnaryOperator.identity(); + distinct ? this::distinctBy : UnaryOperator.identity(); return distinctFunction.apply( mapToList( @@ -63,8 +68,30 @@ public List toDimensionResponse( pDimension -> toDimensionResponse(pDimension, prefixStrategy.apply(pDimension)))); } - private List distinctByUid(List dimensionResponses) { - return dimensionResponses.stream().filter(distinctBy(DimensionResponse::getUid)).toList(); + private List distinctBy(List dimensionResponses) { + + // dimensionResponses by type + Map> byType = + dimensionResponses.stream() + .collect(Collectors.groupingBy(DimensionResponse::getDimensionType)); + + // we're gonna distinct by id (fully prefixed) for all whose type is not PROGRAM_ATTRIBUTE + Stream byId = + byType.keySet().stream() + .filter(k -> !k.equals(PROGRAM_ATTRIBUTE)) + .map(byType::get) + .flatMap(List::stream) + .filter(distinctBy(DimensionResponse::getId)); + + // we're gonna distinct by Uid for all whose type is PROGRAM_ATTRIBUTE + Stream programAttributes = + byType.keySet().stream() + .filter(k -> k.equals(PROGRAM_ATTRIBUTE)) + .map(byType::get) + .flatMap(List::stream) + .filter(distinctBy(DimensionResponse::getUid)); + + return Stream.concat(byId, programAttributes).toList(); } private static Predicate distinctBy(Function keyExtractor) { diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/dimension/DimensionMapperServiceTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/dimension/DimensionMapperServiceTest.java index 5ec514e47256..f4f66196fbf6 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/dimension/DimensionMapperServiceTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/dimension/DimensionMapperServiceTest.java @@ -35,10 +35,15 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Stream; +import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.hisp.dhis.common.BaseIdentifiableObject; -import org.hisp.dhis.common.DimensionType; import org.hisp.dhis.common.PrefixedDimension; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramStage; +import org.hisp.dhis.program.ProgramStageDataElement; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.webapi.dimension.mappers.BaseDimensionalItemObjectMapper; import org.junit.jupiter.api.BeforeEach; @@ -56,19 +61,23 @@ void setUp() { } @Test - void testReturnedDimensionsHaveNoDuplicates() { + void testReturnedDimensionsHaveNoDuplicatesWhenProgramAttributes() { when(baseDimensionMapper.map(any(), any())) .thenAnswer( invocation -> { PrefixedDimension prefixedDimension = invocation.getArgument(0); - return DimensionResponse.builder().uid(prefixedDimension.getItem().getUid()).build(); + return DimensionResponse.builder() + .dimensionType(prefixedDimension.getDimensionType()) + .id(prefixedDimension.getPrefix() + "." + prefixedDimension.getItem().getUid()) + .uid(prefixedDimension.getItem().getUid()) + .build(); }); when(baseDimensionMapper.supports(any())).thenReturn(true); List dimensionResponse = dimensionMapperService.toDimensionResponse( - mockDimensions(), EnrollmentAnalyticsPrefixStrategy.INSTANCE, true); + mockDimensions(DimType.PROGRAM_ATTRIBUTE), TeiAnalyticsPrefixStrategy.INSTANCE, true); assertEquals(4, dimensionResponse.size()); @@ -78,21 +87,61 @@ void testReturnedDimensionsHaveNoDuplicates() { assertEquals(List.of("uid1", "uid2", "uid3", "repeated"), dimensionResponseUids); } - private Collection mockDimensions() { - return Stream.of("uid1", "uid2", "uid3", "repeated", "repeated") - .map(this::asPrefixedDimension) + @Test + void testReturnedDimensionsHaveDuplicatesWhenDataElements() { + + when(baseDimensionMapper.map(any(), any())) + .thenAnswer( + invocation -> { + PrefixedDimension prefixedDimension = invocation.getArgument(0); + return DimensionResponse.builder() + .dimensionType(prefixedDimension.getDimensionType()) + .id(prefixedDimension.getPrefix() + "." + prefixedDimension.getItem().getUid()) + .uid(prefixedDimension.getItem().getUid()) + .build(); + }); + when(baseDimensionMapper.supports(any())).thenReturn(true); + + List dimensionResponse = + dimensionMapperService.toDimensionResponse( + mockDimensions(DimType.DATA_ELEMENT), TeiAnalyticsPrefixStrategy.INSTANCE, true); + + assertEquals(5, dimensionResponse.size()); + + Collection dimensionResponseIds = + dimensionResponse.stream().map(DimensionResponse::getId).toList(); + + assertEquals( + List.of("p1.s1.uid1", "p1.s1.uid2", "p1.s1.uid3", "p1.s1.repeated", "p1.s2.repeated"), + dimensionResponseIds); + } + + @Getter + @RequiredArgsConstructor + private enum DimType { + PROGRAM_ATTRIBUTE(TrackedEntityAttribute::new), + DATA_ELEMENT(ProgramStageDataElement::new); + private final Supplier instanceSupplier; + } + + private Collection mockDimensions(DimType dimType) { + return Stream.of("p1.s1.uid1", "p1.s1.uid2", "p1.s1.uid3", "p1.s1.repeated", "p1.s2.repeated") + .map(uid -> asItem(uid, dimType)) .toList(); } - private PrefixedDimension asPrefixedDimension(String dimension) { + private PrefixedDimension asItem(String uid, DimType dimType) { + String[] split = uid.split("\\."); return PrefixedDimension.builder() - .item(buildItem(dimension)) - .dimensionType(DimensionType.PROGRAM_ATTRIBUTE.name()) + .program((Program) buildItem(split[0], Program::new)) + .programStage((ProgramStage) buildItem(split[1], ProgramStage::new)) + .item(buildItem(split[2], dimType.getInstanceSupplier())) + .dimensionType(dimType.name()) .build(); } - private BaseIdentifiableObject buildItem(String uid) { - TrackedEntityAttribute item = new TrackedEntityAttribute(); + private BaseIdentifiableObject buildItem(String uid, Supplier supplier) { + BaseIdentifiableObject item = supplier.get(); item.setUid(uid); return item; } From ae674bbb125180400b9caf0a74ab96db4463f82e Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Fri, 10 Nov 2023 03:01:06 +0100 Subject: [PATCH 04/12] fix: run continuous jobs immediately [DHIS2-15276] (#15630) --- .../DefaultJobSchedulerService.java | 6 +++++ .../org/hisp/dhis/scheduling/JobRunner.java | 20 ++++++++++++++++ .../hisp/dhis/scheduling/JobScheduler.java | 23 ++++++++++++------- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/DefaultJobSchedulerService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/DefaultJobSchedulerService.java index 0fa7649de58d..6a66f2e6f657 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/DefaultJobSchedulerService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/DefaultJobSchedulerService.java @@ -84,6 +84,12 @@ public void executeNow(@Nonnull String jobId) throws NotFoundException, Conflict if (job == null) throw new NotFoundException(JobConfiguration.class, jobId); // run "execute now" request directly when scheduling is not active (tests) jobRunner.runDueJob(job); + } else { + JobConfiguration job = jobConfigurationStore.getByUid(jobId); + if (job == null) throw new NotFoundException(JobConfiguration.class, jobId); + if (job.getJobType().isUsingContinuousExecution()) { + jobRunner.runIfDue(job); + } } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobRunner.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobRunner.java index 5be683b59163..d137bf265d9f 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobRunner.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobRunner.java @@ -40,7 +40,27 @@ */ public interface JobRunner { + /** + * During testing the scheduler might not be active in which case this is false. Otherwise, this + * should always be true in a production environment. + * + * @return true, if the scheduler is running a scheduling loop cycle, otherwise false + */ boolean isScheduling(); + /** + * Runs a job if it should now run according to its {@link SchedulingType} and related information + * like the CRON expression or the delay time. + * + * @param config the job to check and potentially run + */ + void runIfDue(JobConfiguration config); + + /** + * Manually runs a job. OBS! This bypasses any actual checking if the job is due to run. When this + * is called the job will run. + * + * @param config The job to run. + */ void runDueJob(JobConfiguration config); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobScheduler.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobScheduler.java index 5a81d5c5646d..c3583f06810f 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobScheduler.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/scheduling/JobScheduler.java @@ -137,20 +137,27 @@ private void createHousekeepingJob() { } } + @Override + public void runIfDue(JobConfiguration job) { + runIfDue(Instant.now().truncatedTo(ChronoUnit.SECONDS), job.getJobType(), List.of(job)); + } + private void runIfDue(Instant now, JobType type, List jobs) { if (!type.isUsingContinuousExecution()) { runIfDue(now, jobs.get(0)); return; } - Queue jobIds = - continuousJobsByType.computeIfAbsent(type, key -> new ConcurrentLinkedQueue<>()); - // add a worker either if no worker is on it (empty new queue) or if there are many jobs - boolean spawnWorker = jobIds.isEmpty(); + Queue jobIds = continuousJobsByType.get(type); + boolean spawnWorker = false; + if (jobIds == null) { + Queue localQueue = new ConcurrentLinkedQueue<>(); + Queue sharedQueue = continuousJobsByType.putIfAbsent(type, localQueue); + spawnWorker = sharedQueue == null; // no previous queue => this thread put the queue + jobIds = continuousJobsByType.get(type); + } // add those IDs to the queue that are not yet in it - jobs.stream() - .map(JobConfiguration::getUid) - .filter(jobId -> !jobIds.contains(jobId)) - .forEach(jobIds::add); + jobs.stream().map(JobConfiguration::getUid).forEach(jobIds::add); + if (spawnWorker) { // we want to prevent starting more than one worker per job type // but if this does happen it is no issue as both will be pulling From e418388f6404312ede1b08cd9d179ebef4c2fabd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:20:16 +0100 Subject: [PATCH 05/12] chore(deps): bump org.apache.maven.plugins:maven-failsafe-plugin (#15637) Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.2.1 to 3.2.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.1...surefire-3.2.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin 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 ac33d71dda78..cc19f9ef6b4e 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -228,7 +228,7 @@ 3.2.2 3.11.0 3.3.1 - 3.2.1 + 3.2.2 3.6.2 3.1.0 3.4.1 From dae330825b756f5c47fbfe869cfcd52722f1fee4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:20:34 +0100 Subject: [PATCH 06/12] chore(deps): bump com.github.spotbugs:spotbugs-maven-plugin in /dhis-2 (#15638) Bumps [com.github.spotbugs:spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 4.7.3.6 to 4.8.1.0. - [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases) - [Commits](https://github.com/spotbugs/spotbugs-maven-plugin/compare/spotbugs-maven-plugin-4.7.3.6...spotbugs-maven-plugin-4.8.1.0) --- updated-dependencies: - dependency-name: com.github.spotbugs:spotbugs-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... 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 cc19f9ef6b4e..098d2f1aa577 100644 --- a/dhis-2/pom.xml +++ b/dhis-2/pom.xml @@ -236,7 +236,7 @@ 2.4.0 2.16.1 8.4.2 - 4.7.3.6 + 4.8.1.0 2.40.0 0.8.11 1.2.0 From 40cf7ad7984d0800722253f9dec7b4975baffd4d Mon Sep 17 00:00:00 2001 From: David Mackessy <131455290+david-mackessy@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:04:42 +0000 Subject: [PATCH 07/12] fix: Remove unnecessary calls to the DB during DataValueSet import [DHIS2-16138] (#15639) * fix: Remove calls to DB during DataValueSet import [DHIS2-16138] * fix: Update tests to reflect the removal of DB interaction [DHIS2-16138] --- .../dxf2/datavalueset/DataValueSetImportValidator.java | 4 +--- .../datavalueset/DataValueSetImportValidatorTest.java | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java index 2e71592e11fb..cccdc7053c59 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidator.java @@ -351,9 +351,7 @@ private void validateDataValueOrgUnitInUserHierarchy( .getOrgUnitInHierarchyMap() .get( valueContext.getOrgUnit().getUid(), - () -> - organisationUnitService.isDescendant( - valueContext.getOrgUnit(), context.getCurrentOrgUnits())); + () -> valueContext.getOrgUnit().isDescendant(context.getCurrentOrgUnits())); if (!inUserHierarchy) { context.addConflict( diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java index 4db3dd2d5ead..a4c87d0ef9ad 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetImportValidatorTest.java @@ -110,11 +110,6 @@ void setUp() { approvalService = mock(DataApprovalService.class); dataValueService = mock(DataValueService.class); organisationUnitService = mock(OrganisationUnitService.class); - when(organisationUnitService.isDescendant(any(OrganisationUnit.class), any(Set.class))) - .thenReturn(true); - when(organisationUnitService.isDescendant( - any(OrganisationUnit.class), any(OrganisationUnit.class))) - .thenReturn(true); i18n = mock(I18n.class); validator = @@ -899,6 +894,9 @@ private DataValueContextBuilder createDataValueContext(DataValue dataValue) { if (ouId != null) { OrganisationUnit ou = new OrganisationUnit(); ou.setUid(ouId); + // we set the path here just for the tests. This is usually done by the persistence layer + // but there is no interaction with that in these tests. + ou.setPath(ou.getPath()); builder.orgUnit(ou); } if (coId != null) { From 5ad257bb67ff0562534dd13f8ab016c0524af9b1 Mon Sep 17 00:00:00 2001 From: lucaCambi77 Date: Fri, 10 Nov 2023 14:39:43 +0100 Subject: [PATCH 08/12] fix: tracker/events not returning event relationships [DHIS2-16117] (#15626) * fix: include relationships in event request mapper * fix: typo * fix: review * fix: formatting * fix: integration tests * fix: more integration tests --- .../export/event/EventOperationParams.java | 2 + .../event/EventOperationParamsMapper.java | 2 +- .../event/EventOperationParamsMapperTest.java | 29 ++++++++++-- .../org/hisp/dhis/tracker/TrackerApiTest.java | 43 ++++++----------- .../tracker/imports/TrackerExportTests.java | 30 +++++++++++- .../resources/setup/tracker_metadata.json | 35 ++++++++++++++ .../OrderAndPaginationExporterTest.java | 5 +- .../export/event/AclEventExporterTest.java | 46 +++++++++---------- .../export/event/EventExporterTest.java | 17 +++---- .../event/EventRequestParamsMapper.java | 5 +- .../event/EventRequestParamsMapperTest.java | 30 ++++++++++++ 11 files changed, 173 insertions(+), 71 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java index b2d7afa8549c..2228d926a56c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParams.java @@ -147,6 +147,8 @@ public class EventOperationParams { private Set enrollments; + private EventParams eventParams; + public static class EventOperationParamsBuilder { private List order = new ArrayList<>(); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java index 5b6f0313c67d..58c41bfcd0c5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java @@ -146,7 +146,7 @@ public EventQueryParams map(EventOperationParams operationParams) .setEvents(operationParams.getEvents()) .setEnrollments(operationParams.getEnrollments()) .setIncludeDeleted(operationParams.isIncludeDeleted()) - .setIncludeRelationships(operationParams.isIncludeRelationships()); + .setIncludeRelationships(operationParams.getEventParams().isIncludeRelationships()); } private Program validateProgram(String programUid) throws BadRequestException { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java index 4941cb5e099a..d216d01f1299 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java @@ -40,6 +40,7 @@ import static org.hisp.dhis.utils.Assertions.assertContainsOnly; import static org.hisp.dhis.utils.Assertions.assertStartsWith; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -153,7 +154,7 @@ public void setUp() { // By default set to ACCESSIBLE for tests that don't set an orgUnit. The orgUnitMode needs to be // set because its validation is in the EventRequestParamsMapper. - eventBuilder = eventBuilder.orgUnitMode(ACCESSIBLE); + eventBuilder = eventBuilder.orgUnitMode(ACCESSIBLE).eventParams(EventParams.FALSE); userMap.put("admin", createUserWithAuthority(F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS)); userMap.put("superuser", createUserWithAuthority(Authorities.ALL)); @@ -499,7 +500,7 @@ void shouldMapOrgUnitWhenProgramProvidedAndRequestedOrgUnitInSearchScope( .thenReturn(true); EventOperationParams operationParams = - EventOperationParams.builder() + eventBuilder .programUid(program.getUid()) .orgUnitUid(searchScopeChildOrgUnit.getUid()) .orgUnitMode(orgUnitMode) @@ -532,7 +533,7 @@ void shouldMapOrgUnitWhenModeAllProgramProvidedAndRequestedOrgUnitInSearchScope( .thenReturn(searchScopeChildOrgUnit); EventOperationParams operationParams = - EventOperationParams.builder() + eventBuilder .programUid(program.getUid()) .orgUnitUid(searchScopeChildOrgUnit.getUid()) .orgUnitMode(ALL) @@ -574,6 +575,28 @@ void shouldMapOrgUnitAndModeWhenModeAllAndUserIsAuthorized(String userName) assertEquals(ALL, params.getOrgUnitMode()); } + @Test + void shouldIncludeRelationshipsWhenFieldPathIncludeRelationships() + throws BadRequestException, ForbiddenException { + when(currentUserService.getCurrentUser()).thenReturn(userMap.get("admin")); + + EventOperationParams operationParams = + eventBuilder.orgUnitMode(ALL).eventParams(EventParams.TRUE).build(); + EventQueryParams params = mapper.map(operationParams); + assertTrue(params.isIncludeRelationships()); + } + + @Test + void shouldNotIncludeRelationshipsWhenFieldPathDoNotIncludeRelationships() + throws BadRequestException, ForbiddenException { + when(currentUserService.getCurrentUser()).thenReturn(userMap.get("admin")); + + EventOperationParams operationParams = + eventBuilder.orgUnitMode(ALL).eventParams(EventParams.FALSE).build(); + EventQueryParams params = mapper.map(operationParams); + assertFalse(params.isIncludeRelationships()); + } + private User createUserWithAuthority(Authorities authority) { User user = new User(); UserRole userRole = new UserRole(); diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/TrackerApiTest.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/TrackerApiTest.java index 3ca07fa7075b..c29794b34bb3 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/TrackerApiTest.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/TrackerApiTest.java @@ -91,20 +91,6 @@ protected String importTei() throws Exception { .get(0); } - protected String importTei(String orgUnit) throws Exception { - JsonObject teiBody = - new FileReaderUtils() - .read(new File("src/test/resources/tracker/importer/teis/tei.json")) - .replacePropertyValuesRecursivelyWith("orgUnit", orgUnit) - .get(JsonObject.class); - - return trackerImportExportActions - .postAndGetJobReport(teiBody) - .validateSuccessfulImport() - .extractImportedTeis() - .get(0); - } - protected List importEvents() throws Exception { JsonObject object = new FileReaderUtils() @@ -130,20 +116,6 @@ protected TrackerApiResponse importTeiWithEnrollment(String programId) throws Ex .validateSuccessfulImport(); } - protected TrackerApiResponse importTeiWithEnrollment(String ouId, String programId) - throws Exception { - JsonObject teiWithEnrollment = - new FileReaderUtils() - .read(new File("src/test/resources/tracker/importer/teis/teiWithEnrollments.json")) - .replacePropertyValuesRecursivelyWith("program", programId) - .replacePropertyValuesRecursivelyWith("orgUnit", ouId) - .get(JsonObject.class); - - return trackerImportExportActions - .postAndGetJobReport(teiWithEnrollment) - .validateSuccessfulImport(); - } - /* * Imports one new TEI with enrollment and event */ @@ -196,17 +168,28 @@ protected TrackerApiResponse importRelationshipBetweenTeis(String teiA, String t return trackerImportExportActions.postAndGetJobReport(payload).validateSuccessfulImport(); } - protected TrackerApiResponse importRelationshipEnrollmentToTei(String enrollment, String teiB) { + protected TrackerApiResponse importRelationshipEnrollmentToTei(String enrollment, String tei) { JsonObject payload = new RelationshipDataBuilder() .setFromEntity("enrollment", enrollment) - .setToTrackedEntity(teiB) + .setToTrackedEntity(tei) .setRelationshipType("fdc6uOvgoji") .array(); return trackerImportExportActions.postAndGetJobReport(payload).validateSuccessfulImport(); } + protected TrackerApiResponse importRelationshipEventToTei(String event, String tei) { + JsonObject payload = + new RelationshipDataBuilder() + .setFromEntity("event", event) + .setToTrackedEntity(tei) + .setRelationshipType("gdc6uOvgoji") + .array(); + + return trackerImportExportActions.postAndGetJobReport(payload).validateSuccessfulImport(); + } + @AfterEach public void tearDown() { loginActions.loginAsSuperUser(); diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/imports/TrackerExportTests.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/imports/TrackerExportTests.java index bd6b7ee403d4..4a1badd37aaa 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/imports/TrackerExportTests.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/tracker/imports/TrackerExportTests.java @@ -33,6 +33,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.emptyIterable; +import static org.hamcrest.Matchers.emptyOrNullString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.everyItem; @@ -88,6 +89,8 @@ public class TrackerExportTests extends TrackerApiTest { private static String enrollmentToTeiRelationship; + private static String eventToTeiRelationship; + private static JsonObject teiWithEnrollmentAndEventsTemplate; @BeforeAll @@ -103,12 +106,15 @@ public void beforeAll() throws Exception { enrollment = response.extractImportedEnrollments().get(0); + event = response.extractImportedEvents().get(0); + teiToTeiRelationship = importRelationshipBetweenTeis(teiA, teiB).extractImportedRelationships().get(0); enrollmentToTeiRelationship = importRelationshipEnrollmentToTei(enrollment, teiB).extractImportedRelationships().get(0); - event = response.extractImportedEvents().get(0); + eventToTeiRelationship = + importRelationshipEventToTei(event, teiB).extractImportedRelationships().get(0); teiWithEnrollmentAndEventsTemplate = new FileReaderUtils() @@ -425,6 +431,28 @@ public void shouldReturnRelationshipsByTei() { .body("to.trackedEntity.trackedEntity", equalTo(teiB)); } + @Test + public void shouldReturnRelationshipsWhenEventHasRelationshipsAndFieldsIncludeRelationships() { + trackerImportExportActions + .get("events?event=" + event + "&fields=relationships") + .validate() + .statusCode(200) + .body("instances", hasSize(greaterThanOrEqualTo(1))) + .rootPath("instances[0].relationships[0]") + .body("relationship", equalTo(eventToTeiRelationship)) + .body("from.event.event", equalTo(event)) + .body("to.trackedEntity.trackedEntity", equalTo(teiB)); + } + + @Test + public void shouldNotReturnRelationshipsWhenEventHasRelationshipsAndFieldsExcludeRelationships() { + trackerImportExportActions + .get("events?event=" + event) + .validate() + .statusCode(200) + .body("instances[0].relationships", emptyOrNullString()); + } + @Test public void shouldReturnFilteredEvent() { trackerImportExportActions diff --git a/dhis-2/dhis-test-e2e/src/test/resources/setup/tracker_metadata.json b/dhis-2/dhis-test-e2e/src/test/resources/setup/tracker_metadata.json index 610506d7199e..d42a466f6b17 100644 --- a/dhis-2/dhis-test-e2e/src/test/resources/setup/tracker_metadata.json +++ b/dhis-2/dhis-test-e2e/src/test/resources/setup/tracker_metadata.json @@ -3178,6 +3178,41 @@ } } } + }, + { + "lastUpdated": "2020-11-20T09:06:23.348", + "id": "gdc6uOvgoji", + "created": "2020-11-20T09:06:23.348", + "name": "Person to Event", + "code": "Person to Event", + "bidirectional": false, + "displayName": "Person to Event", + "fromToName": "Person to Event", + "displayFromToName": "Person to Event", + "favorite": false, + "toConstraint": { + "relationshipEntity": "TRACKED_ENTITY_INSTANCE", + "trackedEntityType": { + "id": "Q9GufDoplCL", + "code": "TA_PERSON_TET" + } + }, + "fromConstraint": { + "relationshipEntity": "PROGRAM_STAGE_INSTANCE", + "programStage": { + "id": "PaOOjwLVW23" + } + }, + "sharing": { + "public": "rw------", + "external": false, + "userGroups": { + "OPVIvvXzNTw": { + "id": "OPVIvvXzNTw", + "access": "rwrw----" + } + } + } } ] } \ No newline at end of file diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java index 6bbc9c6b9793..28c706005044 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/OrderAndPaginationExporterTest.java @@ -68,6 +68,7 @@ import org.hisp.dhis.tracker.export.enrollment.EnrollmentService; import org.hisp.dhis.tracker.export.event.EventOperationParams; import org.hisp.dhis.tracker.export.event.EventOperationParams.EventOperationParamsBuilder; +import org.hisp.dhis.tracker.export.event.EventParams; import org.hisp.dhis.tracker.export.event.EventService; import org.hisp.dhis.tracker.export.relationship.RelationshipOperationParams; import org.hisp.dhis.tracker.export.relationship.RelationshipService; @@ -125,7 +126,7 @@ void setUp() { // expect to be run by admin injectAdminUser(); - eventParamsBuilder = EventOperationParams.builder(); + eventParamsBuilder = EventOperationParams.builder().eventParams(EventParams.FALSE); eventParamsBuilder.orgUnitMode(SELECTED); } @@ -756,7 +757,7 @@ void shouldOrderEventsByEnrollmentProgramUIDAsc() throws ForbiddenException, Bad .toList(); EventOperationParams params = - EventOperationParams.builder() + eventParamsBuilder .orgUnitMode(ACCESSIBLE) .events(Set.of("pTzf9KYMk72", "QRYjLTiJTrA")) .orderBy("enrollment.program.uid", SortDirection.ASC) diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java index e9f6311b80e3..c2bd259a0c20 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/AclEventExporterTest.java @@ -78,6 +78,8 @@ class AclEventExporterTest extends TrackerTest { private Program program; + private EventOperationParams.EventOperationParamsBuilder operationParamsBuilder; + @Override protected void initTest() throws IOException { setUpMetadata("tracker/simple_metadata.json"); @@ -102,6 +104,7 @@ void setUp() { // needed as some tests are run using another user (injectSecurityContext) while most tests // expect to be run by admin injectAdminUser(); + operationParamsBuilder = EventOperationParams.builder().eventParams(EventParams.FALSE); } @Test @@ -109,7 +112,7 @@ void shouldReturnEventsWhenProgramClosedOuModeDescendantsAndOrgUnitInCaptureScop throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .programUid("pcxIanBWlSY") .orgUnitUid(orgUnit.getUid()) .orgUnitMode(DESCENDANTS) @@ -135,10 +138,7 @@ void shouldReturnEventsWhenNoProgramSpecifiedOuModeDescendantsAndOrgUnitInSearch throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() - .orgUnitUid(orgUnit.getUid()) - .orgUnitMode(DESCENDANTS) - .build(); + operationParamsBuilder.orgUnitUid(orgUnit.getUid()).orgUnitMode(DESCENDANTS).build(); List events = eventService.getEvents(params); @@ -162,7 +162,7 @@ void shouldReturnEventsWhenProgramClosedOuModeChildrenAndOrgUnitInCaptureScope() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .programUid("pcxIanBWlSY") .orgUnitUid(orgUnit.getUid()) .orgUnitMode(CHILDREN) @@ -188,7 +188,7 @@ void shouldReturnEventsWhenNoProgramSpecifiedOuModeChildrenAndOrgUnitInSearchSco throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder().orgUnitUid(orgUnit.getUid()).orgUnitMode(CHILDREN).build(); + operationParamsBuilder.orgUnitUid(orgUnit.getUid()).orgUnitMode(CHILDREN).build(); List events = eventService.getEvents(params); @@ -204,7 +204,7 @@ void shouldReturnEventsWhenNoProgramSpecifiedOuModeChildrenAndOrgUnitInSearchSco void shouldFailWhenProgramIsOpenAndOrgUnitNotInSearchScope() { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .programUid(program.getUid()) .orgUnitUid("DiszpKrYNg8") .orgUnitMode(DESCENDANTS) @@ -220,7 +220,7 @@ void shouldFailWhenProgramIsOpenAndOrgUnitNotInSearchScope() { void shouldFailWhenProgramIsClosedAndOrgUnitNotInSearchScope() { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .programUid("pcxIanBWlSY") .orgUnitUid("DiszpKrYNg8") .orgUnitMode(DESCENDANTS) @@ -237,7 +237,7 @@ void shouldReturnEventsWhenProgramClosedOuModeSelectedAndOrgUnitInCaptureScope() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .programUid("pcxIanBWlSY") .orgUnitUid("uoNW0E3xXUy") .orgUnitMode(SELECTED) @@ -263,7 +263,7 @@ void shouldReturnEventsWhenNoProgramSpecifiedOuModeSelectedAndOrgUnitInSearchSco throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("nIidJVYpQQK")); EventOperationParams params = - EventOperationParams.builder().orgUnitUid("DiszpKrYNg8").orgUnitMode(SELECTED).build(); + operationParamsBuilder.orgUnitUid("DiszpKrYNg8").orgUnitMode(SELECTED).build(); List events = eventService.getEvents(params); @@ -281,7 +281,7 @@ void shouldReturnEventsWhenNoProgramSpecifiedOuModeSelectedAndOrgUnitInCaptureSc throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder().orgUnitUid("RojfDTBhoGC").orgUnitMode(SELECTED).build(); + operationParamsBuilder.orgUnitUid("RojfDTBhoGC").orgUnitMode(SELECTED).build(); List events = eventService.getEvents(params); @@ -299,7 +299,7 @@ void shouldReturnNoEventsWhenProgramOpenOuModeSelectedAndNoProgramEvents() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .programUid("shPjYNifvMK") .orgUnitUid(orgUnit.getUid()) .orgUnitMode(SELECTED) @@ -315,7 +315,7 @@ void shouldReturnEventsWhenProgramClosedOuModeAccessible() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder().programUid("pcxIanBWlSY").orgUnitMode(ACCESSIBLE).build(); + operationParamsBuilder.programUid("pcxIanBWlSY").orgUnitMode(ACCESSIBLE).build(); List events = eventService.getEvents(params); @@ -336,7 +336,7 @@ void shouldReturnEventsWhenProgramOpenOuModeAccessible() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder().programUid(program.getUid()).orgUnitMode(ACCESSIBLE).build(); + operationParamsBuilder.programUid(program.getUid()).orgUnitMode(ACCESSIBLE).build(); List events = eventService.getEvents(params); @@ -357,7 +357,7 @@ void shouldReturnEventsWhenProgramClosedOuModeCapture() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder().programUid("pcxIanBWlSY").orgUnitMode(CAPTURE).build(); + operationParamsBuilder.programUid("pcxIanBWlSY").orgUnitMode(CAPTURE).build(); List events = eventService.getEvents(params); @@ -378,7 +378,7 @@ void shouldReturnAccessibleOrgUnitEventsWhenNoOrgUnitSpecified() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("FIgVWzUCkpw")); EventOperationParams params = - EventOperationParams.builder().programUid("pcxIanBWlSY").orgUnitMode(ACCESSIBLE).build(); + operationParamsBuilder.programUid("pcxIanBWlSY").orgUnitMode(ACCESSIBLE).build(); List events = eventService.getEvents(params); @@ -403,7 +403,7 @@ void shouldReturnEventsNonSuperUserIsOwnerOrHasUserAccess() injectSecurityContext(userService.getUser("o1HMTIzBGo7")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .orgUnitUid("DiszpKrYNg8") .orgUnitMode(SELECTED) .events(Set.of("lumVtWwwy0O", "cadc5eGj0j7")) @@ -437,7 +437,7 @@ void shouldReturnNoEventsGivenUserHasNoAccess() throws ForbiddenException, BadRe injectSecurityContext(userService.getUser("CYVgFNKCaUS")); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .orgUnitUid("DiszpKrYNg8") .orgUnitMode(SELECTED) .events(Set.of("lumVtWwwy0O", "cadc5eGj0j7")) @@ -453,7 +453,7 @@ void shouldReturnAllEventsWhenOrgUnitModeAllAndNoOrgUnitProvided() throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("lPaILkLkgOM")); - EventOperationParams params = EventOperationParams.builder().orgUnitMode(ALL).build(); + EventOperationParams params = operationParamsBuilder.orgUnitMode(ALL).build(); List events = eventService.getEvents(params); @@ -476,7 +476,7 @@ void shouldReturnAllEventsWhenOrgUnitModeAllAndNoOrgUnitProvidedAndUserNull() throws ForbiddenException, BadRequestException { injectSecurityContext(null); - EventOperationParams params = EventOperationParams.builder().orgUnitMode(ALL).build(); + EventOperationParams params = operationParamsBuilder.orgUnitMode(ALL).build(); List events = eventService.getEvents(params); @@ -500,7 +500,7 @@ void shouldIgnoreRequestedOrgUnitAndReturnAllEventsWhenOrgUnitModeAllAndOrgUnitP injectSecurityContext(userService.getUser("lPaILkLkgOM")); EventOperationParams params = - EventOperationParams.builder().orgUnitUid("uoNW0E3xXUy").orgUnitMode(ALL).build(); + operationParamsBuilder.orgUnitUid("uoNW0E3xXUy").orgUnitMode(ALL).build(); List events = eventService.getEvents(params); @@ -524,7 +524,7 @@ void shouldIgnoreRequestedOrgUnitAndReturnAllEventsWhenOrgUnitModeAllAndOrgUnitP throws ForbiddenException, BadRequestException { injectSecurityContext(userService.getUser("nIidJVYpQQK")); - EventOperationParams params = EventOperationParams.builder().orgUnitMode(ACCESSIBLE).build(); + EventOperationParams params = operationParamsBuilder.orgUnitMode(ACCESSIBLE).build(); List events = eventService.getEvents(params); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java index d8a74b448dd2..33ebe1e366ef 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java @@ -130,7 +130,7 @@ void setUp() { // expect to be run by admin injectAdminUser(); - operationParamsBuilder = EventOperationParams.builder(); + operationParamsBuilder = EventOperationParams.builder().eventParams(EventParams.FALSE); operationParamsBuilder.orgUnitUid(orgUnit.getUid()).orgUnitMode(SELECTED); } @@ -152,7 +152,7 @@ void shouldExportEventAndMapAssignedUserWhenAssignedUserIsNotNull() @Test void shouldReturnEventsWithRelationships() throws ForbiddenException, BadRequestException { EventOperationParams params = - operationParamsBuilder.events(Set.of("pTzf9KYMk72")).includeRelationships(true).build(); + operationParamsBuilder.events(Set.of("pTzf9KYMk72")).eventParams(EventParams.TRUE).build(); List events = eventService.getEvents(params); @@ -262,10 +262,7 @@ void testExportEventsWithLastUpdateDates() throws ForbiddenException, BadRequest void testExportEventsWithDatesIncludingTimeStamp() throws ForbiddenException, BadRequestException { EventOperationParams params = - EventOperationParams.builder() - .orgUnitMode(ACCESSIBLE) - .events(Set.of("pTzf9KYMk72")) - .build(); + operationParamsBuilder.orgUnitMode(ACCESSIBLE).events(Set.of("pTzf9KYMk72")).build(); List events = eventService.getEvents(params); @@ -414,7 +411,7 @@ void testExportEventsWhenFilteringByDataElementsWithCategoryOptionSuperUser() @Test void shouldReturnEventsGivenCategoryOptionCombo() throws ForbiddenException, BadRequestException { EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .orgUnitUid("DiszpKrYNg8") .orgUnitMode(SELECTED) .attributeCategoryCombo("O4VaNks6tta") @@ -450,7 +447,7 @@ void shouldFailIfCategoryOptionComboOfGivenEventDoesNotHaveAValueForGivenIdSchem IdSchemes idSchemes = new IdSchemes(); idSchemes.setCategoryOptionComboIdScheme("ATTRIBUTE:GOLswS44mh8"); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .orgUnitUid("DiszpKrYNg8") .orgUnitMode(SELECTED) .idSchemes(idSchemes) @@ -472,7 +469,7 @@ void shouldReturnEventsGivenIdSchemeCode() throws ForbiddenException, BadRequest idSchemes.setCategoryOptionComboIdScheme("code"); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .orgUnitUid("DiszpKrYNg8") .orgUnitMode(SELECTED) .idSchemes(idSchemes) @@ -523,7 +520,7 @@ void shouldReturnEventsGivenIdSchemeAttribute() throws ForbiddenException, BadRe idSchemes.setOrgUnitIdScheme("ATTRIBUTE:j45AR9cBQKc"); idSchemes.setCategoryOptionComboIdScheme("ATTRIBUTE:j45AR9cBQKc"); EventOperationParams params = - EventOperationParams.builder() + operationParamsBuilder .orgUnitUid("DiszpKrYNg8") .orgUnitMode(SELECTED) .idSchemes(idSchemes) diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapper.java index 4a6fa703a003..b15543bc46f2 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapper.java @@ -59,6 +59,8 @@ class EventRequestParamsMapper { private static final Set ORDERABLE_FIELD_NAMES = EventMapper.ORDERABLE_FIELDS.keySet(); + private final EventFieldsParamMapper eventsMapper; + public EventOperationParams map(RequestParams requestParams) throws BadRequestException { OrganisationUnitSelectionMode orgUnitMode = validateDeprecatedParameter( @@ -144,7 +146,8 @@ public EventOperationParams map(RequestParams requestParams) throws BadRequestEx .attributeFilters(attributeFilters) .events(UID.toValueSet(eventUids)) .enrollments(UID.toValueSet(requestParams.getEnrollments())) - .includeDeleted(requestParams.isIncludeDeleted()); + .includeDeleted(requestParams.isIncludeDeleted()) + .eventParams(eventsMapper.map(requestParams.getFields())); mapOrderParam(builder, requestParams.getOrder()); diff --git a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapperTest.java b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapperTest.java index 7099161a8708..5de64f36a3b0 100644 --- a/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapperTest.java +++ b/dhis-2/dhis-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventRequestParamsMapperTest.java @@ -34,6 +34,7 @@ import static org.hisp.dhis.utils.Assertions.assertContainsOnly; import static org.hisp.dhis.utils.Assertions.assertIsEmpty; import static org.hisp.dhis.utils.Assertions.assertStartsWith; +import static org.hisp.dhis.webapi.controller.tracker.export.FieldsParamMapper.FIELD_RELATIONSHIPS; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -55,6 +56,8 @@ import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.feedback.BadRequestException; +import org.hisp.dhis.fieldfiltering.FieldFilterParser; +import org.hisp.dhis.fieldfiltering.FieldPath; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.program.Program; @@ -68,6 +71,7 @@ import org.hisp.dhis.trackedentity.TrackedEntityService; import org.hisp.dhis.tracker.export.Order; import org.hisp.dhis.tracker.export.event.EventOperationParams; +import org.hisp.dhis.tracker.export.event.EventParams; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.webapi.controller.event.mapper.SortDirection; @@ -113,6 +117,8 @@ class EventRequestParamsMapperTest { @Mock private DataElementService dataElementService; + @Mock EventFieldsParamMapper eventFieldsParamMapper; + @InjectMocks private EventRequestParamsMapper mapper; private Program program; @@ -589,4 +595,28 @@ void shouldFailWhenNoOrgUnitSuppliedAndOrgUnitModeNeedsOrgUnit( "At least one org unit is required for orgUnitMode: " + orgUnitMode, exception.getMessage()); } + + @Test + void shouldMapEventParamsTrueWhenFieldPathIncludeRelationships() throws BadRequestException { + RequestParams requestParams = new RequestParams(); + List fieldPaths = FieldFilterParser.parse(FIELD_RELATIONSHIPS); + + requestParams.setFields(fieldPaths); + when(eventFieldsParamMapper.map(fieldPaths)).thenReturn(EventParams.TRUE); + + EventOperationParams eventOperationParams = mapper.map(requestParams); + assertEquals(EventParams.TRUE, eventOperationParams.getEventParams()); + } + + @Test + void shouldMapEventParamsFalseWhenFieldPathIncludeRelationships() throws BadRequestException { + RequestParams requestParams = new RequestParams(); + List fieldPaths = FieldFilterParser.parse(FIELD_RELATIONSHIPS); + + requestParams.setFields(fieldPaths); + when(eventFieldsParamMapper.map(fieldPaths)).thenReturn(EventParams.FALSE); + + EventOperationParams eventOperationParams = mapper.map(requestParams); + assertEquals(EventParams.FALSE, eventOperationParams.getEventParams()); + } } From 37ba2183b831e558d6fef1afbe0239f72121e886 Mon Sep 17 00:00:00 2001 From: Enrico Colasante Date: Fri, 10 Nov 2023 16:10:14 +0100 Subject: [PATCH 09/12] chore: Rename duedate to scheduleddate in DB [TECH-1615] (#15642) --- .../org/hisp/dhis/analytics/TimeField.java | 2 +- .../dhis/program/AnalyticsPeriodBoundary.java | 2 +- .../data/DefaultEventDataQueryService.java | 2 +- .../data/JdbcEnrollmentAnalyticsManager.java | 2 +- .../event/data/JdbcEventAnalyticsManager.java | 2 +- .../table/JdbcEventAnalyticsTableManager.java | 4 +-- .../JdbcTeiEventsAnalyticsTableManager.java | 2 +- .../data/EnrollmentAnalyticsManagerTest.java | 2 +- .../event/data/EventAnalyticsManagerTest.java | 8 +++--- .../event/data/TimeFieldSqlRendererTest.java | 4 +-- .../JdbcEventAnalyticsTableManagerTest.java | 2 +- .../hisp/dhis/period/PeriodDataProvider.java | 2 +- .../hisp/dhis/program/variable/vDueDate.java | 4 +-- .../dhis/program/variable/vScheduledDate.java | 4 +-- .../HibernateTrackedEntityStore.java | 6 ++--- .../dhis/program/hibernate/Enrollment.hbm.xml | 2 +- .../hisp/dhis/program/hibernate/Event.hbm.xml | 2 +- .../ProgramSqlGeneratorVariablesTest.java | 2 +- .../tracker/event/JdbcEventStore.java | 20 +++++++-------- .../context/ProgramStageInstanceSupplier.java | 4 +-- .../trackedentity/store/query/EventQuery.java | 2 +- .../dhis/tracker/export/event/EventQuery.java | 2 +- .../tracker/export/event/JdbcEventStore.java | 25 ++++++++++--------- .../HibernateTrackedEntityStore.java | 12 ++++----- .../mapper/EventRowCallbackHandler.java | 2 +- .../aggregates/query/EventQuery.java | 2 +- ...nameDueDateToScheduledDateInEventTable.sql | 11 ++++++++ .../AbstractStatementBuilder.java | 7 +++--- .../ProgramIndicatorServiceVariableTest.java | 8 +++--- .../tracker/event_and_enrollment.json | 16 ++++++------ 30 files changed, 89 insertions(+), 76 deletions(-) create mode 100644 dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.41/V2_41_35__RenameDueDateToScheduledDateInEventTable.sql diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/TimeField.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/TimeField.java index 17a5d0907602..03d3fe774034 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/TimeField.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/TimeField.java @@ -44,7 +44,7 @@ public enum TimeField { ENROLLMENT_DATE("enrollmentdate"), INCIDENT_DATE("incidentdate"), // Not a typo, different naming convention between FE and database - SCHEDULED_DATE("duedate"), + SCHEDULED_DATE("scheduleddate"), COMPLETED_DATE("completeddate"), CREATED("created"), LAST_UPDATED("lastupdated"); diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/AnalyticsPeriodBoundary.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/AnalyticsPeriodBoundary.java index 7b5a8cb94758..75dd0fff3c17 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/AnalyticsPeriodBoundary.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/AnalyticsPeriodBoundary.java @@ -98,7 +98,7 @@ public class AnalyticsPeriodBoundary extends BaseIdentifiableObject implements E public static final String DB_INCIDENT_DATE = "incidentdate"; - public static final String DB_SCHEDULED_DATE = "duedate"; + public static final String DB_SCHEDULED_DATE = "scheduleddate"; public static final String DB_QUOTE = "\""; diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java index 27fd03bcfe69..8fda325d19c3 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java @@ -124,7 +124,7 @@ public class DefaultEventDataQueryService implements EventDataQueryService { private static final String COL_NAME_INCIDENTDATE = "incidentdate"; - private static final String COL_NAME_DUEDATE = "duedate"; + private static final String COL_NAME_DUEDATE = "scheduleddate"; private final ProgramService programService; diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java index 672bfdf83ce6..267f704f6e23 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEnrollmentAnalyticsManager.java @@ -553,7 +553,7 @@ protected String getColumn(QueryItem item, String suffix) { && !item.getRepeatableStageParams().simpleStageValueExpected()) { return "(select json_agg(t1) from (select " + colName - + ", incidentdate, duedate, executiondate " + + ", incidentdate, scheduleddate, executiondate " + " from " + eventTableName + " where " diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java index 710eab35adf6..de170a7b5a4b 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java @@ -324,7 +324,7 @@ protected String getSelectClause(EventQueryParams params) { "createdbydisplayname", "lastupdatedbydisplayname", "lastupdated", - "duedate"); + "scheduleddate"); if (params.getProgram().isRegistration()) { cols.add("enrollmentdate", "incidentdate", "tei", "pi"); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java index 9afd7d577b8b..3c3b1e515992 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java @@ -142,7 +142,7 @@ public JdbcEventAnalyticsTableManager( new AnalyticsTableColumn(quote("enrollmentdate"), TIMESTAMP, "pi.enrollmentdate"), new AnalyticsTableColumn(quote("incidentdate"), TIMESTAMP, "pi.incidentdate"), new AnalyticsTableColumn(quote("executiondate"), TIMESTAMP, "psi.executiondate"), - new AnalyticsTableColumn(quote("duedate"), TIMESTAMP, "psi.duedate"), + new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"), new AnalyticsTableColumn(quote("completeddate"), TIMESTAMP, "psi.completeddate"), /* @@ -262,7 +262,7 @@ public List getAnalyticsTables(AnalyticsTableUpdateParams params * status */ static String getDateLinkedToStatus() { - return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.duedate ELSE psi.executiondate END"; + return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.executiondate END"; } /** diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTeiEventsAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTeiEventsAnalyticsTableManager.java index 58d36e1d063e..608cb0f1d7f5 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTeiEventsAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcTeiEventsAnalyticsTableManager.java @@ -137,7 +137,7 @@ public JdbcTeiEventsAnalyticsTableManager( new AnalyticsTableColumn(quote("executiondate"), TIMESTAMP, "psi.executiondate"), new AnalyticsTableColumn(quote("lastupdated"), TIMESTAMP, "psi.lastupdated"), new AnalyticsTableColumn(quote("created"), TIMESTAMP, "psi.created"), - new AnalyticsTableColumn(quote("duedate"), TIMESTAMP, "psi.duedate"), + new AnalyticsTableColumn(quote("scheduleddate"), TIMESTAMP, "psi.scheduleddate"), new AnalyticsTableColumn(quote("status"), VARCHAR_50, "psi.status"), new AnalyticsTableColumn(quote("psigeometry"), GEOMETRY, "psi.geometry") .withIndexType(GIST), diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EnrollmentAnalyticsManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EnrollmentAnalyticsManagerTest.java index 7104b15d3f62..c8a2d60e945f 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EnrollmentAnalyticsManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EnrollmentAnalyticsManagerTest.java @@ -744,7 +744,7 @@ void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTy is( "(select json_agg(t1) from (select \"" + dataElementA.getUid() - + "\", incidentdate, duedate, executiondate from analytics_event_" + + "\", incidentdate, scheduleddate, executiondate from analytics_event_" + programB.getUid() + " where analytics_event_" + programB.getUid() diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsManagerTest.java index 0547659a422c..0e53b0b1d3c6 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsManagerTest.java @@ -119,7 +119,7 @@ class EventAnalyticsManagerTest extends EventAnalyticsTest { + "createdbydisplayname" + "," + "lastupdatedbydisplayname" - + ",lastupdated,duedate,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,longitude,latitude,ouname,ounamehierarchy," + + ",lastupdated,scheduleddate,enrollmentdate,incidentdate,tei,pi,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,longitude,latitude,ouname,ounamehierarchy," + "oucode,pistatus,psistatus"; @BeforeEach @@ -157,7 +157,7 @@ void verifyGetEventSqlWithProgramWithNoRegistration() { + "createdbydisplayname" + "," + "lastupdatedbydisplayname" - + ",lastupdated,duedate,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry," + + ",lastupdated,scheduleddate,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry," + "longitude,latitude,ouname,ounamehierarchy,oucode,pistatus,psistatus,ax.\"quarterly\",ax.\"ou\" from " + getTable(programA.getUid()) + " as ax where (ax.\"quarterly\" in ('2000Q1') ) and ax.\"uidlevel1\" in ('ouabcdefghA') limit 101"; @@ -218,7 +218,7 @@ void verifyGetEventSqlWithOrgUnitTypeDataElement() { + "createdbydisplayname" + "," + "lastupdatedbydisplayname" - + ",lastupdated,duedate,enrollmentdate," + + ",lastupdated,scheduleddate,enrollmentdate," + "incidentdate,tei,pi,ST_AsGeoJSON(coalesce(ax.\"psigeometry\",ax.\"pigeometry\",ax.\"teigeometry\",ax.\"ougeometry\"), 6) as geometry,longitude,latitude,ouname,ounamehierarchy,oucode,pistatus," + "psistatus,ax.\"quarterly\",ax.\"ou\",\"" + dataElement.getUid() @@ -334,7 +334,7 @@ void verifyGetEventsWithScheduledDateTimeFieldParam() { String expected = "ps.\"quarterly\",ax.\"ou\" from " + getTable(programA.getUid()) - + " as ax left join _dateperiodstructure as ps on cast(ax.\"duedate\" as date) = ps.\"dateperiod\" " + + " as ax left join _dateperiodstructure as ps on cast(ax.\"scheduleddate\" as date) = ps.\"dateperiod\" " + "where (ps.\"quarterly\" in ('2000Q1') ) and ax.\"uidlevel1\" " + "in ('ouabcdefghA') and pistatus in ('ACTIVE','COMPLETED') limit 101"; diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/TimeFieldSqlRendererTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/TimeFieldSqlRendererTest.java index 0ed496d0e458..359ba86e483a 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/TimeFieldSqlRendererTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/TimeFieldSqlRendererTest.java @@ -201,8 +201,8 @@ void testRenderEnrollmentTimeFieldSqlWhenNoContinuousMonthlyPeriodWithTimeFieldA params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build(); assertEquals( - "((ax.\"duedate\" >= '2022-03-01' and ax.\"duedate\" < '2022-04-01') " - + "or (ax.\"duedate\" >= '2022-09-01' and ax.\"duedate\" < '2022-10-01')) ", + "((ax.\"scheduleddate\" >= '2022-03-01' and ax.\"scheduleddate\" < '2022-04-01') " + + "or (ax.\"scheduleddate\" >= '2022-09-01' and ax.\"scheduleddate\" < '2022-10-01')) ", timeFieldSqlRenderer.renderPeriodTimeFieldSql(params)); } diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManagerTest.java index 078af8dd771e..aaa51c85c446 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManagerTest.java @@ -976,6 +976,6 @@ private String getYearQueryForCurrentYear( } private String getDateLinkedToStatus() { - return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.duedate ELSE psi.executiondate END"; + return "CASE WHEN 'SCHEDULE' = psi.status THEN psi.scheduleddate ELSE psi.executiondate END"; } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/PeriodDataProvider.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/PeriodDataProvider.java index 9d87831c4a20..cfe7edd007af 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/PeriodDataProvider.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/PeriodDataProvider.java @@ -118,7 +118,7 @@ void addSafetyBuffer(List years, int buffer) { */ private List fetchAvailableYears() { String dueDateOrExecutionDate = - "(case when 'SCHEDULE' = ev.status then ev.duedate else ev.executiondate end)"; + "(case when 'SCHEDULE' = ev.status then ev.scheduleddate else ev.executiondate end)"; String sql = "( select distinct (extract(year from pe.startdate)) as datayear from period pe )" diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vDueDate.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vDueDate.java index e46a683455a9..e2cb1b986602 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vDueDate.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vDueDate.java @@ -42,14 +42,14 @@ public Object getSql(CommonExpressionVisitor visitor) { ProgramExpressionParams params = visitor.getProgParams(); if (AnalyticsType.EVENT == params.getProgramIndicator().getAnalyticsType()) { - return "duedate"; + return "scheduleddate"; } return visitor .getStatementBuilder() .getProgramIndicatorEventColumnSql( null, - "duedate", + "scheduleddate", params.getReportingStartDate(), params.getReportingEndDate(), params.getProgramIndicator()); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vScheduledDate.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vScheduledDate.java index 073a0e9969c8..ad32b9ddd6db 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vScheduledDate.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/variable/vScheduledDate.java @@ -47,7 +47,7 @@ public Object getSql(CommonExpressionVisitor visitor) { .getStatementBuilder() .getProgramIndicatorEventColumnSql( null, - "duedate", + "scheduleddate", params.getReportingStartDate(), params.getReportingEndDate(), params.getProgramIndicator()); @@ -55,7 +55,7 @@ public Object getSql(CommonExpressionVisitor visitor) { return maybeAppendEventStatusFilterIntoWhere(sqlStatement); } - return "duedate"; + return "scheduleddate"; } private String maybeAppendEventStatusFilterIntoWhere(String sqlStatement) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java index ed5f6f24f49e..25c2d934d30b 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityStore.java @@ -116,7 +116,7 @@ public class HibernateTrackedEntityStore extends SoftDeleteHibernateObjectStore< private static final String EV_EXECUTIONDATE = "EV.executiondate"; - private static final String EV_DUEDATE = "EV.duedate"; + private static final String EV_DUEDATE = "EV.scheduleddate"; private static final String IS_NULL = "IS NULL"; @@ -1035,7 +1035,7 @@ private String getFromSubQueryEvent(TrackedEntityQueryParams params) { .append(SPACE) .append(IS_NULL) .append(whereHlp.whereAnd()) - .append("date(now()) <= date(EV.duedate) "); + .append("date(now()) <= date(EV.scheduleddate) "); } else if (params.isEventStatus(EventStatus.OVERDUE)) { events .append(getQueryDateConditionBetween(whereHlp, EV_DUEDATE, start, end)) @@ -1048,7 +1048,7 @@ private String getFromSubQueryEvent(TrackedEntityQueryParams params) { .append(SPACE) .append(IS_NULL) .append(whereHlp.whereAnd()) - .append("date(now()) > date(EV.duedate) "); + .append("date(now()) > date(EV.scheduleddate) "); } else if (params.isEventStatus(EventStatus.SKIPPED)) { events .append(getQueryDateConditionBetween(whereHlp, EV_DUEDATE, start, end)) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml index be60fd779475..010cb4d4bab6 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml @@ -59,7 +59,7 @@ - + diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Event.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Event.hbm.xml index 67e24a8085a4..41d76601455a 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Event.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Event.hbm.xml @@ -44,7 +44,7 @@ - + diff --git a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramSqlGeneratorVariablesTest.java b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramSqlGeneratorVariablesTest.java index ef3aa361fd7d..37fe6b97aab2 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramSqlGeneratorVariablesTest.java +++ b/dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/program/ProgramSqlGeneratorVariablesTest.java @@ -159,7 +159,7 @@ void testCurrentDateForEvent() { @Test void testDueDate() { String sql = castString(test("V{due_date}", new DefaultLiteral(), eventIndicator)); - assertThat(sql, is("duedate")); + assertThat(sql, is("scheduleddate")); } @Test diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java index ea762db34bf8..fe2d09c35b67 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java @@ -1029,7 +1029,7 @@ private String getEventSelectQuery( .append( "psi.eventid as psi_id, psi.status as psi_status, psi.executiondate as psi_executiondate, ") .append( - "psi.eventdatavalues as psi_eventdatavalues, psi.duedate as psi_duedate, psi.completedby as psi_completedby, psi.storedby as psi_storedby, ") + "psi.eventdatavalues as psi_eventdatavalues, psi.scheduleddate as psi_duedate, psi.completedby as psi_completedby, psi.storedby as psi_storedby, ") .append( "psi.created as psi_created, psi.createdbyuserinfo as psi_createdbyuserinfo, psi.lastupdated as psi_lastupdated, psi.lastupdatedbyuserinfo as psi_lastupdatedbyuserinfo, ") .append("psi.completeddate as psi_completeddate, psi.deleted as psi_deleted, ") @@ -1185,7 +1185,7 @@ private StringBuilder getFromWhereClause( fromBuilder .append(hlp.whereAnd()) - .append(" (psi.duedate is not null and psi.duedate >= :startDueDate ) "); + .append(" (psi.scheduleddate is not null and psi.scheduleddate >= :startDueDate ) "); } if (params.getDueDateEnd() != null) { @@ -1193,7 +1193,7 @@ private StringBuilder getFromWhereClause( fromBuilder .append(hlp.whereAnd()) - .append(" (psi.duedate is not null and psi.duedate <= :endDueDate ) "); + .append(" (psi.scheduleddate is not null and psi.scheduleddate <= :endDueDate ) "); } if (params.getFollowUp() != null) { @@ -1242,7 +1242,7 @@ private StringBuilder getFromWhereClause( .append(hlp.whereAnd()) .append(" (psi.executiondate >= ") .append(":startDate") - .append(" or (psi.executiondate is null and psi.duedate >= ") + .append(" or (psi.executiondate is null and psi.scheduleddate >= ") .append(":startDate") .append(" )) "); } @@ -1254,7 +1254,7 @@ private StringBuilder getFromWhereClause( .append(hlp.whereAnd()) .append(" (psi.executiondate < ") .append(":endDate") - .append(" or (psi.executiondate is null and psi.duedate < ") + .append(" or (psi.executiondate is null and psi.scheduleddate < ") .append(":endDate") .append(" )) "); } @@ -1531,7 +1531,7 @@ private String getFromWhereClause( .append(hlp.whereAnd()) .append(" (psi.executiondate >= ") .append(":startDate") - .append(" or (psi.executiondate is null and psi.duedate >= ") + .append(" or (psi.executiondate is null and psi.scheduleddate >= ") .append(":startDate") .append(" )) "); } @@ -1543,7 +1543,7 @@ private String getFromWhereClause( .append(hlp.whereAnd()) .append(" (psi.executiondate < ") .append(":endDate ") - .append(" or (psi.executiondate is null and psi.duedate < ") + .append(" or (psi.executiondate is null and psi.scheduleddate < ") .append(":endDate") .append(" )) "); } @@ -1568,7 +1568,7 @@ private String getFromWhereClause( sqlBuilder .append(hlp.whereAnd()) - .append(" psi.duedate is not null and psi.duedate >= ") + .append(" psi.scheduleddate is not null and psi.scheduleddate >= ") .append(":dueDate") .append(" "); } @@ -1578,7 +1578,7 @@ private String getFromWhereClause( sqlBuilder .append(hlp.whereAnd()) - .append(" psi.duedate is not null and psi.duedate <= ") + .append(" psi.scheduleddate is not null and psi.scheduleddate <= ") .append(":endDueDate") .append(" "); } @@ -1637,7 +1637,7 @@ private String eventStatusSql( stringBuilder .append(hlp.whereAnd()) - .append(" date(now()) > date(psi.duedate) and psi.status = ") + .append(" date(now()) > date(psi.scheduleddate) and psi.status = ") .append(":" + PSI_STATUS) .append(" "); } else { diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/context/ProgramStageInstanceSupplier.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/context/ProgramStageInstanceSupplier.java index fc972b0bedca..0a3590ea4eeb 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/context/ProgramStageInstanceSupplier.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/context/ProgramStageInstanceSupplier.java @@ -91,7 +91,7 @@ public Map get( final String sql = "select psi.enrollmentid, psi.programstageid, psi.eventid, " - + "psi.uid, psi.status, psi.deleted, psi.eventdatavalues, psi.duedate, psi.executiondate, " + + "psi.uid, psi.status, psi.deleted, psi.eventdatavalues, psi.scheduleddate, psi.executiondate, " + "psi.completeddate, psi.attributeoptioncomboid, psi.geometry, " + "ou.organisationunitid, ou.uid, ou.code, ou.name, psi.attributeoptioncomboid, c.uid as coc_uid " + "from event psi join organisationunit ou on psi.organisationunitid = ou.organisationunitid " @@ -116,7 +116,7 @@ public Map get( psi.setDeleted(rs.getBoolean("deleted")); psi.setProgramStage(getProgramStage(importOptions, rs.getLong("programstageid"))); psi.setOrganisationUnit(getOu(rs)); - psi.setScheduledDate(rs.getTimestamp("duedate")); + psi.setScheduledDate(rs.getTimestamp("scheduleddate")); psi.setOccurredDate(rs.getTimestamp("executiondate")); psi.setCompletedDate(rs.getTimestamp("completeddate")); psi.setAttributeOptionCombo(getCatOptionCombo(rs)); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/query/EventQuery.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/query/EventQuery.java index e7d23c56931e..69050674cd78 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/query/EventQuery.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/query/EventQuery.java @@ -50,7 +50,7 @@ public enum COLUMNS { UID(new TableColumn("psi", "uid")), STATUS(new TableColumn("psi", "status")), EXECUTION_DATE(new TableColumn("psi", "executiondate")), - DUE_DATE(new TableColumn("psi", "duedate")), + DUE_DATE(new TableColumn("psi", "scheduleddate")), STOREDBY(new TableColumn("psi", "storedby")), COMPLETEDBY(new TableColumn("psi", "completedby")), COMPLETEDDATE(new TableColumn("psi", "completeddate")), diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventQuery.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventQuery.java index 3e8d6e5e7ddb..c5b14535eeda 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventQuery.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventQuery.java @@ -40,7 +40,7 @@ public enum COLUMNS { UID(new TableColumn("ev", "uid")), STATUS(new TableColumn("ev", "status")), EXECUTION_DATE(new TableColumn("ev", "executiondate")), - DUE_DATE(new TableColumn("ev", "duedate")), + SCHEDULED_DATE(new TableColumn("ev", "scheduleddate")), STOREDBY(new TableColumn("ev", "storedby")), COMPLETEDBY(new TableColumn("ev", "completedby")), COMPLETEDDATE(new TableColumn("ev", "completeddate")), diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java index 0650e9f9ba25..1a6c81fdc885 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java @@ -164,7 +164,7 @@ class JdbcEventStore implements EventStore { private static final String COLUMN_EVENT_EXECUTION_DATE = "ev_executiondate"; private static final String COLUMN_ENROLLMENT_FOLLOWUP = "en_followup"; private static final String COLUMN_EVENT_STATUS = "ev_status"; - private static final String COLUMN_EVENT_DUE_DATE = "ev_duedate"; + private static final String COLUMN_EVENT_SCHEDULED_DATE = "ev_scheduleddate"; private static final String COLUMN_EVENT_STORED_BY = "ev_storedby"; private static final String COLUMN_EVENT_LAST_UPDATED_BY = "ev_lastupdatedbyuserinfo"; private static final String COLUMN_EVENT_CREATED_BY = "ev_createdbyuserinfo"; @@ -201,7 +201,7 @@ class JdbcEventStore implements EventStore { entry("occurredDate", COLUMN_EVENT_EXECUTION_DATE), entry("enrollment.followUp", COLUMN_ENROLLMENT_FOLLOWUP), entry("status", COLUMN_EVENT_STATUS), - entry("scheduledDate", COLUMN_EVENT_DUE_DATE), + entry("scheduledDate", COLUMN_EVENT_SCHEDULED_DATE), entry("storedBy", COLUMN_EVENT_STORED_BY), entry("lastUpdatedBy", COLUMN_EVENT_LAST_UPDATED_BY), entry("createdBy", COLUMN_EVENT_CREATED_BY), @@ -326,7 +326,7 @@ private List fetchEvents(EventQueryParams queryParams, PageParams pagePar event.setAttributeOptionCombo(coc); event.setStoredBy(resultSet.getString(COLUMN_EVENT_STORED_BY)); - event.setScheduledDate(resultSet.getTimestamp(COLUMN_EVENT_DUE_DATE)); + event.setScheduledDate(resultSet.getTimestamp(COLUMN_EVENT_SCHEDULED_DATE)); event.setOccurredDate(resultSet.getTimestamp(COLUMN_EVENT_EXECUTION_DATE)); event.setCreated(resultSet.getTimestamp(COLUMN_EVENT_CREATED)); event.setCreatedByUserInfo( @@ -736,8 +736,8 @@ private String getEventSelectQuery( .append(", ev.executiondate as ") .append(COLUMN_EVENT_EXECUTION_DATE) .append(", ") - .append("ev.eventdatavalues as ev_eventdatavalues, ev.duedate as ") - .append(COLUMN_EVENT_DUE_DATE) + .append("ev.eventdatavalues as ev_eventdatavalues, ev.scheduleddate as ") + .append(COLUMN_EVENT_SCHEDULED_DATE) .append(", ev.completedby as ") .append(COLUMN_EVENT_COMPLETED_BY) .append(", ev.storedby as ") @@ -925,19 +925,20 @@ private StringBuilder getFromWhereClause( if (params.getScheduleAtStartDate() != null) { mapSqlParameterSource.addValue( - "startDueDate", params.getScheduleAtStartDate(), Types.TIMESTAMP); + "startScheduledDate", params.getScheduleAtStartDate(), Types.TIMESTAMP); fromBuilder .append(hlp.whereAnd()) - .append(" (ev.duedate is not null and ev.duedate >= :startDueDate ) "); + .append(" (ev.scheduleddate is not null and ev.scheduleddate >= :startScheduledDate ) "); } if (params.getScheduleAtEndDate() != null) { - mapSqlParameterSource.addValue("endDueDate", params.getScheduleAtEndDate(), Types.TIMESTAMP); + mapSqlParameterSource.addValue( + "endScheduledDate", params.getScheduleAtEndDate(), Types.TIMESTAMP); fromBuilder .append(hlp.whereAnd()) - .append(" (ev.duedate is not null and ev.duedate <= :endDueDate ) "); + .append(" (ev.scheduleddate is not null and ev.scheduleddate <= :endScheduledDate ) "); } if (params.getFollowUp() != null) { @@ -986,7 +987,7 @@ private StringBuilder getFromWhereClause( .append(hlp.whereAnd()) .append(" (ev.executiondate >= ") .append(":startDate") - .append(" or (ev.executiondate is null and ev.duedate >= ") + .append(" or (ev.executiondate is null and ev.scheduleddate >= ") .append(":startDate") .append(" )) "); } @@ -999,7 +1000,7 @@ private StringBuilder getFromWhereClause( .append(hlp.whereAnd()) .append(" (ev.executiondate < ") .append(":endDate") - .append(" or (ev.executiondate is null and ev.duedate < ") + .append(" or (ev.executiondate is null and ev.scheduleddate < ") .append(":endDate") .append(" )) "); } @@ -1377,7 +1378,7 @@ private String eventStatusSql( stringBuilder .append(hlp.whereAnd()) - .append(" date(now()) > date(ev.duedate) and ev.status = ") + .append(" date(now()) > date(ev.scheduleddate) and ev.status = ") .append(":" + COLUMN_EVENT_STATUS) .append(" "); } else { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java index d35b691346d2..3674f00c448c 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/HibernateTrackedEntityStore.java @@ -98,7 +98,7 @@ class HibernateTrackedEntityStore extends SoftDeleteHibernateObjectStore date(EV.duedate) "); + .append("date(now()) > date(EV.scheduleddate) "); } else if (params.isEventStatus(EventStatus.SKIPPED)) { events - .append(getQueryDateConditionBetween(whereHlp, EV_DUEDATE, start, end)) + .append(getQueryDateConditionBetween(whereHlp, EV_SCHEDULEDDATE, start, end)) .append(whereHlp.whereAnd()) .append(EV_STATUS) .append(EQUALS) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java index 53d4e128a652..2e1c96decbd2 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EventRowCallbackHandler.java @@ -69,7 +69,7 @@ private Event getEvent(ResultSet rs) throws SQLException { event.setStatus(EventStatus.valueOf(rs.getString(EventQuery.getColumnName(COLUMNS.STATUS)))); event.setOccurredDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.EXECUTION_DATE))); - event.setScheduledDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.DUE_DATE))); + event.setScheduledDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.SCHEDULED_DATE))); event.setStoredBy(rs.getString(EventQuery.getColumnName(COLUMNS.STOREDBY))); event.setCompletedBy(rs.getString(EventQuery.getColumnName(COLUMNS.COMPLETEDBY))); event.setCompletedDate(rs.getTimestamp(EventQuery.getColumnName(COLUMNS.COMPLETEDDATE))); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java index d1b2daf90705..0ee147c615de 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/query/EventQuery.java @@ -46,7 +46,7 @@ public enum COLUMNS { UID(new TableColumn("ev", "uid")), STATUS(new TableColumn("ev", "status")), EXECUTION_DATE(new TableColumn("ev", "executiondate")), - DUE_DATE(new TableColumn("ev", "duedate")), + SCHEDULED_DATE(new TableColumn("ev", "scheduleddate")), STOREDBY(new TableColumn("ev", "storedby")), COMPLETEDBY(new TableColumn("ev", "completedby")), COMPLETEDDATE(new TableColumn("ev", "completeddate")), diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.41/V2_41_35__RenameDueDateToScheduledDateInEventTable.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.41/V2_41_35__RenameDueDateToScheduledDateInEventTable.sql new file mode 100644 index 000000000000..14af6e85b71b --- /dev/null +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.41/V2_41_35__RenameDueDateToScheduledDateInEventTable.sql @@ -0,0 +1,11 @@ +-- rename duedate in event + +do $$ +begin + if exists(select 1 + from information_schema.columns + where table_schema != 'information_schema' and table_name='event' and column_name='duedate') + then +alter table event rename column duedate to scheduleddate; +end if; +end $$; \ No newline at end of file diff --git a/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java b/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java index 0542f74bc987..6b201cacbc3e 100644 --- a/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java +++ b/dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/AbstractStatementBuilder.java @@ -557,9 +557,10 @@ private String getBoundaryColumn( * COMPLETED status). * *

Now, we also need to support SCHEDULE status for events. For this reason this method - * compares the status. If the column is "duedate", it means we only want SCHEDULE status, so we - * return "duedate". In all other cases we assume any other status different from SCHEDULE (which - * makes it backward compatible). In this case the logic will remain based on "executiondate". + * compares the status. If the column is "scheduleddate", it means we only want SCHEDULE status, + * so we return "scheduleddate". In all other cases we assume any other status different from + * SCHEDULE (which makes it backward compatible). In this case the logic will remain based on + * "executiondate". * * @param column * @return the backwards compatible column diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceVariableTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceVariableTest.java index 8efc0da25ada..e1b4d54040bf 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceVariableTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceVariableTest.java @@ -138,9 +138,9 @@ void testCurrentDate() { @Test void testDueDate() { - assertEquals("duedate", getSql("V{due_date}")); + assertEquals("scheduleddate", getSql("V{due_date}")); assertEquals( - "(select duedate from analytics_event_Program000A where analytics_event_Program000A.pi = ax.pi and duedate is not null and executiondate < cast( '2020-02-01' as date ) and executiondate >= cast( '2020-01-01' as date ) order by executiondate desc limit 1 )", + "(select scheduleddate from analytics_event_Program000A where analytics_event_Program000A.pi = ax.pi and scheduleddate is not null and executiondate < cast( '2020-02-01' as date ) and executiondate >= cast( '2020-01-01' as date ) order by executiondate desc limit 1 )", getSqlEnrollment("V{due_date}")); } @@ -211,9 +211,9 @@ void testEventDate() { @Test void testScheduledDate() { - assertEquals("duedate", getSql("V{scheduled_date}")); + assertEquals("scheduleddate", getSql("V{scheduled_date}")); assertEquals( - "(select duedate from analytics_event_Program000A where analytics_event_Program000A.pi = ax.pi and duedate is not null and executiondate < cast( '2020-02-01' as date ) and executiondate >= cast( '2020-01-01' as date ) and psistatus = 'SCHEDULE' order by executiondate desc limit 1 )", + "(select scheduleddate from analytics_event_Program000A where analytics_event_Program000A.pi = ax.pi and scheduleddate is not null and executiondate < cast( '2020-02-01' as date ) and executiondate >= cast( '2020-01-01' as date ) and psistatus = 'SCHEDULE' order by executiondate desc limit 1 )", getSqlEnrollment("V{scheduled_date}")); } diff --git a/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json b/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json index 4c8d09ca4b2a..4aebaaca982d 100644 --- a/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json +++ b/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json @@ -311,7 +311,7 @@ "orgUnitName": "Mbokie CHP", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -335,7 +335,7 @@ "orgUnitName": "Mbokie CHP", "enrolledAt": "2021-03-28T12:05:00.000", "occurredAt": "2021-03-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -359,7 +359,7 @@ "orgUnitName": "test-orgunit-2", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -383,7 +383,7 @@ "orgUnitName": "test-orgunit-2", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -407,7 +407,7 @@ "orgUnitName": "test-orgunit-3", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -431,7 +431,7 @@ "orgUnitName": "test-orgunit-3", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -455,7 +455,7 @@ "orgUnitName": "test-orgunit-3", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], @@ -479,7 +479,7 @@ "orgUnitName": "test-orgunit-3", "enrolledAt": "2021-02-28T12:05:00.000", "occurredAt": "2021-02-28T12:05:00.000", - "dueDate": "2021-02-28T12:05:00.000", + "scheduledAt": "2021-02-28T12:05:00.000", "followUp": false, "deleted": false, "events": [], From 21d1572ee77a7664cafe60396dcd75881f0ecf5c Mon Sep 17 00:00:00 2001 From: Giuseppe Nespolino Date: Fri, 10 Nov 2023 16:26:12 +0100 Subject: [PATCH 10/12] refactor: changed analytics export controller flag names [DHIS2-13779] (#15643) --- .../extensions/AnalyticsSetupExtension.java | 5 +++- .../controller/ResourceTableController.java | 26 ++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/helpers/extensions/AnalyticsSetupExtension.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/helpers/extensions/AnalyticsSetupExtension.java index 51c178575835..eed27ec7ce50 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/helpers/extensions/AnalyticsSetupExtension.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/helpers/extensions/AnalyticsSetupExtension.java @@ -73,7 +73,10 @@ public void beforeAll(ExtensionContext context) { // Invoke the analytics table generation process. ApiResponse response = new ResourceTableActions() - .post("/analytics", new JsonObject(), new QueryParamsBuilder().add("executeTei=true")) + .post( + "/analytics", + new JsonObject(), + new QueryParamsBuilder().add("skipTrackedEntities=false")) .validateStatus(200); String analyticsTaskId = response.extractString("response.id"); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceTableController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceTableController.java index e1f48dbdc291..4a5046960285 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceTableController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ResourceTableController.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.webapi.controller; +import static org.apache.commons.lang3.BooleanUtils.isTrue; import static org.hisp.dhis.analytics.AnalyticsTableType.COMPLETENESS; import static org.hisp.dhis.analytics.AnalyticsTableType.COMPLETENESS_TARGET; import static org.hisp.dhis.analytics.AnalyticsTableType.DATA_VALUE; @@ -69,7 +70,7 @@ import org.springframework.web.bind.annotation.ResponseBody; /** - * @author Lars Helge Overland + * @author Lars Helge Overland. This is the AnalyticsExportController */ @OpenApi.Tags("analytics") @Controller @@ -88,36 +89,37 @@ public class ResourceTableController { @PreAuthorize("hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')") @ResponseBody public WebMessage analytics( - @RequestParam(required = false) boolean skipResourceTables, - @RequestParam(required = false) boolean skipAggregate, - @RequestParam(required = false) boolean skipEvents, - @RequestParam(required = false) boolean skipEnrollment, - @RequestParam(required = false) boolean executeTei, - @RequestParam(required = false) boolean skipOrgUnitOwnership, + @RequestParam(defaultValue = "false") Boolean skipResourceTables, + @RequestParam(defaultValue = "false") Boolean skipAggregate, + @RequestParam(defaultValue = "false") Boolean skipEvents, + @RequestParam(defaultValue = "false") Boolean skipEnrollment, + // STILL EXPERIMENTAL: to export TEIs, FE needs to set this to "false" explicitly + @RequestParam(defaultValue = "true") Boolean skipTrackedEntities, + @RequestParam(defaultValue = "false") Boolean skipOrgUnitOwnership, @RequestParam(required = false) Integer lastYears) throws ConflictException, @OpenApi.Ignore NotFoundException { Set skipTableTypes = new HashSet<>(); Set skipPrograms = new HashSet<>(); - if (skipAggregate) { + if (isTrue(skipAggregate)) { skipTableTypes.add(DATA_VALUE); skipTableTypes.add(COMPLETENESS); skipTableTypes.add(COMPLETENESS_TARGET); } - if (skipEvents) { + if (isTrue(skipEvents)) { skipTableTypes.add(EVENT); } - if (skipEnrollment) { + if (isTrue(skipEnrollment)) { skipTableTypes.add(ENROLLMENT); } - if (skipOrgUnitOwnership) { + if (isTrue(skipOrgUnitOwnership)) { skipTableTypes.add(OWNERSHIP); } - if (!executeTei) { + if (isTrue(skipTrackedEntities)) { skipTableTypes.add(TRACKED_ENTITY_INSTANCE); skipTableTypes.add(TRACKED_ENTITY_INSTANCE_EVENTS); skipTableTypes.add(TRACKED_ENTITY_INSTANCE_ENROLLMENTS); From 270ca56ff741e9c187d6cde00bea9814894a9906 Mon Sep 17 00:00:00 2001 From: Enrico Colasante Date: Mon, 13 Nov 2023 08:08:52 +0100 Subject: [PATCH 11/12] chore: Rename endDate to completedDate in service layer [TECH-1665] (#15652) * chore: Rename endDate to completedDate in service layer [TECH-1665] * Fix tests --- .../main/java/org/hisp/dhis/program/Enrollment.java | 12 ++++++------ .../java/org/hisp/dhis/program/EnrollmentTest.java | 8 ++++---- .../hisp/dhis/program/DefaultEnrollmentService.java | 4 ++-- .../hisp/dhis/program/hibernate/Enrollment.hbm.xml | 2 +- .../enrollment/AbstractEnrollmentService.java | 8 ++++---- .../importer/shared/validation/EventBaseCheck.java | 4 ++-- .../shared/validation/EventBaseCheckTest.java | 2 +- .../export/enrollment/DefaultEnrollmentService.java | 2 +- .../export/enrollment/HibernateEnrollmentStore.java | 2 +- .../mapper/EnrollmentRowCallbackHandler.java | 2 +- .../converter/EnrollmentTrackerConverterService.java | 4 ++-- .../dhis/tracker/imports/bundle/OwnershipTest.java | 4 ++-- .../tracker/export/enrollment/EnrollmentMapper.java | 4 ++-- .../export/relationship/RelationshipItemMapper.java | 2 +- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Enrollment.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Enrollment.java index 6176a373c0a3..af2e119d9631 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Enrollment.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Enrollment.java @@ -71,7 +71,7 @@ public class Enrollment extends SoftDeletableObject { private Date enrollmentDate; - private Date endDate; + private Date completedDate; private UserInfoSnapshot createdByUserInfo; @@ -238,12 +238,12 @@ public void setEnrollmentDate(Date enrollmentDate) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) - public Date getEndDate() { - return endDate; + public Date getCompletedDate() { + return completedDate; } - public void setEndDate(Date endDate) { - this.endDate = endDate; + public void setCompletedDate(Date completedDate) { + this.completedDate = completedDate; } @JsonProperty @@ -434,7 +434,7 @@ private static void setShallowCopyValues( copy.setCompletedBy(original.getCompletedBy()); copy.setCreatedAtClient(original.getCreatedAtClient()); copy.setCreatedByUserInfo(original.getCreatedByUserInfo()); - copy.setEndDate(original.getEndDate()); + copy.setCompletedDate(original.getCompletedDate()); copy.setEnrollmentDate(original.getEnrollmentDate()); copy.setEvents(new HashSet<>()); copy.setFollowup(original.getFollowup()); diff --git a/dhis-2/dhis-api/src/test/java/org/hisp/dhis/program/EnrollmentTest.java b/dhis-2/dhis-api/src/test/java/org/hisp/dhis/program/EnrollmentTest.java index 5e127fd2abd1..4f34112e5c6f 100644 --- a/dhis-2/dhis-api/src/test/java/org/hisp/dhis/program/EnrollmentTest.java +++ b/dhis-2/dhis-api/src/test/java/org/hisp/dhis/program/EnrollmentTest.java @@ -68,7 +68,7 @@ void testCopyOfWithPropertyValuesSet() { assertEquals(original.getFollowup(), copy.getFollowup()); assertEquals(original.getGeometry(), copy.getGeometry()); assertEquals(original.getOrganisationUnit(), copy.getOrganisationUnit()); - assertEquals(original.getEndDate(), copy.getEndDate()); + assertEquals(original.getCompletedDate(), copy.getCompletedDate()); assertEquals(original.getRelationshipItems(), copy.getRelationshipItems()); assertEquals(original.getCreatedByUserInfo(), copy.getCreatedByUserInfo()); assertEquals(original.getMessageConversations(), copy.getMessageConversations()); @@ -86,7 +86,7 @@ void testCopyOfWithNullPropertyValues() { assertNotEquals(original.getProgram(), copy.getProgram()); assertEquals(original.getCreatedByUserInfo(), copy.getCreatedByUserInfo()); - assertEquals(original.getEndDate(), copy.getEndDate()); + assertEquals(original.getCompletedDate(), copy.getCompletedDate()); assertEquals(original.getEnrollmentDate(), copy.getEnrollmentDate()); assertEquals(original.getFollowup(), copy.getFollowup()); assertEquals(original.getGeometry(), copy.getGeometry()); @@ -117,7 +117,7 @@ private Enrollment getNewEnrollmentWithNoNulls() { e.setAutoFields(); e.setNotes(List.of(new Note("note", "amin"))); e.setCompletedBy("admin"); - e.setEndDate(new Date()); + e.setCompletedDate(new Date()); e.setEnrollmentDate(new Date()); e.setEvents(Set.of()); e.setFollowup(true); @@ -138,7 +138,7 @@ private Enrollment getNewEnrollmentWithNulls() { e.setName(null); e.setNotes(null); e.setCompletedBy(null); - e.setEndDate(null); + e.setCompletedDate(null); e.setEnrollmentDate(null); e.setEvents(null); e.setIncidentDate(null); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEnrollmentService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEnrollmentService.java index 672459e49f49..f4e8752ba6da 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultEnrollmentService.java @@ -472,7 +472,7 @@ public void cancelEnrollmentStatus(Enrollment enrollment) { // Set status as skipped for overdue events, or delete // ------------------------------------------------------------- - if (event.getScheduledDate().before(enrollment.getEndDate())) { + if (event.getScheduledDate().before(enrollment.getCompletedDate())) { event.setStatus(EventStatus.SKIPPED); eventStore.update(event); } else { @@ -501,7 +501,7 @@ public void incompleteEnrollmentStatus(Enrollment enrollment) { // ----------------------------------------------------------------- enrollment.setStatus(ProgramStatus.ACTIVE); - enrollment.setEndDate(null); + enrollment.setCompletedDate(null); updateEnrollment(enrollment); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml index 010cb4d4bab6..d51291283fb5 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/Enrollment.hbm.xml @@ -32,7 +32,7 @@ - + diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/enrollment/AbstractEnrollmentService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/enrollment/AbstractEnrollmentService.java index acf92bb1d53f..11ab9b31dfb3 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/enrollment/AbstractEnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/enrollment/AbstractEnrollmentService.java @@ -320,7 +320,7 @@ public org.hisp.dhis.dxf2.deprecated.tracker.enrollment.Enrollment getEnrollment enrollment.setEnrollmentDate(programInstance.getEnrollmentDate()); enrollment.setIncidentDate(programInstance.getIncidentDate()); enrollment.setFollowup(programInstance.getFollowup()); - enrollment.setCompletedDate(programInstance.getEndDate()); + enrollment.setCompletedDate(programInstance.getCompletedDate()); enrollment.setCompletedBy(programInstance.getCompletedBy()); enrollment.setStoredBy(programInstance.getStoredBy()); enrollment.setCreatedByUserInfo(programInstance.getCreatedByUserInfo()); @@ -598,7 +598,7 @@ private ImportSummary addEnrollment( } programInstance.setCompletedBy(user); - programInstance.setEndDate(date); + programInstance.setCompletedDate(date); } programInstance.setCreatedByUserInfo(UserInfoSnapshot.from(importOptions.getUser())); @@ -973,11 +973,11 @@ private ImportSummary updateEnrollment( } if (EnrollmentStatus.CANCELLED == enrollment.getStatus()) { - programInstance.setEndDate(endDate); + programInstance.setCompletedDate(endDate); enrollmentService.cancelEnrollmentStatus(programInstance); } else if (EnrollmentStatus.COMPLETED == enrollment.getStatus()) { - programInstance.setEndDate(endDate); + programInstance.setCompletedDate(endDate); programInstance.setCompletedBy(user); enrollmentService.completeEnrollmentStatus(programInstance); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheck.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheck.java index f7ce521224bf..fe59df475dd1 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheck.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheck.java @@ -115,12 +115,12 @@ private void validateProgramInstance(ImmutableEvent event, WorkContext ctx, List referenceDate = removeTimeStamp(referenceDate); - if (referenceDate.after(removeTimeStamp(enrollment.getEndDate()))) { + if (referenceDate.after(removeTimeStamp(enrollment.getCompletedDate()))) { errors.add( "Not possible to add event to a completed enrollment. Event created date ( " + referenceDate + " ) is after enrollment completed date ( " - + removeTimeStamp(enrollment.getEndDate()) + + removeTimeStamp(enrollment.getCompletedDate()) + " )."); } } diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheckTest.java b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheckTest.java index 8f7b2bca3259..56c453a6a44d 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheckTest.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/deprecated/tracker/importer/shared/validation/EventBaseCheckTest.java @@ -129,7 +129,7 @@ void verifyErrorOnEventWithDateNewerThanCompletedProgramInstance() { Enrollment enrollment = new Enrollment(); enrollment.setStatus(ProgramStatus.COMPLETED); // Set enrollment end date to NOW - one month - enrollment.setEndDate(Date.from(ZonedDateTime.now().minusMonths(1).toInstant())); + enrollment.setCompletedDate(Date.from(ZonedDateTime.now().minusMonths(1).toInstant())); programInstanceMap.put(event.getUid(), enrollment); when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap); when(workContext.getImportOptions()).thenReturn(importOptions); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java index cc21908c3b6d..3992d9c27579 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/DefaultEnrollmentService.java @@ -125,7 +125,7 @@ public Enrollment getEnrollment( result.setEnrollmentDate(enrollment.getEnrollmentDate()); result.setIncidentDate(enrollment.getIncidentDate()); result.setFollowup(enrollment.getFollowup()); - result.setEndDate(enrollment.getEndDate()); + result.setCompletedDate(enrollment.getCompletedDate()); result.setCompletedBy(enrollment.getCompletedBy()); result.setStoredBy(enrollment.getStoredBy()); result.setCreatedByUserInfo(enrollment.getCreatedByUserInfo()); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java index 156170e36521..660d10da4951 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/enrollment/HibernateEnrollmentStore.java @@ -78,7 +78,7 @@ class HibernateEnrollmentStore extends SoftDeleteHibernateObjectStore ORDERABLE_FIELDS = Set.of( - "endDate", + "completedDate", "created", "createdAtClient", "enrollmentDate", diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java index 568b8c57e093..79afa20af9f2 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/EnrollmentRowCallbackHandler.java @@ -99,7 +99,7 @@ private Enrollment getEnrollment(ResultSet rs) throws SQLException { rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.ENROLLMENTDATE))); enrollment.setIncidentDate( rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.INCIDENTDATE))); - enrollment.setEndDate(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.COMPLETED))); + enrollment.setCompletedDate(rs.getTimestamp(EnrollmentQuery.getColumnName(COLUMNS.COMPLETED))); enrollment.setCompletedBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.COMPLETEDBY))); enrollment.setStoredBy(rs.getString(EnrollmentQuery.getColumnName(COLUMNS.STOREDBY))); enrollment.setDeleted(rs.getBoolean(EnrollmentQuery.getColumnName(COLUMNS.DELETED))); diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/converter/EnrollmentTrackerConverterService.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/converter/EnrollmentTrackerConverterService.java index 1344f829efc0..ef7a396bde6b 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/converter/EnrollmentTrackerConverterService.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/imports/converter/EnrollmentTrackerConverterService.java @@ -158,10 +158,10 @@ private Enrollment from( if (previousStatus != dbEnrollment.getStatus()) { if (dbEnrollment.isCompleted()) { - dbEnrollment.setEndDate(now); + dbEnrollment.setCompletedDate(now); dbEnrollment.setCompletedBy(preheat.getUsername()); } else if (dbEnrollment.getStatus().equals(ProgramStatus.CANCELLED)) { - dbEnrollment.setEndDate(now); + dbEnrollment.setCompletedDate(now); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java index d77d75a77b92..9c2517c0ad18 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/imports/bundle/OwnershipTest.java @@ -175,7 +175,7 @@ void testUpdateEnrollment() throws IOException { enrollments.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get(); compareEnrollmentBasicProperties(enrollment, enrollmentParams.getEnrollments().get(0)); assertNull(enrollment.getCompletedBy()); - assertNull(enrollment.getEndDate()); + assertNull(enrollment.getCompletedDate()); org.hisp.dhis.tracker.imports.domain.Enrollment updatedEnrollment = enrollmentParams.getEnrollments().get(0); @@ -194,7 +194,7 @@ void testUpdateEnrollment() throws IOException { enrollment = enrollments.stream().filter(e -> e.getUid().equals("TvctPPhpD8u")).findAny().get(); compareEnrollmentBasicProperties(enrollment, updatedEnrollment); assertNotNull(enrollment.getCompletedBy()); - assertNotNull(enrollment.getEndDate()); + assertNotNull(enrollment.getCompletedDate()); } @Test diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentMapper.java index 9521190a9b6e..3a58126c3798 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/enrollment/EnrollmentMapper.java @@ -59,7 +59,7 @@ public interface EnrollmentMapper */ Map ORDERABLE_FIELDS = Map.ofEntries( - entry("completedAt", "endDate"), + entry("completedAt", "completedDate"), entry("createdAt", "created"), entry("createdAtClient", "createdAtClient"), entry("enrolledAt", "enrollmentDate"), @@ -77,7 +77,7 @@ public interface EnrollmentMapper @Mapping(target = "enrolledAt", source = "enrollmentDate") @Mapping(target = "occurredAt", source = "incidentDate") @Mapping(target = "followUp", source = "followup") - @Mapping(target = "completedAt", source = "endDate") + @Mapping(target = "completedAt", source = "completedDate") @Mapping(target = "createdBy", source = "createdByUserInfo") @Mapping(target = "updatedBy", source = "lastUpdatedByUserInfo") @Mapping(target = "relationships", source = "relationshipItems") diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java index 021ec0c6565f..204f856aa4ac 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/tracker/export/relationship/RelationshipItemMapper.java @@ -83,7 +83,7 @@ interface RelationshipItemMapper @Mapping(target = "enrolledAt", source = "enrollmentDate") @Mapping(target = "occurredAt", source = "incidentDate") @Mapping(target = "followUp", source = "followup") - @Mapping(target = "completedAt", source = "endDate") + @Mapping(target = "completedAt", source = "completedDate") @Mapping(target = "createdBy", source = "createdByUserInfo") @Mapping(target = "updatedBy", source = "lastUpdatedByUserInfo") @Mapping(target = "attributes", source = "trackedEntity.trackedEntityAttributeValues") From baddaf80f0994d56cd8f5967b16310bf1f3dc61c Mon Sep 17 00:00:00 2001 From: Jason Pickering Date: Mon, 13 Nov 2023 12:36:19 +0300 Subject: [PATCH 12/12] fix: Close database connection after test statement. (#15640) * fix: Close database connection after test statement. --- .../java/org/hisp/dhis/datasource/DatabasePoolUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java index 9d7d9ada1a9a..417b3bafac9b 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/datasource/DatabasePoolUtils.java @@ -342,10 +342,12 @@ private static DataSource createC3p0DbPool(PoolConfig config) } public static void testConnection(DataSource dataSource) throws SQLException { - Connection conn = dataSource.getConnection(); - try (Statement stmt = conn.createStatement()) { + try (Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement()) { stmt.executeQuery("select 'connection_test' as connection_test;"); + } catch (SQLException e) { + log.error(e.getMessage()); } } }