Project

General

Profile

1 35797 claudio.at
package eu.dnetlib.msro.workflows.hadoop;
2
3
import java.io.IOException;
4
5
import com.googlecode.sarasvati.Arc;
6
import com.googlecode.sarasvati.NodeToken;
7 37014 claudio.at
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
8
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
9
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
10
import eu.dnetlib.msro.rmi.MSROException;
11 35797 claudio.at
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
12 40247 claudio.at
import org.apache.commons.lang.StringUtils;
13
import org.apache.commons.logging.Log;
14
import org.apache.commons.logging.LogFactory;
15
import org.springframework.beans.factory.annotation.Autowired;
16 35797 claudio.at
17
public class PrepareMDStoreImportJobNode extends SimpleJobNode {
18
19 37014 claudio.at
	private static final Log log = LogFactory.getLog(PrepareMDStoreImportJobNode.class);
20
21
	@Autowired
22
	private UniqueServiceLocator serviceLocator;
23
24 35797 claudio.at
	private String hdfsPathParam;
25 37014 claudio.at
26 35797 claudio.at
	private String hdfsPath;
27 37014 claudio.at
28
	private String mappingParam;
29
30
	private String mapping;
31
32 35797 claudio.at
	@Override
33 37014 claudio.at
	protected String execute(final NodeToken token) throws Exception {
34
35 35797 claudio.at
		token.getEnv().setAttribute(getHdfsPathParam(), getHdfsPath());
36 37014 claudio.at
		token.getEnv().setAttribute(getMappingParam(), readXslt(getMapping()));
37
38 35797 claudio.at
		return Arc.DEFAULT_ARC;
39
	}
40
41 40247 claudio.at
	private String readXslt(final String profileId) throws IOException, MSROException, ISLookUpException {
42 37014 claudio.at
		if (StringUtils.isBlank(profileId)) throw new MSROException("missing profile id");
43
44
		log.info("loading mapping from profile id: " + profileId);
45
46
		final String xquery =
47
				String.format("/RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value='%s']/BODY/CONFIGURATION/SCRIPT/CODE/*[local-name()='stylesheet']", profileId);
48
		return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery);
49 35797 claudio.at
	}
50
51
	public String getHdfsPathParam() {
52
		return hdfsPathParam;
53
	}
54
55 37014 claudio.at
	public void setHdfsPathParam(final String hdfsPathParam) {
56 35797 claudio.at
		this.hdfsPathParam = hdfsPathParam;
57
	}
58
59
	public String getHdfsPath() {
60
		return hdfsPath;
61
	}
62
63 37014 claudio.at
	public void setHdfsPath(final String hdfsPath) {
64 35797 claudio.at
		this.hdfsPath = hdfsPath;
65
	}
66
67 37014 claudio.at
	public String getMapping() {
68
		return mapping;
69 35797 claudio.at
	}
70
71 37014 claudio.at
	public void setMapping(final String mapping) {
72
		this.mapping = mapping;
73 35797 claudio.at
	}
74
75 37014 claudio.at
	public String getMappingParam() {
76
		return mappingParam;
77 35797 claudio.at
	}
78
79 37014 claudio.at
	public void setMappingParam(final String mappingParam) {
80
		this.mappingParam = mappingParam;
81 35797 claudio.at
	}
82
83
}