use of org.hisp.dhis.audit.AuditType 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);
});
}
use of org.hisp.dhis.audit.AuditType in project dhis2-core by dhis2.
the class AuditMatrixConfigurer method configure.
public Map<AuditScope, Map<AuditType, Boolean>> configure() {
Map<AuditScope, Map<AuditType, Boolean>> matrix = new HashMap<>();
for (AuditScope value : AuditScope.values()) {
Optional<ConfigurationKey> confKey = ConfigurationKey.getByKey(PROPERTY_PREFIX + value.name().toLowerCase());
if (confKey.isPresent() && !StringUtils.isEmpty(config.getProperty(confKey.get()))) {
String[] configuredTypes = config.getProperty(confKey.get()).split(AUDIT_TYPE_STRING_SEPAR);
Map<AuditType, Boolean> matrixAuditTypes = new HashMap<>();
for (AuditType auditType : AuditType.values()) {
matrixAuditTypes.put(auditType, ArrayUtils.contains(configuredTypes, auditType.name()));
}
matrix.put(value, matrixAuditTypes);
} else {
matrix.put(value, DEFAULT_AUDIT_CONFIGURATION);
}
}
return matrix;
}
Aggregations