123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- include "modelling.alh"
- include "library.alh"
- include "primitives.alh"
- include "constructors.alh"
- include "object_operations.alh"
- include "mini_modify.alh"
- include "model_management.alh"
- include "ramify.alh"
- Element core = ?
- Void function main():
- // Initialize the Core Formalism
- String core_location
- String core_model
- String admin_group
- String admin_user
- core_location = "models/CoreFormalism"
- // Create the Model itself and make public
- core = instantiate_model(import_node(core_location))
- // Create admin group
- admin_group = instantiate_node(core, "Group", "")
- instantiate_attribute(core, admin_group, "name", "admin")
- // Create admin user
- admin_user = instantiate_node(core, "User", "")
- 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
- instantiate_link(core, "ownedBy", "", admin_group, admin_user)
- instantiate_link(core, "belongsTo", "", admin_user, admin_group)
- // Add the core formalism already
- core_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, core_model, "name", "CoreFormalism")
- instantiate_attribute(core, core_model, "location", core_location)
- instantiate_attribute(core, core_model, "permissions", "220")
- // Make necessary links for the formalism to the owners
- instantiate_link(core, "group", "", core_model, admin_group)
- instantiate_link(core, "owner", "", core_model, admin_user)
- // Switch all new users to the user_function
- // This accesses the bootstrap level, so do not change this unless you know what you are doing
- Element root
- root = read_root()
- dict_delete(root["__hierarchy"], "__IP")
- dict_add(root["__hierarchy"], "__IP", user_function)
- // Call this for ourselves as well
- user_function_skip_init(admin_user)
- // Done, so finish up
- // Admin user will have been deleted by the user_function as usual
- // Note that if there are no admin users left, it will be very difficult to manage, as nobody will have admin permissions!
- 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!
- 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!
- Boolean function is_admin(user_id : String):
- if (read_attribute(core, user_id, "admin")):
- return True!
- else:
- return False!
-
- Boolean function allow_read(user_id : String, model_id : String):
- if (is_admin(user_id)):
- // Is admin, so always allow
- return True!
- else:
- // Check permissions
- String permission
- permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
- if (bool_or(permission == "1", permission == "2")):
- return True!
- else:
- return False!
- Boolean function allow_write(user_id : String, model_id : String):
- if (is_admin(user_id)):
- // Is admin, so always allow
- return True!
- else:
- // Check permissions
- String permission
- permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
- if (permission == "2"):
- return True!
- else:
- return False!
- Boolean function allow_change_metadata(user_id : String, model_id : String):
- if (is_admin(user_id)):
- // Is admin, so always allow
- return True!
- else:
- if (get_relation_to_model(user_id, model_id) == 0):
- // Only owner can chmod
- return True!
- else:
- return False!
- Boolean function allow_group_modify(user_id : String, group_id : String):
- if (is_admin(user_id)):
- // Is admin, so always allow
- return True!
- else:
- if (read_nr_out(set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))) > 0):
- // We are an owner
- return True!
- else:
- return False!
- Boolean function check_login(user_id : String):
- // TODO
- return False!
- Element function user_function():
- String username
- String 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 create_node()!
- String function get_model_id(name : String):
- Element models
- String model
- models = allInstances(core, "Model")
- while (read_nr_out(models) > 0):
- model = set_pop(models)
- if (value_eq(name, read_attribute(core, model, "name"))):
- return model!
-
- return ""!
- String function get_user_id(name : String):
- Element users
- String user
- users = allInstances(core, "User")
- while (read_nr_out(users) > 0):
- user = set_pop(users)
- if (value_eq(read_attribute(core, user, "name"), name)):
- return user!
-
- return ""!
- String function get_group_id(name : String):
- Element groups
- String group
- groups = allInstances(core, "Group")
- while (read_nr_out(groups) > 0):
- group = set_pop(groups)
- if (value_eq(read_attribute(core, group, "name"), name)):
- return group!
-
- return ""!
- Void function model_create(model : Element, name : String, user_id : String, type_id : String):
- String location
- location = "/models/" + cast_id2s(model)
- export_node(model, location)
- // Manage meta-info
- model_id = instantiate_node(core, "Model", "")
- instantiate_attribute(core, model_id, "name", name)
- instantiate_attribute(core, model_id, "location", location)
- instantiate_attribute(core, model_id, "permissions", "200")
- instantiate_link(core, "owner", "", model_id, user_id)
- instantiate_link(core, "instanceOf", "", model_id, type_id)
- return!
- Void function model_overwrite(model : Element, name : String):
- String location
- String model_id
- location = "/models/" + cast_id2s(model)
- export_node(model, location)
- model_id = get_model_id(name)
- // Change location in meta-data
- unset_attribute(core, model_id, "location")
- instantiate_attribute(core, model_id, "location", location)
- return!
- Void function user_function_skip_init(user_id : String):
- Boolean do_continue
- String cmd
- do_continue = True
- output("Welcome to the Model Management Interface v2.0!")
- output("Use the 'help' command for a list of possible commands")
- while (do_continue):
- output("Ready for command...")
- cmd = input()
- if (cmd == "help"):
- output("Model operations")
- output(" model_add -- Add a new model")
- output(" model_modify -- Modify an existing model")
- output(" model_delete -- [TODO] Delete a model and all related transformations")
- output(" model_list -- List all models")
- output(" model_list_full -- List all models with full info")
- output(" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata")
- output("")
- output("Transformation-specific operations")
- output(" transformation_add_MT_language -- Create a RAMified metamodel")
- output(" transformation_reRAMify -- RAMify a merged metamodel again")
- output(" transformation_add_MT -- Initialize a new model transformation")
- output(" transformation_add_AL -- TODO")
- output(" transformation_execute -- TODO")
- output("")
- output("Model permission operations")
- output(" permission_modify -- Change model permissions")
- output(" permission_owner -- Change model owner")
- output(" permission_group -- Change model group")
- output("")
- output("Group operations")
- 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")
- output(" group_join -- Add someone to your group")
- output(" group_kick -- Kick someone from your group")
- output(" group_list -- List all groups you are a member of")
- output("")
- output("Admin operations")
- output(" admin_promote -- Promote a user to admin status")
- output(" admin_demote -- Demote a user to normal status")
- output("")
- output("General operations")
- output(" account_delete -- Remove current user and revoke all permissions ")
- elif (cmd == "model_add"):
- // Model addition operation, which uses model upload commands of the compiler
- String name
- String type
- String location
- String type_id
- Element new_model
- String new_model_id
- output("Creating new model!")
- output("Model type?")
- type_id = get_model_id(input())
- if (type_id != ""):
- // Type exists
- if (allow_read(user_id, type_id)):
- // And is readable
- output("Model name?")
- name = input()
- if (get_model_id(name) == ""):
- // Model doesn't exist yet
- output("Waiting for model constructors...")
- // TODO Update construct_model call to this interface
- new_model = construct_model(import_node(read_attribute(core, type_id, "location")))
- model_create(new_model, name, user_id, type_id)
- output("Model upload success!")
- else:
- output("Model with that name already exists!")
- else:
- output("You are not allowed to read this type model!")
- else:
- output("Could not find type model!")
- elif (cmd == "transformation_execute"):
- // Execute a transformation, whatever type it is
- // First we detect the type, so we know how to prepare for invocation
- String transformation_id
- String exact_type
- Element sources
- Element targets
- String source
- String target
- String name_id
- output("Which transformation do you want to execute?")
- transformation_id = get_model_id(input())
- if (transformation_id != ""):
- if (allow_read(user_id, transformation_id)):
- if (is_nominal_instance(core, transformation_id, "Transformation")):
- // Read out source and target links
- sources = readOutgoingAssociationInstances(core, transformation_id, "transformInput")
- inputs = create_node()
- while (read_nr_out(source) > 0):
- source = set_pop(sources)
- output(string_join("Which model to bind for source element ", read_attribute(core, source, "name")))
- name_id = get_model_id(input())
- if (name_id != ""):
- if (allow_read(user_id, name_id)):
- dict_add(inputs, read_attribute(core, source, "name"), name_id)
- else:
- output("Permission denied")
- set_add(sources, source)
- else:
- output("No such model")
- set_add(sources, source)
- targets = readOutgoingAssociationInstances(core, transformation_id, "transformOutput")
- outputs = create_node()
- while (read_nr_out(targets) > 0):
- target = set_pop(targets)
- output(string_join("Which model to create for target element ", read_attribute(core, target, "name")))
- name_id = get_model_id(input())
- dict_add(outputs, read_attribute(core, target, "name"), name_id)
- exact_type = read_type(core, transformation_id)
- if (exact_type == "ModelTransformation"):
- // Model transformation is always in-place and uses only a single metamodel
- // Therefore, we must:
- // 1) Create an empty model, instance of merged metamodel
- // 2) Merge the different source models and retype
- // 3) Perform the transformation on the merged model
- // 4) Split the resulting model based on the target formalisms
- //
- // There is one exception: if the target model is bound to a source model, that model is overwritten
- // This allows for some optimizations when it is a simple in-place transformation (skip model copy, join, and split)
- // First check for this exception, as it is much faster
- Element input_model
- Element schedule_model
- schedule_model = import_node(read_attribute(core, transformation_id, "location"))
- if (bool_and(bool_and(read_nr_out(inputs) == 1, read_nr_out(outputs) == 1), set_equality(inputs, outputs))):
- // inputs and outputs have the same values and there is only one: keep in-place without additional bookkeeping
- input_model = import_node(read_attribute(core, set_pop(inputs), "location"))
- transform(input_model, schedule_model)
- else:
- // Need to fall back to the default approach, which is way slower
- // 1) Create empty instance of merged metamodel
- trace_links = allOutgoingAssociationInstances(core, transformation_id, "tracability")
- ramified_metamodel = ""
- while (read_nr_out(trace_links) > 0):
- trace_link_id = set_pop(trace_links)
- if (read_attribute(core, trace_link_id, "type") == "ramified"):
- ramified_metamodel = readAssociationDestination(core, trace_link_id)
- if (ramified_metamodel != ""):
- merged_model = instantiate_model(import_node(merged_metamodel))
- // 2) Merge source models
- String key
- Element keys
- input_keys = dict_keys(inputs)
- while (read_nr_out(input_keys) > 0):
- key = set_pop(input_keys)
- model = import_node(read_attribute(core, inputs[key], "location"))
- model_join(merged_model, model, key)
- // 3) Transform
- transform(merged_model, schedule_model)
- // 4) Split in different files depending on type
- output_keys = dict_keys(outputs)
- while (read_nr_out(output_keys) > 0):
- key = set_pop(output_keys)
- desired_metamodel_id = followAssociation(core, outputs[key])
- desired_metamodel = import_node(read_attribute(core, desired_metamodel_id, "location"))
- split_off_model = model_split(merged_model, desired_metamodel, key)
- // 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)
- else:
- // Model exists, so we overwrite
- model_overwrite(split_off_model, outputs[key])
- else:
- output("Could not resolve intermediate merged metamodel")
- elif (exact_type == "ActionLanguage"):
- output("Not Implemented yet!)
- else:
- output("Did not know how to interpret model of type " + exact_type)
- else:
- output("Model is not an executable transformation")
- else:
- output("Permission denied")
- else:
- output("No such transformation")
- elif (cmd == "model_overwrite"):
- // Overwrites an existing model without changing any metadata
- output("Which model to overwrite?")
- model_id = get_model_id(input())
- if (model_id == ""):
- if (allow_write(user_id, model_id)):
- if (allow_read(user_id, followAssociation(core, model_id, "instanceOf"))):
- output("Waiting for model constructors...")
- new_model = construct_model(import_node(read_attribute(core, followAssociation(core, model_id, "instanceOf"), "location")))
- model_overwrite(new_model, model_id)
- output("Model overwrite success!")
- else:
- output("Permission denied")
- else:
- output("Permission denied")
- else:
- output("No such model")
- elif (cmd == "model_modify"):
- // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
- String model_id
- String type_id
- output("Which model do you want to modify?")
- model_id = get_model_id(input())
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
- if (allow_read(user_id, type_id)):
- modify(import_node(read_attribute(core, model_id, "location")), allow_write(user_id, model_id))
- else:
- output("You are not allowed to read the type model!")
- else:
- output("You are not allowed to read this model!")
- else:
- output("Could not find model!")
- elif (cmd == "model_delete"):
- // Delete a model and all of its related transformations
- String model_id
- output("=================================================")
- output("WARNING: Deletion is a very destructive operation")
- output(" as it also deletes all transformations ")
- output(" defined which make use of this model! ")
- output("=================================================")
- output("")
- output("Currently not supported!")
- elif (cmd == "model_list"):
- // List all models
- Element models
- String m
- models = allInstances(core, "Model")
- while (read_nr_out(models) > 0):
- m = set_pop(models)
- output(string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")))
- elif (cmd == "model_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, "Model")
- 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) + " ") + 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
- Element ramified_formalism
- String old_type_id
- String type_id
- String location
- String new_model_id
- source = create_node()
- target = create_node()
- old_type_id = ""
- // Read involved formalisms
- output("Formalisms to include (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(all_formalisms, create_tuple(name, import_node(read_attribute(core, model_id, "location"))))
- 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")
- else:
- output("No such model; try again")
-
- name = input()
- // Merge both into a single metamodel
- if (read_nr_out(source) > 0):
- if (read_nr_out(target) > 0):
- output("Name of the RAMified tranformation metamodel?")
- name = input()
- if (get_model_id(name) == ""):
- String merged_formalism_id
- String ramified_formalism_id
- String source_formalism_id
- String tracability_link
- // 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", "")
- merged_formalism_id = new_model_id
- instantiate_attribute(core, new_model_id, "name", "__merged_" + 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)
- // Add tracability links at this level
- while (read_nr_out(all_formalisms) > 0):
- source_formalism_id = list_read(set_pop(all_formalisms), 1)
- tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
- instantiate_attribute(core, tracability_link, "type", "merged")
- // Merge complete, now RAMify!
- ramified_formalism = ramify(merged_formalism)
- location = "/models/" + cast_id2s(ramified_formalism)
- export_node(ramified_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)
- // Add tracability link at this level
- tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
- instantiate_attribute(core, tracability_link, "type", "RAMified")
- 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 == "transformation_reRAMify"):
- String model_id
- String source_id
- Element trace_links
- String trace_link
- String merged_model_id
- Element new_model
- String location
- output("Merged metamodel to RAMify again?")
- model_id = get_model_id(input())
- if (model_id != ""):
- if (allow_write(user_id, model_id)):
- // We must be able to write the RAMification model, as we will update it in-place
- trace_links = allOutgoingAssociationInstances(core, model_id, "tracability")
- merged_model_id = ""
- while (read_nr_out(trace_links) > 0):
- trace_link = set_pop(trace_links)
- if (value_eq(read_attribute(core, trace_link, "type"), "RAMified")):
- // Found a RAMification link, so redo it on the original model
- merged_model_id = readAssociationDestination(core, trace_link)
- if (merged_model_id != ""):
- new_model = ramify(core["model"][merged_model_id])
- location = "/models/" + cast_id2s(new_model)
- export_node(new_model, location)
- // Update meta-info
- unset_attribute(core, model_id, "location")
- instantiate_attribute(core, model_id, "location", location)
- else:
- output("Could not determine original model of RAMified metamodel!")
- else:
- output("Permission denied")
- else:
- output("No such model")
- elif (cmd == "transformation_add_MT"):
- // Add a model transformation model
- // Just a usual model instantiation, but need to add the source and target links based on user info
- String ramified_metamodel_id
- String model_id
- Element models
- Element links
- String link_id
- Element supported
- Element source
- Element target
- String name
- String new_model_id
- source = create_node()
- target = create_node()
- supported = create_node()
- output("RAMified metamodel to use?")
- ramified_metamodel_id = get_model_id(input())
- if (ramified_metamodel_id != ""):
- if (allow_read(user_id, ramified_metamodel_id)):
- output("Supported metamodels:")
- links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
- while (read_nr_out(links) > 0):
- link_id = set_pop(linkss)
- if (value_eq(read_attribute(core, link_id, "type"), "merged")):
- output(string_join(" ", read_attribute(core, readAssociationDestination(core, link_id), "name")))
- set_add(supported, readAssociationDestination(core, link_id))
- output("")
- output("Which ones do you want to use as source (empty string to finish)?")
- name = input()
- while (name != ""):
- model_id = get_model_id(name)
- if (model_id != ""):
- if (set_in(supported, model_id)):
- if (bool_not(set_in(source, model_id))):
- set_add(source, model_id)
- output("Model added as source")
- else:
- output("Model already selected as source")
- else:
- output("Model is not supported by RAMified metamodel!")
- else:
- output("No such model; try again")
-
- name = input()
- output("Which ones do you want to use as target (empty string to finish)?")
- name = input()
- while (name != ""):
- model_id = get_model_id(name)
- if (model_id != ""):
- if (set_in(supported, model_id)):
- if (bool_not(set_in(target, model_id))):
- set_add(target, model_id)
- output("Model added as target")
- else:
- output("Model already selected as target")
- else:
- output("Model is not supported by RAMified metamodel!")
- else:
- output("No such model; try again")
-
- name = input()
- output("Name of new transformation?")
- name = input()
- if (get_model_id(name) == ""):
- // Finished with all information, now create the model itself!
- new_model = instantiate_model(import_node(read_attribute(core, ramified_model_id, "location")))
- location = "/models/" + cast_id2s(new_model)
- export_node(new_model, location)
- // Manage meta-info
- new_model_id = instantiate_node(core, "ModelTransformation", "")
- 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, ramified_model_id)
- while (read_nr_out(source) > 0):
- instantiate_link(core, "transformInput", "", new_model_id, set_pop(source))
- while (read_nr_out(target) > 0):
- instantiate_link(core, "transformOutput", "", new_model_id, set_pop(target))
- output("Meta-info correctly set!")
- else:
- output("Model already exists")
- else:
- output("Permission denied")
- else:
- output("No such model")
- elif (cmd == "permission_modify"):
- String permissions
- Integer permission
- String model_id
- output("Which model do you want to change permissions of?")
- model_id = get_model_id(input())
- if (model_id != ""):
- if (get_relation_to_model(user_id, model_id) == 0):
- output("New permissions?")
- permissions = input()
- Boolean fail
- Integer i
- i = 0
- if (string_len(permissions) != 3):
- fail = True
- while (bool_and(bool_not(fail), i < 3)):
- permission = cast_s2i(string_get(permissions, i))
- if (bool_or(permission < 0, permission > 2)):
- fail = True
- if (bool_not(fail)):
- unset_attribute(core, model_id, "permissions")
- instantiate_attribute(core, model_id, "permissions", permissions)
- else:
- output("Permissions must be a string of three characters with each character being a digit between 0 and 2")
- else:
- output("Permission denied!")
- else:
- output("No such model!")
-
- elif (cmd == "permission_owner"):
- String permissions
- String model_id
- String user_id
- output("Which model do you want to change owner of?")
- model_id = get_model_id(input())
- if (model_id != ""):
- if (get_relation_to_model(user_id, model_id) == 0):
- output("New owner?")
- user_id = get_user_id(input())
- if (user_id != ""):
- model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
- instantiate_link(core, "owner", "", model_id, user_id)
- else:
- output("No such user!")
- else:
- output("Permission denied!")
- else:
- output("No such model!")
- elif (cmd == "permission_group"):
- String permissions
- String model_id
- String group_id
- output("Which model do you want to change permissions of?")
- model_id = get_model_id(input())
- if (model_id != ""):
- if (get_relation_to_model(user_id, model_id) == 0):
- output("New group?")
- group_id = get_group_id(input())
- if (group_id != ""):
- model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
- instantiate_link(core, "group", "", model_id, group_id)
- else:
- output("No such group!")
- else:
- output("Permission denied!")
- else:
- output("No such model!")
- elif (cmd == "group_create"):
- // Create a new group and become its owner
- String group_id
- String name
- output("Which group do you want to create?")
- name = input()
- group_id = get_group_id(name)
- if (group_id == ""):
- group_id = instantiate_node(core, "Group", "")
- instantiate_attribute(core, group_id, "name", name)
- instantiate_link(core, "belongsTo", "", user_id, group_id)
- instantiate_link(core, "owner", "", group_id, user_id)
- output("Group created!")
- else:
- output("Group already exists")
- elif (cmd == "group_delete"):
- // Delete an existing group
- String group_id
- String name
- output("Which group do you want to delete?")
- name = input()
- group_id = get_group_id(name)
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- model_delete_element(core, group_id)
- else:
- output("Permission denied")
- else:
- output("No such group")
- elif (cmd == "group_owner_add"):
- // Add an owner to your group
- String group_id
- String other_user_id
- output("Which group do you want to add an owner to?")
- group_id = get_group_id(input())
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- output("Which user do you want to make an owner?")
- other_user_id = get_user_id(input())
- if (other_user_id != ""):
- Element overlap
- overlap = set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
- if (read_nr_out(overlap) == 0):
- instantiate_link(core, "owner", "", group_id, user_id)
- overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) == 0):
- instantiate_link(core, "belongsTo", "", user_id, group_id)
- output("New owner added to group!")
- else:
- output("User is already an owner!")
- else:
- output("No such user")
- else:
- output("Permission denied!")
- else:
- output("No such group")
- elif (cmd == "group_owner_delete"):
- // Remove an owner from your group
- String group_id
- String other_user_id
- output("Which group do you want to disown someone from?")
- group_id = get_group_id(input())
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- output("Which user do you want to disown?")
- other_user_id = get_user_id(input())
- if (other_user_id != ""):
- Element overlap
- overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) > 0):
- overlap = set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
- if (read_nr_out(overlap) > 0):
- model_delete_element(core, set_pop(overlap))
- output("Disowned group from user!")
- else:
- output("User is not even an owner of the group!")
- else:
- output("User is not even a member of the group!")
- else:
- output("No such user")
- else:
- output("Permission denied!")
- else:
- output("No such group")
- elif (cmd == "group_join"):
- // Add someone to your group
- String group_id
- String other_user_id
- output("Which group do you want to add someone to?")
- group_id = get_group_id(input())
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- output("Which user do you want to add?")
- other_user_id = get_user_id(input())
- if (other_user_id != ""):
- Element overlap
- overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) == 0):
- instantiate_link(core, "belongsTo", "", user_id, group_id)
- output("User added to the group!")
- else:
- output("User is already a member of the group!")
- else:
- output("No such user")
- else:
- output("Permission denied!")
- else:
- output("No such group")
- elif (cmd == "group_kick"):
- // Remove someone from your group
- String group_id
- String other_user_id
- output("Which group do you want to kick someone from?")
- group_id = get_group_id(input())
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- output("Which user do you want to kick?")
- other_user_id = get_user_id(input())
- if (other_user_id != ""):
- Element overlap
- overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) > 0):
- model_delete_element(core, set_pop(overlap))
- // Check if user was an owner as well
- overlap = set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
- if (read_nr_out(overlap) > 0):
- model_delete_element(core, set_pop(overlap))
- output("User kicked!")
- else:
- output("User is not even a member of the group!")
- else:
- output("No such user")
- else:
- output("Permission denied!")
- else:
- output("No such group")
- elif (cmd == "group_list"):
- // List all groups you are a member of (and whether you are admin or not!)
- Element groups
- String group_id
- String admin
-
- groups = allAssociationDestinations(core, user_id, "belongsTo")
- while (True):
- group_id = set_pop(groups)
- if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
- admin = " A "
- else:
- admin = " "
- output(string_join(admin, read_attribute(core, group_id, "name")))
- elif (cmd == "admin_promote"):
- // Promote a user to admin status
- if (is_admin(user_id)):
- String other_user_id
- output("Which user do you want to promote?")
- other_user_id = get_user_id(input())
- if (other_user_id != ""):
- unset_attribute(core, other_user_id, "admin")
- instantiate_attribute(core, other_user_id, "admin", True)
- output("Permissions granted!")
- else:
- output("No such user!")
- else:
- output("Permission denied!")
- elif (cmd == "admin_demote"):
- // Demote a user to normal status
- if (is_admin(user_id)):
- String other_user_id
- output("Which user do you want to demote?")
- other_user_id = get_user_id(input())
- if (other_user_id != ""):
- unset_attribute(core, other_user_id, "admin")
- instantiate_attribute(core, other_user_id, "admin", False)
- output("Permissions revoked!")
- else:
- output("No such user!")
- else:
- output("Permission denied!")
- elif (cmd == "exit"):
- // Exit by actually removing the user and decoupling it from all of its models
- // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
- do_continue = False
- // Delete user from Core Formalism
- model_delete_element(core, user_id)
- output("Goodbye!")
- return !
|