|
4 | 4 | import org.jetbrains.annotations.NotNull; |
5 | 5 | import org.jetbrains.annotations.Nullable; |
6 | 6 | import org.json.JSONException; |
| 7 | +import org.labkey.api.collections.CaseInsensitiveHashMap; |
7 | 8 | import org.labkey.remoteapi.CommandException; |
8 | 9 | import org.labkey.remoteapi.Connection; |
9 | 10 | import org.labkey.remoteapi.query.ContainerFilter; |
|
29 | 30 | import java.util.Map; |
30 | 31 | import java.util.Objects; |
31 | 32 | import java.util.Set; |
32 | | -import java.util.stream.Stream; |
33 | 33 |
|
34 | 34 | import static java.lang.Integer.parseInt; |
35 | 35 | import static org.junit.Assert.assertEquals; |
| 36 | +import static org.junit.Assert.assertFalse; |
36 | 37 | import static org.junit.Assert.assertTrue; |
37 | 38 | import static org.junit.Assert.fail; |
38 | 39 | import static org.labkey.test.WebDriverWrapper.WAIT_FOR_JAVASCRIPT; |
@@ -85,16 +86,19 @@ public enum AuditBehaviorType |
85 | 86 |
|
86 | 87 | public enum AuditEvent |
87 | 88 | { |
88 | | - SAMPLE_TIMELINE_EVENT("SampleTimelineEvent"), |
89 | | - SOURCES_AUDIT_EVENT("SourcesAuditEvent"), // avaialble with SampleManagement module |
| 89 | + ASSAY_AUDIT_EVENT("AssayAuditEvent"), // available with SampleManagement module |
| 90 | + ASSAY_RESULT_AUDIT_EVENT("AssayResultAuditEvent"), // available with SampleManagement module |
| 91 | + EXPERIMENT_AUDIT_EVENT("ExperimentAuditEvent"), |
| 92 | + FILE_SYSTEM_EVENT("FileSystem"), |
90 | 93 | INVENTORY_AUDIT_EVENT("InventoryAuditEvent"), |
91 | 94 | LIST_AUDIT_EVENT("ListAuditEvent"), |
92 | | - ASSAY_AUDIT_EVENT("AssayAuditEvent"), // avaialble with SampleManagement module |
93 | | - ASSAY_RESULT_AUDIT_EVENT("AssayResultAuditEvent"), // avaialble with SampleManagement module |
94 | | - EXPERIMENT_AUDIT_EVENT("ExperimentAuditEvent"), |
95 | | - SAMPLE_WORKFLOW_AUDIT_EVENT("SamplesWorkflowAuditEvent"), |
| 95 | + PLATE_AUDIT_EVENT("PlateEvent"), // available in Biologics module |
| 96 | + PLATE_DATA_AUDIT_EVENT("PlateDataAuditEvent"), // available in Biologics module |
| 97 | + PLATE_SET_AUDIT_EVENT("PlateSetEvent"), // available in Biologics module |
96 | 98 | QUERY_UPDATE_AUDIT_EVENT("QueryUpdateAuditEvent"), |
97 | | - FILE_SYSTEM_EVENT("FileSystem"); |
| 99 | + SAMPLE_TIMELINE_EVENT("SampleTimelineEvent"), |
| 100 | + SAMPLE_WORKFLOW_AUDIT_EVENT("SamplesWorkflowAuditEvent"), |
| 101 | + SOURCES_AUDIT_EVENT("SourcesAuditEvent"); // available with SampleManagement module |
98 | 102 |
|
99 | 103 | private final String _name; |
100 | 104 |
|
@@ -257,16 +261,16 @@ public void checkAuditEventDiffCount(String containerPath, AuditEvent auditEvent |
257 | 261 | boolean isInventoryUpdateType = event.get("InventoryUpdateType") != null; |
258 | 262 | int expectedDiffCount = isInventoryUpdateType ? 0 : expectedDiffCounts.get(i); |
259 | 263 | String dataChangesStr = (String) event.get(eventDiffFieldName); |
260 | | - String[] dataChanges = dataChangesStr != null ? dataChangesStr.split("&") : new String[0]; |
| 264 | + Map<String, String> dataChanges = decodeValues(dataChangesStr); |
261 | 265 |
|
262 | 266 | // filter out SampleStateLabel as that is not a change, it is added for display purposes |
263 | | - dataChanges = Stream.of(dataChanges).filter(s -> !s.toLowerCase().startsWith("samplestatelabel=")).toArray(String[]::new); |
| 267 | + dataChanges.remove("SampleStateLabel"); |
264 | 268 | // filter out RowId as that is not a change, it is added for display purposes |
265 | | - dataChanges = Stream.of(dataChanges).filter(s -> !s.toLowerCase().startsWith("rowid=")).toArray(String[]::new); |
| 269 | + dataChanges.remove("RowId"); |
266 | 270 |
|
267 | 271 | log("Audit record data changes diff count check (" + eventDiffFieldName + "): " + dataChangesStr); |
268 | | - assertEquals("Audit record data changes did not include the expected number of diffs in " + eventDiffFieldName + ", expected " + expectedDiffCount + " but was " + dataChanges.length + ": " + dataChangesStr, |
269 | | - expectedDiffCount, dataChanges.length); |
| 272 | + assertEquals("Audit record data changes did not include the expected number of diffs in " + eventDiffFieldName + ", expected " + expectedDiffCount + " but was " + dataChanges.size() + ": " + dataChangesStr, |
| 273 | + expectedDiffCount, dataChanges.size()); |
270 | 274 | } |
271 | 275 | } |
272 | 276 |
|
@@ -527,6 +531,24 @@ public String getLogString() |
527 | 531 | } |
528 | 532 | } |
529 | 533 |
|
| 534 | + public static Map<String, String> decodeValues(String recordMapString) |
| 535 | + { |
| 536 | + if (recordMapString == null || recordMapString.isEmpty()) |
| 537 | + return Collections.emptyMap(); |
| 538 | + |
| 539 | + Map<String, String> recordMap = new CaseInsensitiveHashMap<>(); |
| 540 | + for (String part : recordMapString.split("&")) |
| 541 | + { |
| 542 | + String[] keyValue = part.split("="); |
| 543 | + String key = EscapeUtil.decode(keyValue[0]); |
| 544 | + assertFalse(String.format("Audit record map already contains key for %s", key), recordMap.containsKey(key)); |
| 545 | + |
| 546 | + recordMap.put(key, keyValue.length > 1 ? EscapeUtil.decode(keyValue[1]) : null); |
| 547 | + } |
| 548 | + |
| 549 | + return recordMap; |
| 550 | + } |
| 551 | + |
530 | 552 | /** |
531 | 553 | * URL-encode fields and values for {@link DetailedAuditEventRow#newValues} or {@link DetailedAuditEventRow#oldValues} |
532 | 554 | * @param pairs alternating field names and their associated values |
|
0 commit comments