Project

General

Profile

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

    
3
import java.util.Map;
4

    
5
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
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.lang.StringUtils;
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14

    
15
public class CreateObjectStoreJobNode extends BlackboardJobNode {
16

    
17
	private static final Log log = LogFactory.getLog(CreateObjectStoreJobNode.class);
18

    
19
	private String interpretation;
20
	private String outputPrefix = "objectStore_";
21

    
22
	@Override
23
	protected String obtainServiceId(final Env env) {
24
		return getServiceLocator().getServiceId(ObjectStoreService.class);
25
	}
26

    
27
	@Override
28
	protected void prepareJob(final BlackboardJob job, final Env env) {
29
		log.info("preparing blackboard job for the creation of the objectStore ");
30
		String basePath = env.getAttribute("objectStoreBasePath", String.class);
31
		job.setAction("CREATE");
32
		job.getParameters().put("interpretation", interpretation);
33
		if (!StringUtils.isEmpty(basePath)) {
34
			job.getParameters().put("basePath", basePath);
35
		}
36
	}
37

    
38
	public String getInterpretation() {
39
		return interpretation;
40
	}
41

    
42
	public void setInterpretation(final String interpretation) {
43
		this.interpretation = interpretation;
44
	}
45

    
46
	public String getOutputPrefix() {
47
		return outputPrefix;
48
	}
49

    
50
	public void setOutputPrefix(final String outputPrefix) {
51
		this.outputPrefix = outputPrefix;
52
	}
53

    
54
	@Override
55
	protected BlackboardWorkflowJobListener generateBlackboardListener(final Token token) {
56
		return new BlackboardWorkflowJobListener(token) {
57

    
58
			@Override
59
			protected void responseToEnv(final Env env, final Map<String, String> responseParams) {
60

    
61
				env.setAttribute(getOutputPrefix() + "interpretation", interpretation);
62
				env.setAttribute(getOutputPrefix() + "id", responseParams.get("objectStoreId"));
63
			}
64
		};
65
	}
66

    
67
}
(2-2/6)