summaryrefslogtreecommitdiff
path: root/src/hydrilla/server/serve.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-05-31 18:25:18 +0200
committerWojtek Kosior <koszko@koszko.org>2022-05-31 18:25:18 +0200
commit9dcbfdfe8620cc417438d1727aa1e0c89846e9bf (patch)
tree9d93c401bff22799aff9b02afab89715fe55f74a /src/hydrilla/server/serve.py
parent2290975f9e867938116bf1e4d21f83eb073eb906 (diff)
downloadhaketilo-hydrilla-9dcbfdfe8620cc417438d1727aa1e0c89846e9bf.tar.gz
haketilo-hydrilla-9dcbfdfe8620cc417438d1727aa1e0c89846e9bf.zip
update to schema version 2 and hydrilla builder version 1.1-beta1
Diffstat (limited to 'src/hydrilla/server/serve.py')
-rw-r--r--src/hydrilla/server/serve.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/hydrilla/server/serve.py b/src/hydrilla/server/serve.py
index a6a1204..779f3d2 100644
--- a/src/hydrilla/server/serve.py
+++ b/src/hydrilla/server/serve.py
@@ -56,13 +56,18 @@ generated_by = {
class ItemInfo(ABC):
"""Shortened data of a resource/mapping."""
- def __init__(self, item_obj: dict):
+ def __init__(self, item_obj: dict, major_schema_version: int):
"""Initialize ItemInfo using item definition read from JSON."""
self.version = util.normalize_version(item_obj['version'])
self.identifier = item_obj['identifier']
self.uuid = item_obj.get('uuid')
self.long_name = item_obj['long_name']
+ self.required_mappings = []
+ if major_schema_version >= 2:
+ self.required_mappings = [map_ref['identifier'] for map_ref in
+ item_obj.get('required_mappings', [])]
+
def path(self) -> str:
"""
Get a relative path to this item's JSON definition with respect to
@@ -72,18 +77,18 @@ class ItemInfo(ABC):
class ResourceInfo(ItemInfo):
"""Shortened data of a resource."""
- def __init__(self, resource_obj: dict):
+ def __init__(self, resource_obj: dict, major_schema_version: int):
"""Initialize ResourceInfo using resource definition read from JSON."""
- super().__init__(resource_obj)
+ super().__init__(resource_obj, major_schema_version)
dependencies = resource_obj.get('dependencies', [])
self.dependencies = [res_ref['identifier'] for res_ref in dependencies]
class MappingInfo(ItemInfo):
"""Shortened data of a mapping."""
- def __init__(self, mapping_obj: dict):
+ def __init__(self, mapping_obj: dict, major_schema_version: int):
"""Initialize MappingInfo using mapping definition read from JSON."""
- super().__init__(mapping_obj)
+ super().__init__(mapping_obj, major_schema_version)
self.payloads = {}
for pattern, res_ref in mapping_obj.get('payloads', {}).items():
@@ -332,16 +337,15 @@ class Malcontent:
version = util.parse_version(ver_file.name)
identifier = ver_file.parent.name
- with open(ver_file, 'rt') as file_handle:
- item_json = json.load(file_handle)
+ item_json, major = util.load_instance_from_file(ver_file)
- util.validator_for(f'api_{item_type}_description-1.0.1.schema.json')\
+ util.validator_for(f'api_{item_type}_description-{major}.schema.json')\
.validate(item_json)
if item_type == 'resource':
- item_info = ResourceInfo(item_json)
+ item_info = ResourceInfo(item_json, major)
else:
- item_info = MappingInfo(item_json)
+ item_info = MappingInfo(item_json, major)
if item_info.identifier != identifier:
msg = f_('item_{item}_in_file_{file}')\
@@ -394,6 +398,19 @@ class Malcontent:
if payload not in self.infos['resource']:
report_missing_payload(mapping_info, payload)
+ def report_missing_mapping(info: Union[MappingInfo, ResourceInfo],
+ required_mapping: str) -> None:
+ msg = _('no_mapping_{required_by}_{ver}_{required}')\
+ .format(required_by=info.identifier, required=required_mapping,
+ ver=util.version_string(info.version))
+ logging.error(msg)
+
+ for item_info in (*self._all_of_type('mapping'),
+ *self._all_of_type('resource')):
+ for required in item_info.required_mappings:
+ if required not in self.infos['mapping']:
+ report_missing_mapping(item_info, required)
+
def _finalize(self):
"""
Initialize structures needed to serve queries. Called once after all