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.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
|
10
|
import com.googlecode.sarasvati.Arc;
|
11
|
import com.googlecode.sarasvati.NodeToken;
|
12
|
|
13
|
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
|
14
|
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao;
|
15
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
16
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
17
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
18
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
19
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
20
|
|
21
|
public class FindInvalidStoresJobNode extends SimpleJobNode {
|
22
|
|
23
|
@Autowired
|
24
|
private UniqueServiceLocator serviceLocator;
|
25
|
|
26
|
@Autowired
|
27
|
private MDStoreDao mdstoreDao;
|
28
|
|
29
|
@Autowired
|
30
|
private ObjectStoreDao objDao;
|
31
|
|
32
|
private static final Log log = LogFactory.getLog(FindInvalidStoresJobNode.class);
|
33
|
|
34
|
private boolean deleteInvalidStores = false;
|
35
|
|
36
|
@Override
|
37
|
protected String execute(final NodeToken token) throws Exception {
|
38
|
final ISLookUpService lookup = serviceLocator.getService(ISLookUpService.class);
|
39
|
final ISRegistryService registry = serviceLocator.getService(ISRegistryService.class);
|
40
|
|
41
|
final String q1 = "distinct-values("
|
42
|
+ "for $x in collection('/db/DRIVER/WorkflowDSResources/WorkflowDSResourceType')//PARAM[@category='MDSTORE_ID' or @category='OBJECTSTORE_ID'] "
|
43
|
+ "return $x/text())";
|
44
|
|
45
|
final String q2 = "for $x in collection('/db/DRIVER/MDStoreDSResources/MDStoreDSResourceType') return $x//RESOURCE_IDENTIFIER/@value/string()";
|
46
|
final String q3 = "for $x in collection('/db/DRIVER/ObjectStoreDSResources/ObjectStoreDSResourceType') return $x//RESOURCE_IDENTIFIER/@value/string()";
|
47
|
|
48
|
final Set<String> valids = new HashSet<>(lookup.quickSearchProfile(q1));
|
49
|
|
50
|
int countMdstores = 0;
|
51
|
int countInvalidMdStores = 0;
|
52
|
int countDeletedMdStores = 0;
|
53
|
int countObjstores = 0;
|
54
|
int countInvalidObjStores = 0;
|
55
|
int countDeletedObjStores = 0;
|
56
|
|
57
|
for (final String id : lookup.quickSearchProfile(q2)) {
|
58
|
countMdstores++;
|
59
|
if (!valids.contains(id)) {
|
60
|
log.warn("Invalid mdstore: " + id);
|
61
|
countInvalidMdStores++;
|
62
|
if (deleteInvalidStores) {
|
63
|
registry.deleteProfile(id);
|
64
|
mdstoreDao.deleteMDStore(id);
|
65
|
log.info(" -- Deleted");
|
66
|
countDeletedMdStores++;
|
67
|
}
|
68
|
|
69
|
}
|
70
|
}
|
71
|
|
72
|
for (final String id : lookup.quickSearchProfile(q3)) {
|
73
|
countObjstores++;
|
74
|
if (!valids.contains(id)) {
|
75
|
log.warn("Invalid objstore: " + id);
|
76
|
countInvalidObjStores++;
|
77
|
if (deleteInvalidStores) {
|
78
|
registry.deleteProfile(id);
|
79
|
objDao.deleteObjectStore(id);
|
80
|
log.info(" -- Deleted");
|
81
|
countDeletedObjStores++;
|
82
|
}
|
83
|
|
84
|
}
|
85
|
}
|
86
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "totalMdStores", countMdstores);
|
87
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "invalidMdStores", countInvalidMdStores);
|
88
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "deletedMdStores", countDeletedMdStores);
|
89
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "totalObjStores", countObjstores);
|
90
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "invalidObjStores", countInvalidObjStores);
|
91
|
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "deletedObjStores", countDeletedObjStores);
|
92
|
|
93
|
return Arc.DEFAULT_ARC;
|
94
|
}
|
95
|
|
96
|
public boolean isDeleteInvalidStores() {
|
97
|
return deleteInvalidStores;
|
98
|
}
|
99
|
|
100
|
public void setDeleteInvalidStores(final boolean deleteInvalidStores) {
|
101
|
this.deleteInvalidStores = deleteInvalidStores;
|
102
|
}
|
103
|
}
|