Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions api/src/org/labkey/api/data/AbstractWrappedColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,4 @@ public boolean isMultiValued()
{
return delegate.isMultiValued();
}

@Override @Transient
public final SimpleConvert getConvertFn()
{
return ColumnRenderProperties.getDefaultConvertFn(this);
}
}
7 changes: 0 additions & 7 deletions api/src/org/labkey/api/data/BaseColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -2233,10 +2232,4 @@ public void setRemapMissingBehavior(SimpleTranslator.RemapMissingBehavior missin
{
_remapMissingBehavior = missingBehavior;
}

@Override @Transient
public final SimpleConvert getConvertFn()
{
return ColumnRenderProperties.getDefaultConvertFn(this);
}
}
25 changes: 25 additions & 0 deletions api/src/org/labkey/api/data/ColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.api.data;

import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -457,6 +458,30 @@ static String toString(ColumnInfo col)

return sb.toString();
}

/// The returned Function<Object,Object> should throw ConversionException (undeclared RuntimeException).
/// This method does not handle compound conversions e.g. MissingValues or Out-of-range indicators.
/// Also, converting the pieces of a MVFK column is handled by QUS.
@Override
@Transient
default SimpleConvert getConvertFn()
{
return getDefaultConvertFn(this);
}

@Override
default Object convert(Object o) throws ConversionException
{
return getConvertFn().convert(o);
}

static SimpleConvert getDefaultConvertFn(ColumnInfo col)
{
// NOTE for MultiValued columns e.g. col.isMultiValued() || col.getFk() instanceof MultiValuedForeignKey
// MultiValuedDisplayColumn currently relies on the parent fk column hanldling convert from String to the element type (see MultiValuedRenderContext.get())
// However, This behavior is obviously wrong for MVFC that support insert/update, callers must be aware of this unfortunately (e.g. TableViewForm and CoerceDataIterator)
return ColumnRenderProperties.getDefaultConvertFn(col);
}
}


4 changes: 2 additions & 2 deletions api/src/org/labkey/api/data/MultiChoice.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map)
}


public static class Converter implements org.apache.commons.beanutils.Converter, Function<Object,Object>
public static class Converter implements org.apache.commons.beanutils.Converter, SimpleConvert
{
private Converter()
{
Expand Down Expand Up @@ -558,7 +558,7 @@ public <T> T convert(Class<T> aClass, Object o)
}

@Override
final public Object apply(Object o)
final public Object convert(Object o)
{
return convert(MultiChoice.Array.class, o);
}
Expand Down
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/data/SimpleConvert.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ default SimpleConvert getConvertFn()
{
return this;
}

SimpleConvert identity = (v) -> v;
}
9 changes: 1 addition & 8 deletions api/src/org/labkey/api/data/TableViewForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,9 @@ protected void _populateValues(BindException errors)

try
{
Object val;
if (col != null)
{
propType = col.getJavaClass();
val = col.convert(bindValue);
}
else
{
val = getSimpleConvert(propName).convert(bindValue);
}
Object val = getSimpleConvert(propName).convert(bindValue);

boolean requiredError = false;
if (_validateRequired && null != _tinfo && null != col && col.isRequired() && !col.isAutoIncrement())
Expand Down