|
@@ -1,11 +1,15 @@
|
|
|
include "modelling.alh"
|
|
|
include "library.alh"
|
|
|
+include "primitives.alh"
|
|
|
+include "constructors.alh"
|
|
|
+include "object_operations.alh"
|
|
|
|
|
|
Element core = ?
|
|
|
|
|
|
Void function main():
|
|
|
// Initialize the Core Formalism
|
|
|
String core_location
|
|
|
+ String core_model
|
|
|
String admin_group
|
|
|
String admin_user
|
|
|
|
|
@@ -20,7 +24,8 @@ Void function main():
|
|
|
|
|
|
// Create admin user
|
|
|
admin_user = instantiate_node(core, "User", "")
|
|
|
- instantiate_attribute(core, admin_user, "name", get_username())
|
|
|
+ output("Desired username for admin user?")
|
|
|
+ instantiate_attribute(core, admin_user, "name", input())
|
|
|
instantiate_attribute(core, admin_user, "admin", True)
|
|
|
|
|
|
// Create link between admin user and group
|
|
@@ -41,7 +46,7 @@ Void function main():
|
|
|
// This accesses the bootstrap level, so do not change this unless you know what you are doing
|
|
|
Element root
|
|
|
root = read_root()
|
|
|
- dict_del(root["__hierarchy"], "__IP")
|
|
|
+ dict_delete(root["__hierarchy"], "__IP")
|
|
|
dict_add(root["__hierarchy"], "__IP", user_function)
|
|
|
|
|
|
// Call this for ourselves as well
|
|
@@ -53,18 +58,18 @@ Void function main():
|
|
|
return !
|
|
|
|
|
|
Integer function get_relation_to_model(user_id : String, model_id : String):
|
|
|
- if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
|
|
|
- // We are the owner
|
|
|
- return 0!
|
|
|
+ if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
|
|
|
+ // We are the owner
|
|
|
+ return 0!
|
|
|
+ else:
|
|
|
+ String group_id
|
|
|
+ group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
|
|
|
+ if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
|
|
|
+ // We are in the owning group
|
|
|
+ return 1!
|
|
|
else:
|
|
|
- String group_id
|
|
|
- group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
|
|
|
- if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
|
|
|
- // We are in the owning group
|
|
|
- return 1!
|
|
|
- else:
|
|
|
- // We are not related whatsoever
|
|
|
- return 2!
|
|
|
+ // We are not related whatsoever
|
|
|
+ return 2!
|
|
|
|
|
|
Boolean function is_admin(user_id : String):
|
|
|
if (read_attribute(core, user_id, "admin")):
|
|
@@ -109,18 +114,32 @@ Boolean function allow_change_metadata(user_id : String, model_id : String):
|
|
|
else:
|
|
|
return False!
|
|
|
|
|
|
-Void function user_function():
|
|
|
- // Now the username is bound to the task ID, so there is no problem
|
|
|
- // TODO check whether username isn't registered yet
|
|
|
+Void function check_login(user_id : String):
|
|
|
+ // TODO
|
|
|
+ return !
|
|
|
|
|
|
- // Add user to Core Formalism
|
|
|
+Element function user_function():
|
|
|
+ String username
|
|
|
String user_id
|
|
|
- user_id = instantiate_node(core, "User", "")
|
|
|
- instantiate_attribute(core, user_id, "name", get_username())
|
|
|
- instantiate_attribute(core, user_id, "admin", False)
|
|
|
|
|
|
- // Now call with user created
|
|
|
- user_function_skip_init(user_id)
|
|
|
+ output("Log on as which user?")
|
|
|
+ output("non-existing user will be created")
|
|
|
+
|
|
|
+ username = input()
|
|
|
+
|
|
|
+ user_id = get_user_id(username)
|
|
|
+ if (user_id == ""):
|
|
|
+ // New user
|
|
|
+ // Add user to Core Formalism
|
|
|
+ user_id = instantiate_node(core, "User", "")
|
|
|
+ instantiate_attribute(core, user_id, "name", username)
|
|
|
+ instantiate_attribute(core, user_id, "admin", False)
|
|
|
+
|
|
|
+ // Now call with user created
|
|
|
+ user_function_skip_init(user_id)
|
|
|
+ else:
|
|
|
+ if (check_login(user_id)):
|
|
|
+ user_function_skip_init(user_id)
|
|
|
|
|
|
// User destroyed already, so just stop execution
|
|
|
return !
|
|
@@ -137,7 +156,7 @@ String function get_model_id(name : String):
|
|
|
|
|
|
return ""!
|
|
|
|
|
|
-Void function user_function_skip_init(user_id : String)
|
|
|
+Void function user_function_skip_init(user_id : String):
|
|
|
Boolean do_continue
|
|
|
String cmd
|
|
|
|
|
@@ -158,6 +177,7 @@ Void function user_function_skip_init(user_id : String)
|
|
|
output(" model_list_full -- List all models with full info")
|
|
|
output("")
|
|
|
output("Transformation-specific operations")
|
|
|
+ output(" transformation_add_MT_language -- TODO")
|
|
|
output(" transformation_add_MT -- TODO")
|
|
|
output(" transformation_add_AL -- TODO")
|
|
|
output(" transformation_source_add -- TODO")
|
|
@@ -172,7 +192,7 @@ Void function user_function_skip_init(user_id : String)
|
|
|
output(" permission_group -- Change model group")
|
|
|
output("")
|
|
|
output("Group operations")
|
|
|
- output(" group_create -- Create a group"))
|
|
|
+ output(" group_create -- Create a group")
|
|
|
output(" group_delete -- Delete a group")
|
|
|
output(" group_owner_add -- Add group owner")
|
|
|
output(" group_owner_delete -- Remove group owner")
|
|
@@ -269,7 +289,7 @@ Void function user_function_skip_init(user_id : String)
|
|
|
m = set_pop(models)
|
|
|
output((" " + (read_attribute(core, m, "name")) + " : ") + read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))
|
|
|
|
|
|
- elif (cmd == "model_list_full")
|
|
|
+ elif (cmd == "model_list_full"):
|
|
|
// List all models with full info
|
|
|
Element models
|
|
|
String m
|
|
@@ -290,6 +310,87 @@ Void function user_function_skip_init(user_id : String)
|
|
|
type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
|
|
|
output(((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + size) + " ") + name) + " : ") + type)
|
|
|
|
|
|
+ elif (cmd == "transformation_add_MT_language"):
|
|
|
+ // Create a model transformation language from a set of input and output formalisms
|
|
|
+ String name
|
|
|
+ String model_id
|
|
|
+ Element source
|
|
|
+ Element target
|
|
|
+ Element all_formalisms
|
|
|
+ Element merged_formalism
|
|
|
+ String old_type_id
|
|
|
+ String type_id
|
|
|
+
|
|
|
+ source = create_node()
|
|
|
+ target = create_node()
|
|
|
+ old_type_id = ""
|
|
|
+
|
|
|
+ output("Source formalisms (terminate with empty string)?")
|
|
|
+ name = input()
|
|
|
+ while (name != ""):
|
|
|
+ model_id = get_model_id(name)
|
|
|
+ if (model_id != ""):
|
|
|
+ if (allow_read(user_id, model_id)):
|
|
|
+ type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
|
|
|
+ if (bool_or(old_type_id == "", type_id == old_type_id)):
|
|
|
+ set_add(source, model_id)
|
|
|
+ set_add(all_formalisms, create_tuple(name, model_id))
|
|
|
+ old_type_id = type_id
|
|
|
+ elif (old_type_id != type_id):
|
|
|
+ // Already have a previous type_id and now another: CLASH
|
|
|
+ output("Cannot add model as types not compatible with previous models; try again")
|
|
|
+ else:
|
|
|
+ output("Model not readable; try again")
|
|
|
+ name = input()
|
|
|
+ else:
|
|
|
+ output("No such model; try again")
|
|
|
+
|
|
|
+ output("Target formalisms (terminate with empty string)?")
|
|
|
+ name = input()
|
|
|
+ while (name != ""):
|
|
|
+ model_id = get_model_id(name)
|
|
|
+ if (model_id != ""):
|
|
|
+ if (allow_read(user_id, model_id)):
|
|
|
+ type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
|
|
|
+ if (bool_or(old_type_id == "", type_id == old_type_id)):
|
|
|
+ set_add(target, model_id)
|
|
|
+ if (bool_not(set_in(source, model_id))):
|
|
|
+ set_add(all_formalisms, create_tuple(name, model_id))
|
|
|
+ old_type_id = type_id
|
|
|
+ elif (old_type_id != type_id):
|
|
|
+ // Already have a previous type_id and now another: CLASH
|
|
|
+ output("Cannot add model as types not compatible with previous models; try again")
|
|
|
+ else:
|
|
|
+ output("Model not readable; try again")
|
|
|
+ name = input()
|
|
|
+ else:
|
|
|
+ output("No such model; try again")
|
|
|
+
|
|
|
+ if (read_nr_out(source) > 0):
|
|
|
+ if (read_nr_out(target) > 0):
|
|
|
+ output("Name of the new tranformation?")
|
|
|
+ name = input()
|
|
|
+ if (get_model_id(name) == ""):
|
|
|
+ // New location is available, so write
|
|
|
+ merged_formalism = model_fuse(all_formalisms)
|
|
|
+
|
|
|
+ location = "/models/" + cast_id2s(merged_formalism)
|
|
|
+ export_node(merged_formalism, location)
|
|
|
+
|
|
|
+ // Manage meta-info
|
|
|
+ new_model_id = instantiate_node(core, "Model", "")
|
|
|
+ instantiate_attribute(core, new_model_id, "name", name)
|
|
|
+ instantiate_attribute(core, new_model_id, "location", location)
|
|
|
+ instantiate_attribute(core, new_model_id, "permissions", "200")
|
|
|
+ instantiate_link(core, "owner", "", new_model_id, user_id)
|
|
|
+ instantiate_link(core, "instanceOf", "", new_model_id, type_id)
|
|
|
+ else:
|
|
|
+ output("Model already exists!")
|
|
|
+ else:
|
|
|
+ output("At least one target formalism is required")
|
|
|
+ else:
|
|
|
+ output("At least one source formalism is required")
|
|
|
+
|
|
|
elif (cmd == "permission_modify"):
|
|
|
String permissions
|
|
|
String model_id
|
|
@@ -419,7 +520,6 @@ Void function user_function_skip_init(user_id : String)
|
|
|
instantiate_link(core, "belongsTo", "", user_id, group_id)
|
|
|
|
|
|
output("New owner added to group!")
|
|
|
-
|
|
|
else:
|
|
|
output("User is already an owner!")
|
|
|
else:
|
|
@@ -574,4 +674,4 @@ Void function user_function_skip_init(user_id : String)
|
|
|
model_delete_element(core, user_id)
|
|
|
output("Goodbye!")
|
|
|
|
|
|
- return !
|
|
|
+ return create_node()!
|