1
|
package eu.dnetlib.msro.workflows.nodes.collect;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import javax.annotation.Resource;
|
7
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
8
|
|
9
|
import eu.dnetlib.msro.rmi.MSROException;
|
10
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
11
|
import org.apache.commons.lang3.StringUtils;
|
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 DateRangeCollectRecordsJobNode extends SimpleJobNode {
|
26
|
|
27
|
@Resource
|
28
|
private UniqueServiceLocator serviceLocator;
|
29
|
|
30
|
private String datasourceId;
|
31
|
private String datasourceInterface;
|
32
|
private String eprParam;
|
33
|
private String fromDateParam;
|
34
|
private String untilDateParam;
|
35
|
private String overrideFrom;
|
36
|
private String overrideUntil;
|
37
|
|
38
|
@Override
|
39
|
protected String execute(final NodeToken token) throws Exception {
|
40
|
final String profile = serviceLocator.getService(ISLookUpService.class).getResourceProfile(datasourceId);
|
41
|
final Document doc = new SAXReader().read(new StringReader(profile));
|
42
|
final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id='" + datasourceInterface + "']");
|
43
|
final String fromDate = StringUtils.isNoneBlank(overrideFrom) ? overrideFrom : token.getEnv().getAttribute(getFromDateParam());
|
44
|
final String untilDate = StringUtils.isNoneBlank(overrideUntil) ? overrideUntil :token.getEnv().getAttribute(getUntilDateParam());
|
45
|
|
46
|
final InterfaceDescriptor interfaceDescriptor = InterfaceDescriptor.newInstance(ifcNode);
|
47
|
|
48
|
if (interfaceDescriptor == null) {
|
49
|
throw new MSROException("invalid interface descriptor: " + datasourceInterface);
|
50
|
}
|
51
|
|
52
|
final W3CEndpointReference epr = serviceLocator.getService(CollectorService.class).dateRangeCollect(interfaceDescriptor, fromDate, untilDate);
|
53
|
|
54
|
token.getEnv().setAttribute(getEprParam(), epr.toString());
|
55
|
|
56
|
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE_BASEURL, interfaceDescriptor.getBaseUrl());
|
57
|
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_PREFIX + "protocol", interfaceDescriptor.getProtocol());
|
58
|
final Map<String, String> params = interfaceDescriptor.getParams();
|
59
|
if (params != null) {
|
60
|
for(Map.Entry<String, String> e : params.entrySet()) {
|
61
|
token.getEnv().setAttribute(WorkflowsConstants.DATAPROVIDER_PREFIX + e.getKey(), e.getValue());
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
return Arc.DEFAULT_ARC;
|
67
|
}
|
68
|
|
69
|
public String getFromDateParam() {
|
70
|
return fromDateParam;
|
71
|
}
|
72
|
|
73
|
public void setFromDateParam(final String fromDateParam) {
|
74
|
this.fromDateParam = fromDateParam;
|
75
|
}
|
76
|
|
77
|
public String getUntilDateParam() {
|
78
|
return untilDateParam;
|
79
|
}
|
80
|
|
81
|
public void setUntilDateParam(final String untilDateParam) {
|
82
|
this.untilDateParam = untilDateParam;
|
83
|
}
|
84
|
|
85
|
public String getDatasourceId() {
|
86
|
return datasourceId;
|
87
|
}
|
88
|
|
89
|
public void setDatasourceId(final String datasourceId) {
|
90
|
this.datasourceId = datasourceId;
|
91
|
}
|
92
|
|
93
|
public String getDatasourceInterface() {
|
94
|
return datasourceInterface;
|
95
|
}
|
96
|
|
97
|
public void setDatasourceInterface(final String datasourceInterface) {
|
98
|
this.datasourceInterface = datasourceInterface;
|
99
|
}
|
100
|
|
101
|
public String getEprParam() {
|
102
|
return eprParam;
|
103
|
}
|
104
|
|
105
|
public void setEprParam(final String eprParam) {
|
106
|
this.eprParam = eprParam;
|
107
|
}
|
108
|
|
109
|
public String getOverrideFrom() {
|
110
|
return overrideFrom;
|
111
|
}
|
112
|
|
113
|
public void setOverrideFrom(String overrideFrom) {
|
114
|
this.overrideFrom = overrideFrom;
|
115
|
}
|
116
|
|
117
|
public String getOverrideUntil() {
|
118
|
return overrideUntil;
|
119
|
}
|
120
|
|
121
|
public void setOverrideUntil(String overrideUntil) {
|
122
|
this.overrideUntil = overrideUntil;
|
123
|
}
|
124
|
}
|