Skip to content

Commit

Permalink
Issue #5 add merging for links
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVerstraelen authored and soxofaan committed Sep 16, 2022
1 parent 57301c6 commit 88201ec
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import flask

import openeo_driver.util.view_helpers
from flask import url_for
from openeo.capabilities import ComparableVersion
from openeo.rest import OpenEoApiError, OpenEoRestError, OpenEoClientException
from openeo.util import dict_no_none, TimingLogger, deep_get
Expand Down Expand Up @@ -153,11 +154,14 @@ def _merge_collection_metadata(self, by_backend: Dict[str, dict]) -> dict:
result["type"] = getter.first("type", default="Collection")
# license
licenses = set(getter.get("license"))
# Assume the license links are available.
result["license"] = licenses.pop() if len(licenses) == 1 else ("various" if licenses else "proprietary")
# TODO: .. "various" if multiple licenses apply ... links to the license texts SHOULD be added,
# TODO: Log warning if Properierty or various and links are missing.
# providers
providers = getter.union("providers", skip_duplicates=True)
if providers:
result["providers"] = list(providers)
# extent
result["extent"] = {
"spatial": {
"bbox": getter.select("extent").select("spatial").union("bbox", skip_duplicates=True) \
Expand All @@ -168,7 +172,21 @@ def _merge_collection_metadata(self, by_backend: Dict[str, dict]) -> dict:
or [[None, None]],
},
}
result["links"] = list(getter.union("links"))
# links
result["links"] = [l for l in list(getter.union("links")) if l["rel"] not in ("self", "parent", "root")]
result["links"].append({
"href": url_for("openeo.collections", _external=True),
"rel": "root"
})
result["links"].append({
"href": url_for("openeo.collections", _external=True),
"rel": "parent"
})
result["links"].append({
"href": url_for("openeo.collection_by_id", collection_id=result["id"], _external=True),
"rel": "self"
})
# cube_dimensions
# TODO: combine cube:dimensions smarter?
cube_dimensions = getter.first("cube:dimensions")
if cube_dimensions:
Expand Down

0 comments on commit 88201ec

Please sign in to comment.