1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780 |
- 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"
- include "conformance_scd.alh"
- include "transform.alh"
- include "metamodels.alh"
- Element core = ?
- String core_location = "models/CoreFormalism"
- String core_model_location = "core"
- Void function main():
- // Initialize the Core Formalism
- String core_model
- String core_formalism_model
- String scd_model
- Element al_model
- String admin_group
- String admin_user
- String nobody_group
- String instance_of
- String core_formalism
- Element scd
- Element al
- Element pm
- Element tracability
- String pm_model
- String tracability_model
- String coreM_model_location
- String pm_location
- String scd_location
- String al_location
- String tracability_location
- coreM_model_location = "models/core"
- pm_location = "models/ProcessModel"
- scd_location = "models/SimpleClassDiagrams"
- al_location = "models/ActionLanguage"
- tracability_location = "models/Tracability"
- scd = import_node(scd_location)
- al = import_node(al_location)
- pm = import_node(pm_location)
- tracability = import_node(tracability_location)
- // Create the Model itself and make public
- core_formalism = import_node(core_location)
- core = instantiate_model(core_formalism)
- export_node(core_model_location, core)
- export_node(coreM_model_location, core["model"])
- // 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
- Element prev
- root = read_root()
- root = root["__hierarchy"]["__IP"]
- while (value_neq(root, !call)):
- prev = root
- root = root["next"]
- dict_delete(prev, "next")
- dict_add(prev, "next", user_function["body"])
- // Create admin group
- admin_group = instantiate_node(core, "Group", "")
- instantiate_attribute(core, admin_group, "name", "admin")
- // Create nobody group
- nobody_group = instantiate_node(core, "Group", "")
- instantiate_attribute(core, nobody_group, "name", "nobody")
- // 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)
- String password
- while (True):
- output("Desired password for admin user?")
- password = hash(input())
- output("Please repeat the password")
- if (password == hash(input())):
- output("Passwords match!")
- instantiate_attribute(core, admin_user, "password", password)
- break!
- else:
- output("Not the same password, please try again!")
- // 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 SimpleClassDiagrams formalism already
- scd_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, scd_model, "name", "SimpleClassDiagrams")
- instantiate_attribute(core, scd_model, "location", scd_location + "/model")
- instantiate_attribute(core, scd_model, "permissions", "221")
- instance_of = instantiate_link(core, "instanceOf", "", scd_model, scd_model)
- instantiate_attribute(core, instance_of, "type_mapping", scd["type_mapping"])
- // Make necessary links for the formalism to the owners
- instantiate_link(core, "group", "", scd_model, admin_group)
- instantiate_link(core, "owner", "", scd_model, admin_user)
- // Add the Tracability formalism
- tracability_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, tracability_model, "name", "Tracability")
- instantiate_attribute(core, tracability_model, "location", tracability_location + "/model")
- instantiate_attribute(core, tracability_model, "permissions", "221")
- instance_of = instantiate_link(core, "instanceOf", "", tracability_model, scd_model)
- instantiate_attribute(core, instance_of, "type_mapping", tracability["type_mapping"])
- // Add the user/group links
- instantiate_link(core, "group", "", tracability_model, admin_group)
- instantiate_link(core, "owner", "", tracability_model, admin_user)
- // Add the Process Model formalism
- pm_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, pm_model, "name", "ProcessModel")
- instantiate_attribute(core, pm_model, "location", pm_location + "/model")
- instantiate_attribute(core, pm_model, "permissions", "221")
- instance_of = instantiate_link(core, "instanceOf", "", pm_model, scd_model)
- instantiate_attribute(core, instance_of, "type_mapping", pm["type_mapping"])
- // Make necessary links for the formalism to the owners
- instantiate_link(core, "group", "", pm_model, admin_group)
- instantiate_link(core, "owner", "", pm_model, admin_user)
- // Add the Action Language formalism
- al_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, al_model, "name", "ActionLanguage")
- instantiate_attribute(core, al_model, "location", al_location + "/model")
- instantiate_attribute(core, al_model, "permissions", "221")
- instance_of = instantiate_link(core, "instanceOf", "", al_model, scd_model)
- instantiate_attribute(core, instance_of, "type_mapping", al["type_mapping"])
- // Make necessary links for the formalism to the owners
- instantiate_link(core, "group", "", al_model, admin_group)
- instantiate_link(core, "owner", "", al_model, admin_user)
- // Add the Manual Operation formalism
- Element manual
- String manual_model
- manual = instantiate_model(scd)
- manual_model = instantiate_node(core, "Model", "")
- export_node("models/ManualOperation", manual)
- instantiate_attribute(core, manual_model, "name", "ManualOperation")
- instantiate_attribute(core, manual_model, "location", "models/ManualOperation/model")
- instantiate_attribute(core, manual_model, "permissions", "221")
- instance_of = instantiate_link(core, "instanceOf", "", manual_model, scd_model)
- instantiate_attribute(core, instance_of, "type_mapping", create_node())
- // Make necessary links for the formalism to the owners
- instantiate_link(core, "group", "", manual_model, admin_group)
- instantiate_link(core, "owner", "", manual_model, admin_user)
- // Add the core formalism already
- core_formalism_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, core_formalism_model, "name", "CoreFormalism")
- instantiate_attribute(core, core_formalism_model, "location", core_location + "/model")
- instantiate_attribute(core, core_formalism_model, "permissions", "221")
- instance_of = instantiate_link(core, "instanceOf", "", core_formalism_model, scd_model)
- instantiate_attribute(core, instance_of, "type_mapping", core_formalism["type_mapping"])
- // Make necessary links for the formalism to the owners
- instantiate_link(core, "group", "", core_formalism_model, admin_group)
- instantiate_link(core, "owner", "", core_formalism_model, admin_user)
- // Add the core model
- core_model = instantiate_node(core, "Model", "")
- instantiate_attribute(core, core_model, "name", "core")
- instantiate_attribute(core, core_model, "location", coreM_model_location)
- instantiate_attribute(core, core_model, "permissions", "200")
- instance_of = instantiate_link(core, "instanceOf", "", core_model, core_formalism_model)
- instantiate_attribute(core, instance_of, "type_mapping", core["type_mapping"])
- // 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)
- // Call this for ourselves as well
- log("MvC is ready!")
- 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 !
- String function get_instanceOf_link(model_id : String):
- Element all_links
- String choice
- all_links = allOutgoingAssociationInstances(core, model_id, "instanceOf")
- if (read_nr_out(all_links) > 1):
- log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
- elif (read_nr_out(all_links) == 0):
- log("ERROR: untyped model!")
-
- choice = set_pop(allOutgoingAssociationInstances(core, model_id, "instanceOf"))
- return choice!
- Element function get_full_model(model_id : String):
- Element m
- Element all_links
- String choice
- choice = get_instanceOf_link(model_id)
- m = create_node()
- dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
- dict_add(m, "type_mapping", read_attribute(core, choice, "type_mapping"))
- if (readAssociationDestination(core, choice) == model_id):
- // Found the meta-circular level, so we can stop!
- dict_add(m, "metamodel", m)
- else:
- dict_add(m, "metamodel", get_full_model(readAssociationDestination(core, choice)))
-
- return m!
- 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):
- String password
- String stored_password
- stored_password = read_attribute(core, user_id, "password")
- output("Password for existing user?")
- password = hash(input())
- return password == stored_password!
- Element function extract_ftg(user_id : String):
- // Extract your personal FTG, showing only the readable models that can be opened
- // This function does the actual projection of transformations
- // TODO: Only keep transformations satisfying some properties!
- return create_node()!
- Element function user_function():
- String username
- String user_id
- String password
- // Load in all global variables, as this code is hotloaded!
- Element root
- root = read_root()
- root = root["__hierarchy"]["objects"]
- exec(root["bootstrap/modelling.alc"]["initializers"])
- exec(root["bootstrap/library.alc"]["initializers"])
- exec(root["bootstrap/constructors.alc"]["initializers"])
- exec(root["bootstrap/object_operations.alc"]["initializers"])
- exec(root["core/mini_modify.alc"]["initializers"])
- exec(root["bootstrap/model_management.alc"]["initializers"])
- exec(root["bootstrap/ramify.alc"]["initializers"])
- exec(root["bootstrap/transform.alc"]["initializers"])
- exec(root["bootstrap/conformance_scd.alc"]["initializers"])
- exec(root["core/core_algorithm.alc"]["initializers"])
- // Load in a hard-reference to the previously created model
- core = import_node(core_model_location)
- output("Log on as which user?")
- 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)
- while (True):
- output("This is a new user: please give password!")
- password = hash(input())
- output("Please repeat the password")
- if (password == hash(input())):
- output("Passwords match!")
- output("User created")
- instantiate_attribute(core, user_id, "password", password)
- break!
- else:
- output("Not the same password, please try again!")
- // Now call with user created
- user_function_skip_init(user_id)
- else:
- while (bool_not(check_login(user_id))):
- output("Wrong password! Try again")
-
- user_function_skip_init(user_id)
- // User destroyed already, so just stop execution
- // TODO return a fresh node as otherwise the compiler doesn't take this
- 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, kind : String):
- String location
- String model_id
- String instance_of
- location = "models/" + cast_id2s(model)
- export_node(location, model["model"])
- // Manage meta-info
- 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")
- instantiate_link(core, "owner", "", model_id, user_id)
- instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
- instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
- instantiate_attribute(core, instance_of, "type_mapping", model["type_mapping"])
- return!
- Void function model_overwrite(model : Element, model_id : String):
- String location
- String instanceOf_link
- location = "models/" + cast_id2s(model)
- export_node(location, model["model"])
- // Change location in meta-data
- unset_attribute(core, model_id, "location")
- instantiate_attribute(core, model_id, "location", location)
- instanceOf_link = get_instanceOf_link(model_id)
- unset_attribute(core, instanceOf_link, "type_mapping")
- instantiate_attribute(core, instanceOf_link, "type_mapping", model["type_mapping"])
- return!
- Boolean function check_is_typed_by(model_id : String, metamodel_id : String):
- // TODO check if there is actually an instanceOf link between them
- // --> quick check!
- return True!
- Boolean function check_conformance(model_id : String):
- // TODO check if it actually conforms, considering that instanceOf link
- // --> in-depth check
- return True!
- Boolean function pm_finished(worklist : Element, pm : String):
- Element finished
- Integer cnt
- Integer i
- // Check if any of the "finish" elements are in the worklist
- // If so, we can already finish, and therefore will stop immediately
- finished = allInstances(pm, "Finish")
- i = 0
- cnt = read_nr_out(finished)
- while (i < cnt):
- // Check each finished element individually
- if (set_in(finished, dict_read(read_edge_dst(read_out(worklist, i)), 0))):
- return True!
- i = i + 1
- return False!
- Element function execute_operation(operation_id : String, input_models : Element, output_metamodels : Element, tracability_model : Element):
- // Operations are always in-place and uses only a single metamodel
- // Therefore, we must:
- // 1) Find merged metamodel
- // 2) Merge the different source models and retype
- // 3) Perform the operation on the merged model
- // 4) Split the resulting model based on the target formalisms; if operation successful
-
- Element input_model
- String trace_link_id
- Element merged_model
- String merged_metamodel_id
- String ramified_metamodel_id
- Boolean result
- String exact_type
- Element trace_links
- String linktype
- String model_ID
- String key
- Element keys
- Element input_keys
- Element output_keys
- Element model_tuples
- String metamodel_name
- Element metamodel
- String metamodel_ID
- Boolean tracability
- // 1) Find merged metamodel
- log("Find merged")
- exact_type = read_type(core, operation_id)
- if (exact_type == "ModelTransformation"):
- linktype = "RAMified"
- ramified_metamodel_id = set_pop(allAssociationDestinations(core, operation_id, "instanceOf"))
- trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
- elif (exact_type == "ManualOperation"):
- linktype = "operatesOn"
- trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
- elif (exact_type == "ActionLanguage"):
- linktype = "operatesOn"
- trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
- else:
- // Don't know how to execute this operation!
- return read_root()!
- merged_metamodel_id = ""
- while (read_nr_out(trace_links) > 0):
- trace_link_id = set_pop(trace_links)
- if (value_eq(read_attribute(core, trace_link_id, "type"), linktype)):
- merged_metamodel_id = readAssociationDestination(core, trace_link_id)
- if (merged_metamodel_id != ""):
- // 2) Merge source models
- log("Merge source")
- model_tuples = create_node()
- while (read_nr_out(input_models) > 0):
- model_ID = get_model_id(set_pop(input_models))
- input_model = get_full_model(model_ID)
- metamodel_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_ID, "instanceOf")), "name")
- set_add(model_tuples, create_tuple(metamodel_name, input_model))
- merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id), read_root())
- // 3) Transform
- log("Transform")
- log("Source model: " + pretty_print(merged_model))
- log("Types of merged: " + set_to_string(dict_keys(merged_model["metamodel"]["model"])))
- log("operation: " + pretty_print(get_full_model(operation_id)))
- if (exact_type == "ModelTransformation"):
- result = transform(merged_model, get_full_model(operation_id))
- elif (exact_type == "ManualOperation"):
- output("Please perform manual operation " + cast_v2s(read_attribute(core, operation_id, "name")))
- modify(merged_model, True)
- result = True
- elif (exact_type == "ActionLanguage"):
- Element func
- func = get_func_AL_model(get_full_model(operation_id))
- result = func(merged_model)
- else:
- log("ERROR")
- // 4) Split in different models depending on type
- log("Split")
- if (element_neq(tracability_model, read_root())):
- tracability = True
- else:
- tracability = False
- if (result):
- model_tuples = create_node()
- while (read_nr_out(output_metamodels) > 0):
- metamodel_ID = get_model_id(set_pop(output_metamodels))
- metamodel_name = read_attribute(core, metamodel_ID, "name")
- metamodel = get_full_model(metamodel_ID)
- set_add(model_tuples, create_tuple(metamodel_name, metamodel))
- result = model_split(merged_model, model_tuples, tracability)
- if (tracability):
- log("Trace")
- Element new_tracability_model
- new_tracability_model = result["__tracability"]
- dict_overwrite(tracability_model, "model", new_tracability_model["model"])
- dict_overwrite(tracability_model, "type_mapping", new_tracability_model["type_mapping"])
- dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
- dict_delete(result, "__tracability")
- log("Done")
- return result!
- else:
- return read_root()!
- else:
- output("Could not resolve intermediate merged metamodel")
- return read_root()!
- Boolean function enact_action(pm : Element, element : String, prefix : String, user_id : String):
- Boolean result
- String transformation_id
- Element lst
- String elem
- Element inputs
- Element outputs
- String type_name
- String exact_type
- Element trace_links
- Element output_mms
- Element consumes_link
- String name
- String value
- String elem_name
- Element keys
- String key
- inputs = create_node()
- outputs = create_node()
- // Read out the referenced element from the MvC
- transformation_id = get_model_id(read_attribute(pm, element, "name"))
- // Find all input model names
- lst = allOutgoingAssociationInstances(pm, element, "Consumes")
- while (read_nr_out(lst) > 0):
- value = read_attribute(pm, readAssociationDestination(pm, set_pop(lst)), "name")
- set_add(inputs, prefix + value)
- // Find all output model names and their metamodel
- lst = allAssociationDestinations(pm, element, "Produces")
- while (read_nr_out(lst) > 0):
- elem = set_pop(lst)
- type_name = read_attribute(pm, elem, "type")
- elem_name = read_attribute(pm, elem, "name")
- dict_add(outputs, type_name, prefix + elem_name)
- result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
- if (element_eq(result, read_root())):
- // Something went wrong!
- return False!
- else:
- keys = dict_keys(result)
- while (read_nr_out(keys) > 0):
- key = set_pop(keys)
- if (get_model_id(outputs[key]) == ""):
- // New model
- model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
- else:
- model_overwrite(result[key], get_model_id(outputs[key]))
- return result!
- Void function enact_PM(pm : Element, prefix : String, user_id : String):
- Element worklist
- String element
- String start
- String type
- Boolean result
- Element tuple
- Element counters
- Element join_nodes
- // Initialize Join counters
- counters = create_node()
- join_nodes = allInstances(pm, "Join")
- while (read_nr_out(join_nodes) > 0):
- dict_add(counters, set_pop(join_nodes), 0)
- // Create the worklist with the Start instance as first element
- worklist = create_node()
- set_add(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
- while (bool_not(pm_finished(worklist, pm))):
- // Pop a random element from the list and execute it
- tuple = set_pop(worklist)
- element = tuple[0]
- result = tuple[1]
- log("Enacting " + cast_v2s(element))
- // Find the type (to see what to do with it)
- // this does not yet yield the type of transformation, if it is an Execution
- type = read_type(pm, element)
- if (type == "Start"):
- // Initial node, just progress to the next elements
- // Nothing to do here though, as we have just started
- result = True
- elif (type == "Finish"):
- // Should be impossible, as we would have ended...
- result = result
- elif (type == "Fork"):
- result = result
- elif (type == "Join"):
- // Only do this if all dependencies are fullfilled
- // So add to the counter of this Join
- dict_overwrite(counters, element, integer_addition(counters[element], 1))
- // Now check whether we have enough tokens to execute the Join itself
- Integer required
- Integer got
- required = read_nr_out(allIncomingAssociationInstances(pm, element, "Next")) + read_nr_out(allIncomingAssociationInstances(pm, element, "Else"))
- got = counters[element]
- if (got == required):
- // Reset counter to 0
- dict_overwrite(counters, element, 0)
- // And continue
- else:
- // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
- continue!
- elif (type == "Exec"):
- // Execute a transformation
- // This the difficult part!
- result = enact_action(pm, element, prefix, user_id)
- elif (type == "Decision"):
- // If the previous result is true, we add the normal one, otherwise the false one
- // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
- if (bool_not(result)):
- // Apparently it is False, so map this to the "Else" branch
- set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
- continue!
- else:
- // Apparently it is True, so map this to the "Then" branch
- set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
- continue!
- // We have finished the execution, so add all outgoing edges to the worklist
- Element all_next
- all_next = allAssociationDestinations(pm, element, "Next")
- String next
- while (read_nr_out(all_next) > 0):
- next = set_pop(all_next)
- set_add(worklist, create_tuple(next, result))
- // Reached a finish element, so stop
- return !
- Void function user_function_skip_init(user_id : String):
- String cmd
- output("Welcome to the Model Management Interface v2.0!")
- output("Use the 'help' command for a list of possible commands")
- while (True):
- 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_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(" model_render -- Render a given model with a specified mapper")
- output(" verify -- Check whether a model conforms to its metamodel")
- output("")
- output("Transformation-specific operations")
- output(" transformation_add_MT_language -- Create a RAMified metamodel of a set of models")
- output(" transformation_add_MT -- Initialize a new model transformation")
- output(" transformation_add_AL -- Initialize a new action language transformation")
- output(" transformation_add_MANUAL -- Initialize a new manual transformation")
- output(" transformation_execute -- Execute a transformation on a set of input models")
- output(" transformation_list -- List all model transformations")
- output(" transformation_list_full -- List all model transformations with permissions")
- output(" transformation_detail -- List transformation details")
- output(" transformation_RAMify -- RAMify a metamodel (again)")
- output("")
- output("Process operations")
- output(" process_execute -- Execute a process model")
- 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(" self-destruct -- Remove current user and revoke all permissions ")
- output(" exit -- Kill the current task, while retaining user")
- 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 = input()
- type_id = get_model_id(type)
- 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...")
- new_model = construct_model_raw(get_full_model(type_id))
- model_create(new_model, name, user_id, type_id, "Model")
- output("Model upload success!")
- else:
- output("Model with that name already exists!")
- else:
- output("Permission denied")
- else:
- output("Could not find type model: " + type)
- elif (cmd == "process_execute"):
- // Execute a process model until it reaches termination
- String process_id
- output("Which process model do you want to execute?")
- process_id = get_model_id(input())
- if (process_id != ""):
- if (allow_read(user_id, process_id)):
- output("Model prefix to use?")
- enact_PM(get_full_model(process_id), input(), user_id)
- else:
- output("Permission denied")
- else:
- output("No such model")
- elif (cmd == "model_render"):
- String model_name
- String model_ID
- String mapper_name
- String mapper_ID
- String rendered_name
- String tracability_name
- String type_ID
- Element inputs
- Element outputs
- Element rendered_model
- Element tracability_model
- Element result
- output("Model to render?")
- model_name = input()
- model_ID = get_model_id(model_name)
- if (model_ID != ""):
- output("Mapper to use?")
- mapper_name = input()
- mapper_ID = get_model_id(mapper_name)
- if (allow_read(user_id, model_ID)):
- if (mapper_ID != ""):
- if (allow_read(user_id, mapper_ID)):
- // Everything is fine; start the actual operation
- // Find metamodel to render to
- rendered_name = (("__RENDERED_" + model_name) + "__") + mapper_name
- tracability_name = (("__TRACABILITY_" + model_name) + "__") + mapper_name
- // Take the abstract syntax model and the previously rendered model
- inputs = create_node()
- set_add(inputs, model_name)
- set_add(inputs, rendered_name)
- // Generate a new rendered model only (no write to original model!)
- outputs = create_node()
- type_ID = set_pop(allAssociationDestinations(core, mapper_ID, "transformOutput"))
- set_add(outputs, read_attribute(core, type_ID, "name"))
- // Rendered model doesn't exist yet, so create first
- if (get_model_id(rendered_name) == ""):
- // Rendered model doesn't exist yet, so create first!
- rendered_model = instantiate_model(get_full_model(type_ID))
- model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
-
- // Tracability model won't exist either
- tracability_model = instantiate_model(get_full_model(get_model_id("Tracability")))
- model_create(tracability_model, tracability_name, user_id, get_model_id("Tracability"), "Model")
- else:
- // Read out tracability model
- tracability_model = get_full_model(get_model_id(tracability_name))
- // Do the operation itself!
- log("Start transformation!")
- result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
- log("Transformation done")
- // Overwrite the previous rendered model; tracability updated in-place
- model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
- // Also output the resulting model
- output("Mapping success!")
- output(pretty_print(rendered_name))
- else:
- output("Permission denied")
- else:
- output("No such mapper")
- else:
- output("Permission denied")
- else:
- output("No such 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
- Element inputs
- Element outputs
- Element trace_links
- String target_model_name
- String source_model_name
- String source_model_ID
- Element result
- Element keys
- String key
- output("Which transformation do you want to execute?")
- transformation_id = input()
- transformation_id = get_model_id(transformation_id)
- 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 = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
- inputs = create_node()
- while (read_nr_out(sources) > 0):
- source = set_pop(sources)
- output(string_join("Which model to bind for source type ", read_attribute(core, readAssociationDestination(core, source), "name")))
- source_model_name = input()
- source_model_ID = get_model_id(source_model_name)
- if (name_id != ""):
- if (allow_read(user_id, name_id)):
- // Check for conformance to the requested metamodel
- if (check_is_typed_by(source_model_ID, source)):
- if (check_conformance(source_model_ID)):
- set_add(inputs, source_model_name)
- continue!
- else:
- output("Model has correct type but does not conform completely!")
- else:
- output("Model has different type!")
- else:
- output("Permission denied")
- else:
- output("No such model")
- // Retry this model type
- set_add(sources, source)
- targets = allOutgoingAssociationInstances(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 type ", read_attribute(core, readAssociationDestination(core, target), "name")))
- target_model_name = input()
- if (get_model_id(target_model_name) == ""):
- // Doesn't exist yet, so we can easily create
- dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
- else:
- // Already exists, so we need to check for write access
- if (allow_write(user_id, get_model_id(target_model_name))):
- dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
- else:
- output("Permission denied; try again")
- set_add(targets, target)
- result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
- // Now write out the models again
- if (element_eq(result, read_root())):
- // Something went wrong!
- log("Transformation failed; discarding changes")
- else:
- keys = dict_keys(result)
- while (read_nr_out(keys) > 0):
- key = set_pop(keys)
-
- if (get_model_id(outputs[key]) == ""):
- // New model
- model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
- else:
- model_overwrite(result[key], get_model_id(outputs[key]))
- else:
- output("Model is not an executable transformation")
- else:
- output("Permission denied")
- else:
- output("No such transformation")
- elif (cmd == "verify"):
- // Check whether a model conforms to its specification (with the selected type mapping)
- String model_id
- String result
- output("Which model to verify?")
- model_id = get_model_id(input())
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- result = conformance_scd(get_full_model(model_id))
- output(result)
- else:
- output("Permission denied")
- else:
- output("No such model")
- elif (cmd == "model_overwrite"):
- // Overwrites an existing model without changing any metadata
- String model_id
- Element new_model
- 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, set_pop(allAssociationDestinations(core, model_id, "instanceOf")))):
- output("Waiting for model constructors...")
- new_model = construct_model_raw(get_full_model(set_pop(allAssociationDestinations(core, model_id, "instanceOf"))))
- 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(get_full_model(model_id), allow_write(user_id, model_id))
- else:
- output("Permission denied")
- else:
- output("Permission denied")
- 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
- 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")
- type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
- output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + 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
- old_type_id = ""
- // Read involved formalisms
- all_formalisms = create_node()
- 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, get_full_model(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")
- else:
- output("No such model; try again")
-
- name = input()
- // Merge all into a single metamodel
- if (read_nr_out(all_formalisms) > 0):
- output("Name of the RAMified transformation 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(set_copy(all_formalisms))
- 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
- while (read_nr_out(all_formalisms) > 0):
- source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
- 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)
- model_create(ramified_formalism, name, user_id, type_id, "Model")
- ramified_formalism_id = get_model_id(name)
- // 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 formalism is required")
- elif (cmd == "transformation_RAMify"):
- // RAMify a metamodel
- String merged_model_id
- String target_model_name
- String target_model_id
- Element target_model
- String tracability_link
- output("Which metamodel do you want to RAMify?")
- merged_model_id = get_model_id(input())
- if (merged_model_id != ""):
- if (allow_read(user_id, merged_model_id)):
- output("Where do you want to store the RAMified metamodel?")
- target_model_name = input()
- target_model_id = get_model_id(target_model_name)
- if (target_model_id == ""):
- // New model, so everything is fine
- target_model = ramify(get_full_model(merged_model_id))
- model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
- target_model_id = get_model_id(target_model_name)
- tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
- instantiate_attribute(core, tracability_link, "type", "RAMified")
- else:
- // Existing model, so overwrite
- if (allow_write(user_id, target_model_id)):
- target_model = ramify(get_full_model(merged_model_id))
- model_overwrite(target_model, target_model_id)
- model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
- tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
- instantiate_attribute(core, tracability_link, "type", "RAMified")
- else:
- output("Permission denied")
- else:
- output("Permission denied!")
- else:
- output("No such model")
- elif (bool_or(cmd == "transformation_add_MANUAL", cmd == "transformation_add_AL")):
- // Add a manual transformation model
- String model_id
- Element models
- Element source
- Element target
- String name
- Element all_formalisms
- Element merged_formalism
- String merged_formalism_id
- String source_formalism_id
- String tracability_link
- String type_id
- String old_type_id
- source = create_node()
- target = create_node()
- all_formalisms = create_node()
- type_id = ""
- old_type_id = ""
- output("Which metamodels do you want to use as source for the operation (empty string to finish)?")
- name = input()
- while (name != ""):
- model_id = get_model_id(name)
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- if (bool_not(set_in(source, model_id))):
- type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
- if (bool_or(old_type_id == "", type_id == old_type_id)):
- old_type_id = type_id
- set_add(source, model_id)
- set_add(all_formalisms, create_tuple(name, get_full_model(model_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 already selected as source")
- else:
- output("Permission denied")
- else:
- output("No such model; try again")
-
- name = input()
- output("Which metamodels do you want to use as target for the operation (empty string to finish)?")
- name = input()
- while (name != ""):
- model_id = get_model_id(name)
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- if (bool_not(set_in(target, model_id))):
- type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
- if (bool_or(old_type_id == "", type_id == old_type_id)):
- old_type_id = type_id
- set_add(target, model_id)
- set_add(all_formalisms, create_tuple(name, get_full_model(model_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 already selected as target")
- else:
- output("Permission denied")
- else:
- output("No such model; try again")
-
- name = input()
- output("Name of operation model?")
- name = input()
- if (get_model_id(name) == ""):
- if (cmd == "transformation_add_MANUAL"):
- // Finished with all information, now create the model itself!
- model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), name, user_id, get_model_id("ManualOperation"), "ManualOperation")
- model_id = get_model_id(name)
- elif (cmd == "transformation_add_AL"):
- // Finished with all information, now create the model itself!
- output("Waiting for model constructors...")
- add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + name, construct_function())
- model_create(import_node("AL/" + name), name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
- model_id = get_model_id(name)
- // Write out a merged metamodel containing all these models: this is the MM for the manual operation
- // 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")
- merged_formalism_id = get_model_id("__merged_" + name)
- // Add tracability links at this level
- while (read_nr_out(all_formalisms) > 0):
- source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
- tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
- instantiate_attribute(core, tracability_link, "type", "merged")
- tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
- instantiate_attribute(core, tracability_link, "type", "operatesOn")
- // Extend metadata with info on source and target
- String link
- String dst
- while (read_nr_out(source) > 0):
- dst = set_pop(source)
- link = instantiate_link(core, "transformInput", "", model_id, dst)
- while (read_nr_out(target) > 0):
- dst = set_pop(target)
- link = instantiate_link(core, "transformOutput", "", model_id, dst)
- else:
- output("Model already exists")
- 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
- String merged_link_id
- Element links_merged
- String merged_metamodel_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(links)
- merged_metamodel_id = readAssociationDestination(core, link_id)
- if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
- links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
- while (read_nr_out(links_merged) > 0):
- merged_link_id = set_pop(links_merged)
- if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
- output(string_join(" ", read_attribute(core, readAssociationDestination(core, merged_link_id), "name")))
- set_add(supported, readAssociationDestination(core, merged_link_id))
- output("Which metamodels do you want to use as source for the operation (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)
- 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 metamodels do you want to use as target for the operation (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)
- 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 operation?")
- name = input()
- if (get_model_id(name) == ""):
- String new_model
- // Finished with all information, now create the model itself!
- output("Waiting for model constructors...")
- new_model = construct_model_raw(get_full_model(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
- String link
- String dst
- while (read_nr_out(source) > 0):
- dst = set_pop(source)
- link = instantiate_link(core, "transformInput", "", model_id, dst)
- while (read_nr_out(target) > 0):
- dst = set_pop(target)
- link = instantiate_link(core, "transformOutput", "", model_id, dst)
- else:
- output("Model already exists")
- else:
- output("Permission denied")
- else:
- output("No such model")
- elif (cmd == "transformation_list"):
- // List all models
- Element models
- String m
- String type
- models = allInstances(core, "Transformation")
- 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(allAssociationDestinations(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
- 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")
- type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
- output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type)
- 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 (i < 3):
- permission = cast_s2i(string_get(permissions, i))
- if (bool_or(permission < 0, permission > 2)):
- fail = True
- break!
- i = i + 1
- 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 (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
- 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 (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
- 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, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
- if (read_nr_out(overlap) == 0):
- instantiate_link(core, "owner", "", group_id, other_user_id)
- overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) == 0):
- instantiate_link(core, "belongsTo", "", other_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, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) > 0):
- overlap = set_overlap(allIncomingAssociationInstances(core, other_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, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
- if (read_nr_out(overlap) == 0):
- instantiate_link(core, "belongsTo", "", other_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, other_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, other_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 (read_nr_out(groups) > 0):
- 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 == "self-destruct"):
- // Delete user from Core Formalism
- model_delete_element(core, user_id)
- return !
- 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
- // as the current user will have been deleted
- return !
- else:
- output("Unknown command: " + cmd)
- // We never get here!
- return !
|