Skip to content

Commit 4590fda

Browse files
Merge branch 'develop' into fb_53306_propertyName
2 parents 680d396 + a45c1f4 commit 4590fda

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/org/labkey/test/params/FieldKey.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.commons.lang3.StringUtils;
44
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Nullable;
56

67
import java.util.ArrayList;
78
import java.util.Arrays;
@@ -65,15 +66,22 @@ public static FieldKey fromParts(String... parts)
6566
* @param fieldKey String or FieldKey
6667
* @return FieldKey representation of the String, or the identity if a FieldKey was provided
6768
*/
68-
public static FieldKey fromFieldKey(CharSequence fieldKey)
69+
public static @Nullable FieldKey fromFieldKey(CharSequence fieldKey)
6970
{
7071
if (fieldKey instanceof WrapsFieldKey fk)
7172
{
7273
return fk.getFieldKey();
7374
}
7475
else
7576
{
76-
return fromParts(Arrays.stream(fieldKey.toString().split(SEPARATOR)).map(FieldKey::decodePart).toList());
77+
try
78+
{
79+
return fromParts(Arrays.stream(fieldKey.toString().split(SEPARATOR)).map(FieldKey::decodePart).toList());
80+
}
81+
catch (IllegalArgumentException iae)
82+
{
83+
return null; // FieldReferenceManager depends on this returning null.
84+
}
7785
}
7886
}
7987

src/org/labkey/test/tests/SampleTypeTest.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@
4848
import org.labkey.test.params.FieldDefinition;
4949
import org.labkey.test.params.FieldDefinition.ColumnType;
5050
import org.labkey.test.params.FieldDefinition.LookupInfo;
51+
import org.labkey.test.params.FieldInfo;
5152
import org.labkey.test.params.experiment.SampleTypeDefinition;
5253
import org.labkey.test.tests.study.AssayTest;
5354
import org.labkey.test.util.DataRegionExportHelper;
5455
import org.labkey.test.util.DataRegionTable;
56+
import org.labkey.test.util.EscapeUtil;
5557
import org.labkey.test.util.ExcelHelper;
5658
import org.labkey.test.util.PortalHelper;
5759
import org.labkey.test.util.SampleTypeHelper;
@@ -80,6 +82,7 @@
8082
import static org.junit.Assert.assertNotEquals;
8183
import static org.junit.Assert.assertNotNull;
8284
import static org.junit.Assert.assertTrue;
85+
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;
8386
import static org.labkey.test.util.DataRegionTable.DataRegion;
8487

8588
@Category({Daily.class})
@@ -242,7 +245,47 @@ public void testCreateSampleTypeNoExpression()
242245
sampleTypeHelper.verifyDataValues(data);
243246
}
244247

245-
// Issue 47280: LKSM: Trailing/Leading whitespace in Source name won't resolve when deriving samples
248+
// Issue 53313: LKS doesn't show Sample Type fields with special characters in Custom Properties
249+
@Test
250+
public void testCustomProperties()
251+
{
252+
final String sampleTypeName = "SampleTypeCustomProps" + DOMAIN_TRICKY_CHARACTERS;
253+
FieldInfo stringCol1 = new FieldInfo(TestDataGenerator.randomFieldName("StringColPlain"), ColumnType.String);
254+
FieldInfo stringCol2 = new FieldInfo(TestDataGenerator.randomFieldName("StringCol%"), ColumnType.String);
255+
// Used to make sure the details page shows properties with null values
256+
FieldInfo stringCol3 = new FieldInfo(TestDataGenerator.randomFieldName("StringColNull"), ColumnType.String);
257+
FieldInfo calcCol = new FieldInfo(TestDataGenerator.randomFieldName("CalcCol"), ColumnType.Calculation);
258+
final List<FieldDefinition> fields = List.of(
259+
stringCol1.getFieldDefinition(),
260+
stringCol2.getFieldDefinition(),
261+
stringCol3.getFieldDefinition(),
262+
calcCol.getFieldDefinition().setValueExpression(EscapeUtil.getSqlQuotedValue(stringCol1.getName()) + " || 'Concat'")
263+
);
264+
265+
SampleTypeDefinition sampleTypeDefinition = new SampleTypeDefinition(sampleTypeName).setFields(fields);
266+
267+
SampleTypeAPIHelper.createEmptySampleType(getProjectName(), sampleTypeDefinition);
268+
269+
log("Create a new sample type");
270+
projectMenu().navigateToFolder(PROJECT_NAME, FOLDER_NAME);
271+
SampleTypeHelper sampleTypeHelper = new SampleTypeHelper(this);
272+
sampleTypeHelper.goToSampleType(sampleTypeName);
273+
274+
log("Add a single row to the sample type, with trailing spaces");
275+
Map<String, String> fieldMap = Map.of("Name", "CustomPropsSample", stringCol1.getName(), "PlainValue", stringCol2.getName(), "PercentValue");
276+
sampleTypeHelper.insertRow(fieldMap);
277+
278+
log("Verify custom properties, both name and values, are shown in both the grid and detail pages");
279+
var dataRegion = DataRegionTable.DataRegion(getDriver()).withName("Material").waitFor();
280+
checker().verifyEquals("Row data does not contain expected custom properties", "PlainValue", dataRegion.getDataAsText(0, stringCol1.getLabel()));
281+
checker().verifyEquals("Row data does not contain expected custom properties", "PercentValue", dataRegion.getDataAsText(0, stringCol2.getLabel()));
282+
checker().verifyEquals("Row data does not contain expected custom properties", " ", dataRegion.getDataAsText(0, stringCol3.getLabel()));
283+
checker().verifyEquals("Row data does not contain expected custom properties", "PlainValueConcat", dataRegion.getDataAsText(0, calcCol.getLabel()));
284+
clickAndWait(Locator.linkWithText("CustomPropsSample"));
285+
assertTextPresent(stringCol1.getLabel(), stringCol2.getLabel(), stringCol3.getLabel(), calcCol.getLabel(), "PlainValue", "PercentValue", "PlainValueConcat");
286+
}
287+
288+
// Issue 47280: LKSM: Trailing/Leading whitespace in Source name won't resolve when deriving samples
246289
@Test
247290
public void testImportSamplesWithTrailingSpace()
248291
{

0 commit comments

Comments
 (0)