Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/org/labkey/test/util/AuditLogHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.labkey.test.util;

import org.labkey.remoteapi.CommandException;
import org.labkey.remoteapi.Connection;
import org.labkey.remoteapi.query.ContainerFilter;
import org.labkey.remoteapi.query.SelectRowsCommand;
import org.labkey.remoteapi.query.SelectRowsResponse;
Expand All @@ -12,14 +13,22 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public class AuditLogHelper
{
private final LabKeySiteWrapper _wrapper;
private final ConnectionSupplier _connectionSupplier;

public AuditLogHelper(LabKeySiteWrapper wrapper)
public AuditLogHelper(LabKeySiteWrapper wrapper, ConnectionSupplier connectionSupplier)
{
_wrapper = wrapper;
_connectionSupplier = connectionSupplier;
}

public AuditLogHelper(LabKeySiteWrapper wrapper)
{
this(wrapper, wrapper::createDefaultConnection);
}

public Integer getLatestAuditRowId(String auditTable) throws IOException, CommandException
Expand All @@ -32,11 +41,11 @@ public Integer getLatestAuditRowId(String auditTable) throws IOException, Comman
selectRows.setMaxRows(1);
selectRows.setContainerFilter(ContainerFilter.AllFolders);

SelectRowsResponse response = selectRows.execute(_wrapper.createDefaultConnection(), null);
SelectRowsResponse response = selectRows.execute(_connectionSupplier.get(), null);
List<Map<String, Object>> rows = response.getRows();
if (rows.isEmpty())
{
return -1;
return 0;
}
return (Integer) rows.get(0).get(rowId);
}
Expand All @@ -59,4 +68,9 @@ public DataRegionTable goToAuditEventView(String eventType)
}
return new DataRegionTable("query", _wrapper);
}

public interface ConnectionSupplier
{
Connection get() throws IOException, CommandException;
}
}