diff --git a/README.md b/README.md index 46c07fcdf4119e967cc87ccd8ecc2fea2b37160b..12d1fca7171ac71411511a0e45d3dbab2cdad7e3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/commits/master) # Python Unified Device Interface -Current stable version: 9.3.6 +Current stable version: 9.3.7 ## Installation 1. Install the WZL-UDI package via pip @@ -58,6 +58,9 @@ Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) ## Recent changes +**9.3.7** - 2024-03-18 + - fixed serialization of semantics + **9.3.6** - 2024-03-18 - fixed serialization of semantic values diff --git a/setup.py b/setup.py index d477a6803b2d5cb5f3dbcd2929ebe3173eb983ed..6c25d066f4cc00a19d60250dea6560f41abef02e 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() setup(name='wzl-udi', - version='9.3.6', + version='9.3.7', url='https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python', project_urls={ "Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python/-/issues", diff --git a/src/http/server.py b/src/http/server.py index 1697b3068153af1d632dc82c19322879e2d59e64..f78cf4a6b9d5e22b8414249722767158b6ed6281 100644 --- a/src/http/server.py +++ b/src/http/server.py @@ -197,51 +197,53 @@ class HTTPServer(object): resource_type = HTTPServer.analyze_request_url(request) keys = self._filter_query(request.query) - if resource_type == ResourceType.profile: - if self._profiles_path is None: - raise UserException('Can\'t return requested metadata profile, as no profiles have been created for this sensor service.') - - profilename = request.url.parts[-2] if request.url.parts[-1] == '' else request.url.parts[-1] - - if len(profilename) > 12 and profilename[-12:-7] == 'Range': - filename = profilename.replace('RangeProfile', '.shacl.ttl') - else: - filename = profilename.replace('Profile', '.shacl.ttl') - - profile_path = os.path.join(self._profiles_path, filename) - response = rdflib.Graph() - response.parse(profile_path) - response.add( - (rdflib.URIRef(Semantics.namespace[profilename]), Namespaces.dcterms.license, Semantics.profile_license)) - item, status = None, 200 + try: + if resource_type == ResourceType.profile: + if self._profiles_path is None: + raise UserException('Can\'t return requested metadata profile, as no profiles have been created for this sensor service.') - elif resource_type == ResourceType.metadata or resource_type == ResourceType.data: - semantic_name = request.url.parts[-2] if request.url.parts[-1] == '' else request.url.parts[-1] + profilename = request.url.parts[-2] if request.url.parts[-1] == '' else request.url.parts[-1] - item, resource_type = self.root.resolve_semantic_path(semantic_name) - else: - assert resource_type == ResourceType.element - uuids = HTTPServer.parse_uuids(request) + if len(profilename) > 12 and profilename[-12:-7] == 'Range': + filename = profilename.replace('RangeProfile', '.shacl.ttl') + else: + filename = profilename.replace('Profile', '.shacl.ttl') - if request.query is not None and 'semantic' in request.query and request.query[ - 'semantic'] in ResourceType.semantic_resources: - resource_type = ResourceType.from_string(request.query['semantic']) + profile_path = os.path.join(self._profiles_path, filename) + response = rdflib.Graph() + response.parse(profile_path) + response.add( + (rdflib.URIRef(Semantics.namespace[profilename]), Namespaces.dcterms.license, Semantics.profile_license)) + item, status = None, 200 - try: - item = self.root[uuids] - except KeyError as e: - logger.error(traceback.format_exc()) - response = {'error': str(e)} - logger.error('Response: {}'.format(response)) - return self.prepare_response(response, None, status=404, query=request.query) + elif resource_type == ResourceType.metadata or resource_type == ResourceType.data: + semantic_name = request.url.parts[-2] if request.url.parts[-1] == '' else request.url.parts[-1] - # serializing the element - try: - if resource_type.is_semantic() and resource_type != ResourceType.profile: + item, resource_type = self.root.resolve_semantic_path(semantic_name) recursive = request.query is not None and 'all' in request.query response = item.serialize_semantics(resource_type, recursive) - elif resource_type == ResourceType.element: - response = item.serialize(keys, self._legacy_mode, HTTP_GET) + else: + assert resource_type == ResourceType.element + uuids = HTTPServer.parse_uuids(request) + + if request.query is not None and 'semantic' in request.query and request.query[ + 'semantic'] in ResourceType.semantic_resources: + resource_type = ResourceType.from_string(request.query['semantic']) + + try: + item = self.root[uuids] + + if resource_type.is_semantic(): + recursive = request.query is not None and 'all' in request.query + response = item.serialize_semantics(resource_type, recursive) + else: + response = item.serialize(keys, self._legacy_mode, HTTP_GET) + except KeyError as e: + logger.error(traceback.format_exc()) + response = {'error': str(e)} + logger.error('Response: {}'.format(response)) + return self.prepare_response(response, None, status=404, query=request.query) + status = 200 logger.info('Response: {}'.format(response)) except (DeviceException, ServerException, UserException) as e: