Skip to content

Commit

Permalink
Merge branch 'master' into DHIS-16705_DORIS_TEI_TABLE_POPULATION
Browse files Browse the repository at this point in the history
  • Loading branch information
luciano-fiandesio authored Nov 26, 2024
2 parents a5565cd + 56a870d commit 2738f17
Show file tree
Hide file tree
Showing 36 changed files with 116 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
@Service("org.hisp.dhis.analytics.DataQueryService")
@RequiredArgsConstructor
public class DefaultDataQueryService implements DataQueryService {
private final DimensionalObjectProducer dimensionalObjectProducer;
private final DimensionalObjectProvider dimensionalObjectProducer;

private final IdentifiableObjectManager idObjectManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
*/
@Component
@RequiredArgsConstructor
public class DimensionalObjectProducer {
public class DimensionalObjectProvider {
private final IdentifiableObjectManager idObjectManager;

private final OrganisationUnitService organisationUnitService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.UUID;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.analytics.data.DimensionalObjectProducer;
import org.hisp.dhis.analytics.data.DimensionalObjectProvider;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.DisplayProperty;
Expand All @@ -60,7 +60,7 @@
@AllArgsConstructor
public class OutlierQueryParser {
private final IdentifiableObjectManager idObjectManager;
private final DimensionalObjectProducer dimensionalObjectProducer;
private final DimensionalObjectProvider dimensionalObjectProducer;
private final UserService userService;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.hisp.dhis.analytics.cache.OutliersCache;
import org.hisp.dhis.analytics.common.ColumnHeader;
import org.hisp.dhis.analytics.common.TableInfoReader;
import org.hisp.dhis.analytics.data.DimensionalObjectProducer;
import org.hisp.dhis.analytics.data.DimensionalObjectProvider;
import org.hisp.dhis.analytics.outlier.data.Outlier;
import org.hisp.dhis.analytics.outlier.data.OutlierRequest;
import org.hisp.dhis.category.CategoryOptionCombo;
Expand Down Expand Up @@ -104,7 +104,7 @@ public class AnalyticsOutlierService {

private final IdentifiableObjectManager idObjectManager;

private final DimensionalObjectProducer dimensionalObjectProducer;
private final DimensionalObjectProvider dimensionalObjectProducer;

/**
* Transform the incoming request into api response (json).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,23 @@ protected List<AnalyticsTableColumn> getTrackedEntityAttributeColumns(Program pr
* The select statement used by the table population.
*
* @param attribute the {@link TrackedEntityAttribute}.
* @param fromType the sql snippet related to "from" part
* @param columnExpression the column expression.
* @param dataClause the data type related clause like "NUMERIC".
* @return a select statement.
*/
protected String selectForInsert(
TrackedEntityAttribute attribute, String fromType, String dataClause) {
TrackedEntityAttribute attribute, String columnExpression, String dataClause) {
return replaceQualify(
"""
(select ${fromType} from ${trackedentityattributevalue} \
(select ${columnExpression} from ${trackedentityattributevalue} \
where trackedentityid=en.trackedentityid \
and trackedentityattributeid=${attributeId}\
${dataClause})\
and trackedentityattributeid=${attributeId}${dataClause})\
${closingParentheses} as ${attributeUid}""",
Map.of(
"fromType", fromType,
"columnExpression", columnExpression,
"dataClause", dataClause,
"attributeId", String.valueOf(attribute.getId()),
"closingParentheses", getClosingParentheses(fromType),
"closingParentheses", getClosingParentheses(columnExpression),
"attributeUid", quote(attribute.getUid())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static org.hisp.dhis.commons.util.TextUtils.emptyIfTrue;
import static org.hisp.dhis.commons.util.TextUtils.format;
import static org.hisp.dhis.commons.util.TextUtils.removeLastComma;
import static org.hisp.dhis.commons.util.TextUtils.replace;
import static org.hisp.dhis.db.model.DataType.CHARACTER_11;
import static org.hisp.dhis.db.model.DataType.DATE;
import static org.hisp.dhis.db.model.DataType.INTEGER;
Expand Down Expand Up @@ -213,18 +212,17 @@ private List<Integer> getDataYears(AnalyticsTableUpdateParams params) {
String fromDateClause =
params.getFromDate() == null
? ""
: replace(
"and ps.startdate >= '${fromDate}'",
Map.of("fromDate", DateUtils.toMediumDate(params.getFromDate())));
: String.format(
" and ps.startdate >= '%s'", DateUtils.toMediumDate(params.getFromDate()));

String sql =
replaceQualify(
"""
select distinct(extract(year from ps.startdate)) \
from ${validationresult} vrs \
inner join analytics_rs_periodstructure ps on vrs.periodid=ps.periodid \
where ps.startdate is not null \
and vrs.created < '${startTime}'
${fromDateClause}""",
and vrs.created < '${startTime}'${fromDateClause}""",
Map.of(
"startTime", toLongDate(params.getStartTime()), "fromDateClause", fromDateClause));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@
import org.hisp.dhis.common.IllegalQueryException;
import org.junit.jupiter.api.Test;

/** Unit tests for {@link DimensionIdentifierHelper} */
class DimensionIdentifierHelperTest {
@Test
void testFromFullDimensionId() {
// Given
String fullDimensionId = "lxAQ7Zs9VYR[0].RaMbOrTys0n[4].bh1Edk21e2n";

// When
StringDimensionIdentifier dimensionIdentifier = fromFullDimensionId(fullDimensionId);

// Then
assertEquals(
"bh1Edk21e2n",
dimensionIdentifier.getDimension().getUid(),
Expand All @@ -64,26 +60,20 @@ void testFromFullDimensionId() {

@Test
void testFromDimensionIdWithUnsupportedOffset() {
// Given
String dimensionIdWithDashOffset = "lxAQ7Zs9VYR[-].bh1Edk21e2n";
String dimensionIdWithStringOffset = "lxAQ7Zs9VYR[X].bh1Edk21e2n";

// When
// Then
assertThrows(IllegalQueryException.class, () -> fromFullDimensionId(dimensionIdWithDashOffset));
assertThrows(
IllegalQueryException.class, () -> fromFullDimensionId(dimensionIdWithStringOffset));
}

@Test
void testFromFullDimensionIdWithSingleDimension() {
// Given
String singleDimensionId = "bh1Edk21e2n";

// When
StringDimensionIdentifier dimensionIdentifier = fromFullDimensionId(singleDimensionId);

// Then
assertEquals(
"bh1Edk21e2n",
dimensionIdentifier.getDimension().getUid(),
Expand All @@ -96,13 +86,10 @@ void testFromFullDimensionIdWithSingleDimension() {

@Test
void testFromFullDimensionIdWithProgramAndDimension() {
// Given
String singleDimensionId = "lxAQ7Zs9VYR.bh1Edk21e2n";

// When
StringDimensionIdentifier dimensionIdentifier = fromFullDimensionId(singleDimensionId);

// Then
assertEquals(
"bh1Edk21e2n",
dimensionIdentifier.getDimension().getUid(),
Expand All @@ -117,15 +104,12 @@ void testFromFullDimensionIdWithProgramAndDimension() {

@Test
void testFromFullDimensionIdWhenSingleDimensionHasOffset() {
// Given
String singleDimensionWithOffset = "bh1Edk21e2n[2]";

// When
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> fromFullDimensionId(singleDimensionWithOffset));

// Then
assertEquals(
"Only program and program stage can have offset",
thrown.getMessage(),
Expand All @@ -134,15 +118,12 @@ void testFromFullDimensionIdWhenSingleDimensionHasOffset() {

@Test
void testFromFullDimensionIdWhenDimensionHasInvalidFormat() {
// Given
String invalidFullDimensionId = "lxAQ7Zs9VYR[1].RaMbOrTys0n[4].bh1Edk21e2n.invalid-id";

// When
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> fromFullDimensionId(invalidFullDimensionId));

// Then
assertEquals(
"Invalid dimension identifier: " + invalidFullDimensionId,
thrown.getMessage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ void mapWhenProgramsCannotBeFound() {
programService,
dimensionIdentifierConverter);

// List has only one Program, but the CommonQueryRequest, below, has
// two.
// List has only one Program, but the CommonQueryRequest, has two
List<Program> programs = List.of(program1);

CommonRequestParams commonRequestParams =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.junit.jupiter.api.Test;

class NotConditionRendererTest {

@Test
void testInWithSingleValueProduceCorrectSql() {
Renderable renderable = () -> "test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void verifyReportingRatesValueWhenPeriodIsFilter() {
DataQueryParams.newBuilder()
.withOrganisationUnit(ou)
// DATA ELEMENTS
.withDataElements(newArrayList(reportingRateA, reportingRateB, reportingRateC))
.withDataElements(List.of(reportingRateA, reportingRateB, reportingRateC))
.withIgnoreLimit(true)
// FILTERS (OU)
.withFilters(List.of(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class DataQueryServiceDimensionItemKeywordTest {

@Mock private I18n i18n;

@InjectMocks private DimensionalObjectProducer dimensionalObjectProducer;
@InjectMocks private DimensionalObjectProvider dimensionalObjectProducer;

private DefaultDataQueryService target;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
@ExtendWith(MockitoExtension.class)
class DataQueryServiceTest {

@Mock private DimensionalObjectProducer dimensionalObjectProducer;
@Mock private DimensionalObjectProvider dimensionalObjectProducer;

@Mock private IdentifiableObjectManager idObjectManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Unit tests for {@link DimensionalObjectProducer}.
* Unit tests for {@link DimensionalObjectProvider}.
*
* @author maikel arabori
*/
@ExtendWith(MockitoExtension.class)
class DimensionalObjectProducerTest {
class DimensionalObjectProviderTest {

@Mock private IdentifiableObjectManager idObjectManager;

Expand All @@ -135,7 +135,7 @@ class DimensionalObjectProducerTest {

@Mock private I18nFormat i18nFormat;

@InjectMocks private DimensionalObjectProducer target;
@InjectMocks private DimensionalObjectProvider target;

@BeforeEach
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@
* @author Jim Grace
*/
class OrgUnitTableJoinerTest extends TestBase {
private static final OrgUnitField DEFAULT = new OrgUnitField(null);
private final OrgUnitField DEFAULT = new OrgUnitField(null);

private static final OrgUnitField ATTRIBUTE = new OrgUnitField("AttributeId");
private final OrgUnitField ATTRIBUTE = new OrgUnitField("AttributeId");

private static final OrgUnitField OWNER_AT_START = new OrgUnitField("OWNER_AT_START");
private final OrgUnitField OWNER_AT_START = new OrgUnitField("OWNER_AT_START");

private static final OrgUnitField OWNER_AT_END = new OrgUnitField("OWNER_AT_END");
private final OrgUnitField OWNER_AT_END = new OrgUnitField("OWNER_AT_END");

private static final Program programA = createProgram('A');
private final Program programA = createProgram('A');

private static final Period periodDaily = PeriodType.getPeriodFromIsoString("20230101");
private final Period periodDaily = PeriodType.getPeriodFromIsoString("20230101");

private static final Period periodMonthly = PeriodType.getPeriodFromIsoString("202201");
private final Period periodMonthly = PeriodType.getPeriodFromIsoString("202201");

private static final Period periodQuarterly = PeriodType.getPeriodFromIsoString("2022Q1");
private final Period periodQuarterly = PeriodType.getPeriodFromIsoString("2022Q1");

private static final Date dateA = new GregorianCalendar(2022, JANUARY, 1).getTime();
private final Date dateA = new GregorianCalendar(2022, JANUARY, 1).getTime();

private static final Date dateB = new GregorianCalendar(2023, JANUARY, 1).getTime();
private final Date dateB = new GregorianCalendar(2023, JANUARY, 1).getTime();

private static final DimensionalItemObject ouA = createOrganisationUnit('A');
private final DimensionalItemObject ouA = createOrganisationUnit('A');

private static final DimensionalObject ouGroupSetA =
private final DimensionalObject ouGroupSetA =
new BaseDimensionalObject(
"OrgUnitGrSe", DimensionType.ORGANISATION_UNIT_GROUP_SET, emptyList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@
* @author Dusan Bernat
*/
class QueryItemHelperTest extends TestBase {
private String UID_A = CodeGenerator.generateUid();
private final String UID_A = CodeGenerator.generateUid();

private String UID_B = CodeGenerator.generateUid();
private final String UID_B = CodeGenerator.generateUid();

private String OPTION_NAME_A = "OptionA";
private final String OPTION_NAME_A = "OptionA";

private String OPTION_NAME_B = "OptionB";
private final String OPTION_NAME_B = "OptionB";

private String LEGEND_NAME_A = "LegendA";
private final String LEGEND_NAME_A = "LegendA";

private String LEGEND_NAME_B = "LegendB";
private final String LEGEND_NAME_B = "LegendB";

private String LEGEND_CODE_A = "LegendCodeA";
private final String LEGEND_CODE_A = "LegendCodeA";

private String LEGEND_CODE_B = "LegendCodeB";
private final String LEGEND_CODE_B = "LegendCodeB";

@Test
void testGeItemOptionValueWithIdSchemeNAME() {
Expand Down
Loading

0 comments on commit 2738f17

Please sign in to comment.