Browse Source

Added transformation_list and transformation_list_full + fixed related
bugs

Yentl Van Tendeloo 4 years ago
parent
commit
469340a433
2 changed files with 49 additions and 7 deletions
  1. 41 7
      core/core_algorithm.alc
  2. 8 0
      integration/test_mvc.py

+ 41 - 7
core/core_algorithm.alc

@@ -252,7 +252,7 @@ String function get_group_id(name : String):
 	
 	return ""!
 
-Void function model_create(model : Element, name : String, user_id : String, type_id : String):
+Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
 	String location
 	String model_id
 
@@ -260,7 +260,7 @@ Void function model_create(model : Element, name : String, user_id : String, typ
 	export_node(location, model)
 
 	// Manage meta-info
-	model_id = instantiate_node(core, "Model", "")
+	model_id = instantiate_node(core, kind, "")
 	instantiate_attribute(core, model_id, "name", name)
 	instantiate_attribute(core, model_id, "location", location)
 	instantiate_attribute(core, model_id, "permissions", "200")
@@ -359,7 +359,7 @@ Void function user_function_skip_init(user_id : String):
 
 						// TODO Update construct_model call to this interface
 						new_model = construct_model_raw(import_node(read_attribute(core, type_id, "location")))
-						model_create(new_model, name, user_id, type_id)
+						model_create(new_model, name, user_id, type_id, "Model")
 						output("Model upload success!")
 					else:
 						output("Model with that name already exists!")
@@ -480,7 +480,7 @@ Void function user_function_skip_init(user_id : String):
 										// Check if the destination model already exists
 										if (get_model_id(outputs[key]) == ""):
 											// New model
-											model_create(split_off_model, outputs[key], user_id, desired_metamodel_id)
+											model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
 										else:
 											// Model exists, so we overwrite
 											model_overwrite(split_off_model, outputs[key])
@@ -634,7 +634,7 @@ Void function user_function_skip_init(user_id : String):
 
 					// New location is available, so write
 					merged_formalism = model_fuse(set_copy(all_formalisms))
-					model_create(merged_formalism, "__merged_" + name, user_id, type_id)
+					model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
 					merged_formalism_id = get_model_id("__merged_" + name)
 
 					// Add tracability links at this level
@@ -646,7 +646,7 @@ Void function user_function_skip_init(user_id : String):
 
 					// Merge complete, now RAMify!
 					ramified_formalism = ramify(merged_formalism)
-					model_create(ramified_formalism, name, user_id, type_id)
+					model_create(ramified_formalism, name, user_id, type_id, "Model")
 					ramified_formalism_id = get_model_id(name)
 
 					// Add tracability link at this level
@@ -746,7 +746,7 @@ Void function user_function_skip_init(user_id : String):
 						// Finished with all information, now create the model itself!
 						new_model = instantiate_model(import_node(read_attribute(core, ramified_metamodel_id, "location")))
 
-						model_create(new_model, name, user_id, ramified_metamodel_id)
+						model_create(new_model, name, user_id, ramified_metamodel_id, "ModelTransformation")
 						model_id = get_model_id(name)
 
 						// Extend metadata with info on source and target
@@ -767,6 +767,40 @@ Void function user_function_skip_init(user_id : String):
 			else:
 				output("No such model")
 
+		elif (cmd == "transformation_list"):
+			// List all models
+			Element models
+			String m
+			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"))))
+
+		elif (cmd == "transformation_list_full"):
+			// List all models with full info
+			Element models
+			String m
+			String permissions
+			String owner
+			String group
+			String name
+			String type
+			String size
+
+			models = allInstances(core, "Transformation")
+			while (read_nr_out(models) > 0):
+				m = set_pop(models)
+				permissions = read_attribute(core, m, "permissions")
+				owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
+				group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
+				name = read_attribute(core, m, "name")
+				size = cast_i2s(read_nr_out(dict_read(import_node(read_attribute(core, m, "location")), "model")))
+				type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
+				output((((((((((("  " + permissions) + "  ") + owner) + " ") + group) + "    ") + size) + "   ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type)
+
 		elif (cmd == "permission_modify"):
 			String permissions
 			Integer permission

+ 8 - 0
integration/test_mvc.py

@@ -300,6 +300,8 @@ class TestModelverseCore(unittest.TestCase):
                 "",
                 "PetriNets_Print",
                 "model_list_full",
+                "transformation_list",
+                "transformation_list_full",
             ],
             [   "Desired username for admin user?",
                 "Welcome to the Model Management Interface v2.0!",
@@ -345,5 +347,11 @@ class TestModelverseCore(unittest.TestCase):
                      "  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"
+                    ]),
+                "Ready for command...",
             ],
             mode))