RKuttruff commented on code in PR #291:
URL: 
https://github.com/apache/incubator-sdap-nexus/pull/291#discussion_r1475192473


##########
analysis/webservice/algorithms/doms/StacCatalog.py:
##########
@@ -0,0 +1,166 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the 'License'); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an 'AS IS' BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import re
+import uuid
+from typing import List
+
+from webservice.NexusHandler import nexus_handler
+from webservice.algorithms.doms.ResultsStorage import ResultsRetrieval
+from webservice.webmodel import NexusProcessingException
+from webservice.webmodel import NexusResults
+
+from . import BaseDomsHandler
+
+
+class StacResults(NexusResults):
+    def __init__(self, contents):
+        NexusResults.__init__(self)
+        self.contents = contents
+
+    def toJson(self):
+        return json.dumps(self.contents, indent=4)
+
+
+@nexus_handler
+class StacCatalog(BaseDomsHandler.BaseDomsQueryCalcHandler):
+    name = 'STAC Catalog Handler'
+    path = '^/cdmscatalog/?.*$'
+    description = ''
+    params = {}
+    singleton = True
+
+    def __init__(self, tile_service_factory, config=None):
+        BaseDomsHandler.BaseDomsQueryCalcHandler.__init__(self, 
tile_service_factory)
+        self.config = config
+
+    def construct_catalog(self, execution_id: str):
+        return {
+            'stac_version': '1.0.0',
+            'type': 'Catalog',
+            'id': str(execution_id),
+            'description': 'STAC Catalog for CDMS output',
+            'links': [
+                {
+                    'rel': 'collection',
+                    'href': 
f'https://{self.host}/cdmscatalog/{execution_id}/{output_format}',
+                    'title': f'Collection of pages for {execution_id} 
{output_format} output'
+                }
+                for output_format in ['CSV', 'JSON', 'NETCDF']
+            ]
+        }
+
+    def construct_collection(self, execution_id: str, output_format: str,
+                             num_primary_matched: int, page_size: int, 
start_time: str,
+                             end_time: str, bbox: List[float]):
+        links = [
+            {
+                'rel': 'self',
+                'href': 
f'https://{self.host}/cdmscatalog/{execution_id}/{output_format}',
+                'title': 'The current page',
+                'type': 'application/json'
+            },
+            {
+                'rel': 'root',
+                'href': f'https://{self.host}/cdmscatalog/{execution_id}',
+                'title': f'Root catalog for {execution_id}',
+            }
+        ]
+
+        url = 
f'https://{self.host}/cdmsresults?id={execution_id}&output={output_format}'
+        for page_num in range(1, num_primary_matched, page_size):
+            links.append({
+                'rel': 'data',
+                'href': f'{url}&pageNum={page_num}&pageSize={page_size}'
+            })

Review Comment:
   If the matchup has only one primary match, this loop will miss the results 
link.
   Ex: `0e664875-61fe-4540-a80d-1fba8f1fad61`
   
   `/job`:
   ```json
   {
       "status": "success",
       "message": "",
       "createdAt": "2024-02-01 19:19:37.474000",
       "updatedAt": "2024-02-01 19:19:46.084000",
       "links": [
           {
               "href": 
"https://doms.jpl.nasa.gov/job?id=0e664875-61fe-4540-a80d-1fba8f1fad61";,
               "title": "Get job status - the current page",
               "type": "application/json",
               "rel": "self"
           },
           {
               "href": 
"https://doms.jpl.nasa.gov/cdmscatalog/0e664875-61fe-4540-a80d-1fba8f1fad61";,
               "title": "STAC Catalog for execution results",
               "type": "application/json",
               "rel": "stac"
           },
           {
               "href": 
"https://doms.jpl.nasa.gov/cdmsresults?id=0e664875-61fe-4540-a80d-1fba8f1fad61&output=CSV";,
               "title": "Download CSV results",
               "type": "text/csv",
               "rel": "data"
           },
           {
               "href": 
"https://doms.jpl.nasa.gov/cdmsresults?id=0e664875-61fe-4540-a80d-1fba8f1fad61&output=JSON";,
               "title": "Download JSON results",
               "type": "application/json",
               "rel": "data"
           },
           {
               "href": 
"https://doms.jpl.nasa.gov/cdmsresults?id=0e664875-61fe-4540-a80d-1fba8f1fad61&output=NETCDF";,
               "title": "Download NETCDF results",
               "type": "binary/octet-stream",
               "rel": "data"
           }
       ],
       "params": {
           "primary": "JPL-L4-MRVA-CHLA-GLOB-v3.0",
           "matchup": "shark-2018",
           "startTime": "2018-04-01 00:00:00+00:00",
           "endTime": "2018-04-01 23:59:59+00:00",
           "bbox": "-131,26,-130,27",
           "timeTolerance": 86400,
           "radiusTolerance": 10000.0,
           "platforms": "3B",
           "parameter": "mass_concentration_of_chlorophyll_in_sea_water",
           "depthMin": -5.0,
           "depthMax": 5.0
       },
       "executionID": "0e664875-61fe-4540-a80d-1fba8f1fad61",
       "totalPrimaryMatched": 1,
       "totalSecondaryMatched": 1,
       "averageSecondaryMatched": 1,
       "totalUniqueSecondaryMatched": 1
   }
   ```
   
   `/cdmscatalog/0e664875-61fe-4540-a80d-1fba8f1fad61/JSON`:
   ```json
   {
       "stac_version": "1.0.0",
       "type": "Collection",
       "license": "not-provided",
       "id": "0e664875-61fe-4540-a80d-1fba8f1fad61.JSON",
       "description": "Collection of results for CDMS execution and result 
format",
       "extent": {
           "spatial": {
               "bbox": [
                   -131.0,
                   26.0,
                   -130.0,
                   27.0
               ]
           },
           "temporal": {
               "interval": [
                   "2018-04-01T00:00:00+00:00",
                   "2018-04-01T23:59:59+00:00"
               ]
           }
       },
       "links": [
           {
               "rel": "self",
               "href": 
"https://doms.jpl.nasa.gov/cdmscatalog/0e664875-61fe-4540-a80d-1fba8f1fad61/JSON";,
               "title": "The current page",
               "type": "application/json"
           },
           {
               "rel": "root",
               "href": 
"https://doms.jpl.nasa.gov/cdmscatalog/0e664875-61fe-4540-a80d-1fba8f1fad61";,
               "title": "Root catalog for 0e664875-61fe-4540-a80d-1fba8f1fad61"
           }
       ]
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@sdap.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to