Skip to content

Commit c18b8b8

Browse files
committed
code review feedback
1 parent 090f2e1 commit c18b8b8

3 files changed

Lines changed: 52 additions & 50 deletions

File tree

signalData/resources/views/mockSignalDataWatch.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,9 @@
211211
paths : paths,
212212
files : fileNames
213213
},
214-
success: function (response) {
215-
let result = Ext4.decode(response.responseText);
216-
callback.call(scope || this, result.files);
217-
},
214+
success: LABKEY.Utils.getCallbackWrapper(function(response) {
215+
callback.call(scope || this, response.files);
216+
}, this, true),
218217
scope: this
219218
});
220219
}

signalData/resources/web/signaldata/ResultUpdate/resultupdate.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ var init = function(assay, row){
6868
paths: [decodeURIComponent(file.internalId)],
6969
files: [file.name]
7070
},
71-
success: function (response) {
72-
var result = Ext4.decode(response.responseText);
73-
Ext4.each(result.files, function(file) {
74-
71+
success: LABKEY.Utils.getCallbackWrapper(function(response) {
72+
Ext4.each(response.files, function(file) {
7573
var updatedRow = setRunFields(form, file);
7674
updateRunResult(updatedRow, file);
7775
}, this);
78-
},
76+
}, this, true),
7977
scope: this
8078
});
8179
}

signalData/src/org/labkey/signaldata/SignalDataController.java

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.labkey.api.action.ReadOnlyApiAction;
2323
import org.labkey.api.action.SpringActionController;
2424
import org.labkey.api.data.Container;
25+
import org.labkey.api.data.DbScope;
2526
import org.labkey.api.data.TableInfo;
2627
import org.labkey.api.exp.api.ExpData;
2728
import org.labkey.api.exp.api.ExperimentService;
@@ -133,64 +134,68 @@ public ApiResponse execute(SignalDataResourceForm form, BindException errors) th
133134
List<Map<String, String>> results = new ArrayList<>();
134135
Container c = getContainer();
135136
FileContentService svc = FileContentService.get();
136-
TableInfo ti = ExpSchema.TableType.Data.createTable(new ExpSchema(getUser(), c), ExpSchema.TableType.Data.toString(), null);
137+
TableInfo ti = new ExpSchema(getUser(), getContainer()).getDatasTable();
137138
QueryUpdateService qus = ti.getUpdateService();
138-
int maxUrlSize = ExperimentService.get().getTinfoData().getColumn("DataFileURL").getScale();
139+
int maxUrlSize = ExperimentService.get().getTinfoData().getColumn(ExpDataTable.Column.DataFileUrl.name()).getScale();
139140
int idx = 0;
140141

141-
for (String path : form.getPaths())
142+
try (DbScope.Transaction transaction = DbScope.getLabKeyScope().ensureTransaction())
142143
{
143-
WebdavResource resource = WebdavService.get().lookup(path);
144-
String fileName = form.getFiles().get(idx++);
145-
146-
if (null != resource)
144+
for (String path : form.getPaths())
147145
{
148-
ExpData data = svc.getDataObject(resource, c);
149-
if (data == null)
146+
WebdavResource resource = WebdavService.get().lookup(path);
147+
String fileName = form.getFiles().get(idx++);
148+
149+
if (null != resource)
150150
{
151-
// create the ExpData object if it doesn't already exist
152-
File file = resource.getFile();
153-
if (null != file)
151+
ExpData data = svc.getDataObject(resource, c);
152+
if (data == null)
154153
{
155-
data = ExperimentService.get().createData(c, UPLOADED_FILE);
156-
data.setName(file.getName());
157-
data.setDataFileURI(file.toURI());
158-
159-
String dataFileURL = data.getDataFileUrl();
160-
if (dataFileURL == null || dataFileURL.length() <= maxUrlSize)
161-
{
162-
data.save(getUser());
163-
}
164-
else
154+
// create the ExpData object if it doesn't already exist
155+
File file = resource.getFile();
156+
if (null != file)
165157
{
166-
throw new ValidationException(String.format("The data file URL is too long to store in the database (max %d).", maxUrlSize));
158+
data = ExperimentService.get().createData(c, UPLOADED_FILE);
159+
data.setName(file.getName());
160+
data.setDataFileURI(file.toURI());
161+
162+
String dataFileURL = data.getDataFileUrl();
163+
if (dataFileURL == null || dataFileURL.length() <= maxUrlSize)
164+
{
165+
data.save(getUser());
166+
}
167+
else
168+
{
169+
throw new ValidationException(String.format("The data file URL is too long to store in the database (max %d).", maxUrlSize));
170+
}
167171
}
168172
}
169-
}
170-
171-
if (null != data)
172-
{
173-
File canonicalFile = FileUtil.getAbsoluteCaseSensitiveFile(resource.getFile());
174-
String url = canonicalFile.toURI().toURL().toString();
175-
List<Map<String, Object>> rows = qus.getRows(getUser(), c, Collections.singletonList(Map.of(ExpDataTable.Column.DataFileUrl.name(), url)));
176173

177-
if (rows.size() == 1)
174+
if (null != data)
178175
{
179-
Map<String, String> props = new HashMap<>();
180-
props.put("FilePath", path);
181-
props.put("FileName", fileName);
182-
results.add(props);
183-
for (Map.Entry<String, Object> entry : rows.get(0).entrySet())
176+
File canonicalFile = FileUtil.getAbsoluteCaseSensitiveFile(resource.getFile());
177+
String url = canonicalFile.toURI().toURL().toString();
178+
List<Map<String, Object>> rows = qus.getRows(getUser(), c, Collections.singletonList(Map.of(ExpDataTable.Column.DataFileUrl.name(), url)));
179+
180+
if (rows.size() == 1)
184181
{
185-
Object value = entry.getValue();
186-
if (null != value)
187-
props.put(entry.getKey(), String.valueOf(value));
182+
Map<String, String> props = new HashMap<>();
183+
props.put("FilePath", path);
184+
props.put("FileName", fileName);
185+
results.add(props);
186+
for (Map.Entry<String, Object> entry : rows.get(0).entrySet())
187+
{
188+
Object value = entry.getValue();
189+
if (null != value)
190+
props.put(entry.getKey(), String.valueOf(value));
191+
}
188192
}
193+
else
194+
throw new RuntimeException(String.format("Unexpected number of rows returned for DataFileUrl '%s': %d", url, rows.size()));
189195
}
190-
else
191-
throw new RuntimeException(String.format("Unexpected number of rows returned for DataFileUrl '%s': %d", url, rows.size()));
192196
}
193197
}
198+
transaction.commit();
194199
}
195200
return new ApiSimpleResponse(Map.of("files", results));
196201
}

0 commit comments

Comments
 (0)