1 |
42169
|
michele.ar
|
package eu.dnetlib.msro.workflows.nodes.misc;
|
2 |
26600
|
sandro.lab
|
|
3 |
|
|
import com.google.common.base.Splitter;
|
4 |
32639
|
michele.ar
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
5 |
40094
|
michele.ar
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
6 |
26600
|
sandro.lab
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
7 |
40099
|
michele.ar
|
import eu.dnetlib.msro.workflows.procs.Env;
|
8 |
41620
|
michele.ar
|
import eu.dnetlib.msro.workflows.procs.ProcessAware;
|
9 |
|
|
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
|
10 |
41783
|
michele.ar
|
import eu.dnetlib.rmi.datasource.DatasourceConstants;
|
11 |
|
|
import eu.dnetlib.rmi.enabling.ISLookUpDocumentNotFoundException;
|
12 |
|
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
13 |
|
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
14 |
|
|
import eu.dnetlib.rmi.manager.MSROException;
|
15 |
42621
|
sandro.lab
|
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
26600
|
sandro.lab
|
|
17 |
41620
|
michele.ar
|
public class VerifyDatasourceJobNode extends SimpleJobNode implements ProcessAware {
|
18 |
26600
|
sandro.lab
|
|
19 |
42621
|
sandro.lab
|
@Autowired
|
20 |
32639
|
michele.ar
|
private UniqueServiceLocator serviceLocator;
|
21 |
26600
|
sandro.lab
|
|
22 |
|
|
private String expectedInterfaceTypologyPrefixes;
|
23 |
|
|
|
24 |
|
|
private String expectedCompliancePrefixes;
|
25 |
|
|
|
26 |
41620
|
michele.ar
|
private WorkflowProcess process;
|
27 |
|
|
|
28 |
26600
|
sandro.lab
|
@Override
|
29 |
40094
|
michele.ar
|
protected String execute(final Env env) throws Exception {
|
30 |
41620
|
michele.ar
|
final String dsId = this.process.getDsId();
|
31 |
|
|
final String ifaceId = this.process.getDsInterface();
|
32 |
|
|
final ISLookUpService lookupService = this.serviceLocator.getService(ISLookUpService.class);
|
33 |
26600
|
sandro.lab
|
|
34 |
29884
|
michele.ar
|
String compliance;
|
35 |
|
|
try {
|
36 |
32639
|
michele.ar
|
compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
|
37 |
|
|
+ "']/INTERFACE_EXTRA_FIELD[@name='"
|
38 |
33834
|
michele.ar
|
+ DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD + "']/text()");
|
39 |
41620
|
michele.ar
|
} catch (final ISLookUpDocumentNotFoundException e) {
|
40 |
32639
|
michele.ar
|
compliance = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
|
41 |
|
|
+ "']/@compliance/string()");
|
42 |
29884
|
michele.ar
|
}
|
43 |
26600
|
sandro.lab
|
|
44 |
32639
|
michele.ar
|
final String typology = lookupService.getResourceProfileByQuery("/*[.//RESOURCE_IDENTIFIER/@value='" + dsId + "']//INTERFACE[@id = '" + ifaceId
|
45 |
|
|
+ "']/@typology/string()");
|
46 |
|
|
|
47 |
41620
|
michele.ar
|
verifyValue(compliance, this.expectedCompliancePrefixes);
|
48 |
|
|
verifyValue(typology, this.expectedInterfaceTypologyPrefixes);
|
49 |
29884
|
michele.ar
|
|
50 |
32639
|
michele.ar
|
if (isPending(dsId)) {
|
51 |
|
|
return "validateDs";
|
52 |
|
|
} else {
|
53 |
|
|
return Arc.DEFAULT_ARC;
|
54 |
|
|
}
|
55 |
26600
|
sandro.lab
|
}
|
56 |
|
|
|
57 |
29884
|
michele.ar
|
private void verifyValue(final String value, final String expected) throws Exception {
|
58 |
32639
|
michele.ar
|
if (expected != null && !expected.isEmpty()) {
|
59 |
41620
|
michele.ar
|
for (final String s : Splitter.on(",").omitEmptyStrings().trimResults().split(expected)) {
|
60 |
32639
|
michele.ar
|
if (value.toLowerCase().startsWith(s.toLowerCase())) { return; }
|
61 |
26600
|
sandro.lab
|
}
|
62 |
|
|
throw new MSROException("Invalid value: " + value + ", Valid term prefixes are: [" + expected + "]");
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
private boolean isPending(final String id) throws ISLookUpDocumentNotFoundException, ISLookUpException {
|
67 |
|
|
final String query = "/*[.//RESOURCE_IDENTIFIER/@value='" + id + "']//RESOURCE_KIND/@value/string()";
|
68 |
41620
|
michele.ar
|
final String res = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query);
|
69 |
26600
|
sandro.lab
|
return res.trim().equals("PendingRepositoryResources");
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
public String getExpectedInterfaceTypologyPrefixes() {
|
73 |
41620
|
michele.ar
|
return this.expectedInterfaceTypologyPrefixes;
|
74 |
26600
|
sandro.lab
|
}
|
75 |
|
|
|
76 |
|
|
public void setExpectedInterfaceTypologyPrefixes(final String expectedInterfaceTypologyPrefixes) {
|
77 |
|
|
this.expectedInterfaceTypologyPrefixes = expectedInterfaceTypologyPrefixes;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
public String getExpectedCompliancePrefixes() {
|
81 |
41620
|
michele.ar
|
return this.expectedCompliancePrefixes;
|
82 |
26600
|
sandro.lab
|
}
|
83 |
|
|
|
84 |
|
|
public void setExpectedCompliancePrefixes(final String expectedCompliancePrefixes) {
|
85 |
|
|
this.expectedCompliancePrefixes = expectedCompliancePrefixes;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
41620
|
michele.ar
|
public WorkflowProcess getProcess() {
|
89 |
|
|
return this.process;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
@Override
|
93 |
|
|
public void setProcess(final WorkflowProcess process) {
|
94 |
|
|
this.process = process;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
26600
|
sandro.lab
|
}
|