core_algorithm.alc 67 KB

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