Uh oh!
There was an error while loading. Please reload this page.
forked from bimberlabinternal/LabDevKitModules
- Notifications
You must be signed in to change notification settings - Fork 1
Use UpdateService instead of raw DbSchema layer for assay_template edits#292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
labkey-martyp
merged 5 commits into
release25.7-SNAPSHOT
from
25.7_fb_scope_assay_template_lookups2Jun 29, 2026
+117
−24
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8068a00
Use UpdateService instead of raw DbSchema layer for assay_template edits
bbimber 9a96634
Code review
bbimber d8e37ff
Tighten behavior around cross-container actions
bbimber e448eaf
Use List.get(0) instead of getFirst() so this compiles on Java 17
labkey-martyp 47b0bcb
Fix assay template save: correct rowid key casing and don't log expec…
labkey-martyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
55 changes: 41 additions & 14 deletions
55 laboratory/api-src/org/labkey/api/laboratory/assay/DefaultAssayParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 76 additions & 10 deletions
86 laboratory/src/org/labkey/laboratory/assay/AssayHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,9 +32,9 @@ | ||
| import org.labkey.api.collections.CollectionUtils; | ||
| import org.labkey.api.data.Container; | ||
| import org.labkey.api.data.ContainerManager; | ||
| import org.labkey.api.data.RuntimeSQLException; | ||
| import org.labkey.api.data.ContainerType; | ||
| import org.labkey.api.data.SimpleFilter; | ||
| import org.labkey.api.data.TSVMapWriter; | ||
| import org.labkey.api.data.Table; | ||
| import org.labkey.api.data.TableInfo; | ||
| import org.labkey.api.data.TableSelector; | ||
| import org.labkey.api.exp.ChangePropertyDescriptorException; | ||
| @@ -51,9 +51,14 @@ | ||
| import org.labkey.api.laboratory.assay.AssayDataProvider; | ||
| import org.labkey.api.laboratory.assay.AssayImportMethod; | ||
| import org.labkey.api.query.BatchValidationException; | ||
| import org.labkey.api.query.FieldKey; | ||
| import org.labkey.api.query.QueryService; | ||
| import org.labkey.api.query.UserSchema; | ||
| import org.labkey.api.query.ValidationException; | ||
| import org.labkey.api.security.User; | ||
| import org.labkey.api.security.permissions.UpdatePermission; | ||
| import org.labkey.api.util.FileUtil; | ||
| import org.labkey.api.util.PageFlowUtil; | ||
| import org.labkey.api.util.Pair; | ||
| import org.labkey.api.view.ActionURL; | ||
| import org.labkey.api.view.ViewContext; | ||
| @@ -66,6 +71,7 @@ | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| @@ -125,35 +131,52 @@ public Map<String, Object> saveTemplate(User u, Container c, ExpProtocol protoco | ||
| { | ||
| validateTemplate(u, c, protocol, templateId, title, importMethod, json); | ||
| TableInfo ti = LaboratorySchema.getInstance().getSchema().getTable(LaboratorySchema.TABLE_ASSAY_RUN_TEMPLATES); | ||
| UserSchema us = QueryService.get().getUserSchema(u, c, "laboratory"); | ||
| if (us == null) | ||
| { | ||
| throw new IllegalStateException("Could not find the laboratory schema in container: " + c.getPath()); | ||
| } | ||
| TableInfo ti = us.getTable(LaboratorySchema.TABLE_ASSAY_RUN_TEMPLATES); | ||
| Map<String, Object> row = new HashMap<>(); | ||
| row.put("assayId", protocol.getRowId()); | ||
| row.put("title", title); | ||
| row.put("importMethod", importMethod); | ||
| row.put("json", json.toString()); | ||
| row.put("container", c.getId()); | ||
| if (templateId == null) | ||
| { | ||
| row = Table.insert(u, ti, row); | ||
| BatchValidationException bve = new BatchValidationException(); | ||
| List<Map<String, Object>> rows = ti.getUpdateService().insertRows(u, c, Arrays.asList(row), bve, null, null); | ||
| if (bve.hasErrors()) | ||
| { | ||
| throw bve; | ||
| } | ||
| return rows.get(0); | ||
| } | ||
| else | ||
| { | ||
| row.put("rowid", templateId); | ||
| row = Table.update(u, ti, row, templateId); | ||
| List<Map<String, Object>> rows = ti.getUpdateService().updateRows(u, c, Arrays.asList(row), Arrays.asList(Map.of("rowid", templateId)), null, null); | ||
| return rows.get(0); | ||
| } | ||
| return row; | ||
| } | ||
| catch (RuntimeSQLException e) | ||
| catch (BatchValidationException e) | ||
| { | ||
| // Expected validation failures (e.g. from validateTemplate() or insertRows()) should propagate to the | ||
| // client as-is, not be logged as server errors. | ||
| throw e; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _log.error(e.getMessage(), e); | ||
| errors.addRowError(new ValidationException(e.getMessage())); | ||
| throw errors; | ||
| } | ||
| } | ||
| public void validateTemplate(User u, Container c, ExpProtocol protocol, Integer templateId, String title, String importMethod, JSONObject json) throws BatchValidationException | ||
| public void validateTemplate(User u, Container c, ExpProtocol protocol, @Nullable Integer templateId, String title, String importMethod, JSONObject json) throws BatchValidationException | ||
| { | ||
| BatchValidationException errors = new BatchValidationException(); | ||
| @@ -178,6 +201,49 @@ public void validateTemplate(User u, Container c, ExpProtocol protocol, Integer | ||
| throw errors; | ||
| } | ||
| // Verify if this template exists and permissions. This expects any existing row to be present in the current container: | ||
| if (templateId != null) | ||
| { | ||
| // This queries the current container+workbooks to identify the existence of rows in other reasonable containers: | ||
| UserSchema us = QueryService.get().getUserSchema(u, c.getContainerFor(ContainerType.DataType.tabParent), "laboratory"); | ||
bbimber marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| TableInfo ti = us.getTable("assay_run_templates"); | ||
| TableSelector ts = new TableSelector(ti, PageFlowUtil.set("container"), new SimpleFilter(FieldKey.fromString("rowId"), templateId), null); | ||
| if (ts.exists()) | ||
| { | ||
| Container rowContainer = ContainerManager.getForId(ts.getObject(String.class)); | ||
| if (rowContainer == null) | ||
| { | ||
| errors.addRowError(new ValidationException("Unable to determine the container for template: " + templateId)); | ||
| throw errors; | ||
| } | ||
| if (!rowContainer.hasPermission("AssayHelper.validateTemplate()", u, UpdatePermission.class)) | ||
| { | ||
| errors.addRowError(new ValidationException("The current user does not have permission to edit template: " + templateId)); | ||
| throw errors; | ||
| } | ||
| if (!c.equals(rowContainer)) | ||
| { | ||
| errors.addRowError(new ValidationException("Template " + templateId + " is not from this folder")); | ||
| throw errors; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| errors.addRowError(new ValidationException("Unable to find template with ID: " + templateId)); | ||
| throw errors; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (!c.hasPermission("AssayHelper.validateTemplate()", u, UpdatePermission.class)) | ||
| { | ||
| errors.addRowError(new ValidationException("The current user does not have permission to creates templates in folder: " + c.getName())); | ||
| throw errors; | ||
| } | ||
| } | ||
| method.validateTemplate(u, c, protocol, templateId, title, json, errors); | ||
| if (errors.hasErrors()) | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.