mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
Add defaults to calculations for ToolIO (#7289)
# Description of Changes Currently when calculating the output file type for some tools, the system will get it wrong because it doesn't know about what the default parameters in tools are, so if it doesn't have a value for some key, it'll just bail out and say "it might not be compatible". This PR adds logic to `ToolIO` to read the default values set for the parameters if the tool has `ToolIOCase`s and takes them into account when figuring out the output type. I've built it with horrible Java reflection magic to avoid having to specify the default for params twice, which will make it impossible for the defaults to disagree with each other. This just runs once at startup so there's negligible performance impact. The change is easily tested with Change Parameters, which is just `add-password` behind the scenes but with the password params omitted (so Change Password is always PDF->PDF, never encrypted like Add Password). Also (somewhat hackily) fixes a bug I noticed where saving a Change Permissions step then leaving and returning to the pipeline will cause the step to be reloaded as Add Password. I've added a system to disambiguate tools which share the same endpoint (which is only these two currently). ## Currently <img width="455" height="135" alt="image" src="https://github.com/user-attachments/assets/c8867d6a-599b-4f21-a2db-4a1b6ac22d73" /> ## Now <img width="415" height="122" alt="image" src="https://github.com/user-attachments/assets/bd8d1bab-f00a-421b-8c91-5af0d2ad5335" />
This commit is contained in:
@@ -70,6 +70,33 @@
|
||||
"arity": "SISO"
|
||||
}
|
||||
]
|
||||
},
|
||||
"autoRotateShape": {
|
||||
"accepts": ["PDF"],
|
||||
"produces": "PDF",
|
||||
"arity": "SISO",
|
||||
"cases": [
|
||||
{
|
||||
"when": [{ "param": "dryRun", "matches": ["true"], "default": "false" }],
|
||||
"produces": "JSON",
|
||||
"arity": "SISO"
|
||||
}
|
||||
]
|
||||
},
|
||||
"changePermsShape": {
|
||||
"accepts": ["PDF"],
|
||||
"produces": "PDF_ENCRYPTED",
|
||||
"arity": "SISO",
|
||||
"cases": [
|
||||
{
|
||||
"when": [
|
||||
{ "param": "password", "matches": [""], "default": "" },
|
||||
{ "param": "ownerPassword", "matches": [""], "default": "" }
|
||||
],
|
||||
"produces": "PDF",
|
||||
"arity": "SISO"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"cases": [
|
||||
@@ -250,6 +277,35 @@
|
||||
],
|
||||
"expected": [{ "stepIndex": 1, "severity": "INFO", "code": "fan-in" }]
|
||||
},
|
||||
{
|
||||
"name": "an absent parameter takes its default, which here does not trigger the case",
|
||||
"steps": [{ "spec": "autoRotateShape" }, { "spec": "pdfToPdf" }],
|
||||
"expected": []
|
||||
},
|
||||
{
|
||||
"name": "an explicit value overrides the default and triggers the case",
|
||||
"steps": [
|
||||
{ "spec": "autoRotateShape", "parameters": { "dryRun": "true" } },
|
||||
{ "spec": "pdfToPdf" }
|
||||
],
|
||||
"expected": [{ "stepIndex": 1, "severity": "ERROR", "code": "format-mismatch" }]
|
||||
},
|
||||
{
|
||||
"name": "an absent parameter whose default triggers the case resolves to that branch",
|
||||
"steps": [{ "spec": "changePermsShape" }, { "spec": "pdfToPdf" }],
|
||||
"expected": []
|
||||
},
|
||||
{
|
||||
"name": "setting the branch parameter away from its default flips the outcome",
|
||||
"steps": [
|
||||
{
|
||||
"spec": "changePermsShape",
|
||||
"parameters": { "password": "hunter2", "ownerPassword": "hunter2" }
|
||||
},
|
||||
{ "spec": "pdfToPdf" }
|
||||
],
|
||||
"expected": [{ "stepIndex": 1, "severity": "ERROR", "code": "format-mismatch" }]
|
||||
},
|
||||
{
|
||||
"name": "an undeclared step warns and stops the chain being checked past it",
|
||||
"steps": [{ "spec": "addPassword" }, { "spec": null }, { "spec": "pdfToPdf" }],
|
||||
|
||||
Reference in New Issue
Block a user