Prechádzať zdrojové kódy

Fix when modifying defined attribute on the non-defining element (thereby impacting other elements as well)

Yentl Van Tendeloo 7 rokov pred
rodič
commit
0a756be92c

+ 33 - 21
bootstrap/mini_modify.alc

@@ -169,13 +169,16 @@ String function cmd_attr_name(write : Boolean, model : Element, element_name : S
 			if (set_in(dict_keys(attrs), attr_name)):
 				if (set_in(dict_keys(attrs), attr_name)):
 					if (bool_not(set_in(dict_keys(attrs), new_attr_name))):
-						Boolean optional
-						String attr_edge
-						attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
-						optional = read_attribute(model, attr_edge, "optional")
-						model_undefine_attribute(model, element_name, attr_name)
-						model_define_attribute_ID(model, element_name, new_attr_name, optional, attrs[attr_name], attr_edge)
-						return "Success"!
+						if (dict_in(model["model"][element_name], attr_name)):
+							Boolean optional
+							String attr_edge
+							attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
+							optional = read_attribute(model, attr_edge, "optional")
+							model_undefine_attribute(model, element_name, attr_name)
+							model_define_attribute_ID(model, element_name, new_attr_name, optional, attrs[attr_name], attr_edge)
+							return "Success"!
+						else:
+							return "Attribute not defined here: " + new_attr_name!
 					else:
 						return "Attribute exists: " + new_attr_name!
 				else:
@@ -194,13 +197,16 @@ String function cmd_attr_type(write : Boolean, model : Element, element_name : S
 			attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
 			if (set_in(dict_keys(attrs), attr_name)):
 				if (set_in(dict_keys(attrs), attr_name)):
-					Boolean optional
-					String attr_edge
-					attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
-					optional = read_attribute(model, attr_edge, "optional")
-					model_undefine_attribute(model, element_name, attr_name)
-					model_define_attribute_ID(model, element_name, attr_name, optional, new_attr_type, attr_edge)
-					return "Success"!
+					if (dict_in(model["model"][element_name], attr_name)):
+						Boolean optional
+						String attr_edge
+						attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
+						optional = read_attribute(model, attr_edge, "optional")
+						model_undefine_attribute(model, element_name, attr_name)
+						model_define_attribute_ID(model, element_name, attr_name, optional, new_attr_type, attr_edge)
+						return "Success"!
+					else:
+						return "Attribute not defined here: " + attr_name!
 				else:
 					return "Attribute not defined: " + attr_name!
 			else:
@@ -217,11 +223,14 @@ String function cmd_attr_optional(write : Boolean, model : Element, element_name
 			attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
 			if (set_in(dict_keys(attrs), attr_name)):
 				if (set_in(dict_keys(attrs), attr_name)):
-					String attr_edge
-					attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
-					model_undefine_attribute(model, element_name, attr_name)
-					model_define_attribute_ID(model, element_name, attr_name, optional, attrs[attr_name], attr_edge)
-					return "Success"!
+					if (dict_in(model["model"][element_name], attr_name)):
+						String attr_edge
+						attr_edge = reverseKeyLookup(model["model"], dict_read_edge(model["model"][element_name], attr_name))
+						model_undefine_attribute(model, element_name, attr_name)
+						model_define_attribute_ID(model, element_name, attr_name, optional, attrs[attr_name], attr_edge)
+						return "Success"!
+					else:
+						return "Attribute not defined here: " + attr_name!
 				else:
 					return "Attribute not defined: " + attr_name!
 			else:
@@ -238,8 +247,11 @@ String function cmd_undefine_attribute(write : Boolean, model : Element, element
 			attrs = getInstantiatableAttributes(model, element_name, "AttributeLink")
 			if (set_in(dict_keys(attrs), attr_name)):
 				if (set_in(dict_keys(attrs), attr_name)):
-					model_undefine_attribute(model, element_name, attr_name)
-					return "Success"!
+					if (dict_in(model["model"][element_name], attr_name)):
+						model_undefine_attribute(model, element_name, attr_name)
+						return "Success"!
+					else:
+						return "Attribute not defined here: " + attr_name!
 				else:
 					return "Attribute not defined: " + attr_name!
 			else:

+ 49 - 2
unit/test_all.py

@@ -2012,6 +2012,52 @@ class TestModelverse(unittest.TestCase):
         # No write permissions, but can still query
         assert read_defined_attrs("formalisms/SimpleClassDiagrams", "Association") == ({"name": "String"}, {"abstract": "Boolean", "constraint": "ActionCode", "lower_cardinality": "Natural", "upper_cardinality": "Natural", "source_lower_cardinality": "Natural", "source_upper_cardinality": "Natural", "target_lower_cardinality": "Natural", "target_upper_cardinality": "Natural"})
 
+    def test_op_undefine_attribute(self):
+        model_add("users/user/test/a", "formalisms/SimpleClassDiagrams", """
+            SimpleAttribute String {}
+            SimpleAttribute Natural {}
+            Class A {
+                name = "ABC"
+                value : Natural
+                new_name ?: String
+                name : String
+            }
+            Association B (A, A) {
+                name = "DEF"
+                edge_value : Natural
+                name : String
+                other_value ?: String
+            }
+            Class C {}
+            Class D : A {
+                additional_attr : Natural
+            }
+            Association E : B (D, A) {
+                next_attr : String
+            }
+            """)
+
+        assert read_defined_attrs("users/user/test/a", "A") == ({"value": "Natural", "name": "String"}, {"new_name": "String"})
+        assert read_defined_attrs("users/user/test/a", "D") == ({"value": "Natural", "name": "String", "additional_attr": "Natural"}, {"new_name": "String"})
+        undefine_attribute("users/user/test/a", "A", "name")
+        assert read_defined_attrs("users/user/test/a", "A") == ({"value": "Natural"}, {"new_name": "String"})
+        assert read_defined_attrs("users/user/test/a", "D") == ({"value": "Natural", "additional_attr": "Natural"}, {"new_name": "String"})
+
+        assert read_defined_attrs("users/user/test/a", "B") == ({"edge_value": "Natural", "name": "String"}, {"other_value": "String"})
+        assert read_defined_attrs("users/user/test/a", "E") == ({"edge_value": "Natural", "name": "String", "next_attr": "String"}, {"other_value": "String"})
+        undefine_attribute("users/user/test/a", "B", "other_value")
+        assert read_defined_attrs("users/user/test/a", "B") == ({"edge_value": "Natural", "name": "String"}, {})
+        assert read_defined_attrs("users/user/test/a", "E") == ({"edge_value": "Natural", "name": "String", "next_attr": "String"}, {})
+
+        # Remove superclass definition
+        assert read_defined_attrs("users/user/test/a", "D") == ({"value": "Natural", "additional_attr": "Natural"}, {"new_name": "String"})
+        try:
+            undefine_attribute("users/user/test/a", "D", "value")
+            self.fail()
+        except SuperclassAttribute:
+            pass
+        assert read_defined_attrs("users/user/test/a", "D") == ({"value": "Natural", "additional_attr": "Natural"}, {"new_name": "String"})
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):
@@ -2032,10 +2078,11 @@ class TestModelverse(unittest.TestCase):
     def test_op_group_join(self):
     def test_op_group_kick(self):
     def test_op_group_list(self):
-    def test_op_undefine_attribute(self):
-    def test_op_read_defined_attrs(self):
     def test_op_conformance_delete(self):
     def test_op_conformance_add(self):
+    def test_op_attribute_optional(self):
+    def test_op_attribute_type(self):
+    def test_op_attribute_name(self):
     """
 
     def test_modelling(self):

+ 7 - 0
wrappers/classes/modelverse.xml

@@ -1342,6 +1342,13 @@
                         </raise>
                     </transition>
 
+                    <transition cond="self.expect_response_partial('Attribute not defined here: ', pop=False)" target="../wait_for_action/history">
+                        <raise event="exception">
+                            <parameter expr="'SuperclassAttribute'"/>
+                            <parameter expr="self.split_response(self.responses.pop(0))[0]"/>
+                        </raise>
+                    </transition>
+
                     <transition cond="self.expect_response_partial('Unknown location: ', pop=False)" target="../wait_for_action/history">
                         <raise event="exception">
                             <parameter expr="'UnknownLocation'"/>

+ 3 - 0
wrappers/modelverse.py

@@ -18,6 +18,9 @@ else:
 class ModelverseException(Exception):
     pass
 
+class SuperclassAttribute(ModelverseException):
+    pass
+
 class UnknownError(ModelverseException):
     pass
 

+ 48 - 37
wrappers/modelverse_SCCD.py

@@ -1779,6 +1779,11 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_operations_20.setTrigger(None)
         _initialized_behaviour_operations_20.setGuard(self._initialized_behaviour_operations_20_guard)
         self.states["/initialized/behaviour/operations"].addTransition(_initialized_behaviour_operations_20)
+        _initialized_behaviour_operations_21 = Transition(self, self.states["/initialized/behaviour/operations"], [self.states["/initialized/behaviour/wait_for_action/history"]])
+        _initialized_behaviour_operations_21.setAction(self._initialized_behaviour_operations_21_exec)
+        _initialized_behaviour_operations_21.setTrigger(None)
+        _initialized_behaviour_operations_21.setGuard(self._initialized_behaviour_operations_21_guard)
+        self.states["/initialized/behaviour/operations"].addTransition(_initialized_behaviour_operations_21)
         
         # transition /initialized/behaviour/wait_for_action
         _initialized_behaviour_wait_for_action_0 = Transition(self, self.states["/initialized/behaviour/wait_for_action"], [self.states["/initialized/behaviour/wait_for_action/history"]])
@@ -2163,119 +2168,125 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response_partial('Attribute not found: ', pop=False)
     
     def _initialized_behaviour_operations_2_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownLocation', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['SuperclassAttribute', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_2_guard(self, parameters):
-        return self.expect_response_partial('Unknown location: ', pop=False)
+        return self.expect_response_partial('Attribute not defined here: ', pop=False)
     
     def _initialized_behaviour_operations_3_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['NotAnAssociation', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['UnknownLocation', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_3_guard(self, parameters):
-        return self.expect_response_partial('Not an association: ', pop=False)
+        return self.expect_response_partial('Unknown location: ', pop=False)
     
     def _initialized_behaviour_operations_4_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['ModelExists', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['NotAnAssociation', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_4_guard(self, parameters):
-        return self.expect_response_partial('Model exists: ', pop=False)
+        return self.expect_response_partial('Not an association: ', pop=False)
     
     def _initialized_behaviour_operations_5_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['FolderExists', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['ModelExists', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_5_guard(self, parameters):
-        return self.expect_response_partial('Folder exists: ', pop=False)
+        return self.expect_response_partial('Model exists: ', pop=False)
     
     def _initialized_behaviour_operations_6_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['AttributeExists', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['FolderExists', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_6_guard(self, parameters):
-        return self.expect_response_partial('Attribute exists: ', pop=False)
+        return self.expect_response_partial('Folder exists: ', pop=False)
     
     def _initialized_behaviour_operations_7_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownM3', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['AttributeExists', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_7_guard(self, parameters):
-        return self.expect_response_partial('Type cannot be typed as formalisms/SimpleClassDiagrams: ', pop=False)
+        return self.expect_response_partial('Attribute exists: ', pop=False)
     
     def _initialized_behaviour_operations_8_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['ElementExists', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['UnknownM3', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_8_guard(self, parameters):
-        return self.expect_response_partial('Element exists: ', pop=False)
+        return self.expect_response_partial('Type cannot be typed as formalisms/SimpleClassDiagrams: ', pop=False)
     
     def _initialized_behaviour_operations_9_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['ReadPermissionDenied', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['ElementExists', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_9_guard(self, parameters):
-        return self.expect_response_partial('Read permission denied to: ', pop=False)
+        return self.expect_response_partial('Element exists: ', pop=False)
     
     def _initialized_behaviour_operations_10_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['WritePermissionDenied', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['ReadPermissionDenied', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_10_guard(self, parameters):
-        return self.expect_response_partial('Write permission denied to: ', pop=False)
+        return self.expect_response_partial('Read permission denied to: ', pop=False)
     
     def _initialized_behaviour_operations_11_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['WritePermissionDenied', self.current_model]))
+        self.raiseInternalEvent(Event("exception", None, ['WritePermissionDenied', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_11_guard(self, parameters):
-        return self.expect_response('Write permission denied', pop=True)
+        return self.expect_response_partial('Write permission denied to: ', pop=False)
     
     def _initialized_behaviour_operations_12_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['ExecutePermissionDenied', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['WritePermissionDenied', self.current_model]))
     
     def _initialized_behaviour_operations_12_guard(self, parameters):
-        return self.expect_response_partial('Execute permission denied to: ', pop=False)
+        return self.expect_response('Write permission denied', pop=True)
     
     def _initialized_behaviour_operations_13_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['GroupPermissionDenied', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['ExecutePermissionDenied', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_13_guard(self, parameters):
-        return self.expect_response_partial('Group permission denied to: ', pop=False)
+        return self.expect_response_partial('Execute permission denied to: ', pop=False)
     
     def _initialized_behaviour_operations_14_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UserPermissionDenied', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['GroupPermissionDenied', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_14_guard(self, parameters):
-        return self.expect_response_partial('User permission denied to: ', pop=False)
+        return self.expect_response_partial('Group permission denied to: ', pop=False)
     
     def _initialized_behaviour_operations_15_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['AdminPermissionDenied', 'Admin permissions are required for this operation!']))
+        self.raiseInternalEvent(Event("exception", None, ['UserPermissionDenied', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_15_guard(self, parameters):
-        return self.expect_response_partial('Admin permission denied', pop=True)
+        return self.expect_response_partial('User permission denied to: ', pop=False)
     
     def _initialized_behaviour_operations_16_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['InterfaceMismatch', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['AdminPermissionDenied', 'Admin permissions are required for this operation!']))
     
     def _initialized_behaviour_operations_16_guard(self, parameters):
-        return self.expect_response_partial('Incorrect format: ', pop=False)
+        return self.expect_response_partial('Admin permission denied', pop=True)
     
     def _initialized_behaviour_operations_17_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownElement', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['InterfaceMismatch', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_17_guard(self, parameters):
-        return self.expect_response_partial('Element not found: ', pop=False)
+        return self.expect_response_partial('Incorrect format: ', pop=False)
     
     def _initialized_behaviour_operations_18_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownModel', self.split_response(self.responses.pop(0))[0]]))
+        self.raiseInternalEvent(Event("exception", None, ['UnknownElement', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_18_guard(self, parameters):
-        return self.expect_response_partial('Model not found: ', pop=False)
+        return self.expect_response_partial('Element not found: ', pop=False)
     
     def _initialized_behaviour_operations_19_exec(self, parameters):
-        self.raiseInternalEvent(Event("exception", None, ['UnknownMetamodellingHierarchy', 'Metamodelling hierarchy could not be resolved or automatically inferred: there is no typing relation between your specified model and metamodel (%s)' % self.responses.pop(0)]))
+        self.raiseInternalEvent(Event("exception", None, ['UnknownModel', self.split_response(self.responses.pop(0))[0]]))
     
     def _initialized_behaviour_operations_19_guard(self, parameters):
-        return self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)
+        return self.expect_response_partial('Model not found: ', pop=False)
     
     def _initialized_behaviour_operations_20_exec(self, parameters):
+        self.raiseInternalEvent(Event("exception", None, ['UnknownMetamodellingHierarchy', 'Metamodelling hierarchy could not be resolved or automatically inferred: there is no typing relation between your specified model and metamodel (%s)' % self.responses.pop(0)]))
+    
+    def _initialized_behaviour_operations_20_guard(self, parameters):
+        return self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)
+    
+    def _initialized_behaviour_operations_21_exec(self, parameters):
         print("Unknown Error: " + self.responses[0])
         pass
         self.raiseInternalEvent(Event("exception", None, ['UnknownError', 'Error: %s' % self.responses.pop(0)]))
     
-    def _initialized_behaviour_operations_20_guard(self, parameters):
+    def _initialized_behaviour_operations_21_guard(self, parameters):
         return self.expect_response_partial('', pop=False)
     
     def _initialized_behaviour_wait_for_action_0_exec(self, parameters):