1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.hostedby;
|
2
|
|
3
|
import java.util.Map.Entry;
|
4
|
import javax.annotation.Resource;
|
5
|
|
6
|
import com.googlecode.sarasvati.Arc;
|
7
|
import com.googlecode.sarasvati.NodeToken;
|
8
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc;
|
9
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService;
|
10
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException;
|
11
|
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
|
12
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
13
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
14
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
15
|
import org.apache.commons.logging.Log;
|
16
|
import org.apache.commons.logging.LogFactory;
|
17
|
|
18
|
public class UpsertHostedByApisJobNode extends SimpleJobNode {
|
19
|
|
20
|
private static final Log log = LogFactory.getLog(UpsertHostedByApisJobNode.class);
|
21
|
|
22
|
private static final String HOSTED_BY_COMPLIANCE = "hostedBy";
|
23
|
|
24
|
@Resource
|
25
|
private UniqueServiceLocator serviceLocator;
|
26
|
|
27
|
private String countersParam;
|
28
|
private String mdId;
|
29
|
public static final String extraFieldsForTotal = "last_aggregation_total";
|
30
|
public static final String extraFieldForDate = "last_aggregation_date";
|
31
|
public static final String extraFieldForMdId = "last_aggregation_mdId";
|
32
|
|
33
|
@Override
|
34
|
protected String execute(final NodeToken token) throws Exception {
|
35
|
final HostedByCounters counters = (HostedByCounters) token.getEnv().getTransientAttribute(countersParam);
|
36
|
final DatasourceManagerService dsManager = serviceLocator.getService(DatasourceManagerService.class);
|
37
|
final String date = DateUtils.now_ISO8601();
|
38
|
final String namespacePrefix = token.getEnv().getAttribute("namespacePrefix");
|
39
|
|
40
|
log.info(counters);
|
41
|
|
42
|
for (Entry<String, Integer> e : counters.getCounters().entrySet()) {
|
43
|
updateHostedByApi(dsManager, e.getKey(), namespacePrefix, date, e.getValue());
|
44
|
}
|
45
|
|
46
|
return Arc.DEFAULT_ARC;
|
47
|
}
|
48
|
|
49
|
private void updateHostedByApi(final DatasourceManagerService dsManager,
|
50
|
final String dsId,
|
51
|
final String namepsacePrefix,
|
52
|
final String date,
|
53
|
final int size) {
|
54
|
log.info("Verifying hostedBy api in ds: " + dsId);
|
55
|
try {
|
56
|
final DatasourceDesc ds = dsManager.getDatasource(dsId);
|
57
|
|
58
|
for (IfaceDesc iface : ds.getInterfaces()) {
|
59
|
if (HOSTED_BY_COMPLIANCE.equals(iface.getCompliance())) {
|
60
|
return;
|
61
|
}
|
62
|
}
|
63
|
|
64
|
final IfaceDesc iface = new IfaceDesc();
|
65
|
iface.setId("api_________::" + dsId + "::hostedBy");
|
66
|
iface.setTypology(ds.getDatasourceClass());
|
67
|
iface.setCompliance(HOSTED_BY_COMPLIANCE);
|
68
|
iface.setAccessProtocol("UNKNOWN");
|
69
|
iface.setContentDescription("metadata");
|
70
|
iface.setBaseUrl("");
|
71
|
iface.setActive(false);
|
72
|
iface.setRemovable(true);
|
73
|
dsManager.addInterface(dsId, iface);
|
74
|
} catch (DatasourceManagerServiceException e) {
|
75
|
log.warn("Error setting hostedBy api of ds: " + dsId, e);
|
76
|
}
|
77
|
}
|
78
|
|
79
|
public String getMdId() {
|
80
|
return mdId;
|
81
|
}
|
82
|
|
83
|
public void setMdId(final String mdId) {
|
84
|
this.mdId = mdId;
|
85
|
}
|
86
|
|
87
|
public String getCountersParam() {
|
88
|
return countersParam;
|
89
|
}
|
90
|
|
91
|
public void setCountersParam(final String countersParam) {
|
92
|
this.countersParam = countersParam;
|
93
|
}
|
94
|
|
95
|
}
|