Revision 45814
Added by Michele Artini about 7 years ago
MsroWorkerController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.workers.controller; |
2 | 2 |
|
3 |
import java.util.Arrays; |
|
3 | 4 |
import java.util.List; |
4 |
import java.util.stream.Collectors; |
|
5 | 5 |
|
6 |
import org.apache.commons.lang3.StringUtils; |
|
7 |
import org.dom4j.DocumentHelper; |
|
8 |
import org.dom4j.Element; |
|
6 | 9 |
import org.springframework.beans.BeansException; |
7 | 10 |
import org.springframework.context.ApplicationContext; |
8 | 11 |
import org.springframework.context.ApplicationContextAware; |
9 | 12 |
import org.springframework.web.bind.annotation.RequestMapping; |
10 | 13 |
import org.springframework.web.bind.annotation.RestController; |
11 | 14 |
|
15 |
import eu.dnetlib.clients.msro.ProtocolParameterType; |
|
12 | 16 |
import eu.dnetlib.enabling.annotations.DnetService; |
13 | 17 |
import eu.dnetlib.enabling.annotations.DnetServiceType; |
18 |
import eu.dnetlib.msro.annotations.ProcessNode; |
|
19 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.CollectorPlugin; |
|
20 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorParam; |
|
21 |
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin; |
|
14 | 22 |
import eu.dnetlib.msro.workflows.nodes.AbstractProcessNode; |
15 |
import eu.dnetlib.msro.workflows.procs.ProcessNodeDetails; |
|
16 | 23 |
import eu.dnetlib.services.BaseService; |
17 | 24 |
|
18 | 25 |
@RestController |
... | ... | |
22 | 29 |
|
23 | 30 |
private ApplicationContext applicationContext; |
24 | 31 |
|
25 |
@RequestMapping("nodes") |
|
26 |
public List<ProcessNodeDetails> listNodes() { |
|
27 |
return applicationContext.getBeansOfType(AbstractProcessNode.class) |
|
32 |
@Override |
|
33 |
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { |
|
34 |
this.applicationContext = applicationContext; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public List<Element> geXmlProfileSections() { |
|
39 |
final Element nodes = DocumentHelper.createElement("WORKFLOW_NODES"); |
|
40 |
applicationContext.getBeansOfType(AbstractProcessNode.class) |
|
28 | 41 |
.values() |
29 | 42 |
.stream() |
30 | 43 |
.map(Object::getClass) |
31 |
.map(ProcessNodeDetails::prepare) |
|
32 |
.collect(Collectors.toList()); |
|
33 |
} |
|
44 |
.filter(cl -> cl.isAnnotationPresent(ProcessNode.class)) |
|
45 |
.forEach(cl -> { |
|
46 |
final Element n = nodes.addElement("NODE"); |
|
47 |
n.addAttribute("type", cl.getAnnotation(ProcessNode.class).value()); |
|
48 |
n.addAttribute("class", cl.getName()); |
|
49 |
}); |
|
34 | 50 |
|
35 |
@Override |
|
36 |
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { |
|
37 |
this.applicationContext = applicationContext; |
|
51 |
final Element collPlugins = DocumentHelper.createElement("COLLECTOR_PLUGINS"); |
|
52 |
applicationContext.getBeansOfType(CollectorPlugin.class) |
|
53 |
.values() |
|
54 |
.stream() |
|
55 |
.map(Object::getClass) |
|
56 |
.filter(cl -> cl.isAnnotationPresent(DnetCollectorPlugin.class)) |
|
57 |
.map(cl -> cl.getAnnotation(DnetCollectorPlugin.class)) |
|
58 |
.forEach(ann -> { |
|
59 |
final Element plugin = collPlugins.addElement("PLUGIN"); |
|
60 |
plugin.addAttribute("protocol", ann.value()); |
|
61 |
for (final DnetCollectorParam ap : ann.parameters()) { |
|
62 |
final Element p = plugin.addElement("PARAM"); |
|
63 |
p.addAttribute("name", ap.value()); |
|
64 |
p.addAttribute("type", ap.type().toString()); |
|
65 |
p.addAttribute("optional", Boolean.toString(ap.optional())); |
|
66 |
if (StringUtils.isNotBlank(ap.regex()) && (ap.type() == ProtocolParameterType.TEXT)) { |
|
67 |
p.addAttribute("regex", ap.regex()); |
|
68 |
} |
|
69 |
} |
|
70 |
}); |
|
71 |
|
|
72 |
return Arrays.asList(nodes, collPlugins); |
|
38 | 73 |
} |
39 | 74 |
} |
Also available in: Unified diff