From 6722bfb53ea121ddf34e59c9dd8efe055bc02586 Mon Sep 17 00:00:00 2001 From: Jiahang Chen <chen@mmi.rwth-aachen.de> Date: Thu, 10 Dec 2020 09:59:41 +0100 Subject: [PATCH] deactivate lokal id --- ml/feature.py | 7 ++++--- ml/role.py | 7 ++++--- ml/thing.py | 16 ++++++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ml/feature.py b/ml/feature.py index b851865..8cad153 100644 --- a/ml/feature.py +++ b/ml/feature.py @@ -24,7 +24,7 @@ def __init__(self, name="", identifier=""): self.__class_name = "fml40::{}".format(self.__class__.__name__) else: self.__class_name = "ml40::{}".format(self.__class__.__name__) - self.__identifier = ID(identifier).identifier + self.__identifier = identifier self.__subFeatures = dict() self.__json_out = dict() @@ -94,7 +94,7 @@ def identifier(self, value): :type value: str """ - self.__identifier = ID(value).identifier + self.__identifier = value @property def subFeatures(self): @@ -129,8 +129,9 @@ def to_json(self): self.__json_out = { "class": self.class_name, - "identifier": self.identifier, } + if self.identifier: + self.__json_out["identifier"] = self.identifier if self.name: self.__json_out["name"] = self.name if self.subFeatures: diff --git a/ml/role.py b/ml/role.py index 9dccfff..0f0db9f 100644 --- a/ml/role.py +++ b/ml/role.py @@ -15,7 +15,7 @@ def __init__(self, name="", identifier=""): :param identifier: Identifier of the feature """ - self.__identifier = ID(identifier).identifier + self.__identifier = identifier self.__name = name # TODO: Remove code duplication (feature.py). @@ -74,7 +74,7 @@ def identifier(self, value): :param value: Proposal of the identifier """ - self.__identifier = ID(value).identifier + self.__identifier = value def to_json(self): """Returns a JSON representation of this role. @@ -82,6 +82,7 @@ def to_json(self): self.__json_out = { "class": self.__class_name, - "identifier": self.__identifier, } + if self.identifier: + self.__json_out["identifier"] = self.identifier return self.__json_out diff --git a/ml/thing.py b/ml/thing.py index c17ee4a..230b666 100644 --- a/ml/thing.py +++ b/ml/thing.py @@ -66,8 +66,6 @@ def __init__( self.__model = model self.__thing_id = model.get("thingId", "") - if not self.__thing_id: - self.__thing_id = ID().identifier self.__policy_id = model.get("policyId", "") self.__grant_type = grant_type self.__username = username @@ -843,8 +841,10 @@ def to_dir_json(self): for key in self.features.keys(): feature_target = { "class": self.features[key].to_json()["class"], - "identifier": self.features[key].to_json()["identifier"] } + if self.features[key].to_json().get("identifier") is not None: + feature_target["identifier"] = self.features[key].to_json()["identifier"] + feature_entry = {"association": "features", "target": feature_target} # if the feature has targets, like ml40::Composite if hasattr(self.features[key], "targets"): @@ -906,11 +906,12 @@ def to_subthing_json(self): json_out = { "class": "ml40::Thing", - "identifier": self.thing_id, "name": self.name, "roles": [], "features": [], } + if self.thing_id: + json_out["identifier"] = self.thing_id for key in self.roles.keys(): json_out["roles"].append(self.roles[key].to_json()) for key in self.features.keys(): @@ -927,15 +928,18 @@ def to_subthing_dir_json(self): """ - json_out = {"class": "ml40::Thing", "identifier": self.thing_id, "links": []} + json_out = {"class": "ml40::Thing", "links": []} + if self.thing_id: + json_out["identifier"] = self.thing_id for key in self.roles.keys(): role_entry = {"association": "roles", "target": self.roles[key].to_json()} json_out["links"].append(role_entry) for key in self.features.keys(): feature_target = { "class": self.features[key].to_json()["class"], - "identifier": self.features[key].to_json()["identifier"], } + if self.features[key].to_json().get("identifier") is not None: + feature_target["identifier"] = self.features[key].to_json()["identifier"] feature_entry = {"association": "features", "target": feature_target} json_out["links"].append(feature_entry) return json_out -- GitLab