2525<%@ page import =" org.labkey.api.data.CompareType" %>
2626<%@ page import =" org.labkey.api.data.Container" %>
2727<%@ page import =" org.labkey.api.data.ContainerManager" %>
28- <%@ page import =" org.labkey.api.data.DbScope" %>
2928<%@ page import =" org.labkey.api.data.JdbcType" %>
3029<%@ page import =" org.labkey.api.data.SQLFragment" %>
3130<%@ page import =" org.labkey.api.data.SimpleFilter" %>
7069<%@ page import =" org.labkey.api.util.PageFlowUtil" %>
7170<%@ page import =" org.labkey.api.util.TestContext" %>
7271<%@ page import =" org.labkey.experiment.api.ExpProvisionedTableTestHelper" %>
73- <%@ page import =" org.labkey.experiment.api.ExpSampleTypeImpl" %>
7472<%@ page import =" org.labkey.experiment.api.ExperimentServiceImpl" %>
75- <%@ page import =" org.labkey.experiment.api.SampleTypeServiceImpl" %>
7673<%@ page import =" java.io.StringBufferInputStream" %>
7774<%@ page import =" java.util.ArrayList" %>
7875<%@ page import =" java.util.Arrays" %>
9188<%@ page import =" org.labkey.api.dataiterator.MapDataIterator" %>
9289<%@ page import =" static org.labkey.api.exp.api.ExperimentService.asInteger" %>
9390<%@ page import =" static org.labkey.api.exp.api.ExperimentService.asLong" %>
91+ <%@ page import =" static java.util.Collections.emptyList" %>
92+ <%@ page import =" org.jetbrains.annotations.Nullable" %>
93+ <%@ page import =" org.labkey.api.view.ActionURL" %>
94+ <%@ page import =" org.labkey.api.query.QueryParam" %>
95+ <%@ page import =" org.labkey.api.view.ViewServlet" %>
96+ <%@ page import =" org.labkey.api.util.JsonUtil" %>
97+ <%@ page import =" org.labkey.api.settings.LookAndFeelProperties" %>
9498<%@ page extends =" org.labkey.api.jsp.JspTest.BVT" %>
9599
96100<%!
@@ -128,16 +132,12 @@ private void assertExpectedName(ExpSampleType st, String expectedName)
128132@Test
129133public void nameNotNull() throws Exception
130134{
131- final User user = TestContext . get(). getUser();
132-
133135 try
134136 {
135137 List<GWTPropertyDescriptor > props = new ArrayList<> ();
136138 props. add(new GWTPropertyDescriptor (" name" , " string" ));
137139
138- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
139- null , null , props, Collections . emptyList(),
140- - 1 , - 1 , - 1 , - 1 , null , null );
140+ createSampleType(null , props, null );
141141 }
142142 catch (ApiUsageException ee)
143143 {
@@ -148,16 +148,12 @@ public void nameNotNull() throws Exception
148148@Test // Issue 51321
149149public void reservedNameFirst() throws Exception
150150{
151- final User user = TestContext . get(). getUser();
152-
153151 try
154152 {
155153 List<GWTPropertyDescriptor > props = new ArrayList<> ();
156154 props. add(new GWTPropertyDescriptor (" name" , " string" ));
157155
158- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
159- " First" , null , props, Collections . emptyList(),
160- - 1 , - 1 , - 1 , - 1 , null , null );
156+ createSampleType(" First" , props, null );
161157 }
162158 catch (ApiUsageException ee)
163159 {
@@ -168,16 +164,12 @@ public void reservedNameFirst() throws Exception
168164@Test // Issue 51321
169165public void reservedNameAll() throws Exception
170166{
171- final User user = TestContext . get(). getUser();
172-
173167 try
174168 {
175169 List<GWTPropertyDescriptor > props = new ArrayList<> ();
176170 props. add(new GWTPropertyDescriptor (" name" , " string" ));
177171
178- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
179- " All" , null , props, Collections . emptyList(),
180- - 1 , - 1 , - 1 , - 1 , null , null );
172+ createSampleType(" All" , props, null );
181173 }
182174 catch (ApiUsageException ee)
183175 {
@@ -189,18 +181,12 @@ public void reservedNameAll() throws Exception
189181@Test
190182public void nameScale() throws Exception
191183{
192- final User user = TestContext . get(). getUser();
193-
194184 try
195185 {
196186 List<GWTPropertyDescriptor > props = new ArrayList<> ();
197187 props. add(new GWTPropertyDescriptor (" name" , " string" ));
198188
199- String name = StringUtils . repeat(" a" , 1000 );
200-
201- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
202- name, null , props, Collections . emptyList(),
203- - 1 , - 1 , - 1 , - 1 , null , null );
189+ createSampleType(StringUtils . repeat(" a" , 1000 ), props, null );
204190 }
205191 catch (ApiUsageException ee)
206192 {
@@ -212,20 +198,14 @@ public void nameScale() throws Exception
212198@Test
213199public void nameExpressionScale() throws Exception
214200{
215- final User user = TestContext . get(). getUser();
216-
217201 try
218202 {
219203 List<GWTPropertyDescriptor > props = new ArrayList<> ();
220204 props. add(new GWTPropertyDescriptor (" name" , " string" ));
221205 props. add(new GWTPropertyDescriptor (" prop" , " string" ));
222206 props. add(new GWTPropertyDescriptor (" age" , " int" ));
223207
224- String nameExpression = StringUtils . repeat(" a" , 1000 );
225-
226- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
227- " Samples" , null , props, Collections . emptyList(),
228- - 1 , - 1 , - 1 , - 1 , nameExpression, null );
208+ createSampleType(" Samples" , props, StringUtils . repeat(" a" , 1000 ));
229209 }
230210 catch (ApiUsageException ee)
231211 {
@@ -237,17 +217,13 @@ public void nameExpressionScale() throws Exception
237217@Test
238218public void idColsUnset_nameExpressionNull_noNameProperty() throws Exception
239219{
240- final User user = TestContext . get(). getUser();
241-
242220 try
243221 {
244222 List<GWTPropertyDescriptor > props = new ArrayList<> ();
245223 props. add(new GWTPropertyDescriptor (" notName" , " string" ));
246224 props. add(new GWTPropertyDescriptor (" age" , " int" ));
247225
248- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
249- " Samples" , null , props, Collections . emptyList(),
250- - 1 , - 1 , - 1 , - 1 , null , null );
226+ createSampleType(" Samples" , props, null );
251227 fail(" Expected exception" );
252228 }
253229 catch (ApiUsageException ee)
@@ -260,15 +236,11 @@ public void idColsUnset_nameExpressionNull_noNameProperty() throws Exception
260236@Test
261237public void idColsUnset_nameExpressionNull_hasNameProperty() throws Exception
262238{
263- final User user = TestContext . get(). getUser();
264-
265239 List<GWTPropertyDescriptor > props = new ArrayList<> ();
266240 props. add(new GWTPropertyDescriptor (" name" , " string" ));
267241 props. add(new GWTPropertyDescriptor (" age" , " int" ));
268242
269- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
270- " Samples" , null , props, Collections . emptyList(),
271- - 1 , - 1 , - 1 , - 1 , null , null );
243+ final ExpSampleType st = createSampleType(" Samples" , props, null );
272244
273245 ExpMaterial sample = st. getSample(c, " bob" );
274246 assertNull(sample);
@@ -285,18 +257,12 @@ public void idColsUnset_nameExpressionNull_hasNameProperty() throws Exception
285257@Test
286258public void idColsUnset_nameExpression_hasNameProperty() throws Exception
287259{
288- final User user = TestContext . get(). getUser();
289-
290260 List<GWTPropertyDescriptor > props = new ArrayList<> ();
291261 props. add(new GWTPropertyDescriptor (" name" , " string" ));
292262 props. add(new GWTPropertyDescriptor (" prop" , " string" ));
293263 props. add(new GWTPropertyDescriptor (" age" , " int" ));
294264
295- final String nameExpression = " S-${ prop } .${ age } " ;
296-
297- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
298- " Samples" , null , props, Collections . emptyList(),
299- - 1 , - 1 , - 1 , - 1 , nameExpression, null );
265+ createSampleType(" Samples" , props, " S-${ prop } .${ age } " );
300266}
301267
302268// idCols not null, nameExpression null, no 'name' property -- ok
@@ -364,9 +330,7 @@ public void idColsSet_nameExpressionNull_hasNameProperty() throws Exception
364330 props. add(new GWTPropertyDescriptor (" prop" , " string" ));
365331 props. add(new GWTPropertyDescriptor (" age" , " int" ));
366332
367- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
368- " Samples" , null , props, Collections . emptyList(),
369- 0 , - 1 , - 1 , - 1 , null , null );
333+ final ExpSampleType st = createSampleType(" Samples" , props, null );
370334
371335 final String expectedName1 = " bob" ;
372336 ExpMaterial sample1 = st. getSample(c, expectedName1);
@@ -428,11 +392,7 @@ public void testNameExpression() throws Exception
428392 props. add(new GWTPropertyDescriptor (" age" , " int" ));
429393
430394 final String sampleTypeName = " Samples" ;
431- final String nameExpression = " S-${ prop } .${ age } .${ genId: number(' 000' ) } " ;
432-
433- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
434- sampleTypeName, null , props, Collections . emptyList(),
435- - 1 , - 1 , - 1 , - 1 , nameExpression, null );
395+ final ExpSampleType st = createSampleType(sampleTypeName, props, " S-${ prop } .${ age } .${ genId: number(' 000' ) } " );
436396
437397 final String expectedName1 = " bob" ;
438398 final String expectedName2 = " S-red.11.002" ;
@@ -547,16 +507,12 @@ public void testNameExpression() throws Exception
547507@Test
548508public void testAliases() throws Exception
549509{
550- final User user = TestContext . get(). getUser();
551-
552510 // setup
553511 List<GWTPropertyDescriptor > props = new ArrayList<> ();
554512 props. add(new GWTPropertyDescriptor (" name" , " string" ));
555513 props. add(new GWTPropertyDescriptor (" age" , " int" ));
556514
557- final ExpSampleType st = SampleTypeService . get(). createSampleType(c, user,
558- " Samples" , null , props, Collections . emptyList(),
559- - 1 , - 1 , - 1 , - 1 , null , null );
515+ final ExpSampleType st = createSampleType(" Samples" , props, null );
560516
561517 List<Map<String , Object > > rows = new ArrayList<> ();
562518 Map<String , Object > row = new CaseInsensitiveHashMap<> ();
@@ -584,11 +540,7 @@ public void testBlankRows() throws Exception
584540 props. add(new GWTPropertyDescriptor (" name" , " string" ));
585541 props. add(new GWTPropertyDescriptor (" age" , " int" ));
586542
587- final String nameExpression = " S-${ now: date } -${ dailySampleCount } " ;
588-
589- final ExpSampleTypeImpl st = SampleTypeServiceImpl . get(). createSampleType(c, user,
590- " Samples" , null , props, Collections . emptyList(),
591- - 1 , - 1 , - 1 , - 1 , nameExpression, null );
543+ final ExpSampleType st = createSampleType(" Samples" , props, " S-${ now: date } -${ dailySampleCount } " );
592544
593545 List<? extends ExpMaterial > allSamples = st. getSamples(c);
594546 assertTrue(" Expected no samples" , allSamples. isEmpty());
@@ -685,18 +637,9 @@ public void testUpdateSomeParents() throws Exception
685637 List<GWTPropertyDescriptor > props = new ArrayList<> ();
686638 props. add(new GWTPropertyDescriptor (" name" , " string" ));
687639 props. add(new GWTPropertyDescriptor (" age" , " int" ));
688- final ExpSampleTypeImpl childType = SampleTypeServiceImpl . get(). createSampleType(c, user,
689- " ChildSamples" , null , props, Collections . emptyList(),
690- - 1 , - 1 , - 1 , - 1 , null , null );
691-
692- final ExpSampleTypeImpl parent1Type = SampleTypeServiceImpl . get(). createSampleType(c, user,
693- " Parent1Samples" , null , props, Collections . emptyList(),
694- - 1 , - 1 , - 1 , - 1 , null , null );
695-
696- final ExpSampleTypeImpl parent2Type = SampleTypeServiceImpl . get(). createSampleType(c, user,
697- " Parent2Samples" , null , props, Collections . emptyList(),
698- - 1 , - 1 , - 1 , - 1 , null , null );
699-
640+ final ExpSampleType childType = createSampleType(" ChildSamples" , props, null );
641+ final ExpSampleType parent1Type = createSampleType(" Parent1Samples" , props, null );
642+ final ExpSampleType parent2Type = createSampleType(" Parent2Samples" , props, null );
700643
701644 UserSchema schema = QueryService . get(). getUserSchema(user, c, SchemaKey . fromParts(" Samples" ));
702645 List<Map<String , Object > > rows = new ArrayList<> ();
@@ -827,13 +770,12 @@ public void testParentColAndDataInputDerivation() throws Exception
827770 props. add(new GWTPropertyDescriptor (" data" , " int" ));
828771 props. add(new GWTPropertyDescriptor (" parent" , " string" ));
829772
830- final ExpSampleTypeImpl st = SampleTypeServiceImpl . get(). createSampleType(c, user,
831- " Samples" , null , props, Collections . emptyList(),
832- 0 , - 1 , - 1 , 2 , null , null );
773+ String sampleTypeName = " Samples" ;
774+ final ExpSampleType st = createSampleType(sampleTypeName, props, null );
833775
834776 // insert and derive with both 'parent' column and 'DataInputs/Samples'
835- UserSchema schema = QueryService . get(). getUserSchema(user, c, SchemaKey . fromParts( " Samples " ) );
836- TableInfo table = schema. getTable(" Samples " );
777+ UserSchema schema = QueryService . get(). getUserSchema(user, c, SamplesSchema . SCHEMA_SAMPLES );
778+ TableInfo table = schema. getTable(sampleTypeName );
837779 QueryUpdateService svc = table. getUpdateService();
838780
839781 List<Map<String , Object > > rows = new ArrayList<> ();
@@ -955,6 +897,48 @@ public void testParentColAndDataInputDerivation() throws Exception
955897 assertFalse(oldDerivationRun. getMaterialInputs(). containsKey(E ));
956898 assertFalse(oldDerivationRun. getMaterialOutputs(). contains(D ));
957899 assertTrue(oldDerivationRun. getMaterialOutputs(). contains(E ));
900+
901+ // Issue 43241: Display of dates from Input/Output columns for sample types does not use the project date format
902+ {
903+ var folderProps = LookAndFeelProperties . getWriteableInstance(c);
904+ folderProps. setDefaultDateTimeFormat(" 'kevink' dd-MM-yyyy" );
905+ folderProps. save();
906+
907+ var multiValueColumn = " Outputs/Materials/" + sampleTypeName + " /Created" ;
908+ var url = new ActionURL (" query" , " selectRows" , c);
909+ url. addParameter(QueryParam . schemaName, schema. getName());
910+ url. addParameter(" query." + QueryParam . queryName, sampleTypeName);
911+ url. addParameter(" query." + QueryParam . columns, " Name, " + multiValueColumn);
912+ url. addFilter(" query" , FieldKey . fromParts(" Name" ), CompareType . EQUAL , " A" );
913+ url. addParameter(" includeMetadata" , false );
914+ url. addParameter(" apiVersion" , " 17.1" );
915+
916+ var response = ViewServlet . GET (url, user, null );
917+ assertEquals(200 , response. getStatus());
918+
919+ var json = JsonUtil . DEFAULT_MAPPER. readTree(response. getContentAsString());
920+ var resultRows = json. get(" rows" );
921+ assertEquals(1 , resultRows. size());
922+
923+ var createdValues = resultRows. get(0 ). get(" data" ). get(multiValueColumn);
924+ assertEquals(4 , createdValues. size());
925+
926+ for (var data : createdValues)
927+ {
928+ var value = data. get(" value" ). asText();
929+ assertNotNull(value);
930+
931+ // Formatted with container date format
932+ var formattedValue = data. get(" formattedValue" ). asText();
933+ assertTrue(" Expected date format not applied" , formattedValue. startsWith(" kevink " ));
934+
935+ // Do not care what the JSON format looks like, as long as it is different
936+ assertNotEquals(value, formattedValue);
937+ }
938+
939+ folderProps. clearDefaultDateTimeFormat();
940+ folderProps. save();
941+ }
958942}
959943
960944@Test
@@ -971,12 +955,8 @@ public void testSampleTypeWithVocabularyProperties() throws Exception
971955 Domain mockDomain = helper. createVocabularyTestDomain(user, c);
972956 Map<String , String > vocabularyPropertyURIs = helper. getVocabularyPropertyURIS(mockDomain);
973957
974- // create sample type
975- ExpSampleTypeImpl st = SampleTypeServiceImpl . get(). createSampleType(c, user,
976- sampleName, null , List . of(new GWTPropertyDescriptor (" name" , " string" )), Collections . emptyList(),
977- - 1 , - 1 , - 1 , - 1 , null , null );
978-
979- assertNotNull(st);
958+ // create a sample type
959+ createSampleType(sampleName, List . of(new GWTPropertyDescriptor (" name" , " string" )), null );
980960
981961 UserSchema schema = QueryService . get(). getUserSchema(user, c, SchemaKey . fromParts(" Samples" ));
982962
@@ -1038,9 +1018,7 @@ public void testDetailedAuditLog() throws Exception
10381018 props. add(new GWTPropertyDescriptor (" Name" , " string" ));
10391019 props. add(new GWTPropertyDescriptor (" Measure" , " string" ));
10401020 props. add(new GWTPropertyDescriptor (" Value" , " float" ));
1041- final ExpSampleTypeImpl st = SampleTypeServiceImpl . get(). createSampleType(c, user,
1042- " SamplesDAL" , null , props, Collections . emptyList(),
1043- - 1 , - 1 , - 1 , - 1 , null , null );
1021+ final ExpSampleType st = createSampleType(" SamplesDAL" , props, null );
10441022
10451023 QuerySchema samplesSchema = DefaultSchema . get(user, c, " samples" );
10461024 assertNotNull(samplesSchema);
@@ -1130,10 +1108,8 @@ public void testExpMaterialPermissions() throws Exception
11301108 User user = TestContext . get(). getUser();
11311109 var schema = QueryService . get(). getUserSchema(user, c, ExpSchema . SCHEMA_EXP );
11321110
1133- // create sample type
1134- ExpSampleTypeImpl st = SampleTypeServiceImpl . get(). createSampleType(c, user,
1135- " MySamples" , null , List . of(new GWTPropertyDescriptor (" name" , " string" )), Collections . emptyList(),
1136- - 1 , - 1 , - 1 , - 1 , null , null );
1111+ // create a sample type
1112+ ExpSampleType st = createSampleType(" MySamples" , List . of(new GWTPropertyDescriptor (" name" , " string" )), null );
11371113
11381114 // insert a sample
11391115 var errors = new BatchValidationException ();
@@ -1214,7 +1190,7 @@ public void testInsertOptionUpdate() throws Exception
12141190 props. add(new GWTPropertyDescriptor (longFieldName, " string" ));
12151191
12161192 final String sampleTypeName = " TestSamplesWithRequired" ;
1217- ExpSampleType sampleType = SampleTypeService . get() . createSampleType(c, user, sampleTypeName, null , props, Collections . emptyList(), - 1 , - 1 , - 1 , - 1 , null );
1193+ ExpSampleType sampleType = createSampleType(sampleTypeName, props, null );
12181194
12191195 TableInfo table = getSampleTypeTable(sampleTypeName);
12201196 QueryUpdateService qus = table. getUpdateService();
@@ -1353,6 +1329,11 @@ public void testInsertOptionUpdate() throws Exception
13531329 assertNull(rows. get(2 ). get(" AliquotedFromLSID" ));
13541330}
13551331
1332+ private ExpSampleType createSampleType(String sampleTypeName, List<GWTPropertyDescriptor > props, @Nullable String nameExpression) throws Exception
1333+ {
1334+ return SampleTypeService . get(). createSampleType(c, TestContext . get(). getUser(), sampleTypeName, null , props, emptyList(), - 1 , - 1 , - 1 , - 1 , nameExpression, null );
1335+ }
1336+
13561337private @NotNull TableInfo getSampleTypeTable(String sampleType)
13571338{
13581339 UserSchema schema = QueryService . get(). getUserSchema(TestContext . get(). getUser(), c, SamplesSchema . SCHEMA_SAMPLES );
0 commit comments