Revision 54517
Added by Claudio Atzori almost 6 years ago
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/actions/ExtractOutputPathJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.actions; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import com.googlecode.sarasvati.Arc; |
|
5 |
import com.googlecode.sarasvati.NodeToken; |
|
6 |
import eu.dnetlib.msro.rmi.MSROException; |
|
7 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
|
|
10 |
import java.util.List; |
|
11 |
import java.util.Map; |
|
12 |
|
|
13 |
public class ExtractOutputPathJobNode extends SimpleJobNode { |
|
14 |
|
|
15 |
private String hdfsOutputPathParam; |
|
16 |
|
|
17 |
|
|
18 |
@Override |
|
19 |
protected String execute(NodeToken token) throws Exception { |
|
20 |
final String sets = token.getEnv().getAttribute("sets"); |
|
21 |
if (StringUtils.isBlank(sets)) |
|
22 |
throw new MSROException("¯\\\\_(ツ)_/¯ cannot find sets on env"); |
|
23 |
|
|
24 |
final List<Map<String, String>> setsMap = new Gson().fromJson(sets, List.class); |
|
25 |
if (setsMap== null || setsMap.size() !=1) { |
|
26 |
throw new MSROException("¯\\\\_(ツ)_/¯ Sets map from json is wrong!"); |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
final String path = setsMap.get(0).get("path"); |
|
31 |
if (StringUtils.isEmpty(path)){ |
|
32 |
throw new MSROException("Path is empty"); |
|
33 |
} |
|
34 |
token.getEnv().setAttribute(getHdfsOutputPathParam(), path); |
|
35 |
return Arc.DEFAULT_ARC; |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
public String getHdfsOutputPathParam() { |
|
40 |
return hdfsOutputPathParam; |
|
41 |
} |
|
42 |
|
|
43 |
public void setHdfsOutputPathParam(String hdfsOutputPathParam) { |
|
44 |
this.hdfsOutputPathParam = hdfsOutputPathParam; |
|
45 |
} |
|
46 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/actions/PrepareActionSetsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.actions; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import com.google.common.base.Predicate; |
|
7 |
import com.google.common.collect.Maps; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import com.googlecode.sarasvati.Arc; |
|
10 |
import com.googlecode.sarasvati.NodeToken; |
|
11 |
import eu.dnetlib.actionmanager.set.RawSet; |
|
12 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
13 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
14 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
15 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
16 |
import eu.dnetlib.msro.rmi.MSROException; |
|
17 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
18 |
import org.apache.commons.logging.Log; |
|
19 |
import org.apache.commons.logging.LogFactory; |
|
20 |
import org.apache.hadoop.fs.Path; |
|
21 |
import org.springframework.beans.factory.annotation.Autowired; |
|
22 |
|
|
23 |
public class PrepareActionSetsJobNode extends SimpleJobNode { |
|
24 |
|
|
25 |
/** |
|
26 |
* logger. |
|
27 |
*/ |
|
28 |
private static final Log log = LogFactory.getLog(PrepareActionSetsJobNode.class); |
|
29 |
|
|
30 |
private String ACTIONSET_PATH_XQUERY_TEMPLATE = |
|
31 |
"for $x in collection('/db/DRIVER/ActionManagerSetDSResources/ActionManagerSetDSResourceType') " |
|
32 |
+ "return $x/RESOURCE_PROFILE/BODY/SET[@id = '%s']/@directory/string()"; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private UniqueServiceLocator serviceLocator; |
|
36 |
|
|
37 |
private String sets; |
|
38 |
|
|
39 |
@Override |
|
40 |
protected String execute(final NodeToken token) throws Exception { |
|
41 |
|
|
42 |
final List<Map<String, String>> setList = getSetList(); |
|
43 |
final String now = DateUtils.now_ISO8601(); |
|
44 |
|
|
45 |
final ISLookUpService lookUpService = serviceLocator.getService(ISLookUpService.class); |
|
46 |
final String basePath = lookUpService.getResourceProfileByQuery( |
|
47 |
"/RESOURCE_PROFILE[./HEADER/RESOURCE_TYPE/@value='ActionManagerServiceResourceType']//SERVICE_PROPERTIES/PROPERTY[@key='basePath']/@value/string()"); |
|
48 |
|
|
49 |
for (Map<String, String> set : setList) { |
|
50 |
|
|
51 |
set.put("rawset", RawSet.newInstance().getId()); |
|
52 |
set.put("creationDate", now); |
|
53 |
set.put("path", getFullPath(basePath, set, lookUpService)); |
|
54 |
|
|
55 |
if (set.get("enabled").equals("true")) { |
|
56 |
log.info("preparing set: " + simplifySetInfo(set)); |
|
57 |
} |
|
58 |
// setting the job properties needed to name the rawsets |
|
59 |
token.getEnv().setAttribute(set.get("jobProperty"), set.get("rawset")); |
|
60 |
} |
|
61 |
|
|
62 |
token.getEnv().setAttribute("sets", new Gson().toJson(setList)); |
|
63 |
token.getEnv().setAttribute("actionManagerBasePath", basePath); |
|
64 |
|
|
65 |
return Arc.DEFAULT_ARC; |
|
66 |
} |
|
67 |
|
|
68 |
private String getFullPath(final String basePath, final Map<String, String> set, final ISLookUpService lookUpService) throws MSROException { |
|
69 |
return new Path(basePath + "/" + getPath(set.get("set"), lookUpService) + "/" + set.get("rawset")).toString(); |
|
70 |
} |
|
71 |
|
|
72 |
private String getPath(final String setId, final ISLookUpService lookUpService) throws MSROException { |
|
73 |
try { |
|
74 |
return lookUpService.getResourceProfileByQuery(String.format(ACTIONSET_PATH_XQUERY_TEMPLATE, setId)); |
|
75 |
} catch (ISLookUpException e) { |
|
76 |
throw new MSROException(String.format("Error obtaining directory from ActionSet profile %s", setId), e); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
private Map<String, String> simplifySetInfo(final Map<String, String> set) { |
|
81 |
return Maps.filterKeys(set, new Predicate<String>() { |
|
82 |
|
|
83 |
@Override |
|
84 |
public boolean apply(final String k) { |
|
85 |
|
|
86 |
return k.equals("set") || k.equals("rawset"); |
|
87 |
} |
|
88 |
}); |
|
89 |
} |
|
90 |
|
|
91 |
@SuppressWarnings("unchecked") |
|
92 |
protected List<Map<String, String>> getSetList() { |
|
93 |
return new Gson().fromJson(getSets(), List.class); |
|
94 |
} |
|
95 |
|
|
96 |
public String getSets() { |
|
97 |
return sets; |
|
98 |
} |
|
99 |
|
|
100 |
public void setSets(final String sets) { |
|
101 |
this.sets = sets; |
|
102 |
} |
|
103 |
|
|
104 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/actions/PromoteActionsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.actions; |
|
2 |
|
|
3 |
import com.googlecode.sarasvati.NodeToken; |
|
4 |
import eu.dnetlib.actionmanager.rmi.ActionManagerService; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
7 |
import org.apache.commons.lang.StringUtils; |
|
8 |
|
|
9 |
public class PromoteActionsJobNode extends BlackboardJobNode { |
|
10 |
|
|
11 |
public static final String ALL_SETS = "ALL SETS"; |
|
12 |
|
|
13 |
private String set; |
|
14 |
|
|
15 |
@Override |
|
16 |
protected String obtainServiceId(final NodeToken token) { |
|
17 |
return getServiceLocator().getServiceId(ActionManagerService.class); |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
22 |
job.setAction("PROMOTE"); |
|
23 |
if (!StringUtils.isBlank(getSet()) && !getSet().equals(ALL_SETS)) { |
|
24 |
job.getParameters().put("set", getSet()); |
|
25 |
token.getEnv().setAttribute("set", getSet()); |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
public String getSet() { |
|
30 |
return set; |
|
31 |
} |
|
32 |
|
|
33 |
public void setSet(final String set) { |
|
34 |
this.set = set; |
|
35 |
} |
|
36 |
|
|
37 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/actions/PromoteActionsHDFSJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.actions; |
|
2 |
|
|
3 |
import com.googlecode.sarasvati.NodeToken; |
|
4 |
import eu.dnetlib.actionmanager.rmi.ActionManagerService; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
6 |
import eu.dnetlib.msro.workflows.nodes.BlackboardJobNode; |
|
7 |
import org.apache.commons.lang.StringUtils; |
|
8 |
|
|
9 |
/** |
|
10 |
* Created by claudio on 14/04/16. |
|
11 |
*/ |
|
12 |
public class PromoteActionsHDFSJobNode extends BlackboardJobNode { |
|
13 |
|
|
14 |
public static final String ALL_SETS = "ALL SETS"; |
|
15 |
|
|
16 |
private String set; |
|
17 |
|
|
18 |
@Override |
|
19 |
protected String obtainServiceId(final NodeToken token) { |
|
20 |
return getServiceLocator().getServiceId(ActionManagerService.class); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void prepareJob(final BlackboardJob job, final NodeToken token) throws Exception { |
|
25 |
job.setAction("PROMOTE_FROM_HDFS"); |
|
26 |
if (!StringUtils.isBlank(getSet()) && !getSet().equals(ALL_SETS)) { |
|
27 |
job.getParameters().put("set", getSet()); |
|
28 |
token.getEnv().setAttribute("set", getSet()); |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
public String getSet() { |
|
33 |
return set; |
|
34 |
} |
|
35 |
|
|
36 |
public void setSet(final String set) { |
|
37 |
this.set = set; |
|
38 |
} |
|
39 |
|
|
40 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/contexts/ProcessContextsJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import com.googlecode.sarasvati.Arc; |
|
6 |
import com.googlecode.sarasvati.NodeToken; |
|
7 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
8 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
9 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
10 |
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory; |
|
11 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
12 |
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
|
|
16 |
public class ProcessContextsJobNode extends SimpleJobNode implements ProgressJobNode { |
|
17 |
|
|
18 |
private static final Log log = LogFactory.getLog(ProcessContextsJobNode.class); |
|
19 |
|
|
20 |
private String eprParam; |
|
21 |
private String contextObj; |
|
22 |
private ResultsetProgressProvider progressProvider; |
|
23 |
private String contextId; |
|
24 |
private String contextLabel; |
|
25 |
private String contextType; |
|
26 |
|
|
27 |
private String contextParams; |
|
28 |
private String dashboardVisibility; |
|
29 |
|
|
30 |
@Resource |
|
31 |
private ResultSetClientFactory resultSetClientFactory; |
|
32 |
|
|
33 |
@Resource |
|
34 |
private ProcessCountingResultSetFactory processCountingResultSetFactory; |
|
35 |
|
|
36 |
@Override |
|
37 |
protected String execute(final NodeToken token) throws Exception { |
|
38 |
|
|
39 |
final String epr = token.getEnv().getAttribute(eprParam); |
|
40 |
|
|
41 |
this.progressProvider = processCountingResultSetFactory.createProgressProvider(token.getProcess(), epr); |
|
42 |
|
|
43 |
final Iterable<String> iter = resultSetClientFactory.getClient(progressProvider.getEpr()); |
|
44 |
|
|
45 |
final ContextDesc context = ContextUtils.getContext(iter, getContextId(), getContextLabel(), getContextType(), getContextParams(), getDashboardVisibility()); |
|
46 |
|
|
47 |
token.getEnv().setTransientAttribute(contextObj, context); |
|
48 |
|
|
49 |
return Arc.DEFAULT_ARC; |
|
50 |
} |
|
51 |
|
|
52 |
public String getEprParam() { |
|
53 |
return eprParam; |
|
54 |
} |
|
55 |
|
|
56 |
public void setEprParam(final String eprParam) { |
|
57 |
this.eprParam = eprParam; |
|
58 |
} |
|
59 |
|
|
60 |
public String getContextObj() { |
|
61 |
return contextObj; |
|
62 |
} |
|
63 |
|
|
64 |
public void setContextObj(final String contextObj) { |
|
65 |
this.contextObj = contextObj; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public ProgressProvider getProgressProvider() { |
|
70 |
return progressProvider; |
|
71 |
} |
|
72 |
|
|
73 |
public String getContextId() { |
|
74 |
return contextId; |
|
75 |
} |
|
76 |
|
|
77 |
public void setContextId(final String contextId) { |
|
78 |
this.contextId = contextId; |
|
79 |
} |
|
80 |
|
|
81 |
public String getContextLabel() { |
|
82 |
return contextLabel; |
|
83 |
} |
|
84 |
|
|
85 |
public void setContextLabel(final String contextLabel) { |
|
86 |
this.contextLabel = contextLabel; |
|
87 |
} |
|
88 |
|
|
89 |
public String getContextType() { |
|
90 |
return contextType; |
|
91 |
} |
|
92 |
|
|
93 |
public void setContextType(final String contextType) { |
|
94 |
this.contextType = contextType; |
|
95 |
} |
|
96 |
|
|
97 |
public String getContextParams() { |
|
98 |
return contextParams; |
|
99 |
} |
|
100 |
|
|
101 |
public void setContextParams(final String contextParams) { |
|
102 |
this.contextParams = contextParams; |
|
103 |
} |
|
104 |
|
|
105 |
public String getDashboardVisibility() { |
|
106 |
return dashboardVisibility; |
|
107 |
} |
|
108 |
|
|
109 |
public void setDashboardVisibility(final String dashboardVisibility) { |
|
110 |
this.dashboardVisibility = dashboardVisibility; |
|
111 |
} |
|
112 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/contexts/ContextDesc.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
import java.util.Map.Entry; |
|
6 |
|
|
7 |
import com.google.common.collect.Lists; |
|
8 |
import com.google.common.collect.Maps; |
|
9 |
import org.dom4j.DocumentHelper; |
|
10 |
import org.dom4j.Element; |
|
11 |
|
|
12 |
public class ContextDesc { |
|
13 |
|
|
14 |
private String id; |
|
15 |
private String label; |
|
16 |
private String type; |
|
17 |
private String xml; |
|
18 |
private Map<String, ContextPart> categories = Maps.newLinkedHashMap(); |
|
19 |
private Map<String, String> dbEntries = Maps.newLinkedHashMap(); |
|
20 |
private Map<String, String> params; |
|
21 |
|
|
22 |
public ContextDesc(final String id, final String label, final String type, final Map<String, String> params) { |
|
23 |
this.id = id; |
|
24 |
this.label = label; |
|
25 |
this.type = type; |
|
26 |
this.params = params; |
|
27 |
} |
|
28 |
|
|
29 |
public String getId() { |
|
30 |
return id; |
|
31 |
} |
|
32 |
|
|
33 |
public void setId(final String id) { |
|
34 |
this.id = id; |
|
35 |
} |
|
36 |
|
|
37 |
public String getLabel() { |
|
38 |
return label; |
|
39 |
} |
|
40 |
|
|
41 |
public void setLabel(final String label) { |
|
42 |
this.label = label; |
|
43 |
} |
|
44 |
|
|
45 |
public String getType() { |
|
46 |
return type; |
|
47 |
} |
|
48 |
|
|
49 |
public void setType(final String type) { |
|
50 |
this.type = type; |
|
51 |
} |
|
52 |
|
|
53 |
public String getXml() { |
|
54 |
return xml; |
|
55 |
} |
|
56 |
|
|
57 |
public void setXml(final String xml) { |
|
58 |
this.xml = xml; |
|
59 |
} |
|
60 |
|
|
61 |
public Map<String, ContextPart> getCategories() { |
|
62 |
return categories; |
|
63 |
} |
|
64 |
|
|
65 |
public void setCategories(final Map<String, ContextPart> categories) { |
|
66 |
this.categories = categories; |
|
67 |
} |
|
68 |
|
|
69 |
public Map<String, String> getDbEntries() { |
|
70 |
return dbEntries; |
|
71 |
} |
|
72 |
|
|
73 |
public void setDbEntries(final Map<String, String> dbEntries) { |
|
74 |
this.dbEntries = dbEntries; |
|
75 |
} |
|
76 |
|
|
77 |
public Element asDomElement() { |
|
78 |
final Element ctxElem = DocumentHelper.createElement("context"); |
|
79 |
ctxElem.addAttribute("id", getId()); |
|
80 |
ctxElem.addAttribute("label", getLabel()); |
|
81 |
ctxElem.addAttribute("type", getType()); |
|
82 |
for (Element param : getParamsAsElements()) { |
|
83 |
ctxElem.add(param); |
|
84 |
} |
|
85 |
for (ContextPart part : getCategories().values()) { |
|
86 |
ctxElem.add(part.asDomElement("category")); |
|
87 |
} |
|
88 |
|
|
89 |
return ctxElem; |
|
90 |
} |
|
91 |
|
|
92 |
public List<Element> getParamsAsElements() { |
|
93 |
List<Element> elements = Lists.newArrayList(); |
|
94 |
for (Entry<String, String> e : params.entrySet()) { |
|
95 |
Element param = DocumentHelper.createElement("param"); |
|
96 |
param.addAttribute("name", e.getKey()); |
|
97 |
param.setText(e.getValue()); |
|
98 |
elements.add(param); |
|
99 |
} |
|
100 |
return elements; |
|
101 |
} |
|
102 |
|
|
103 |
public Map<String, String> getParams() { |
|
104 |
return params; |
|
105 |
} |
|
106 |
|
|
107 |
public void setParams(final Map<String, String> params) { |
|
108 |
this.params = params; |
|
109 |
} |
|
110 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/contexts/ContextUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.lang.reflect.Type; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.Map.Entry; |
|
7 |
|
|
8 |
import com.google.common.base.Function; |
|
9 |
import com.google.common.collect.Maps; |
|
10 |
import com.google.common.reflect.TypeToken; |
|
11 |
import com.google.gson.Gson; |
|
12 |
import org.apache.commons.lang.StringUtils; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
import org.dom4j.*; |
|
16 |
import org.dom4j.io.SAXReader; |
|
17 |
|
|
18 |
/** |
|
19 |
* Created by claudio on 01/03/16. |
|
20 |
*/ |
|
21 |
public class ContextUtils { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(ContextUtils.class); |
|
24 |
private static final String DASHBOARD_VISIBILITY = "status"; |
|
25 |
|
|
26 |
public static ContextDesc getContext(final Iterable<String> it, |
|
27 |
final String contextId, |
|
28 |
final String contextLabel, |
|
29 |
final String contextType, |
|
30 |
final String params, final String dashboardVisibility) throws |
|
31 |
DocumentException { |
|
32 |
|
|
33 |
final Map<String, String> paramMap = getParamMap(params); |
|
34 |
paramMap.put(DASHBOARD_VISIBILITY, dashboardVisibility); |
|
35 |
return new ContextUtils().getContextDesc(it, contextId, contextLabel, contextType, paramMap); |
|
36 |
} |
|
37 |
|
|
38 |
private static Map<String, String> getParamMap(String jsonMap) { |
|
39 |
Map<String, String> paramMap = Maps.newHashMap(); |
|
40 |
|
|
41 |
if (StringUtils.isNotBlank(jsonMap)) { |
|
42 |
Type mapType = new TypeToken<Map<String, String>>() { |
|
43 |
}.getType(); |
|
44 |
paramMap = new Gson().fromJson(jsonMap, mapType); |
|
45 |
} |
|
46 |
return paramMap; |
|
47 |
} |
|
48 |
|
|
49 |
private ContextDesc getContextDesc(final Iterable<String> it, |
|
50 |
final String contextId, |
|
51 |
final String contextLabel, |
|
52 |
final String contextType, |
|
53 |
final Map<String, String> params) throws |
|
54 |
DocumentException { |
|
55 |
final ContextDesc context = new ContextDesc(contextId, contextLabel, contextType, params); |
|
56 |
final SAXReader reader = new SAXReader(); |
|
57 |
|
|
58 |
for (String s : it) { |
|
59 |
populateContext(context, reader, s); |
|
60 |
} |
|
61 |
return context; |
|
62 |
} |
|
63 |
|
|
64 |
private void populateContext(final ContextDesc context, final SAXReader reader, final String s) throws DocumentException { |
|
65 |
final Document doc = reader.read(new StringReader(s)); |
|
66 |
|
|
67 |
for (Object o : doc.selectNodes("//fundingtree")) { |
|
68 |
final Element treeNode = (Element) o; |
|
69 |
|
|
70 |
final String funder = treeNode.valueOf("./funder/id"); |
|
71 |
if (StringUtils.isBlank(funder)) { |
|
72 |
log.debug("No funder found, skipping population from the following XML: \n" + s); |
|
73 |
return; |
|
74 |
} |
|
75 |
if (!context.getDbEntries().containsKey(funder)) { |
|
76 |
log.info("Found funder: " + funder); |
|
77 |
context.getDbEntries().put(funder, "<fundingtree>" + treeNode.selectSingleNode("./funder").asXML() + "</fundingtree>"); |
|
78 |
log.debug("db entry: " + context.getDbEntries().get(funder)); |
|
79 |
} |
|
80 |
|
|
81 |
final String openaireId = treeNode.valueOf("./*[starts-with(local-name(),'funding_level_')]/id"); |
|
82 |
if (!context.getDbEntries().containsKey(openaireId) && StringUtils.isNotBlank(openaireId)) { |
|
83 |
log.info("Found funding: " + openaireId); |
|
84 |
context.getDbEntries().put(openaireId, treeNode.asXML()); |
|
85 |
log.debug("db entry: " + context.getDbEntries().get(openaireId)); |
|
86 |
final Node node0 = treeNode.selectSingleNode(".//funding_level_0"); |
|
87 |
if (node0 != null) { |
|
88 |
final ContextPart part = calculatePart(node0); |
|
89 |
if (context.getCategories().containsKey(part.getId())) { |
|
90 |
for (ContextPart p : part.getParts().values()) { |
|
91 |
context.getCategories().get(part.getId()).addPart(p); |
|
92 |
} |
|
93 |
} else { |
|
94 |
context.getCategories().put(part.getId(), part); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
private ContextPart calculatePart(final Node node) { |
|
102 |
|
|
103 |
// final String newId = contextId + "::" + StringUtils.substringAfter(node.valueOf("./id"), "::"); |
|
104 |
// ids are built as: nsPrefix :: funderID :: fundingLevel0ID :: etc etc, hence it seems we might not need the contextId parameter. |
|
105 |
final String newId = StringUtils.substringAfter(node.valueOf("./id"), "::"); |
|
106 |
|
|
107 |
final ContextPart part = new ContextPart(newId, node.valueOf("./description")); |
|
108 |
|
|
109 |
part.getParams().put("name", node.valueOf("./name")); |
|
110 |
part.getParams().put("openaireId", node.valueOf("./id")); |
|
111 |
part.getParams().put("class", node.valueOf("./class")); |
|
112 |
|
|
113 |
final Element parent = node.getParent() != null ? node.getParent().getParent() : null; |
|
114 |
|
|
115 |
if (parent != null && parent.getName().startsWith("funding_level_")) { |
|
116 |
final ContextPart p = calculatePart(parent); |
|
117 |
part.getParts().put(p.getId(), p); |
|
118 |
} |
|
119 |
return part; |
|
120 |
} |
|
121 |
|
|
122 |
public static Function<Entry<String, String>, String> getContextRowTransformer() { |
|
123 |
|
|
124 |
return new Function<Entry<String, String>, String>() { |
|
125 |
|
|
126 |
private final SAXReader reader = new SAXReader(); |
|
127 |
|
|
128 |
@Override |
|
129 |
public String apply(final Entry<String, String> e) { |
|
130 |
try { |
|
131 |
final Document docFundingPath = reader.read(new StringReader(e.getValue())); |
|
132 |
|
|
133 |
final Element root = DocumentHelper.createElement("ROWS"); |
|
134 |
|
|
135 |
final Map<String, String> fundingFields = Maps.newLinkedHashMap(); |
|
136 |
fundingFields.put("_dnet_resource_identifier_", e.getKey()); |
|
137 |
fundingFields.put("id", e.getKey()); |
|
138 |
fundingFields.put("path", e.getValue()); |
|
139 |
fundingFields.put("jurisdiction", docFundingPath.valueOf("//funder/jurisdiction")); |
|
140 |
final String desc = docFundingPath.valueOf("(//*[starts-with(local-name(),'funding_level_')])[1]/description"); |
|
141 |
if (StringUtils.isNotBlank(desc)) { |
|
142 |
fundingFields.put("description", desc); |
|
143 |
} |
|
144 |
final Map<String, String> orgFields = findFunderInfo(docFundingPath); |
|
145 |
final String orgId = orgFields.get("id"); |
|
146 |
if (StringUtils.isNotBlank(orgId)) { |
|
147 |
addRow(root, "dsm_organizations", orgFields); |
|
148 |
fundingFields.put("funder", orgId); |
|
149 |
} |
|
150 |
|
|
151 |
addRow(root, "fundingpaths", fundingFields); |
|
152 |
|
|
153 |
if (log.isDebugEnabled()) { |
|
154 |
log.debug("Db entries: " + root.asXML()); |
|
155 |
} |
|
156 |
|
|
157 |
return root.asXML(); |
|
158 |
} catch (DocumentException e1) { |
|
159 |
log.error("Error parsing xml", e1); |
|
160 |
throw new RuntimeException("Error parsing xml", e1); |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
private Map<String, String> findFunderInfo(final Document doc) { |
|
165 |
final Map<String, String> res = Maps.newLinkedHashMap(); |
|
166 |
res.put("_dnet_resource_identifier_", doc.valueOf("//funder/id")); |
|
167 |
res.put("id", doc.valueOf("//funder/id")); |
|
168 |
res.put("legalshortname", doc.valueOf("//funder/shortname")); |
|
169 |
res.put("legalname", doc.valueOf("//funder/name")); |
|
170 |
return res; |
|
171 |
} |
|
172 |
|
|
173 |
private void addRow(final Element root, final String table, final Map<String, String> fields) { |
|
174 |
final Element row = root.addElement("ROW"); |
|
175 |
row.addAttribute("table", table); |
|
176 |
for (Map.Entry<String, String> e : fields.entrySet()) { |
|
177 |
final Element pathField = row.addElement("FIELD"); |
|
178 |
pathField.addAttribute("name", e.getKey()); |
|
179 |
pathField.setText(e.getValue()); |
|
180 |
} |
|
181 |
} |
|
182 |
}; |
|
183 |
} |
|
184 |
|
|
185 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/contexts/GenerateFETH2020ContextJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import javax.annotation.Resource; |
|
5 |
|
|
6 |
import com.googlecode.sarasvati.Arc; |
|
7 |
import com.googlecode.sarasvati.NodeToken; |
|
8 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
9 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
10 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
11 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
12 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
13 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
14 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
15 |
import eu.dnetlib.msro.workflows.resultset.ProcessCountingResultSetFactory; |
|
16 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
17 |
import eu.dnetlib.msro.workflows.util.ResultsetProgressProvider; |
|
18 |
import org.apache.commons.logging.Log; |
|
19 |
import org.apache.commons.logging.LogFactory; |
|
20 |
|
|
21 |
public class GenerateFETH2020ContextJobNode extends SimpleJobNode implements ProgressJobNode { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(GenerateFETH2020ContextJobNode.class); |
|
24 |
private String eprParam; |
|
25 |
private ResultsetProgressProvider progressProvider; |
|
26 |
@Resource |
|
27 |
private ResultSetClientFactory resultSetClientFactory; |
|
28 |
@Resource |
|
29 |
private ProcessCountingResultSetFactory processCountingResultSetFactory; |
|
30 |
@Resource |
|
31 |
private UniqueServiceLocator serviceLocator; |
|
32 |
|
|
33 |
@Override |
|
34 |
public ProgressProvider getProgressProvider() { |
|
35 |
return this.progressProvider; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected String execute(NodeToken token) throws Exception { |
|
40 |
final String epr = token.getEnv().getAttribute(eprParam); |
|
41 |
|
|
42 |
this.progressProvider = processCountingResultSetFactory.createProgressProvider(token.getProcess(), epr); |
|
43 |
|
|
44 |
final Iterable<String> iter = resultSetClientFactory.getClient(progressProvider.getEpr()); |
|
45 |
|
|
46 |
BuildH2020FETTaxonomy builder = new BuildH2020FETTaxonomy(); |
|
47 |
builder.setIterator(iter.iterator()); |
|
48 |
String taxonomy = builder.parseProjects(); |
|
49 |
final String xquery = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " |
|
50 |
+ "where $x//CONFIGURATION/context[@id='fet-h2020'] return $x//RESOURCE_IDENTIFIER/@value/string()"; |
|
51 |
List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery); |
|
52 |
if (list.isEmpty()) { |
|
53 |
registerProfile(taxonomy); |
|
54 |
} else { |
|
55 |
deleteProfile(list.get(0)); |
|
56 |
registerProfile(taxonomy); |
|
57 |
} |
|
58 |
return Arc.DEFAULT_ARC; |
|
59 |
} |
|
60 |
|
|
61 |
private void registerProfile(String profile) throws ISRegistryException { |
|
62 |
log.info("registering fet-h2020 profile"); |
|
63 |
ISRegistryService is = serviceLocator.getService(ISRegistryService.class); |
|
64 |
String id = is.registerProfile(profile); |
|
65 |
log.info("Generating profile with id " + id); |
|
66 |
} |
|
67 |
|
|
68 |
private void deleteProfile(String profId) throws ISRegistryException { |
|
69 |
log.info("deleting fet-h2020 profile with id " + profId); |
|
70 |
ISRegistryService is = serviceLocator.getService(ISRegistryService.class); |
|
71 |
is.deleteProfile(profId); |
|
72 |
} |
|
73 |
|
|
74 |
public String getEprParam() { |
|
75 |
return eprParam; |
|
76 |
} |
|
77 |
|
|
78 |
public void setEprParam(final String eprParam) { |
|
79 |
this.eprParam = eprParam; |
|
80 |
} |
|
81 |
|
|
82 |
public void setProgressProvider(final ResultsetProgressProvider progressProvider) { |
|
83 |
this.progressProvider = progressProvider; |
|
84 |
} |
|
85 |
|
|
86 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
87 |
return resultSetClientFactory; |
|
88 |
} |
|
89 |
|
|
90 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
91 |
this.resultSetClientFactory = resultSetClientFactory; |
|
92 |
} |
|
93 |
|
|
94 |
public ProcessCountingResultSetFactory getProcessCountingResultSetFactory() { |
|
95 |
return processCountingResultSetFactory; |
|
96 |
} |
|
97 |
|
|
98 |
public void setProcessCountingResultSetFactory(final ProcessCountingResultSetFactory processCountingResultSetFactory) { |
|
99 |
this.processCountingResultSetFactory = processCountingResultSetFactory; |
|
100 |
} |
|
101 |
|
|
102 |
public UniqueServiceLocator getServiceLocator() { |
|
103 |
return serviceLocator; |
|
104 |
} |
|
105 |
|
|
106 |
public void setServiceLocator(final UniqueServiceLocator serviceLocator) { |
|
107 |
this.serviceLocator = serviceLocator; |
|
108 |
} |
|
109 |
|
|
110 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/contexts/SaveContextProfileJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.List; |
|
5 |
import javax.annotation.Resource; |
|
6 |
|
|
7 |
import com.googlecode.sarasvati.Arc; |
|
8 |
import com.googlecode.sarasvati.NodeToken; |
|
9 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
10 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException; |
|
11 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
12 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
13 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
14 |
import org.apache.commons.logging.Log; |
|
15 |
import org.apache.commons.logging.LogFactory; |
|
16 |
import org.dom4j.Document; |
|
17 |
import org.dom4j.DocumentException; |
|
18 |
import org.dom4j.Element; |
|
19 |
import org.dom4j.Node; |
|
20 |
import org.dom4j.io.SAXReader; |
|
21 |
|
|
22 |
public class SaveContextProfileJobNode extends SimpleJobNode { |
|
23 |
|
|
24 |
private String contextObj; |
|
25 |
|
|
26 |
private static final Log log = LogFactory.getLog(SaveContextProfileJobNode.class); |
|
27 |
|
|
28 |
@Resource |
|
29 |
private UniqueServiceLocator serviceLocator; |
|
30 |
|
|
31 |
@Override |
|
32 |
protected String execute(final NodeToken token) throws Exception { |
|
33 |
final ContextDesc desc = (ContextDesc) token.getEnv().getTransientAttribute(contextObj); |
|
34 |
|
|
35 |
final String xquery = "for $x in collection('/db/DRIVER/ContextDSResources/ContextDSResourceType') " + "where $x//CONFIGURATION/context[@id='" |
|
36 |
+ desc.getId() + "' " + "and @type='" + desc.getType() + "'] " + "return $x"; |
|
37 |
List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery); |
|
38 |
|
|
39 |
if (list.isEmpty()) { |
|
40 |
registerNewProfile(desc); |
|
41 |
} else { |
|
42 |
updateProfile(list.get(0), desc); |
|
43 |
} |
|
44 |
|
|
45 |
return Arc.DEFAULT_ARC; |
|
46 |
} |
|
47 |
|
|
48 |
private boolean updateProfile(final String profile, final ContextDesc desc) throws DocumentException, ISRegistryException { |
|
49 |
final SAXReader reader = new SAXReader(); |
|
50 |
final Document doc = reader.read(new StringReader(profile)); |
|
51 |
final String profId = doc.valueOf("//HEADER/RESOURCE_IDENTIFIER/@value"); |
|
52 |
final Element ctxElem = (Element) doc.selectSingleNode("//CONFIGURATION/context[@id='" + desc.getId() + "' and @type='" + desc.getType() + "']"); |
|
53 |
updateContextParams(ctxElem, desc); |
|
54 |
|
|
55 |
for (ContextPart cat : desc.getCategories().values()) { |
|
56 |
final Node catElem = ctxElem.selectSingleNode("./category[@id='" + cat.getId() + "']"); |
|
57 |
if (catElem != null) { |
|
58 |
catElem.detach(); |
|
59 |
} |
|
60 |
ctxElem.add(cat.asDomElement("category")); |
|
61 |
} |
|
62 |
log.info("registering profile context " + desc.getId()); |
|
63 |
return serviceLocator.getService(ISRegistryService.class).updateProfile(profId, doc.asXML(), "ContextDSResourceType"); |
|
64 |
} |
|
65 |
|
|
66 |
private void updateContextParams(final Element ctxElement, ContextDesc desc) { |
|
67 |
//removing old PARAMs |
|
68 |
List<Node> oldParams = ctxElement.selectNodes("param"); |
|
69 |
for (Node n : oldParams) { |
|
70 |
n.detach(); |
|
71 |
} |
|
72 |
//adding new params |
|
73 |
for (Element param : desc.getParamsAsElements()) { |
|
74 |
ctxElement.add(param); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
private String registerNewProfile(final ContextDesc desc) throws DocumentException, ISRegistryException { |
|
79 |
final SAXReader reader = new SAXReader(); |
|
80 |
final Document doc = reader.read(getClass().getResourceAsStream( |
|
81 |
"/eu/dnetlib/msro/openaireplus/workflows/repo-hi/entityreg-contexts/xml/contextProfile.xml")); |
|
82 |
((Element) doc.selectSingleNode("//CONFIGURATION")).add(desc.asDomElement()); |
|
83 |
log.info("updating profile context " + desc.getId()); |
|
84 |
return serviceLocator.getService(ISRegistryService.class).registerProfile(doc.asXML()); |
|
85 |
} |
|
86 |
|
|
87 |
public String getContextObj() { |
|
88 |
return contextObj; |
|
89 |
} |
|
90 |
|
|
91 |
public void setContextObj(final String contextObj) { |
|
92 |
this.contextObj = contextObj; |
|
93 |
} |
|
94 |
|
|
95 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/contexts/ContextPart.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
import java.util.Map.Entry; |
|
5 |
|
|
6 |
import com.google.common.collect.Maps; |
|
7 |
import org.dom4j.DocumentHelper; |
|
8 |
import org.dom4j.Element; |
|
9 |
|
|
10 |
public class ContextPart { |
|
11 |
|
|
12 |
private String id; |
|
13 |
private String label; |
|
14 |
private Map<String, String> params = Maps.newLinkedHashMap(); |
|
15 |
private Map<String, ContextPart> parts = Maps.newLinkedHashMap(); |
|
16 |
|
|
17 |
public ContextPart() { |
|
18 |
} |
|
19 |
|
|
20 |
public ContextPart(final String id, final String label) { |
|
21 |
this.id = id; |
|
22 |
this.label = label; |
|
23 |
} |
|
24 |
|
|
25 |
public String getId() { |
|
26 |
return id; |
|
27 |
} |
|
28 |
|
|
29 |
public void setId(final String id) { |
|
30 |
this.id = id; |
|
31 |
} |
|
32 |
|
|
33 |
public String getLabel() { |
|
34 |
return label; |
|
35 |
} |
|
36 |
|
|
37 |
public void setLabel(final String label) { |
|
38 |
this.label = label; |
|
39 |
} |
|
40 |
|
|
41 |
public Map<String, String> getParams() { |
|
42 |
return params; |
|
43 |
} |
|
44 |
|
|
45 |
public void setParams(final Map<String, String> params) { |
|
46 |
this.params = params; |
|
47 |
} |
|
48 |
|
|
49 |
public Map<String, ContextPart> getParts() { |
|
50 |
return parts; |
|
51 |
} |
|
52 |
|
|
53 |
public void setParts(final Map<String, ContextPart> parts) { |
|
54 |
this.parts = parts; |
|
55 |
} |
|
56 |
|
|
57 |
public void addPart(final ContextPart part) { |
|
58 |
if (parts.containsKey(part.getId())) { |
|
59 |
final ContextPart localChild = getParts().get(part.getId()); |
|
60 |
for (ContextPart child : part.getParts().values()) { |
|
61 |
localChild.addPart(child); |
|
62 |
} |
|
63 |
} else { |
|
64 |
parts.put(part.getId(), part); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
public Element asDomElement(final String name) { |
|
69 |
final Element elem = DocumentHelper.createElement(name); |
|
70 |
elem.addAttribute("id", id); |
|
71 |
elem.addAttribute("label", label); |
|
72 |
elem.addAttribute("claim", "false"); |
|
73 |
for (Entry<String, String> e : params.entrySet()) { |
|
74 |
final Element p = elem.addElement("param"); |
|
75 |
p.addAttribute("name", e.getKey()); |
|
76 |
p.setText(e.getValue()); |
|
77 |
} |
|
78 |
for (ContextPart child : parts.values()) { |
|
79 |
elem.add(child.asDomElement("concept")); |
|
80 |
} |
|
81 |
return elem; |
|
82 |
} |
|
83 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/repohi/UpdateOpenaireMetaWfStatusJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.repohi; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
|
|
6 |
import eu.dnetlib.enabling.datasources.LocalOpenaireDatasourceManager; |
|
7 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
8 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
9 |
import eu.dnetlib.msro.workflows.nodes.repohi.UpdateMetaWfStatusJobNode; |
|
10 |
import org.springframework.beans.factory.annotation.Required; |
|
11 |
|
|
12 |
public class UpdateOpenaireMetaWfStatusJobNode extends UpdateMetaWfStatusJobNode { |
|
13 |
|
|
14 |
@Autowired |
|
15 |
private UniqueServiceLocator serviceLocator; |
|
16 |
|
|
17 |
@Autowired |
|
18 |
private LocalDatasourceManager dsManager; |
|
19 |
|
|
20 |
@Override |
|
21 |
protected void updateDatasource(final String dsId, final String ifaceId) throws Exception { |
|
22 |
|
|
23 |
final String openaireDsId = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery( |
|
24 |
"/*[.//RESOURCE_IDENTIFIER/@value = '" + dsId + "']//FIELD/value[../key='OpenAireDataSourceId']/text()"); |
|
25 |
|
|
26 |
if (openaireDsId.equals("openaire____::bootstrap")) { |
|
27 |
super.updateDatasource(dsId, ifaceId); |
|
28 |
} else { |
|
29 |
dsManager.setManaged(openaireDsId, true); |
|
30 |
dsManager.setActive(openaireDsId, ifaceId, true); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/IncrementalOperationJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import com.googlecode.sarasvati.Arc; |
|
7 |
import com.googlecode.sarasvati.NodeToken; |
|
8 |
import eu.dnetlib.common.logging.DnetLogger; |
|
9 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
10 |
import eu.dnetlib.msro.rmi.MSROException; |
|
11 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
12 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
13 |
import org.apache.commons.lang.math.NumberUtils; |
|
14 |
import org.apache.commons.logging.Log; |
|
15 |
import org.apache.commons.logging.LogFactory; |
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
|
|
18 |
public class IncrementalOperationJobNode extends SimpleJobNode { |
|
19 |
|
|
20 |
private static final Log log = LogFactory.getLog(IncrementalOperationJobNode.class); |
|
21 |
|
|
22 |
//incremental or refresh |
|
23 |
private String operationType; |
|
24 |
|
|
25 |
@Autowired |
|
26 |
private DnetLogger dnetLogger; |
|
27 |
|
|
28 |
@Override |
|
29 |
protected String execute(NodeToken nodeToken) throws Exception { |
|
30 |
|
|
31 |
if ("incremental".equalsIgnoreCase(operationType)) { |
|
32 |
final String currentWfProfileId = findCurrentWfProfileId(nodeToken); |
|
33 |
final Long lastSuccessEndDate = findLastSuccessEndDate(currentWfProfileId); |
|
34 |
if(forceRefresh(nodeToken, lastSuccessEndDate, currentWfProfileId)) return Arc.DEFAULT_ARC; |
|
35 |
log.info("Last success date "+ lastSuccessEndDate); |
|
36 |
|
|
37 |
nodeToken.getFullEnv().setAttribute("OperationTypeInfo", "Operation type set to INCREMENTAL with date "+DateUtils.calculate_ISO8601(lastSuccessEndDate)); |
|
38 |
nodeToken.getFullEnv().setAttribute("operationType", "INCREMENTAL"); |
|
39 |
nodeToken.getFullEnv().setAttribute("DateFromFilter", lastSuccessEndDate); |
|
40 |
return Arc.DEFAULT_ARC; |
|
41 |
} |
|
42 |
nodeToken.getFullEnv().setAttribute("operationType", "REFRESH"); |
|
43 |
nodeToken.getFullEnv().setAttribute("OperationTypeInfo", "Operation type manually set to REFRESH"); |
|
44 |
return Arc.DEFAULT_ARC; |
|
45 |
} |
|
46 |
|
|
47 |
protected boolean forceRefresh(final NodeToken nodeToken, final Long lastSuccessEndDate, final String currentWfProfileId) throws Exception { |
|
48 |
if (lastSuccessEndDate < 0) { |
|
49 |
nodeToken.getFullEnv().setAttribute("OperationTypeInfo", "Last success date < 0, operation forced to REFRESH"); |
|
50 |
nodeToken.getFullEnv().setAttribute("operationType", "REFRESH"); |
|
51 |
return true; |
|
52 |
} |
|
53 |
return false; |
|
54 |
} |
|
55 |
|
|
56 |
private Long findLastSuccessEndDate(String profId) { |
|
57 |
long res = -1; |
|
58 |
|
|
59 |
final Iterator<Map<String, String>> iter = dnetLogger.find(WorkflowsConstants.SYSTEM_WF_PROFILE_ID, profId); |
|
60 |
while (iter.hasNext()) { |
|
61 |
final Map<String, String> map = iter.next(); |
|
62 |
log.debug("Iterating on the logs"); |
|
63 |
if ("true".equalsIgnoreCase(map.get(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY))) { |
|
64 |
final long curr = NumberUtils.toLong(map.get(WorkflowsConstants.SYSTEM_END_DATE), -1); |
|
65 |
if (curr > res) { |
|
66 |
res = curr; |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
return res; |
|
71 |
} |
|
72 |
|
|
73 |
private String findCurrentWfProfileId(NodeToken token) throws MSROException { |
|
74 |
log.debug("Start to find the current profile Id"); |
|
75 |
final String p1 = token.getEnv().getAttribute(WorkflowsConstants.SYSTEM_WF_PROFILE_ID); |
|
76 |
if (p1 != null && !p1.isEmpty()) { |
|
77 |
log.debug("The profile Id found is "+p1); |
|
78 |
return p1; |
|
79 |
} |
|
80 |
final String p2 = token.getFullEnv().getAttribute(WorkflowsConstants.SYSTEM_WF_PROFILE_ID); |
|
81 |
if (p2 != null && !p2.isEmpty()) { |
|
82 |
log.debug("The profile Id found is "+p2); |
|
83 |
return p2; |
|
84 |
} |
|
85 |
final String p3 = token.getProcess().getEnv().getAttribute(WorkflowsConstants.SYSTEM_WF_PROFILE_ID); |
|
86 |
if (p3 != null && !p3.isEmpty()) { |
|
87 |
log.debug("The profile Id found is "+p3); |
|
88 |
return p3; |
|
89 |
} |
|
90 |
throw new MSROException("Missing property in env: " + WorkflowsConstants.SYSTEM_WF_PROFILE_ID); |
|
91 |
} |
|
92 |
|
|
93 |
public String getOperationType() { |
|
94 |
return operationType; |
|
95 |
} |
|
96 |
|
|
97 |
public void setOperationType(final String operationType) { |
|
98 |
this.operationType = operationType; |
|
99 |
} |
|
100 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/hostedby/PatchHostedByJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.hostedby; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
|
8 |
|
|
9 |
import org.apache.commons.lang.StringUtils; |
|
10 |
import org.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
import org.dom4j.Document; |
|
13 |
import org.dom4j.DocumentException; |
|
14 |
import org.dom4j.io.SAXReader; |
|
15 |
import org.springframework.beans.factory.annotation.Required; |
|
16 |
import org.springframework.beans.factory.annotation.Value; |
|
17 |
|
|
18 |
import com.google.common.collect.Maps; |
|
19 |
import com.googlecode.sarasvati.Arc; |
|
20 |
import com.googlecode.sarasvati.NodeToken; |
|
21 |
|
|
22 |
import eu.dnetlib.enabling.database.rmi.DatabaseException; |
|
23 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
|
24 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
25 |
import eu.dnetlib.enabling.resultset.MappedResultSetFactory; |
|
26 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
27 |
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils; |
|
28 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
29 |
|
|
30 |
public class PatchHostedByJobNode extends SimpleJobNode { |
|
31 |
|
|
32 |
private static final Log log = LogFactory.getLog(PatchHostedByJobNode.class); |
|
33 |
private String inputEprParam; |
|
34 |
private String outputEprParam; |
|
35 |
@Value("${dnet.openaire.db.name}") |
|
36 |
private String dbName; |
|
37 |
private String countersParam; |
|
38 |
private String hostedbyMapTable; |
|
39 |
private String xpathEntry; |
|
40 |
private String overrideDataSourceId; |
|
41 |
private String keyTypeFilter; |
|
42 |
@Resource |
|
43 |
private UniqueServiceLocator serviceLocator; |
|
44 |
private MappedResultSetFactory mappedResultSetFactory; |
|
45 |
private ResultSetClientFactory resultSetClientFactory; |
|
46 |
|
|
47 |
/** |
|
48 |
* {@inheritDoc} |
|
49 |
*/ |
|
50 |
@Override |
|
51 |
protected String execute(final NodeToken token) throws Exception { |
|
52 |
final W3CEndpointReference inputEpr = new EPRUtils().getEpr(token.getEnv().getAttribute(inputEprParam)); |
|
53 |
final HostedByCounters counters = new HostedByCounters(); |
|
54 |
String datasourceId; |
|
55 |
if (StringUtils.isEmpty(overrideDataSourceId)) { |
|
56 |
datasourceId = token.getEnv().getAttribute("parentDatasourceId"); |
|
57 |
} else { |
|
58 |
datasourceId = getOverrideDataSourceId(); |
|
59 |
} |
|
60 |
|
|
61 |
Map<String, HostedByEntry> hostedByEntryMap; |
|
62 |
|
|
63 |
if (!StringUtils.isBlank(keyTypeFilter)) { |
|
64 |
hostedByEntryMap = loadHostedByMapFromType(keyTypeFilter); |
|
65 |
} else { |
|
66 |
hostedByEntryMap = loadHostedByMap(datasourceId); |
|
67 |
} |
|
68 |
|
|
69 |
final W3CEndpointReference epr = mappedResultSetFactory.createMappedResultSet(inputEpr, new PatchHostedBy(hostedByEntryMap, |
|
70 |
getXpathEntry(), counters)); |
|
71 |
|
|
72 |
token.getEnv().setAttribute(outputEprParam, epr.toString()); |
|
73 |
token.getEnv().setTransientAttribute(countersParam, counters); |
|
74 |
|
|
75 |
return Arc.DEFAULT_ARC; |
|
76 |
} |
|
77 |
|
|
78 |
private Map<String, HostedByEntry> loadHostedByMap(final String datasourceId) throws DocumentException, DatabaseException { |
|
79 |
final String sql = "SELECT d.id, d.officialname, p.entry from %s p JOIN dsm_datasources d ON (p.datasourceid = d.id) WHERE p.oa_source_id= '%s'"; |
|
80 |
return getHostedByEntryMapByQuery(datasourceId, sql); |
|
81 |
} |
|
82 |
|
|
83 |
private Map<String, HostedByEntry> loadHostedByMapFromType(final String keyType) throws DocumentException, DatabaseException { |
|
84 |
final String sql = "SELECT d.id, d.officialname, p.entry from %s p JOIN dsm_datasources d ON (p.datasourceid = d.id) WHERE p.key_type= '%s'"; |
|
85 |
return getHostedByEntryMapByQuery(keyType, sql); |
|
86 |
} |
|
87 |
|
|
88 |
private Map<String, HostedByEntry> getHostedByEntryMapByQuery(final String datasourceId, final String sql) |
|
89 |
throws DatabaseException, DocumentException { |
|
90 |
final Map<String, HostedByEntry> map = Maps.newHashMap(); |
|
91 |
final W3CEndpointReference epr = serviceLocator.getService(DatabaseService.class).searchSQL(getDbName(), |
|
92 |
String.format(sql, getHostedbyMapTable(), datasourceId)); |
|
93 |
final SAXReader reader = new SAXReader(); |
|
94 |
for (final String s : resultSetClientFactory.getClient(epr)) { |
|
95 |
final Document doc = reader.read(new StringReader(s)); |
|
96 |
final String entry = doc.valueOf("//FIELD[@name='entry']"); |
|
97 |
final String dsId = doc.valueOf("//FIELD[@name='id']"); |
|
98 |
final String dsName = doc.valueOf("//FIELD[@name='officialname']"); |
|
99 |
map.put(entry, new HostedByEntry(dsId, dsName)); |
|
100 |
} |
|
101 |
log.info(String.format("built hostedByMap from dsId '%s', size: '%s'", datasourceId, map.size())); |
|
102 |
return map; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Getter for property 'inputEprParam'. |
|
107 |
* |
|
108 |
* @return Value for property 'inputEprParam'. |
|
109 |
*/ |
|
110 |
public String getInputEprParam() { |
|
111 |
return inputEprParam; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Setter for property 'inputEprParam'. |
|
116 |
* |
|
117 |
* @param inputEprParam |
|
118 |
* Value to set for property 'inputEprParam'. |
|
119 |
*/ |
|
120 |
public void setInputEprParam(final String inputEprParam) { |
|
121 |
this.inputEprParam = inputEprParam; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Getter for property 'outputEprParam'. |
|
126 |
* |
|
127 |
* @return Value for property 'outputEprParam'. |
|
128 |
*/ |
|
129 |
public String getOutputEprParam() { |
|
130 |
return outputEprParam; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Setter for property 'outputEprParam'. |
|
135 |
* |
|
136 |
* @param outputEprParam |
|
137 |
* Value to set for property 'outputEprParam'. |
|
138 |
*/ |
|
139 |
public void setOutputEprParam(final String outputEprParam) { |
|
140 |
this.outputEprParam = outputEprParam; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Getter for property 'dbName'. |
|
145 |
* |
|
146 |
* @return Value for property 'dbName'. |
|
147 |
*/ |
|
148 |
public String getDbName() { |
|
149 |
return dbName; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Setter for property 'dbName'. |
|
154 |
* |
|
155 |
* @param dbName |
|
156 |
* Value to set for property 'dbName'. |
|
157 |
*/ |
|
158 |
public void setDbName(final String dbName) { |
|
159 |
this.dbName = dbName; |
|
160 |
} |
|
161 |
|
|
162 |
public String getKeyTypeFilter() { |
|
163 |
return keyTypeFilter; |
|
164 |
} |
|
165 |
|
|
166 |
public void setKeyTypeFilter(final String keyTypeFilter) { |
|
167 |
this.keyTypeFilter = keyTypeFilter; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Getter for property 'mappedResultSetFactory'. |
|
172 |
* |
|
173 |
* @return Value for property 'mappedResultSetFactory'. |
|
174 |
*/ |
|
175 |
public MappedResultSetFactory getMappedResultSetFactory() { |
|
176 |
return mappedResultSetFactory; |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* Setter for property 'mappedResultSetFactory'. |
|
181 |
* |
|
182 |
* @param mappedResultSetFactory |
|
183 |
* Value to set for property 'mappedResultSetFactory'. |
|
184 |
*/ |
|
185 |
@Required |
|
186 |
public void setMappedResultSetFactory(final MappedResultSetFactory mappedResultSetFactory) { |
|
187 |
this.mappedResultSetFactory = mappedResultSetFactory; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* Getter for property 'resultSetClientFactory'. |
|
192 |
* |
|
193 |
* @return Value for property 'resultSetClientFactory'. |
|
194 |
*/ |
|
195 |
public ResultSetClientFactory getResultSetClientFactory() { |
|
196 |
return resultSetClientFactory; |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Setter for property 'resultSetClientFactory'. |
|
201 |
* |
|
202 |
* @param resultSetClientFactory |
|
203 |
* Value to set for property 'resultSetClientFactory'. |
|
204 |
*/ |
|
205 |
@Required |
|
206 |
public void setResultSetClientFactory(final ResultSetClientFactory resultSetClientFactory) { |
|
207 |
this.resultSetClientFactory = resultSetClientFactory; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Getter for property 'countersParam'. |
|
212 |
* |
|
213 |
* @return Value for property 'countersParam'. |
|
214 |
*/ |
|
215 |
public String getCountersParam() { |
|
216 |
return countersParam; |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* Setter for property 'countersParam'. |
|
221 |
* |
|
222 |
* @param countersParam |
|
223 |
* Value to set for property 'countersParam'. |
|
224 |
*/ |
|
225 |
public void setCountersParam(final String countersParam) { |
|
226 |
this.countersParam = countersParam; |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* @return the hostedbyMapTable |
|
231 |
*/ |
|
232 |
public String getHostedbyMapTable() { |
|
233 |
return hostedbyMapTable; |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* @param hostedbyMapTable |
|
238 |
* the hostedbyMapTable to set |
|
239 |
*/ |
|
240 |
public void setHostedbyMapTable(final String hostedbyMapTable) { |
|
241 |
this.hostedbyMapTable = hostedbyMapTable; |
|
242 |
} |
|
243 |
|
|
244 |
public String getXpathEntry() { |
|
245 |
return xpathEntry; |
|
246 |
} |
|
247 |
|
|
248 |
public void setXpathEntry(final String xpathEntry) { |
|
249 |
this.xpathEntry = xpathEntry; |
|
250 |
} |
|
251 |
|
|
252 |
/** |
|
253 |
* @return the overrideDataSourceId |
|
254 |
*/ |
|
255 |
public String getOverrideDataSourceId() { |
|
256 |
return overrideDataSourceId; |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* @param overrideDataSourceId |
|
261 |
* the overrideDataSourceId to set |
|
262 |
*/ |
|
263 |
public void setOverrideDataSourceId(final String overrideDataSourceId) { |
|
264 |
this.overrideDataSourceId = overrideDataSourceId; |
|
265 |
} |
|
266 |
} |
modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" ?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet45-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
<relativePath /> |
|
8 |
</parent> |
|
9 |
<modelVersion>4.0.0</modelVersion> |
|
10 |
<groupId>eu.dnetlib</groupId> |
|
11 |
<artifactId>dnet-openaireplus-workflows</artifactId> |
|
12 |
<packaging>jar</packaging> |
|
13 |
<version>6.3.27</version> |
|
14 |
|
|
15 |
<scm> |
|
16 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-openaireplus-workflows/tags/dnet-openaireplus-workflows-6.3.27</developerConnection> |
|
17 |
</scm> |
|
18 |
<dependencies> |
|
19 |
<dependency> |
|
20 |
<groupId>eu.dnetlib</groupId> |
|
21 |
<artifactId>cnr-data-flow-monitoring-core</artifactId> |
|
22 |
<version>[2.0.0,3.0.0)</version> |
|
23 |
<exclusions> |
|
24 |
<exclusion> |
|
25 |
<artifactId>wstx-asl</artifactId> |
|
26 |
<groupId>org.codehaus.woodstox</groupId> |
|
27 |
</exclusion> |
|
28 |
</exclusions> |
|
29 |
</dependency> |
|
30 |
<dependency> |
|
31 |
<groupId>eu.dnetlib</groupId> |
|
32 |
<artifactId>cnr-enabling-database-api</artifactId> |
|
33 |
<version>[2.0.0,3.0.0)</version> |
|
34 |
</dependency> |
|
35 |
<dependency> |
|
36 |
<groupId>eu.dnetlib</groupId> |
|
37 |
<artifactId>cnr-enabling-database-service</artifactId> |
|
38 |
<version>[3.0.0,4.0.0)</version> |
|
39 |
</dependency> |
|
40 |
<dependency> |
|
41 |
<groupId>eu.dnetlib</groupId> |
|
42 |
<artifactId>dnet-msro-service</artifactId> |
|
43 |
<version>[3.0.0,4.0.0)</version> |
|
44 |
</dependency> |
|
45 |
<dependency> |
|
46 |
<groupId>eu.dnetlib</groupId> |
|
47 |
<artifactId>cnr-resultset-service</artifactId> |
|
48 |
<version>[2.0.0,3.0.0)</version> |
|
49 |
</dependency> |
|
50 |
<dependency> |
|
51 |
<groupId>eu.dnetlib</groupId> |
|
52 |
<artifactId>dnet-openaire-datasource-manager</artifactId> |
|
53 |
<version>[1.0.0-SNAPSHOT,2.0.0)</version> |
|
54 |
</dependency> |
|
55 |
<dependency> |
|
56 |
<groupId>eu.dnetlib</groupId> |
|
57 |
<artifactId>dnet-openaireplus-mapping-utils</artifactId> |
|
58 |
<version>[6.2.26]</version> |
|
59 |
</dependency> |
|
60 |
<dependency> |
|
61 |
<groupId>eu.dnetlib</groupId> |
|
62 |
<artifactId>dnet-hadoop-service-rmi</artifactId> |
|
63 |
<version>[1.0.0,2.0.0)</version> |
|
64 |
</dependency> |
|
65 |
<dependency> |
|
66 |
<groupId>eu.dnetlib</groupId> |
|
67 |
<artifactId>dnet-index-solr-common</artifactId> |
|
68 |
<version>[1.0.0,2.0.0)</version> |
|
69 |
</dependency> |
|
70 |
<dependency> |
|
71 |
<groupId>eu.dnetlib</groupId> |
|
72 |
<artifactId>dnet-collector-plugins</artifactId> |
|
73 |
<version>[1.0.0,2.0.0)</version> |
|
74 |
</dependency> |
|
75 |
|
|
76 |
<dependency> |
|
77 |
<groupId>eu.dnetlib</groupId> |
|
78 |
<artifactId>dnet-actionmanager-api</artifactId> |
|
79 |
<version>[4.0.0,5.0.0)</version> |
|
80 |
</dependency> |
|
81 |
|
|
82 |
<dependency> |
|
83 |
<groupId>eu.dnetlib</groupId> |
|
84 |
<artifactId>dnet-oai-common-workflows</artifactId> |
|
85 |
<version>[5.0.0,6.0.0)</version> |
|
86 |
</dependency> |
|
87 |
|
|
88 |
<dependency> |
|
89 |
<groupId>eu.dnetlib</groupId> |
|
90 |
<artifactId>cnr-mongo-mdstore</artifactId> |
|
91 |
<version>[6.0.0,7.0.0)</version> |
|
92 |
<scope>provided</scope> |
|
93 |
</dependency> |
|
94 |
|
|
95 |
<dependency> |
|
96 |
<groupId>eu.dnetlib</groupId> |
|
97 |
<artifactId>dnet-modular-objectstore-service</artifactId> |
|
98 |
<version>[4.2.1,5.0.0)</version> |
|
99 |
<scope>provided</scope> |
|
100 |
</dependency> |
|
101 |
|
|
102 |
<dependency> |
|
103 |
<groupId>eu.dnetlib</groupId> |
|
104 |
<artifactId>dnet-index-solr-client</artifactId> |
|
105 |
<version>[2.0.0,2.9.9)</version> |
|
106 |
</dependency> |
|
107 |
|
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-openaireplus-workflows-6.3.27