1 |
57299
|
sandro.lab
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.dhp;
|
2 |
|
|
|
3 |
|
|
import java.net.URI;
|
4 |
|
|
import java.util.Date;
|
5 |
|
|
import java.util.HashMap;
|
6 |
|
|
import java.util.Map;
|
7 |
|
|
|
8 |
|
|
import org.apache.commons.logging.Log;
|
9 |
|
|
import org.apache.commons.logging.LogFactory;
|
10 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
11 |
|
|
import org.springframework.web.client.RestTemplate;
|
12 |
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
13 |
|
|
|
14 |
|
|
import com.googlecode.sarasvati.Arc;
|
15 |
|
|
import com.googlecode.sarasvati.NodeToken;
|
16 |
|
|
|
17 |
|
|
import eu.dnetlib.data.mdstore.manager.common.model.MDStoreWithInfo;
|
18 |
|
|
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager;
|
19 |
|
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
20 |
|
|
|
21 |
|
|
public class MDStoreToApiExtraFieldHadoopJobNode extends SimpleJobNode {
|
22 |
|
|
|
23 |
|
|
private String mdId;
|
24 |
|
|
private String datasourceId;
|
25 |
|
|
private String datasourceInterface;
|
26 |
|
|
private String extraFieldForTotal;
|
27 |
|
|
private String extraFieldForDate;
|
28 |
|
|
private String extraFieldForMdId;
|
29 |
|
|
|
30 |
|
|
/* Spring managed params */
|
31 |
|
|
private String mdStoreManagerUrl;
|
32 |
|
|
|
33 |
|
|
@Autowired
|
34 |
|
|
private LocalDatasourceManager<?, ?> dsManager;
|
35 |
|
|
|
36 |
|
|
private static final Log log = LogFactory.getLog(MDStoreToApiExtraFieldHadoopJobNode.class);
|
37 |
|
|
|
38 |
|
|
@Override
|
39 |
|
|
protected String execute(final NodeToken token) throws Exception {
|
40 |
|
|
|
41 |
|
|
final String url = getMdStoreManagerUrl() + "/mdstore/{mdId}";
|
42 |
|
|
|
43 |
|
|
final Map<String, Object> params = new HashMap<>();
|
44 |
|
|
params.put("mdId", getMdId());
|
45 |
|
|
|
46 |
|
|
final URI uri = UriComponentsBuilder.fromUriString(url)
|
47 |
|
|
.buildAndExpand(params)
|
48 |
|
|
.toUri();
|
49 |
|
|
|
50 |
|
|
final RestTemplate restTemplate = new RestTemplate();
|
51 |
|
|
final MDStoreWithInfo mdstore = restTemplate.getForObject(uri, MDStoreWithInfo.class);
|
52 |
|
|
|
53 |
|
|
final int size = Math.toIntExact(mdstore.getSize());
|
54 |
|
|
final Date date = mdstore.getLastUpdate();
|
55 |
|
|
|
56 |
|
|
if (extraFieldForTotal.equals("last_collection_total")) {
|
57 |
|
|
dsManager.setLastCollectionInfo(datasourceId, datasourceInterface, mdId, size, date);
|
58 |
|
|
} else if (extraFieldForTotal.equals("last_aggregation_total")) {
|
59 |
|
|
dsManager.setLastAggregationInfo(datasourceId, datasourceInterface, mdId, size, date);
|
60 |
|
|
} else {
|
61 |
|
|
log.warn("Invalid field for total: " + extraFieldForTotal);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
return Arc.DEFAULT_ARC;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
public String getMdId() {
|
68 |
|
|
return mdId;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
public void setMdId(final String mdId) {
|
72 |
|
|
this.mdId = mdId;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
public String getDatasourceId() {
|
76 |
|
|
return datasourceId;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
public void setDatasourceId(final String datasourceId) {
|
80 |
|
|
this.datasourceId = datasourceId;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
public String getDatasourceInterface() {
|
84 |
|
|
return datasourceInterface;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
public void setDatasourceInterface(final String datasourceInterface) {
|
88 |
|
|
this.datasourceInterface = datasourceInterface;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
public String getExtraFieldForTotal() {
|
92 |
|
|
return extraFieldForTotal;
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
public void setExtraFieldForTotal(final String extraFieldForTotal) {
|
96 |
|
|
this.extraFieldForTotal = extraFieldForTotal;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
public String getExtraFieldForDate() {
|
100 |
|
|
return extraFieldForDate;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
public void setExtraFieldForDate(final String extraFieldForDate) {
|
104 |
|
|
this.extraFieldForDate = extraFieldForDate;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
public String getExtraFieldForMdId() {
|
108 |
|
|
return extraFieldForMdId;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
public void setExtraFieldForMdId(final String extraFieldForMdId) {
|
112 |
|
|
this.extraFieldForMdId = extraFieldForMdId;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
public String getMdStoreManagerUrl() {
|
116 |
|
|
return mdStoreManagerUrl;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
public void setMdStoreManagerUrl(final String mdStoreManagerUrl) {
|
120 |
|
|
this.mdStoreManagerUrl = mdStoreManagerUrl;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
}
|