use of org.hisp.dhis.common.AuditType.DELETE in project dhis2-core by dhis2.
the class HibernatePotentialDuplicateStore method moveEnrollments.
@Override
public void moveEnrollments(TrackedEntityInstance original, TrackedEntityInstance duplicate, List<String> enrollments) {
List<ProgramInstance> pis = duplicate.getProgramInstances().stream().filter(e -> !e.isDeleted()).filter(e -> enrollments.contains(e.getUid())).collect(Collectors.toList());
pis.forEach(duplicate.getProgramInstances()::remove);
pis.forEach(e -> {
e.setEntityInstance(original);
e.setLastUpdatedBy(currentUserService.getCurrentUser());
e.setLastUpdatedByUserInfo(UserInfoSnapshot.from(currentUserService.getCurrentUser()));
e.setLastUpdated(new Date());
getSession().update(e);
});
// Flush to update records before we delete duplicate, or else it might
// be soft-deleted by hibernate.
getSession().flush();
}
use of org.hisp.dhis.common.AuditType.DELETE in project dhis2-core by dhis2.
the class HibernatePotentialDuplicateStore method moveTrackedEntityAttributeValues.
@Override
public void moveTrackedEntityAttributeValues(TrackedEntityInstance original, TrackedEntityInstance duplicate, List<String> trackedEntityAttributes) {
// Collect existing teav from original for the tea list
Map<String, TrackedEntityAttributeValue> originalAttributeValueMap = new HashMap<>();
original.getTrackedEntityAttributeValues().forEach(oav -> {
if (trackedEntityAttributes.contains(oav.getAttribute().getUid())) {
originalAttributeValueMap.put(oav.getAttribute().getUid(), oav);
}
});
duplicate.getTrackedEntityAttributeValues().stream().filter(av -> trackedEntityAttributes.contains(av.getAttribute().getUid())).forEach(av -> {
TrackedEntityAttributeValue updatedTeav;
org.hisp.dhis.common.AuditType auditType;
if (originalAttributeValueMap.containsKey(av.getAttribute().getUid())) {
// Teav exists in original, overwrite the value
updatedTeav = originalAttributeValueMap.get(av.getAttribute().getUid());
updatedTeav.setValue(av.getValue());
auditType = UPDATE;
} else {
// teav does not exist in original, so create new and attach
// it to original
updatedTeav = new TrackedEntityAttributeValue();
updatedTeav.setAttribute(av.getAttribute());
updatedTeav.setEntityInstance(original);
updatedTeav.setValue(av.getValue());
auditType = CREATE;
}
getSession().delete(av);
// We need to flush to make sure the previous teav is
// deleted.
// Or else we might end up breaking a
// constraint, since hibernate does not respect order.
getSession().flush();
getSession().saveOrUpdate(updatedTeav);
auditTeav(av, updatedTeav, auditType);
});
}
Aggregations