1
|
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
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceConstants;
|
10
|
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.locators.UniqueServiceLocator;
|
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
|
21
|
private UniqueServiceLocator serviceLocator;
|
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
|
final ISLookUpService lookupService = serviceLocator.getService(ISLookUpService.class);
|
32
|
|
33
|
String compliance;
|
34
|
try {
|
35
|
compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
|
36
|
+ "']/INTERFACE_EXTRA_FIELD[@name='"
|
37
|
+ DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD + "']/text()");
|
38
|
} catch (ISLookUpDocumentNotFoundException e) {
|
39
|
compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
|
40
|
+ "']/@compliance/string()");
|
41
|
}
|
42
|
|
43
|
final String typology = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
|
44
|
+ "']/@typology/string()");
|
45
|
|
46
|
verifyValue(compliance, expectedCompliancePrefixes);
|
47
|
verifyValue(typology, expectedInterfaceTypologyPrefixes);
|
48
|
|
49
|
if (isPending(dsId)) {
|
50
|
return "validateDs";
|
51
|
} else {
|
52
|
return Arc.DEFAULT_ARC;
|
53
|
}
|
54
|
}
|
55
|
|
56
|
private void verifyValue(final String value, final String expected) throws Exception {
|
57
|
if (expected != null && !expected.isEmpty()) {
|
58
|
for (String s : Splitter.on(",").omitEmptyStrings().trimResults().split(expected)) {
|
59
|
if (value.toLowerCase().startsWith(s.toLowerCase())) { return; }
|
60
|
}
|
61
|
throw new MSROException("Invalid value: " + value + ", Valid term prefixes are: [" + expected + "]");
|
62
|
}
|
63
|
}
|
64
|
|
65
|
private boolean isPending(final String id) throws ISLookUpDocumentNotFoundException, ISLookUpException {
|
66
|
final String query = "/*[.//RESOURCE_IDENTIFIER/@value='" + id + "']//RESOURCE_KIND/@value/string()";
|
67
|
final String res = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query);
|
68
|
return res.trim().equals("PendingRepositoryResources");
|
69
|
}
|
70
|
|
71
|
public String getExpectedInterfaceTypologyPrefixes() {
|
72
|
return expectedInterfaceTypologyPrefixes;
|
73
|
}
|
74
|
|
75
|
public void setExpectedInterfaceTypologyPrefixes(final String expectedInterfaceTypologyPrefixes) {
|
76
|
this.expectedInterfaceTypologyPrefixes = expectedInterfaceTypologyPrefixes;
|
77
|
}
|
78
|
|
79
|
public String getExpectedCompliancePrefixes() {
|
80
|
return expectedCompliancePrefixes;
|
81
|
}
|
82
|
|
83
|
public void setExpectedCompliancePrefixes(final String expectedCompliancePrefixes) {
|
84
|
this.expectedCompliancePrefixes = expectedCompliancePrefixes;
|
85
|
}
|
86
|
|
87
|
}
|