1
|
package eu.dnetlib.msro.workflows.nodes.collect;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
import java.util.HashMap;
|
5
|
import java.util.Map;
|
6
|
|
7
|
import javax.annotation.Resource;
|
8
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
9
|
|
10
|
import eu.dnetlib.msro.rmi.MSROException;
|
11
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
12
|
import org.dom4j.Document;
|
13
|
import org.dom4j.Node;
|
14
|
import org.dom4j.io.SAXReader;
|
15
|
|
16
|
import com.googlecode.sarasvati.Arc;
|
17
|
import com.googlecode.sarasvati.NodeToken;
|
18
|
|
19
|
import eu.dnetlib.data.collector.rmi.CollectorService;
|
20
|
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
|
21
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
22
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
23
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
24
|
|
25
|
public class CollectRecordsJobNode extends SimpleJobNode {
|
26
|
|
27
|
@Resource
|
28
|
private UniqueServiceLocator serviceLocator;
|
29
|
|
30
|
private String datasourceId;
|
31
|
private String datasourceInterface;
|
32
|
private String eprParam;
|
33
|
|
34
|
@Override
|
35
|
protected String execute(final NodeToken token) throws Exception {
|
36
|
final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(datasourceId);
|
37
|
final Document doc = new SAXReader().read(new StringReader(profile));
|
38
|
final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id='" + datasourceInterface + "']");
|
39
|
|
40
|
final InterfaceDescriptor interfaceDescriptor = InterfaceDescriptor.newInstance(ifcNode);
|
41
|
|
42
|
if (interfaceDescriptor == null) {
|
43
|
throw new MSROException("invalid interface descriptor: " + datasourceInterface);
|
44
|
}
|
45
|
|
46
|
final W3CEndpointReference epr = serviceLocator.getService(CollectorService.class).collect(interfaceDescriptor);
|
47
|
|
48
|
token.getEnv().setAttribute(getEprParam(), epr.toString());
|
49
|
|
50
|
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE_BASEURL, interfaceDescriptor.getBaseUrl());
|
51
|
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_PREFIX + "protocol", interfaceDescriptor.getProtocol());
|
52
|
final Map<String, String> params = interfaceDescriptor.getParams();
|
53
|
if (params != null) {
|
54
|
for(Map.Entry<String, String> e : params.entrySet()) {
|
55
|
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_PREFIX + e.getKey(), e.getValue());
|
56
|
}
|
57
|
}
|
58
|
|
59
|
return Arc.DEFAULT_ARC;
|
60
|
}
|
61
|
|
62
|
public String getDatasourceId() {
|
63
|
return datasourceId;
|
64
|
}
|
65
|
|
66
|
public void setDatasourceId(final String datasourceId) {
|
67
|
this.datasourceId = datasourceId;
|
68
|
}
|
69
|
|
70
|
public String getDatasourceInterface() {
|
71
|
return datasourceInterface;
|
72
|
}
|
73
|
|
74
|
public void setDatasourceInterface(final String datasourceInterface) {
|
75
|
this.datasourceInterface = datasourceInterface;
|
76
|
}
|
77
|
|
78
|
public String getEprParam() {
|
79
|
return eprParam;
|
80
|
}
|
81
|
|
82
|
public void setEprParam(final String eprParam) {
|
83
|
this.eprParam = eprParam;
|
84
|
}
|
85
|
|
86
|
}
|