1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.datacite;
|
2
|
|
3
|
import java.util.Map.Entry;
|
4
|
|
5
|
import org.apache.commons.lang.StringUtils;
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
import org.springframework.beans.factory.annotation.Required;
|
9
|
|
10
|
import com.googlecode.sarasvati.Arc;
|
11
|
import com.googlecode.sarasvati.NodeToken;
|
12
|
|
13
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc;
|
14
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService;
|
15
|
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException;
|
16
|
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc;
|
17
|
import eu.dnetlib.enabling.tools.ServiceLocator;
|
18
|
import eu.dnetlib.miscutils.datetime.DateUtils;
|
19
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
20
|
|
21
|
public class ValidateDataciteHostedByReposJobNode extends SimpleJobNode {
|
22
|
private static final Log log = LogFactory.getLog(ValidateDataciteHostedByReposJobNode.class);
|
23
|
|
24
|
private static final String HOSTED_BY_COMPLIANCE = "hostedBy";
|
25
|
|
26
|
private ServiceLocator<DatasourceManagerService> datasourceManagerLocator;
|
27
|
|
28
|
private String countersParam;
|
29
|
private String mdId;
|
30
|
private String extraFieldsForTotal;
|
31
|
private String extraFieldForDate;
|
32
|
private String extraFieldForMdId;
|
33
|
|
34
|
@Override
|
35
|
protected String execute(NodeToken token) throws Exception {
|
36
|
final DataciteHostedByCounters counters = (DataciteHostedByCounters) token.getEnv().getTransientAttribute(countersParam);
|
37
|
final DatasourceManagerService dsManager = datasourceManagerLocator.getService();
|
38
|
final String date = DateUtils.now_ISO8601();
|
39
|
|
40
|
log.info(counters);
|
41
|
|
42
|
for(Entry<String, Integer> e : counters.getCounters().entrySet()) {
|
43
|
updateHostedByApi(dsManager, e.getKey(), date, e.getValue());
|
44
|
}
|
45
|
|
46
|
return Arc.DEFAULT_ARC;
|
47
|
}
|
48
|
|
49
|
private void updateHostedByApi(final DatasourceManagerService dsManager, final String dsId, final String date, final int size) {
|
50
|
log.info("Verifying hostedBy api in ds: " + dsId);
|
51
|
try {
|
52
|
final DatasourceDesc ds = dsManager.getDatasource(dsId);
|
53
|
|
54
|
for (IfaceDesc iface : ds.getInterfaces()) {
|
55
|
if (HOSTED_BY_COMPLIANCE.equals(iface.getCompliance())) {
|
56
|
if (StringUtils.isNotBlank(extraFieldForDate)) {
|
57
|
dsManager.updateExtraField(dsId, iface.getId(), extraFieldForDate, date, false);
|
58
|
}
|
59
|
if (StringUtils.isNotBlank(extraFieldsForTotal)) {
|
60
|
dsManager.updateExtraField(dsId, iface.getId(), extraFieldsForTotal, Integer.toString(size), false);
|
61
|
}
|
62
|
if (StringUtils.isNotBlank(mdId) && StringUtils.isNotBlank(extraFieldForMdId)) {
|
63
|
dsManager.updateExtraField(dsId, iface.getId(), extraFieldForMdId, mdId, false);
|
64
|
}
|
65
|
return;
|
66
|
}
|
67
|
}
|
68
|
|
69
|
final IfaceDesc iface = new IfaceDesc();
|
70
|
iface.setId("api_________::" + dsId + "::hostedBy");
|
71
|
iface.setTypology(ds.getTypology());
|
72
|
iface.setCompliance(HOSTED_BY_COMPLIANCE);
|
73
|
iface.setAccessProtocol("UNKNOWN");
|
74
|
iface.setContentDescription("metadata");
|
75
|
iface.setBaseUrl("");
|
76
|
iface.setActive(false);
|
77
|
iface.setRemovable(true);
|
78
|
if (StringUtils.isNotBlank(extraFieldForDate)) {
|
79
|
iface.getExtraFields().put(extraFieldForDate, date);
|
80
|
}
|
81
|
if (StringUtils.isNotBlank(extraFieldsForTotal)) {
|
82
|
iface.getExtraFields().put(extraFieldsForTotal, Integer.toString(size));
|
83
|
}
|
84
|
if (StringUtils.isNotBlank(mdId) && StringUtils.isNotBlank(extraFieldForMdId)) {
|
85
|
iface.getExtraFields().put(extraFieldForMdId, mdId);
|
86
|
}
|
87
|
dsManager.addInterface(dsId, iface);
|
88
|
} catch (DatasourceManagerServiceException e) {
|
89
|
log.warn("Error setting hostedBy api of ds: " + dsId, e);
|
90
|
}
|
91
|
}
|
92
|
|
93
|
public ServiceLocator<DatasourceManagerService> getDatasourceManagerLocator() {
|
94
|
return datasourceManagerLocator;
|
95
|
}
|
96
|
|
97
|
@Required
|
98
|
public void setDatasourceManagerLocator(ServiceLocator<DatasourceManagerService> datasourceManagerLocator) {
|
99
|
this.datasourceManagerLocator = datasourceManagerLocator;
|
100
|
}
|
101
|
|
102
|
public String getMdId() {
|
103
|
return mdId;
|
104
|
}
|
105
|
|
106
|
public void setMdId(String mdId) {
|
107
|
this.mdId = mdId;
|
108
|
}
|
109
|
|
110
|
public String getExtraFieldsForTotal() {
|
111
|
return extraFieldsForTotal;
|
112
|
}
|
113
|
|
114
|
public void setExtraFieldsForTotal(String extraFieldsForTotal) {
|
115
|
this.extraFieldsForTotal = extraFieldsForTotal;
|
116
|
}
|
117
|
|
118
|
public String getExtraFieldForDate() {
|
119
|
return extraFieldForDate;
|
120
|
}
|
121
|
|
122
|
public void setExtraFieldForDate(String extraFieldForDate) {
|
123
|
this.extraFieldForDate = extraFieldForDate;
|
124
|
}
|
125
|
|
126
|
public String getExtraFieldForMdId() {
|
127
|
return extraFieldForMdId;
|
128
|
}
|
129
|
|
130
|
public void setExtraFieldForMdId(String extraFieldForMdId) {
|
131
|
this.extraFieldForMdId = extraFieldForMdId;
|
132
|
}
|
133
|
|
134
|
public String getCountersParam() {
|
135
|
return countersParam;
|
136
|
}
|
137
|
|
138
|
public void setCountersParam(String countersParam) {
|
139
|
this.countersParam = countersParam;
|
140
|
}
|
141
|
|
142
|
}
|