1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900 |
- 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"
- include "utils.alh"
- include "conformance_finding.alh"
- include "typing.alh"
- Element core = ?
- String core_model_location = "models/core"
- Element caches = ?
- Void function initialize_core():
- // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
- add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
- dict_add_fast(caches, "models", dict_create())
- dict_add_fast(caches, "users", dict_create())
- return !
- Boolean function is_typed_by(model_id : String, metamodel_id : String):
- return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
- Element function get_instanceOf_links(model_id : String, metamodel_id : String):
- Element result
- Element options
- String elem
- result = set_create()
- options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
- while (set_len(options) > 0):
- elem = set_pop(options)
- if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
- set_add(result, elem)
- return result!
- String function get_instanceOf_link(model_id : String, metamodel_id : String):
- Element all_links
- String choice
- all_links = get_instanceOf_links(model_id, metamodel_id)
- if (set_len(all_links) > 1):
- log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
- elif (set_len(all_links) == 0):
- log("No types found!")
- return read_root()!
-
- choice = set_pop(all_links)
- return choice!
- Element function get_full_model(model_id : String, metamodel_id : String):
- // TODO we are restricted to using SimpleClassDiagrams as M3 level, through this code!
- Element m
- Element all_links
- String choice
- choice = get_instanceOf_link(model_id, metamodel_id)
- m = dict_create()
- dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
- // TODO for now this is restricted to the fixed semantics
- // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
- dict_add(m, "semantics", get_model_id("conformance_mv"))
- if (metamodel_id == model_id):
- // Found the meta-circular level, so we can stop!
- dict_add(m, "metamodel", m)
- else:
- Element mm
- mm = get_full_model(metamodel_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return read_root()!
- else:
- dict_add(m, "metamodel", mm)
- if (element_neq(choice, read_root())):
- if (set_len(allAssociationDestinations(core, choice, "typing")) == 1):
- // Add the preferred original type mapping
- dict_add(m, "type_mapping", import_node(read_attribute(core, set_pop(allAssociationDestinations(core, choice, "typing")), "location")))
- else:
- // Start from scratch
- dict_add(m, "type_mapping", new_type_mapping())
- else:
- // Start from scratch
- dict_add(m, "type_mapping", new_type_mapping())
-
- if (find_type_mapping(m)):
- // TODO store the found type model somewhere
- return m!
- else:
- log("No type mapping could be deduced!")
- log("Error for " + cast_v2s(read_attribute(core, model_id, "name")))
- log(" and type " + cast_v2s(read_attribute(core, metamodel_id, "name")))
- return read_root()!
- 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 (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
- // 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!
- Void function new_task():
- String username
- String user_id
- String password
- // Load in a hard-reference to the previously created model
- core = import_node(core_model_location)
- while (True):
- 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)
- output("This is a new user: please give password!")
- password = hash(input())
- output("Please repeat the password")
- if (password == hash(input())):
- output("Passwords match!")
- instantiate_attribute(core, user_id, "password", password)
- break!
- else:
- output("Not the same password!")
- else:
- if (check_login(user_id)):
- break!
- else:
- output("Wrong password!")
- user_function_skip_init(user_id)
- // User destroyed already, so just stop execution
- return!
- String function get_model_id(name : String):
- Element models
- String model
- if (dict_in(caches["models"], name)):
- if (value_eq(read_attribute(core, caches["models"][name], "name"), name)):
- return caches["models"][name]!
- models = allInstances(core, "Model")
- while (set_len(models) > 0):
- model = set_pop(models)
- if (value_eq(name, read_attribute(core, model, "name"))):
- dict_overwrite(caches["models"], name, model)
- return model!
-
- return ""!
- String function get_service_id(name : String):
- Element services
- String service
- services = allInstances(core, "Service")
- while (set_len(services) > 0):
- service = set_pop(services)
- if (value_eq(read_attribute(core, service, "name"), name)):
- return service!
-
- return ""!
- String function get_user_id(name : String):
- Element users
- String user
- users = allInstances(core, "User")
- while (set_len(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 (set_len(groups) > 0):
- group = set_pop(groups)
- if (value_eq(read_attribute(core, group, "name"), name)):
- return group!
-
- return ""!
- String function export_typing(model : Element, name : String, user_id : String):
- String result
- result = instantiate_node(core, "TypeMapping", "")
- // Create type mapping model
- String location
- location = "type_mappings/" + cast_id2s(model["type_mapping"])
- export_node(location, model["type_mapping"])
- String instance_of
- instantiate_attribute(core, result, "name", "TM_" + name)
- instantiate_attribute(core, result, "location", location)
- instantiate_attribute(core, result, "permissions", "200")
- instantiate_link(core, "owner", "", result, user_id)
- instantiate_link(core, "group", "", result, get_group_id("nobody"))
- instance_of = instantiate_link(core, "instanceOf", "", result, get_model_id("TypeMapping"))
- instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
- return result!
- Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
- String location
- String model_id
- String instance_of
- // Create model itself
- location = "models/" + cast_id2s(model)
- export_node(location, model["model"])
- 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_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
- // Create type mapping model
- instantiate_link(core, "typing", "", instance_of, export_typing(model, name, user_id))
- return!
- Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
- // TODO this should be more elegant than just hiding the old elements
- 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)
- // Update the instanceOf relation of the context in which we are working
- String choice
- choice = get_instanceOf_link(model_id, metamodel_id)
- if (element_neq(choice, read_root())):
- // There was a link, so we remove it
- model_delete_element(core, choice)
- // Create a new instanceOf relation now
- String instance_of
- instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
- instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
- instantiate_link(core, "typing", "", instance_of, export_typing(model, read_attribute(core, model_id, "name"), get_user_id("admin")))
- return!
- 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")
- worklist = set_copy(worklist)
- while (set_len(worklist) > 0):
- // Check each finished element individually
- if (set_in(finished, list_read(set_pop(worklist), 0))):
- return True!
- return False!
- Element function execute_operation(operation_id : String, input_models : 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 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
- // 0) Find the signature of the operation
- Element input_metamodels
- Element output_metamodels
- Element iter
- String edge
- input_metamodels = dict_create()
- iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
- while (set_len(iter) > 0):
- edge = set_pop(iter)
- dict_add(input_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
- output_metamodels = dict_create()
- iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
- while (set_len(iter) > 0):
- edge = set_pop(iter)
- dict_add(output_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
- // 1) Find merged metamodel
- exact_type = read_type(core, operation_id)
- trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
- merged_metamodel_id = ""
- while (set_len(trace_links) > 0):
- trace_link_id = set_pop(trace_links)
- if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
- merged_metamodel_id = readAssociationDestination(core, trace_link_id)
- // 2) Merge source models
- if (merged_metamodel_id != ""):
- model_tuples = set_create()
- keys = dict_keys(input_models)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- Element mm
- mm = get_full_model(get_model_id(input_models[key]), get_model_id(input_metamodels[key]))
- if (element_eq(mm, read_root())):
- log("Signature mismatch in operation for tag " + key)
- output("Signature mismatch in operation for tag " + key)
- return read_root()!
- set_add_node(model_tuples, create_tuple(key, mm))
- Element merged_metamodel
- merged_metamodel = get_full_model(merged_metamodel_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(merged_metamodel, read_root())):
- log("Merged metamodel in operation is not of type SimpleClassDiagrams")
- output("Merged metamodel in operation is not of type SimpleClassDiagrams")
- return read_root()!
- merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
- else:
- if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
- // Just skip the merge...
- Element m
- m = get_full_model(get_model_id(input_models[set_pop(dict_keys(input_models))]), get_model_id(input_metamodels[set_pop(dict_keys(input_metamodels))]))
- if (element_eq(m, read_root())):
- log("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
- output("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
- return read_root()!
- merged_model = model_copy(m)
- elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
- merged_model = read_root()
- else:
- log("Could not resolve intermediate merged metamodel")
- output("Could not resolve intermediate merged metamodel")
- return read_root()!
- // 3) Transform
- if (exact_type == "ModelTransformation"):
- trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
- ramified_metamodel_id = ""
- while (set_len(trace_links) > 0):
- trace_link_id = set_pop(trace_links)
- if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
- ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
- Element operation
- operation = get_full_model(operation_id, ramified_metamodel_id)
- if (element_eq(operation, read_root())):
- log("Operation could not be typed by specified RAMified metamodel!")
- output("Operation could not be typed by specified RAMified metamodel!")
- return read_root()!
- result = transform(merged_model, operation)
- 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
- Element al
- al = get_full_model(operation_id, get_model_id("ActionLanguage"))
- if (element_eq(al, read_root())):
- log("Action Language operation not typed by ActionLanguage metamodel!")
- output("Action Language operation not typed by ActionLanguage metamodel!")
- return read_root()!
- func = get_func_AL_model(al)
- result = func(merged_model)
- else:
- log("Unknown type of operation: " + exact_type)
- output("Unknown type of operation: " + exact_type)
- return read_root()!
- // 4) Split in different models depending on type
- if (element_neq(tracability_model, read_root())):
- tracability = True
- else:
- tracability = False
- if (result):
- model_tuples = set_create()
- keys = dict_keys(output_metamodels)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- Element mm
- mm = get_full_model(get_model_id(output_metamodels[key]), get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- log("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
- output("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
- return read_root()!
- set_add_node(model_tuples, create_tuple(key, mm))
- result = model_split(merged_model, model_tuples, tracability)
- if (tracability):
- 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")
- return result!
- else:
- log("Negative result of execution")
- 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
- String consume
- String produce
- Element output_map
- inputs = dict_create()
- outputs = dict_create()
- output_map = dict_create()
- // 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 (set_len(lst) > 0):
- consume = set_pop(lst)
- value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
- dict_add(inputs, read_attribute(pm, consume, "name"), prefix + value)
- // Find all output model names and their metamodel
- lst = allOutgoingAssociationInstances(pm, element, "Produces")
- while (set_len(lst) > 0):
- produce = set_pop(lst)
- elem = readAssociationDestination(pm, produce)
- type_name = read_attribute(pm, elem, "type")
- elem_name = read_attribute(pm, elem, "name")
- dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
- dict_add(output_map, read_attribute(pm, produce, "name"), prefix + elem_name)
- if read_type(core, transformation_id) == "ActionLanguage":
- log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
- output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
- elif read_type(core, transformation_id) == "ManualOperation":
- log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
- output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
- else:
- log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
- output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
-
- result = execute_operation(transformation_id, inputs, read_root())
- if (element_eq(result, read_root())):
- // Something went wrong!
- return False!
- else:
- keys = dict_keys(result)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- if (get_model_id(output_map[key]) == ""):
- // New model
- model_create(result[key], output_map[key], user_id, get_model_id(key), "Model")
- else:
- model_overwrite(result[key], get_model_id(output_map[key]), get_model_id(outputs[key]))
- return True!
- 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
- output("Success")
- // Initialize Join counters
- counters = dict_create()
- join_nodes = allInstances(pm, "Join")
- while (set_len(join_nodes) > 0):
- dict_add(counters, set_pop(join_nodes), 0)
- // Create the worklist with the Start instance as first element
- worklist = set_create()
- set_add_node(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]
- // 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 = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(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_node(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_node(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 (set_len(all_next) > 0):
- next = set_pop(all_next)
- set_add_node(worklist, create_tuple(next, result))
- // Reached a finish element, so stop
- output("Success")
- return !
- String function cmd_help(user_id : String):
- String result
- result = ""
- result = result + ("Model operations\n")
- result = result + (" model_add -- Add a new model\n")
- result = result + (" model_modify -- Modify an existing model\n")
- result = result + (" model_list -- List all models\n")
- result = result + (" model_list_full -- List all models with full info\n")
- result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
- result = result + (" model_render -- Render a given model with a specified mapper\n")
- result = result + (" verify -- Check whether a model conforms to its metamodel\n")
- result = result + ("\n")
- result = result + ("Transformation-specific operations\n")
- result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
- result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
- result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
- result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
- result = result + (" transformation_list -- List all model transformations\n")
- result = result + (" transformation_list_full -- List all model transformations with permissions\n")
- result = result + (" transformation_detail -- List transformation details\n")
- result = result + (" transformation_between -- List all transformations between two metamodels\n")
- result = result + ("\n")
- result = result + ("Process operations\n")
- result = result + (" process_execute -- Execute a process model\n")
- result = result + ("\n")
- result = result + ("Model permission operations\n")
- result = result + (" permission_modify -- Change model permissions\n")
- result = result + (" permission_owner -- Change model owner\n")
- result = result + (" permission_group -- Change model group\n")
- result = result + ("\n")
- result = result + ("Group operations\n")
- result = result + (" group_create -- Create a group\n")
- result = result + (" group_delete -- Delete a group\n")
- result = result + (" group_owner_add -- Add group owner\n")
- result = result + (" group_owner_delete -- Remove group owner\n")
- result = result + (" group_join -- Add someone to your group\n")
- result = result + (" group_kick -- Kick someone from your group\n")
- result = result + (" group_list -- List all groups you are a member of\n")
- result = result + ("\n")
- if (is_admin(user_id)):
- result = result + ("Admin operations\n")
- result = result + (" admin_promote -- Promote a user to admin status\n")
- result = result + (" admin_demote -- Demote a user to normal status\n")
- result = result + ("\n")
- result = result + ("General operations\n")
- result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
- result = result + (" exit -- Kill the current task, while retaining user\n")
- return result!
- String function cmd_model_add(user_id : String, type : String, name : String):
- // Model addition operation, which uses model upload commands of the compiler
- String location
- String type_id
- Element new_model
- String new_model_id
- type_id = get_model_id(type)
- if (type_id != ""):
- // Type exists
- if (allow_read(user_id, type_id)):
- // And is readable
- if (get_model_id(name) == ""):
- // Model doesn't exist yet
- Element mm
- mm = get_full_model(type_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return "Type is not typed by SimpleClassDiagrams: " + type!
- output("Waiting for model constructors...")
- new_model = construct_model_raw(mm)
- model_create(new_model, name, user_id, type_id, "Model")
- return "Success"!
- else:
- return "Model exists: " + name!
- else:
- return "Permission denied to model: " + type!
- else:
- return "Model not found: " + type!
- String function cmd_process_execute(user_id : String, process : String, prefix : String):
- // Execute a process model until it reaches termination
- String process_id
- process_id = get_model_id(process)
- if (process_id != ""):
- if (allow_read(user_id, process_id)):
- Element pm
- pm = get_full_model(process_id, get_model_id("ProcessModel"))
- if (element_eq(pm, read_root())):
- return "Specified model cannot be interpreted as a ProcessModel: " + process!
- enact_PM(pm, prefix, user_id)
- return "Success"!
- else:
- return "Permission denied to model: " + process!
- else:
- return "Model not found: " + process!
- String function cmd_transformation_between(user_id : String, source_name : String, target_name : String):
- String source_id
- String target_id
- Element onSource
- Element onTarget
- Element result
- String transformation
- source_id = get_model_id(source_name)
- if (source_id != ""):
- target_id = get_model_id(target_name)
- if (target_id != ""):
- onSource = allAssociationOrigins(core, source_id, "transformInput")
- onTarget = allAssociationOrigins(core, target_id, "transformOutput")
- result = set_overlap(onSource, onTarget)
- String r
- r = "Success: "
- while (set_len(result) > 0):
- transformation = set_pop(result)
- if (allow_read(user_id, transformation)):
- r = r + string_join(read_attribute(core, transformation, "name"), "\n")
- return r!
- else:
- return "Model not found: " + target_name!
- else:
- return "Model not found: " + source_name!
- String function cmd_model_render(user_id : String, model_name : String, mapper_name : String):
- String model_ID
- String mapper_ID
- String rendered_name
- String tracability_name
- Element inputs
- Element output_map
- Element rendered_model
- Element tracability_model
- Element result
- Element out_links
- String link
- model_ID = get_model_id(model_name)
- if (model_ID != ""):
- 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 = dict_create()
- dict_add(inputs, "abstract", model_name)
- dict_add(inputs, "rendered", rendered_name)
- // Fetch the output types
- output_map = dict_create()
- out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
- while(set_len(out_links) > 0):
- link = set_pop(out_links)
- dict_add(output_map, read_attribute(core, link, "name"), read_attribute(core, readAssociationDestination(core, link), "name"))
- if (get_model_id(rendered_name) == ""):
- // Instantiate
- Element rendered
- rendered = get_full_model(get_model_id(output_map["rendered"]), get_model_id("SimpleClassDiagrams"))
- if (element_eq(rendered, read_root())):
- return "Rendered metamodel cannot conform to SimpleClassDiagrams"!
- rendered_model = instantiate_model(rendered)
- model_create(rendered_model, rendered_name, user_id, get_model_id(output_map["rendered"]), "Model")
-
- // Tracability model won't exist either
- tracability_model = instantiate_model(get_full_model(get_model_id("Tracability"), get_model_id("SimpleClassDiagrams")))
- 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), get_model_id("Tracability"))
- if (element_eq(tracability_model, read_root())):
- return "Tracability model not typed by Tracability metamodel: " + tracability_name!
- // Do the operation itself!
- result = execute_operation(mapper_ID, inputs, tracability_model)
- // Overwrite the previous rendered model
- model_overwrite(result["rendered"], get_model_id(rendered_name), get_model_id(output_map["rendered"]))
- model_overwrite(result["abstract"], get_model_id(model_name), get_model_id(output_map["abstract"]))
- // Tracability updated in-place
- model_overwrite(tracability_model, get_model_id(tracability_name), get_model_id("Tracability"))
- tracability_model = get_full_model(get_model_id(tracability_name), get_model_id("Tracability"))
- if (element_eq(tracability_model, read_root())):
- return "Tracability model not typed by Tracability metamodel: " + tracability_name!
- // Also output the resulting model
- return "Success: " + JSON_print(get_full_model(get_model_id(rendered_name), get_model_id(output_map["rendered"])))!
- else:
- return "Permission denied to model: " + mapper_name!
- else:
- return "Model not found: " + mapper_name!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_transformation_execute(user_id : String, transformation_name : String, source_models : Element, target_models : Element):
- // 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
- Element inputs
- Element outputs
- Element output_map
- Element trace_links
- String target_model_name
- String source_model_name
- String source_model_ID
- Element result
- Element keys
- String key
- String assoc_name
- transformation_id = get_model_id(transformation_name)
- if (transformation_id != ""):
- if (allow_read(user_id, transformation_id)):
- if (is_nominal_instance(core, transformation_id, "Transformation")):
- // Read out source and target links
- inputs = dict_create()
- sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
- while (set_len(sources) > 0):
- source = set_pop(sources)
- assoc_name = read_attribute(core, source, "name")
- if (dict_in(source_models, assoc_name)):
- source_model_name = source_models[assoc_name]
- else:
- return "Source model not bound: " + assoc_name!
- source_model_ID = get_model_id(source_model_name)
- if (source_model_ID != ""):
- if (allow_read(user_id, source_model_ID)):
- // Check for conformance to the requested metamodel
- dict_add(inputs, assoc_name, source_model_name)
- continue!
- else:
- return "Permission denied to model: " + source_model_name!
- else:
- return "Model not found: " + source_model_name!
- targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
- outputs = dict_create()
- output_map = dict_create()
- while (set_len(targets) > 0):
- target = set_pop(targets)
- assoc_name = read_attribute(core, target, "name")
- if (dict_in(target_models, assoc_name)):
- target_model_name = target_models[assoc_name]
- else:
- return "Target model not bound: " + assoc_name!
- if (get_model_id(target_model_name) == ""):
- // Doesn't exist yet, so we can easily create
- dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
- dict_add(outputs, assoc_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(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
- dict_add(outputs, assoc_name, target_model_name)
- else:
- return "Permission denied to model: " + target_model_name!
- if (read_type(core, transformation_id) == "ActionLanguage"):
- output("Success: ready for AL execution")
- elif (read_type(core, transformation_id) == "ManualOperation"):
- output("Success: ready for MANUAL execution")
- else:
- output("Success: ready for MT execution")
- result = execute_operation(transformation_id, inputs, read_root())
- // Now write out the models again
- if (element_eq(result, read_root())):
- // Something went wrong!
- return "Failure"!
- else:
- keys = dict_keys(result)
- while (set_len(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]), get_model_id(output_map[key]))
- return "Success"!
- else:
- return "Model is not executable: " + transformation_name!
- else:
- return "Permission denied to model: " + transformation_name!
- else:
- return "Model not found: " + transformation_name!
- String function cmd_verify(user_id : String, model_name : String, metamodel_name : String):
- // Check whether a model conforms to its specification (with the selected type mapping)
- String model_id
- String result
- Element inputs
- model_id = get_model_id(model_name)
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- Element m
- m = get_full_model(get_model_id(model_name), get_model_id(metamodel_name))
- if (element_eq(m, read_root())):
- return "No conformance relation can be found between these models"!
- return string_join("Success: ", conformance_scd(m))!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_model_overwrite(user_id : String, model_name : String, metamodel_name : String):
- // Overwrites an existing model without changing any metadata
- String model_id
- String type_id
- Element new_model
- model_id = get_model_id(model_name)
- if (model_id != ""):
- if (allow_write(user_id, model_id)):
- type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
- if (allow_read(user_id, type_id)):
- Element mm
- mm = get_full_model(get_model_id(metamodel_name), get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return "Metamodel does not conform to SimpleClassDiagrams: " + metamodel_name!
- output("Waiting for model constructors...")
- new_model = construct_model_raw(mm)
- model_overwrite(new_model, model_id, metamodel_name)
- return "Success"!
- else:
- return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_model_modify(user_id : String, model_name : String, metamodel_name : String):
- // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
- String model_id
- String type_id
- model_id = get_model_id(model_name)
- 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)):
- Element new_model
- new_model = get_full_model(model_id, get_model_id(metamodel_name))
- if (element_eq(new_model, read_root())):
- return "No conformance relation can be found between these models"!
- output("Success")
- modify(new_model, allow_write(user_id, model_id))
- if (allow_write(user_id, model_id)):
- // Overwrite the modified model
- model_overwrite(new_model, model_id, metamodel_name)
- return "Success"!
- else:
- return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_model_delete(user_id : String, model_name : String):
- String model_id
- model_id = get_model_id(model_name)
- if (model_id != ""):
- if (allow_write(user_id, model_id)):
- model_delete_element(core, model_id)
- return "Success"!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_model_list():
- // List all models
- Element models
- String result
- String m
- result = "Success: "
- models = allInstances(core, "Model")
- while (set_len(models) > 0):
- m = set_pop(models)
- if (set_len(allAssociationDestinations(core, m, "instanceOf")) > 0):
- result = (result + string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))) + "\n"
- else:
- result = result + string_join(string_join(" ", read_attribute(core, m, "name")), " : None\n")
- return result!
- String function 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 result
- result = "Success: "
- models = allInstances(core, "Model")
- while (set_len(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")
- if (set_len(allAssociationDestinations(core, m, "instanceOf")) > 0):
- type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
- else:
- type = "None"
- result = (result + (((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)) + "\n"
- return result!
- String function cmd_transformation_add_MANUAL(user_id : String, source_models : Element, target_models : Element, operation_name : String):
- return transformation_add(user_id, source_models, target_models, operation_name, "manual")!
- String function cmd_transformation_add_AL(user_id : String, source_models : Element, target_models : Element, operation_name : String):
- return transformation_add(user_id, source_models, target_models, operation_name, "actionlanguage")!
- String function transformation_add(user_id : String, source_models : Element, target_models : Element, operation_name : String, operation_type : String):
- // Add a manual transformation model
- String model_id
- Element models
- Element source
- Element target
- String name
- Element all_formalisms
- Element formalism_map
- Element merged_formalism
- String merged_formalism_id
- String source_formalism_id
- String tracability_link
- Element fused
- Element keys
- String key
- Element mm
- source = dict_create()
- target = dict_create()
- all_formalisms = set_create()
- formalism_map = set_create()
- fused = set_create()
- keys = dict_keys(source_models)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- name = source_models[key]
- model_id = get_model_id(name)
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- if (bool_not(dict_in(source, key))):
- dict_add(source, key, model_id)
- mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return "Transformation source type not in SimpleClassDiagrams hierarchy: " + key!
- if (bool_not(set_in(fused, key))):
- set_add_node(formalism_map, create_tuple(key, mm))
- set_add(fused, key)
- if (bool_not(set_in(all_formalisms, model_id))):
- set_add(all_formalisms, model_id)
- else:
- return "Name already selected for source: " + key!
- else:
- return "Permission denied to model: " + name!
- else:
- return "Model not found: " + name!
- keys = dict_keys(target_models)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- name = target_models[key]
- model_id = get_model_id(name)
- if (model_id != ""):
- if (allow_read(user_id, model_id)):
- if (bool_not(dict_in(target, key))):
- dict_add(target, key, model_id)
- mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return "Transformation target type not in SimpleClassDiagrams hierarchy: " + key!
- if (bool_not(set_in(fused, key))):
- set_add_node(formalism_map, create_tuple(key, mm))
- set_add(fused, key)
- if (bool_not(set_in(all_formalisms, model_id))):
- set_add(all_formalisms, model_id)
- else:
- return "Name already selected for target: " + key!
- else:
- return "Permission denied to model: " + name!
- else:
- return "Model not found: " + name!
- if (get_model_id(operation_name) == ""):
- // Write out a merged metamodel containing all these models: this is the MM for the manual operation
- // New location is available, so write
- if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
- merged_formalism = model_fuse(formalism_map)
- modify(merged_formalism, True)
- if (operation_type == "manual"):
- // Finished with all information, now create the model itself!
- Element m
- m = get_full_model(get_model_id("ManualOperation"), get_model_id("SimpleClassDiagrams"))
- if (element_eq(m, read_root())):
- log("Error when opening ManualOperation: no conformance relation found")
- return "Error when opening ManualOperation: no conformance relation found"!
- model_create(instantiate_model(m), operation_name, user_id, get_model_id("ManualOperation"), "ManualOperation")
- model_id = get_model_id(operation_name)
- elif (operation_type == "actionlanguage"):
- // Finished with all information, now create the model itself!
- output("Waiting for code constructors...")
- add_code_model(get_full_model(get_model_id("ActionLanguage"), get_model_id("SimpleClassDiagrams")), "AL/" + operation_name, construct_function())
- model_create(import_node("AL/" + operation_name), operation_name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
- model_id = get_model_id(operation_name)
- if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
- model_create(merged_formalism, "__merged_" + operation_name, user_id, get_model_id("SimpleClassDiagrams"), "Model")
- merged_formalism_id = get_model_id("__merged_" + operation_name)
- // Add tracability links at this level
- while (set_len(all_formalisms) > 0):
- source_formalism_id = set_pop(all_formalisms)
- 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
- keys = dict_keys(source)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- link = instantiate_link(core, "transformInput", "", model_id, source[key])
- instantiate_attribute(core, link, "name", key)
- keys = dict_keys(target)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- link = instantiate_link(core, "transformOutput", "", model_id, target[key])
- instantiate_attribute(core, link, "name", key)
-
- return "Success"!
- else:
- return "Model exists: " + operation_name!
- String function cmd_transformation_add_MT(user_id : String, source_models : Element, target_models : Element, operation_name : String):
- // 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
- Element ramified_metamodel
- 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_formalism
- Element keys
- String key
- Element mm
- Element to_ramify
- String source_formalism_id
- String merged_formalism_id
- String tracability_link
- source = dict_create()
- target = dict_create()
- to_ramify = set_create()
- keys = dict_keys(source_models)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- name = source_models[key]
- model_id = get_model_id(name)
- if (model_id != ""):
- if (allow_read(user_id, name)):
- // Check whether or not it is SimpleClassDiagrams
- if (is_typed_by(model_id, get_model_id("SimpleClassDiagrams"))):
- if (bool_not(dict_in(source, key))):
- dict_add(source, key, model_id)
- mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return "ModelTransformation source type not in SimpleClassDiagrams hierarchy: " + name!
- set_add_node(to_ramify, create_tuple(key, mm))
- else:
- return "Name was already assigned a metamodel: " + key!
- else:
- return "Model not supported for RAMification: " + name!
- else:
- return "Permission denied: " + name!
- else:
- return "Model not found: " + name!
- keys = dict_keys(target_models)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- name = target_models[key]
- model_id = get_model_id(name)
- if (model_id != ""):
- if (allow_read(user_id, name)):
- if (is_typed_by(model_id, get_model_id("SimpleClassDiagrams"))):
- if (bool_not(dict_in(target, key))):
- if (dict_in(source, key)):
- if (value_eq(model_id, source[key])):
- dict_add(target, key, model_id)
- // Don't add to to_ramify, as it is already in there!
- else:
- return "Name in output cannot have different type than input: " + key!
- else:
- dict_add(target, key, model_id)
- mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
- if (element_eq(mm, read_root())):
- return "ModelTransformation target type not in SimpleClassDiagrams hierarchy: " + name!
- set_add_node(to_ramify, create_tuple(key, mm))
- else:
- return "Name was already assigned a metamodel: " + key!
- else:
- return "Model not supported for RAMification: " + name!
- else:
- return "Permission denied: " + name!
- else:
- return "Model not found: " + name!
- merged_formalism = model_fuse(to_ramify)
- modify(merged_formalism, True)
- ramified_metamodel = ramify(merged_formalism)
- model_create(ramified_metamodel, "__RAM_" + operation_name, user_id, get_model_id("SimpleClassDiagrams"), "Model")
- ramified_metamodel_id = get_model_id("__RAM_" + operation_name)
-
- // Now use the RAMified model to create the instance
- if (get_model_id(operation_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, get_model_id("SimpleClassDiagrams")))
- model_create(new_model, operation_name, user_id, ramified_metamodel_id, "ModelTransformation")
- model_id = get_model_id(operation_name)
- // Write out a merged metamodel containing all these models: this is the MM for the manual operation
- // New location is available, so write
- model_create(merged_formalism, "__merged_" + operation_name, user_id, get_model_id("SimpleClassDiagrams"), "Model")
- merged_formalism_id = get_model_id("__merged_" + operation_name)
- // Add tracability links at this level
- tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
- instantiate_attribute(core, tracability_link, "type", "operatesOn")
- // Add tracability links at this level
- tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
- instantiate_attribute(core, tracability_link, "type", "RAMified")
- // Extend metadata with info on source and target
- String link
- String dst
- keys = dict_keys(source)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- dst = source[key]
- link = instantiate_link(core, "transformInput", "", model_id, dst)
- instantiate_attribute(core, link, "name", key)
- keys = dict_keys(target)
- while (set_len(keys) > 0):
- key = set_pop(keys)
- dst = target[key]
- link = instantiate_link(core, "transformOutput", "", model_id, dst)
- instantiate_attribute(core, link, "name", key)
- return "Success"!
- else:
- return "Model exists: " + operation_name!
- String function cmd_transformation_list():
- // List all models
- Element models
- String m
- String type
- String result
- result = "Success: "
- models = allInstances(core, "Transformation")
- while (set_len(models) > 0):
- m = set_pop(models)
- result = result + ((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")))) + "\n")
- return result!
- String function cmd_transformation_list_full():
- // List all models with full info
- Element models
- String m
- String permissions
- String owner
- String group
- String name
- String type
- String result
- result = ""
- models = allInstances(core, "Transformation")
- while (set_len(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")
- result = result + ((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type) + "\n")
- return result!
- String function cmd_permission_modify(user_id : String, model_name : String, permissions : String):
- Integer permission
- String model_id
- model_id = get_model_id(model_name)
- if (model_id != ""):
- if (get_relation_to_model(user_id, model_id) == 0):
- 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)
- return "Success"!
- else:
- return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_permission_owner(user_id : String, model_name : String, new_user_name : String):
- String model_id
- String new_user_id
- model_id = get_model_id(model_name)
- if (model_id != ""):
- if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
- new_user_id = get_user_id(new_user_name)
- if (new_user_id != ""):
- model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
- instantiate_link(core, "owner", "", model_id, new_user_id)
- return "Success"!
- else:
- return "No such user: " + new_user_name!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_permission_group(user_id : String, model_name : String, new_group_name : String):
- String model_id
- String group_id
- model_id = get_model_id(model_name)
- if (model_id != ""):
- if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
- group_id = get_group_id(new_group_name)
- if (group_id != ""):
- model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
- instantiate_link(core, "group", "", model_id, group_id)
- return "Success"!
- else:
- return "No such group: " + new_group_name!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "Model not found: " + model_name!
- String function cmd_group_create(user_id : String, group_name : String):
- // Create a new group and become its owner
- String group_id
- String name
- group_id = get_group_id(group_name)
- if (group_id == ""):
- group_id = instantiate_node(core, "Group", "")
- instantiate_attribute(core, group_id, "name", group_name)
- instantiate_link(core, "belongsTo", "", user_id, group_id)
- instantiate_link(core, "owner", "", group_id, user_id)
- return "Success"!
- else:
- return "Group exists: " + group_name!
- String function cmd_group_delete(user_id : String, group_name : String):
- // Delete an existing group
- String group_id
- group_id = get_group_id(group_name)
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- model_delete_element(core, group_id)
- return "Success"!
- else:
- return "Permission denied to group: " + group_name!
- else:
- return "Group not found: " + group_name!
- String function cmd_group_owner_add(user_id : String, group_name : String, other_user_name : String):
- // Add an owner to your group
- String group_id
- String other_user_id
- group_id = get_group_id(group_name)
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- other_user_id = get_user_id(other_user_name)
- if (other_user_id != ""):
- if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
- instantiate_link(core, "owner", "", group_id, other_user_id)
- if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
- instantiate_link(core, "belongsTo", "", other_user_id, group_id)
- return "Success"!
- else:
- return "User is already the owner!"!
- else:
- return "User not found: " + other_user_name!
- else:
- return "Permission denied to group: " + group_name!
- else:
- return "Group not found: " + group_name!
- String function cmd_group_owner_delete(user_id : String, group_name : String, other_user_name : String):
- // Remove an owner from your group
- String group_id
- String other_user_id
- group_id = get_group_id(group_name)
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- other_user_id = get_user_id(other_user_name)
- if (other_user_id != ""):
- if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
- if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
- Element overlap
- overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
- model_delete_element(core, set_pop(overlap))
- return "Success"!
- else:
- return "User is not an owner of the group!"!
- else:
- return "User is not a member of the group!"!
- else:
- return "User not found: " + other_user_name!
- else:
- return "Permission denied to group: " + group_name!
- else:
- return "Group not found: " + group_name!
- String function cmd_group_join(user_id : String, group_name : String, other_user_name : String):
- // Add someone to your group
- String group_id
- String other_user_id
- group_id = get_group_id(group_name)
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- other_user_id = get_user_id(other_user_name)
- if (other_user_id != ""):
- if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
- instantiate_link(core, "belongsTo", "", other_user_id, group_id)
- return "Success"!
- else:
- return "User is already a member of the group!"!
- else:
- return "User not found: " + other_user_name!
- else:
- return "Permission denied to group: " + group_name!
- else:
- return "Group not found: " + group_name!
- String function cmd_group_kick(user_id : String, group_name : String, other_user_name : String):
- // Remove someone from your group
- String group_id
- String other_user_id
- group_id = get_group_id(group_name)
- if (group_id != ""):
- if (allow_group_modify(user_id, group_id)):
- other_user_id = get_user_id(other_user_name)
- if (other_user_id != ""):
- Element overlap
- if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
- overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
- model_delete_element(core,set_pop(overlap))
- // Check if user was an owner as well
- if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
- overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
- model_delete_element(core, set_pop(overlap))
- return "Success"!
- else:
- return "User is not a member of the group!"!
- else:
- return "User not found: " + other_user_name!
- else:
- return "Permission denied to group: " + group_name!
- else:
- return "Group not found: " + group_name!
- String function cmd_group_list(user_id : String):
- // List all groups you are a member of (and whether you are admin or not!)
- Element groups
- String group_id
- String admin
- String result
-
- result = ""
- groups = allAssociationDestinations(core, user_id, "belongsTo")
- while (set_len(groups) > 0):
- group_id = set_pop(groups)
- if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
- admin = " A "
- else:
- admin = " "
- result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
- return result!
- String function cmd_admin_promote(user_id : String, other_user_name : String):
- // Promote a user to admin status
- if (is_admin(user_id)):
- String other_user_id
- other_user_id = get_user_id(other_user_name)
- if (other_user_id != ""):
- unset_attribute(core, other_user_id, "admin")
- instantiate_attribute(core, other_user_id, "admin", True)
- return "Success"!
- else:
- return "User not found: " + other_user_name!
- else:
- return "Permission denied to administrate: " + other_user_name!
- String function cmd_admin_demote(user_id : String, other_user_name : String):
- // Demote a user to normal status
- if (is_admin(user_id)):
- String other_user_id
- other_user_id = get_user_id(other_user_name)
- if (other_user_id != ""):
- unset_attribute(core, other_user_id, "admin")
- instantiate_attribute(core, other_user_id, "admin", False)
- return "Success"!
- else:
- return "User not found: " + other_user_name!
- else:
- return "Permission denied to administrate: " + other_user_name!
- String function cmd_service_register(user_id : String, service_name : String):
- // Active a service for this specific user
- if (get_service_id(service_name) == ""):
- String service
- service = instantiate_node(core, "Service", "")
- instantiate_attribute(core, service, "name", service_name)
- instantiate_attribute(core, service, "port", get_taskname())
- output("Success: " + get_taskname())
- // Wait until we can stop the service
- log("Waiting for service_stop")
- while (cast_v2s(input()) != "\"service_stop\""):
- output("Service is running on this task: stop it by sending 'service_stop'")
- log("Finished")
- model_delete_element(core, service)
- // Service terminated
- return "Success"!
- else:
- return "Service already exists: " + service_name!
- String function cmd_user_password(user_id : String, user_name : String, new_password : String):
- if (bool_or(user_id == get_user_id(user_name), is_admin(user_id))):
- if (get_user_id(user_name) != ""):
- instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
- return "Success"!
- else:
- return "No such user: " + user_name!
- else:
- return "Permission denied to user: " + user_name!
- String function cmd_transformation_signature(user_id : String, transformation_name : String):
- String model_id
- model_id = get_model_id(transformation_name)
- if (model_id != ""):
- if (is_nominal_instance(core, model_id, "Transformation")):
- if (allow_read(user_id, transformation_name)):
- String result
- String elem
- Element inputs
- Element outputs
- result = "Success: "
- inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
- while (set_len(inputs) > 0):
- elem = set_pop(inputs)
- result = string_join(string_join(string_join(string_join("I ", read_attribute(core, elem, "name")), " "), read_attribute(core, readAssociationDestination(core, elem), "name")), "\n")
- outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
- while (set_len(outputs) > 0):
- elem = set_pop(outputs)
- result = string_join(string_join(string_join(string_join("O ", read_attribute(core, elem, "name")), " "), read_attribute(core, readAssociationDestination(core, elem), "name")), "\n")
- return result!
- else:
- return "Permission denied to transformation: " + transformation_name!
- else:
- return "Model is not a transformation: " + transformation_name!
- else:
- return "No such transformation: " + transformation_name!
-
- String function cmd_element_list_nice(user_id : String, model_name : String, metamodel_name : String):
- if (get_model_id(model_name) != ""):
- if (allow_read(user_id, get_model_id(model_name))):
- Element mm
- mm = get_full_model(get_model_id(model_name), get_model_id(metamodel_name))
- if (element_eq(mm, read_root())):
- return "No conformance relation between these models"!
- return "Success: " + JSON_print(mm)!
- else:
- return "Permission denied to model: " + model_name!
- else:
- return "No such model: " + model_name!
- Void function user_function_skip_init(user_id : String):
- String cmd
- String result
- output("Welcome to the Model Management Interface v2.0!")
- output("Use the 'help' command for a list of possible commands")
- while (True):
- cmd = input()
- if (cmd == "help"):
- output(cmd_help(user_id))
- elif (cmd == "model_add"):
- output(cmd_model_add(user_id, single_input("Model type?"), single_input("Model name?")))
- elif (cmd == "process_execute"):
- output(cmd_process_execute(user_id, single_input("Process to execute?"), single_input("Model prefix to use?")))
- elif (cmd == "transformation_between"):
- output(cmd_transformation_between(user_id, single_input("Source type?"), single_input("Target type?")))
- elif (cmd == "model_render"):
- output(cmd_model_render(user_id, single_input("Model name?"), single_input("Mapper name?")))
- elif (cmd == "transformation_execute"):
- output(cmd_transformation_execute(user_id, single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
- elif (cmd == "verify"):
- result = cmd_verify(user_id, single_input("Model name?"), single_input("Metamodel name?"))
- if (result != ""):
- output(result)
- elif (cmd == "model_overwrite"):
- output(cmd_model_overwrite(user_id, single_input("Model name?"), single_input("Metamodel name?")))
- elif (cmd == "model_modify"):
- output(cmd_model_modify(user_id, single_input("Model name?"), single_input("Metamodel name?")))
- elif (cmd == "model_delete"):
- output(cmd_model_delete(user_id, single_input("Model name?")))
- elif (cmd == "model_list"):
- output(cmd_model_list())
- elif (cmd == "model_list_full"):
- output(cmd_model_list_full())
- elif (cmd == "transformation_add_MANUAL"):
- output(cmd_transformation_add_MANUAL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
- elif (cmd == "transformation_add_AL"):
- output(cmd_transformation_add_AL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
- elif (cmd == "transformation_add_MT"):
- output(cmd_transformation_add_MT(user_id, dict_input("Source model names?"), dict_input("Target models?"), single_input("Operation name?")))
- elif (cmd == "transformation_list"):
- output(cmd_transformation_list())
- elif (cmd == "transformation_list_full"):
- output(cmd_transformation_list_full())
- elif (cmd == "permission_modify"):
- output(cmd_permission_modify(user_id, single_input("Model name?"), single_input("Permissions?")))
- elif (cmd == "permission_owner"):
- output(cmd_permission_owner(user_id, single_input("Model name?"), single_input("New owning user?")))
- elif (cmd == "permission_group"):
- output(cmd_permission_group(user_id, single_input("Model name?"), single_input("New owning group?")))
- elif (cmd == "group_create"):
- output(cmd_group_create(user_id, single_input("New group name?")))
- elif (cmd == "group_delete"):
- output(cmd_group_delete(user_id, single_input("Group name?")))
- elif (cmd == "group_owner_add"):
- output(cmd_group_owner_add(user_id, single_input("Group name?"), single_input("User name?")))
- elif (cmd == "group_owner_delete"):
- output(cmd_group_owner_delete(user_id, single_input("Group name?"), single_input("User name?")))
- elif (cmd == "group_join"):
- output(cmd_group_join(user_id, single_input("Group name?"), single_input("User name?")))
- elif (cmd == "group_kick"):
- output(cmd_group_kick(user_id, single_input("Group name?"), single_input("User name?")))
- elif (cmd == "group_list"):
- output(cmd_group_list(user_id))
- elif (cmd == "admin_promote"):
- output(cmd_admin_promote(user_id, single_input("User name?")))
- elif (cmd == "admin_demote"):
- output(cmd_admin_demote(user_id, single_input("User name?")))
- elif (cmd == "service_register"):
- output(cmd_service_register(user_id, single_input("Service name?")))
- elif (cmd == "user_password"):
- output(cmd_user_password(user_id, single_input("User name?"), single_input("New password?")))
- elif (cmd == "transformation_read_signature"):
- output(cmd_transformation_signature(user_id, single_input("Transformation name?")))
- elif (cmd == "element_list_nice"):
- output(cmd_element_list_nice(user_id, single_input("Model name?"), single_input("Metamodel name?")))
- elif (cmd == "verbose"):
- set_verbose(True)
- elif (cmd == "quiet"):
- set_verbose(False)
- 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 !
- elif (cmd == "add_conformance"):
- // TODO
- cmd = "FAIL"
- elif (cmd == "remove_conformance"):
- // TODO
- cmd = "FAIL"
- elif (cmd == "user_name"):
- // TODO
- cmd = "FAIL"
- elif (cmd == "service_poll"):
- // TODO
- cmd = "FAIL"
- else:
- output("Unknown command: " + cmd)
- // We never get here!
- return !
|