1
|
package eu.dnetlib.administration.uis.modules.workflows;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.StringReader;
|
5
|
import java.util.Map;
|
6
|
import java.util.Map.Entry;
|
7
|
|
8
|
import javax.servlet.http.HttpServletResponse;
|
9
|
|
10
|
import org.apache.commons.io.IOUtils;
|
11
|
import org.dom4j.Document;
|
12
|
import org.dom4j.Element;
|
13
|
import org.dom4j.io.SAXReader;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.beans.factory.annotation.Value;
|
16
|
import org.springframework.core.io.ClassPathResource;
|
17
|
import org.springframework.stereotype.Controller;
|
18
|
import org.springframework.web.bind.annotation.RequestMapping;
|
19
|
import org.springframework.web.bind.annotation.RequestParam;
|
20
|
|
21
|
import eu.dnetlib.clients.dsManager.DatasourceDesc;
|
22
|
import eu.dnetlib.clients.dsManager.DsManagerClient;
|
23
|
import eu.dnetlib.clients.dsManager.IfaceDesc;
|
24
|
import eu.dnetlib.clients.is.InformationServiceClient;
|
25
|
import eu.dnetlib.miscutils.functional.xml.ApplyXsltDom4j;
|
26
|
|
27
|
@Controller
|
28
|
public class WorkflowsOtherController {
|
29
|
|
30
|
@Value("${ds.vocabulary.compatibilityLevels}")
|
31
|
private String compatibilityLevelsVocabulary;
|
32
|
|
33
|
@Autowired
|
34
|
private InformationServiceClient isClient;
|
35
|
|
36
|
@Autowired
|
37
|
private DsManagerClient dsManagerClient;
|
38
|
|
39
|
@RequestMapping("/page/datasource_api")
|
40
|
public void getDatasourceApiHtml(final HttpServletResponse res, @RequestParam final String dsId, @RequestParam final String ifaceId) throws Exception {
|
41
|
|
42
|
// final String profile = wfUtils.getDatasourceProfile(dsId);
|
43
|
/*
|
44
|
* final DatasourceDesc ds = dsManagerClient.getDatasource(dsId);
|
45
|
*
|
46
|
* final SAXReader reader = new SAXReader(); final Document doc = reader.read(new StringReader(profile));
|
47
|
*
|
48
|
* final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id = '" + ifaceId + "']");
|
49
|
*
|
50
|
* final String profileId = doc.valueOf("//RESOURCE_IDENTIFIER/@value");
|
51
|
*
|
52
|
* final String protocol = ifcNode.valueOf("./ACCESS_PROTOCOL"); final Element extra =
|
53
|
* doc.getRootElement().addElement("extra_info");
|
54
|
*
|
55
|
* final Element compLevels = extra.addElement("compatibilityLevels"); for (final VocabularyEntry e :
|
56
|
* wfUtils.fetchVocabularyTerms(compatibilityLevelsVocabulary)) { final Element l = compLevels.addElement("level");
|
57
|
* l.setText(e.getName()); }
|
58
|
*
|
59
|
* final Element parameters = extra.addElement("parameters"); for (final Object o : ifcNode.selectNodes("./ACCESS_PROTOCOL/@*")) {
|
60
|
* final Element p = parameters.addElement("param"); p.addAttribute("name", ((Node) o).getName()); p.setText(((Node) o).getText());
|
61
|
* }
|
62
|
*
|
63
|
* final Element extraFields = extra.addElement("extraFields"); for (final Object o :
|
64
|
* ifcNode.selectNodes("./INTERFACE_EXTRA_FIELD")) { final Element f = extraFields.addElement("field"); f.addAttribute("name",
|
65
|
* ((Node) o).valueOf("@name")); f.setText(((Node) o).getText()); }
|
66
|
*
|
67
|
* final Element wfs = extra.addElement("workflows"); for (final WorkflowItem item : wfUtils.listWorflowsForApi(profileId, ifaceId))
|
68
|
* { final Element wf = wfs.addElement("workflow"); wf.addAttribute("id", item.getWfId()); wf.addAttribute("name", item.getName());
|
69
|
* wf.addAttribute("description", item.getDesc()); if (item.isDestroy()) { wf.addAttribute("destroy", "1"); } } final Map<String,
|
70
|
* String> params = new HashMap<>(); params.put("profileId", doc.valueOf("//RESOURCE_IDENTIFIER/@value")); params.put("ifaceId",
|
71
|
* ifaceId); params.put("protocol", protocol); params.put("baseUrl", ifcNode.valueOf("./BASE_URL")); params.put("prefix",
|
72
|
* doc.valueOf(".//FIELD[./key = 'NamespacePrefix']/value")); params.put("typology", ifcNode.valueOf("@typology"));
|
73
|
* params.put("compliance", ifcNode.valueOf("@compliance")); params.put("overrideCompliance",
|
74
|
* ifcNode.valueOf("./INTERFACE_EXTRA_FIELD[@name='overriding_compliance']"));
|
75
|
*
|
76
|
* doc.selectSingleNode("/RESOURCE_PROFILE/HEADER").detach();
|
77
|
* doc.selectSingleNode("/RESOURCE_PROFILE/BODY/CONFIGURATION/INTERFACES").detach();
|
78
|
* doc.selectSingleNode("/RESOURCE_PROFILE/BODY/CONFIGURATION/EXTRA_FIELDS").detach();
|
79
|
* doc.selectSingleNode("/RESOURCE_PROFILE/BODY/QOS").detach(); doc.selectSingleNode("/RESOURCE_PROFILE/BODY/STATUS").detach();
|
80
|
* doc.selectSingleNode("/RESOURCE_PROFILE/BODY/SECURITY_PARAMETERS").detach();
|
81
|
* doc.selectSingleNode("/RESOURCE_PROFILE/BODY/BLACKBOARD").detach();
|
82
|
*
|
83
|
* applyXsltAndSend(res, doc, "/xslt/datasource_api.xslt", params);
|
84
|
*
|
85
|
*/
|
86
|
}
|
87
|
|
88
|
@RequestMapping("/page/wf")
|
89
|
public void getWorkflowHtml(final HttpServletResponse res, @RequestParam(value = "id", required = true) final String id) throws Exception {
|
90
|
final SAXReader reader = new SAXReader();
|
91
|
final String profile = isClient.getProfile(id);
|
92
|
final Document doc = reader.read(new StringReader(profile));
|
93
|
final Element dsNode = (Element) doc.selectSingleNode("//DATASOURCE");
|
94
|
if (dsNode != null) {
|
95
|
final String dsId = dsNode.valueOf("@id");
|
96
|
final String ifaceId = dsNode.valueOf("@interface");
|
97
|
|
98
|
final DatasourceDesc ds = dsManagerClient.getDatasource(dsId);
|
99
|
final IfaceDesc iface = ds.getInterfaces().stream().filter(ifc -> ifc.getId().equals(ifaceId)).findFirst().get();
|
100
|
|
101
|
dsNode.addAttribute("name", ds.getOfficialName());
|
102
|
dsNode.addAttribute("protocol", iface.getAccessProtocol());
|
103
|
final Element extraFields = dsNode.addElement("extraFields");
|
104
|
|
105
|
for (final Entry<String, String> e : iface.getExtraFields().entrySet()) {
|
106
|
final Element f = extraFields.addElement("field");
|
107
|
f.addAttribute("name", e.getKey());
|
108
|
f.setText(e.getValue());
|
109
|
}
|
110
|
}
|
111
|
|
112
|
applyXsltAndSend(res, doc, "/xslt/wf.xslt", null);
|
113
|
}
|
114
|
|
115
|
private void applyXsltAndSend(final HttpServletResponse res, final Document doc, final String path, final Map<String, String> params) throws IOException {
|
116
|
final ApplyXsltDom4j xslt = new ApplyXsltDom4j(new ClassPathResource(path), params);
|
117
|
res.setContentType("text/html");
|
118
|
IOUtils.copy(new StringReader(xslt.apply(doc)), res.getOutputStream());
|
119
|
}
|
120
|
|
121
|
}
|