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
30 changes: 5 additions & 25 deletions api/src/org/labkey/api/dataiterator/SimpleTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.labkey.api.data.TableSelector;
import org.labkey.api.data.TestSchema;
import org.labkey.api.exp.MvFieldWrapper;
import org.labkey.api.exp.PropertyDescriptor;
import org.labkey.api.exp.PropertyType;
import org.labkey.api.files.FileContentService;
import org.labkey.api.ontology.Unit;
Expand Down Expand Up @@ -486,28 +485,24 @@ protected class DerivationScopedConvertColumn extends SimpleConvertColumn
final int derivationDataColInd;
final int index;
final boolean isDerivation;
final String presentDerivationWarning;
final String presentNonDerivationWarning;

final SimpleConvertColumn _convertCol;

public DerivationScopedConvertColumn(int index, SimpleConvertColumn convertCol, int derivationDataColInd, boolean isDerivation, @Nullable String presentDerivationWarning, @Nullable String presentNonDerivationWarning)
public DerivationScopedConvertColumn(int index, SimpleConvertColumn convertCol, int derivationDataColInd, boolean isDerivation)
{
super(convertCol.fieldName, convertCol.index, convertCol.type, convertCol.defaultUnit);
_convertCol = convertCol;
this.index = index;
this.derivationDataColInd = derivationDataColInd;
this.isDerivation = isDerivation;
this.presentDerivationWarning = presentDerivationWarning;
this.presentNonDerivationWarning = presentNonDerivationWarning;
}

@Override
protected Object convert(Object o)
{
Object thisValue = _convertCol.convert(o);

return getDerivationData(thisValue, derivationDataColInd, isDerivation, presentDerivationWarning, presentNonDerivationWarning);
return getDerivationData(thisValue, derivationDataColInd, isDerivation);

}
}
Expand All @@ -520,48 +515,33 @@ protected class DerivationScopedColumn implements Supplier
final int index;
final boolean isDerivation;

final String presentDerivationWarning;
final String presentNonDerivationWarning;

public DerivationScopedColumn(int index, int derivationDataColInd, boolean isDerivation, @Nullable String presentDerivationWarning, @Nullable String presentNonDerivationWarning)
public DerivationScopedColumn(int index, int derivationDataColInd, boolean isDerivation)
{
this.index = index;
this.derivationDataColInd = derivationDataColInd;
this.isDerivation = isDerivation;
this.presentDerivationWarning = presentDerivationWarning;
this.presentNonDerivationWarning = presentNonDerivationWarning;
}

@Override
public Object get()
{
Object thisValue = _data.get(index);
return getDerivationData(thisValue, derivationDataColInd, isDerivation, presentDerivationWarning, presentNonDerivationWarning);
return getDerivationData(thisValue, derivationDataColInd, isDerivation);
}
}

/**
* @param thisValue the original field value
* @param derivationDataColInd the col index for the field used to determine if a record is child or parent
* @param isDerivationField if this field is a child only field
* @param presentDerivationWarning the warning msg to log if a child field is present for a parent record
* @param presentNonDerivationWarning the warning msg to log if a parent field is present for a child record
*/
private Object getDerivationData(Object thisValue, int derivationDataColInd, boolean isDerivationField, @Nullable String presentDerivationWarning, @Nullable String presentNonDerivationWarning)
private Object getDerivationData(Object thisValue, int derivationDataColInd, boolean isDerivationField)
{
Object derivationData = derivationDataColInd < 0 ? null : _data.get(derivationDataColInd);
if ((isDerivationField && derivationData != null)
|| (!isDerivationField && derivationData == null))
return thisValue;

if (thisValue != null)
{
if (isDerivationField && presentDerivationWarning != null)
LOG.warn(presentDerivationWarning);
else if (!isDerivationField && presentNonDerivationWarning != null)
LOG.warn(presentNonDerivationWarning);
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1753,9 +1753,6 @@ private boolean rowExists(String name)

static class _SamplesCoerceDataIterator extends SimpleTranslator
{
private static final String INVALID_ALIQUOT_PROPERTY = "An aliquot-specific property [%1$s] value has been ignored for a non-aliquot sample.";
private static final String INVALID_NON_ALIQUOT_PROPERTY = "A sample property [%1$s] value has been ignored for an aliquot.";

private final ExpSampleTypeImpl _sampleType;
private final Unit _sampleTypeBaseUnit;

Expand Down Expand Up @@ -1810,14 +1807,12 @@ else if (amountImportAliasSet.contains(from.getName()))
String name = to.getName();
boolean isScopedField = scopedFields.containsKey(name);

String ignoredAliquotPropValue = String.format(INVALID_ALIQUOT_PROPERTY, name);
String ignoredMetaPropValue = String.format(INVALID_NON_ALIQUOT_PROPERTY, name);
if (to.getPropertyType() == PropertyType.ATTACHMENT || to.getPropertyType() == PropertyType.FILE_LINK)
{
if (isScopedField)
{
ColumnInfo clone = new BaseColumnInfo(to);
addColumn(clone, new DerivationScopedColumn(i, aliquotedFromDataColInd, scopedFields.get(name), ignoredAliquotPropValue, ignoredMetaPropValue));
addColumn(clone, new DerivationScopedColumn(i, aliquotedFromDataColInd, scopedFields.get(name)));
}
else
addColumn(to, i);
Expand All @@ -1829,7 +1824,7 @@ else if (to.isMultiValued() || to.getFk() instanceof MultiValuedForeignKey)
{
var col = new BaseColumnInfo(getInput().getColumnInfo(i));
col.setName(name);
addColumn(col, new DerivationScopedColumn(i, aliquotedFromDataColInd, scopedFields.get(name), ignoredAliquotPropValue, ignoredMetaPropValue));
addColumn(col, new DerivationScopedColumn(i, aliquotedFromDataColInd, scopedFields.get(name)));
}
else
addColumn(to.getName(), i);
Expand Down Expand Up @@ -1900,7 +1895,7 @@ private void _addConvertColumn(String name, int fromIndex, JdbcType toType, @Nul
private void _addConvertColumn(ColumnInfo col, int fromIndex, int derivationDataColInd, boolean isAliquotField)
{
SimpleConvertColumn c = createConvertColumn(col, fromIndex, RemapMissingBehavior.Error);
c = new DerivationScopedConvertColumn(fromIndex, c, derivationDataColInd, isAliquotField, String.format(INVALID_ALIQUOT_PROPERTY, col.getName()), String.format(INVALID_NON_ALIQUOT_PROPERTY, col.getName()));
c = new DerivationScopedConvertColumn(fromIndex, c, derivationDataColInd, isAliquotField);

addColumn(col, c);
}
Expand Down