Project

General

Profile

1
package eu.dnetlib.msro.workflows.nodes.index;
2

    
3
import java.util.Map;
4

    
5
import eu.dnetlib.data.provision.index.rmi.IndexService;
6
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
7
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode;
8
import eu.dnetlib.msro.workflows.nodes.blackboard.BlackboardWorkflowJobListener;
9
import eu.dnetlib.msro.workflows.procs.Env;
10
import eu.dnetlib.msro.workflows.procs.Token;
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13
import org.springframework.beans.factory.annotation.Required;
14

    
15
// TODO: Auto-generated Javadoc
16

    
17
/**
18
 * The Class CreateIndexJobNode.
19
 */
20
public class CreateIndexJobNode extends BlackboardJobNode {
21

    
22
	/**
23
	 * The Constant log.
24
	 */
25
	private static final Log log = LogFactory.getLog(CreateIndexJobNode.class);
26

    
27
	/**
28
	 * The output prefix.
29
	 */
30
	private String outputPrefix = "index_";
31

    
32
	/**
33
	 * The default backend id.
34
	 */
35
	private String defaultBackendId;
36

    
37
	/**
38
	 * The format.
39
	 */
40
	private String format;
41

    
42
	/**
43
	 * The layout.
44
	 */
45
	private String layout;
46

    
47
	/**
48
	 * The interpretation.
49
	 */
50
	private String interpretation;
51

    
52
	@Override
53
	protected String obtainServiceId(final Env env) {
54
		return getServiceLocator().getServiceId(IndexService.class);
55
	}
56

    
57
	@Override
58
	protected void prepareJob(final BlackboardJob job, final Env env) {
59
		final String env_format = env.getAttribute("format", String.class);
60
		final String env_layout = env.getAttribute("layout", String.class);
61
		final String env_interp = env.getAttribute("interpretation", String.class);
62

    
63
		if (env_format != null && !env_format.isEmpty()) {
64
			this.format = env_format;
65
		}
66
		if (env_layout != null && !env_layout.isEmpty()) {
67
			this.layout = env_layout;
68
		}
69
		if (env_interp != null && !env_interp.isEmpty()) {
70
			this.interpretation = env_interp;
71
		}
72

    
73
		log.info("preparing CREATE blackboard job: " + format + "-" + layout + "-" + interpretation);
74

    
75
		job.setAction("CREATE");
76
		job.getParameters().put("format", format);
77
		job.getParameters().put("layout", layout);
78
		job.getParameters().put("interpretation", interpretation);
79
		job.getParameters().put("backend_Id", defaultBackendId);
80
	}
81

    
82
	/**
83
	 * Gets the output prefix.
84
	 *
85
	 * @return the output prefix
86
	 */
87
	public String getOutputPrefix() {
88
		return outputPrefix;
89
	}
90

    
91
	/**
92
	 * Sets the output prefix.
93
	 *
94
	 * @param outputPrefix the output prefix
95
	 */
96
	public void setOutputPrefix(final String outputPrefix) {
97
		this.outputPrefix = outputPrefix;
98
	}
99

    
100
	@Override
101
	protected BlackboardWorkflowJobListener generateBlackboardListener(final Token token) {
102
		return new BlackboardWorkflowJobListener(token) {
103

    
104
			@Override
105
			protected void responseToEnv(final Env env, final Map<String, String> responseParams) {
106
				env.setAttribute(getOutputPrefix() + "format", getFormat());
107
				env.setAttribute(getOutputPrefix() + "layout", getLayout());
108
				env.setAttribute(getOutputPrefix() + "interpretation", getInterpretation());
109
				env.setAttribute(getOutputPrefix() + "id", responseParams.get("id"));
110
			}
111
		};
112
	}
113

    
114
	/**
115
	 * Gets the default backend id.
116
	 *
117
	 * @return the default backend id
118
	 */
119
	public String getDefaultBackendId() {
120
		return defaultBackendId;
121
	}
122

    
123
	/**
124
	 * Sets the default backend id.
125
	 *
126
	 * @param defaultBackendId the default backend id
127
	 */
128
	@Required
129
	public void setDefaultBackendId(final String defaultBackendId) {
130
		this.defaultBackendId = defaultBackendId;
131
	}
132

    
133
	/**
134
	 * Gets the format.
135
	 *
136
	 * @return the format
137
	 */
138
	public String getFormat() {
139
		return format;
140
	}
141

    
142
	/**
143
	 * Sets the format.
144
	 *
145
	 * @param format the format
146
	 */
147
	public void setFormat(final String format) {
148
		this.format = format;
149
	}
150

    
151
	/**
152
	 * Gets the layout.
153
	 *
154
	 * @return the layout
155
	 */
156
	public String getLayout() {
157
		return layout;
158
	}
159

    
160
	/**
161
	 * Sets the layout.
162
	 *
163
	 * @param layout the layout
164
	 */
165
	public void setLayout(final String layout) {
166
		this.layout = layout;
167
	}
168

    
169
	/**
170
	 * Gets the interpretation.
171
	 *
172
	 * @return the interpretation
173
	 */
174
	public String getInterpretation() {
175
		return interpretation;
176
	}
177

    
178
	/**
179
	 * Sets the interpretation.
180
	 *
181
	 * @param interpretation the interpretation
182
	 */
183
	public void setInterpretation(final String interpretation) {
184
		this.interpretation = interpretation;
185
	}
186

    
187
}
(1-1/4)