Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
5fdf098
fix: Update code
larshelge Nov 25, 2024
12f1f27
fix: Update code
larshelge Nov 25, 2024
6647eac
fix: Update code
larshelge Nov 25, 2024
50825c4
fix: Update code
larshelge Nov 25, 2024
719655c
fix: Update code
larshelge Nov 25, 2024
c5863b1
fix: Update code
larshelge Nov 25, 2024
d2095b9
fix: Update code
larshelge Nov 25, 2024
18b9782
fix: Update code
larshelge Nov 25, 2024
d1520e3
fix: Update code
larshelge Nov 25, 2024
6c0b5a6
fix: Update code
larshelge Nov 25, 2024
7d42bb0
fix: Update code
larshelge Nov 25, 2024
1ebed16
Merge branch 'master' into DHIS2-18417
larshelge Nov 25, 2024
cb3d523
fix: Update code
larshelge Nov 26, 2024
9f369e4
fix: Update code
larshelge Nov 26, 2024
acccd5d
fix: Update code
larshelge Nov 26, 2024
97b6697
fix: Update code
larshelge Nov 26, 2024
7c725c7
fix: Update code
larshelge Nov 26, 2024
e58f104
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
e8e862a
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
490ea09
fix: Update code
larshelge Nov 26, 2024
781d2e4
fix: Update code
larshelge Nov 26, 2024
c1b20d7
fix: Update code
larshelge Nov 26, 2024
c51fb14
fix: Update code
larshelge Nov 26, 2024
a84ff58
fix: Update code
larshelge Nov 26, 2024
e375211
fix: Update code
larshelge Nov 26, 2024
ccbc1e4
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
43ff102
fix: Update code
larshelge Nov 26, 2024
2cab8fc
fix: Update code
larshelge Nov 26, 2024
adc1599
fix: Update code
larshelge Nov 26, 2024
d013060
Merge branch 'master' into DHIS2-18417
larshelge Nov 26, 2024
793b9fa
fix: Update code
larshelge Nov 26, 2024
105b514
fix: Update code
larshelge Nov 26, 2024
45d734e
fix: Update code
larshelge Nov 26, 2024
793a55b
fix: Update code
larshelge Nov 26, 2024
0640b81
fix: Update code
larshelge Nov 26, 2024
f33bd88
fix: Update code
larshelge Nov 26, 2024
3a6b574
fix: Update code
larshelge Nov 26, 2024
7ac31de
fix: Update code
larshelge Nov 26, 2024
cd9c2ed
fix: Update code
larshelge Nov 26, 2024
e4c070d
fix: Update code
larshelge Nov 26, 2024
9cf4321
fix: Update code
larshelge Nov 26, 2024
df69357
fix: Update code
larshelge Nov 26, 2024
007fabb
fix: Update code
larshelge Nov 29, 2024
8af5d48
Revert "fix: Update code"
larshelge Nov 29, 2024
62627f0
Merge branch 'master' into DHIS2-18417
larshelge Nov 29, 2024
b3b0391
Merge branch 'master' into DHIS2-18417
larshelge Nov 29, 2024
77f814b
Merge branch 'master' into DHIS2-18417
larshelge Nov 30, 2024
4038b0d
fix: Update code
larshelge Nov 30, 2024
b48b83c
fix: Update code
larshelge Dec 1, 2024
f9ed2a3
fix: Update code
larshelge Dec 1, 2024
9a3afb8
fix: Update code
larshelge Dec 1, 2024
92be248
fix: Update code
larshelge Dec 1, 2024
8186edc
fix: Update code
larshelge Dec 1, 2024
31524ca
fix: Update code
larshelge Dec 1, 2024
04965f3
Merge branch 'master' into DHIS2-18417
larshelge Dec 2, 2024
4742e3b
fix: Update code
larshelge Dec 2, 2024
4259834
fix: Update code
larshelge Dec 2, 2024
25f4feb
fix: Update code
larshelge Dec 2, 2024
df215ec
fix: Update code
larshelge Dec 2, 2024
83b4758
fix: Update code
larshelge Dec 2, 2024
7a481d6
fix: Update code
larshelge Dec 2, 2024
bca8df5
fix: Update code
larshelge Dec 2, 2024
fdc5578
fix: Update code
larshelge Dec 2, 2024
13fbc75
fix: Update code
larshelge Dec 3, 2024
50da70c
Merge branch 'master' into DHIS2-18417
larshelge Dec 3, 2024
6633861
Revert "feat: skipAnalytics and ConfidentialFlag only for QUERY Analy…
larshelge Dec 4, 2024
693ac89
fix: Update code
larshelge Dec 4, 2024
b1e7bb3
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
7b310eb
fix: Update code
larshelge Dec 4, 2024
be271e6
fix: Update code
larshelge Dec 4, 2024
e178384
fix: Update code
larshelge Dec 4, 2024
d3c1957
fix: Update code
larshelge Dec 4, 2024
55d8a84
fix: Update code
larshelge Dec 4, 2024
86ef201
fix: Update code
larshelge Dec 4, 2024
f4e7684
fix: Update code
larshelge Dec 4, 2024
a032072
fix: Update code
larshelge Dec 4, 2024
87a0fd3
fix: Update code
larshelge Dec 4, 2024
c93f4ff
fix: Update code
larshelge Dec 4, 2024
8d9b40f
fix: Update code
larshelge Dec 4, 2024
00536ff
fix: Update code
larshelge Dec 4, 2024
15cb92a
fix: Update code
larshelge Dec 4, 2024
85c2c92
fix: Update code
larshelge Dec 4, 2024
cd2cb15
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
bec3c7e
fix: Update code
larshelge Dec 4, 2024
f66b2be
fix: Update code
larshelge Dec 4, 2024
7b92571
fix: Update code
larshelge Dec 4, 2024
b400d6b
fix: Update code
larshelge Dec 4, 2024
f55b900
fix: Update code
larshelge Dec 4, 2024
fb8c59f
fix: Update code
larshelge Dec 4, 2024
b4f34ba
fix: Update code
larshelge Dec 4, 2024
50d99c6
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
ddb1161
fix: Update code
larshelge Dec 4, 2024
251e246
fix: Update code
larshelge Dec 4, 2024
d6c9f0e
fix: Update code
larshelge Dec 4, 2024
4bd41ca
fix: Update code
larshelge Dec 4, 2024
427ffbb
fix: Update code
larshelge Dec 4, 2024
b0f0751
fix: Update code
larshelge Dec 4, 2024
cce6d85
fix: Update code
larshelge Dec 4, 2024
63484bd
fix: Update code
larshelge Dec 4, 2024
c083771
Merge branch 'master' into DHIS2-18417
larshelge Dec 4, 2024
1064844
fix: Update code
larshelge Dec 4, 2024
67ef7db
fix: Update code
larshelge Dec 4, 2024
a4084c5
fix: Update code
larshelge Dec 4, 2024
1ed29a4
fix: Update code
larshelge Dec 4, 2024
ee94d65
fix: Update code
larshelge Dec 4, 2024
7918f3f
fix: Update code
larshelge Dec 4, 2024
000cc5d
fix: Update code
larshelge Dec 4, 2024
8caf620
fix: Update code
larshelge Dec 4, 2024
aeca0bd
fix: Update code
larshelge Dec 4, 2024
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 @@ -49,7 +49,6 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.model.DataType;
import org.hisp.dhis.db.model.IndexType;
Expand Down Expand Up @@ -171,19 +170,13 @@ protected void populateTableInternal(AnalyticsTablePartition partition, String f

String sql = "insert into " + tableName + " (";

for (AnalyticsTableColumn col : columns) {
sql += quote(col.getName()) + ",";
}

sql = TextUtils.removeLastComma(sql) + ") select ";
sql += toCommaSeparated(columns, col -> quote(col.getName()));

for (AnalyticsTableColumn col : columns) {
sql += col.getSelectExpression() + ",";
}
sql += ") select ";

sql = TextUtils.removeLastComma(sql) + " ";
sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression);

sql += fromClause;
sql += " " + fromClause;

invokeTimeAndLog(sql, "Populating table: '{}'", tableName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -672,6 +673,19 @@ protected boolean tableIsNotEmpty(String name) {
return jdbcTemplate.queryForRowSet(sql).next();
}

/**
* Converts the given list of items to a comma-separated string, using the given mapping function
* to map the object to string.
*
* @param <T> the type.
* @param list the list.
* @param mapper the mapping function.
* @return a comma-separated string.
*/
protected <T> String toCommaSeparated(List<T> list, Function<T, String> mapper) {
return list.stream().map(mapper).collect(Collectors.joining(","));
}

/**
* Quotes the given relation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.hisp.dhis.analytics.AnalyticsAggregationType;
import org.hisp.dhis.analytics.EventOutputType;
import org.hisp.dhis.analytics.analyze.ExecutionPlanStore;
import org.hisp.dhis.analytics.common.ProgramIndicatorSubqueryBuilder;
import org.hisp.dhis.analytics.event.EventQueryParams;
import org.hisp.dhis.analytics.event.EventQueryParams.Builder;
import org.hisp.dhis.analytics.event.data.programindicator.DefaultProgramIndicatorSubqueryBuilder;
Expand Down Expand Up @@ -107,7 +108,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
Expand All @@ -126,11 +129,23 @@ class AbstractJdbcEventAnalyticsManagerTest extends EventAnalyticsTest {

@Mock private OrganisationUnitService organisationUnitService;

private final SqlBuilder sqlBuilder = new PostgreSqlBuilder();
@Spy
private ProgramIndicatorSubqueryBuilder programIndicatorSubqueryBuilder =
new DefaultProgramIndicatorSubqueryBuilder(programIndicatorService);

private JdbcEventAnalyticsManager eventSubject;
@Spy private SqlBuilder sqlBuilder = new PostgreSqlBuilder();

private JdbcEnrollmentAnalyticsManager enrollmentSubject;
@Spy
private EventTimeFieldSqlRenderer eventTimeFieldSqlRenderer =
new EventTimeFieldSqlRenderer(sqlBuilder);

@Spy
private EnrollmentTimeFieldSqlRenderer enrollmentTimeFieldSqlRenderer =
new EnrollmentTimeFieldSqlRenderer(sqlBuilder);

@InjectMocks private JdbcEventAnalyticsManager eventSubject;

@InjectMocks private JdbcEnrollmentAnalyticsManager enrollmentSubject;

private Program programA;

Expand All @@ -146,29 +161,7 @@ class AbstractJdbcEventAnalyticsManagerTest extends EventAnalyticsTest {

@BeforeEach
public void setUp() {
DefaultProgramIndicatorSubqueryBuilder programIndicatorSubqueryBuilder =
new DefaultProgramIndicatorSubqueryBuilder(programIndicatorService);

eventSubject =
new JdbcEventAnalyticsManager(
jdbcTemplate,
programIndicatorService,
programIndicatorSubqueryBuilder,
new EventTimeFieldSqlRenderer(sqlBuilder),
executionPlanStore,
sqlBuilder);

enrollmentSubject =
new JdbcEnrollmentAnalyticsManager(
jdbcTemplate,
programIndicatorService,
programIndicatorSubqueryBuilder,
new EnrollmentTimeFieldSqlRenderer(sqlBuilder),
executionPlanStore,
sqlBuilder);

programA = createProgram('A');

dataElementA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM);
dataElementA.setUid("fWIAEtYVEGk");
}
Expand Down Expand Up @@ -241,8 +234,6 @@ void verifyGetCoordinateColumn() {
+ colName
+ ")::numeric, 6) || ']' as "
+ colName));

return;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
*/
package org.hisp.dhis.analytics.event.data;

import static org.hisp.dhis.analytics.common.AnalyticsDimensionsTestSupport.allValueTypeDataElements;
import static org.hisp.dhis.analytics.common.AnalyticsDimensionsTestSupport.allValueTypeTEAs;
import static org.hisp.dhis.analytics.common.DimensionServiceCommonTest.aggregateAllowedValueTypesPredicate;
import static org.hisp.dhis.analytics.common.DimensionServiceCommonTest.queryDisallowedValueTypesPredicate;
import static org.hisp.dhis.test.TestBase.injectSecurityContextNoSettings;
Expand All @@ -37,38 +35,35 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.List;
import org.hisp.dhis.analytics.event.EnrollmentAnalyticsDimensionsService;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.PrefixedDimension;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.security.acl.AclService;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.user.SystemUser;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class EnrollmentAnalyticsDimensionsServiceTest {
private EnrollmentAnalyticsDimensionsService enrollmentAnalyticsDimensionsService;
@Mock private ProgramService programService;

@InjectMocks
private DefaultEnrollmentAnalyticsDimensionsService enrollmentAnalyticsDimensionsService;

@BeforeEach
void setup() {
injectSecurityContextNoSettings(new SystemUser());

ProgramService programService = mock(ProgramService.class);

Program program = mock(Program.class);

when(programService.getProgram(any())).thenReturn(program);
when(program.getDataElements()).thenReturn(allValueTypeDataElements());
when(program.getProgramIndicators()).thenReturn(Collections.emptySet());
when(program.getTrackedEntityAttributes()).thenReturn(allValueTypeTEAs());

enrollmentAnalyticsDimensionsService =
new DefaultEnrollmentAnalyticsDimensionsService(programService, mock(AclService.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
Expand All @@ -108,7 +109,11 @@ class EnrollmentAnalyticsManagerTest extends EventAnalyticsTest {

@Mock private ProgramIndicatorService programIndicatorService;

private final SqlBuilder sqlBuilder = new PostgreSqlBuilder();
@Spy private SqlBuilder sqlBuilder = new PostgreSqlBuilder();

@Spy
private EnrollmentTimeFieldSqlRenderer enrollmentTimeFieldSqlRenderer =
new EnrollmentTimeFieldSqlRenderer(sqlBuilder);

@Captor private ArgumentCaptor<String> sql;

Expand All @@ -133,7 +138,7 @@ public void setUp() {
jdbcTemplate,
programIndicatorService,
programIndicatorSubqueryBuilder,
new EnrollmentTimeFieldSqlRenderer(sqlBuilder),
enrollmentTimeFieldSqlRenderer,
executionPlanStore,
sqlBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CHILDREN;
import static org.hisp.dhis.common.OrganisationUnitSelectionMode.SELECTED;
import static org.hisp.dhis.period.RelativePeriodEnum.LAST_3_DAYS;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.Set;
Expand All @@ -52,7 +52,6 @@ class EnrollmentQueryHelperTest {

@Test
void testGetHeaderColumnsSamePrefixedDimension() {
// Given
List<GridHeader> headers =
List.of(
new GridHeader("name0"),
Expand All @@ -64,10 +63,8 @@ void testGetHeaderColumnsSamePrefixedDimension() {

String sql = "select name0, name1, dim.name2, pe, value, ou from table";

// When
Set<String> headerColumns = EnrollmentQueryHelper.getHeaderColumns(headers, sql);

// Then
String[] columns = headerColumns.toArray(String[]::new);
assertEquals(3, columns.length);
assertEquals("t1.\"name0\"", columns[0]);
Expand All @@ -77,7 +74,6 @@ void testGetHeaderColumnsSamePrefixedDimension() {

@Test
void testGetHeaderColumnsDifferentPrefixedDimension() {
// Given
List<GridHeader> headers =
List.of(
new GridHeader("name0"),
Expand All @@ -89,10 +85,8 @@ void testGetHeaderColumnsDifferentPrefixedDimension() {

String sql = "select name0, name1, ax.name2, pe, value, ou from table";

// When
Set<String> headerColumns = EnrollmentQueryHelper.getHeaderColumns(headers, sql);

// Then
String[] columns = headerColumns.toArray(String[]::new);
assertEquals(3, columns.length);
assertEquals("t1.\"name0\"", columns[0]);
Expand All @@ -102,7 +96,6 @@ void testGetHeaderColumnsDifferentPrefixedDimension() {

@Test
void testGetOrgUnitLevelColumnsOuMode() {
// Given
OrganisationUnit organisationUnit = new OrganisationUnit("OrgTest");
organisationUnit.setPath("/Level1/OrgTest");

Expand All @@ -114,18 +107,15 @@ void testGetOrgUnitLevelColumnsOuMode() {
ORGUNIT_DIM_ID, ORGANISATION_UNIT, List.of(organisationUnit)))
.build();

// When
Set<String> orgUnitColumns = EnrollmentQueryHelper.getOrgUnitLevelColumns(params);

// Then
String[] columns = orgUnitColumns.toArray(String[]::new);
assertEquals(1, columns.length);
assertEquals("uidlevel2", columns[0]);
}

@Test
void testGetOrgUnitLevelColumnsOuModeSelected() {
// Given
OrganisationUnit organisationUnit = new OrganisationUnit("/Level1/Level2");

EventQueryParams params =
Expand All @@ -136,16 +126,13 @@ void testGetOrgUnitLevelColumnsOuModeSelected() {
ORGUNIT_DIM_ID, ORGANISATION_UNIT, List.of(organisationUnit)))
.build();

// When
Set<String> orgUnitColumns = EnrollmentQueryHelper.getOrgUnitLevelColumns(params);

// Then
assertEquals(0, orgUnitColumns.size());
}

@Test
void testGetOrgUnitLevelColumnsOuModeChildren() {
// Given
OrganisationUnit organisationUnit = new OrganisationUnit("/Level1/Level2");

EventQueryParams params =
Expand All @@ -156,16 +143,13 @@ void testGetOrgUnitLevelColumnsOuModeChildren() {
ORGUNIT_DIM_ID, ORGANISATION_UNIT, List.of(organisationUnit)))
.build();

// When
Set<String> orgUnitColumns = EnrollmentQueryHelper.getOrgUnitLevelColumns(params);

// Then
assertEquals(0, orgUnitColumns.size());
}

@Test
void testGetPeriodColumns() {
// Given
Period period = new Period(LAST_3_DAYS);
period.setPeriodType(PeriodType.getPeriodTypeFromIsoString("201101"));

Expand All @@ -174,27 +158,22 @@ void testGetPeriodColumns() {
.addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, PERIOD, List.of(period)))
.build();

// When
Set<String> periodColumns = EnrollmentQueryHelper.getPeriodColumns(params);

// Then
String[] columns = periodColumns.toArray(String[]::new);
assertEquals(1, columns.length);
assertEquals("t1.Monthly", columns[0]);
}

@Test
void testGetPeriodColumnsNoPeriods() {
// Given
EventQueryParams params =
new EventQueryParams.Builder()
.addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, ORGANISATION_UNIT, List.of()))
.build();

// When
Set<String> periodColumns = EnrollmentQueryHelper.getPeriodColumns(params);

// Then
assertEquals(0, periodColumns.size());
}
}
Loading
Loading