From a3a85b220b572546a5ca005fb50d85b38242b7e5 Mon Sep 17 00:00:00 2001 From: Tal Liron Date: Fri, 13 Jan 2017 15:16:23 -0600 Subject: [PATCH] ARIA-65 Add validation for relationship assignment type --- .../simple_v1_0/modeling/requirements.py | 17 +++++++++++++---- .../aria_extension_tosca/simple_v1_0/types.py | 8 ++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py index 8f6c38fc..97e30eea 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py @@ -159,12 +159,21 @@ def convert_requirement_from_definition_to_assignment(context, requirement_defin relationship_template = relationship_type relationship_type = relationship_template._get_type(context) + definition_relationship_type = None + relationship_definition = requirement_definition.relationship # RelationshipDefinition + if relationship_definition is not None: + definition_relationship_type = relationship_definition._get_type(context) + # If not exists, try at the node type - relationship_definition = None if relationship_type is None: - relationship_definition = requirement_definition.relationship # RelationshipDefinition - if relationship_definition is not None: - relationship_type = relationship_definition._get_type(context) + relationship_type = definition_relationship_type + else: + # Make sure the type is derived + if not definition_relationship_type._is_descendant(context, relationship_type): + context.validation.report( + 'assigned relationship type "%s" is not a descendant of declared relationship type "%s"' + % (relationship_type._name, definition_relationship_type._name), + locator=container._locator, level=Issue.BETWEEN_TYPES) if relationship_type is not None: raw['relationship'] = OrderedDict() diff --git a/extensions/aria_extension_tosca/simple_v1_0/types.py b/extensions/aria_extension_tosca/simple_v1_0/types.py index 39843aca..2112f7f1 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/types.py @@ -483,6 +483,14 @@ def _get_parent(self, context): return get_parent_presentation(context, self, convert_shorthand_to_full_type_name, 'relationship_types') + @cachedmethod + def _is_descendant(self, context, the_type): + if the_type is None: + return False + elif the_type._name == self._name: + return True + return self._is_descendant(context, the_type._get_parent(context)) + @cachedmethod def _get_properties(self, context): return FrozenDict(get_inherited_property_definitions(context, self, 'properties'))