1
|
package eu.dnetlib.msro.workflows.nodes.download;
|
2
|
|
3
|
import java.util.Map;
|
4
|
|
5
|
import eu.dnetlib.data.download.rmi.DownloadService;
|
6
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
7
|
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
|
8
|
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode;
|
9
|
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener;
|
10
|
import eu.dnetlib.msro.workflows.procs.Env;
|
11
|
import eu.dnetlib.msro.workflows.procs.ProcessAware;
|
12
|
import eu.dnetlib.msro.workflows.procs.Token;
|
13
|
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
|
14
|
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory;
|
15
|
import eu.dnetlib.msro.workflows.util.ProgressProvider;
|
16
|
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider;
|
17
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
|
21
|
// TODO: Auto-generated Javadoc
|
22
|
|
23
|
/**
|
24
|
* The Class DownloadFromMetadata is a job node that send a blackboard message to the Download service to start to download file from url
|
25
|
* retrieved by Metadata .
|
26
|
*/
|
27
|
public class DownloadFromMetadataJobNode extends BlackboardJobNode implements ProgressJobNode, ProcessAware {
|
28
|
|
29
|
protected String regularExpression;
|
30
|
/**
|
31
|
* The inputepr param.
|
32
|
*/
|
33
|
private String inputeprParam;
|
34
|
/**
|
35
|
* The object store id.
|
36
|
*/
|
37
|
private String objectStoreID;
|
38
|
/**
|
39
|
* The plugin.
|
40
|
*/
|
41
|
private String plugin;
|
42
|
/**
|
43
|
* The protocol.
|
44
|
*/
|
45
|
private String protocol;
|
46
|
/**
|
47
|
* The mime type.
|
48
|
*/
|
49
|
private String mimeType;
|
50
|
/**
|
51
|
* The process counting result set factory.
|
52
|
*/
|
53
|
@Autowired
|
54
|
private ProcessCountingResultSetFactory processCountingResultSetFactory;
|
55
|
|
56
|
/**
|
57
|
* The progress provider.
|
58
|
*/
|
59
|
private ResultsetProgressProvider progressProvider;
|
60
|
|
61
|
private WorkflowProcess process;
|
62
|
|
63
|
@Override
|
64
|
protected String obtainServiceId(final Env env) {
|
65
|
return getServiceLocator().getServiceId(DownloadService.class);
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
protected void prepareJob(final BlackboardJob job, final Env env) throws Exception {
|
70
|
job.setAction("DOWNLOAD");
|
71
|
final String eprS = env.getAttribute(getInputeprParam(), String.class);
|
72
|
this.progressProvider = processCountingResultSetFactory.createProgressProvider(process, eprS);
|
73
|
job.getParameters().put("epr", progressProvider.getEpr().toString());
|
74
|
job.getParameters().put("protocol", getProtocol());
|
75
|
job.getParameters().put("plugin", getPlugin());
|
76
|
job.getParameters().put("mimeType", getMimeType());
|
77
|
job.getParameters().put("objectStoreID", getObjectStoreID());
|
78
|
|
79
|
if (!StringUtils.isEmpty(getRegularExpression())) {
|
80
|
job.getParameters().put("regularExpressions", getRegularExpression());
|
81
|
}
|
82
|
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
protected BlackboardWorkflowJobListener generateBlackboardListener(final Token token) {
|
87
|
return new BlackboardWorkflowJobListener(token) {
|
88
|
@Override
|
89
|
protected void responseToEnv(final Env env, Map<String, String> responseParams) {
|
90
|
env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "total", responseParams.get("total"));
|
91
|
}
|
92
|
};
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Gets the inputepr param.
|
97
|
*
|
98
|
* @return the inputeprParam
|
99
|
*/
|
100
|
public String getInputeprParam() {
|
101
|
return inputeprParam;
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Sets the inputepr param.
|
106
|
*
|
107
|
* @param inputeprParam the inputeprParam to set
|
108
|
*/
|
109
|
public void setInputeprParam(final String inputeprParam) {
|
110
|
this.inputeprParam = inputeprParam;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Gets the object store id.
|
115
|
*
|
116
|
* @return the objectStoreID
|
117
|
*/
|
118
|
public String getObjectStoreID() {
|
119
|
return objectStoreID;
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Sets the object store id.
|
124
|
*
|
125
|
* @param objectStoreID the objectStoreID to set
|
126
|
*/
|
127
|
public void setObjectStoreID(final String objectStoreID) {
|
128
|
this.objectStoreID = objectStoreID;
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* Gets the plugin.
|
133
|
*
|
134
|
* @return the plugin
|
135
|
*/
|
136
|
public String getPlugin() {
|
137
|
return plugin;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Sets the plugin.
|
142
|
*
|
143
|
* @param plugin the plugin to set
|
144
|
*/
|
145
|
public void setPlugin(final String plugin) {
|
146
|
this.plugin = plugin;
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* Gets the protocol.
|
151
|
*
|
152
|
* @return the protol
|
153
|
*/
|
154
|
public String getProtocol() {
|
155
|
return protocol;
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* Sets the protocol.
|
160
|
*
|
161
|
* @param protol the protol to set
|
162
|
*/
|
163
|
public void setProtocol(final String protol) {
|
164
|
this.protocol = protol;
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Gets the mime type.
|
169
|
*
|
170
|
* @return the mimeType
|
171
|
*/
|
172
|
public String getMimeType() {
|
173
|
return mimeType;
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* Sets the mime type.
|
178
|
*
|
179
|
* @param mimeType the mimeType to set
|
180
|
*/
|
181
|
public void setMimeType(final String mimeType) {
|
182
|
this.mimeType = mimeType;
|
183
|
}
|
184
|
|
185
|
/*
|
186
|
* (non-Javadoc)
|
187
|
*
|
188
|
* @see eu.dnetlib.msro.workflows.nodes.ProgressJobNode#getProgressProvider()
|
189
|
*/
|
190
|
@Override
|
191
|
public ProgressProvider getProgressProvider() {
|
192
|
return progressProvider;
|
193
|
}
|
194
|
|
195
|
public String getRegularExpression() {
|
196
|
return regularExpression;
|
197
|
}
|
198
|
|
199
|
public void setRegularExpression(final String regularExpression) {
|
200
|
this.regularExpression = regularExpression;
|
201
|
}
|
202
|
|
203
|
@Override
|
204
|
public void setProcess(final WorkflowProcess process) {
|
205
|
this.process = process;
|
206
|
}
|
207
|
}
|