Skip to content

Commit

Permalink
audit list does not fill in changedItems, useless + the format is wrong
Browse files Browse the repository at this point in the history
We would need to "de-canonicalize" those items so they are properly
formatted item paths - and they can be obtained from deltas anyway.
This fixes the related problems in export/import of audit.
Import will refill the items from deltas again.
  • Loading branch information
virgo47 committed Jan 26, 2022
1 parent ee69f47 commit f8fa0b6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -21,7 +21,6 @@
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.SqaleUtils;
Expand Down Expand Up @@ -144,7 +143,7 @@ public AuditEventRecordType toSchemaObject(MAuditEventRecord row) {
.message(row.message);

mapDeltas(record, row.deltas);
mapChangedItems(record, row.changedItemPaths);
// Changed items are only for searching, we don't want to reconstruct them, they are even "canonicalized".
mapRefValues(record, row.refValues);
mapProperties(record, row.properties);
mapResourceOids(record, row.resourceOids);
Expand All @@ -161,17 +160,6 @@ private void mapDeltas(AuditEventRecordType record, Collection<MAuditDelta> delt
}
}

private void mapChangedItems(AuditEventRecordType record, String[] changedItemPaths) {
if (changedItemPaths == null) {
return;
}

for (String changedItemPath : changedItemPaths) {
ItemPath itemPath = ItemPath.create(changedItemPath);
record.getChangedItem().add(new ItemPathType(itemPath));
}
}

private void mapRefValues(
AuditEventRecordType record, Map<String, List<MAuditRefValue>> refValues) {
if (refValues == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -985,8 +985,10 @@ public void test300SearchReturnsMappedToManyAttributes() throws SchemaException
AuditEventRecordPropertyType prop1 = record1.getProperty().get(0);
assertThat(prop1.getName()).isEqualTo("prop1");
assertThat(prop1.getValue()).containsExactly("val1");
// Changed items are not returned, they are used for query only and can be found in deltas.
// Also, they may be stored in wrong format (e.g. "canonicalized").
assertThat(record1.getChangedItem()).isNullOrEmpty();
// for other attributes we just use the size check, fetch mechanism is similar
assertThat(record1.getChangedItem()).hasSize(4);
assertThat(record1.getDelta()).hasSize(3)
.allMatch(d -> d.getObjectDelta() != null);
assertThat(record1.getReference()).hasSize(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -949,8 +949,10 @@ public void test300SearchReturnsMappedToManyAttributes() throws SchemaException
AuditEventRecordPropertyType prop1 = record1.getProperty().get(0);
assertThat(prop1.getName()).isEqualTo("prop1");
assertThat(prop1.getValue()).containsExactly("val1");
// Changed items are not returned, they are used for query only and can be found in deltas.
// Also, they may be stored in wrong format (e.g. "canonicalized").
assertThat(record1.getChangedItem()).isNullOrEmpty();
// for other attributes we just use the size check, fetch mechanism is similar
assertThat(record1.getChangedItem()).hasSize(4);
assertThat(record1.getDelta()).hasSize(3)
.allMatch(d -> d.getObjectDelta() != null);
assertThat(record1.getReference()).hasSize(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -10,7 +10,6 @@
import static com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord.TABLE_NAME;
import static com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -25,7 +24,6 @@
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta;
import com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord;
Expand All @@ -47,7 +45,6 @@
import com.evolveum.midpoint.xml.ns._public.common.audit_3.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
Expand Down Expand Up @@ -159,7 +156,6 @@ protected QAuditEventRecord newAliasInstance(String alias) {
public AuditEventRecordType toSchemaObject(MAuditEventRecord row) {
AuditEventRecordType record = mapSimpleAttributes(row);
mapDeltas(record, row.deltas);
mapChangedItems(record, row.changedItemPaths);
mapRefValues(record, row.refValues);
mapProperties(record, row.properties);
mapResourceOids(record, row.resourceOids);
Expand Down Expand Up @@ -213,17 +209,6 @@ private void mapDeltas(AuditEventRecordType record, List<MAuditDelta> deltas) {
}
}

private void mapChangedItems(AuditEventRecordType record, Collection<String> changedItemPaths) {
if (changedItemPaths == null) {
return;
}

for (String changedItemPath : changedItemPaths) {
ItemPath itemPath = ItemPath.create(changedItemPath);
record.getChangedItem().add(new ItemPathType(itemPath));
}
}

private void mapRefValues(
AuditEventRecordType record, Map<String, List<MAuditRefValue>> refValues) {
if (refValues == null) {
Expand Down

0 comments on commit f8fa0b6

Please sign in to comment.