Skip to content

Commit 0dcb815

Browse files
committed
Merge branch 'develop' into fb_tippy
2 parents 92f7230 + cc399aa commit 0dcb815

69 files changed

Lines changed: 1351 additions & 414 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/messages/Validation.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ UniqueViolationError=The value of the {0} field conflicts with another value in
1010
typeMismatch=This value could not be converted
1111
typeMismatch.int=Please enter a valid integer value
1212
typeMismatch.double=Please enter a valid floating point number
13-
tyepMismatch.Date=Please enter a valid date
1413
requiredError=This field is required
1514
uniqueConstraint=Value conflicts with existing data. Please enter a unique value.

api/src/org/labkey/api/action/BaseApiAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private FormAndErrors<FORM> populateForm() throws Exception
312312
if (null != contentType)
313313
{
314314
if (MimeMap.DEFAULT.isJsonContentTypeHeader(contentType))
315-
{
315+
{
316316
_reqFormat = ApiResponseWriter.Format.JSON;
317317
return populateJsonForm();
318318
}

api/src/org/labkey/api/admin/AdminUrls.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public interface AdminUrls extends UrlProvider
6565
ActionURL getSessionLoggingURL();
6666
ActionURL getTrackedAllocationsViewerURL();
6767
ActionURL getSystemMaintenanceURL();
68+
ActionURL getCspReportToURL(String cspVersion);
6869

6970
/**
7071
* Simply adds an "Admin Console" link to nav trail if invoked in the root container. Otherwise, root is unchanged.

api/src/org/labkey/api/assay/actions/AssayRunUploadForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ else if (AbstractAssayProvider.PARTICIPANT_VISIT_RESOLVER_PROPERTY_NAME.equals(k
509509
ColumnInfo pk = pks.get(0);
510510
try
511511
{
512-
Object filterValue = ConvertUtils.convert(value, pk.getJavaClass());
512+
Object filterValue = pk.convert(value);
513513
SimpleFilter filter = new SimpleFilter(pk.getFieldKey(), filterValue);
514514
Set<String> cols = new HashSet<>();
515515
cols.add(lookupTable.getTitleColumn());

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,4 +848,10 @@ public boolean isMultiValued()
848848
{
849849
return delegate.isMultiValued();
850850
}
851+
852+
@Override @Transient
853+
public final SimpleConvert getConvertFn()
854+
{
855+
return ColumnRenderProperties.getDefaultConvertFn(this);
856+
}
851857
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.util.Map;
7676
import java.util.Objects;
7777
import java.util.Set;
78+
import java.util.concurrent.atomic.AtomicReference;
7879
import java.util.stream.Collectors;
7980

8081
/**
@@ -1461,7 +1462,10 @@ public String toString()
14611462
@Override
14621463
public boolean isRequiredForInsert(@Nullable DomainProperty dp)
14631464
{
1464-
if (isCalculated() || !isUserEditable() || isAutoIncrement() || isVersionColumn() || null != getJdbcDefaultValue())
1465+
if (isCalculated() || !isUserEditable() || isAutoIncrement() || isVersionColumn())
1466+
return false;
1467+
// ARRAY may have DEFAULT [] which does not satisfy our isRequired() constraint
1468+
if (!JdbcType.ARRAY.equals(getJdbcType()) && null != getJdbcDefaultValue())
14651469
return false;
14661470
return !isNullable() || (null != dp && dp.isRequired());
14671471
}
@@ -2229,4 +2233,10 @@ public void setRemapMissingBehavior(SimpleTranslator.RemapMissingBehavior missin
22292233
{
22302234
_remapMissingBehavior = missingBehavior;
22312235
}
2236+
2237+
@Override @Transient
2238+
public final SimpleConvert getConvertFn()
2239+
{
2240+
return ColumnRenderProperties.getDefaultConvertFn(this);
2241+
}
22322242
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ else if (o instanceof Map)
124124
}
125125

126126
@Override
127-
protected Class<?> getTruePropType(String propName)
127+
protected SimpleConvert getSimpleConvert(String propName)
128128
{
129-
var ret = _dynaClass.getTruePropType(propName);
130-
if (null == ret)
131-
ret = super.getTruePropType(propName);
132-
return ret;
129+
var type = _dynaClass.getTruePropType(propName);
130+
if (null != type)
131+
{
132+
return ConvertHelper.getSimpleConvert(type);
133+
}
134+
return super.getSimpleConvert(propName);
133135
}
134136

135137
// DynaBean
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
<%@ page import="org.labkey.api.data.JdbcType" %>
2+
<%@ page import="org.junit.Test" %>
3+
<%@ page import="static org.junit.Assert.*" %>
4+
<%@ page import="org.labkey.api.data.BaseColumnInfo" %>
5+
<%@ page import="org.jetbrains.annotations.NotNull" %>
6+
<%@ page import="java.math.BigDecimal" %>
7+
<%@ page import="org.labkey.api.exp.PropertyType" %>
8+
<%@ page import="org.labkey.api.ontology.Quantity" %>
9+
<%@ page import="org.labkey.api.ontology.Unit" %>
10+
<%@ page import="org.labkey.api.ontology.KindOfQuantity" %>
11+
<%@ page import="org.labkey.api.data.MutableColumnInfo" %>
12+
<%@ page import="org.labkey.api.data.WrappedColumnInfo" %>
13+
<%@ page import="org.apache.commons.beanutils.ConversionException" %>
14+
<%@ page import="org.labkey.api.data.ColumnInfo" %>
15+
<%@ page import="org.labkey.api.data.dialect.SqlDialect" %>
16+
<%@ page import="org.labkey.api.data.CoreSchema" %>
17+
<%@ page import="java.nio.ByteBuffer" %>
18+
<%@ page extends="org.labkey.api.jsp.JspTest.BVT" %>
19+
<%--
20+
This tests uses MockRequest to test some expected Headers and Meta tags for various types of requests.
21+
--%>
22+
<%!
23+
void testConvert(ColumnInfo col, Object expected, Object val)
24+
{
25+
var result = col.convert(val);
26+
assertNotNull(result);
27+
//assertEquals(col.getJdbcType().getJavaClass(), result.getClass());
28+
assertEquals(expected, result);
29+
}
30+
31+
void testConvertsToNull(ColumnInfo col, Object val)
32+
{
33+
var result = col.convert(val);
34+
assertNull(result);
35+
}
36+
37+
void testConversionException(ColumnInfo col, Object val)
38+
{
39+
try
40+
{
41+
col.convert(val);
42+
fail();
43+
}
44+
catch (ConversionException x)
45+
{
46+
return;
47+
}
48+
}
49+
50+
void testConvert(JdbcType type, Object expected, Object val)
51+
{
52+
var col = new BaseColumnInfo("~", null, type);
53+
testConvert(col.lock(), expected, val);
54+
}
55+
56+
void testConvertsToNull(JdbcType type, Object val)
57+
{
58+
var col = new BaseColumnInfo("~", null, type);
59+
testConvertsToNull(col.lock(), val);
60+
}
61+
62+
void testConversionException(JdbcType type, Object val)
63+
{
64+
var col = new BaseColumnInfo("~", null, type);
65+
testConversionException(col.lock(), val);
66+
}
67+
68+
void testConvert(PropertyType pt, Object expected, @NotNull Object val)
69+
{
70+
var col = new BaseColumnInfo("~", null, pt.getJdbcType());
71+
col.setPropertyType(pt);
72+
testConvert(col.lock(), expected, val);
73+
}
74+
75+
void testConvertsToNull(PropertyType pt, Object val)
76+
{
77+
var col = new BaseColumnInfo("~", null, pt.getJdbcType());
78+
col.setPropertyType(pt);
79+
testConvertsToNull(col.lock(), val);
80+
}
81+
82+
void testConversionException(PropertyType pt, Object val)
83+
{
84+
var col = new BaseColumnInfo("~", null, pt.getJdbcType());
85+
col.setPropertyType(pt);
86+
testConversionException(col.lock(), val);
87+
}
88+
89+
void testQuantity(Unit displayUnit, Quantity expected, Object value)
90+
{
91+
// UNDONE: setDisplayUnit is NYI???
92+
var col = new BaseColumnInfo("~", null, JdbcType.DOUBLE)
93+
{
94+
@Override
95+
public Unit getDisplayUnit()
96+
{
97+
return displayUnit;
98+
}
99+
100+
@Override
101+
public KindOfQuantity getKindOfQuantity()
102+
{
103+
return null==displayUnit ? null : displayUnit.getKindOfQuantity();
104+
}
105+
};
106+
testConvert(col.lock(), expected, value);
107+
}
108+
109+
110+
/** This test is for the integrated ColumnInfo.convert() logic.
111+
* <p></p>
112+
* A lot of this testing is redundant with lower-level unit testing,
113+
* however, this still serves as a basic conversion smoke test.
114+
* <p></p>
115+
* In particular, the PropertyType conversions are pretty
116+
* redundant with ConvertHelper.convert() and JdbcType.convert()
117+
* (PropertyType predates JdbcType), but there are some differences
118+
* in implementation. We should try to reconcile these differences.
119+
*/
120+
@Test
121+
public void testColumnConvert() throws Exception
122+
{
123+
// see also ConvertHelper.testEmpty()
124+
125+
// w/o propertyType
126+
for (JdbcType type : JdbcType.values())
127+
{
128+
switch (type)
129+
{
130+
case BIGINT ->
131+
{
132+
testConvert(type, Long.valueOf(5), Integer.valueOf(5));
133+
testConvert(type, Long.valueOf(5), "5");
134+
testConvert(type, Long.valueOf(5), Double.valueOf(5.00000));
135+
testConversionException(type, Double.valueOf(5.00001));
136+
testConvert(type, Long.valueOf(5), new BigDecimal("5.000"));
137+
testConversionException(type, new BigDecimal("5.001"));
138+
testConversionException(type, "5g");
139+
testConvertsToNull(type, "");
140+
testConvertsToNull(type, null);
141+
}
142+
case BINARY, LONGVARBINARY, VARBINARY ->
143+
{
144+
}
145+
case BOOLEAN -> {}
146+
case CHAR,LONGVARCHAR,VARCHAR ->
147+
{
148+
testConvertsToNull(type, null);
149+
// NOTE StandardDataIterator optionally trims, but convert() does not.
150+
// see SimpleTranslator.createConvertColumn()
151+
testConvert(type, " no trim ", " no trim ");
152+
// JdbcType does not convert empty string to null, ColumnInfo.convert() and PropertyType.conver() do
153+
assertNull("", type.convert(""));
154+
testConvertsToNull(type, "");
155+
testConvertsToNull(type, null);
156+
}
157+
case DECIMAL -> {}
158+
case DOUBLE -> {}
159+
case INTEGER -> {}
160+
case REAL -> {}
161+
case SMALLINT, TINYINT -> {}
162+
case DATE -> {}
163+
case TIME -> {}
164+
case TIMESTAMP -> {}
165+
case GUID -> {}
166+
case ARRAY, NULL, OTHER -> { /* ignore */ }
167+
default -> fail("We missed a JdbcType: " + type.name());
168+
}
169+
}
170+
171+
// testArray()
172+
173+
// w/ propertyType
174+
for (var type : PropertyType.values())
175+
{
176+
switch (type)
177+
{
178+
case BOOLEAN -> {}
179+
case STRING ->
180+
{
181+
testConvertsToNull(type, null);
182+
testConvertsToNull(type, "");
183+
testConvert(type, " no trim ", " no trim ");
184+
}
185+
case MULTI_LINE ->
186+
{
187+
testConvertsToNull(type, null);
188+
testConvertsToNull(type, "");
189+
testConvert(type, " no trim ", " no trim ");
190+
}
191+
case MULTI_CHOICE -> {}
192+
case RESOURCE -> {}
193+
case INTEGER -> {}
194+
case BIGINT ->
195+
{
196+
testConvert(type, Long.valueOf(5), Integer.valueOf(5));
197+
testConvert(type, Long.valueOf(5), "5");
198+
testConversionException(type, new BigDecimal("5.001"));
199+
testConvertsToNull(type, null);
200+
testConvertsToNull(type, "");
201+
testConversionException(type, "5g");
202+
}
203+
case BINARY -> {}
204+
case FILE_LINK -> {}
205+
case ATTACHMENT -> {}
206+
case DATE_TIME -> {}
207+
case DATE -> {}
208+
case TIME -> {}
209+
case DOUBLE -> {}
210+
case FLOAT -> {}
211+
case DECIMAL -> {}
212+
case XML_TEXT -> {}
213+
default -> fail("We missed a PropertyType: " + type.name());
214+
}
215+
}
216+
217+
// Quantity
218+
Unit unit = Unit.kg;
219+
testQuantity(unit, Quantity.of(5000,unit.getBase()), "5");
220+
}
221+
222+
223+
public void testLocked(MutableColumnInfo col)
224+
{
225+
col.setAlias("!");
226+
col.lock();
227+
try
228+
{
229+
col.setAlias("!");
230+
fail("not locked?");
231+
}
232+
catch (IllegalStateException x)
233+
{
234+
// success
235+
}
236+
}
237+
238+
static class _ColumnInfo extends BaseColumnInfo
239+
{
240+
_ColumnInfo()
241+
{
242+
super("~", JdbcType.INTEGER);
243+
}
244+
245+
@Override
246+
public SqlDialect getSqlDialect()
247+
{
248+
return CoreSchema.getInstance().getSqlDialect();
249+
}
250+
}
251+
252+
@Test
253+
public void testLocked()
254+
{
255+
testLocked(new _ColumnInfo());
256+
testLocked(WrappedColumnInfo.wrap(new _ColumnInfo()));
257+
}
258+
%>

0 commit comments

Comments
 (0)