Skip to content

Commit

Permalink
feat: default period is no more automatically added [DHIS2-16052] (#1…
Browse files Browse the repository at this point in the history
…5519)

* feat: default period is no more automatically added [DHIS2-16052]

* test: fixing e2e tests [DHIS2-16052]
  • Loading branch information
gnespolino authored Oct 27, 2023
1 parent e1cdd70 commit 08149c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,26 @@
*/
package org.hisp.dhis.analytics.tei;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.analytics.common.params.dimension.DimensionIdentifier;
import org.hisp.dhis.analytics.common.params.dimension.DimensionParam;
import org.hisp.dhis.analytics.common.params.dimension.DimensionParamType;
import org.hisp.dhis.analytics.common.processing.CommonQueryRequestMapper;
import org.hisp.dhis.analytics.common.processing.Processor;
import org.springframework.stereotype.Component;

/**
* This component is a hook to allow for post-processing of the {@link TeiQueryParams} before it is
* used to build the query context.
*/
@Component
@RequiredArgsConstructor
public class TeiQueryParamPostProcessor implements Processor<TeiQueryParams> {
private static final String DEFAULT_PERIOD = "pe:LAST_YEAR:LAST_UPDATED";

private final CommonQueryRequestMapper commonQueryRequestMapper;

/**
* Processes the given {@link TeiQueryParams} and returns the processed version.
*
* @param params to be processed.
* @return the processed {@link TeiQueryParams}.
*/
public TeiQueryParams process(TeiQueryParams params) {
boolean existsPeriodRestriction =
params.getCommonParams().getDimensionIdentifiers().stream()
.filter(d -> d.getDimension().isPeriodDimension())
.anyMatch(d -> d.getDimension().hasRestrictions());

if (existsPeriodRestriction) {
return params;
}

DimensionIdentifier<DimensionParam> defaultPeriod =
commonQueryRequestMapper.toDimensionIdentifier(
DEFAULT_PERIOD,
DimensionParamType.DATE_FILTERS,
params.getCommonParams().getRelativePeriodDate(),
params.getCommonParams().getDisplayProperty(),
params.getCommonParams().getPrograms(),
params.getCommonParams().getUserOrgUnit());

List<DimensionIdentifier<DimensionParam>> dimensionIdentifiers =
Stream.concat(
params.getCommonParams().getDimensionIdentifiers().stream(),
Stream.of(defaultPeriod))
.collect(Collectors.toList());

return params.toBuilder()
.commonParams(
params.getCommonParams().toBuilder().dimensionIdentifiers(dimensionIdentifiers).build())
.build();
// do nothing for now - implement required TeiQueryParams processing here.
return params;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void queryWithProgramAndProgramStageWhenTotalPagesIsFalse() {
.add("dimension=ou:ImspTQPwCqd")
.add("program=IpHINAT79UW")
.add("asc=IpHINAT79UW.w75KJ2mc4zz")
.add("lastUpdated=LAST_YEAR")
.add("totalPages=false")
.add("pageSize=100")
.add("page=1")
Expand Down Expand Up @@ -2577,6 +2578,7 @@ public void queryWithProgramStatus() {
new QueryParamsBuilder()
.add("program=IpHINAT79UW")
.add("programStatus=IpHINAT79UW.COMPLETED")
.add("lastUpdated=LAST_YEAR")
.add("desc=lastupdated")
.add("relativePeriodDate=2018-01-01");

Expand Down Expand Up @@ -2630,6 +2632,7 @@ public void queryWithEnrollmentStatus() {
new QueryParamsBuilder()
.add("program=IpHINAT79UW")
.add("enrollmentStatus=IpHINAT79UW.COMPLETED")
.add("lastUpdated=LAST_YEAR")
.add("desc=lastupdated")
.add("relativePeriodDate=2018-01-01");

Expand Down Expand Up @@ -2683,6 +2686,7 @@ public void queryWithEventStatus() {
new QueryParamsBuilder()
.add("program=IpHINAT79UW")
.add("eventStatus=IpHINAT79UW.A03MvHHogjR.COMPLETED")
.add("lastUpdated=LAST_YEAR")
.add("desc=lastupdated")
.add("relativePeriodDate=2018-01-01");

Expand Down

0 comments on commit 08149c2

Please sign in to comment.