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
15 changes: 15 additions & 0 deletions modules/ETLtest/resources/ETLs/SourceToTarget2BulkLoad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<etl xmlns="http://labkey.org/etl/xml" transactDestinationSchema="etltest">
<name>Source to target2 bulk load</name>
<description>append rows from source to target, skip detailed auditing</description>
<transforms>
<transform id="step1" type="org.labkey.di.pipeline.TransformTask">
<description>Copy to target2</description>
<source schemaName="etltest" queryName="source" />
<destination schemaName="etltest" bulkLoad="true" queryName="target2" />
</transform>
</transforms>
<schedule>
<poll interval="15s" />
</schedule>
</etl>
15 changes: 15 additions & 0 deletions modules/ETLtest/resources/ETLs/SourceToTarget2NoBulkLoad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<etl xmlns="http://labkey.org/etl/xml" transactDestinationSchema="etltest">
<name>Source to target2 no bulk load</name>
<description>append rows from source to target, with detailed auditing</description>
<transforms>
<transform id="step1" type="org.labkey.di.pipeline.TransformTask">
<description>Copy to target2 no bulkLoad</description>
<source schemaName="etltest" queryName="source" />
<destination schemaName="etltest" queryName="target2" />
</transform>
</transforms>
<schedule>
<poll interval="15s" />
</schedule>
</etl>
1 change: 1 addition & 0 deletions modules/ETLtest/resources/schemas/etltest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</table>

<table tableName="target2" tableDbType="TABLE">
<auditLogging>DETAILED</auditLogging>
<columns>
<column columnName="rowid"/>
<column columnName="container"/>
Expand Down
78 changes: 78 additions & 0 deletions src/org/labkey/remoteapi/query/ImportExperimentDataCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.labkey.remoteapi.query;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.labkey.test.WebTestHelper;
import org.labkey.test.util.AuditLogHelper;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

public class ImportExperimentDataCommand extends ImportDataCommand
{
private AuditLogHelper.AuditBehaviorType _auditBehavior;
private Boolean _crossTypeImport;
private Boolean _crossFolderImport;
private String _containerPath;

public ImportExperimentDataCommand(String schemaName, String queryName, String containerPath)
{
super(schemaName, queryName);
_containerPath = containerPath;
}

public AuditLogHelper.AuditBehaviorType getAuditBehavior()
{
return _auditBehavior;
}

public void setAuditBehavior(AuditLogHelper.AuditBehaviorType auditBehavior)
{
_auditBehavior = auditBehavior;
}

public Boolean getCrossTypeImport()
{
return _crossTypeImport;
}

public void setCrossTypeImport(Boolean crossTypeImport)
{
_crossTypeImport = crossTypeImport;
}

public Boolean getCrossFolderImport()
{
return _crossFolderImport;
}

public void setCrossFolderImport(Boolean crossFolderImport)
{
_crossFolderImport = crossFolderImport;
}

@Override
protected HttpPost createRequest(URI uri) {
HttpPost post = super.createRequest(uri);
String action = "samples".equalsIgnoreCase(getSchemaName()) ? "importSamples" : "importData";
Map<String, String> params = new HashMap<>();
if (_auditBehavior != null)
params.put("auditBehavior", _auditBehavior.name());
if (_crossTypeImport)
params.put("crossTypeImport", "true");
if (_crossFolderImport)
params.put("crossFolderImport", "true");
String url = WebTestHelper.buildURL("experiment", _containerPath, action, params);
try
{
post.setUri(new URI(url));
}
catch (URISyntaxException e)
{
throw new RuntimeException(e);
}
return post;
}

}
22 changes: 22 additions & 0 deletions src/org/labkey/test/BaseWebDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.labkey.test.util.AbstractContainerHelper;
import org.labkey.test.util.ApiPermissionsHelper;
import org.labkey.test.util.ArtifactCollector;
import org.labkey.test.util.AuditLogHelper;
import org.labkey.test.util.ComponentQuery;
import org.labkey.test.util.Crawler;
import org.labkey.test.util.CspLogUtil;
Expand Down Expand Up @@ -2743,14 +2744,35 @@ public void dismissReleaseBanner(String productName, boolean dismiss)
}

protected void verifyQueryAPI(String schema, String dataType, Map<String, Object> row, boolean isInsert, String... errorMsg)
{
verifyQueryAPI(schema, dataType, null, row, isInsert, errorMsg);
}

protected void verifyQueryAPI(String schema, String dataType, @Nullable AuditLogHelper.AuditBehaviorType auditBehavior, Map<String, Object> row, boolean isInsert, String... errorMsg)
{
String action = isInsert ? "insertRows" : "updateRows";
String updateScript = "LABKEY.Query." + action + "({ schemaName: \"" + schema + "\", "+
"queryName: " + EscapeUtil.toJSONStr(dataType) + ", " +
(auditBehavior == null ? "" : ("auditBehavior: " + EscapeUtil.toJSONStr(auditBehavior.name())) + ", ") +
"success: callback," +
"failure: callback," +
"rows: [" + EscapeUtil.toJSONRow(row) + "]" +
"})";
log(updateScript);
executeAndVerifyScript(updateScript, errorMsg);
}

protected void verifyQueryAPI(String schema, String dataType, @Nullable AuditLogHelper.AuditBehaviorType auditBehavior, List<Map<String, Object>> rows, boolean isInsert, String... errorMsg)
{
String action = isInsert ? "insertRows" : "updateRows";
String updateScript = "LABKEY.Query." + action + "({ schemaName: \"" + schema + "\", "+
"queryName: " + EscapeUtil.toJSONStr(dataType) + ", " +
(auditBehavior == null ? "" : ("auditBehavior: " + EscapeUtil.toJSONStr(auditBehavior.name())) + ", ") +
"success: callback," +
"failure: callback," +
"rows: [" + EscapeUtil.toJSONRow(rows) + "]" +
"})";
log(updateScript);
executeAndVerifyScript(updateScript, errorMsg);
}

Expand Down
51 changes: 50 additions & 1 deletion src/org/labkey/test/tests/AuditLogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.experimental.categories.Category;
import org.labkey.remoteapi.CommandException;
import org.labkey.remoteapi.Connection;
import org.labkey.remoteapi.query.BaseRowsCommand;
import org.labkey.remoteapi.query.InsertRowsCommand;
import org.labkey.remoteapi.query.RowsResponse;
import org.labkey.test.BaseWebDriverTest;
Expand Down Expand Up @@ -428,7 +429,7 @@ public void testDetailedQueryUpdateAuditLog() throws IOException, CommandExcepti
{
_containerHelper.createProject(AUDIT_DETAILED_TEST_PROJECT, "Custom");
_containerHelper.enableModule("simpletest");
goToProjectHome();
goToProjectHome(AUDIT_DETAILED_TEST_PROJECT);

Connection cn = WebTestHelper.getRemoteApiConnection();

Expand All @@ -439,9 +440,43 @@ public void testDetailedQueryUpdateAuditLog() throws IOException, CommandExcepti
insertCmd.addRow(rowMap);
RowsResponse resp1 = insertCmd.execute(cn, AUDIT_DETAILED_TEST_PROJECT);

Integer transactionId = _auditLogHelper.checkAuditEventDiffCountForLastTransaction(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, 0, 1);
Map<String, Object> expectedValues = new HashMap<>();
expectedValues.put("Comment", "1 row(s) were inserted.");
_auditLogHelper.checkAuditEventValuesForTransactionId(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, transactionId, 1, expectedValues);
goToProjectHome(AUDIT_DETAILED_TEST_PROJECT);

Map<String, String> auditLog = getAuditLogRow(this, "Query update events", "Query Name", "Manufacturers");
assertEquals("Did not find expected audit log for summary log level", "1 row(s) were inserted.", auditLog.get("Comment"));

// create manufacturer (which has summary audit log level) with api audit override to detail
insertCmd = new InsertRowsCommand("vehicle", "manufacturers");
insertCmd.setAuditBehavior(BaseRowsCommand.AuditBehavior.DETAILED);
rowMap = new HashMap<>();
rowMap.put("name", "Kia_ev");
insertCmd.addRow(rowMap);
insertCmd.execute(cn, AUDIT_DETAILED_TEST_PROJECT);

goToProjectHome(AUDIT_DETAILED_TEST_PROJECT);
transactionId = _auditLogHelper.checkAuditEventDiffCountForLastTransaction(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, 7, 1);
expectedValues = new HashMap<>();
expectedValues.put("Comment", "A row was inserted.");
_auditLogHelper.checkAuditEventValuesForTransactionId(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, transactionId, 1, expectedValues);

// create manufacturer (which has summary audit log level) with api audit override to NONE. The override should be ignored
insertCmd = new InsertRowsCommand("vehicle", "manufacturers");
insertCmd.setAuditBehavior(BaseRowsCommand.AuditBehavior.NONE);
rowMap = new HashMap<>();
rowMap.put("name", "Kia_hybrid");
insertCmd.addRow(rowMap);
insertCmd.execute(cn, AUDIT_DETAILED_TEST_PROJECT);

goToProjectHome(AUDIT_DETAILED_TEST_PROJECT);
transactionId = _auditLogHelper.checkAuditEventDiffCountForLastTransaction(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, 0, 1);
expectedValues = new HashMap<>();
expectedValues.put("Comment", "1 row(s) were inserted.");
_auditLogHelper.checkAuditEventValuesForTransactionId(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, transactionId, 1, expectedValues);

//then create model (which has detailed audit log level)
InsertRowsCommand insertCmd2 = new InsertRowsCommand("vehicle", "models");
rowMap = new HashMap<>();
Expand All @@ -453,6 +488,20 @@ public void testDetailedQueryUpdateAuditLog() throws IOException, CommandExcepti
refresh();
auditLog = getAuditLogRow(this, "Query update events", "Query Name", "Models");
assertEquals("Did not find expected audit log for detailed log level", "A row was inserted.", auditLog.get("Comment"));
goToProjectHome(AUDIT_DETAILED_TEST_PROJECT);

// create model (which has detailed audit log level), with API audit SUMMARY, effective audit should be detailed
rowMap.put("name", "Carnival");
insertCmd2 = new InsertRowsCommand("vehicle", "models");
insertCmd2.setAuditBehavior(BaseRowsCommand.AuditBehavior.SUMMARY);
insertCmd2.addRow(rowMap);
insertCmd2.execute(cn, AUDIT_DETAILED_TEST_PROJECT);

transactionId = _auditLogHelper.checkAuditEventDiffCountForLastTransaction(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, 8, 1);
expectedValues = new HashMap<>();
expectedValues.put("Comment", "A row was inserted.");
_auditLogHelper.checkAuditEventValuesForTransactionId(AUDIT_DETAILED_TEST_PROJECT, AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, transactionId, 1, expectedValues);

_containerHelper.deleteProject(AUDIT_DETAILED_TEST_PROJECT, false);
}
else
Expand Down
9 changes: 8 additions & 1 deletion src/org/labkey/test/tests/SampleTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.labkey.test.params.FieldInfo;
import org.labkey.test.params.experiment.SampleTypeDefinition;
import org.labkey.test.util.ApiPermissionsHelper;
import org.labkey.test.util.AuditLogHelper;
import org.labkey.test.util.DataRegionExportHelper;
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.EscapeUtil;
Expand Down Expand Up @@ -296,7 +297,7 @@ public void testCustomProperties()

// Issue 47280: LKSM: Trailing/Leading whitespace in Source name won't resolve when deriving samples
@Test
public void testImportSamplesWithTrailingSpace()
public void testImportSamplesWithTrailingSpace() throws IOException, CommandException
{
final String sampleTypeName = "SampleTypeWithProvidedName";
final List<FieldDefinition> fields = List.of(
Expand All @@ -317,6 +318,12 @@ public void testImportSamplesWithTrailingSpace()
Map<String, String> fieldMap = Map.of("Name", " S-1 ", "StringCol", "Ess ", "IntCol", "1 ");
sampleTypeHelper.insertRow(fieldMap);

AuditLogHelper auditLogHelper = new AuditLogHelper(this);
int transactionId = auditLogHelper.checkAuditEventDiffCountForLastTransaction(getProjectName(), AuditLogHelper.AuditEvent.SAMPLE_TIMELINE_EVENT, 21, 1);
Map<String, Object>expectedValues = new HashMap<>();
expectedValues.put("Comment", "Sample was registered.");
auditLogHelper.checkAuditEventValuesForTransactionId(getProjectName(), AuditLogHelper.AuditEvent.SAMPLE_TIMELINE_EVENT, transactionId, 1, expectedValues);

log("Verify values were saved are without trailing spaces");
sampleTypeHelper.verifyDataValues(Collections.singletonList(fieldMap));

Expand Down
Loading