Skip to content

Commit

Permalink
Merge branch 'master' into DHIS2-15066
Browse files Browse the repository at this point in the history
  • Loading branch information
zubaira committed Dec 11, 2024
2 parents cfea998 + 067112f commit 2682751
Show file tree
Hide file tree
Showing 61 changed files with 314 additions and 1,066 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,16 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.tracker.export.trackedentity;

import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
package org.hisp.dhis.audit;

/**
* Encapsulation of a web API request for tracked entity data value audit records.
*
* @author Lars Helge Overland
* @author Halvdan Hoem Grelland
* @author Luca Cambi split Changelog from Audit
*/
@Data
@Accessors(chain = true)
public class TrackedEntityAttributeValueChangeLogQueryParams {
private List<TrackedEntityAttribute> trackedEntityAttributes = new ArrayList<>();

private List<TrackedEntity> trackedEntities = new ArrayList<>();

private List<ChangeLogType> auditTypes = new ArrayList<>();

private Pager pager;

public boolean hasPager() {
return pager != null;
}
public enum AuditOperationType {
CREATE,
UPDATE,
DELETE,
READ,
SEARCH
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2022, University of Oslo
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -27,14 +27,8 @@
*/
package org.hisp.dhis.changelog;

/**
* @author Halvdan Hoem Grelland
* @author Luca Cambi split Changelog from Audit
*/
public enum ChangeLogType {
CREATE,
UPDATE,
DELETE,
READ,
SEARCH
DELETE
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import com.google.common.base.MoreObjects;
import java.util.Date;
import java.util.Objects;
import org.hisp.dhis.audit.AuditOperationType;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class DataValueAudit {

private Date created;

private ChangeLogType auditType;
private AuditOperationType auditType;

// -------------------------------------------------------------------------
// Constructors
Expand All @@ -71,7 +71,7 @@ public class DataValueAudit {
public DataValueAudit() {}

public DataValueAudit(
DataValue dataValue, String value, String modifiedBy, ChangeLogType auditType) {
DataValue dataValue, String value, String modifiedBy, AuditOperationType auditType) {
this.dataElement = dataValue.getDataElement();
this.period = dataValue.getPeriod();
this.organisationUnit = dataValue.getSource();
Expand All @@ -91,7 +91,7 @@ public DataValueAudit(
CategoryOptionCombo attributeOptionCombo,
String value,
String modifiedBy,
ChangeLogType auditType) {
AuditOperationType auditType) {
this.dataElement = dataElement;
this.period = period;
this.organisationUnit = organisationUnit;
Expand Down Expand Up @@ -277,11 +277,11 @@ public void setCreated(Date created) {

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public ChangeLogType getAuditType() {
public AuditOperationType getAuditType() {
return auditType;
}

public void setAuditType(ChangeLogType auditType) {
public void setAuditType(AuditOperationType auditType) {
this.auditType = auditType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hisp.dhis.audit.AuditOperationType;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
Expand All @@ -56,7 +56,7 @@ public class DataValueAuditQueryParams {

private CategoryOptionCombo attributeOptionCombo;

private List<ChangeLogType> auditTypes = new ArrayList<>();
private List<AuditOperationType> auditTypes = new ArrayList<>();

private Pager pager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
package org.hisp.dhis.trackedentity;

import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.audit.AuditOperationType;

/**
* @author Abyot Asalefew Gizaw [email protected]
Expand All @@ -38,5 +38,5 @@ public interface ApiTrackedEntityAuditService {
String ID = ApiTrackedEntityAuditService.class.getName();

void addTrackedEntityAudit(
TrackedEntity trackedEntity, String username, ChangeLogType changeLogType);
TrackedEntity trackedEntity, String username, AuditOperationType auditOperationType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.audit.AuditOperationType;
import org.hisp.dhis.common.DxfNamespaces;

/**
Expand All @@ -55,15 +55,15 @@ public class TrackedEntityAudit implements Serializable {

private String accessedBy;

private ChangeLogType auditType;
private AuditOperationType auditType;

// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------

public TrackedEntityAudit() {}

public TrackedEntityAudit(String trackedEntity, String accessedBy, ChangeLogType auditType) {
public TrackedEntityAudit(String trackedEntity, String accessedBy, AuditOperationType auditType) {
this.trackedEntity = trackedEntity;
this.accessedBy = accessedBy;
this.created = new Date();
Expand All @@ -75,8 +75,8 @@ public TrackedEntityAudit(
String comment,
Date created,
String accessedBy,
ChangeLogType changeLogType) {
this(trackedEntity, accessedBy, changeLogType);
AuditOperationType auditOperationType) {
this(trackedEntity, accessedBy, auditOperationType);
this.comment = comment;
this.created = created;
}
Expand Down Expand Up @@ -159,11 +159,11 @@ public void setAccessedBy(String accessedBy) {

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public ChangeLogType getAuditType() {
public AuditOperationType getAuditType() {
return auditType;
}

public void setAuditType(ChangeLogType auditType) {
public void setAuditType(AuditOperationType auditType) {
this.auditType = auditType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.audit.AuditOperationType;
import org.hisp.dhis.common.Pager;

/**
Expand All @@ -45,7 +45,7 @@ public class TrackedEntityAuditQueryParams {

private List<String> users = new ArrayList<>();

private List<ChangeLogType> auditTypes = new ArrayList<>();
private List<AuditOperationType> auditTypes = new ArrayList<>();

private Date startDate = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void initMergeHandlers() {

auditMergeHandlers =
ImmutableList.<DataElementAuditMergeHandler>builder()
.add(trackerMergeHandler::handleTrackedEntityDataValueChangelog)
.add(trackerMergeHandler::handleEventChangeLogs)
.add(dataDataElementMergeHandler::handleDataValueAuditDataElement)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.hisp.dhis.programrule.ProgramRuleVariableStore;
import org.hisp.dhis.tracker.export.event.EventChangeLog;
import org.hisp.dhis.tracker.export.event.EventChangeLogService;
import org.hisp.dhis.tracker.export.event.TrackedEntityDataValueChangeLog;
import org.springframework.stereotype.Component;

/**
Expand Down Expand Up @@ -275,14 +274,13 @@ private void setLastUpdatedAsTargetAndRemoveRemaining(
}

/**
* Method handling {@link TrackedEntityDataValueChangeLog}s and {@link EventChangeLog}s. Both of
* them will either be deleted or left as is, based on whether the source {@link DataElement}s are
* being deleted or not.
* Method handling {@link EventChangeLog}s. They will either be deleted or left as is, based on
* whether the source {@link DataElement}s are being deleted or not.
*
* @param sources source {@link DataElement}s used to retrieve {@link DataValueAudit}s
* @param mergeRequest merge request
*/
public void handleTrackedEntityDataValueChangelog(
public void handleEventChangeLogs(
@Nonnull List<DataElement> sources, @Nonnull MergeRequest mergeRequest) {
if (mergeRequest.isDeleteSources()) {
log.info("Deleting source event change log records as source DataElements are being deleted");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,38 +340,33 @@ private void populateTable(
StringBuilder sql =
new StringBuilder(replace("insert into ${tableName} (", Map.of("tableName", tableName)));

List<AnalyticsTableColumn> dimensions = partition.getMasterTable().getDimensionColumns();
List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();
List<AnalyticsTableColumn> dimensions = partition.getMasterTable().getDimensionColumns();

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

sql = TextUtils.removeLastComma(sql).append(") select ");

for (AnalyticsTableColumn col : dimensions) {
sql.append(col.getSelectExpression() + ",");
}
sql.append(toCommaSeparated(columns, col -> quote(col.getName())));
sql.append(") select ");
sql.append(toCommaSeparated(dimensions, AnalyticsTableColumn::getSelectExpression));
sql.append(",");

sql.append(
replaceQualify(
"""
${approvalSelectExpression} \
as approvallevel, \
${valueExpression} * ps.daysno as daysxvalue, \
ps.daysno as daysno, \
${valueExpression} as value, \
${textValueExpression} as textvalue \
from ${datavalue} dv \
inner join analytics_rs_periodstructure ps on dv.periodid=ps.periodid \
inner join analytics_rs_dataelementstructure des on dv.dataelementid=des.dataelementid \
inner join analytics_rs_dataelementgroupsetstructure degs on dv.dataelementid=degs.dataelementid \
inner join analytics_rs_orgunitstructure ous on dv.sourceid=ous.organisationunitid \
inner join analytics_rs_organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid \
inner join analytics_rs_categorystructure dcs on dv.categoryoptioncomboid=dcs.categoryoptioncomboid \
inner join analytics_rs_categorystructure acs on dv.attributeoptioncomboid=acs.categoryoptioncomboid \
inner join analytics_rs_categoryoptioncomboname aon on dv.attributeoptioncomboid=aon.categoryoptioncomboid \
inner join analytics_rs_categoryoptioncomboname con on dv.categoryoptioncomboid=con.categoryoptioncomboid\s""",
${approvalSelectExpression} \
as approvallevel, \
${valueExpression} * ps.daysno as daysxvalue, \
ps.daysno as daysno, \
${valueExpression} as value, \
${textValueExpression} as textvalue \
from ${datavalue} dv \
inner join analytics_rs_periodstructure ps on dv.periodid=ps.periodid \
inner join analytics_rs_dataelementstructure des on dv.dataelementid=des.dataelementid \
inner join analytics_rs_dataelementgroupsetstructure degs on dv.dataelementid=degs.dataelementid \
inner join analytics_rs_orgunitstructure ous on dv.sourceid=ous.organisationunitid \
inner join analytics_rs_organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid \
inner join analytics_rs_categorystructure dcs on dv.categoryoptioncomboid=dcs.categoryoptioncomboid \
inner join analytics_rs_categorystructure acs on dv.attributeoptioncomboid=acs.categoryoptioncomboid \
inner join analytics_rs_categoryoptioncomboname aon on dv.attributeoptioncomboid=aon.categoryoptioncomboid \
inner join analytics_rs_categoryoptioncomboname con on dv.categoryoptioncomboid=con.categoryoptioncomboid\s""",
Map.of(
"approvalSelectExpression", approvalSelectExpression,
"valueExpression", valueExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.hisp.dhis.analytics.table.setting.AnalyticsTableSettings;
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataapproval.DataApprovalLevelService;
import org.hisp.dhis.db.sql.SqlBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
Expand Down Expand Up @@ -151,11 +150,11 @@ public boolean hasUpdatedLatestData(Date startDate, Date endDate) {
String sql =
replaceQualify(
"""
select cdr.datasetid \
from ${completedatasetregistration} cdr \
where cdr.lastupdated >= '${startDate}' \
and cdr.lastupdated < '${endDate}' \
limit 1;""",
select cdr.datasetid \
from ${completedatasetregistration} cdr \
where cdr.lastupdated >= '${startDate}' \
and cdr.lastupdated < '${endDate}' \
limit 1;""",
Map.of("startDate", toLongDate(startDate), "endDate", toLongDate(endDate)));

return !jdbcTemplate.queryForList(sql).isEmpty();
Expand Down Expand Up @@ -196,24 +195,14 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti
String tableName = partition.getName();
String partitionClause = getPartitionClause(partition);

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

List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

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

sql = TextUtils.removeLastComma(sql) + ") select ";

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

sql = TextUtils.removeLastComma(sql) + " ";

String sql = "insert into " + tableName + " (";
sql += toCommaSeparated(columns, col -> quote(col.getName()));
sql += ") select ";
sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression);
sql += " ";
// Database legacy fix

sql = sql.replace("organisationunitid", "sourceid");

sql +=
Expand Down
Loading

0 comments on commit 2682751

Please sign in to comment.