Skip to content

Commit e7c224f

Browse files
Backport fixes and reporting for issue 52666 (#6516)
Co-authored-by: Nick Kerr <nickk@labkey.com>
1 parent dfbf33f commit e7c224f

File tree

7 files changed

+233
-60
lines changed

7 files changed

+233
-60
lines changed

api/src/org/labkey/api/data/StatementUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,14 @@ else if (column.getName().equalsIgnoreCase(updatable.getObjectURIColumnName()) &
864864
for (int i = 0; i < cols.size(); i++)
865865
{
866866
FieldKey fk = cols.get(i).getFieldKey();
867-
if (keys.containsKey(fk) || null != _dontUpdateColumnNames && _dontUpdateColumnNames.contains(cols.get(i).getName()))
867+
if (keys.containsKey(fk))
868868
continue;
869+
870+
// Issue 52666: Check column remapping when looking for columns to not update
871+
String colName = cols.get(i).getName();
872+
if (_dontUpdateColumnNames.contains(colName) || (remap.containsKey(colName) && _dontUpdateColumnNames.contains(remap.get(colName))))
873+
continue;
874+
869875
sqlfUpdate.append(comma);
870876
comma = ", ";
871877
sqlfUpdate.appendIdentifier(cols.get(i).getSelectName());

experiment/src/org/labkey/experiment/api/BaseFieldNamesTable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public BaseFieldNamesTable(String tableName, @NotNull ExpSchema userSchema, @Nul
3131
addWrapColumn(_rootTable.getColumn("Label"));
3232
addWrapColumn(_rootTable.getColumn("Description"));
3333
addWrapColumn(_rootTable.getColumn("RangeURI"));
34+
addWrapColumn(_rootTable.getColumn("StorageColumnName"));
3435
}
3536

3637
protected MutableColumnInfo addColumn(String name, JdbcType type)

experiment/src/org/labkey/experiment/api/ExpDataClassDataTestCase.jsp

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
<%@ page import="org.labkey.api.query.QueryService" %>
6868
<%@ page import="org.labkey.api.query.SchemaKey" %>
6969
<%@ page import="org.labkey.api.query.UserSchema" %>
70-
<%@ page import="org.labkey.api.reader.MapLoader" %>
7170
<%@ page import="static java.util.Collections.emptyList" %>
7271
<%@ page import="org.labkey.api.security.SecurityManager" %>
7372
<%@ page import="org.labkey.api.security.User" %>
@@ -102,6 +101,9 @@
102101
<%@ page import="org.labkey.api.action.ApiUsageException" %>
103102
<%@ page import="org.labkey.api.search.SearchService" %>
104103
<%@ page import="java.util.concurrent.TimeUnit" %>
104+
<%@ page import="org.labkey.api.dataiterator.MapDataIterator" %>
105+
<%@ page import="org.labkey.api.exp.query.ExpSchema" %>
106+
<%@ page import="org.jetbrains.annotations.NotNull" %>
105107

106108
<%@ page extends="org.labkey.api.jsp.JspTest.BVT" %>
107109

@@ -231,6 +233,7 @@ public void testDataClass() throws Exception
231233
{
232234
final User user = TestContext.get().getUser();
233235
final Container sub = ContainerManager.createContainer(c, "sub", TestContext.get().getUser());
236+
final String dataClassName = "testing";
234237
235238
List<GWTPropertyDescriptor> props = new ArrayList<>();
236239
props.add(new GWTPropertyDescriptor("aa", "int"));
@@ -242,16 +245,13 @@ public void testDataClass() throws Exception
242245
DataClassDomainKindProperties options = new DataClassDomainKindProperties();
243246
options.setNameExpression("JUNIT-${genId}-${aa}");
244247
245-
final ExpDataClassImpl dataClass = ExperimentServiceImpl.get().createDataClass(c, user, "testing", options, props, indices, null, null);
248+
final ExpDataClassImpl dataClass = ExperimentServiceImpl.get().createDataClass(c, user, dataClassName, options, props, indices, null, null);
246249
assertNotNull(dataClass);
247250
248251
final Domain domain = dataClass.getDomain();
249252
assertNotNull(domain);
250253
251-
UserSchema schema = QueryService.get().getUserSchema(user, c, helper.expDataSchemaKey);
252-
TableInfo table = schema.getTable("testing");
253-
assertNotNull("data class not in query schema", table);
254-
254+
TableInfo table = getDataClassTable(dataClassName);
255255
String expectedName = "JUNIT-1-20";
256256
testNameExpressionGeneration(dataClass, table, expectedName);
257257
testInsertDuplicate(dataClass, table);
@@ -373,8 +373,7 @@ private void testBulkImport(ExpDataClassImpl dataClass, TableInfo table, User us
373373
row.put("alias", "a,b,c");
374374
rows.add(row);
375375
376-
MapLoader mapLoader = new MapLoader(rows);
377-
int count = table.getUpdateService().loadRows(user, c, mapLoader, new DataIteratorContext(), null);
376+
int count = table.getUpdateService().loadRows(user, c, MapDataIterator.of(rows), new DataIteratorContext(), null);
378377
assertEquals(2, count);
379378
assertEquals(2, dataClass.getDatas().size());
380379
@@ -492,17 +491,13 @@ private void verifyAliasesViaSelectRows(String schemaName, String queryName, int
492491
private void testEmptyInsert(ExpDataClassImpl dataClass, TableInfo table, User user) throws Exception
493492
{
494493
List<Map<String, Object>> rows = new ArrayList<>();
495-
MapLoader b = new MapLoader(rows);
496-
497494
BatchValidationException errors = new BatchValidationException();
498-
int count = table.getUpdateService().importRows(user, c, b, errors, null, null);
495+
int count = table.getUpdateService().importRows(user, c, MapDataIterator.of(rows), errors, null, null);
499496
if (errors.hasErrors())
500497
throw errors;
501498
assertEquals(0, count);
502499
}
503500
504-
505-
506501
@Test
507502
public void testDataClassFromTemplate() throws Exception
508503
{
@@ -553,11 +548,8 @@ public void testDataClassFromTemplate() throws Exception
553548
Lookup lookup = new Lookup(c, "lists", listName);
554549
ConceptURIProperties.setLookup(c, "http://cpas.labkey.com/Experiment#Testing", lookup);
555550
556-
UserSchema schema = QueryService.get().getUserSchema(user, c, helper.expDataSchemaKey);
557-
TableInfo table = schema.getTable(domainName);
558-
assertNotNull("data class not in query schema", table);
559-
560551
// verify that the lookup from the ConceptURI mapping is applied as a FK to the column
552+
TableInfo table = getDataClassTable(domainName);
561553
TableInfo aaLookupTable = table.getColumn("aa").getFkTableInfo();
562554
assertNotNull(aaLookupTable);
563555
assertEquals("lists", aaLookupTable.getPublicSchemaName());
@@ -701,15 +693,15 @@ public void testContainerDelete() throws Exception
701693
{
702694
final User user = TestContext.get().getUser();
703695
final Container sub = ContainerManager.createContainer(c, "sub", user);
696+
final String dataClassName = "testing";
704697
705698
List<GWTPropertyDescriptor> props = new ArrayList<>();
706699
props.add(new GWTPropertyDescriptor("aa", "int"));
707700
708-
final ExpDataClassImpl dataClass = ExperimentServiceImpl.get().createDataClass(c, user, "testing", null, props, emptyList(), null, null);
701+
final ExpDataClassImpl dataClass = ExperimentServiceImpl.get().createDataClass(c, user, dataClassName, null, props, emptyList(), null, null);
709702
final int dataClassId = dataClass.getRowId();
710703
711-
UserSchema schema = QueryService.get().getUserSchema(user, c, helper.expDataSchemaKey);
712-
TableInfo table = schema.getTable("testing");
704+
TableInfo table = getDataClassTable(dataClassName);
713705
714706
// setup: insert into junit container
715707
int dataRowId1;
@@ -1039,26 +1031,32 @@ public void testInsertOptionUpdate() throws Exception
10391031
List<GWTPropertyDescriptor> props = new ArrayList<>();
10401032
props.add(new GWTPropertyDescriptor("prop", "string"));
10411033
1042-
ExpDataClass dataClass = ExperimentServiceImpl.get().createDataClass(c, user, dataClassName, null, props, emptyList(), null, null);
1034+
String longFieldName = "Field100 ABCDEFGHIJKLMNOPQRSTUVWXYZ%()=+-[]_|*`'\":;<>?!@#^AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTU)";
1035+
props.add(new GWTPropertyDescriptor(longFieldName, "string"));
1036+
1037+
ExperimentServiceImpl.get().createDataClass(c, user, dataClassName, null, props, emptyList(), null, null);
10431038
List<Map<String, Object>> rowsToAdd = new ArrayList<>();
1044-
rowsToAdd.add(CaseInsensitiveHashMap.of("name", "D-1", "prop", "a"));
1045-
rowsToAdd.add(CaseInsensitiveHashMap.of("name", "D-1-d", "prop", "c"));
1046-
rowsToAdd.add(CaseInsensitiveHashMap.of("name", "D-2", "prop", "b"));
1039+
rowsToAdd.add(CaseInsensitiveHashMap.of("name", "D-1", "prop", "a", longFieldName, "Very"));
1040+
rowsToAdd.add(CaseInsensitiveHashMap.of("name", "D-1-d", "prop", "c", longFieldName, "Long"));
1041+
rowsToAdd.add(CaseInsensitiveHashMap.of("name", "D-2", "prop", "b", longFieldName, "Field"));
10471042
1048-
UserSchema schema = QueryService.get().getUserSchema(user, c, helper.expDataSchemaKey);
1049-
TableInfo table = schema.getTable(dataClassName);
1043+
TableInfo table = getDataClassTable(dataClassName);
10501044
QueryUpdateService qus = table.getUpdateService();
1045+
assertNotNull(qus);
1046+
1047+
String longFieldAlias = table.getColumn(longFieldName).getAlias();
1048+
assertFalse("Unexpected long field alias", longFieldName.equalsIgnoreCase(longFieldAlias));
10511049
10521050
DataIteratorContext context = new DataIteratorContext();
10531051
context.setInsertOption(QueryUpdateService.InsertOption.IMPORT);
10541052
1055-
var count = qus.loadRows(user, c, new MapLoader(rowsToAdd), context, null);
1053+
var count = qus.loadRows(user, c, MapDataIterator.of(rowsToAdd), context, null);
10561054
assertFalse(context.getErrors().hasErrors());
1057-
assertEquals(count,3);
1055+
assertEquals(3, count);
10581056
10591057
TableInfo dataInputTInfo = ((ExperimentServiceImpl) ExperimentService.get()).getTinfoExperimentRunDataInputs();
10601058
SimpleFilter filter = SimpleFilter.createContainerFilter(c);
1061-
TableSelector ts = new TableSelector(dataInputTInfo, TableSelector.ALL_COLUMNS, filter, null);
1059+
TableSelector ts = new TableSelector(dataInputTInfo, filter, null);
10621060
int inputCount = (int) ts.getRowCount();
10631061
10641062
// update regular properties as well as datainputs
@@ -1068,23 +1066,33 @@ public void testInsertOptionUpdate() throws Exception
10681066
rowsToUpdate.add(CaseInsensitiveHashMap.of("name", "D-2", "prop", "b1", "DataInputs/DataClassWithImportOption", null));
10691067
10701068
context.setInsertOption(QueryUpdateService.InsertOption.UPDATE);
1071-
count = qus.loadRows(user, c, new MapLoader(rowsToUpdate), context, null);
1069+
count = qus.loadRows(user, c, MapDataIterator.of(rowsToUpdate), context, null);
10721070
10731071
assertFalse(context.getErrors().hasErrors());
1074-
assertEquals(count,3);
1072+
assertEquals(3, count);
10751073
10761074
Set<String> columnNames = new HashSet<>();
10771075
columnNames.add("Name");
10781076
columnNames.add("prop");
1077+
columnNames.add(longFieldName);
10791078
10801079
List<Map<String,Object>> rows = Arrays.asList(new TableSelector(table, columnNames, null, new Sort("Name")).getMapArray());
10811080
assertEquals("a1", rows.get(0).get("prop"));
10821081
assertEquals("c1", rows.get(1).get("prop"));
10831082
assertEquals("b1", rows.get(2).get("prop"));
1083+
assertEquals("Very", rows.get(0).get(longFieldAlias));
1084+
assertEquals("Long", rows.get(1).get(longFieldAlias));
1085+
assertEquals("Field", rows.get(2).get(longFieldAlias));
10841086
1085-
ts = new TableSelector(dataInputTInfo, TableSelector.ALL_COLUMNS, filter, null);
1087+
ts = new TableSelector(dataInputTInfo, filter, null);
10861088
int newInputCount = (int) ts.getRowCount();
10871089
assertEquals(inputCount + 1, newInputCount);
10881090
}
10891091
1092+
private @NotNull TableInfo getDataClassTable(String dataClassName)
1093+
{
1094+
UserSchema schema = QueryService.get().getUserSchema(TestContext.get().getUser(), c, ExpSchema.SCHEMA_EXP_DATA);
1095+
return schema.getTableOrThrow(dataClassName);
1096+
}
1097+
10901098
%>

0 commit comments

Comments
 (0)