This commit is contained in:
Michele Artini 2024-01-15 11:04:10 +01:00
parent 00f735e116
commit 0816c578eb
5 changed files with 93 additions and 53 deletions

View File

@ -2,6 +2,8 @@ package eu.dnetlib.wfs.manager.controller;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -29,6 +31,7 @@ import eu.dnetlib.domain.wfs.graph.Node;
import eu.dnetlib.domain.wfs.jobs.WfJournalEntry;
import eu.dnetlib.domain.wfs.jobs.WfRunningJob;
import eu.dnetlib.domain.wfs.subscriptions.WfSubscription;
import eu.dnetlib.domain.wfs.templates.WfParam;
import eu.dnetlib.domain.wfs.templates.WfRepoHiDesc;
import eu.dnetlib.domain.wfs.templates.WfRepoHiParams;
import eu.dnetlib.domain.wfs.templates.WfTemplate;
@ -104,9 +107,15 @@ public class ApiController extends DnetRestController {
}
@GetMapping("/conf/{id}/start")
public List<WfJournalEntry> startWorkflowConfiguration(@PathVariable final String id) throws Exception {
public List<WfJournalEntry> startWorkflowConfiguration(@PathVariable final String id,
@RequestParam(name = "wf", required = false) final String[] overrideStartWfs)
throws Exception {
final WfConfiguration conf = this.wfManagerService.findWorkflowConfiguration(id);
if (overrideStartWfs.length > 0) {
conf.setWorkflows(Arrays.asList(overrideStartWfs));
}
this.wfManagerService.prepareNewJob(conf, false);
if (StringUtils.isNotBlank(conf.getApiId())) { return this.wfManagerService.recentHistoryForApiId(conf.getApiId()); }
@ -127,7 +136,6 @@ public class ApiController extends DnetRestController {
if (StringUtils.isNotBlank(conf.getId())) { return this.wfManagerService.recentHistoryForConfiguration(conf.getId()); }
return this.wfManagerService.recentHistory();
}
@GetMapping("/conf/{id}/subscriptions")
@ -168,6 +176,38 @@ public class ApiController extends DnetRestController {
return this.wfManagerService.findWfTemplateDesc(id);
}
@GetMapping("/parameters")
public Collection<WfParam> findWfTemplateParameters(@RequestParam(name = "wf", required = true) final String[] workflows) throws Exception {
final Map<String, WfParam> params = new LinkedHashMap<>();
final SimpleResourceClient client = this.clientFactory.getClient(SimpleResourceClient.class);
for (final String wf : workflows) {
for (final WfParam p : client.findResourceContent(WorkflowsConstants.WF_TEMPLATE, wf, WfTemplate.class).getParameters()) {
if (params.containsKey(p.getName())) {
final WfParam main = params.get(p.getName());
main.setDefaultValue(StringUtils.firstNonBlank(main.getDefaultValue(), p.getDefaultValue()));
main.setRequired(main.isRequired() || p.isRequired());
main.setDescription(StringUtils.firstNonBlank(main.getDescription(), p.getDescription()));
if (!p.getValidTerms().isEmpty()) {
if (main.getValidTerms().isEmpty()) {
main.setValidTerms(p.getValidTerms());
} else {
main.setValidTerms(main.getValidTerms().stream().filter(t -> p.getValidTerms().contains(t)).toList());
}
}
} else {
params.put(p.getName(), p);
}
}
}
return params.values();
}
@GetMapping("/confs/byApi/{id}")
public List<WfConfiguration> listWfConfigurationsByApi(@PathVariable final String id) {
return this.wfManagerService.listWfConfigurationsByApiId(id);

View File

@ -173,38 +173,27 @@ export class WfConfDialog implements OnInit {
this.wfConfFormStep3.controls = {};
this.wfParameters = [];
let wfParameterNames: string[] = [];
this.client.loadWfTemplatesParams(wfTemplateIds, (data: WfParam[]) => {
this.wfParameters = data;
wfTemplateIds.forEach(id => {
this.client.loadWfTemplate(id, (data: any) => {
let tmpParams = data.parameters ? data.parameters : JSON.parse(data).parameters;
tmpParams.forEach((p: WfParam) => {
if (!wfParameterNames.includes(p.name)) {
this.wfParameters.push(p);
wfParameterNames.push(p.name);
}
});
this.wfParameters.forEach(p => {
let validations: ValidatorFn[] = [];
if (p.required) { validations.push(Validators.required); }
if (p.type == 'number') { validations.push(Validators.pattern('^[0-9]*$')); }
this.wfParameters.forEach(p => {
let validations: ValidatorFn[] = [];
if (p.required) { validations.push(Validators.required); }
if (p.type == 'number') { validations.push(Validators.pattern('^[0-9]*$')); }
if (this.data.userParams[p.name]) {
this.wfConfFormStep3.addControl(p.name, new FormControl(this.data.userParams[p.name], validations));
} else if (this.data.systemParams[p.name]) {
this.wfConfFormStep3.addControl(p.name, new FormControl({ value: this.data.systemParams[p.name], disabled: true }, validations));
} else {
this.wfConfFormStep3.addControl(p.name, new FormControl('', validations));
}
if (this.data.userParams[p.name]) {
this.wfConfFormStep3.addControl(p.name, new FormControl(this.data.userParams[p.name], validations));
} else if (this.data.systemParams[p.name]) {
this.wfConfFormStep3.addControl(p.name, new FormControl({ value: this.data.systemParams[p.name], disabled: true }, validations));
} else {
this.wfConfFormStep3.addControl(p.name, new FormControl('', validations));
}
})
});
})
});
}
onSubmit(): void {

View File

@ -61,10 +61,21 @@ export class WfConfsClient extends ISClient {
this.httpGet<SimpleResource[]>("/proxy/byType/resource_manager/api/resources/byType/wf_template", onSuccess);
}
loadWfTemplate(id: any, onSuccess: Function): void {
loadWfTemplate(id: string, onSuccess: Function): void {
const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
this.httpGetWithOptions<string>("/proxy/byType/resource_manager/api/resources/byType/wf_template/" + encodeURIComponent(id) + '/content', {
headers, responseType: 'text' as 'json'
}, onSuccess);
}
loadWfTemplatesParams(wfs: string[], onSuccess: Function) {
let opts = '';
wfs.forEach(id => {
if (opts) { opts += '&'; }
opts += 'wf=' + encodeURIComponent(id);
});
this.httpGet<SimpleResource[]>('/proxy/byType/wf_manager/api/parameters?' + opts, onSuccess);
}
}

View File

@ -1,6 +1,8 @@
package eu.dnetlib.domain.wfs.templates;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@ -14,29 +16,9 @@ public class WfParam implements Serializable {
private String description;
private WfParamType type = WfParamType.STRING;
private String defaultValue;
private List<String> validTerms = new ArrayList<>();
private boolean required = true;
public WfParam() {}
public WfParam(final String name) {
this.name = name;
this.description = name;
}
public WfParam(final String name, final WfParamType type) {
this.name = name;
this.description = name;
this.type = type;
}
public WfParam(final String name, final String description, final WfParamType type, final String defaultValue, final boolean required) {
this.name = name;
this.description = description;
this.type = type;
this.defaultValue = defaultValue;
this.required = required;
}
public String getName() {
return this.name;
}
@ -77,4 +59,12 @@ public class WfParam implements Serializable {
this.required = required;
}
public List<String> getValidTerms() {
return this.validTerms;
}
public void setValidTerms(final List<String> validTerms) {
this.validTerms = validTerms;
}
}

View File

@ -46,9 +46,19 @@ class WorkflowTemplateTest {
this.a23 = new Arc("N3");
this.a3succ = new Arc("success");
this.p1 = new WfParam("Name");
this.p2 = new WfParam("Age", WfParamType.NUMBER);
this.p3 = new WfParam("Birthday", "Your Birthday", WfParamType.DATE, "1900-01-01", false);
this.p1 = new WfParam();
this.p1.setName("Name");
this.p2 = new WfParam();
this.p2.setName("Age");
this.p2.setType(WfParamType.NUMBER);
this.p3 = new WfParam();
this.p3.setName("Birthday");
this.p3.setDescription("Your Birthday");
this.p3.setType(WfParamType.DATE);
this.p3.setDefaultValue("1900-01-01");
this.p3.setRequired(false);
this.np1 = NodeInputParam.newRefParam("Age", "Age");
this.np1 = NodeInputParam.newSimpleParam("Test", "test");