1 |
26600
|
sandro.lab
|
package eu.dnetlib.msro.workflows.nodes.repohi;
|
2 |
|
|
|
3 |
|
|
import javax.annotation.Resource;
|
4 |
|
|
|
5 |
|
|
import com.google.common.base.Splitter;
|
6 |
|
|
import com.googlecode.sarasvati.Arc;
|
7 |
|
|
import com.googlecode.sarasvati.NodeToken;
|
8 |
|
|
|
9 |
29884
|
michele.ar
|
import eu.dnetlib.datasource.common.utils.DefaultDatasourceUpdater;
|
10 |
26600
|
sandro.lab
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
|
11 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
12 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
13 |
|
|
import eu.dnetlib.enabling.tools.ServiceLocator;
|
14 |
|
|
import eu.dnetlib.msro.rmi.MSROException;
|
15 |
|
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
16 |
|
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
17 |
|
|
|
18 |
|
|
public class VerifyDatasourceJobNode extends SimpleJobNode {
|
19 |
|
|
|
20 |
|
|
@Resource(name = "lookupLocator")
|
21 |
|
|
private ServiceLocator<ISLookUpService> lookupLocator;
|
22 |
|
|
|
23 |
|
|
private String expectedInterfaceTypologyPrefixes;
|
24 |
|
|
|
25 |
|
|
private String expectedCompliancePrefixes;
|
26 |
|
|
|
27 |
|
|
@Override
|
28 |
|
|
protected String execute(final NodeToken token) throws Exception {
|
29 |
|
|
final String dsId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID);
|
30 |
|
|
final String ifaceId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE);
|
31 |
|
|
|
32 |
29884
|
michele.ar
|
String compliance;
|
33 |
|
|
try {
|
34 |
|
|
compliance = lookupLocator.getService().getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId + "']/INTERFACE_EXTRA_FIELD[@name='" + DefaultDatasourceUpdater.OVERRIDING_COMPLIANCE_FIELD + "']/text()");
|
35 |
|
|
} catch(ISLookUpDocumentNotFoundException e) {
|
36 |
|
|
compliance = lookupLocator.getService().getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId + "']/@compliance/string()");
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
final String typology = lookupLocator.getService().getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId + "']/@typology/string()");
|
40 |
26600
|
sandro.lab
|
|
41 |
29884
|
michele.ar
|
verifyValue(compliance, expectedCompliancePrefixes);
|
42 |
|
|
verifyValue(typology , expectedInterfaceTypologyPrefixes);
|
43 |
|
|
|
44 |
26600
|
sandro.lab
|
if (isPending(dsId)) return "validateDs";
|
45 |
|
|
else return Arc.DEFAULT_ARC;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
29884
|
michele.ar
|
private void verifyValue(final String value, final String expected) throws Exception {
|
49 |
26600
|
sandro.lab
|
if ((expected != null) && !expected.isEmpty()) {
|
50 |
|
|
for (String s : Splitter.on(",").omitEmptyStrings().trimResults().split(expected)) {
|
51 |
|
|
if (value.toLowerCase().startsWith(s.toLowerCase())) return;
|
52 |
|
|
}
|
53 |
|
|
throw new MSROException("Invalid value: " + value + ", Valid term prefixes are: [" + expected + "]");
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
private boolean isPending(final String id) throws ISLookUpDocumentNotFoundException, ISLookUpException {
|
58 |
|
|
final String query = "/*[.//RESOURCE_IDENTIFIER/@value='" + id + "']//RESOURCE_KIND/@value/string()";
|
59 |
|
|
final String res = lookupLocator.getService().getResourceProfileByQuery(query);
|
60 |
|
|
return res.trim().equals("PendingRepositoryResources");
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
public String getExpectedInterfaceTypologyPrefixes() {
|
64 |
|
|
return expectedInterfaceTypologyPrefixes;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
public void setExpectedInterfaceTypologyPrefixes(final String expectedInterfaceTypologyPrefixes) {
|
68 |
|
|
this.expectedInterfaceTypologyPrefixes = expectedInterfaceTypologyPrefixes;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
public String getExpectedCompliancePrefixes() {
|
72 |
|
|
return expectedCompliancePrefixes;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
public void setExpectedCompliancePrefixes(final String expectedCompliancePrefixes) {
|
76 |
|
|
this.expectedCompliancePrefixes = expectedCompliancePrefixes;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
}
|