Browse Source

Added some new utility functions

Yentl Van Tendeloo 8 years ago
parent
commit
fd61d765e2
2 changed files with 75 additions and 2 deletions
  1. 56 0
      bootstrap/core_algorithm.alc
  2. 19 2
      bootstrap/mini_modify.alc

+ 56 - 0
bootstrap/core_algorithm.alc

@@ -1744,6 +1744,56 @@ String function cmd_service_register(user_id : String, service_name : String):
 	else:
 		return "Service already exists: " + service_name!
 
+String function cmd_user_password(user_id : String, user_name : String, new_password : String):
+	if (bool_or(user_id == get_user_id(user_name), is_admin(user_id))):
+		if (get_user_id(user_name) != ""):
+			instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
+			return "Success"!
+		else:
+			return "No such user: " + user_name!
+	else:
+		return "Permission denied to user: " + user_name!
+
+String function cmd_transformation_signature(user_id : String, transformation_name : String):
+	String model_id
+	model_id = get_model_id(transformation_name)
+
+	if (model_id != ""):
+		if (is_nominal_instance(core, model_id, "Transformation")):
+			if (allow_read(user_id, transformation_name)):
+				String result
+				String elem
+				Element inputs
+				Element outputs
+
+				result = "Success: "
+				inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
+				while (read_nr_out(inputs) > 0):
+					elem = set_pop(inputs)
+					result = string_join(string_join(string_join(string_join("I ", read_attribute(core, elem, "name")), " "), read_attribute(core, readAssociationDestination(core, elem), "name")), "\n")
+
+				outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
+				while (read_nr_out(outputs) > 0):
+					elem = set_pop(outputs)
+					result = string_join(string_join(string_join(string_join("O ", read_attribute(core, elem, "name")), " "), read_attribute(core, readAssociationDestination(core, elem), "name")), "\n")
+
+				return result!
+			else:
+				return "Permission denied to transformation: " + transformation_name!
+		else:
+			return "Model is not a transformation: " + transformation_name!
+	else:
+		return "No such transformation: " + transformation_name!
+	
+String function cmd_element_list_nice(user_id : String, model_name : String):
+	if (get_model_id(model_name) != ""):
+		if (allow_read(user_id, get_model_id(model_name))):
+			return "Success: " + JSON_print(get_full_model(get_model_id(model_name)))!
+		else:
+			return "Permission denied to model: " + model_name!
+	else:
+		return "No such model: " + model_name!
+
 Void function user_function_skip_init(user_id : String):
 	String cmd
 	String result
@@ -1815,6 +1865,12 @@ Void function user_function_skip_init(user_id : String):
 			output(cmd_admin_demote(user_id, single_input("User name?")))
 		elif (cmd == "service_register"):
 			output(cmd_service_register(user_id, single_input("Service name?")))
+		elif (cmd == "user_password"):
+			output(cmd_user_password(user_id, single_input("User name?"), single_input("New password?")))
+		elif (cmd == "transformation_read_signature"):
+			output(cmd_transformation_signature(user_id, single_input("Transformation name?")))
+		elif (cmd == "element_list_nice"):
+			output(cmd_element_list_nice(user_id, single_input("Model name?")))
 		elif (cmd == "verbose"):
 			set_verbose(True)
 		elif (cmd == "quiet"):

+ 19 - 2
bootstrap/mini_modify.alc

@@ -222,8 +222,8 @@ String function cmd_read_outgoing(model : Element, element_name : String, type :
 	String result
 	Element elems
 
-	result = "Success: "
 	if (dict_in(model["model"], element_name)):
+		result = "Success: "
 		elems = allOutgoingAssociationInstances(model, element_name, type)
 		while (read_nr_out(elems) > 0):
 			result = string_join(result, set_pop(elems)) + "\n"
@@ -235,8 +235,8 @@ String function cmd_read_incoming(model : Element, element_name : String, type :
 	String result
 	Element elems
 
-	result = "Success: "
 	if (dict_in(model["model"], element_name)):
+		result = "Success: "
 		elems = allIncomingAssociationInstances(model, element_name, type)
 		while (read_nr_out(elems) > 0):
 			result = string_join(result, set_pop(elems)) + "\n"
@@ -244,6 +244,21 @@ String function cmd_read_incoming(model : Element, element_name : String, type :
 	else:
 		return "Element not found: " + element_name!
 
+String function cmd_connections_between(model : Element, source_name : String, target_name : String):
+	String result
+	Element options
+
+	if (dict_in(model["model"], source_name)):
+		if (dict_in(model["model"], target_name)):
+			result = "Success: "
+			options = allowedAssociationsBetween(model, source_name, target_name)
+			while (read_nr_out(options) > 0):
+				result = string_join(result, set_pop(options)) + "\n"
+		else:
+			return ("Element not found: " + target_name)!
+	else:
+		return ("Element not found: " + source_name)!
+
 String function cmd_read(model : Element, element_name : String):
 	String result
 	Element attr_list
@@ -367,6 +382,8 @@ Element function modify(model : Element, write : Boolean):
 			output(cmd_read_association_source(write, model, single_input("Name?")))
 		elif (cmd == "read_association_destination"):
 			output(cmd_read_association_destination(write, model, single_input("Name?")))
+		elif (cmd == "connections_between"):
+			output(cmd_connections_between(model, single_input("Source element?"), single_input("Target element?")))
 		else:
 			output("Unknown command while modelling: " + cast_v2s(cmd))
 			output("Use command 'help' to get a list of available commands")