Skip to content

Commit

Permalink
Merge branch 'master' into DHIS2-18606-di2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee authored Dec 11, 2024
2 parents b624009 + d3f466e commit daa51cc
Show file tree
Hide file tree
Showing 45 changed files with 182 additions and 762 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 @@ -30,10 +30,10 @@
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.audit.AuditOperationType;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.category.CategoryOptionComboStore;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
Expand Down Expand Up @@ -134,29 +134,31 @@ public List<DataValueAudit> getDataValueAudits(
}

// case if the audit trail started out with DELETE
if (dataValueAudits.get(dataValueAudits.size() - 1).getAuditType() == ChangeLogType.DELETE) {
if (dataValueAudits.get(dataValueAudits.size() - 1).getAuditType()
== AuditOperationType.DELETE) {
DataValueAudit valueAudit = createDataValueAudit(dataValue);
valueAudit.setValue(dataValueAudits.get(dataValueAudits.size() - 1).getValue());
dataValueAudits.add(valueAudit);
}

// unless top is CREATE, inject current DV as audit on top
if (!dataValue.isDeleted() && dataValueAudits.get(0).getAuditType() != ChangeLogType.CREATE) {
if (!dataValue.isDeleted()
&& dataValueAudits.get(0).getAuditType() != AuditOperationType.CREATE) {
DataValueAudit dataValueAudit = createDataValueAudit(dataValue);
dataValueAudit.setAuditType(ChangeLogType.UPDATE);
dataValueAudit.setAuditType(AuditOperationType.UPDATE);
dataValueAudit.setCreated(dataValue.getLastUpdated());
dataValueAudits.add(0, dataValueAudit);
}

dataValueAudits.get(dataValueAudits.size() - 1).setAuditType(ChangeLogType.CREATE);
dataValueAudits.get(dataValueAudits.size() - 1).setAuditType(AuditOperationType.CREATE);

return dataValueAudits;
}

private static DataValueAudit createDataValueAudit(DataValue dataValue) {
DataValueAudit dataValueAudit =
new DataValueAudit(
dataValue, dataValue.getValue(), dataValue.getStoredBy(), ChangeLogType.CREATE);
dataValue, dataValue.getValue(), dataValue.getStoredBy(), AuditOperationType.CREATE);
dataValueAudit.setCreated(dataValue.getCreated());

return dataValueAudit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
import javax.annotation.Nonnull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hisp.dhis.audit.AuditOperationType;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.changelog.ChangeLogType;
import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.dataelement.DataElement;
Expand Down Expand Up @@ -143,7 +143,10 @@ public boolean addDataValue(DataValue dataValue) {
if (config.isEnabled(CHANGELOG_AGGREGATE)) {
DataValueAudit dataValueAudit =
new DataValueAudit(
dataValue, dataValue.getValue(), dataValue.getStoredBy(), ChangeLogType.CREATE);
dataValue,
dataValue.getValue(),
dataValue.getStoredBy(),
AuditOperationType.CREATE);

dataValueAuditService.addDataValueAudit(dataValueAudit);
}
Expand All @@ -168,7 +171,7 @@ public void updateDataValue(DataValue dataValue) {
dataValue,
dataValue.getAuditValue(),
dataValue.getStoredBy(),
ChangeLogType.UPDATE);
AuditOperationType.UPDATE);

dataValueAuditService.addDataValueAudit(dataValueAudit);
}
Expand Down Expand Up @@ -196,7 +199,7 @@ public void deleteDataValue(DataValue dataValue) {
dataValue,
dataValue.getAuditValue(),
CurrentUserUtil.getCurrentUsername(),
ChangeLogType.DELETE);
AuditOperationType.DELETE);

dataValueAuditService.addDataValueAudit(dataValueAudit);
}
Expand Down
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 @@ -38,17 +38,14 @@
*/
@Component
@RequiredArgsConstructor
public class TrackedEntityDataValueChangeLogDeletionHandler extends JdbcDeletionHandler {
public class EventChangeLogDeletionHandler extends JdbcDeletionHandler {

@Override
protected void register() {
whenDeleting(DataElement.class, this::deleteDataElement);
}

private void deleteDataElement(DataElement dataElement) {
delete(
"delete from trackedentitydatavalueaudit where dataelementid = :id",
Map.of("id", dataElement.getId()));
delete(
"delete from eventchangelog where dataelementid = :id", Map.of("id", dataElement.getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
package org.hisp.dhis.program.message;

import static org.hisp.dhis.changelog.ChangeLogType.READ;
import static org.hisp.dhis.audit.AuditOperationType.READ;
import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
package org.hisp.dhis.program.message;

import static org.hisp.dhis.changelog.ChangeLogType.READ;
import static org.hisp.dhis.audit.AuditOperationType.READ;
import static org.hisp.dhis.user.CurrentUserUtil.getCurrentUsername;

import java.util.Set;
Expand Down
Loading

0 comments on commit daa51cc

Please sign in to comment.