Skip to content

Commit

Permalink
feat: Remove old TEA change log [DHIS2-18477] (#19388)
Browse files Browse the repository at this point in the history
* feat: Remove old TEA change log [DHIS2-18477]

* feat: Remove unused tests [DHIS2-18477]

* feat: Remove delete old table change log method [DHIS2-18477]

* feat: Remove unused imports [DHIS2-18477]

* feat: Remove incorrect deprecated annotation [DHIS2-18477]

* feat: Move audit services and stores to regular package [DHIS2-18477]
  • Loading branch information
muilpp authored Dec 6, 2024
1 parent f6548f7 commit c274824
Show file tree
Hide file tree
Showing 35 changed files with 302 additions and 1,007 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public boolean pruneData(DataElement dataElement) {
return false;
}

eventChangeLogService.deleteTrackedEntityDataValueChangeLog(dataElement);
eventChangeLogService.deleteEventChangeLog(dataElement);
dataValueAuditService.deleteDataValueAudits(dataElement);
dataValueService.deleteDataValues(dataElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,11 @@ private void setLastUpdatedAsTargetAndRemoveRemaining(
public void handleTrackedEntityDataValueChangelog(
@Nonnull List<DataElement> sources, @Nonnull MergeRequest mergeRequest) {
if (mergeRequest.isDeleteSources()) {
log.info(
"Deleting source tracked entity data value change log records as source DataElements are being deleted");
sources.forEach(eventChangeLogService::deleteTrackedEntityDataValueChangeLog);
log.info("Deleting source event change log records as source DataElements are being deleted");
sources.forEach(eventChangeLogService::deleteEventChangeLog);
} else {
log.info(
"Leaving source tracked entity data value change log records as is, source DataElements are not being deleted");
"Leaving source event change log records as is, source DataElements are not being deleted");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* (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.deprecated.audit;
package org.hisp.dhis.tracker.audit;

import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* (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.deprecated.audit;
package org.hisp.dhis.tracker.audit;

import static org.hisp.dhis.system.util.SqlUtils.singleQuote;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* (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.deprecated.audit;
package org.hisp.dhis.tracker.audit;

import java.util.List;
import org.hisp.dhis.changelog.ChangeLogType;
Expand All @@ -36,7 +36,6 @@
/**
* @author Abyot Asalefew Gizaw [email protected]
*/
@Deprecated(since = "2.42", forRemoval = true)
public interface TrackedEntityAuditService {

String ID = TrackedEntityAuditService.class.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* (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.deprecated.audit;
package org.hisp.dhis.tracker.audit;

import java.util.List;
import org.hisp.dhis.trackedentity.TrackedEntityAudit;
Expand All @@ -34,7 +34,6 @@
/**
* @author Abyot Asalefew Gizaw [email protected]
*/
@Deprecated(since = "2.42", forRemoval = true)
public interface TrackedEntityAuditStore {
String ID = TrackedEntityAuditStore.class.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
package org.hisp.dhis.tracker.deduplication;

import static org.hisp.dhis.changelog.ChangeLogType.CREATE;
import static org.hisp.dhis.changelog.ChangeLogType.DELETE;
import static org.hisp.dhis.changelog.ChangeLogType.UPDATE;
import static org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER;

Expand Down Expand Up @@ -66,8 +65,8 @@
import org.hisp.dhis.security.acl.AclService;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityAttributeValueChangeLog;
import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityAttributeValueChangeLogStore;
import org.hisp.dhis.tracker.export.trackedentity.HibernateTrackedEntityChangeLogStore;
import org.hisp.dhis.tracker.export.trackedentity.TrackedEntityChangeLog;
import org.hisp.dhis.user.CurrentUserUtil;
import org.hisp.dhis.user.User;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -81,7 +80,7 @@ class HibernatePotentialDuplicateStore
extends HibernateIdentifiableObjectStore<PotentialDuplicate> {
private final AuditManager auditManager;

private final TrackedEntityAttributeValueChangeLogStore trackedEntityAttributeValueChangeLogStore;
private final HibernateTrackedEntityChangeLogStore hibernateTrackedEntityChangeLogStore;

private final DhisConfigurationProvider config;

Expand All @@ -91,11 +90,11 @@ public HibernatePotentialDuplicateStore(
ApplicationEventPublisher publisher,
AclService aclService,
AuditManager auditManager,
TrackedEntityAttributeValueChangeLogStore trackedEntityAttributeValueChangeLogStore,
HibernateTrackedEntityChangeLogStore hibernateTrackedEntityChangeLogStore,
DhisConfigurationProvider config) {
super(entityManager, jdbcTemplate, publisher, PotentialDuplicate.class, aclService, false);
this.auditManager = auditManager;
this.trackedEntityAttributeValueChangeLogStore = trackedEntityAttributeValueChangeLogStore;
this.hibernateTrackedEntityChangeLogStore = hibernateTrackedEntityChangeLogStore;
this.config = config;
}

Expand Down Expand Up @@ -202,24 +201,26 @@ public void moveTrackedEntityAttributeValues(
duplicate.getTrackedEntityAttributeValues().stream()
.filter(av -> trackedEntityAttributes.contains(UID.of(av.getAttribute())))
.forEach(
av -> {
dav -> {
String previousValue = null;
TrackedEntityAttributeValue updatedTeav;
ChangeLogType changeLogType;
if (originalAttributeValueMap.containsKey(av.getAttribute().getUid())) {
if (originalAttributeValueMap.containsKey(dav.getAttribute().getUid())) {
// Teav exists in original, overwrite the value
updatedTeav = originalAttributeValueMap.get(av.getAttribute().getUid());
updatedTeav.setValue(av.getValue());
updatedTeav = originalAttributeValueMap.get(dav.getAttribute().getUid());
previousValue = updatedTeav.getPlainValue();
updatedTeav.setValue(dav.getPlainValue());
changeLogType = UPDATE;
} else {
// teav does not exist in original, so create new and attach
// it to original
updatedTeav = new TrackedEntityAttributeValue();
updatedTeav.setAttribute(av.getAttribute());
updatedTeav.setAttribute(dav.getAttribute());
updatedTeav.setTrackedEntity(original);
updatedTeav.setValue(av.getValue());
updatedTeav.setValue(dav.getPlainValue());
changeLogType = CREATE;
}
getSession().delete(av);
getSession().delete(dav);
// We need to flush to make sure the previous teav is
// deleted.
// Or else we might end up breaking a
Expand All @@ -228,27 +229,28 @@ public void moveTrackedEntityAttributeValues(

getSession().saveOrUpdate(updatedTeav);

auditTeav(av, updatedTeav, changeLogType);
addTrackedEntityChangeLog(updatedTeav, previousValue, changeLogType);
});
}

private void auditTeav(
TrackedEntityAttributeValue av,
private void addTrackedEntityChangeLog(
TrackedEntityAttributeValue createOrUpdateTeav,
String previousValue,
ChangeLogType changeLogType) {
String currentUsername = CurrentUserUtil.getCurrentUsername();

TrackedEntityAttributeValueChangeLog deleteTeavAudit =
new TrackedEntityAttributeValueChangeLog(av, av.getAuditValue(), currentUsername, DELETE);
TrackedEntityAttributeValueChangeLog updatedTeavAudit =
new TrackedEntityAttributeValueChangeLog(
createOrUpdateTeav, createOrUpdateTeav.getValue(), currentUsername, changeLogType);
TrackedEntityChangeLog updatedTrackedEntityChangeLog =
new TrackedEntityChangeLog(
createOrUpdateTeav.getTrackedEntity(),
createOrUpdateTeav.getAttribute(),
previousValue,
createOrUpdateTeav.getPlainValue(),
changeLogType,
new Date(),
currentUsername);

if (config.isEnabled(CHANGELOG_TRACKER)) {
trackedEntityAttributeValueChangeLogStore.addTrackedEntityAttributeValueChangeLog(
deleteTeavAudit);
trackedEntityAttributeValueChangeLogStore.addTrackedEntityAttributeValueChangeLog(
updatedTeavAudit);
hibernateTrackedEntityChangeLogStore.addTrackedEntityChangeLog(updatedTrackedEntityChangeLog);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityType;
import org.hisp.dhis.trackedentity.TrackedEntityTypeService;
import org.hisp.dhis.tracker.deprecated.audit.TrackedEntityAuditService;
import org.hisp.dhis.tracker.audit.TrackedEntityAuditService;
import org.hisp.dhis.user.UserDetails;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class DefaultEventChangeLogService implements EventChangeLogService {

private final EventService eventService;
private final HibernateEventChangeLogStore hibernateEventChangeLogStore;
private final HibernateTrackedEntityDataValueChangeLogStore trackedEntityDataValueChangeLogStore;

@Override
@Transactional(readOnly = true)
Expand All @@ -82,7 +81,7 @@ public void deleteEventChangeLog(DataElement dataElement) {

@Override
@Transactional
public void addDataValueChangeLog(
public void addEventChangeLog(
Event event,
DataElement dataElement,
String previousValue,
Expand All @@ -109,18 +108,6 @@ public void addFieldChangeLog(
"geometry", Event::getGeometry, this::formatGeometry, currentEvent, event, username);
}

@Override
@Transactional
public void deleteTrackedEntityDataValueChangeLog(Event event) {
trackedEntityDataValueChangeLogStore.deleteTrackedEntityDataValueChangeLog(event);
}

@Override
@Transactional
public void deleteTrackedEntityDataValueChangeLog(DataElement dataElement) {
trackedEntityDataValueChangeLogStore.deleteTrackedEntityDataValueChangeLog(dataElement);
}

@Override
@Transactional(readOnly = true)
public Set<String> getOrderableFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Page<EventChangeLog> getEventChangeLog(
UID event, EventChangeLogOperationParams operationParams, PageParams pageParams)
throws NotFoundException, ForbiddenException;

void addDataValueChangeLog(
void addEventChangeLog(
Event event,
DataElement dataElement,
String previousValue,
Expand All @@ -61,12 +61,8 @@ void addDataValueChangeLog(
void addFieldChangeLog(
@Nonnull Event currentEvent, @Nonnull Event event, @Nonnull String userName);

void deleteTrackedEntityDataValueChangeLog(Event event);

void deleteEventChangeLog(Event event);

void deleteTrackedEntityDataValueChangeLog(DataElement dataElement);

void deleteEventChangeLog(DataElement dataElement);

/**
Expand Down
Loading

0 comments on commit c274824

Please sign in to comment.