1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.consistency;
|
2
|
|
3
|
import java.util.HashSet;
|
4
|
import java.util.Set;
|
5
|
|
6
|
import org.apache.commons.lang.StringUtils;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
|
11
|
import com.googlecode.sarasvati.Arc;
|
12
|
import com.googlecode.sarasvati.NodeToken;
|
13
|
|
14
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
15
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
16
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
17
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
18
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
19
|
|
20
|
public class FindInvalidMetaWorkflowsJobNode extends SimpleJobNode {
|
21
|
|
22
|
@Autowired
|
23
|
private UniqueServiceLocator serviceLocator;
|
24
|
|
25
|
private static final Log log = LogFactory.getLog(FindInvalidMetaWorkflowsJobNode.class);
|
26
|
|
27
|
private boolean deleteInvalidProfiles = false;
|
28
|
|
29
|
@Override
|
30
|
protected String execute(final NodeToken token) throws Exception {
|
31
|
|
32
|
final ISLookUpService lookup = serviceLocator.getService(ISLookUpService.class);
|
33
|
final ISRegistryService registry = serviceLocator.getService(ISRegistryService.class);
|
34
|
|
35
|
final String q1 = "for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType')\n" +
|
36
|
"let $id := $x//RESOURCE_IDENTIFIER/@value\n" +
|
37
|
"for $api in $x//INTERFACE/@id\n" +
|
38
|
"return concat($id,'|',$api)";
|
39
|
|
40
|
final String q2 = "for $x in collection(' /db/DRIVER/MetaWorkflowDSResources/MetaWorkflowDSResourceType') \n" +
|
41
|
"where $x//DATAPROVIDER/@id and $x//DATAPROVIDER/@interface\n" +
|
42
|
"return concat($x//RESOURCE_IDENTIFIER/@value,'@@@',$x//DATAPROVIDER/@id,'|',$x//DATAPROVIDER/@interface)";
|
43
|
|
44
|
final Set<String> valids = new HashSet<>(lookup.quickSearchProfile(q1));
|
45
|
|
46
|
int count = 0;
|
47
|
int countInvalids = 0;
|
48
|
int countDeleted = 0;
|
49
|
for (final String s : lookup.quickSearchProfile(q2)) {
|
50
|
count++;
|
51
|
final String metaWfId = StringUtils.substringBefore(s, "@@@");
|
52
|
final String dsapi = StringUtils.substringAfter(s, "@@@");
|
53
|
if (!valids.contains(dsapi)) {
|
54
|
log.warn("Invalid metaWf: " + metaWfId);
|
55
|
countInvalids++;
|
56
|
if (deleteInvalidProfiles) {
|
57
|
registry.deleteProfile(metaWfId);
|
58
|
log.info(" -- Deleted");
|
59
|
countDeleted++;
|
60
|
}
|
61
|
|
62
|
}
|
63
|
}
|
64
|
|
65
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "total", count);
|
66
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "invalid", countInvalids);
|
67
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "deleted", countDeleted);
|
68
|
|
69
|
return Arc.DEFAULT_ARC;
|
70
|
}
|
71
|
|
72
|
public boolean isDeleteInvalidProfiles() {
|
73
|
return deleteInvalidProfiles;
|
74
|
}
|
75
|
|
76
|
public void setDeleteInvalidProfiles(final boolean deleteInvalidProfiles) {
|
77
|
this.deleteInvalidProfiles = deleteInvalidProfiles;
|
78
|
}
|
79
|
}
|