Просмотр исходного кода

Add MT instance with an actual model upload

Yentl Van Tendeloo 8 лет назад
Родитель
Сommit
37708018ca

+ 1 - 1
bootstrap/model_management.alc

@@ -24,7 +24,7 @@ Element function model_fuse(models : Element):
 	// Do the iteration
 	while (read_nr_out(models)):
 		tagged_model = set_pop(models)
-		model_name = string_join(list_read(tagged_model, 0), "/")
+		model_name = string_join(list_read(tagged_model, 0), "_")
 		model = list_read(tagged_model, 1)
 
 		// Add all elements from 'model', but prepend it with the 'model_name'

+ 14 - 1
bootstrap/modelling.alc

@@ -83,8 +83,10 @@ Void function retype_model(model : Element, metamodel : Element):
 Void function retype(model : Element, element : String, type : String):
 	// Retype a model, deleting any previous type the element had
 	// The type string is evaluated in the metamodel previously specified
+
 	if (dict_in_node(model["type_mapping"], model["model"][element])):
 		dict_delete_node(model["type_mapping"], model["model"][element])
+
 	dict_add(model["type_mapping"], model["model"][element], model["metamodel"]["model"][type])
 
 	return!
@@ -102,6 +104,9 @@ String function instantiate_node(model : Element, type_name : String, instance_n
 	// Basically create a node and type it immediately
 	String actual_name
 
+	log("Instantiate node " + instance_name)
+	log("   with type " + type_name)
+
 	actual_name = model_add_node(model, instance_name)
 	retype(model, actual_name, type_name)
 
@@ -121,7 +126,13 @@ String function find_attribute_type(model : Element, elem : String, name : Strin
 	String mm_elem
 	String direct_type
 
-	direct_type = reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][elem]))
+	direct_type = read_type(model, elem)
+
+	if (direct_type == ""):
+		log("Direct type of " + elem)
+		log("  = " + direct_type)
+		return ""!
+	
 	mm_elem = find_attribute_definer(model["metamodel"], direct_type, name)
 
 	if (value_eq(mm_elem, "")):
@@ -194,6 +205,7 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 
 	if (attr_type == ""):
 		log("Could not find attribute " + cast_v2s(attribute_name))
+		log("For element " + element)
 		return!
 		
 	// Make a copy of the value, as it is likely that this value is reused later on
@@ -521,6 +533,7 @@ Element function construct_model_raw(metamodel : Element):
 
 	while (True):
 		command = input()
+		log("Command: " + command)
 		if (command == "add_node"):
 			model_add_node(model, input())
 		elif (command == "add_value"):

+ 19 - 1
bootstrap/object_operations.alc

@@ -239,4 +239,22 @@ Element function allowedAssociationsBetween(model : Element, src : String, dst :
 	return result!
 
 String function read_type(model : Element, name : String):
-	return reverseKeyLookup(model["metamodel"]["model"], dict_read_node(model["type_mapping"], model["model"][name]))!
+	String result
+
+	Element mm
+	Element tm
+
+	mm = model["metamodel"]["model"]
+	if (dict_in(model["model"], name)):
+		if (dict_in_node(model["type_mapping"], model["model"][name])):
+			tm = dict_read_node(model["type_mapping"], model["model"][name])
+			
+			result = reverseKeyLookup(mm, tm)
+			if (element_eq(mm[result], tm)):
+				return result!
+			else:
+				return ""!
+		else:
+			return ""!
+	else:
+		return ""!

+ 0 - 13
core/core_algorithm.alc

@@ -275,7 +275,6 @@ Void function model_overwrite(model : Element, model_id : String):
 
 	location = "/models/" + cast_id2s(model)
 	export_node(location, model)
-	log("Got model ID: " + model_id)
 
 	// Change location in meta-data
 	unset_attribute(core, model_id, "location")
@@ -639,7 +638,6 @@ Void function user_function_skip_init(user_id : String):
 					// Add tracability links at this level
 					while (read_nr_out(all_formalisms) > 0):
 						source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
-						log("ADD tracability link to " + source_formalism_id)
 						tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
 						instantiate_attribute(core, tracability_link, "type", "merged")
 
@@ -683,20 +681,14 @@ Void function user_function_skip_init(user_id : String):
 				if (allow_read(user_id, ramified_metamodel_id)):
 					output("Supported metamodels:")
 					links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
-					log(set_to_string(links))
 					while (read_nr_out(links) > 0):
 						link_id = set_pop(links)
-						log("CHECK " + link_id)
 						merged_metamodel_id = readAssociationDestination(core, link_id)
-						log("Merged: " + merged_metamodel_id)
 						if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
 							links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
-							log(set_to_string(links_merged))
 							while (read_nr_out(links_merged) > 0):
 								merged_link_id = set_pop(links_merged)
-								log("CHECK2 " + merged_link_id)
 								if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
-									log("Found match!")
 									output(string_join("  ", read_attribute(core, readAssociationDestination(core, merged_link_id), "name")))
 									set_add(supported, readAssociationDestination(core, merged_link_id))
 
@@ -750,13 +742,9 @@ Void function user_function_skip_init(user_id : String):
 
 						// Extend metadata with info on source and target
 						while (read_nr_out(source) > 0):
-							log("Instantiate source link")
 							instantiate_link(core, "transformInput", "", model_id, set_pop(source))
-							log("OK")
 						while (read_nr_out(target) > 0):
-							log("Instantiate target link")
 							instantiate_link(core, "transformOutput", "", model_id, set_pop(target))
-							log("OK")
 
 						output("Meta-info correctly set!")
 					else:
@@ -773,7 +761,6 @@ Void function user_function_skip_init(user_id : String):
 			String type
 
 			models = allInstances(core, "Transformation")
-			log("Instances: " + set_to_string(models))
 			while (read_nr_out(models) > 0):
 				m = set_pop(models)
 				output(string_join(("[" + read_type(core, m)) + "]", string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name"))))

+ 10 - 18
integration/test_mvc.py

@@ -362,12 +362,13 @@ class TestModelverseCore(unittest.TestCase):
         self.transform_add_MT_pn_print("PO")
 
     def transform_add_MT_pn_print(self, mode):
+        print("Constructors: " + str(get_raw_model_constructor(open("integration/code/pn_print_MR.mvc", "r").read())))
         self.assertTrue(run_file(all_files,
             [ "root",
                 "model_add",
                 "SimpleClassDiagrams",
                 "PetriNets",
-                ] + get_raw_model_constructor(open("integration/code/petrinets.mvc", "r").read()) + [
+                ] + get_raw_model_constructor(open("integration/code/pn_runtime_MR.mvc", "r").read()) + [
                 "model_list_full",
                 "transformation_add_MT_language",
                 "PetriNets",
@@ -380,7 +381,8 @@ class TestModelverseCore(unittest.TestCase):
                 "",
                 "",
                 "PetriNets_Print",
-                "exit",
+                ] + get_raw_model_constructor(open("integration/code/pn_print_MR.mvc", "r").read()) + [
+                "transformation_list_full",
             ],
             [   "Desired username for admin user?",
                 "Welcome to the Model Management Interface v2.0!",
@@ -394,7 +396,7 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
-                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    22   PetriNets : SimpleClassDiagrams",
                      "  200  root admin    53   core : CoreFormalism"]),
                 "Ready for command...",
                 "Formalisms to include (terminate with empty string)?",
@@ -402,9 +404,9 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
                      "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
-                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
-                     "  200  root nobody    14   __merged_PetriNets_RAM : SimpleClassDiagrams",
-                     "  200  root nobody    328   PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    22   PetriNets : SimpleClassDiagrams",
+                     "  200  root nobody    22   __merged_PetriNets_RAM : SimpleClassDiagrams",
+                     "  200  root nobody    352   PetriNets_RAM : SimpleClassDiagrams",
                      "  200  root admin    79   core : CoreFormalism"]),
                 "Ready for command...",
                 "RAMified metamodel to use?",
@@ -416,20 +418,10 @@ class TestModelverseCore(unittest.TestCase):
                 "Model added as source",
                 "Which ones do you want to use as target (empty string to finish)?",
                 "Name of new transformation?",
+                "Waiting for model constructors...",
                 "Meta-info correctly set!",
                 "Ready for command...",
-                set(["  221  root admin    673   SimpleClassDiagrams : SimpleClassDiagrams",
-                     "  221  root admin    86   CoreFormalism : SimpleClassDiagrams",
-                     "  200  root nobody    14   PetriNets : SimpleClassDiagrams",
-                     "  200  root nobody    14   __merged_PetriNets_RAM : SimpleClassDiagrams",
-                     "  200  root nobody    328   PetriNets_RAM : SimpleClassDiagrams",
-                     "  200  root nobody    0   PetriNets_Print : PetriNets_RAM",
-                     "  200  root admin    90   core : CoreFormalism"]),
-                "Ready for command...",
-                set(["[ModelTransformation] PetriNets_Print : PetriNets_RAM",
-                    ]),
-                "Ready for command...",
-                set(["  200  root nobody    0   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
+                set(["  200  root nobody    26   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
                     ]),
                 "Ready for command...",
             ],