Skip to content

Commit e694ba8

Browse files
committed
Remove AliquotResolutionDataIterator
1 parent a696506 commit e694ba8

File tree

2 files changed

+27
-124
lines changed

2 files changed

+27
-124
lines changed

experiment/src/org/labkey/experiment/ExpDataIterators.java

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ protected AliquotRollupDataIterator(DataIterator di, DataIteratorContext context
380380
_storedAmountCol = map.get(StoredAmount.name());
381381
_unitsCol = map.get(Units.name());
382382
_sampleStateCol = map.get(SampleState.name());
383-
_aliquotedFromCol = map.get(AliquotResolutionDataIterator.ALIQUOT_FROM_RESOLVED_NAME);
383+
_aliquotedFromCol = map.get(ALIQUOTED_FROM_INPUT);
384384
_rootMaterialRowIdCol = map.get(RootMaterialRowId.name());
385385
_rootIdToRecomputeCol = map.get(ROOT_RECOMPUTE_ROWID_COL);
386386
_parentNameToRecomputeCol = map.get(PARENT_RECOMPUTE_NAME_COL);
@@ -3178,110 +3178,4 @@ public boolean next() throws BatchValidationException
31783178
return true;
31793179
}
31803180
}
3181-
3182-
public static class AliquotResolutionDataIterator extends SimpleTranslator
3183-
{
3184-
public static final String ALIQUOT_FROM_IS_ALIQUOT = "_" + AliquotResolutionDataIterator.class.getName() + "#IsAliquot";
3185-
public static final String ALIQUOT_FROM_RESOLVED_NAME = "_" + AliquotResolutionDataIterator.class.getName() + "#Name";
3186-
public static final String ALIQUOT_FROM_RESOLVED_ROW_ID = "_" + AliquotResolutionDataIterator.class.getName() + "#RowId";
3187-
3188-
final Integer _aliquotFromCol;
3189-
final Integer _aliquotNameCol;
3190-
final Integer _aliquotRowIdCol;
3191-
final Container _container;
3192-
final Integer _isAliquotCol;
3193-
final Map<Integer, ExpMaterial> _materialCache;
3194-
final RemapCache _remapCache;
3195-
final ExpSampleTypeImpl _sampleType;
3196-
final User _user;
3197-
3198-
public AliquotResolutionDataIterator(DataIterator di, DataIteratorContext context, Container container, User user, ExpSampleTypeImpl sampleType)
3199-
{
3200-
super(di, context);
3201-
selectAll();
3202-
3203-
_container = container;
3204-
_sampleType = sampleType;
3205-
_user = user;
3206-
3207-
var columnNameMap = getColumnNameMap();
3208-
_aliquotFromCol = columnNameMap.get(ALIQUOTED_FROM_INPUT);
3209-
boolean hasAliquotFromCol = _aliquotFromCol != null;
3210-
3211-
_materialCache = hasAliquotFromCol ? new HashMap<>() : null;
3212-
_remapCache = hasAliquotFromCol ? new RemapCache() : null;
3213-
_isAliquotCol = addColumn(new BaseColumnInfo(ALIQUOT_FROM_IS_ALIQUOT, JdbcType.BOOLEAN), (Supplier<Boolean>)() -> hasAliquotFromCol);
3214-
3215-
if (hasAliquotFromCol)
3216-
{
3217-
_aliquotNameCol = addColumn(new BaseColumnInfo(ALIQUOT_FROM_RESOLVED_NAME, JdbcType.VARCHAR), (Supplier<String>)() -> null);
3218-
_aliquotRowIdCol = addColumn(new BaseColumnInfo(ALIQUOT_FROM_RESOLVED_ROW_ID, JdbcType.INTEGER), (Supplier<Integer>)() -> null);
3219-
}
3220-
else
3221-
{
3222-
_aliquotNameCol = null;
3223-
_aliquotRowIdCol = null;
3224-
}
3225-
}
3226-
3227-
@Override
3228-
public boolean next() throws BatchValidationException
3229-
{
3230-
boolean hasNext = super.next();
3231-
3232-
if (hasNext && _aliquotFromCol != null)
3233-
{
3234-
Object aliquotedFromObj = get(_aliquotFromCol);
3235-
if (aliquotedFromObj != null)
3236-
{
3237-
String aliquotedFrom = null;
3238-
if (aliquotedFromObj instanceof String aliquotStr)
3239-
{
3240-
// Issue 45563: We need the AliquotedFrom name to be quoted so we can properly find the parent,
3241-
// but we don't want to include the quotes in the name we generate using AliquotedFrom
3242-
aliquotedFrom = StringUtilsLabKey.unquoteString(aliquotStr).trim();
3243-
}
3244-
else if (aliquotedFromObj instanceof Number)
3245-
{
3246-
// Issue 53153: support "RowId" as value for "AliquotedFrom"
3247-
aliquotedFrom = aliquotedFromObj.toString();
3248-
}
3249-
3250-
boolean isAliquot = !StringUtils.isEmpty(aliquotedFrom);
3251-
_row[_isAliquotCol] = isAliquot;
3252-
3253-
if (isAliquot)
3254-
{
3255-
try
3256-
{
3257-
ExpMaterial aliquotParent = ExperimentService.get().findExpMaterial(_container, _user, aliquotedFrom, _sampleType, _remapCache, _materialCache);
3258-
if (aliquotParent != null)
3259-
{
3260-
// This is put into a collection to indicate that this is a processed name that does
3261-
// not need to be escaped with quotes, etc. which avoids the complexities of the
3262-
// default name string handling.
3263-
_row[_aliquotNameCol] = List.of(aliquotParent.getName());
3264-
_row[_aliquotRowIdCol] = aliquotParent.getRowId();
3265-
}
3266-
else
3267-
{
3268-
// The referenced sample may not exist yet (e.g. it may be created in the same import)
3269-
_row[_aliquotNameCol] = aliquotedFromObj.toString();
3270-
}
3271-
}
3272-
catch (ValidationException e)
3273-
{
3274-
addRowError(e.getMessage());
3275-
}
3276-
}
3277-
}
3278-
else
3279-
{
3280-
_row[_isAliquotCol] = false;
3281-
}
3282-
}
3283-
3284-
return hasNext;
3285-
}
3286-
}
32873181
}

experiment/src/org/labkey/experiment/api/SampleTypeUpdateServiceDI.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@
151151
import static org.labkey.api.exp.query.ExpMaterialTable.Column.StoredAmount;
152152
import static org.labkey.api.exp.query.ExpMaterialTable.Column.Units;
153153
import static org.labkey.api.exp.query.SamplesSchema.SCHEMA_SAMPLES;
154-
import static org.labkey.experiment.ExpDataIterators.AliquotResolutionDataIterator.ALIQUOT_FROM_IS_ALIQUOT;
155-
import static org.labkey.experiment.ExpDataIterators.AliquotResolutionDataIterator.ALIQUOT_FROM_RESOLVED_NAME;
156154
import static org.labkey.experiment.ExpDataIterators.incrementCounts;
157155
import static org.labkey.experiment.api.SampleTypeServiceImpl.SampleChangeType.insert;
158156
import static org.labkey.experiment.api.SampleTypeServiceImpl.SampleChangeType.rollup;
@@ -1102,7 +1100,7 @@ private record ExistingRowSelect(TableInfo tableInfo, Set<String> columns, boole
11021100
remap = CaseInsensitiveHashMap.of();
11031101

11041102
// AliquotRollupDataIterator needs "samplestate", "storedamount", "rootmaterialrowId", "units" for MERGE option
1105-
Set<String> includedColumns = new CaseInsensitiveHashSet("name", "lsid", "rowid", "samplestate", "storedamount", "rootmaterialrowId", "units");
1103+
Set<String> includedColumns = new CaseInsensitiveHashSet(Name.name(), LSID.name(), RowId.name(), SampleState.name(), StoredAmount.name(), RootMaterialRowId.name(), Units.name());
11061104
for (ColumnInfo column : getQueryTable().getColumns())
11071105
{
11081106
if (dataColumns.contains(column.getColumnName()))
@@ -1533,9 +1531,6 @@ public DataIterator getDataIterator(DataIteratorContext context)
15331531
DataIteratorBuilder dib = ExpDataIterators.CounterDataIteratorBuilder.create(dataIterator, sampleType.getContainer(), materialTable, ExpSampleType.SEQUENCE_PREFIX, sampleType.getRowId());
15341532
dataIterator = dib.getDataIterator(context);
15351533

1536-
// AliquotedFrom resolution
1537-
dataIterator = LoggingDataIterator.wrap(new ExpDataIterators.AliquotResolutionDataIterator(dataIterator, context, container, user, sampleType));
1538-
15391534
// sampleset.createSampleNames() + generate lsid
15401535
// TODO: does not handle insertIgnore
15411536
DataIterator names = new _GenerateNamesDataIterator(sampleType, container, user, DataIteratorUtil.wrapMap(dataIterator, false), context, batchSize);
@@ -1681,6 +1676,25 @@ protected void processNextInput()
16811676
{
16821677
Map<String, Object> map = new HashMap<>(((MapDataIterator)getInput()).getMap());
16831678

1679+
String aliquotedFrom = null;
1680+
Object aliquotedFromObj = map.get(ExpMaterial.ALIQUOTED_FROM_INPUT);
1681+
if (aliquotedFromObj != null)
1682+
{
1683+
if (aliquotedFromObj instanceof String)
1684+
{
1685+
// Issue 45563: We need the AliquotedFrom name to be quoted so we can properly find the parent,
1686+
// but we don't want to include the quotes in the name we generate using AliquotedFrom
1687+
aliquotedFrom = StringUtilsLabKey.unquoteString((String) aliquotedFromObj).trim();
1688+
map.put(ExpMaterial.ALIQUOTED_FROM_INPUT, aliquotedFrom);
1689+
}
1690+
else if (aliquotedFromObj instanceof Number)
1691+
{
1692+
aliquotedFrom = aliquotedFromObj.toString();
1693+
}
1694+
}
1695+
1696+
boolean isAliquot = !StringUtils.isEmpty(aliquotedFrom);
1697+
16841698
try
16851699
{
16861700
Object currNameObj = map.get("Name");
@@ -1710,19 +1724,14 @@ protected void processNextInput()
17101724
catch (NameGenerator.NameGenerationException e)
17111725
{
17121726
// Failed to generate a name due to some part of the expression not in the row
1713-
if ((boolean) map.getOrDefault(ALIQUOT_FROM_IS_ALIQUOT, false))
1714-
{
1727+
if (isAliquot)
17151728
addRowError("Failed to generate name for aliquot on row " + e.getRowNumber() + " using aliquot naming pattern " + _sampleType.getAliquotNameExpression() + ". Check the syntax of the aliquot naming pattern and the data values for the aliquot.");
1716-
}
1729+
else if (_sampleType.hasNameExpression())
1730+
addRowError("Failed to generate name for sample on row " + e.getRowNumber() + " using naming pattern " + _sampleType.getNameExpression() + ". Check the syntax of the naming pattern and the data values for the sample.");
1731+
else if (_sampleType.hasNameAsIdCol())
1732+
addRowError("SampleID or Name is required for sample on row " + e.getRowNumber());
17171733
else
1718-
{
1719-
if (_sampleType.hasNameExpression())
1720-
addRowError("Failed to generate name for sample on row " + e.getRowNumber() + " using naming pattern " + _sampleType.getNameExpression() + ". Check the syntax of the naming pattern and the data values for the sample.");
1721-
else if (_sampleType.hasNameAsIdCol())
1722-
addRowError("SampleID or Name is required for sample on row " + e.getRowNumber());
1723-
else
1724-
addRowError("All id columns are required for sample on row " + e.getRowNumber());
1725-
}
1734+
addRowError("All id columns are required for sample on row " + e.getRowNumber());
17261735
}
17271736
}
17281737

0 commit comments

Comments
 (0)