1 |
57299
|
sandro.lab
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.dhp;
|
2 |
|
|
|
3 |
|
|
import java.net.URI;
|
4 |
|
|
import java.util.HashMap;
|
5 |
|
|
import java.util.Map;
|
6 |
|
|
|
7 |
|
|
import org.apache.commons.logging.Log;
|
8 |
|
|
import org.apache.commons.logging.LogFactory;
|
9 |
|
|
import org.springframework.beans.factory.annotation.Required;
|
10 |
|
|
import org.springframework.web.client.RestTemplate;
|
11 |
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
12 |
|
|
|
13 |
|
|
import com.googlecode.sarasvati.Arc;
|
14 |
|
|
import com.googlecode.sarasvati.NodeToken;
|
15 |
|
|
|
16 |
|
|
import eu.dnetlib.data.mdstore.manager.common.model.MDStoreVersion;
|
17 |
|
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
18 |
|
|
|
19 |
|
|
public class StartReadingMDStoreJobNode extends SimpleJobNode {
|
20 |
|
|
|
21 |
|
|
private static final Log log = LogFactory.getLog(StartReadingMDStoreJobNode.class);
|
22 |
|
|
|
23 |
|
|
private String mdId;
|
24 |
|
|
|
25 |
|
|
/* Spring managed params */
|
26 |
|
|
private String mdStoreManagerUrl;
|
27 |
|
|
|
28 |
|
|
@Override
|
29 |
|
|
protected String execute(final NodeToken token) throws Exception {
|
30 |
|
|
final String url = getMdStoreManagerUrl() + "/mdstore/{mdId}/startReading";
|
31 |
|
|
|
32 |
|
|
final Map<String, Object> params = new HashMap<>();
|
33 |
|
|
params.put("mdId", getMdId());
|
34 |
|
|
|
35 |
|
|
final URI uri = UriComponentsBuilder.fromUriString(url)
|
36 |
|
|
.buildAndExpand(params)
|
37 |
|
|
.toUri();
|
38 |
|
|
|
39 |
|
|
final RestTemplate restTemplate = new RestTemplate();
|
40 |
|
|
final MDStoreVersion version = restTemplate.getForObject(uri, MDStoreVersion.class);
|
41 |
|
|
|
42 |
|
|
log.info("mdstore version ready to read " + version.getId());
|
43 |
|
|
|
44 |
|
|
token.getEnv().setAttribute("reading_mdId", mdId);
|
45 |
|
|
token.getEnv().setAttribute("reading_versionId", version.getId());
|
46 |
|
|
|
47 |
|
|
return Arc.DEFAULT_ARC;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
public String getMdStoreManagerUrl() {
|
51 |
|
|
return mdStoreManagerUrl;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
@Required
|
55 |
|
|
public void setMdStoreManagerUrl(final String mdStoreManagerUrl) {
|
56 |
|
|
this.mdStoreManagerUrl = mdStoreManagerUrl;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
public String getMdId() {
|
60 |
|
|
return mdId;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
public void setMdId(final String mdId) {
|
64 |
|
|
this.mdId = mdId;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
}
|