Procházet zdrojové kódy

Allow traceability models to be used in the PM

Yentl Van Tendeloo před 7 roky
rodič
revize
0868416901
3 změnil soubory, kde provedl 54 přidání a 28 odebrání
  1. binární
      bootstrap/bootstrap.m.gz
  2. 53 27
      bootstrap/core_algorithm.alc
  3. 1 1
      wrappers/modelverse_SCCD.py

binární
bootstrap/bootstrap.m.gz


+ 53 - 27
bootstrap/core_algorithm.alc

@@ -649,6 +649,10 @@ Element function execute_operation(operation_id : String, input_models : Element
 		while (set_len(keys) > 0):
 			key = set_pop(keys)
 			Element mm
+			if (get_entry_id(input_models[key]) == ""):
+				// Input model doesn't exist yet, so create
+				cmd_model_add(input_metamodels[key], input_models[key], "")
+				log("Creating non-existing input model")
 			mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
 			if (element_eq(mm, read_root())):
 				log("Signature mismatch in operation for tag " + key)
@@ -773,17 +777,22 @@ Boolean function enact_action(pm : Element, element : String, mapping : Element)
 	Element output_mms
 	Element consumes_link
 	String name
-	String value
 	String elem_name
 	Element keys
 	String key
 	String consume
 	String produce
+	Element input_traceability_model
+	String output_traceability_name
+	String output_traceability_type
 	Element output_map
 
 	inputs = dict_create()
 	outputs = dict_create()
 	output_map = dict_create()
+	input_traceability_model = read_root()
+	output_traceability_name = read_root()
+	output_traceability_type = read_root()
 
 	// Read out the referenced element from the MvC
 	transformation_id = get_entry_id(read_attribute(pm, element, "name"))
@@ -792,8 +801,19 @@ Boolean function enact_action(pm : Element, element : String, mapping : Element)
 	lst = allOutgoingAssociationInstances(pm, element, "Consumes")
 	while (set_len(lst) > 0):
 		consume = set_pop(lst)
-		value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
-		dict_add(inputs, read_attribute(pm, consume, "name"), mapping[value])
+		elem = readAssociationDestination(pm, consume)
+		type_name = read_attribute(pm, elem, "type")
+		elem_name = read_attribute(pm, elem, "name")
+		if (cast_string(read_attribute(pm, consume, "name")) == "__traceability"):
+			log("Using input traceability model!")
+			log("Mapping: " + cast_string(mapping[elem_name]))
+			log("Type: " + cast_string(type_name))
+			log("Entry mapping: " + get_entry_id(mapping[elem_name]))
+			log("Entry type: " + get_entry_id(type_name))
+			input_traceability_model = model_copy(get_full_model(get_entry_id(mapping[elem_name]), get_entry_id(type_name)))
+			output_traceability_type = type_name
+		else:
+			dict_add(inputs, read_attribute(pm, consume, "name"), mapping[elem_name])
 
 	// Find all output model names and their metamodel
 	lst = allOutgoingAssociationInstances(pm, element, "Produces")
@@ -802,8 +822,11 @@ Boolean function enact_action(pm : Element, element : String, mapping : Element)
 		elem = readAssociationDestination(pm, produce)
 		type_name = read_attribute(pm, elem, "type")
 		elem_name = read_attribute(pm, elem, "name")
-		dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
-		dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
+		if (cast_string(read_attribute(pm, produce, "name")) == "__traceability"):
+			output_traceability_name = mapping[elem_name]
+		else:
+			dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
+			dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
 
 	if read_type(core, transformation_id) == "ActionLanguage":
 		log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
@@ -814,14 +837,21 @@ Boolean function enact_action(pm : Element, element : String, mapping : Element)
 	else:
 		log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
 		output("Success: ready for MT execution")
-		
-	result = execute_operation(transformation_id, inputs, read_root())
+
+	result = execute_operation(transformation_id, inputs, input_traceability_model)
 
 	if (element_eq(result, read_root())):
 		// Something went wrong!
 		output("Failure")
 		return False!
 	else:
+		// Check if we have to store traceability information
+		if (element_neq(output_traceability_name, read_root())):
+			// Yes, so store it
+			// Note that we have overwritten the previous input traceability model, which is why it was a copy
+			model_overwrite(input_traceability_model, get_entry_id(output_traceability_name), get_entry_id(output_traceability_type))
+			log("Writing output traceability model!")
+
 		keys = dict_keys(outputs)
 		while (set_len(keys) > 0):
 			key = set_pop(keys)
@@ -894,6 +924,7 @@ Void function enact_PM(pm : Element, mapping : Element):
 			while (get_entry_id(mock_location) != ""):
 				mock_location = ".tmp/" + random_string(10)
 			dict_add(mapping, key, mock_location)
+			cmd_model_add(signature[key], mapping[key], "")
 			set_add(mock_locations, mock_location)
 
 	// Initialize Join counters
@@ -1085,30 +1116,25 @@ String function cmd_model_add(type : String, name : String, code : String):
 		// Type exists
 		if (allow_read(current_user_id, type_id)):
 			// And is readable
-			if (get_entry_id(get_foldername(name)) != ""):
-				// Folder doesn't exist yet!
-				if (allow_write(current_user_id, get_entry_id(get_foldername(name)))):
-					// Folder is writable
-					if (get_entry_id(name) == ""):
-						// Model doesn't exist yet
-						Element mm
-						mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
-						if (element_eq(mm, read_root())):
-							return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
+			create_folders(current_user_id, get_foldername(name))
+			//TODO check if bottommost existing model was writable by us
+
+			if (get_entry_id(name) == ""):
+				// Model doesn't exist yet
+				Element mm
+				mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
+				if (element_eq(mm, read_root())):
+					return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
 
-						new_model = compile_model(code, mm)
+				new_model = compile_model(code, mm)
 
-						if (element_eq(new_model, read_root())):
-							return "Compilation error"!
+				if (element_eq(new_model, read_root())):
+					return "Compilation error"!
 
-						model_create(new_model, name, type_id, "Model")
-						return "Success"!
-					else:
-						return "Model exists: " + name!
-				else:
-					return "Permission denied to folder: " + get_foldername(name)!
+				model_create(new_model, name, type_id, "Model")
+				return "Success"!
 			else:
-				return "No such folder: " + get_foldername(name)!
+				return "Model exists: " + name!
 		else:
 			return "Permission denied to model: " + type!
 	else:

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Thu Nov 16 15:55:38 2017
+Date:   Fri Nov 17 07:56:27 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server