Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions audit/src/org/labkey/audit/AuditLogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

public class AuditLogImpl implements AuditLogService, StartupListener
{
Expand Down Expand Up @@ -248,7 +249,7 @@ public ActionURL getAuditUrl()
return new ActionURL(AuditController.ShowAuditLogAction.class, ContainerManager.getRoot());
}

public record TransactionRowIds(List<Long> rowIds, Map<Long, Long> dataTypeRowCounts) {}
public record TransactionRowIds(Set<Long> rowIds, Map<Long, Long> dataTypeRowCounts) {}

public TransactionRowIds getTransactionSampleIds(long transactionAuditId, User user, Container container, @Nullable ContainerFilter containerFilter)
{
Expand All @@ -267,8 +268,15 @@ public TransactionRowIds getTransactionSampleIds(long transactionAuditId, User u
.map(SampleTimelineAuditEvent.class::cast)
.toList();
}
// Drop the secondary "added/removed sample to/from job" events; the same sample has a primary registration/update event in the transaction, so counting these would double-count it.
events = events.stream()
.filter(event -> SampleTimelineAuditEvent.SampleTimelineEventType.INSERT.getComment().equals(event.getComment()) || SampleTimelineAuditEvent.SampleTimelineEventType.MERGE.getComment().equals(event.getComment()))
.toList();

Map<Long, Long> dataTypeRowCounts = new HashMap<>();
List<Long> sampleIds = new ArrayList<>();
// Return distinct set of sampleIds, since there might be multiple events in transaction for the same sample
// For example: job derive action creates one registration event, one add to job event.
Set<Long> sampleIds = new HashSet<>();
events.forEach(event -> {
dataTypeRowCounts.merge(event.getSampleTypeId(), 1L, Long::sum);
sampleIds.add(event.getSampleId());
Expand All @@ -279,7 +287,7 @@ public TransactionRowIds getTransactionSampleIds(long transactionAuditId, User u
public TransactionRowIds getTransactionSourceIds(long transactionAuditId, User user, Container container, @Nullable ContainerFilter containerFilter)
{
List<String> lsids = new ArrayList<>();
List<Long> sourceIds = new ArrayList<>();
Set<Long> sourceIds = new HashSet<>();
Map<Long, Long> dataTypeRowCounts = new HashMap<>();
List<AuditTypeEvent> transactionEvents = TRANSACTION_EVENT_CACHE.get(transactionAuditId).second;
List<DetailedAuditTypeEvent> detailedEvents = transactionEvents.isEmpty()
Expand Down
4 changes: 4 additions & 0 deletions query/src/org/labkey/query/controllers/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4651,6 +4651,10 @@ protected JSONObject executeJson(JSONObject json, CommandType commandType, boole
Map<String, Object> auditDetails = json.has("auditDetails") ? json.getJSONObject("auditDetails").toMap() : new CaseInsensitiveHashMap<>();

Map<Enum, Object> configParameters = new HashMap<>();

if (extraContext.containsKey(AbstractQueryImportAction.Params.useTransactionAuditCache.name()))
configParameters.put(AbstractQueryImportAction.Params.useTransactionAuditCache, extraContext.get(AbstractQueryImportAction.Params.useTransactionAuditCache.name()));

if (WorkflowService.get() != null)
WorkflowService.get().populateConfigParams(extraContext, configParameters);

Expand Down