Project

General

Profile

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.graph.Env;
8
import eu.dnetlib.msro.workflows.graph.Process;
9
import eu.dnetlib.msro.workflows.graph.ProcessAware;
10
import eu.dnetlib.msro.workflows.graph.Token;
11
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
12
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode;
13
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener;
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 Process process;
62

    
63
	@Override
64
	protected String obtainServiceId(final Env env) {
65
		return getServiceLocator().getServiceId(DownloadService.class);
66
	}
67

    
68
	/*
69
	 * (non-Javadoc)
70
	 *
71
	 * @see eu.dnetlib.msro.workflows.nodes.BlackboardJobNode#prepareJob(eu.dnetlib.enabling.tools.blackboard.BlackboardJob,
72
	 * com.googlecode.sarasvati.NodeToken)
73
	 */
74
	@Override
75
	protected void prepareJob(final BlackboardJob job, final Env env) throws Exception {
76
		job.setAction("DOWNLOAD");
77
		final String eprS = env.getAttribute(getInputeprParam(), String.class);
78
		this.progressProvider = processCountingResultSetFactory.createProgressProvider(process, eprS);
79
		job.getParameters().put("epr", progressProvider.getEpr().toString());
80
		job.getParameters().put("protocol", getProtocol());
81
		job.getParameters().put("plugin", getPlugin());
82
		job.getParameters().put("mimeType", getMimeType());
83
		job.getParameters().put("objectStoreID", getObjectStoreID());
84

    
85
		if (!StringUtils.isEmpty(getRegularExpression())) {
86
			job.getParameters().put("regularExpressions", getRegularExpression());
87
		}
88

    
89
	}
90

    
91
	@Override
92
	protected BlackboardWorkflowJobListener generateBlackboardListener(final Token token) {
93
		return new BlackboardWorkflowJobListener(token) {
94
			@Override
95
			protected void populateEnv(final Env env, Map<String, String> responseParams) {
96
				env.setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "total", responseParams.get("total"));
97
			}
98
		};
99
	}
100

    
101
	/**
102
	 * Gets the inputepr param.
103
	 *
104
	 * @return the inputeprParam
105
	 */
106
	public String getInputeprParam() {
107
		return inputeprParam;
108
	}
109

    
110
	/**
111
	 * Sets the inputepr param.
112
	 *
113
	 * @param inputeprParam the inputeprParam to set
114
	 */
115
	public void setInputeprParam(final String inputeprParam) {
116
		this.inputeprParam = inputeprParam;
117
	}
118

    
119
	/**
120
	 * Gets the object store id.
121
	 *
122
	 * @return the objectStoreID
123
	 */
124
	public String getObjectStoreID() {
125
		return objectStoreID;
126
	}
127

    
128
	/**
129
	 * Sets the object store id.
130
	 *
131
	 * @param objectStoreID the objectStoreID to set
132
	 */
133
	public void setObjectStoreID(final String objectStoreID) {
134
		this.objectStoreID = objectStoreID;
135
	}
136

    
137
	/**
138
	 * Gets the plugin.
139
	 *
140
	 * @return the plugin
141
	 */
142
	public String getPlugin() {
143
		return plugin;
144
	}
145

    
146
	/**
147
	 * Sets the plugin.
148
	 *
149
	 * @param plugin the plugin to set
150
	 */
151
	public void setPlugin(final String plugin) {
152
		this.plugin = plugin;
153
	}
154

    
155
	/**
156
	 * Gets the protocol.
157
	 *
158
	 * @return the protol
159
	 */
160
	public String getProtocol() {
161
		return protocol;
162
	}
163

    
164
	/**
165
	 * Sets the protocol.
166
	 *
167
	 * @param protol the protol to set
168
	 */
169
	public void setProtocol(final String protol) {
170
		this.protocol = protol;
171
	}
172

    
173
	/**
174
	 * Gets the mime type.
175
	 *
176
	 * @return the mimeType
177
	 */
178
	public String getMimeType() {
179
		return mimeType;
180
	}
181

    
182
	/**
183
	 * Sets the mime type.
184
	 *
185
	 * @param mimeType the mimeType to set
186
	 */
187
	public void setMimeType(final String mimeType) {
188
		this.mimeType = mimeType;
189
	}
190

    
191
	/*
192
	 * (non-Javadoc)
193
	 *
194
	 * @see eu.dnetlib.msro.workflows.nodes.ProgressJobNode#getProgressProvider()
195
	 */
196
	@Override
197
	public ProgressProvider getProgressProvider() {
198
		return progressProvider;
199
	}
200

    
201
	public String getRegularExpression() {
202
		return regularExpression;
203
	}
204

    
205
	public void setRegularExpression(final String regularExpression) {
206
		this.regularExpression = regularExpression;
207
	}
208

    
209
	@Override
210
	public void setProcess(final Process process) {
211
		this.process = process;
212
	}
213
}
(1-1/2)