-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
769 additions
and
26 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/DOIReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.integratedmodelling.klab; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import kong.unirest.HttpResponse; | ||
import kong.unirest.JsonNode; | ||
import kong.unirest.Unirest; | ||
import kong.unirest.json.JSONArray; | ||
import kong.unirest.json.JSONObject; | ||
|
||
/** | ||
* A utility class to obtain the data of the DOI via multiple APIs. | ||
* DataCite API: https://support.datacite.org/docs/api-get-doi | ||
* Crossref API: https://api.crossref.org/swagger-ui/index.html | ||
* | ||
*/ | ||
public class DOIReader { | ||
private static String DATACITE_GET_DOI = "https://api.datacite.org/dois/"; | ||
private static String CROSSREF_GET_DOI = "https://api.crossref.org/works/"; | ||
|
||
public static HttpResponse<JsonNode> getDOIInformationFromDatacite(String doi) { | ||
return Unirest.get(DATACITE_GET_DOI + doi).asJson(); | ||
} | ||
|
||
public static HttpResponse<JsonNode> getDOIInformationFromCrossref(String doi) { | ||
return Unirest.get(CROSSREF_GET_DOI + doi).asJson(); | ||
} | ||
|
||
public static Set<String> readAuthorsDatacite(String doi) { | ||
HttpResponse<JsonNode> response = getDOIInformationFromDatacite(doi); | ||
if (!response.isSuccess()) { | ||
return Collections.emptySet(); | ||
} | ||
JsonNode json = response.getBody(); | ||
JSONArray authorsArray = json.getObject().getJSONObject("data").getJSONObject("attributes").getJSONArray("creators"); | ||
Set<String> authors = new HashSet<>(); | ||
for (Object author : authorsArray) { | ||
if (!((JSONObject) author).has("name")) { | ||
continue; | ||
} | ||
authors.add(((JSONObject) author).getString("name")); | ||
} | ||
return authors; | ||
} | ||
|
||
public static Set<String> readAuthorsCrossref(String doi) { | ||
HttpResponse<JsonNode> response = getDOIInformationFromCrossref(doi); | ||
if (!response.isSuccess()) { | ||
return Collections.emptySet(); | ||
} | ||
JsonNode json = response.getBody(); | ||
JSONArray authorsArray = json.getObject().getJSONObject("message").getJSONArray("author"); | ||
Set<String> authors = new HashSet<>(); | ||
for (Object author : authorsArray) { | ||
if (!((JSONObject) author).has("given") || !((JSONObject) author).has("family")) { | ||
continue; | ||
} | ||
String name = ((JSONObject) author).getString("family").concat(",") | ||
.concat(((JSONObject) author).getString("given")); | ||
authors.add(name); | ||
} | ||
return authors; | ||
} | ||
|
||
public static Set<String> readAuthors(String doi) { | ||
Set<String> authors = readAuthorsDatacite(doi); | ||
if (!authors.isEmpty()) { | ||
return authors; | ||
} | ||
return readAuthorsCrossref(doi); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/stac/STACExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.integratedmodelling.klab.stac; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.integratedmodelling.klab.Version; | ||
|
||
/** | ||
* An list of the most popular extensions for STAC. | ||
* Currently, we only define extensions with a maturity of Stable, Candidate, Pilot or Deprecated. | ||
* https://stac-extensions.github.io/ | ||
*/ | ||
public enum STACExtension { | ||
ElectroOptical("eo"), | ||
FileInfo("file"), | ||
ItemAssetsDefinition("item-assets"), | ||
Projection("projection"), | ||
ScientificCitation("scientific"), | ||
ViewGeometry("view"), | ||
Datacube("datacube"), | ||
Processing("processing"), | ||
Raster("raster"), | ||
SAR("sar"), | ||
Satellite("sat"), | ||
VersioningIndicators("version"), | ||
AlternateAssets("alternate-assets"), | ||
AnonymizedLocation("anonymized-location"), | ||
CARD4L_OpticalAndSAR("card4l"), | ||
Classification("classification"), | ||
Grid("grid"), | ||
Label("label"), | ||
MilitaryGridReferenceSystem("mgrs"), | ||
NOAA_GOES("goes"), // NOAA Geostationary Operational Environmental Satellite | ||
NOAA_MRMS_QPE("noaa-mrms-qpe"), | ||
Order("order"), | ||
PointCloud("pointcloud"), | ||
Stats("stats"), | ||
Storage("storage"), | ||
Table("table"), | ||
Timestamps("timestamps"), | ||
XarrayAssets("xarray-assets"), | ||
SingleFileSTAC("single-file-stac"), | ||
TimeSeries("timeseries"); | ||
|
||
private String name; | ||
|
||
STACExtension(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public static String getExtensionName(String identifier) { | ||
return StringUtils.substringBetween(identifier, "https://stac-extensions.github.io/", "/v"); | ||
} | ||
|
||
public static Version getVersion(String identifier) { | ||
return Version.create(StringUtils.substringBetween(identifier, "/v", "/schema.json")); | ||
} | ||
|
||
public boolean isDeprecated() { | ||
return this.name.equals(SingleFileSTAC.name) || this.name.equals(TimeSeries.name); | ||
} | ||
|
||
public boolean isSupported() { | ||
// TODO | ||
return true; | ||
} | ||
|
||
public static STACExtension valueOfLabel(String label) { | ||
for (STACExtension e : values()) { | ||
if (e.name.equals(label)) { | ||
return e; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.