Revision 43444
Added by Sandro La Bruzzo over 7 years ago
CMRDatasourcePlugin.java | ||
---|---|---|
11 | 11 |
import eu.dnetlib.rmi.data.CollectorServiceException; |
12 | 12 |
import eu.dnetlib.rmi.data.InterfaceDescriptor; |
13 | 13 |
import eu.dnetlib.rmi.data.plugin.AbstractCollectorPlugin; |
14 |
import org.antlr.stringtemplate.StringTemplate; |
|
14 | 15 |
import org.apache.commons.io.IOUtils; |
16 |
import org.apache.commons.lang3.StringUtils; |
|
15 | 17 |
|
16 | 18 |
/** |
17 | 19 |
* Created by sandro on 7/1/16. |
... | ... | |
20 | 22 |
|
21 | 23 |
private static final String BASE_URL = "https://cmr.earthdata.nasa.gov/search/keywords/data_centers?pretty=true"; |
22 | 24 |
|
25 |
private StringTemplate xmlTemplate; |
|
26 |
|
|
27 |
|
|
28 |
|
|
23 | 29 |
@Override |
24 | 30 |
public Iterable<String> collect(final InterfaceDescriptor interfaceDescriptor, final String fromDate, final String untilDate) |
25 | 31 |
throws CollectorServiceException { |
32 |
|
|
33 |
return generateListOfDatasource(); |
|
34 |
|
|
35 |
} |
|
36 |
|
|
37 |
public List<String> generateListOfDatasource() throws CollectorServiceException { |
|
26 | 38 |
try { |
39 |
|
|
27 | 40 |
URL myUrl = new URL(BASE_URL); |
28 | 41 |
|
29 | 42 |
JsonElement element = new JsonParser().parse(IOUtils.toString(myUrl.openStream())); |
... | ... | |
40 | 53 |
|
41 | 54 |
if (short_name != null) { |
42 | 55 |
final JsonArray level_1 = short_name.getAsJsonArray(); |
56 |
|
|
43 | 57 |
for (JsonElement item : level_1) { |
44 | 58 |
final JsonObject currentItem = item.getAsJsonObject(); |
45 | 59 |
final String id = currentItem.get("value").getAsString(); |
... | ... | |
58 | 72 |
final JsonElement urlObject = infoObject.get("url"); |
59 | 73 |
|
60 | 74 |
String url = ""; |
75 |
String uuid = ""; |
|
61 | 76 |
if (urlObject != null) { |
62 | 77 |
if (urlObject.isJsonArray()) { |
63 | 78 |
url = urlObject.getAsJsonArray().get(0).getAsJsonObject().get("value").getAsString(); |
64 |
} else url = urlObject.getAsJsonObject().get("value").getAsString(); |
|
79 |
uuid = urlObject.getAsJsonArray().get(0).getAsJsonObject().get("uuid").getAsString(); |
|
80 |
} else { |
|
81 |
url = urlObject.getAsJsonObject().get("value").getAsString(); |
|
82 |
uuid = urlObject.getAsJsonObject().get("uuid").getAsString(); |
|
83 |
} |
|
65 | 84 |
} |
66 | 85 |
|
67 |
results.add(id + "<---->" + name + " <----------------->" + url); |
|
86 |
CMRDatasource currentDatasource = new CMRDatasource(); |
|
87 |
|
|
88 |
try { |
|
89 |
currentDatasource.setId(id); |
|
90 |
currentDatasource.setName(name); |
|
91 |
currentDatasource.setUrl(url); |
|
92 |
currentDatasource.setUuid(uuid); |
|
93 |
if (!StringUtils.isBlank(id) && !StringUtils.isBlank(name) && !StringUtils.isBlank(url)) { |
|
94 |
xmlTemplate.removeAttribute("datasource"); |
|
95 |
xmlTemplate.setAttribute("datasource", currentDatasource); |
|
96 |
results.add(xmlTemplate.toString()); |
|
97 |
} |
|
98 |
} catch (Throwable e1) { |
|
99 |
System.out.println("ERRORE"); |
|
100 |
} |
|
68 | 101 |
} |
69 | 102 |
} |
70 | 103 |
} |
... | ... | |
73 | 106 |
} catch (Throwable e) { |
74 | 107 |
throw new CollectorServiceException("Error on iterating CMR data centers", e); |
75 | 108 |
} |
109 |
} |
|
76 | 110 |
|
111 |
public StringTemplate getXmlTemplate() { |
|
112 |
return xmlTemplate; |
|
77 | 113 |
} |
78 | 114 |
|
115 |
public void setXmlTemplate(final StringTemplate xmlTemplate) { |
|
116 |
this.xmlTemplate = xmlTemplate; |
|
117 |
} |
|
118 |
|
|
79 | 119 |
} |
Also available in: Unified diff
Added workflows for entity registy