Skip to content
Draft
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
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.labkey.api.data.dialect.StandardDialectStringHandler;
import org.labkey.api.dataiterator.CachingDataIterator;
import org.labkey.api.dataiterator.DataIteratorUtil;
import org.labkey.api.dataiterator.DetailedAuditLogDataIterator;
import org.labkey.api.dataiterator.DiskCachingDataIterator;
import org.labkey.api.dataiterator.ExistingRecordDataIterator;
import org.labkey.api.dataiterator.GenerateUniqueDataIterator;
Expand Down Expand Up @@ -437,6 +438,7 @@ public void registerServlets(ServletContext servletCtx)
DateUtil.TestCase.class,
DbScope.DialectTestCase.class,
DeltaTrackingMap.TestCase.class,
DetailedAuditLogDataIterator.TestCase.class,
DetailsURL.TestCase.class,
DiskCachingDataIterator.DiskTestCase.class,
EmailTemplate.TestCase.class,
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/audit/SampleTimelineAuditEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SampleTimelineAuditEvent extends DetailedAuditTypeEvent
public static final Set<String> EXCLUDED_DETAIL_FIELDS = Set.of(
AvailableAliquotVolume.name(), AvailableAliquotCount.name(), AliquotCount.name(), AliquotVolume.name(), AliquotUnit.name(),
PROVIDED_DATA_PREFIX + StoredAmount.name(), PROVIDED_DATA_PREFIX + Units.name(),
DELTA_PROVIDED_DATA_PREFIX + StoredAmount.name() + DELTA_PROVIDED_DATA_PREFIX + Units.name());
DELTA_PROVIDED_DATA_PREFIX + StoredAmount.name(), DELTA_PROVIDED_DATA_PREFIX + Units.name());

public enum SampleTimelineEventType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import org.labkey.api.audit.AuditHandler;
import org.labkey.api.collections.CaseInsensitiveHashMap;
import org.labkey.api.data.ColumnInfo;
import org.labkey.api.data.Container;
import org.labkey.api.data.TableInfo;
Expand All @@ -28,8 +31,11 @@
import org.labkey.api.security.User;

import java.io.IOException;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import static org.labkey.api.gwt.client.AuditBehaviorType.DETAILED;
Expand Down Expand Up @@ -105,6 +111,7 @@ public boolean next() throws BatchValidationException
if (!_updatedRows.isEmpty())
_auditHandler.addAuditEvent(_user, _container, _table, DETAILED, _userComment, _auditAction, _updatedRows, _existingRows, _providedValues, _useTransactionAuditCache);
_updatedRows.clear();
_providedValues.clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to avoid the synchronization problem to switch to using one list? E.g. List<record<updated,provided,existing>>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bigger change in terms of lines of code, but great idea for ensuring we don't drift again.

if (null != _existingRows)
_existingRows.clear();
}
Expand Down Expand Up @@ -172,4 +179,54 @@ public boolean supportsGetExistingRecord()
{
return _data.supportsGetExistingRecord();
}

public static class TestCase extends Assert
{
@Test
public void testProvidedValuesAlignAcrossBatches() throws Exception
{
int rowCount = 2500;
List<Map<String, Object>> rows = new ArrayList<>();
for (int i = 0; i < rowCount; i++)
rows.add(CaseInsensitiveHashMap.of("name", "S-" + i));

List<Integer> batchSizes = new ArrayList<>();
List<String> auditedNames = new ArrayList<>();
AuditHandler recorder = (AuditHandler) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{AuditHandler.class}, (_, method, args) -> {
if (method.getName().equals("addAuditEvent") && args.length == 10)
{
@SuppressWarnings("unchecked") List<Map<String, Object>> batchRows = (List<Map<String, Object>>) args[6];
@SuppressWarnings("unchecked") List<Map<String, Object>> provided = (List<Map<String, Object>>) args[8];
assertEquals("provided values must pair one-to-one with the batch's rows", batchRows.size(), provided.size());
batchSizes.add(batchRows.size());
for (int i = 0; i < batchRows.size(); i++)
{
assertEquals(batchRows.get(i).get("name"), provided.get(i).get("providedName"));
auditedNames.add((String) batchRows.get(i).get("name"));
}
}
return null;
});
TableInfo table = (TableInfo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{TableInfo.class}, (_, method, _) -> switch (method.getName())
{
case "supportsAuditTracking" -> true;
case "getEffectiveAuditBehavior" -> DETAILED;
case "getAuditHandler" -> recorder;
default -> null;
});

DataIteratorBuilder source = _ -> new ListofMapsDataIterator(Set.of("name"), rows);
DataIteratorBuilder audited = getDataIteratorBuilder(table, source, QueryUpdateService.InsertOption.INSERT, null, null, row -> Map.of("providedName", row.get("name")));
try (DataIterator it = audited.getDataIterator(new DataIteratorContext()))
{
assertTrue(it instanceof DetailedAuditLogDataIterator);
while (it.next())
{
}
}

assertTrue("expected more than one audit batch", batchSizes.size() > 1);
assertEquals(rows.stream().map(row -> row.get("name")).toList(), auditedNames);
}
}
}
Loading