Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Review feedback, remove manageColumns flag
- no longer process non-data iterator pathway for managed columns
  • Loading branch information
labkey-nicka committed Apr 16, 2026
commit 37d410add9672af40dacba1ceac249f4f9c9e3a1
71 changes: 38 additions & 33 deletions src/org/labkey/test/tests/TriggerScriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,40 +389,41 @@ public void testListManagedColumnsTriggers() throws Exception
insCmd.addRow(Map.of("Name", "Managed Struct Remove", "SSN", "111222336", "Company", "Test Co"));
assertAPIErrorMessage(insCmd, MANAGED_STRUCT_REMOVE_ERROR, cn);

// TODO: Test update via DIB -- how is this invoked? Via file only?
// Setup: insert rows for update tests; include "employeeId" in payload so insert validation passes
insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME);
insCmd.addRow(Map.of("Name", "MC Update Setup", "SSN", "111222340", "Company", "Setup Co", "employeeId", "OLD-ID"));
insCmd.addRow(Map.of("Name", "MC Struct Setup", "SSN", "111222341", "Company", "Setup Co", "employeeId", "OLD-ID-2"));
insCmd.addRow(Map.of("Name", "MC Struct Remove Setup", "SSN", "111222342", "Company", "Setup Co", "employeeId", "OLD-ID-3"));
resp = insCmd.execute(cn, getProjectName());
Integer updateKey = (Integer) resp.getRows().getFirst().get("Key");
Integer structKey = (Integer) resp.getRows().get(1).get("Key");
Integer structRemoveKey = (Integer) resp.getRows().get(2).get("Key");

// Update: trigger sets both declared managed columns "company" and "employeeId"
UpdateRowsCommand updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
updCmd.addRow(Map.of("Key", updateKey, "Name", "Managed Update", "SSN", "111222340"));
resp = updCmd.execute(cn, getProjectName());
EmployeeRecord updated = EmployeeRecord.fromMap(resp.getRows().getFirst());
Assert.assertEquals("Trigger should have set company", "Managed Co", updated.company);
Assert.assertEquals("Trigger should have set employeeId", "EMP-UPD", updated.employeeId);

// Update: declared managed column not set by trigger
// "boomerang" is absent from the payload; SSN="-123" causes the trigger to skip setting it
// Name is explicitly provided so the trigger does not accidentally match a named handler
updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
updCmd.addRow(Map.of("Key", updateKey, "Name", "MC Update Setup", "SSN", "-123", "Company", "Test Co"));
assertAPIErrorMessage(updCmd, "declared the managed column 'boomerang'", cn);

// Update: structural add error — trigger adds a column not declared as managed
updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
updCmd.addRow(Map.of("Key", structKey, "Name", "Managed Struct", "SSN", "111222341"));
assertAPIErrorMessage(updCmd, MANAGED_STRUCT_ADD_ERROR, cn);

// Update: structural remove error — trigger deletes a column not declared as managed
updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
updCmd.addRow(Map.of("Key", structRemoveKey, "Name", "Managed Struct Remove", "SSN", "111222342"));
assertAPIErrorMessage(updCmd, MANAGED_STRUCT_REMOVE_ERROR, cn);
// insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME);
// insCmd.addRow(Map.of("Name", "MC Update Setup", "SSN", "111222340", "Company", "Setup Co", "employeeId", "OLD-ID"));
// insCmd.addRow(Map.of("Name", "MC Struct Setup", "SSN", "111222341", "Company", "Setup Co", "employeeId", "OLD-ID-2"));
// insCmd.addRow(Map.of("Name", "MC Struct Remove Setup", "SSN", "111222342", "Company", "Setup Co", "employeeId", "OLD-ID-3"));
// resp = insCmd.execute(cn, getProjectName());
// Integer updateKey = (Integer) resp.getRows().getFirst().get("Key");
// Integer structKey = (Integer) resp.getRows().get(1).get("Key");
// Integer structRemoveKey = (Integer) resp.getRows().get(2).get("Key");
//
// // Update: trigger sets both declared managed columns "company" and "employeeId"
// UpdateRowsCommand updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
// updCmd.addRow(Map.of("Key", updateKey, "Name", "Managed Update", "SSN", "111222340"));
// resp = updCmd.execute(cn, getProjectName());
// EmployeeRecord updated = EmployeeRecord.fromMap(resp.getRows().getFirst());
// Assert.assertEquals("Trigger should have set company", "Managed Co", updated.company);
// Assert.assertEquals("Trigger should have set employeeId", "EMP-UPD", updated.employeeId);
//
// // Update: declared managed column not set by trigger
// // "boomerang" is absent from the payload; SSN="-123" causes the trigger to skip setting it
// // Name is explicitly provided so the trigger does not accidentally match a named handler
// updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
// updCmd.addRow(Map.of("Key", updateKey, "Name", "MC Update Setup", "SSN", "-123", "Company", "Test Co"));
// assertAPIErrorMessage(updCmd, "declared the managed column 'boomerang'", cn);
//
// // Update: structural add error — trigger adds a column not declared as managed
// updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
// updCmd.addRow(Map.of("Key", structKey, "Name", "Managed Struct", "SSN", "111222341"));
// assertAPIErrorMessage(updCmd, MANAGED_STRUCT_ADD_ERROR, cn);
//
// // Update: structural remove error — trigger deletes a column not declared as managed
// updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
// updCmd.addRow(Map.of("Key", structRemoveKey, "Name", "Managed Struct Remove", "SSN", "111222342"));
// assertAPIErrorMessage(updCmd, MANAGED_STRUCT_REMOVE_ERROR, cn);
}

/** Issue 52098 - ensure trigger scripts have a chance to do custom type conversion with the incoming row */
Expand Down Expand Up @@ -694,6 +695,10 @@ private void doManagedColumnsTriggerTest(String schemaName, String queryName, St
"Managed Struct Remove", "MC-SR-001"));
assertAPIErrorMessage(insCmd, MANAGED_STRUCT_REMOVE_ERROR, cn);

// TODO: Test update via DIB -- how is this invoked? Via file only?
if (DATASET_NAME.equals(queryName))
return;

// Setup: insert rows for update tests with neutral Comments so the trigger fallback fires
InsertRowsCommand setupCmd = new InsertRowsCommand(schemaName, queryName);
setupCmd.addRow(makeSetupRow(keyColumnName, requiresDate, dispatchIsKey, "MC Update Setup", "MC-UPD-001"));
Expand Down