Skip to content

Commit

Permalink
Store catalogURL as metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
inigo-cobian committed Feb 20, 2024
1 parent 5f85fe0 commit c45af44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ public IEnvelope getEnvelope(String collectionId) {
}

public IGeometry getGeometry(IParameters<String> parameters) {
String catalogUrl = parameters.get("catalogUrl", String.class);
String collectionId = parameters.get("collectionId", String.class);
String collectionUrl = parameters.get("collectionUrl", String.class);

GeometryBuilder gBuilder = Geometry.builder();

JsonNode collectionMetadata = STACUtils.requestCollectionMetadata(catalogUrl, collectionId);
JsonNode collectionMetadata = STACUtils.requestCollectionMetadata(collectionUrl);
JSONArray bbox = collectionMetadata.getObject().getJSONObject("extent").getJSONObject("spatial").getJSONArray("bbox").getJSONArray(0);
gBuilder.space().boundingBox(bbox.getDouble(0), bbox.getDouble(1), bbox.getDouble(2), bbox.getDouble(3));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static String readDOIAuthors(String doi) {
return authors.toString().trim();
}

public static String[] extractCatalogAndCollection(String collectionURI) {
return collectionURI.split("/collections/");
public static String[] extractCatalogAndCollection(String collectionUrl) {
return collectionUrl.split("/collections/");
}

public static String getExtensionName(String identifier) {
Expand All @@ -57,18 +57,18 @@ public static Version getExtensionVersion(String identifier) {
return Version.create(StringUtils.substringBetween(identifier, "/v", "/schema.json"));
}

public static JsonNode requestCollectionMetadata(String catalogUrl, String collectionId) {
HttpResponse<JsonNode> response = Unirest.get(catalogUrl + "/collections/" + collectionId).asJson();
public static JsonNode requestCollectionMetadata(String collectionUrl) {
HttpResponse<JsonNode> response = Unirest.get(collectionUrl).asJson();
if (!response.isSuccess() || response.getBody() == null) {
throw new KlabResourceAccessException("Cannot access the collection at " + catalogUrl + "/collections/" + collectionId);
throw new KlabResourceAccessException("Cannot access the collection at " + collectionUrl);
}
return response.getBody();
}

public static JsonNode requestItemMetadata(String catalogUrl, String collectionId, String item) {
HttpResponse<JsonNode> response = Unirest.get(catalogUrl + "/collections/" + collectionId).asJson();
public static JsonNode requestItemMetadata(String collectionUrl, String item) {
HttpResponse<JsonNode> response = Unirest.get(collectionUrl).asJson();
if (!response.isSuccess() || response.getBody() == null) {
throw new KlabResourceAccessException("Cannot access the item at " + catalogUrl + "/collections/" + collectionId + "/items/" + item);
throw new KlabResourceAccessException("Cannot access the item at " + collectionUrl + "/items/" + item);
}
return response.getBody();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.integratedmodelling.kim.api.IParameters;
import org.integratedmodelling.klab.api.data.IGeometry;
import org.integratedmodelling.klab.api.data.IResource;
Expand Down Expand Up @@ -48,14 +46,17 @@ public Builder validate(String urn, URL url, IParameters<String> userData, IMoni
STACService service = STACAdapter.getService(catalogUrl);

String collectionId = userData.get("collectionId", String.class);
JsonNode metadata = STACUtils.requestCollectionMetadata(catalogUrl, collectionId);
String collectionUrl = catalogUrl + "/collections/" + collectionId;
userData.put("collectionUrl", collectionUrl);
JsonNode metadata = STACUtils.requestCollectionMetadata(collectionUrl);

Set<String> extensions = readSTACExtensions(metadata);
userData.put("stac_extensions", extensions);

IGeometry geometry = service.getGeometry(userData);

Builder builder = new ResourceBuilder(urn).withParameters(userData).withGeometry(geometry);
builder.withMetadata(IMetadata.DC_URL, collectionUrl);

String assetId = userData.get("asset", String.class);
JSONObject assets = STACCollectionParser.readAssets(catalogUrl, collectionId);
Expand Down

0 comments on commit c45af44

Please sign in to comment.