Skip to content

Commit

Permalink
add class to load PaNOSC mappings into the code #265
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Dec 9, 2021
1 parent 978a8bd commit f9bb6de
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions datagateway_api/src/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ class PythonICATError(ApiError):
def __init__(self, msg="Python ICAT error", *args, **kwargs):
super().__init__(msg, *args, **kwargs)
self.status_code = 500


class SearchAPIError(ApiError):
def __init__(self, msg="Search API error", *args, **kwargs):
super().__init__(msg, *args, **kwargs)
self.status_code = 500
29 changes: 29 additions & 0 deletions datagateway_api/src/search_api/panosc_mappings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json
from pathlib import Path

from datagateway_api.src.common.exceptions import SearchAPIError


class PaNOSCMappings:
def __init__(
self, path=Path(__file__).parent.parent.parent / "search_api_mapping.json",
):
try:
with open(path, encoding="utf-8") as target:
self.mappings = json.load(target)
except IOError as e:
raise SearchAPIError(e)


# TODO - don't think I'll need this
def load_mappings(path=Path(__file__).parent.parent.parent / "search_api_mapping.json"):
try:
with open(path, encoding="utf-8") as target:
data = json.load(target)
except IOError as e:
raise SearchAPIError(e)

return data


mappings = PaNOSCMappings()

0 comments on commit f9bb6de

Please sign in to comment.