1 |
48139
|
alessia.ba
|
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 |
|
|
}
|