-
Notifications
You must be signed in to change notification settings - Fork 7
Transform script refactor #6159
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package org.labkey.api.assay.transform; | ||
|
|
||
| import org.jetbrains.annotations.Nullable; | ||
| import org.json.JSONArray; | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
| import org.labkey.vfs.FileLike; | ||
| import org.labkey.vfs.FileSystemLike; | ||
|
|
||
| import java.io.File; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| public class AnalysisScript | ||
| { | ||
| FileLike _script; | ||
| Set<DataTransformService.TransformOperation> _operations = new HashSet<>(); | ||
|
|
||
| public AnalysisScript(File script, Set<DataTransformService.TransformOperation> operations) | ||
| { | ||
| _script = new FileSystemLike.Builder(script).build().getRoot(); | ||
| _operations = operations; | ||
| } | ||
|
|
||
| private AnalysisScript(File script, List<String> operations) | ||
| { | ||
| _script = new FileSystemLike.Builder(script).build().getRoot(); | ||
| for (String op : operations) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume it is not possible to have a null operations param here, but thoughts on adding in a check and default case for setting operations to insert?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, done. |
||
| { | ||
| if (op != null) | ||
| _operations.add(DataTransformService.TransformOperation.valueOf(op)); | ||
| } | ||
|
|
||
| // default to insert only | ||
| if (_operations.isEmpty()) | ||
| _operations.add(DataTransformService.TransformOperation.INSERT); | ||
| } | ||
|
|
||
| public FileLike getScript() | ||
| { | ||
| return _script; | ||
| } | ||
|
|
||
| public String getScriptPath() | ||
| { | ||
| return _script.toNioPathForRead().toString(); | ||
| } | ||
|
|
||
| public boolean canExecute(DataTransformService.TransformOperation operation) | ||
| { | ||
| return _operations.contains(operation); | ||
| } | ||
|
|
||
| private static JSONObject toJson(AnalysisScript script) | ||
| { | ||
| JSONObject json = new JSONObject(); | ||
|
|
||
| json.put("operations", script._operations); | ||
| json.put("script", script._script.toNioPathForRead()); | ||
|
|
||
| return json; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static JSONArray toJson(Collection<AnalysisScript> scripts) | ||
| { | ||
| if (!scripts.isEmpty()) | ||
| { | ||
| JSONArray json = new JSONArray(); | ||
| for (AnalysisScript script : scripts) | ||
| { | ||
| json.put(toJson(script)); | ||
| } | ||
| return json; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| public static List<AnalysisScript> fromJson(String jsonStr) | ||
| { | ||
| try | ||
| { | ||
| List<AnalysisScript> scripts = new ArrayList<>(); | ||
| JSONArray json = new JSONArray(jsonStr); | ||
| for (Object o : json.toList()) | ||
| { | ||
| if (o instanceof Map<?,?> props) | ||
| { | ||
| File script = new File(String.valueOf(props.get("script"))); | ||
| List<String> ops = (List<String>) props.get("operations"); | ||
|
|
||
| scripts.add(new AnalysisScript(script, ops)); | ||
| } | ||
| } | ||
| return scripts; | ||
| } | ||
| catch (JSONException e) | ||
| { | ||
| // ignore | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we don't expose anything in the UI for defining a validation script, just transform scripts. Was this possible from a file based module? Is there code somewhere that would convert any legacy validation scripts to transform scripts or is that not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I'm aware of, the file based module code for transform scripts is in
ModuleAssayProvider.