67
67
<%@ page import =" org.labkey.api.query.QueryService" %>
68
68
<%@ page import =" org.labkey.api.query.SchemaKey" %>
69
69
<%@ page import =" org.labkey.api.query.UserSchema" %>
70
- <%@ page import =" org.labkey.api.reader.MapLoader" %>
71
70
<%@ page import =" static java.util.Collections.emptyList" %>
72
71
<%@ page import =" org.labkey.api.security.SecurityManager" %>
73
72
<%@ page import =" org.labkey.api.security.User" %>
102
101
<%@ page import =" org.labkey.api.action.ApiUsageException" %>
103
102
<%@ page import =" org.labkey.api.search.SearchService" %>
104
103
<%@ 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" %>
105
107
106
108
<%@ page extends =" org.labkey.api.jsp.JspTest.BVT" %>
107
109
@@ -231,6 +233,7 @@ public void testDataClass() throws Exception
231
233
{
232
234
final User user = TestContext . get(). getUser();
233
235
final Container sub = ContainerManager . createContainer(c, " sub" , TestContext . get(). getUser());
236
+ final String dataClassName = " testing" ;
234
237
235
238
List<GWTPropertyDescriptor > props = new ArrayList<> ();
236
239
props. add(new GWTPropertyDescriptor (" aa" , " int" ));
@@ -242,16 +245,13 @@ public void testDataClass() throws Exception
242
245
DataClassDomainKindProperties options = new DataClassDomainKindProperties ();
243
246
options. setNameExpression(" JUNIT-${ genId } -${ aa } " );
244
247
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 );
246
249
assertNotNull(dataClass);
247
250
248
251
final Domain domain = dataClass. getDomain();
249
252
assertNotNull(domain);
250
253
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);
255
255
String expectedName = " JUNIT-1-20" ;
256
256
testNameExpressionGeneration(dataClass, table, expectedName);
257
257
testInsertDuplicate(dataClass, table);
@@ -373,8 +373,7 @@ private void testBulkImport(ExpDataClassImpl dataClass, TableInfo table, User us
373
373
row. put(" alias" , " a,b,c" );
374
374
rows. add(row);
375
375
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 );
378
377
assertEquals(2 , count);
379
378
assertEquals(2 , dataClass. getDatas(). size());
380
379
@@ -492,17 +491,13 @@ private void verifyAliasesViaSelectRows(String schemaName, String queryName, int
492
491
private void testEmptyInsert(ExpDataClassImpl dataClass, TableInfo table, User user) throws Exception
493
492
{
494
493
List<Map<String , Object > > rows = new ArrayList<> ();
495
- MapLoader b = new MapLoader (rows);
496
-
497
494
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 );
499
496
if (errors. hasErrors())
500
497
throw errors;
501
498
assertEquals(0 , count);
502
499
}
503
500
504
-
505
-
506
501
@Test
507
502
public void testDataClassFromTemplate() throws Exception
508
503
{
@@ -553,11 +548,8 @@ public void testDataClassFromTemplate() throws Exception
553
548
Lookup lookup = new Lookup (c, " lists" , listName);
554
549
ConceptURIProperties . setLookup(c, " http://cpas.labkey.com/Experiment#Testing" , lookup);
555
550
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
-
560
551
// verify that the lookup from the ConceptURI mapping is applied as a FK to the column
552
+ TableInfo table = getDataClassTable(domainName);
561
553
TableInfo aaLookupTable = table. getColumn(" aa" ). getFkTableInfo();
562
554
assertNotNull(aaLookupTable);
563
555
assertEquals(" lists" , aaLookupTable. getPublicSchemaName());
@@ -701,15 +693,15 @@ public void testContainerDelete() throws Exception
701
693
{
702
694
final User user = TestContext . get(). getUser();
703
695
final Container sub = ContainerManager . createContainer(c, " sub" , user);
696
+ final String dataClassName = " testing" ;
704
697
705
698
List<GWTPropertyDescriptor > props = new ArrayList<> ();
706
699
props. add(new GWTPropertyDescriptor (" aa" , " int" ));
707
700
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 );
709
702
final int dataClassId = dataClass. getRowId();
710
703
711
- UserSchema schema = QueryService . get(). getUserSchema(user, c, helper. expDataSchemaKey);
712
- TableInfo table = schema. getTable(" testing" );
704
+ TableInfo table = getDataClassTable(dataClassName);
713
705
714
706
// setup: insert into junit container
715
707
int dataRowId1;
@@ -1039,26 +1031,32 @@ public void testInsertOptionUpdate() throws Exception
1039
1031
List<GWTPropertyDescriptor > props = new ArrayList<> ();
1040
1032
props. add(new GWTPropertyDescriptor (" prop" , " string" ));
1041
1033
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 );
1043
1038
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 " ));
1047
1042
1048
- UserSchema schema = QueryService . get(). getUserSchema(user, c, helper. expDataSchemaKey);
1049
- TableInfo table = schema. getTable(dataClassName);
1043
+ TableInfo table = getDataClassTable(dataClassName);
1050
1044
QueryUpdateService qus = table. getUpdateService();
1045
+ assertNotNull(qus);
1046
+
1047
+ String longFieldAlias = table. getColumn(longFieldName). getAlias();
1048
+ assertFalse(" Unexpected long field alias" , longFieldName. equalsIgnoreCase(longFieldAlias));
1051
1049
1052
1050
DataIteratorContext context = new DataIteratorContext ();
1053
1051
context. setInsertOption(QueryUpdateService . InsertOption . IMPORT );
1054
1052
1055
- var count = qus. loadRows(user, c, new MapLoader (rowsToAdd), context, null );
1053
+ var count = qus. loadRows(user, c, MapDataIterator . of (rowsToAdd), context, null );
1056
1054
assertFalse(context. getErrors(). hasErrors());
1057
- assertEquals(count, 3 );
1055
+ assertEquals(3 , count );
1058
1056
1059
1057
TableInfo dataInputTInfo = ((ExperimentServiceImpl ) ExperimentService . get()). getTinfoExperimentRunDataInputs();
1060
1058
SimpleFilter filter = SimpleFilter . createContainerFilter(c);
1061
- TableSelector ts = new TableSelector (dataInputTInfo, TableSelector . ALL_COLUMNS , filter, null );
1059
+ TableSelector ts = new TableSelector (dataInputTInfo, filter, null );
1062
1060
int inputCount = (int ) ts. getRowCount();
1063
1061
1064
1062
// update regular properties as well as datainputs
@@ -1068,23 +1066,33 @@ public void testInsertOptionUpdate() throws Exception
1068
1066
rowsToUpdate. add(CaseInsensitiveHashMap . of(" name" , " D-2" , " prop" , " b1" , " DataInputs/DataClassWithImportOption" , null ));
1069
1067
1070
1068
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 );
1072
1070
1073
1071
assertFalse(context. getErrors(). hasErrors());
1074
- assertEquals(count, 3 );
1072
+ assertEquals(3 , count );
1075
1073
1076
1074
Set<String > columnNames = new HashSet<> ();
1077
1075
columnNames. add(" Name" );
1078
1076
columnNames. add(" prop" );
1077
+ columnNames. add(longFieldName);
1079
1078
1080
1079
List<Map<String ,Object > > rows = Arrays . asList(new TableSelector (table, columnNames, null , new Sort (" Name" )). getMapArray());
1081
1080
assertEquals(" a1" , rows. get(0 ). get(" prop" ));
1082
1081
assertEquals(" c1" , rows. get(1 ). get(" prop" ));
1083
1082
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));
1084
1086
1085
- ts = new TableSelector (dataInputTInfo, TableSelector . ALL_COLUMNS , filter, null );
1087
+ ts = new TableSelector (dataInputTInfo, filter, null );
1086
1088
int newInputCount = (int ) ts. getRowCount();
1087
1089
assertEquals(inputCount + 1 , newInputCount);
1088
1090
}
1089
1091
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
+
1090
1098
% >
0 commit comments