Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading