Skip to content

Commit d882097

Browse files
committed
Allow insert of records using query API into outputfiles to automatically create ExpData IDs
1 parent 5935482 commit d882097

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

SequenceAnalysis/resources/queries/sequenceanalysis/outputfiles.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ function beforeDelete(row, errors){
1414
errors._form = 'You cannot directly delete analyses. To delete these records, use the delete button above the analysis grid.';
1515
}
1616
}
17+
18+
function beforeInsert(row, errors){
19+
beforeUpsert(row, errors);
20+
}
21+
22+
function beforeUpdate(row, errors){
23+
beforeUpsert(row, errors);
24+
}
25+
26+
function beforeUpsert(row, errors) {
27+
if (row.dataid && typeof row.dataid == 'string') {
28+
row.dataid = triggerHelper.createExpData(row.dataid);
29+
}
30+
}

SequenceAnalysis/src/org/labkey/sequenceanalysis/query/SequenceTriggerHelper.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818
import org.labkey.api.data.SimpleFilter;
1919
import org.labkey.api.data.TableInfo;
2020
import org.labkey.api.data.TableSelector;
21+
import org.labkey.api.exp.api.DataType;
22+
import org.labkey.api.exp.api.ExpData;
23+
import org.labkey.api.exp.api.ExperimentService;
24+
import org.labkey.api.pipeline.PipeRoot;
25+
import org.labkey.api.pipeline.PipelineService;
2126
import org.labkey.api.query.FieldKey;
2227
import org.labkey.api.query.QueryService;
2328
import org.labkey.api.security.User;
2429
import org.labkey.api.security.UserManager;
2530
import org.labkey.api.sequenceanalysis.RefNtSequenceModel;
2631
import org.labkey.sequenceanalysis.SequenceAnalysisSchema;
2732

33+
import java.io.File;
2834
import java.io.IOException;
2935
import java.io.StringWriter;
3036
import java.util.Arrays;
@@ -221,4 +227,31 @@ public void testTranslation() {
221227
}
222228
}
223229
}
230+
231+
public int createExpData(String relPath) {
232+
PipeRoot pr = PipelineService.get().getPipelineRootSetting(getContainer());
233+
if (pr == null)
234+
{
235+
throw new IllegalArgumentException("Unable to find pipeline root");
236+
}
237+
238+
File f = new File(pr.getRootPath(), relPath);
239+
if (!f.exists())
240+
{
241+
throw new IllegalArgumentException("Unable to find file: " + f.getPath());
242+
}
243+
244+
ExpData d = ExperimentService.get().getExpDataByURL(f, getContainer());
245+
if (d != null)
246+
{
247+
return d.getRowId();
248+
}
249+
250+
d = ExperimentService.get().createData(getContainer(), new DataType("Output"));
251+
d.setDataFileURI(f.toURI());
252+
d.setName(f.getName());
253+
d.save(getUser());
254+
255+
return d.getRowId();
256+
}
224257
}

0 commit comments

Comments
 (0)