core_algorithm.alc 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. include "modelling.alh"
  2. include "library.alh"
  3. include "primitives.alh"
  4. include "constructors.alh"
  5. include "object_operations.alh"
  6. include "mini_modify.alh"
  7. include "model_management.alh"
  8. include "ramify.alh"
  9. include "conformance_scd.alh"
  10. include "transform.alh"
  11. include "metamodels.alh"
  12. Element core = ?
  13. String admin_username = "admin"
  14. String admin_password = "admin"
  15. String core_location = "models/CoreFormalism"
  16. String core_model_location = "core"
  17. String function JSON_print(model : Element):
  18. String result
  19. Element keys_m
  20. String v_m
  21. String type
  22. String attr_key
  23. Element attr_keys
  24. Boolean first
  25. Element attr_value
  26. result = "["
  27. keys_m = dict_keys(model["model"])
  28. first = True
  29. while (read_nr_out(keys_m) > 0):
  30. v_m = set_pop(keys_m)
  31. type = read_type(model["metamodel"], read_type(model, v_m))
  32. if (bool_or(type == "Class", type == "Association")):
  33. if (bool_not(first)):
  34. result = result + ","
  35. else:
  36. first = False
  37. result = result + "{"
  38. result = (((result + "\"id\": \"") + v_m) + "\"")
  39. result = (((result + ",") + "\"type\": \"") + read_type(model, v_m)) + "\""
  40. if (type == "Association"):
  41. result = (((result + ", \"__source\": \"") + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + "\"")
  42. result = (((result + ", \"__target\": \"") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m]))) + "\"")
  43. // Has attributes
  44. attr_keys = dict_keys(getAttributeList(model, v_m))
  45. while (0 < read_nr_out(attr_keys)):
  46. attr_key = set_pop(attr_keys)
  47. attr_value = read_attribute(model, v_m, attr_key)
  48. if (element_eq(attr_value, read_root())):
  49. result = (((result + ", \"") + attr_key) + "\": null")
  50. else:
  51. if (is_physical_boolean(attr_value)):
  52. if (attr_value):
  53. result = ((result + ", \"") + attr_key) + "\": true"
  54. else:
  55. result = ((result + ", \"") + attr_key) + "\": false"
  56. else:
  57. result = ((((result + ", \"") + attr_key) + "\": ") + cast_v2s(attr_value))
  58. result = result + "}"
  59. result = result + "]"
  60. return result!
  61. Void function initialize_core():
  62. // Initialize the Core Formalism
  63. String core_model
  64. String core_formalism_model
  65. String scd_model
  66. Element al_model
  67. String admin_group
  68. String admin_user
  69. String nobody_group
  70. String instance_of
  71. String core_formalism
  72. Element scd
  73. Element al
  74. Element pm
  75. Element tracability
  76. String pm_model
  77. String tracability_model
  78. String coreM_model_location
  79. String pm_location
  80. String scd_location
  81. String al_location
  82. String tracability_location
  83. coreM_model_location = "models/core"
  84. pm_location = "models/ProcessModel"
  85. scd_location = "models/SimpleClassDiagrams"
  86. al_location = "models/ActionLanguage"
  87. tracability_location = "models/Tracability"
  88. scd = import_node(scd_location)
  89. al = import_node(al_location)
  90. pm = import_node(pm_location)
  91. tracability = import_node(tracability_location)
  92. // Create the Model itself and make public
  93. core_formalism = import_node(core_location)
  94. core = instantiate_model(core_formalism)
  95. export_node(core_model_location, core)
  96. export_node(coreM_model_location, core["model"])
  97. // Create admin group
  98. admin_group = instantiate_node(core, "Group", "")
  99. instantiate_attribute(core, admin_group, "name", "admin")
  100. // Create nobody group
  101. nobody_group = instantiate_node(core, "Group", "")
  102. instantiate_attribute(core, nobody_group, "name", "nobody")
  103. // Create admin user
  104. admin_user = instantiate_node(core, "User", "")
  105. instantiate_attribute(core, admin_user, "name", admin_username)
  106. instantiate_attribute(core, admin_user, "admin", True)
  107. instantiate_attribute(core, admin_user, "password", hash(admin_password))
  108. // Create link between admin user and group
  109. instantiate_link(core, "ownedBy", "", admin_group, admin_user)
  110. instantiate_link(core, "belongsTo", "", admin_user, admin_group)
  111. // Add the SimpleClassDiagrams formalism already
  112. scd_model = instantiate_node(core, "Model", "")
  113. instantiate_attribute(core, scd_model, "name", "SimpleClassDiagrams")
  114. instantiate_attribute(core, scd_model, "location", scd_location + "/model")
  115. instantiate_attribute(core, scd_model, "permissions", "221")
  116. instance_of = instantiate_link(core, "instanceOf", "", scd_model, scd_model)
  117. instantiate_attribute(core, instance_of, "type_mapping", scd["type_mapping"])
  118. // Make necessary links for the formalism to the owners
  119. instantiate_link(core, "group", "", scd_model, admin_group)
  120. instantiate_link(core, "owner", "", scd_model, admin_user)
  121. // Add the Tracability formalism
  122. tracability_model = instantiate_node(core, "Model", "")
  123. instantiate_attribute(core, tracability_model, "name", "Tracability")
  124. instantiate_attribute(core, tracability_model, "location", tracability_location + "/model")
  125. instantiate_attribute(core, tracability_model, "permissions", "221")
  126. instance_of = instantiate_link(core, "instanceOf", "", tracability_model, scd_model)
  127. instantiate_attribute(core, instance_of, "type_mapping", tracability["type_mapping"])
  128. // Add the user/group links
  129. instantiate_link(core, "group", "", tracability_model, admin_group)
  130. instantiate_link(core, "owner", "", tracability_model, admin_user)
  131. // Add the Process Model formalism
  132. pm_model = instantiate_node(core, "Model", "")
  133. instantiate_attribute(core, pm_model, "name", "ProcessModel")
  134. instantiate_attribute(core, pm_model, "location", pm_location + "/model")
  135. instantiate_attribute(core, pm_model, "permissions", "221")
  136. instance_of = instantiate_link(core, "instanceOf", "", pm_model, scd_model)
  137. instantiate_attribute(core, instance_of, "type_mapping", pm["type_mapping"])
  138. // Make necessary links for the formalism to the owners
  139. instantiate_link(core, "group", "", pm_model, admin_group)
  140. instantiate_link(core, "owner", "", pm_model, admin_user)
  141. // Add the Action Language formalism
  142. al_model = instantiate_node(core, "Model", "")
  143. instantiate_attribute(core, al_model, "name", "ActionLanguage")
  144. instantiate_attribute(core, al_model, "location", al_location + "/model")
  145. instantiate_attribute(core, al_model, "permissions", "221")
  146. instance_of = instantiate_link(core, "instanceOf", "", al_model, scd_model)
  147. instantiate_attribute(core, instance_of, "type_mapping", al["type_mapping"])
  148. // Make necessary links for the formalism to the owners
  149. instantiate_link(core, "group", "", al_model, admin_group)
  150. instantiate_link(core, "owner", "", al_model, admin_user)
  151. // Add the Manual Operation formalism
  152. Element manual
  153. String manual_model
  154. manual = instantiate_model(scd)
  155. manual_model = instantiate_node(core, "Model", "")
  156. export_node("models/ManualOperation", manual)
  157. instantiate_attribute(core, manual_model, "name", "ManualOperation")
  158. instantiate_attribute(core, manual_model, "location", "models/ManualOperation/model")
  159. instantiate_attribute(core, manual_model, "permissions", "221")
  160. instance_of = instantiate_link(core, "instanceOf", "", manual_model, scd_model)
  161. instantiate_attribute(core, instance_of, "type_mapping", create_node())
  162. // Make necessary links for the formalism to the owners
  163. instantiate_link(core, "group", "", manual_model, admin_group)
  164. instantiate_link(core, "owner", "", manual_model, admin_user)
  165. // Add the core formalism already
  166. core_formalism_model = instantiate_node(core, "Model", "")
  167. instantiate_attribute(core, core_formalism_model, "name", "CoreFormalism")
  168. instantiate_attribute(core, core_formalism_model, "location", core_location + "/model")
  169. instantiate_attribute(core, core_formalism_model, "permissions", "221")
  170. instance_of = instantiate_link(core, "instanceOf", "", core_formalism_model, scd_model)
  171. instantiate_attribute(core, instance_of, "type_mapping", core_formalism["type_mapping"])
  172. // Make necessary links for the formalism to the owners
  173. instantiate_link(core, "group", "", core_formalism_model, admin_group)
  174. instantiate_link(core, "owner", "", core_formalism_model, admin_user)
  175. // Add the core model
  176. core_model = instantiate_node(core, "Model", "")
  177. instantiate_attribute(core, core_model, "name", "core")
  178. instantiate_attribute(core, core_model, "location", coreM_model_location)
  179. instantiate_attribute(core, core_model, "permissions", "200")
  180. instance_of = instantiate_link(core, "instanceOf", "", core_model, core_formalism_model)
  181. instantiate_attribute(core, instance_of, "type_mapping", core["type_mapping"])
  182. // Make necessary links for the formalism to the owners
  183. instantiate_link(core, "group", "", core_model, admin_group)
  184. instantiate_link(core, "owner", "", core_model, admin_user)
  185. // Call this for ourselves as well
  186. //log("MvC is ready!")
  187. return !
  188. String function get_instanceOf_link(model_id : String):
  189. Element all_links
  190. String choice
  191. all_links = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  192. if (read_nr_out(all_links) > 1):
  193. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  194. elif (read_nr_out(all_links) == 0):
  195. log("ERROR: untyped model!")
  196. choice = set_pop(allOutgoingAssociationInstances(core, model_id, "instanceOf"))
  197. return choice!
  198. Element function get_full_model(model_id : String):
  199. Element m
  200. Element all_links
  201. String choice
  202. choice = get_instanceOf_link(model_id)
  203. m = create_node()
  204. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  205. dict_add(m, "type_mapping", read_attribute(core, choice, "type_mapping"))
  206. if (readAssociationDestination(core, choice) == model_id):
  207. // Found the meta-circular level, so we can stop!
  208. dict_add(m, "metamodel", m)
  209. else:
  210. dict_add(m, "metamodel", get_full_model(readAssociationDestination(core, choice)))
  211. return m!
  212. Integer function get_relation_to_model(user_id : String, model_id : String):
  213. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  214. // We are the owner
  215. return 0!
  216. else:
  217. String group_id
  218. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  219. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  220. // We are in the owning group
  221. return 1!
  222. else:
  223. // We are not related whatsoever
  224. return 2!
  225. Boolean function is_admin(user_id : String):
  226. if (read_attribute(core, user_id, "admin")):
  227. return True!
  228. else:
  229. return False!
  230. Boolean function allow_read(user_id : String, model_id : String):
  231. if (is_admin(user_id)):
  232. // Is admin, so always allow
  233. return True!
  234. else:
  235. // Check permissions
  236. String permission
  237. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  238. if (bool_or(permission == "1", permission == "2")):
  239. return True!
  240. else:
  241. return False!
  242. Boolean function allow_write(user_id : String, model_id : String):
  243. if (is_admin(user_id)):
  244. // Is admin, so always allow
  245. return True!
  246. else:
  247. // Check permissions
  248. String permission
  249. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  250. if (permission == "2"):
  251. return True!
  252. else:
  253. return False!
  254. Boolean function allow_change_metadata(user_id : String, model_id : String):
  255. if (is_admin(user_id)):
  256. // Is admin, so always allow
  257. return True!
  258. else:
  259. if (get_relation_to_model(user_id, model_id) == 0):
  260. // Only owner can chmod
  261. return True!
  262. else:
  263. return False!
  264. Boolean function allow_group_modify(user_id : String, group_id : String):
  265. if (is_admin(user_id)):
  266. // Is admin, so always allow
  267. return True!
  268. else:
  269. if (read_nr_out(set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))) > 0):
  270. // We are an owner
  271. return True!
  272. else:
  273. return False!
  274. Boolean function check_login(user_id : String):
  275. String password
  276. String stored_password
  277. stored_password = read_attribute(core, user_id, "password")
  278. output("Password for existing user?")
  279. password = hash(input())
  280. return password == stored_password!
  281. Element function extract_ftg(user_id : String):
  282. // Extract your personal FTG, showing only the readable models that can be opened
  283. // This function does the actual projection of transformations
  284. // TODO: Only keep transformations satisfying some properties!
  285. return create_node()!
  286. Void function new_task():
  287. String username
  288. String user_id
  289. String password
  290. // Load in a hard-reference to the previously created model
  291. core = import_node(core_model_location)
  292. while (True):
  293. output("Log on as which user?")
  294. username = input()
  295. user_id = get_user_id(username)
  296. if (user_id == ""):
  297. // New user
  298. // Add user to Core Formalism
  299. user_id = instantiate_node(core, "User", "")
  300. instantiate_attribute(core, user_id, "name", username)
  301. instantiate_attribute(core, user_id, "admin", False)
  302. output("This is a new user: please give password!")
  303. password = hash(input())
  304. output("Please repeat the password")
  305. if (password == hash(input())):
  306. output("Passwords match!")
  307. instantiate_attribute(core, user_id, "password", password)
  308. break!
  309. else:
  310. output("Not the same password!")
  311. else:
  312. if (check_login(user_id)):
  313. break!
  314. else:
  315. output("Wrong password!")
  316. user_function_skip_init(user_id)
  317. // User destroyed already, so just stop execution
  318. return!
  319. String function get_model_id(name : String):
  320. Element models
  321. String model
  322. models = allInstances(core, "Model")
  323. while (read_nr_out(models) > 0):
  324. model = set_pop(models)
  325. if (value_eq(name, read_attribute(core, model, "name"))):
  326. return model!
  327. return ""!
  328. String function get_user_id(name : String):
  329. Element users
  330. String user
  331. users = allInstances(core, "User")
  332. while (read_nr_out(users) > 0):
  333. user = set_pop(users)
  334. if (value_eq(read_attribute(core, user, "name"), name)):
  335. return user!
  336. return ""!
  337. String function get_group_id(name : String):
  338. Element groups
  339. String group
  340. groups = allInstances(core, "Group")
  341. while (read_nr_out(groups) > 0):
  342. group = set_pop(groups)
  343. if (value_eq(read_attribute(core, group, "name"), name)):
  344. return group!
  345. return ""!
  346. Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
  347. String location
  348. String model_id
  349. String instance_of
  350. location = "models/" + cast_id2s(model)
  351. export_node(location, model["model"])
  352. // Manage meta-info
  353. model_id = instantiate_node(core, kind, "")
  354. instantiate_attribute(core, model_id, "name", name)
  355. instantiate_attribute(core, model_id, "location", location)
  356. instantiate_attribute(core, model_id, "permissions", "200")
  357. instantiate_link(core, "owner", "", model_id, user_id)
  358. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  359. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  360. instantiate_attribute(core, instance_of, "type_mapping", model["type_mapping"])
  361. return!
  362. Void function model_overwrite(model : Element, model_id : String):
  363. String location
  364. String instanceOf_link
  365. location = "models/" + cast_id2s(model)
  366. export_node(location, model["model"])
  367. // Change location in meta-data
  368. unset_attribute(core, model_id, "location")
  369. instantiate_attribute(core, model_id, "location", location)
  370. instanceOf_link = get_instanceOf_link(model_id)
  371. unset_attribute(core, instanceOf_link, "type_mapping")
  372. instantiate_attribute(core, instanceOf_link, "type_mapping", model["type_mapping"])
  373. return!
  374. Boolean function check_is_typed_by(model_id : String, metamodel_id : String):
  375. // TODO check if there is actually an instanceOf link between them
  376. // --> quick check!
  377. return True!
  378. Boolean function check_conformance(model_id : String):
  379. // TODO check if it actually conforms, considering that instanceOf link
  380. // --> in-depth check
  381. return True!
  382. Boolean function pm_finished(worklist : Element, pm : String):
  383. Element finished
  384. Integer cnt
  385. Integer i
  386. // Check if any of the "finish" elements are in the worklist
  387. // If so, we can already finish, and therefore will stop immediately
  388. finished = allInstances(pm, "Finish")
  389. i = 0
  390. cnt = read_nr_out(finished)
  391. while (i < cnt):
  392. // Check each finished element individually
  393. if (set_in(finished, dict_read(read_edge_dst(read_out(worklist, i)), 0))):
  394. return True!
  395. i = i + 1
  396. return False!
  397. Element function execute_operation(operation_id : String, input_models : Element, output_metamodels : Element, tracability_model : Element):
  398. // Operations are always in-place and uses only a single metamodel
  399. // Therefore, we must:
  400. // 1) Find merged metamodel
  401. // 2) Merge the different source models and retype
  402. // 3) Perform the operation on the merged model
  403. // 4) Split the resulting model based on the target formalisms; if operation successful
  404. Element input_model
  405. String trace_link_id
  406. Element merged_model
  407. String merged_metamodel_id
  408. String ramified_metamodel_id
  409. Boolean result
  410. String exact_type
  411. Element trace_links
  412. String linktype
  413. String model_ID
  414. String key
  415. Element keys
  416. Element input_keys
  417. Element output_keys
  418. Element model_tuples
  419. String metamodel_name
  420. Element metamodel
  421. String metamodel_ID
  422. Boolean tracability
  423. // 1) Find merged metamodel
  424. exact_type = read_type(core, operation_id)
  425. if (exact_type == "ModelTransformation"):
  426. linktype = "RAMified"
  427. ramified_metamodel_id = set_pop(allAssociationDestinations(core, operation_id, "instanceOf"))
  428. trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  429. elif (exact_type == "ManualOperation"):
  430. linktype = "operatesOn"
  431. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  432. elif (exact_type == "ActionLanguage"):
  433. linktype = "operatesOn"
  434. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  435. else:
  436. // Don't know how to execute this operation!
  437. return read_root()!
  438. merged_metamodel_id = ""
  439. while (read_nr_out(trace_links) > 0):
  440. trace_link_id = set_pop(trace_links)
  441. if (value_eq(read_attribute(core, trace_link_id, "type"), linktype)):
  442. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  443. if (merged_metamodel_id != ""):
  444. // 2) Merge source models
  445. model_tuples = create_node()
  446. while (read_nr_out(input_models) > 0):
  447. model_ID = get_model_id(set_pop(input_models))
  448. input_model = get_full_model(model_ID)
  449. metamodel_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_ID, "instanceOf")), "name")
  450. set_add(model_tuples, create_tuple(metamodel_name, input_model))
  451. merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id), tracability_model)
  452. // 3) Transform
  453. if (exact_type == "ModelTransformation"):
  454. result = transform(merged_model, get_full_model(operation_id))
  455. elif (exact_type == "ManualOperation"):
  456. output("Please perform manual operation " + cast_v2s(read_attribute(core, operation_id, "name")))
  457. modify(merged_model, True)
  458. result = True
  459. elif (exact_type == "ActionLanguage"):
  460. Element func
  461. func = get_func_AL_model(get_full_model(operation_id))
  462. result = func(merged_model)
  463. else:
  464. log("ERROR")
  465. // 4) Split in different models depending on type
  466. if (element_neq(tracability_model, read_root())):
  467. tracability = True
  468. else:
  469. tracability = False
  470. if (result):
  471. model_tuples = create_node()
  472. while (read_nr_out(output_metamodels) > 0):
  473. metamodel_ID = get_model_id(set_pop(output_metamodels))
  474. metamodel_name = read_attribute(core, metamodel_ID, "name")
  475. metamodel = get_full_model(metamodel_ID)
  476. set_add(model_tuples, create_tuple(metamodel_name, metamodel))
  477. result = model_split(merged_model, model_tuples, tracability)
  478. if (tracability):
  479. Element new_tracability_model
  480. new_tracability_model = result["__tracability"]
  481. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  482. dict_overwrite(tracability_model, "type_mapping", new_tracability_model["type_mapping"])
  483. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  484. dict_delete(result, "__tracability")
  485. return result!
  486. else:
  487. return read_root()!
  488. else:
  489. output("Could not resolve intermediate merged metamodel")
  490. return read_root()!
  491. Boolean function enact_action(pm : Element, element : String, prefix : String, user_id : String):
  492. Boolean result
  493. String transformation_id
  494. Element lst
  495. String elem
  496. Element inputs
  497. Element outputs
  498. String type_name
  499. String exact_type
  500. Element trace_links
  501. Element output_mms
  502. Element consumes_link
  503. String name
  504. String value
  505. String elem_name
  506. Element keys
  507. String key
  508. inputs = create_node()
  509. outputs = create_node()
  510. // Read out the referenced element from the MvC
  511. transformation_id = get_model_id(read_attribute(pm, element, "name"))
  512. // Find all input model names
  513. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  514. while (read_nr_out(lst) > 0):
  515. value = read_attribute(pm, readAssociationDestination(pm, set_pop(lst)), "name")
  516. set_add(inputs, prefix + value)
  517. // Find all output model names and their metamodel
  518. lst = allAssociationDestinations(pm, element, "Produces")
  519. while (read_nr_out(lst) > 0):
  520. elem = set_pop(lst)
  521. type_name = read_attribute(pm, elem, "type")
  522. elem_name = read_attribute(pm, elem, "name")
  523. dict_add(outputs, type_name, prefix + elem_name)
  524. if read_type(core, transformation_id) == "ActionLanguage":
  525. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  526. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  527. elif read_type(core, transformation_id) == "ManualOperation":
  528. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  529. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  530. else:
  531. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  532. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  533. result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
  534. if (element_eq(result, read_root())):
  535. // Something went wrong!
  536. return False!
  537. else:
  538. keys = dict_keys(result)
  539. while (read_nr_out(keys) > 0):
  540. key = set_pop(keys)
  541. if (get_model_id(outputs[key]) == ""):
  542. // New model
  543. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  544. else:
  545. model_overwrite(result[key], get_model_id(outputs[key]))
  546. return True!
  547. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  548. Element worklist
  549. String element
  550. String start
  551. String type
  552. Boolean result
  553. Element tuple
  554. Element counters
  555. Element join_nodes
  556. output("Success")
  557. // Initialize Join counters
  558. counters = create_node()
  559. join_nodes = allInstances(pm, "Join")
  560. while (read_nr_out(join_nodes) > 0):
  561. dict_add(counters, set_pop(join_nodes), 0)
  562. // Create the worklist with the Start instance as first element
  563. worklist = create_node()
  564. set_add(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  565. while (bool_not(pm_finished(worklist, pm))):
  566. // Pop a random element from the list and execute it
  567. tuple = set_pop(worklist)
  568. element = tuple[0]
  569. result = tuple[1]
  570. // Find the type (to see what to do with it)
  571. // this does not yet yield the type of transformation, if it is an Execution
  572. type = read_type(pm, element)
  573. if (type == "Start"):
  574. // Initial node, just progress to the next elements
  575. // Nothing to do here though, as we have just started
  576. result = True
  577. elif (type == "Finish"):
  578. // Should be impossible, as we would have ended...
  579. result = result
  580. elif (type == "Fork"):
  581. result = result
  582. elif (type == "Join"):
  583. // Only do this if all dependencies are fullfilled
  584. // So add to the counter of this Join
  585. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  586. // Now check whether we have enough tokens to execute the Join itself
  587. Integer required
  588. Integer got
  589. required = read_nr_out(allIncomingAssociationInstances(pm, element, "Next")) + read_nr_out(allIncomingAssociationInstances(pm, element, "Else"))
  590. got = counters[element]
  591. if (got == required):
  592. // Reset counter to 0
  593. dict_overwrite(counters, element, 0)
  594. // And continue
  595. else:
  596. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  597. continue!
  598. elif (type == "Exec"):
  599. // Execute a transformation
  600. // This the difficult part!
  601. result = enact_action(pm, element, prefix, user_id)
  602. elif (type == "Decision"):
  603. // If the previous result is true, we add the normal one, otherwise the false one
  604. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  605. if (bool_not(result)):
  606. // Apparently it is False, so map this to the "Else" branch
  607. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  608. continue!
  609. else:
  610. // Apparently it is True, so map this to the "Then" branch
  611. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  612. continue!
  613. // We have finished the execution, so add all outgoing edges to the worklist
  614. Element all_next
  615. all_next = allAssociationDestinations(pm, element, "Next")
  616. String next
  617. while (read_nr_out(all_next) > 0):
  618. next = set_pop(all_next)
  619. set_add(worklist, create_tuple(next, result))
  620. // Reached a finish element, so stop
  621. output("Success")
  622. return !
  623. String function cmd_help(user_id : String):
  624. String result
  625. result = ""
  626. result = result + ("Model operations\n")
  627. result = result + (" model_add -- Add a new model\n")
  628. result = result + (" model_modify -- Modify an existing model\n")
  629. result = result + (" model_list -- List all models\n")
  630. result = result + (" model_list_full -- List all models with full info\n")
  631. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  632. result = result + (" model_render -- Render a given model with a specified mapper\n")
  633. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  634. result = result + ("\n")
  635. result = result + ("Transformation-specific operations\n")
  636. result = result + (" transformation_add_MT_language -- Create a RAMified metamodel of a set of models\n")
  637. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  638. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  639. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  640. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  641. result = result + (" transformation_list -- List all model transformations\n")
  642. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  643. result = result + (" transformation_detail -- List transformation details\n")
  644. result = result + (" transformation_RAMify -- RAMify a metamodel (again)\n")
  645. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  646. result = result + ("\n")
  647. result = result + ("Process operations\n")
  648. result = result + (" process_execute -- Execute a process model\n")
  649. result = result + ("\n")
  650. result = result + ("Model permission operations\n")
  651. result = result + (" permission_modify -- Change model permissions\n")
  652. result = result + (" permission_owner -- Change model owner\n")
  653. result = result + (" permission_group -- Change model group\n")
  654. result = result + ("\n")
  655. result = result + ("Group operations\n")
  656. result = result + (" group_create -- Create a group\n")
  657. result = result + (" group_delete -- Delete a group\n")
  658. result = result + (" group_owner_add -- Add group owner\n")
  659. result = result + (" group_owner_delete -- Remove group owner\n")
  660. result = result + (" group_join -- Add someone to your group\n")
  661. result = result + (" group_kick -- Kick someone from your group\n")
  662. result = result + (" group_list -- List all groups you are a member of\n")
  663. result = result + ("\n")
  664. if (is_admin(user_id)):
  665. result = result + ("Admin operations\n")
  666. result = result + (" admin_promote -- Promote a user to admin status\n")
  667. result = result + (" admin_demote -- Demote a user to normal status\n")
  668. result = result + ("\n")
  669. result = result + ("General operations\n")
  670. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  671. result = result + (" exit -- Kill the current task, while retaining user\n")
  672. return result!
  673. String function cmd_model_add(user_id : String, type : String, name : String):
  674. // Model addition operation, which uses model upload commands of the compiler
  675. String location
  676. String type_id
  677. Element new_model
  678. String new_model_id
  679. type_id = get_model_id(type)
  680. if (type_id != ""):
  681. // Type exists
  682. if (allow_read(user_id, type_id)):
  683. // And is readable
  684. if (get_model_id(name) == ""):
  685. // Model doesn't exist yet
  686. output("Waiting for model constructors...")
  687. new_model = construct_model_raw(get_full_model(type_id))
  688. model_create(new_model, name, user_id, type_id, "Model")
  689. return "Success"!
  690. else:
  691. return "Model exists: " + name!
  692. else:
  693. return "Permission denied to model: " + type!
  694. else:
  695. return "Model not found: " + type!
  696. String function cmd_process_execute(user_id : String, process : String, prefix : String):
  697. // Execute a process model until it reaches termination
  698. String process_id
  699. process_id = get_model_id(process)
  700. if (process_id != ""):
  701. if (allow_read(user_id, process_id)):
  702. enact_PM(get_full_model(process_id), prefix, user_id)
  703. return "Success"!
  704. else:
  705. return "Permission denied to model: " + process!
  706. else:
  707. return "Model not found: " + process!
  708. String function cmd_transformation_between(user_id : String, source_name : String, target_name : String):
  709. String source_id
  710. String target_id
  711. Element onSource
  712. Element onTarget
  713. Element result
  714. String transformation
  715. source_id = get_model_id(source_name)
  716. if (source_id != ""):
  717. target_id = get_model_id(target_name)
  718. if (target_id != ""):
  719. onSource = allAssociationOrigins(core, source_id, "transformInput")
  720. onTarget = allAssociationOrigins(core, target_id, "transformOutput")
  721. result = set_overlap(onSource, onTarget)
  722. String r
  723. r = "Success: "
  724. while (read_nr_out(result) > 0):
  725. transformation = set_pop(result)
  726. if (allow_read(user_id, transformation)):
  727. r = r + string_join(read_attribute(core, transformation, "name"), "\n")
  728. return r!
  729. else:
  730. return "Model not found: " + target_name!
  731. else:
  732. return "Model not found: " + source_name!
  733. String function cmd_model_render(user_id : String, model_name : String, mapper_name : String):
  734. String model_ID
  735. String mapper_ID
  736. String rendered_name
  737. String tracability_name
  738. String type_ID
  739. Element inputs
  740. Element outputs
  741. Element rendered_model
  742. Element tracability_model
  743. Element result
  744. Element out_links
  745. Element in_links
  746. model_ID = get_model_id(model_name)
  747. if (model_ID != ""):
  748. mapper_ID = get_model_id(mapper_name)
  749. if (allow_read(user_id, model_ID)):
  750. if (mapper_ID != ""):
  751. if (allow_read(user_id, mapper_ID)):
  752. // Everything is fine; start the actual operation
  753. // Find metamodel to render to
  754. rendered_name = (("__RENDERED_" + model_name) + "__") + mapper_name
  755. tracability_name = (("__TRACABILITY_" + model_name) + "__") + mapper_name
  756. // Take the abstract syntax model and the previously rendered model
  757. inputs = create_node()
  758. set_add(inputs, model_name)
  759. set_add(inputs, rendered_name)
  760. // Generate a new rendered model only (no write to original model!)
  761. outputs = create_node()
  762. out_links = allAssociationDestinations(core, mapper_ID, "transformOutput")
  763. in_links = allAssociationDestinations(core, mapper_ID, "transformInput")
  764. while(read_nr_out(out_links) > 0):
  765. type_ID = set_pop(out_links)
  766. if (bool_not(set_in(in_links, type_ID))):
  767. // It is not the AS model, but another one (the MM_rendered)
  768. break!
  769. // Add the model itself as output as well, as otherwise tracability links get messed up!
  770. set_add(outputs, read_attribute(core, set_pop(allAssociationDestinations(core, get_model_id(model_name), "instanceOf")), "name"))
  771. set_add(outputs, read_attribute(core, type_ID, "name"))
  772. // Rendered model doesn't exist yet, so create first
  773. if (get_model_id(rendered_name) == ""):
  774. // Rendered model doesn't exist yet, so create first!
  775. rendered_model = instantiate_model(get_full_model(type_ID))
  776. model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
  777. // Tracability model won't exist either
  778. tracability_model = instantiate_model(get_full_model(get_model_id("Tracability")))
  779. model_create(tracability_model, tracability_name, user_id, get_model_id("Tracability"), "Model")
  780. else:
  781. // Read out tracability model
  782. tracability_model = get_full_model(get_model_id(tracability_name))
  783. // Do the operation itself!
  784. result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
  785. // Overwrite the previous rendered model
  786. model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
  787. // Tracability updated in-place
  788. model_overwrite(tracability_model, get_model_id(tracability_name))
  789. tracability_model = get_full_model(get_model_id(tracability_name))
  790. // Also output the resulting model
  791. return "Success: " + JSON_print(get_full_model(get_model_id(rendered_name)))!
  792. else:
  793. return "Permission denied to model: " + mapper_name!
  794. else:
  795. return "Model not found: " + mapper_name!
  796. else:
  797. return "Permission denied to model: " + model_name!
  798. else:
  799. return "Model not found: " + model_name!
  800. String function cmd_transformation_execute(user_id : String, transformation_name : String, source_models : Element, target_models : Element):
  801. // Execute a transformation, whatever type it is
  802. // First we detect the type, so we know how to prepare for invocation
  803. String transformation_id
  804. String exact_type
  805. Element sources
  806. Element targets
  807. String source
  808. String target
  809. Element inputs
  810. Element outputs
  811. Element trace_links
  812. String target_model_name
  813. String source_model_name
  814. String source_model_ID
  815. Element result
  816. Element keys
  817. String key
  818. transformation_id = get_model_id(transformation_name)
  819. if (transformation_id != ""):
  820. if (allow_read(user_id, transformation_id)):
  821. if (is_nominal_instance(core, transformation_id, "Transformation")):
  822. // Read out source and target links
  823. inputs = create_node()
  824. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  825. while (read_nr_out(sources) > 0):
  826. source = set_pop(sources)
  827. if (dict_in(source_models, read_attribute(core, readAssociationDestination(core, source), "name"))):
  828. source_model_name = source_models[read_attribute(core, readAssociationDestination(core, source), "name")]
  829. else:
  830. return string_join("Source model not bound: ", read_attribute(core, readAssociationDestination(core, source), "name"))!
  831. source_model_ID = get_model_id(source_model_name)
  832. if (source_model_ID != ""):
  833. if (allow_read(user_id, source_model_ID)):
  834. // Check for conformance to the requested metamodel
  835. if (check_is_typed_by(source_model_ID, source)):
  836. if (check_conformance(source_model_ID)):
  837. set_add(inputs, source_model_name)
  838. continue!
  839. else:
  840. return "Incorrectly typed model: " + source_model_name!
  841. else:
  842. return "Incorrectly typed model: " + source_model_name!
  843. else:
  844. return "Permission denied to model: " + source_model_name!
  845. else:
  846. return "Model not found: " + source_model_name!
  847. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  848. outputs = create_node()
  849. while (read_nr_out(targets) > 0):
  850. target = set_pop(targets)
  851. if (dict_in(target_models, read_attribute(core, readAssociationDestination(core, target), "name"))):
  852. target_model_name = target_models[read_attribute(core, readAssociationDestination(core, target), "name")]
  853. else:
  854. return string_join("Target model not bound: ", read_attribute(core, readAssociationDestination(core, target), "name"))!
  855. if (get_model_id(target_model_name) == ""):
  856. // Doesn't exist yet, so we can easily create
  857. dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
  858. else:
  859. // Already exists, so we need to check for write access
  860. if (allow_write(user_id, get_model_id(target_model_name))):
  861. dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
  862. else:
  863. return "Permission denied to model: " + target_model_name!
  864. if (read_type(core, transformation_id) == "ActionLanguage"):
  865. output("Success: ready for AL execution")
  866. elif (read_type(core, transformation_id) == "ManualOperation"):
  867. output("Success: ready for MANUAL execution")
  868. else:
  869. output("Success: ready for MT execution")
  870. result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
  871. // Now write out the models again
  872. if (element_eq(result, read_root())):
  873. // Something went wrong!
  874. return "Failure"!
  875. else:
  876. keys = dict_keys(result)
  877. while (read_nr_out(keys) > 0):
  878. key = set_pop(keys)
  879. if (get_model_id(outputs[key]) == ""):
  880. // New model
  881. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  882. else:
  883. model_overwrite(result[key], get_model_id(outputs[key]))
  884. return "Success"!
  885. else:
  886. return "Model is not executable: " + transformation_name!
  887. else:
  888. return "Permission denied to model: " + transformation_name!
  889. else:
  890. return "Model not found: " + transformation_name!
  891. String function cmd_verify(user_id : String, model_name : String):
  892. // Check whether a model conforms to its specification (with the selected type mapping)
  893. String model_id
  894. String result
  895. model_id = get_model_id(model_name)
  896. if (model_id != ""):
  897. if (allow_read(user_id, model_id)):
  898. result = conformance_scd(get_full_model(model_id))
  899. return "Success: " + result!
  900. else:
  901. return "Permission denied to model: " + model_name!
  902. else:
  903. return "Model not found: " + model_name!
  904. String function cmd_model_overwrite(user_id : String, model_name : String):
  905. // Overwrites an existing model without changing any metadata
  906. String model_id
  907. String type_id
  908. Element new_model
  909. model_id = get_model_id(model_name)
  910. if (model_id != ""):
  911. if (allow_write(user_id, model_id)):
  912. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  913. if (allow_read(user_id, type_id)):
  914. output("Waiting for model constructors...")
  915. new_model = construct_model_raw(get_full_model(set_pop(allAssociationDestinations(core, model_id, "instanceOf"))))
  916. model_overwrite(new_model, model_id)
  917. return "Success"!
  918. else:
  919. return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
  920. else:
  921. return "Permission denied to model: " + model_name!
  922. else:
  923. return "Model not found: " + model_name!
  924. String function cmd_model_modify(user_id : String, model_name : String):
  925. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  926. String model_id
  927. String type_id
  928. model_id = get_model_id(model_name)
  929. if (model_id != ""):
  930. if (allow_read(user_id, model_id)):
  931. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  932. if (allow_read(user_id, type_id)):
  933. output("Success")
  934. modify(get_full_model(model_id), allow_write(user_id, model_id))
  935. return "Success"!
  936. else:
  937. return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
  938. else:
  939. return "Permission denied to model: " + model_name!
  940. else:
  941. return "Model not found: " + model_name!
  942. String function cmd_model_delete(user_id : String, model_name : String):
  943. return "Not implemented: model_delete"!
  944. String function cmd_model_list():
  945. // List all models
  946. Element models
  947. String result
  948. String m
  949. result = "Success: "
  950. models = allInstances(core, "Model")
  951. while (read_nr_out(models) > 0):
  952. m = set_pop(models)
  953. result = (result + string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))) + "\n"
  954. return result!
  955. String function cmd_model_list_full():
  956. // List all models with full info
  957. Element models
  958. String m
  959. String permissions
  960. String owner
  961. String group
  962. String name
  963. String type
  964. String result
  965. result = "Success: "
  966. models = allInstances(core, "Model")
  967. while (read_nr_out(models) > 0):
  968. m = set_pop(models)
  969. permissions = read_attribute(core, m, "permissions")
  970. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  971. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  972. name = read_attribute(core, m, "name")
  973. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  974. result = (result + (((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)) + "\n"
  975. return result!
  976. String function cmd_transformation_add_MT_language(user_id : String, model_names : Element, RAMified_name : String):
  977. // Create a model transformation language from a set of input and output formalisms
  978. String model_name
  979. String model_id
  980. Element source
  981. Element target
  982. Element all_formalisms
  983. Element merged_formalism
  984. Element ramified_formalism
  985. String type_id
  986. String location
  987. String new_model_id
  988. String type_name
  989. // Read involved formalisms
  990. all_formalisms = create_node()
  991. while (read_nr_out(model_names) > 0):
  992. model_name = set_pop(model_names)
  993. model_id = get_model_id(model_name)
  994. if (model_id != ""):
  995. if (allow_read(user_id, model_id)):
  996. type_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_id, "instanceOf")), "name")
  997. type_id = get_model_id(type_name)
  998. if (type_name != "SimpleClassDiagrams"):
  999. return "Can only RAMify models of type SimpleClassDiagrams"!
  1000. else:
  1001. set_add(all_formalisms, create_tuple(model_name, get_full_model(model_id)))
  1002. else:
  1003. return "Permission denied to model: " + model_name!
  1004. else:
  1005. return "Model not found: " + model_name!
  1006. // Merge all into a single metamodel
  1007. if (read_nr_out(all_formalisms) > 0):
  1008. if (get_model_id(RAMified_name) == ""):
  1009. String merged_formalism_id
  1010. String ramified_formalism_id
  1011. String source_formalism_id
  1012. String tracability_link
  1013. // New location is available, so write
  1014. merged_formalism = model_fuse(set_copy(all_formalisms))
  1015. model_create(merged_formalism, "__merged_" + RAMified_name, user_id, type_id, "Model")
  1016. merged_formalism_id = get_model_id("__merged_" + RAMified_name)
  1017. // Add tracability links at this level
  1018. while (read_nr_out(all_formalisms) > 0):
  1019. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1020. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1021. instantiate_attribute(core, tracability_link, "type", "merged")
  1022. // Merge complete, now RAMify!
  1023. ramified_formalism = ramify(merged_formalism)
  1024. model_create(ramified_formalism, RAMified_name, user_id, type_id, "Model")
  1025. ramified_formalism_id = get_model_id(RAMified_name)
  1026. // Add tracability link at this level
  1027. tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
  1028. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1029. return "Success"!
  1030. else:
  1031. return "Model exists: " + RAMified_name!
  1032. else:
  1033. return "At least one formalism is required"!
  1034. String function cmd_transformation_RAMify(user_id : String, merged_model_name : String, target_model_name : String):
  1035. // RAMify a metamodel
  1036. String merged_model_id
  1037. String target_model_id
  1038. Element target_model
  1039. String tracability_link
  1040. merged_model_id = get_model_id(merged_model_name)
  1041. if (merged_model_id != ""):
  1042. if (allow_read(user_id, merged_model_id)):
  1043. target_model_id = get_model_id(target_model_name)
  1044. if (target_model_id == ""):
  1045. // New model, so everything is fine
  1046. target_model = ramify(get_full_model(merged_model_id))
  1047. model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
  1048. target_model_id = get_model_id(target_model_name)
  1049. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1050. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1051. else:
  1052. // Existing model, so overwrite
  1053. if (allow_write(user_id, target_model_id)):
  1054. target_model = ramify(get_full_model(merged_model_id))
  1055. model_overwrite(target_model, target_model_id)
  1056. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
  1057. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1058. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1059. else:
  1060. return "Permission denied to model: " + target_model_name!
  1061. return "Success"!
  1062. else:
  1063. return "Permission denied to model: " + merged_model_name!
  1064. else:
  1065. return "Model not found: " + merged_model_name!
  1066. String function cmd_transformation_add_MANUAL(user_id : String, source_model_names : Element, target_model_names : Element, operation_name : String):
  1067. return transformation_add(user_id, source_model_names, target_model_names, operation_name, "manual")!
  1068. String function cmd_transformation_add_AL(user_id : String, source_model_names : Element, target_model_names : Element, operation_name : String):
  1069. return transformation_add(user_id, source_model_names, target_model_names, operation_name, "actionlanguage")!
  1070. String function transformation_add(user_id : String, source_model_names : Element, target_model_names : Element, operation_name : String, operation_type : String):
  1071. // Add a manual transformation model
  1072. String model_id
  1073. Element models
  1074. Element source
  1075. Element target
  1076. String name
  1077. Element all_formalisms
  1078. Element merged_formalism
  1079. String merged_formalism_id
  1080. String source_formalism_id
  1081. String tracability_link
  1082. String type_id
  1083. String old_type_id
  1084. source = create_node()
  1085. target = create_node()
  1086. all_formalisms = create_node()
  1087. type_id = ""
  1088. old_type_id = ""
  1089. while (read_nr_out(source_model_names) > 0):
  1090. name = set_pop(source_model_names)
  1091. model_id = get_model_id(name)
  1092. if (model_id != ""):
  1093. if (allow_read(user_id, model_id)):
  1094. if (bool_not(set_in(source, model_id))):
  1095. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1096. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1097. old_type_id = type_id
  1098. set_add(source, model_id)
  1099. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1100. elif (old_type_id != type_id):
  1101. // Already have a previous type_id and now another: CLASH
  1102. return "Cannot add model as type not compatible with previous models: " + name!
  1103. else:
  1104. return "Model already selected as source: " + name!
  1105. else:
  1106. return "Permission denied to model: " + name!
  1107. else:
  1108. return "Model not found: " + name!
  1109. while (read_nr_out(target_model_names) > 0):
  1110. name = set_pop(target_model_names)
  1111. model_id = get_model_id(name)
  1112. if (model_id != ""):
  1113. if (allow_read(user_id, model_id)):
  1114. if (bool_not(set_in(target, model_id))):
  1115. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1116. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1117. old_type_id = type_id
  1118. set_add(target, model_id)
  1119. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1120. elif (old_type_id != type_id):
  1121. // Already have a previous type_id and now another: CLASH
  1122. return "Cannot add mdoel as type not compatible with previous models: " + name!
  1123. else:
  1124. return "Model already selected as target: " + name!
  1125. else:
  1126. return "Permission denied to model: " + name!
  1127. else:
  1128. return "Model not found: " + name!
  1129. if (get_model_id(operation_name) == ""):
  1130. if (operation_type == "manual"):
  1131. // Finished with all information, now create the model itself!
  1132. model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), operation_name, user_id, get_model_id("ManualOperation"), "ManualOperation")
  1133. model_id = get_model_id(operation_name)
  1134. elif (operation_type == "actionlanguage"):
  1135. // Finished with all information, now create the model itself!
  1136. output("Waiting for code constructors...")
  1137. add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + operation_name, construct_function())
  1138. model_create(import_node("AL/" + operation_name), operation_name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
  1139. model_id = get_model_id(operation_name)
  1140. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1141. // New location is available, so write
  1142. merged_formalism = model_fuse(set_copy(all_formalisms))
  1143. model_create(merged_formalism, "__merged_" + operation_name, user_id, type_id, "Model")
  1144. merged_formalism_id = get_model_id("__merged_" + operation_name)
  1145. // Add tracability links at this level
  1146. while (read_nr_out(all_formalisms) > 0):
  1147. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1148. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1149. instantiate_attribute(core, tracability_link, "type", "merged")
  1150. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1151. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1152. // Extend metadata with info on source and target
  1153. String link
  1154. String dst
  1155. while (read_nr_out(source) > 0):
  1156. dst = set_pop(source)
  1157. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1158. while (read_nr_out(target) > 0):
  1159. dst = set_pop(target)
  1160. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1161. return "Success"!
  1162. else:
  1163. return "Model exists: " + operation_name!
  1164. String function cmd_transformation_add_MT(user_id : String, RAMified_metamodel_name : String, source_models : Element, target_models : Element, operation_name : String):
  1165. // Add a model transformation model
  1166. // Just a usual model instantiation, but need to add the source and target links based on user info
  1167. String ramified_metamodel_id
  1168. String model_id
  1169. Element models
  1170. Element links
  1171. String link_id
  1172. Element supported
  1173. Element source
  1174. Element target
  1175. String name
  1176. String new_model_id
  1177. String merged_link_id
  1178. Element links_merged
  1179. String merged_metamodel_id
  1180. source = create_node()
  1181. target = create_node()
  1182. supported = create_node()
  1183. ramified_metamodel_id = get_model_id(RAMified_metamodel_name)
  1184. if (ramified_metamodel_id != ""):
  1185. if (allow_read(user_id, ramified_metamodel_id)):
  1186. links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  1187. while (read_nr_out(links) > 0):
  1188. link_id = set_pop(links)
  1189. merged_metamodel_id = readAssociationDestination(core, link_id)
  1190. if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
  1191. links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  1192. while (read_nr_out(links_merged) > 0):
  1193. merged_link_id = set_pop(links_merged)
  1194. if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
  1195. set_add(supported, readAssociationDestination(core, merged_link_id))
  1196. while (read_nr_out(source_models) > 0):
  1197. name = set_pop(source_models)
  1198. model_id = get_model_id(name)
  1199. if (model_id != ""):
  1200. if (set_in(supported, model_id)):
  1201. if (bool_not(set_in(source, model_id))):
  1202. set_add(source, model_id)
  1203. else:
  1204. return "Model already selected: " + name!
  1205. else:
  1206. return "Model not supported by RAMified metamodel: " + name!
  1207. else:
  1208. return "Model not found: " + name!
  1209. while (read_nr_out(target_models) > 0):
  1210. name = set_pop(target_models)
  1211. model_id = get_model_id(name)
  1212. if (model_id != ""):
  1213. if (set_in(supported, model_id)):
  1214. if (bool_not(set_in(target, model_id))):
  1215. set_add(target, model_id)
  1216. else:
  1217. return "Model already selected: " + name!
  1218. else:
  1219. return "Model not supported by RAMified metamodel: " + name!
  1220. else:
  1221. return "Model not found: " + name!
  1222. if (get_model_id(operation_name) == ""):
  1223. String new_model
  1224. // Finished with all information, now create the model itself!
  1225. output("Waiting for model constructors...")
  1226. new_model = construct_model_raw(get_full_model(ramified_metamodel_id))
  1227. model_create(new_model, operation_name, user_id, ramified_metamodel_id, "ModelTransformation")
  1228. model_id = get_model_id(operation_name)
  1229. // Extend metadata with info on source and target
  1230. String link
  1231. String dst
  1232. while (read_nr_out(source) > 0):
  1233. dst = set_pop(source)
  1234. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1235. while (read_nr_out(target) > 0):
  1236. dst = set_pop(target)
  1237. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1238. return "Success"!
  1239. else:
  1240. return "Model exists: " + operation_name!
  1241. else:
  1242. return "Permission denied to model: " + operation_name!
  1243. else:
  1244. return "Model not found: " + operation_name!
  1245. String function cmd_transformation_list():
  1246. // List all models
  1247. Element models
  1248. String m
  1249. String type
  1250. String result
  1251. result = "Success: "
  1252. models = allInstances(core, "Transformation")
  1253. while (read_nr_out(models) > 0):
  1254. m = set_pop(models)
  1255. 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")
  1256. return result!
  1257. String function cmd_transformation_list_full():
  1258. // List all models with full info
  1259. Element models
  1260. String m
  1261. String permissions
  1262. String owner
  1263. String group
  1264. String name
  1265. String type
  1266. String result
  1267. result = ""
  1268. models = allInstances(core, "Transformation")
  1269. while (read_nr_out(models) > 0):
  1270. m = set_pop(models)
  1271. permissions = read_attribute(core, m, "permissions")
  1272. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1273. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1274. name = read_attribute(core, m, "name")
  1275. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1276. result = result + ((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type) + "\n")
  1277. return result!
  1278. String function cmd_permission_modify(user_id : String, model_name : String, permissions : String):
  1279. Integer permission
  1280. String model_id
  1281. model_id = get_model_id(model_name)
  1282. if (model_id != ""):
  1283. if (get_relation_to_model(user_id, model_id) == 0):
  1284. Boolean fail
  1285. Integer i
  1286. i = 0
  1287. if (string_len(permissions) != 3):
  1288. fail = True
  1289. while (i < 3):
  1290. permission = cast_s2i(string_get(permissions, i))
  1291. if (bool_or(permission < 0, permission > 2)):
  1292. fail = True
  1293. break!
  1294. i = i + 1
  1295. if (bool_not(fail)):
  1296. unset_attribute(core, model_id, "permissions")
  1297. instantiate_attribute(core, model_id, "permissions", permissions)
  1298. return "Success"!
  1299. else:
  1300. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1301. else:
  1302. return "Permission denied to model: " + model_name!
  1303. else:
  1304. return "Model not found: " + model_name!
  1305. String function cmd_permission_owner(user_id : String, model_name : String, new_user_name : String):
  1306. String model_id
  1307. String new_user_id
  1308. model_id = get_model_id(model_name)
  1309. if (model_id != ""):
  1310. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1311. new_user_id = get_user_id(new_user_name)
  1312. if (new_user_id != ""):
  1313. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1314. instantiate_link(core, "owner", "", model_id, new_user_id)
  1315. return "Success"!
  1316. else:
  1317. return "No such user: " + new_user_name!
  1318. else:
  1319. return "Permission denied to model: " + model_name!
  1320. else:
  1321. return "Model not found: " + model_name!
  1322. String function cmd_permission_group(user_id : String, model_name : String, new_group_name : String):
  1323. String model_id
  1324. String group_id
  1325. model_id = get_model_id(model_name)
  1326. if (model_id != ""):
  1327. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1328. group_id = get_group_id(new_group_name)
  1329. if (group_id != ""):
  1330. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1331. instantiate_link(core, "group", "", model_id, group_id)
  1332. return "Success"!
  1333. else:
  1334. return "No such group: " + new_group_name!
  1335. else:
  1336. return "Permission denied to model: " + model_name!
  1337. else:
  1338. return "Model not found: " + model_name!
  1339. String function cmd_group_create(user_id : String, group_name : String):
  1340. // Create a new group and become its owner
  1341. String group_id
  1342. String name
  1343. group_id = get_group_id(group_name)
  1344. if (group_id == ""):
  1345. group_id = instantiate_node(core, "Group", "")
  1346. instantiate_attribute(core, group_id, "name", group_name)
  1347. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1348. instantiate_link(core, "owner", "", group_id, user_id)
  1349. return "Success"!
  1350. else:
  1351. return "Group exists: " + group_name!
  1352. String function cmd_group_delete(user_id : String, group_name : String):
  1353. // Delete an existing group
  1354. String group_id
  1355. group_id = get_group_id(group_name)
  1356. if (group_id != ""):
  1357. if (allow_group_modify(user_id, group_id)):
  1358. model_delete_element(core, group_id)
  1359. return "Success"!
  1360. else:
  1361. return "Permission denied to group: " + group_name!
  1362. else:
  1363. return "Group not found: " + group_name!
  1364. String function cmd_group_owner_add(user_id : String, group_name : String, other_user_name : String):
  1365. // Add an owner to your group
  1366. String group_id
  1367. String other_user_id
  1368. group_id = get_group_id(group_name)
  1369. if (group_id != ""):
  1370. if (allow_group_modify(user_id, group_id)):
  1371. other_user_id = get_user_id(other_user_name)
  1372. if (other_user_id != ""):
  1373. Element overlap
  1374. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1375. if (read_nr_out(overlap) == 0):
  1376. instantiate_link(core, "owner", "", group_id, other_user_id)
  1377. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1378. if (read_nr_out(overlap) == 0):
  1379. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1380. return "Success"!
  1381. else:
  1382. return "User is already the owner!"!
  1383. else:
  1384. return "User not found: " + other_user_name!
  1385. else:
  1386. return "Permission denied to group: " + group_name!
  1387. else:
  1388. return "Group not found: " + group_name!
  1389. String function cmd_group_owner_delete(user_id : String, group_name : String, other_user_name : String):
  1390. // Remove an owner from your group
  1391. String group_id
  1392. String other_user_id
  1393. group_id = get_group_id(group_name)
  1394. if (group_id != ""):
  1395. if (allow_group_modify(user_id, group_id)):
  1396. other_user_id = get_user_id(other_user_name)
  1397. if (other_user_id != ""):
  1398. Element overlap
  1399. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1400. if (read_nr_out(overlap) > 0):
  1401. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1402. if (read_nr_out(overlap) > 0):
  1403. model_delete_element(core, set_pop(overlap))
  1404. return "Success"!
  1405. else:
  1406. return "User is not an owner of the group!"!
  1407. else:
  1408. return "User is not a member of the group!"!
  1409. else:
  1410. return "User not found: " + other_user_name!
  1411. else:
  1412. return "Permission denied to group: " + group_name!
  1413. else:
  1414. return "Group not found: " + group_name!
  1415. String function cmd_group_join(user_id : String, group_name : String, other_user_name : String):
  1416. // Add someone to your group
  1417. String group_id
  1418. String other_user_id
  1419. group_id = get_group_id(group_name)
  1420. if (group_id != ""):
  1421. if (allow_group_modify(user_id, group_id)):
  1422. other_user_id = get_user_id(other_user_name)
  1423. if (other_user_id != ""):
  1424. Element overlap
  1425. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1426. if (read_nr_out(overlap) == 0):
  1427. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1428. return "Success"!
  1429. else:
  1430. return "User is already a member of the group!"!
  1431. else:
  1432. return "User not found: " + other_user_name!
  1433. else:
  1434. return "Permission denied to group: " + group_name!
  1435. else:
  1436. return "Group not found: " + group_name!
  1437. String function cmd_group_kick(user_id : String, group_name : String, other_user_name : String):
  1438. // Remove someone from your group
  1439. String group_id
  1440. String other_user_id
  1441. group_id = get_group_id(group_name)
  1442. if (group_id != ""):
  1443. if (allow_group_modify(user_id, group_id)):
  1444. other_user_id = get_user_id(other_user_name)
  1445. if (other_user_id != ""):
  1446. Element overlap
  1447. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1448. if (read_nr_out(overlap) > 0):
  1449. model_delete_element(core, set_pop(overlap))
  1450. // Check if user was an owner as well
  1451. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1452. if (read_nr_out(overlap) > 0):
  1453. model_delete_element(core, set_pop(overlap))
  1454. return "Success"!
  1455. else:
  1456. return "User is not a member of the group!"!
  1457. else:
  1458. return "User not found: " + other_user_name!
  1459. else:
  1460. return "Permission denied to group: " + group_name!
  1461. else:
  1462. return "Group not found: " + group_name!
  1463. String function cmd_group_list(user_id : String):
  1464. // List all groups you are a member of (and whether you are admin or not!)
  1465. Element groups
  1466. String group_id
  1467. String admin
  1468. String result
  1469. result = ""
  1470. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1471. while (read_nr_out(groups) > 0):
  1472. group_id = set_pop(groups)
  1473. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  1474. admin = " A "
  1475. else:
  1476. admin = " "
  1477. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1478. return result!
  1479. String function cmd_admin_promote(user_id : String, other_user_name : String):
  1480. // Promote a user to admin status
  1481. if (is_admin(user_id)):
  1482. String other_user_id
  1483. other_user_id = get_user_id(other_user_name)
  1484. if (other_user_id != ""):
  1485. unset_attribute(core, other_user_id, "admin")
  1486. instantiate_attribute(core, other_user_id, "admin", True)
  1487. return "Success"!
  1488. else:
  1489. return "User not found: " + other_user_name!
  1490. else:
  1491. return "Permission denied to administrate: " + other_user_name!
  1492. String function cmd_admin_demote(user_id : String, other_user_name : String):
  1493. // Demote a user to normal status
  1494. if (is_admin(user_id)):
  1495. String other_user_id
  1496. other_user_id = get_user_id(other_user_name)
  1497. if (other_user_id != ""):
  1498. unset_attribute(core, other_user_id, "admin")
  1499. instantiate_attribute(core, other_user_id, "admin", False)
  1500. return "Success"!
  1501. else:
  1502. return "User not found: " + other_user_name!
  1503. else:
  1504. return "Permission denied to administrate: " + other_user_name!
  1505. Void function user_function_skip_init(user_id : String):
  1506. String cmd
  1507. output("Welcome to the Model Management Interface v2.0!")
  1508. output("Use the 'help' command for a list of possible commands")
  1509. while (True):
  1510. cmd = input()
  1511. if (cmd == "help"):
  1512. output(cmd_help(user_id))
  1513. elif (cmd == "model_add"):
  1514. output(cmd_model_add(user_id, single_input("Model type?"), single_input("Model name?")))
  1515. elif (cmd == "process_execute"):
  1516. output(cmd_process_execute(user_id, single_input("Process to execute?"), single_input("Model prefix to use?")))
  1517. elif (cmd == "transformation_between"):
  1518. output(cmd_transformation_between(user_id, single_input("Source type?"), single_input("Target type?")))
  1519. elif (cmd == "model_render"):
  1520. output(cmd_model_render(user_id, single_input("Model name?"), single_input("Mapper name?")))
  1521. elif (cmd == "transformation_execute"):
  1522. output(cmd_transformation_execute(user_id, single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
  1523. elif (cmd == "verify"):
  1524. output(cmd_verify(user_id, single_input("Model name?")))
  1525. elif (cmd == "model_overwrite"):
  1526. output(cmd_model_overwrite(user_id, single_input("Model name?")))
  1527. elif (cmd == "model_modify"):
  1528. output(cmd_model_modify(user_id, single_input("Model name?")))
  1529. elif (cmd == "model_delete"):
  1530. output(cmd_model_delete(user_id, single_input("Model name?")))
  1531. elif (cmd == "model_list"):
  1532. output(cmd_model_list())
  1533. elif (cmd == "model_list_full"):
  1534. output(cmd_model_list_full())
  1535. elif (cmd == "transformation_add_MT_language"):
  1536. output(cmd_transformation_add_MT_language(user_id, set_input("Metamodel names?"), single_input("RAMified metamodel name?")))
  1537. elif (cmd == "transformation_RAMify"):
  1538. output(cmd_transformation_RAMify(user_id, single_input("Metamodel name?"), single_input("Target metamodel name?")))
  1539. elif (cmd == "transformation_add_MANUAL"):
  1540. output(cmd_transformation_add_MANUAL(user_id, set_input("Source model names?"), set_input("Target model names?"), single_input("Operation name?")))
  1541. elif (cmd == "transformation_add_AL"):
  1542. output(cmd_transformation_add_AL(user_id, set_input("Source model names?"), set_input("Target model names?"), single_input("Operation name?")))
  1543. elif (cmd == "transformation_add_MT"):
  1544. output(cmd_transformation_add_MT(user_id, single_input("RAMified metamodel name?"), set_input("Source model names?"), set_input("Target models?"), single_input("Operation name?")))
  1545. elif (cmd == "transformation_list"):
  1546. output(cmd_transformation_list())
  1547. elif (cmd == "transformation_list_full"):
  1548. output(cmd_transformation_list_full())
  1549. elif (cmd == "permission_modify"):
  1550. output(cmd_permission_modify(user_id, single_input("Model name?"), single_input("Permissions?")))
  1551. elif (cmd == "permission_owner"):
  1552. output(cmd_permission_owner(user_id, single_input("Model name?"), single_input("New owning user?")))
  1553. elif (cmd == "permission_group"):
  1554. output(cmd_permission_group(user_id, single_input("Model name?"), single_input("New owning group?")))
  1555. elif (cmd == "group_create"):
  1556. output(cmd_group_create(user_id, single_input("New group name?")))
  1557. elif (cmd == "group_delete"):
  1558. output(cmd_group_delete(user_id, single_input("Group name?")))
  1559. elif (cmd == "group_owner_add"):
  1560. output(cmd_group_owner_add(user_id, single_input("Group name?"), single_input("User name?")))
  1561. elif (cmd == "group_owner_delete"):
  1562. output(cmd_group_owner_delete(user_id, single_input("Group name?"), single_input("User name?")))
  1563. elif (cmd == "group_join"):
  1564. output(cmd_group_join(user_id, single_input("Group name?"), single_input("User name?")))
  1565. elif (cmd == "group_kick"):
  1566. output(cmd_group_kick(user_id, single_input("Group name?"), single_input("User name?")))
  1567. elif (cmd == "group_list"):
  1568. output(cmd_group_list(user_id))
  1569. elif (cmd == "admin_promote"):
  1570. output(cmd_admin_promote(user_id, single_input("User name?")))
  1571. elif (cmd == "admin_demote"):
  1572. output(cmd_admin_demote(user_id, single_input("User name?")))
  1573. elif (cmd == "verbose"):
  1574. set_verbose(True)
  1575. elif (cmd == "quiet"):
  1576. set_verbose(False)
  1577. elif (cmd == "self-destruct"):
  1578. // Delete user from Core Formalism
  1579. model_delete_element(core, user_id)
  1580. return !
  1581. elif (cmd == "exit"):
  1582. // Exit by actually removing the user and decoupling it from all of its models
  1583. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1584. // as the current user will have been deleted
  1585. return !
  1586. else:
  1587. output("Unknown command: " + cmd)
  1588. // We never get here!
  1589. return !