Skip to content

Commit 39c0371

Browse files
committed
feat: Support for OpenAIRE Graph lookup
1 parent 61945e4 commit 39c0371

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/main/java/com/knowledgepixels/nanodash/LookupApis.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,32 @@ public static void getPossibleValues(String apiString, String searchterm, Map<St
169169
labelMap.put(uri, label);
170170
}
171171
}
172+
} else if (apiString.startsWith("https://api.openaire.eu/graph/v")) {
173+
String type = apiString.replaceFirst("^https://api\\.openaire\\.eu/graph/(v[0-9]+/[a-zA-Z]+).*$", "$1");
174+
for (Object obj : new JSONObject(respString).getJSONArray("results")) {
175+
if (obj instanceof JSONObject jsonObj) {
176+
String uri = "https://api.openaire.eu/graph/" + type + "/" + jsonObj.getString("id");
177+
if (!values.contains(uri)) {
178+
values.add(uri);
179+
String label = uri;
180+
if (jsonObj.has("mainTitle")) {
181+
label = jsonObj.getString("mainTitle");
182+
} else if (jsonObj.has("legalShortName")) {
183+
label = jsonObj.getString("legalShortName");
184+
} else if (jsonObj.has("officialName")) {
185+
label = jsonObj.getString("officialName");
186+
} else if (jsonObj.has("title")) {
187+
label = jsonObj.getString("title");
188+
} else if (jsonObj.has("familyName")) {
189+
label = jsonObj.getString("familyName");
190+
if (jsonObj.has("givenName")) {
191+
label = jsonObj.getString("givenName") + " " + label;
192+
}
193+
}
194+
labelMap.put(uri, label);
195+
}
196+
}
197+
}
172198
} else if (apiString.startsWith("https://api.gbif.org/v1/species/suggest")) {
173199
JSONArray responseArray = new JSONArray(respString);
174200
for (int i = 0; i < responseArray.length(); i++) {

0 commit comments

Comments
 (0)