Skip to content
20 changes: 13 additions & 7 deletions api/src/org/labkey/api/assay/AbstractAssayTsvDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public void importFile(@NotNull ExpData data, File dataFile, @NotNull ViewBackgr

@Override
public void importFile(@NotNull ExpData data, File dataFile, @NotNull ViewBackgroundInfo info, @NotNull Logger log, @NotNull XarContext context, boolean allowLookupByAlternateKey) throws ExperimentException
{
importFile(data, dataFile, info, log, context, allowLookupByAlternateKey, false);
}

@Override
public void importFile(@NotNull ExpData data, File dataFile, @NotNull ViewBackgroundInfo info, @NotNull Logger log, @NotNull XarContext context, boolean allowLookupByAlternateKey, boolean autoFillDefaultResultColumns) throws ExperimentException
{
ExpProtocolApplication sourceApplication = data.getSourceApplication();
if (sourceApplication == null)
Expand All @@ -140,7 +146,7 @@ public void importFile(@NotNull ExpData data, File dataFile, @NotNull ViewBackgr
assert(rawData.size() <= 1);
try
{
importRows(data, info.getUser(), run, protocol, provider, rawData.values().iterator().next(), settings);
importRows(data, info.getUser(), run, protocol, provider, rawData.values().iterator().next(), settings, autoFillDefaultResultColumns);
}
catch (ValidationException e)
{
Expand All @@ -153,7 +159,7 @@ public void importTransformDataMap(ExpData data, AssayRunUploadContext context,
try
{
DataLoaderSettings settings = new DataLoaderSettings();
importRows(data, context.getUser(), run, context.getProtocol(), context.getProvider(), dataMap, settings);
importRows(data, context.getUser(), run, context.getProtocol(), context.getProvider(), dataMap, settings, context.shouldAutoFillDefaultResultColumns());
}
catch (ValidationException e)
{
Expand Down Expand Up @@ -420,10 +426,10 @@ public void beforeDeleteData(List<ExpData> data, User user) throws ExperimentExc
public void importRows(ExpData data, User user, ExpRun run, ExpProtocol protocol, AssayProvider provider, List<Map<String, Object>> rawData)
throws ExperimentException, ValidationException
{
importRows(data, user, run, protocol, provider, rawData, null);
importRows(data, user, run, protocol, provider, rawData, null, false);
}

public void importRows(ExpData data, User user, ExpRun run, ExpProtocol protocol, AssayProvider provider, List<Map<String, Object>> rawData, @Nullable DataLoaderSettings settings)
public void importRows(ExpData data, User user, ExpRun run, ExpProtocol protocol, AssayProvider provider, List<Map<String, Object>> rawData, @Nullable DataLoaderSettings settings, boolean autoFillDefaultResultColumns)
throws ExperimentException, ValidationException
{
if (settings == null)
Expand Down Expand Up @@ -458,7 +464,7 @@ public void importRows(ExpData data, User user, ExpRun run, ExpProtocol protocol

// Insert the data into the assay's data table.
// On insert, the raw data will have the provisioned table's rowId added to the list of maps
List<Map<String, Object>> inserted = insertRowData(data, user, container, run, protocol, provider, dataDomain, fileData, dataTable);
List<Map<String, Object>> inserted = insertRowData(data, user, container, run, protocol, provider, dataDomain, fileData, dataTable, autoFillDefaultResultColumns/* only popuate created/modified/by for results created separately from runs */);

ProvenanceService pvs = ProvenanceService.get();
Map<Integer, String> rowIdToLsidMap = Collections.emptyMap();
Expand Down Expand Up @@ -607,12 +613,12 @@ protected ParticipantVisitResolver createResolver(User user, ExpRun run, ExpProt
}

/** Insert the data into the database. Transaction is active. */
protected List<Map<String, Object>> insertRowData(ExpData data, User user, Container container, ExpRun run, ExpProtocol protocol, AssayProvider provider, Domain dataDomain, List<Map<String, Object>> fileData, TableInfo tableInfo)
protected List<Map<String, Object>> insertRowData(ExpData data, User user, Container container, ExpRun run, ExpProtocol protocol, AssayProvider provider,Domain dataDomain, List<Map<String, Object>> fileData, TableInfo tableInfo, boolean autoFillDefaultColumns)
throws SQLException, ValidationException
{
if (tableInfo instanceof UpdateableTableInfo)
{
return OntologyManager.insertTabDelimited(tableInfo, container, user, new SimpleAssayDataImportHelper(data), fileData, LOG);
return OntologyManager.insertTabDelimited(tableInfo, container, user, new SimpleAssayDataImportHelper(data), fileData, autoFillDefaultColumns, LOG);
}
else
{
Expand Down
9 changes: 9 additions & 0 deletions api/src/org/labkey/api/assay/AssayRunUploadContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ default void init() throws ExperimentException {}
@Nullable
default File getOriginalFileLocation() { return null; }

default boolean shouldAutoFillDefaultResultColumns()
{
return false;
}

default void setAutoFillDefaultResultColumns(boolean autoFill)
{
}

/**
* Builder pattern for creating a AssayRunUploadContext instance.
*/
Expand Down
15 changes: 15 additions & 0 deletions api/src/org/labkey/api/assay/AssayRunUploadContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class AssayRunUploadContextImpl<ProviderType extends AssayProvider> imple
protected String _jobNotificationProvider;
protected String _pipelineJobGUID;

private boolean _autoFillDefaultResultColumns;

private AssayRunUploadContextImpl(Factory<ProviderType> factory)
{
_protocol = factory._protocol;
Expand Down Expand Up @@ -451,4 +453,17 @@ public Logger getLogger()
return _logger;
}

@Override
public boolean shouldAutoFillDefaultResultColumns()
{
return _autoFillDefaultResultColumns;
}

@Override
public void setAutoFillDefaultResultColumns(boolean autoFill)
{
_autoFillDefaultResultColumns = autoFill;
}


}
6 changes: 4 additions & 2 deletions api/src/org/labkey/api/assay/DefaultAssayRunCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public ExpExperiment saveExperimentRun(
boolean forceSaveBatchProps
) throws ExperimentException, ValidationException
{
context.setAutoFillDefaultResultColumns(run.getRowId() > 0); // need to setAutoFillDefaultResultColumns before run is saved

final Container container = context.getContainer();

Map<ExpMaterial, String> inputMaterials = new HashMap<>();
Expand Down Expand Up @@ -518,7 +520,7 @@ protected void importStandardResultData(
TsvDataHandler dataHandler = new TsvDataHandler();
dataHandler.setAllowEmptyData(true);
dataHandler.setRawPlateMetadata(context.getRawPlateMetadata());
dataHandler.importRows(primaryData, context.getUser(), run, context.getProtocol(), getProvider(), rawData, null);
dataHandler.importRows(primaryData, context.getUser(), run, context.getProtocol(), getProvider(), rawData, null, context.shouldAutoFillDefaultResultColumns());
}
}
else
Expand All @@ -537,7 +539,7 @@ protected void importStandardResultData(
Logger logger = context.getLogger() != null ? context.getLogger() : LOG;
for (ExpData insertedData : insertedDatas)
{
insertedData.findDataHandler().importFile(insertedData, insertedData.getFile(), info, logger, xarContext, context.isAllowLookupByAlternateKey());
insertedData.findDataHandler().importFile(insertedData, insertedData.getFile(), info, logger, xarContext, context.isAllowLookupByAlternateKey(), context.shouldAutoFillDefaultResultColumns());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/data/NameGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ public void testWithCounter()
{

Map<Object, Object> m = new HashMap<>();
m.put("AliquotedFrom", aliquotedFrom);
m.put(ExpMaterial.ALIQUOTED_FROM_INPUT, aliquotedFrom);
m.put("SourceMeta", sourceMeta);

Container c = JunitUtil.getTestContainer();
Expand Down Expand Up @@ -2605,7 +2605,7 @@ public void testWithCounter()
assertEquals("S100.mouse1.2", s);

Map<Object, Object> m2 = new HashMap<>();
m2.put("AliquotedFrom", aliquotedFrom);
m2.put(ExpMaterial.ALIQUOTED_FROM_INPUT, aliquotedFrom);
m2.put("SourceMeta", "mouse2");

s = se.eval(m2);
Expand Down
3 changes: 2 additions & 1 deletion api/src/org/labkey/api/data/generator/DataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.labkey.api.dataiterator.ListofMapsDataIterator;
import org.labkey.api.exp.ExperimentException;
import org.labkey.api.exp.api.ExpDataClass;
import org.labkey.api.exp.api.ExpMaterial;
import org.labkey.api.exp.api.ExpObject;
import org.labkey.api.exp.api.ExpSampleType;
import org.labkey.api.exp.api.ExperimentService;
Expand Down Expand Up @@ -403,7 +404,7 @@ private int generateAliquotsForParents(List<Map<String, Object>> parents, QueryU
for (int i = 0; i < numAliquots; i++)
{
Map<String, Object> row = new CaseInsensitiveHashMap<>();
row.put("AliquotedFrom", parent.get("Name"));
row.put(ExpMaterial.ALIQUOTED_FROM_INPUT, parent.get("Name"));
rows.add(row);
}
generatedCount += numAliquots;
Expand Down
6 changes: 6 additions & 0 deletions api/src/org/labkey/api/exp/ExperimentDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ default void importFile(@NotNull ExpData data, File dataFile, @NotNull ViewBackg
{
importFile(data, dataFile, info, log, context);
}

default void importFile(@NotNull ExpData data, File dataFile, @NotNull ViewBackgroundInfo info, @NotNull Logger log, @NotNull XarContext context, boolean allowLookupByAlternateKey, boolean autoFillDefaultResultColumns) throws ExperimentException
{
importFile(data, dataFile, info, log, context);
}

default void importFile(@NotNull ExpData data, Path dataFile, @NotNull ViewBackgroundInfo info, @NotNull Logger log, @NotNull XarContext context) throws ExperimentException
{
if (FileUtil.hasCloudScheme(dataFile))
Expand Down
30 changes: 25 additions & 5 deletions api/src/org/labkey/api/exp/OntologyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ public static List<String> insertTabDelimited(Container c, User user, @Nullable
return resultingLsids;
}

public static List<Map<String, Object>> insertTabDelimited(TableInfo tableInsert, Container c, User user,
UpdateableTableImportHelper helper,
List<Map<String, Object>> rows,
Logger logger)
throws SQLException, ValidationException
{
return insertTabDelimited(tableInsert, c, user, helper, rows, true, logger);
}

/**
* As an incremental step of QueryUpdateService cleanup, this is a version of insertTabDelimited that works on a
Expand All @@ -425,26 +433,38 @@ public static List<String> insertTabDelimited(Container c, User user, @Nullable
public static List<Map<String, Object>> insertTabDelimited(TableInfo tableInsert, Container c, User user,
UpdateableTableImportHelper helper,
List<Map<String, Object>> rows,
boolean autoFillDefaultColumns,
Logger logger)
throws SQLException, ValidationException
{
return saveTabDelimited(tableInsert, c, user, helper, rows, logger, true);
return saveTabDelimited(tableInsert, c, user, helper, rows, logger, true, autoFillDefaultColumns);
}

public static List<Map<String, Object>> updateTabDelimited(TableInfo tableInsert, Container c, User user,
UpdateableTableImportHelper helper,
List<Map<String, Object>> rows,
Logger logger)
throws SQLException, ValidationException
{
return updateTabDelimited(tableInsert, c, user, helper, rows, true, logger);
}

public static List<Map<String, Object>> updateTabDelimited(TableInfo tableInsert, Container c, User user,
UpdateableTableImportHelper helper,
List<Map<String, Object>> rows,
boolean autoFillDefaultColumns,
Logger logger)
throws SQLException, ValidationException
{
return saveTabDelimited(tableInsert, c, user, helper, rows, logger, false);
return saveTabDelimited(tableInsert, c, user, helper, rows, logger, false, autoFillDefaultColumns);
}

private static List<Map<String, Object>> saveTabDelimited(TableInfo table, Container c, User user,
UpdateableTableImportHelper helper,
List<Map<String, Object>> rows,
Logger logger,
boolean insert)
boolean insert,
boolean autoFillDefaultColumns)
throws SQLException, ValidationException
{
if (!(table instanceof UpdateableTableInfo))
Expand Down Expand Up @@ -475,11 +495,11 @@ private static List<Map<String, Object>> saveTabDelimited(TableInfo table, Conta
conn = scope.getConnection();
if (insert)
{
parameterMap = StatementUtils.insertStatement(conn, table, c, user, true, true);
parameterMap = StatementUtils.insertStatement(conn, table, c, user, true, autoFillDefaultColumns);
}
else
{
parameterMap = StatementUtils.updateStatement(conn, table, c, user, false, true);
parameterMap = StatementUtils.updateStatement(conn, table, c, user, false, autoFillDefaultColumns);
}
List<ValidationError> errors = new ArrayList<>();

Expand Down
1 change: 1 addition & 0 deletions api/src/org/labkey/api/exp/api/ExpMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface ExpMaterial extends ExpRunItem
String DEFAULT_CPAS_TYPE = "Material";
String MATERIAL_INPUT_PARENT = "MaterialInputs";
String MATERIAL_OUTPUT_CHILD = "MaterialOutputs";
String ALIQUOTED_FROM_INPUT = "AliquotedFrom";

@Nullable
ExpSampleType getSampleType();
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/exp/api/SampleTypeDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class SampleTypeDomainKind extends AbstractDomainKind<SampleTypeDomainKin
RESERVED_NAMES.addAll(Arrays.stream(ExpSampleTypeTable.Column.values()).map(ExpSampleTypeTable.Column::name).toList());
RESERVED_NAMES.add("CpasType");
RESERVED_NAMES.add("IsAliquot");
RESERVED_NAMES.add("AliquotedFrom");
RESERVED_NAMES.add(ExpMaterial.ALIQUOTED_FROM_INPUT);
RESERVED_NAMES.add("AliquotedFromLSID");
RESERVED_NAMES.add("RootMaterialLSID");
RESERVED_NAMES.add("RecomputeRollup");
Expand Down
26 changes: 24 additions & 2 deletions assay/api-src/org/labkey/api/assay/AssayResultDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.labkey.api.assay;

import org.labkey.api.data.Container;
import org.labkey.api.data.DbSchema;
import org.labkey.api.data.DbSchemaType;
import org.labkey.api.data.DbScope;
Expand All @@ -27,8 +28,15 @@
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.Pair;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import static org.labkey.api.data.Table.CREATED_BY_COLUMN_NAME;
import static org.labkey.api.data.Table.CREATED_COLUMN_NAME;
import static org.labkey.api.data.Table.MODIFIED_BY_COLUMN_NAME;
import static org.labkey.api.data.Table.MODIFIED_COLUMN_NAME;

/**
* User: brittp
* Date: June 25, 2007
Expand Down Expand Up @@ -59,7 +67,12 @@ public Set<PropertyStorageSpec> getBaseProperties(Domain domain)
rowIdSpec.setAutoIncrement(true);
rowIdSpec.setPrimaryKey(true);

return PageFlowUtil.set(rowIdSpec, dataIdSpec);
PropertyStorageSpec createdSpec = new PropertyStorageSpec(CREATED_COLUMN_NAME, JdbcType.TIMESTAMP);
PropertyStorageSpec createdBySpec = new PropertyStorageSpec(CREATED_BY_COLUMN_NAME, JdbcType.INTEGER);
PropertyStorageSpec modifiedSpec = new PropertyStorageSpec(MODIFIED_COLUMN_NAME, JdbcType.TIMESTAMP);
PropertyStorageSpec modifiedBySpec = new PropertyStorageSpec(MODIFIED_BY_COLUMN_NAME, JdbcType.INTEGER);

return PageFlowUtil.set(rowIdSpec, dataIdSpec, createdSpec, createdBySpec, modifiedSpec, modifiedBySpec);
}

@Override
Expand All @@ -68,6 +81,15 @@ public Set<PropertyStorageSpec.Index> getPropertyIndices(Domain domain)
return PageFlowUtil.set(new PropertyStorageSpec.Index(false, AbstractTsvAssayProvider.DATA_ID_COLUMN_NAME));
}

@Override
public Set<PropertyStorageSpec.ForeignKey> getPropertyForeignKeys(Container container)
{
return new HashSet<>(Arrays.asList(
new PropertyStorageSpec.ForeignKey(CREATED_BY_COLUMN_NAME, "core", "users", "userid", null, false),
new PropertyStorageSpec.ForeignKey(MODIFIED_BY_COLUMN_NAME, "core", "users", "userid", null, false)
));
}

@Override
public DbScope getScope()
{
Expand All @@ -80,7 +102,7 @@ public String getStorageSchemaName()
return AbstractTsvAssayProvider.ASSAY_SCHEMA_NAME;
}

private DbSchema getSchema()
public DbSchema getSchema()
{
return DbSchema.get(getStorageSchemaName(), getSchemaType());
}
Expand Down
Loading