Project

General

Profile

1
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
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
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
12
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

    
17
public class PrepareMDStoreImportJobNode extends SimpleJobNode {
18

    
19
	private static final Log log = LogFactory.getLog(PrepareMDStoreImportJobNode.class);
20

    
21
	@Autowired
22
	private UniqueServiceLocator serviceLocator;
23

    
24
	private String hdfsPathParam;
25

    
26
	private String hdfsPath;
27

    
28
	private String mappingParam;
29

    
30
	private String mapping;
31

    
32
	@Override
33
	protected String execute(final NodeToken token) throws Exception {
34

    
35
		token.getEnv().setAttribute(getHdfsPathParam(), getHdfsPath());
36
		token.getEnv().setAttribute(getMappingParam(), readXslt(getMapping()));
37

    
38
		return Arc.DEFAULT_ARC;
39
	}
40

    
41
	private String readXslt(final String profileId) throws IOException, MSROException, ISLookUpException {
42
		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
	}
50

    
51
	public String getHdfsPathParam() {
52
		return hdfsPathParam;
53
	}
54

    
55
	public void setHdfsPathParam(final String hdfsPathParam) {
56
		this.hdfsPathParam = hdfsPathParam;
57
	}
58

    
59
	public String getHdfsPath() {
60
		return hdfsPath;
61
	}
62

    
63
	public void setHdfsPath(final String hdfsPath) {
64
		this.hdfsPath = hdfsPath;
65
	}
66

    
67
	public String getMapping() {
68
		return mapping;
69
	}
70

    
71
	public void setMapping(final String mapping) {
72
		this.mapping = mapping;
73
	}
74

    
75
	public String getMappingParam() {
76
		return mappingParam;
77
	}
78

    
79
	public void setMappingParam(final String mappingParam) {
80
		this.mappingParam = mappingParam;
81
	}
82

    
83
}
(8-8/12)