@@ -95,40 +95,68 @@ public DataRegionTable goToAuditEventView(String eventType)
9595 * @param auditEventName Name of the audit event to filter on. Example 'SamplesWorkflowAuditEvent'.
9696 * @param columnNames The name of the columns to return.
9797 * @param filters The filters to be applied
98+ * @param maxRows The maximum number of rows to return. If null, all rows for the provided filters will be returned.
99+ * @param containerFilter The container filter to be applied. If null, default is ContainerFilter.Current.
98100 * @return A rowResponse with the query logs.
99101 * @throws IOException Can be thrown by the SelectRowsCommand.
100102 * @throws CommandException Can be thrown by the SelectRowsCommand.
101103 */
102104 public SelectRowsResponse getAuditLogsFromLKS (String containerPath , String auditEventName , List <String > columnNames ,
103- List <Filter > filters , @ Nullable Integer maxRows ) throws IOException , CommandException
105+ List <Filter > filters , @ Nullable Integer maxRows , @ Nullable ContainerFilter containerFilter ) throws IOException , CommandException
104106 {
105107 SelectRowsCommand cmd = new SelectRowsCommand ("auditLog" , auditEventName );
106108 cmd .setColumns (columnNames );
107109 cmd .addFilter ("ProjectId/Name" , _wrapper .getCurrentProject (), Filter .Operator .EQUAL );
108110 filters .forEach (cmd ::addFilter );
109111 if (maxRows != null )
110112 cmd .setMaxRows (maxRows );
113+ if (containerFilter != null )
114+ cmd .setContainerFilter (containerFilter );
111115 return cmd .execute (_connectionSupplier .get (), containerPath );
112116 }
113117
118+ public List <Map <String , Object >> getAuditLogsForTransactionId (String containerPath , String auditEventName , List <String > columnNames ,
119+ Integer transactionId , @ Nullable ContainerFilter containerFilter ) throws IOException , CommandException
120+ {
121+ List <Filter > transactionFilter = List .of (new Filter ("TransactionId" , transactionId , Filter .Operator .EQUAL ));
122+ return getAuditLogsFromLKS (containerPath , auditEventName , columnNames , transactionFilter , null , containerFilter ).getRows ();
123+ }
124+
125+ public void checkAuditEventValuesForTransactionId (String containerPath , String auditEventName , Integer transactionId , int rowCount , Map <String , Object > expectedValues ) throws IOException , CommandException
126+ {
127+ List <String > columnNames = expectedValues .keySet ().stream ().map (Object ::toString ).toList ();
128+ List <Map <String , Object >> events = getAuditLogsForTransactionId (containerPath , auditEventName , columnNames , transactionId , ContainerFilter .CurrentAndSubfolders );
129+ assertEquals ("Unexpected number of events for transactionId " + transactionId , rowCount , events .size ());
130+ for (Map <String , Object > event : events )
131+ {
132+ for (String key : columnNames )
133+ assertEquals ("Event value for " + key + " not as expected" , expectedValues .get (key ), event .get (key ));
134+ }
135+ }
136+
114137 /**
115138 * Check the number of diffs in the audit event. This is a helper function to check the number of diffs in the
116139 * newRecordMap for an audit entry. If a transactionId is provided, it will check all rows for that
117140 * transactionId. If no transactionId is provided, it will check just the latest row.
118141 */
119142 public void checkTimelineAuditEventDiffCount (String containerPath , List <Integer > expectedDiffCounts ) throws IOException , CommandException
120143 {
121- checkTimelineAuditEventDiffCount (containerPath , getAuditEventNameFromURL (), expectedDiffCounts );
144+ checkAuditEventDiffCount (containerPath , getAuditEventNameFromURL (), expectedDiffCounts );
145+ }
146+ public void checkAuditEventDiffCount (String containerPath , String auditEventName , List <Integer > expectedDiffCounts ) throws IOException , CommandException
147+ {
148+ checkAuditEventDiffCount (containerPath , auditEventName , Collections .emptyList (), expectedDiffCounts );
122149 }
123- public void checkTimelineAuditEventDiffCount (String containerPath , String auditEventName , List <Integer > expectedDiffCounts ) throws IOException , CommandException
150+ public void checkAuditEventDiffCount (String containerPath , String auditEventName , List < Filter > filters , List <Integer > expectedDiffCounts ) throws IOException , CommandException
124151 {
125152 Integer maxRows = expectedDiffCounts .size ();
126- List <Map <String , Object >> events = getAuditLogsFromLKS (containerPath , auditEventName , List .of ("NewRecordMap" ), Collections . emptyList () , maxRows ).getRows ();
153+ List <Map <String , Object >> events = getAuditLogsFromLKS (containerPath , auditEventName , List .of ("InventoryUpdateType" , " NewRecordMap" ), filters , maxRows , ContainerFilter . CurrentAndSubfolders ).getRows ();
127154 assertEquals ("Unexpected number of events" , expectedDiffCounts .size (), events .size ());
128155 for (int i = 0 ; i < expectedDiffCounts .size (); i ++)
129156 {
130- int expectedDiffCount = expectedDiffCounts .get (i );
131157 Map <String , Object > event = events .get (i );
158+ boolean isInventoryUpdateType = event .get ("InventoryUpdateType" ) != null ;
159+ int expectedDiffCount = isInventoryUpdateType ? 0 : expectedDiffCounts .get (i );
132160 String dataChangesStr = (String ) event .get ("NewRecordMap" );
133161 String [] dataChanges = dataChangesStr != null ? dataChangesStr .split ("&" ) : new String [0 ];
134162
@@ -143,20 +171,28 @@ public void checkTimelineAuditEventDiffCount(String containerPath, String auditE
143171 }
144172 }
145173
174+ public Integer getLastTransactionId (String containerPath , String auditEventName ) throws IOException , CommandException
175+ {
176+ List <Map <String , Object >> events = getAuditLogsFromLKS (containerPath , auditEventName , List .of ("TransactionId" ), Collections .emptyList (), 1 , ContainerFilter .CurrentAndSubfolders ).getRows ();
177+ return events .size () == 1 ? (Integer ) events .get (0 ).get ("TransactionId" ) : null ;
178+ }
179+
146180 /**
147- * Check for th expected number of diffs in the audit event for the last transactionId.
181+ * Check for the expected number of diffs in the audit event for the last transactionId.
148182 * If an expectedEventCount is also provided, it will check that the number of events for that transactionId matches the expectedEventCount.
183+ * @return transactionId
149184 */
150- public void checkTimelineAuditEventDiffCountForLastTransaction (String containerPath , String auditEventName , int expectedDiffCount , @ Nullable Integer expectedEventCount ) throws IOException , CommandException
185+ public Integer checkAuditEventDiffCountForLastTransaction (String containerPath , String auditEventName , int expectedDiffCount ,
186+ @ Nullable Integer expectedEventCount ) throws IOException , CommandException
151187 {
152- Integer transactionId = (Integer ) getAuditLogsFromLKS (containerPath , auditEventName , List .of ("TransactionId" ), Collections .emptyList (), 1 )
153- .getRows ().get (0 ).get ("TransactionId" );
188+ Integer transactionId = getLastTransactionId (containerPath , auditEventName );
154189 List <Filter > transactionFilter = List .of (new Filter ("TransactionId" , transactionId , Filter .Operator .EQUAL ));
155- int eventCount = getAuditLogsFromLKS (containerPath , auditEventName , List .of ("NewRecordMap" ), transactionFilter , null ).getRows ().size ();
190+ int eventCount = getAuditLogsFromLKS (containerPath , auditEventName , List .of ("NewRecordMap" ), transactionFilter , null , ContainerFilter . CurrentAndSubfolders ).getRows ().size ();
156191 if (expectedEventCount != null )
157192 assertEquals ("Unexpected number of events for transactionId " + transactionId , expectedEventCount .intValue (), eventCount );
158193 List <Integer > expectedChangeCounts = Collections .nCopies (eventCount , expectedDiffCount );
159- checkTimelineAuditEventDiffCount (containerPath , auditEventName , expectedChangeCounts );
194+ checkAuditEventDiffCount (containerPath , auditEventName , transactionFilter , expectedChangeCounts );
195+ return transactionId ;
160196 }
161197
162198 public String getAuditEventNameFromURL ()
0 commit comments