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