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. log("Finished elements: " + set_to_string(finished))
  373. log("Check finished")
  374. while (i < cnt):
  375. // Check each finished element individually
  376. log("Check element " + cast_v2s(dict_read(read_edge_dst(read_out(worklist, i)), 0)))
  377. if (set_in(finished, dict_read(read_edge_dst(read_out(worklist, i)), 0))):
  378. log("Yes")
  379. return True!
  380. i = i + 1
  381. log("NO")
  382. return False!
  383. Boolean function enact_action(pm : Element, element : String, prefix : String, user_id : String):
  384. Boolean result
  385. String transformation_id
  386. Element lst
  387. String elem
  388. Element inputs
  389. Element outputs
  390. String type_name
  391. String exact_type
  392. Element trace_links
  393. Element output_mms
  394. inputs = create_node()
  395. outputs = create_node()
  396. output_mms = create_node()
  397. // TODO use the prefix for data locations (in model write/read in MvC)
  398. // Read out the referenced element from the MvC
  399. transformation_id = get_model_id(read_attribute(pm, element, "name"))
  400. // Find all inputs and their types (i.e., key)
  401. lst = allAssociationOrigins(pm, element, "Consumes")
  402. while (read_nr_out(lst) > 0):
  403. elem = set_pop(lst)
  404. // As there are no inheritance relations between full models, we can just read out the typename
  405. type_name = read_attribute(pm, elem, "type")
  406. dict_add(inputs, type_name, string_join(prefix, read_attribute(pm, elem, "name")))
  407. // Find all outputs and their types (i.e., key)
  408. lst = allAssociationDestinations(pm, element, "Produces")
  409. while (read_nr_out(lst) > 0):
  410. elem = set_pop(lst)
  411. // As there are no inheritance relations between full models, we can just read out the typename
  412. type_name = read_attribute(pm, elem, "type")
  413. dict_add(outputs, type_name, string_join(prefix, read_attribute(pm, elem, "name")))
  414. dict_add(output_mms, type_name, get_full_model(get_model_id(type_name)))
  415. exact_type = read_type(core, transformation_id)
  416. if (exact_type == "ModelTransformation"):
  417. // Model transformation is always in-place and uses only a single metamodel
  418. // Therefore, we must:
  419. // 1) Create an empty model, instance of merged metamodel
  420. // 2) Merge the different source models and retype
  421. // 3) Perform the transformation on the merged model
  422. // 4) Split the resulting model based on the target formalisms
  423. //
  424. Element input_model
  425. Element schedule_model
  426. String trace_link_id
  427. Element merged_model
  428. String merged_metamodel_id
  429. String ramified_metamodel_id
  430. schedule_model = get_full_model(transformation_id)
  431. // 1) Create empty instance of merged metamodel
  432. ramified_metamodel_id = set_pop(followAssociation(core, transformation_id, "instanceOf"))
  433. trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  434. merged_metamodel_id = ""
  435. while (read_nr_out(trace_links) > 0):
  436. trace_link_id = set_pop(trace_links)
  437. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  438. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  439. if (merged_metamodel_id != ""):
  440. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  441. // 2) Merge source models
  442. String key
  443. Element keys
  444. Element input_keys
  445. Element output_keys
  446. input_keys = dict_keys(inputs)
  447. while (read_nr_out(input_keys) > 0):
  448. key = set_pop(input_keys)
  449. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  450. // 3) Transform
  451. result = transform(merged_model, schedule_model)
  452. // 4) Split in different files depending on type
  453. String desired_metamodel_id
  454. Element split_off_model
  455. output_keys = dict_keys(outputs)
  456. while (read_nr_out(output_keys) > 0):
  457. key = set_pop(output_keys)
  458. desired_metamodel_id = get_model_id(key)
  459. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  460. // Check if the destination model already exists
  461. if (get_model_id(outputs[key]) == ""):
  462. // New model
  463. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  464. else:
  465. // Model exists, so we overwrite
  466. model_overwrite(split_off_model, get_model_id(outputs[key]))
  467. else:
  468. log("Intermediate not found")
  469. elif (exact_type == "ActionLanguage"):
  470. Element dictionary
  471. Element new_inputs
  472. Element input_keys
  473. Element output_keys
  474. Element result
  475. String key
  476. Element func
  477. // 1) Group source models in dictionary
  478. // --> This is just the "inputs" variable, but resolve all references
  479. new_inputs = create_node()
  480. input_keys = dict_keys(inputs)
  481. while (read_nr_out(input_keys) > 0):
  482. key = set_pop(input_keys)
  483. dict_add(new_inputs, key, get_full_model(get_model_id(inputs[key])))
  484. inputs = new_inputs
  485. // 2) Execute action language model
  486. func = get_func_AL_model(get_full_model(transformation_id))
  487. result = func(inputs, output_mms)
  488. // 3) Split output dictionary back to seperate models
  489. output_keys = dict_keys(outputs)
  490. while (read_nr_out(output_keys) > 0):
  491. key = set_pop(output_keys)
  492. // Check if the destination model already exists
  493. if (get_model_id(outputs[key]) == ""):
  494. // New model
  495. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  496. else:
  497. // Model exists, so we overwrite
  498. model_overwrite(result[key], get_model_id(outputs[key]))
  499. elif (exact_type == "ManualOperation"):
  500. // Identical to model transformations, but give control to users for modification
  501. // 1) Create empty instance of merged metamodel
  502. Element input_model
  503. String trace_link_id
  504. Element merged_model
  505. String merged_metamodel_id
  506. trace_links = allOutgoingAssociationInstances(core, transformation_id, "tracability")
  507. merged_metamodel_id = ""
  508. while (read_nr_out(trace_links) > 0):
  509. trace_link_id = set_pop(trace_links)
  510. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  511. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  512. if (merged_metamodel_id != ""):
  513. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  514. // 2) Merge source models
  515. String key
  516. Element keys
  517. Element input_keys
  518. Element output_keys
  519. input_keys = dict_keys(inputs)
  520. while (read_nr_out(input_keys) > 0):
  521. key = set_pop(input_keys)
  522. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  523. // 3) Transform
  524. output("Please perform manual transformation " + cast_v2s(read_attribute(pm, element, "name")))
  525. modify(merged_model, True)
  526. // 4) Split in different files depending on type
  527. String desired_metamodel_id
  528. Element split_off_model
  529. output_keys = dict_keys(outputs)
  530. while (read_nr_out(output_keys) > 0):
  531. key = set_pop(output_keys)
  532. desired_metamodel_id = get_model_id(key)
  533. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  534. // Check if the destination model already exists
  535. if (get_model_id(outputs[key]) == ""):
  536. // New model
  537. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  538. else:
  539. // Model exists, so we overwrite
  540. model_overwrite(split_off_model, get_model_id(outputs[key]))
  541. else:
  542. output("Could not find merged metamodel")
  543. // TODO find out whether it succeeded or not
  544. result = True
  545. else:
  546. output("Did not know how to interpret model of type " + exact_type)
  547. return result!
  548. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  549. Element worklist
  550. String element
  551. String start
  552. String type
  553. Boolean result
  554. Element tuple
  555. Element counters
  556. Element join_nodes
  557. // Initialize Join counters
  558. counters = create_node()
  559. join_nodes = allInstances(pm, "ForkJoin")
  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. log("Enacting " + cast_v2s(element))
  571. // Find the type (to see what to do with it)
  572. // this does not yet yield the type of transformation, if it is an Execution
  573. type = read_type(pm, element)
  574. if (type == "Start"):
  575. // Initial node, just progress to the next elements
  576. // Nothing to do here though, as we have just started
  577. result = True
  578. elif (type == "Finish"):
  579. // Should be impossible, as we would have ended...
  580. result = result
  581. elif (type == "ForkJoin"):
  582. // Only do this if all dependencies are fullfilled
  583. // So add to the counter of this Join
  584. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  585. // Now check whether we have enough tokens to execute the Join itself
  586. Integer required
  587. Integer got
  588. required = read_nr_out(allIncomingAssociationInstances(pm, element, "Next")) + read_nr_out(allIncomingAssociationInstances(pm, element, "Else"))
  589. got = counters[element]
  590. if (got == required):
  591. // Reset counter to 0
  592. dict_overwrite(counters, element, 0)
  593. // And continue
  594. else:
  595. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  596. continue!
  597. elif (type == "Exec"):
  598. // Execute a transformation
  599. // This the difficult part!
  600. result = enact_action(pm, element, prefix, user_id)
  601. elif (type == "Decision"):
  602. // If the previous result is true, we add the normal one, otherwise the false one
  603. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  604. if (bool_not(result)):
  605. // Apparently it is False, so map this to the "Else" branch
  606. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  607. continue!
  608. else:
  609. // Apparently it is True, so map this to the "Then" branch
  610. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  611. continue!
  612. // We have finished the execution, so add all outgoing edges to the worklist
  613. Element all_next
  614. all_next = allAssociationDestinations(pm, element, "Next")
  615. String next
  616. while (read_nr_out(all_next) > 0):
  617. next = set_pop(all_next)
  618. log("Adding to worklist: " + next)
  619. set_add(worklist, create_tuple(next, result))
  620. log("FINISHED")
  621. // Reached a finish element, so stop
  622. return !
  623. Void function user_function_skip_init(user_id : String):
  624. String cmd
  625. output("Welcome to the Model Management Interface v2.0!")
  626. output("Use the 'help' command for a list of possible commands")
  627. while (True):
  628. output("Ready for command...")
  629. cmd = input()
  630. if (cmd == "help"):
  631. output("Model operations")
  632. output(" model_add -- Add a new model")
  633. output(" model_modify -- Modify an existing model")
  634. output(" model_list -- List all models")
  635. output(" model_list_full -- List all models with full info")
  636. output(" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata")
  637. output(" verify -- Check whether a model conforms to its metamodel")
  638. output("")
  639. output("Transformation-specific operations")
  640. output(" transformation_add_MT_language -- Create a RAMified metamodel of a set of models")
  641. output(" transformation_add_MT -- Initialize a new model transformation")
  642. output(" transformation_add_AL -- Initialize a new action language transformation")
  643. output(" transformation_add_MANUAL -- Initialize a new manual transformation")
  644. output(" transformation_execute -- Execute a transformation on a set of input models")
  645. output(" transformation_list -- List all model transformations")
  646. output(" transformation_list_full -- List all model transformations with permissions")
  647. output(" transformation_detail -- List transformation details")
  648. output(" transformation_RAMify -- RAMify a metamodel (again)")
  649. output("")
  650. output("Process operations")
  651. output(" process_execute -- Execute a process model")
  652. output("")
  653. output("Model permission operations")
  654. output(" permission_modify -- Change model permissions")
  655. output(" permission_owner -- Change model owner")
  656. output(" permission_group -- Change model group")
  657. output("")
  658. output("Group operations")
  659. output(" group_create -- Create a group")
  660. output(" group_delete -- Delete a group")
  661. output(" group_owner_add -- Add group owner")
  662. output(" group_owner_delete -- Remove group owner")
  663. output(" group_join -- Add someone to your group")
  664. output(" group_kick -- Kick someone from your group")
  665. output(" group_list -- List all groups you are a member of")
  666. output("")
  667. output("Admin operations")
  668. output(" admin_promote -- Promote a user to admin status")
  669. output(" admin_demote -- Demote a user to normal status")
  670. output("")
  671. output("General operations")
  672. output(" self-destruct -- Remove current user and revoke all permissions ")
  673. output(" exit -- Kill the current task, while retaining user")
  674. elif (cmd == "model_add"):
  675. // Model addition operation, which uses model upload commands of the compiler
  676. String name
  677. String type
  678. String location
  679. String type_id
  680. Element new_model
  681. String new_model_id
  682. output("Creating new model!")
  683. output("Model type?")
  684. type_id = get_model_id(input())
  685. if (type_id != ""):
  686. // Type exists
  687. if (allow_read(user_id, type_id)):
  688. // And is readable
  689. output("Model name?")
  690. name = input()
  691. if (get_model_id(name) == ""):
  692. // Model doesn't exist yet
  693. output("Waiting for model constructors...")
  694. new_model = construct_model_raw(get_full_model(type_id))
  695. model_create(new_model, name, user_id, type_id, "Model")
  696. output("Model upload success!")
  697. else:
  698. output("Model with that name already exists!")
  699. else:
  700. output("Permission denied")
  701. else:
  702. output("Could not find type model!")
  703. elif (cmd == "process_execute"):
  704. // Execute a process model until it reaches termination
  705. String process_id
  706. output("Which process model do you want to execute?")
  707. process_id = get_model_id(input())
  708. if (process_id != ""):
  709. if (allow_read(user_id, process_id)):
  710. output("Model prefix to use?")
  711. enact_PM(get_full_model(process_id), input(), user_id)
  712. else:
  713. output("Permission denied")
  714. else:
  715. output("No such model")
  716. elif (cmd == "transformation_execute"):
  717. // Execute a transformation, whatever type it is
  718. // First we detect the type, so we know how to prepare for invocation
  719. String transformation_id
  720. String exact_type
  721. Element sources
  722. Element targets
  723. String source
  724. String target
  725. String name_id
  726. Element inputs
  727. Element outputs
  728. Element trace_links
  729. String target_model_name
  730. String source_model_name
  731. output("Which transformation do you want to execute?")
  732. transformation_id = get_model_id(input())
  733. if (transformation_id != ""):
  734. if (allow_read(user_id, transformation_id)):
  735. if (is_nominal_instance(core, transformation_id, "Transformation")):
  736. // Read out source and target links
  737. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  738. inputs = create_node()
  739. while (read_nr_out(sources) > 0):
  740. source = set_pop(sources)
  741. output(string_join("Which model to bind for source element ", read_attribute(core, source, "name")))
  742. source_model_name = input()
  743. name_id = get_model_id(source_model_name)
  744. if (name_id != ""):
  745. if (allow_read(user_id, name_id)):
  746. // Check for conformance to the specified metamodel!
  747. Element specified_model
  748. // TODO Maybe find out which conformance relation to use, as there might be multiple!
  749. if (check_is_typed_by(name_id, source)):
  750. if (check_conformance(name_id)):
  751. dict_add(inputs, read_attribute(core, source, "name"), source_model_name)
  752. else:
  753. output("Model has correct type but does not conform completely!")
  754. set_add(sources, source)
  755. else:
  756. output("Model has different type!")
  757. set_add(sources, source)
  758. else:
  759. output("Permission denied")
  760. set_add(sources, source)
  761. else:
  762. output("No such model")
  763. set_add(sources, source)
  764. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  765. outputs = create_node()
  766. while (read_nr_out(targets) > 0):
  767. target = set_pop(targets)
  768. output(string_join("Which model to create for target element ", read_attribute(core, target, "name")))
  769. target_model_name = input()
  770. if (get_model_id(target_model_name) == ""):
  771. // Doesn't exist yet, so we can easily create
  772. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  773. else:
  774. // Already exists, so we need to check for write access
  775. if (allow_write(user_id, get_model_id(target_model_name))):
  776. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  777. else:
  778. output("Permission denied; try again")
  779. exact_type = read_type(core, transformation_id)
  780. if (exact_type == "ModelTransformation"):
  781. // Model transformation is always in-place and uses only a single metamodel
  782. // Therefore, we must:
  783. // 1) Create an empty model, instance of merged metamodel
  784. // 2) Merge the different source models and retype
  785. // 3) Perform the transformation on the merged model
  786. // 4) Split the resulting model based on the target formalisms
  787. //
  788. Element input_model
  789. Element schedule_model
  790. String trace_link_id
  791. Element merged_model
  792. String merged_metamodel_id
  793. String ramified_metamodel_id
  794. Boolean result
  795. schedule_model = get_full_model(transformation_id)
  796. // 1) Create empty instance of merged metamodel
  797. ramified_metamodel_id = set_pop(followAssociation(core, transformation_id, "instanceOf"))
  798. trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  799. merged_metamodel_id = ""
  800. while (read_nr_out(trace_links) > 0):
  801. trace_link_id = set_pop(trace_links)
  802. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  803. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  804. if (merged_metamodel_id != ""):
  805. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  806. // 2) Merge source models
  807. String key
  808. Element keys
  809. Element input_keys
  810. Element output_keys
  811. input_keys = dict_keys(inputs)
  812. while (read_nr_out(input_keys) > 0):
  813. key = set_pop(input_keys)
  814. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  815. // 3) Transform
  816. result = transform(merged_model, schedule_model)
  817. output("Transformation executed with result: " + cast_v2s(result))
  818. // 4) Split in different files depending on type
  819. String desired_metamodel_id
  820. Element split_off_model
  821. output_keys = dict_keys(outputs)
  822. while (read_nr_out(output_keys) > 0):
  823. key = set_pop(output_keys)
  824. desired_metamodel_id = get_model_id(key)
  825. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  826. // Check if the destination model already exists
  827. if (get_model_id(outputs[key]) == ""):
  828. // New model
  829. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  830. else:
  831. // Model exists, so we overwrite
  832. model_overwrite(split_off_model, get_model_id(outputs[key]))
  833. else:
  834. output("Could not resolve intermediate merged metamodel")
  835. elif (exact_type == "ActionLanguage"):
  836. Element dictionary
  837. Element new_inputs
  838. Element input_keys
  839. Element output_keys
  840. Element result
  841. String key
  842. Element func
  843. // 1) Group source models in dictionary
  844. // --> This is just the "inputs" variable, but resolve all references
  845. new_inputs = create_node()
  846. input_keys = dict_keys(inputs)
  847. while (read_nr_out(input_keys) > 0):
  848. key = set_pop(input_keys)
  849. dict_add(new_inputs, key, get_full_model(get_model_id(inputs[key])))
  850. inputs = new_inputs
  851. // 2) Execute action language model
  852. func = get_func_AL_model(get_full_model(transformation_id))
  853. result = func(inputs)
  854. // 3) Split output dictionary back to seperate models
  855. output_keys = dict_keys(outputs)
  856. while (read_nr_out(output_keys) > 0):
  857. key = set_pop(output_keys)
  858. // Check if the destination model already exists
  859. if (get_model_id(outputs[key]) == ""):
  860. // New model
  861. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  862. else:
  863. // Model exists, so we overwrite
  864. model_overwrite(result[key], get_model_id(outputs[key]))
  865. elif (exact_type == "ManualOperation"):
  866. // Identical to model transformations, but give control to users for modification
  867. // 1) Create empty instance of merged metamodel
  868. Element input_model
  869. String trace_link_id
  870. Element merged_model
  871. String merged_metamodel_id
  872. trace_links = allOutgoingAssociationInstances(core, transformation_id, "tracability")
  873. merged_metamodel_id = ""
  874. while (read_nr_out(trace_links) > 0):
  875. trace_link_id = set_pop(trace_links)
  876. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  877. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  878. if (merged_metamodel_id != ""):
  879. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  880. // 2) Merge source models
  881. String key
  882. Element keys
  883. Element input_keys
  884. Element output_keys
  885. input_keys = dict_keys(inputs)
  886. while (read_nr_out(input_keys) > 0):
  887. key = set_pop(input_keys)
  888. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  889. // 3) Transform
  890. modify(merged_model, True)
  891. // 4) Split in different files depending on type
  892. String desired_metamodel_id
  893. Element split_off_model
  894. output_keys = dict_keys(outputs)
  895. while (read_nr_out(output_keys) > 0):
  896. key = set_pop(output_keys)
  897. desired_metamodel_id = get_model_id(key)
  898. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  899. // Check if the destination model already exists
  900. if (get_model_id(outputs[key]) == ""):
  901. // New model
  902. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  903. else:
  904. // Model exists, so we overwrite
  905. model_overwrite(split_off_model, get_model_id(outputs[key]))
  906. else:
  907. output("Could not find merged metamodel")
  908. else:
  909. output("Did not know how to interpret model of type " + exact_type)
  910. else:
  911. output("Model is not an executable transformation")
  912. else:
  913. output("Permission denied")
  914. else:
  915. output("No such transformation")
  916. elif (cmd == "verify"):
  917. // Check whether a model conforms to its specification (with the selected type mapping)
  918. String model_id
  919. String result
  920. output("Which model to verify?")
  921. model_id = get_model_id(input())
  922. if (model_id != ""):
  923. if (allow_read(user_id, model_id)):
  924. result = conformance_scd(get_full_model(model_id))
  925. output(result)
  926. else:
  927. output("Permission denied")
  928. else:
  929. output("No such model")
  930. elif (cmd == "model_overwrite"):
  931. // Overwrites an existing model without changing any metadata
  932. String model_id
  933. Element new_model
  934. output("Which model to overwrite?")
  935. model_id = get_model_id(input())
  936. if (model_id != ""):
  937. if (allow_write(user_id, model_id)):
  938. if (allow_read(user_id, set_pop(followAssociation(core, model_id, "instanceOf")))):
  939. output("Waiting for model constructors...")
  940. new_model = construct_model_raw(get_full_model(set_pop(followAssociation(core, model_id, "instanceOf"))))
  941. model_overwrite(new_model, model_id)
  942. output("Model overwrite success!")
  943. else:
  944. output("Permission denied")
  945. else:
  946. output("Permission denied")
  947. else:
  948. output("No such model")
  949. elif (cmd == "model_modify"):
  950. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  951. String model_id
  952. String type_id
  953. output("Which model do you want to modify?")
  954. model_id = get_model_id(input())
  955. if (model_id != ""):
  956. if (allow_read(user_id, model_id)):
  957. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  958. if (allow_read(user_id, type_id)):
  959. modify(get_full_model(model_id), allow_write(user_id, model_id))
  960. else:
  961. output("Permission denied")
  962. else:
  963. output("Permission denied")
  964. else:
  965. output("Could not find model!")
  966. elif (cmd == "model_delete"):
  967. // Delete a model and all of its related transformations
  968. String model_id
  969. output("=================================================")
  970. output("WARNING: Deletion is a very destructive operation")
  971. output(" as it also deletes all transformations ")
  972. output(" defined which make use of this model! ")
  973. output("=================================================")
  974. output("")
  975. output("Currently not supported!")
  976. elif (cmd == "model_list"):
  977. // List all models
  978. Element models
  979. String m
  980. models = allInstances(core, "Model")
  981. while (read_nr_out(models) > 0):
  982. m = set_pop(models)
  983. output(string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name")))
  984. elif (cmd == "model_list_full"):
  985. // List all models with full info
  986. Element models
  987. String m
  988. String permissions
  989. String owner
  990. String group
  991. String name
  992. String type
  993. models = allInstances(core, "Model")
  994. while (read_nr_out(models) > 0):
  995. m = set_pop(models)
  996. permissions = read_attribute(core, m, "permissions")
  997. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  998. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  999. name = read_attribute(core, m, "name")
  1000. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1001. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)
  1002. elif (cmd == "transformation_add_MT_language"):
  1003. // Create a model transformation language from a set of input and output formalisms
  1004. String name
  1005. String model_id
  1006. Element source
  1007. Element target
  1008. Element all_formalisms
  1009. Element merged_formalism
  1010. Element ramified_formalism
  1011. String old_type_id
  1012. String type_id
  1013. String location
  1014. String new_model_id
  1015. old_type_id = ""
  1016. // Read involved formalisms
  1017. all_formalisms = create_node()
  1018. output("Formalisms to include (terminate with empty string)?")
  1019. name = input()
  1020. while (name != ""):
  1021. model_id = get_model_id(name)
  1022. if (model_id != ""):
  1023. if (allow_read(user_id, model_id)):
  1024. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1025. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1026. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1027. old_type_id = type_id
  1028. elif (old_type_id != type_id):
  1029. // Already have a previous type_id and now another: CLASH
  1030. output("Cannot add model as types not compatible with previous models; try again")
  1031. else:
  1032. output("Model not readable; try again")
  1033. else:
  1034. output("No such model; try again")
  1035. name = input()
  1036. // Merge all into a single metamodel
  1037. if (read_nr_out(all_formalisms) > 0):
  1038. output("Name of the RAMified transformation metamodel?")
  1039. name = input()
  1040. if (get_model_id(name) == ""):
  1041. String merged_formalism_id
  1042. String ramified_formalism_id
  1043. String source_formalism_id
  1044. String tracability_link
  1045. // New location is available, so write
  1046. merged_formalism = model_fuse(set_copy(all_formalisms))
  1047. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  1048. merged_formalism_id = get_model_id("__merged_" + name)
  1049. // Add tracability links at this level
  1050. while (read_nr_out(all_formalisms) > 0):
  1051. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1052. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1053. instantiate_attribute(core, tracability_link, "type", "merged")
  1054. // Merge complete, now RAMify!
  1055. ramified_formalism = ramify(merged_formalism)
  1056. model_create(ramified_formalism, name, user_id, type_id, "Model")
  1057. ramified_formalism_id = get_model_id(name)
  1058. // Add tracability link at this level
  1059. tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
  1060. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1061. else:
  1062. output("Model already exists!")
  1063. else:
  1064. output("At least one formalism is required")
  1065. elif (cmd == "transformation_RAMify"):
  1066. // RAMify a metamodel
  1067. String merged_model_id
  1068. String target_model_name
  1069. String target_model_id
  1070. Element target_model
  1071. String tracability_link
  1072. output("Which metamodel do you want to RAMify?")
  1073. merged_model_id = get_model_id(input())
  1074. if (merged_model_id != ""):
  1075. if (allow_read(user_id, merged_model_id)):
  1076. output("Where do you want to store the RAMified metamodel?")
  1077. target_model_name = input()
  1078. target_model_id = get_model_id(target_model_name)
  1079. if (target_model_id == ""):
  1080. // New model, so everything is fine
  1081. target_model = ramify(get_full_model(merged_model_id))
  1082. model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
  1083. target_model_id = get_model_id(target_model_name)
  1084. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1085. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1086. else:
  1087. // Existing model, so overwrite
  1088. if (allow_write(user_id, target_model_id)):
  1089. target_model = ramify(get_full_model(merged_model_id))
  1090. model_overwrite(target_model, target_model_id)
  1091. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
  1092. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1093. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1094. else:
  1095. output("Permission denied")
  1096. else:
  1097. output("Permission denied!")
  1098. else:
  1099. output("No such model")
  1100. elif (cmd == "transformation_add_MANUAL"):
  1101. // Add a manual transformation model
  1102. output("Which metamodels do you want to use as source for the manual operation (empty string to finish)?")
  1103. String model_id
  1104. Element models
  1105. Element source
  1106. Element target
  1107. String name
  1108. Element all_formalisms
  1109. Element merged_formalism
  1110. String merged_formalism_id
  1111. String source_formalism_id
  1112. String tracability_link
  1113. String type_id
  1114. String old_type_id
  1115. name = input()
  1116. source = create_node()
  1117. target = create_node()
  1118. all_formalisms = create_node()
  1119. type_id = ""
  1120. old_type_id = ""
  1121. while (name != ""):
  1122. model_id = get_model_id(name)
  1123. if (model_id != ""):
  1124. if (allow_read(user_id, model_id)):
  1125. if (bool_not(set_in(source, model_id))):
  1126. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1127. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1128. old_type_id = type_id
  1129. set_add(source, model_id)
  1130. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1131. output("Model added as source")
  1132. elif (old_type_id != type_id):
  1133. // Already have a previous type_id and now another: CLASH
  1134. output("Cannot add model as types not compatible with previous models; try again")
  1135. else:
  1136. output("Model already selected as source")
  1137. else:
  1138. output("Permission denied")
  1139. else:
  1140. output("No such model; try again")
  1141. name = input()
  1142. output("Which metamodels do you want to use as target for the manual operation (empty string to finish)?")
  1143. name = input()
  1144. while (name != ""):
  1145. model_id = get_model_id(name)
  1146. if (model_id != ""):
  1147. if (allow_read(user_id, model_id)):
  1148. if (bool_not(set_in(target, model_id))):
  1149. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1150. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1151. old_type_id = type_id
  1152. set_add(target, model_id)
  1153. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1154. output("Model added as target")
  1155. elif (old_type_id != type_id):
  1156. // Already have a previous type_id and now another: CLASH
  1157. output("Cannot add model as types not compatible with previous models; try again")
  1158. else:
  1159. output("Model already selected as target")
  1160. else:
  1161. output("Permission denied")
  1162. else:
  1163. output("No such model; try again")
  1164. name = input()
  1165. output("Name of Manual operation model?")
  1166. name = input()
  1167. if (get_model_id(name) == ""):
  1168. // Finished with all information, now create the model itself!
  1169. model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), name, user_id, get_model_id("ManualOperation"), "ManualOperation")
  1170. model_id = get_model_id(name)
  1171. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1172. // New location is available, so write
  1173. merged_formalism = model_fuse(set_copy(all_formalisms))
  1174. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  1175. merged_formalism_id = get_model_id("__merged_" + name)
  1176. // Add tracability links at this level
  1177. while (read_nr_out(all_formalisms) > 0):
  1178. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1179. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1180. instantiate_attribute(core, tracability_link, "type", "merged")
  1181. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1182. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1183. // Extend metadata with info on source and target
  1184. String link
  1185. String dst
  1186. while (read_nr_out(source) > 0):
  1187. dst = set_pop(source)
  1188. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1189. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1190. while (read_nr_out(target) > 0):
  1191. dst = set_pop(target)
  1192. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1193. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1194. else:
  1195. output("Model already exists")
  1196. elif (cmd == "transformation_add_AL"):
  1197. // Add an action language transformation model
  1198. output("Which metamodels do you want to use as source for the action code (empty string to finish)?")
  1199. String model_id
  1200. Element models
  1201. Element source
  1202. Element target
  1203. String name
  1204. name = input()
  1205. source = create_node()
  1206. target = create_node()
  1207. while (name != ""):
  1208. model_id = get_model_id(name)
  1209. if (model_id != ""):
  1210. if (bool_not(set_in(source, model_id))):
  1211. set_add(source, model_id)
  1212. output("Model added as source")
  1213. else:
  1214. output("Model already selected as source")
  1215. else:
  1216. output("No such model; try again")
  1217. name = input()
  1218. output("Which metamodels do you want to use as target for the action code (empty string to finish)?")
  1219. name = input()
  1220. while (name != ""):
  1221. model_id = get_model_id(name)
  1222. if (model_id != ""):
  1223. if (bool_not(set_in(target, model_id))):
  1224. set_add(target, model_id)
  1225. output("Model added as target")
  1226. else:
  1227. output("Model already selected as target")
  1228. else:
  1229. output("No such model; try again")
  1230. name = input()
  1231. output("Name of Action Language model?")
  1232. name = input()
  1233. if (get_model_id(name) == ""):
  1234. // Finished with all information, now create the model itself!
  1235. output("Waiting for model constructors...")
  1236. add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + name, construct_function())
  1237. model_create(import_node("AL/" + name), name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
  1238. model_id = get_model_id(name)
  1239. // Extend metadata with info on source and target
  1240. String link
  1241. String dst
  1242. while (read_nr_out(source) > 0):
  1243. dst = set_pop(source)
  1244. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1245. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1246. while (read_nr_out(target) > 0):
  1247. dst = set_pop(target)
  1248. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1249. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1250. else:
  1251. output("Model already exists")
  1252. elif (cmd == "transformation_add_MT"):
  1253. // Add a model transformation model
  1254. // Just a usual model instantiation, but need to add the source and target links based on user info
  1255. String ramified_metamodel_id
  1256. String model_id
  1257. Element models
  1258. Element links
  1259. String link_id
  1260. Element supported
  1261. Element source
  1262. Element target
  1263. String name
  1264. String new_model_id
  1265. String merged_link_id
  1266. Element links_merged
  1267. String merged_metamodel_id
  1268. source = create_node()
  1269. target = create_node()
  1270. supported = create_node()
  1271. output("RAMified metamodel to use?")
  1272. ramified_metamodel_id = get_model_id(input())
  1273. if (ramified_metamodel_id != ""):
  1274. if (allow_read(user_id, ramified_metamodel_id)):
  1275. output("Supported metamodels:")
  1276. links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  1277. while (read_nr_out(links) > 0):
  1278. link_id = set_pop(links)
  1279. merged_metamodel_id = readAssociationDestination(core, link_id)
  1280. if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
  1281. links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  1282. while (read_nr_out(links_merged) > 0):
  1283. merged_link_id = set_pop(links_merged)
  1284. if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
  1285. output(string_join(" ", read_attribute(core, readAssociationDestination(core, merged_link_id), "name")))
  1286. set_add(supported, readAssociationDestination(core, merged_link_id))
  1287. output("")
  1288. output("Which ones do you want to use as source (empty string to finish)?")
  1289. name = input()
  1290. while (name != ""):
  1291. model_id = get_model_id(name)
  1292. if (model_id != ""):
  1293. if (set_in(supported, model_id)):
  1294. if (bool_not(set_in(source, model_id))):
  1295. set_add(source, model_id)
  1296. output("Model added as source")
  1297. else:
  1298. output("Model already selected as source")
  1299. else:
  1300. output("Model is not supported by RAMified metamodel!")
  1301. else:
  1302. output("No such model; try again")
  1303. name = input()
  1304. output("Which ones do you want to use as target (empty string to finish)?")
  1305. name = input()
  1306. while (name != ""):
  1307. model_id = get_model_id(name)
  1308. if (model_id != ""):
  1309. if (set_in(supported, model_id)):
  1310. if (bool_not(set_in(target, model_id))):
  1311. set_add(target, model_id)
  1312. output("Model added as target")
  1313. else:
  1314. output("Model already selected as target")
  1315. else:
  1316. output("Model is not supported by RAMified metamodel!")
  1317. else:
  1318. output("No such model; try again")
  1319. name = input()
  1320. output("Name of new transformation?")
  1321. name = input()
  1322. if (get_model_id(name) == ""):
  1323. String new_model
  1324. // Finished with all information, now create the model itself!
  1325. output("Waiting for model constructors...")
  1326. new_model = construct_model_raw(get_full_model(ramified_metamodel_id))
  1327. model_create(new_model, name, user_id, ramified_metamodel_id, "ModelTransformation")
  1328. model_id = get_model_id(name)
  1329. // Extend metadata with info on source and target
  1330. String link
  1331. String dst
  1332. while (read_nr_out(source) > 0):
  1333. dst = set_pop(source)
  1334. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1335. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1336. while (read_nr_out(target) > 0):
  1337. dst = set_pop(target)
  1338. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1339. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1340. else:
  1341. output("Model already exists")
  1342. else:
  1343. output("Permission denied")
  1344. else:
  1345. output("No such model")
  1346. elif (cmd == "transformation_list"):
  1347. // List all models
  1348. Element models
  1349. String m
  1350. String type
  1351. models = allInstances(core, "Transformation")
  1352. while (read_nr_out(models) > 0):
  1353. m = set_pop(models)
  1354. 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"))))
  1355. elif (cmd == "transformation_list_full"):
  1356. // List all models with full info
  1357. Element models
  1358. String m
  1359. String permissions
  1360. String owner
  1361. String group
  1362. String name
  1363. String type
  1364. models = allInstances(core, "Transformation")
  1365. while (read_nr_out(models) > 0):
  1366. m = set_pop(models)
  1367. permissions = read_attribute(core, m, "permissions")
  1368. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1369. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1370. name = read_attribute(core, m, "name")
  1371. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1372. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type)
  1373. elif (cmd == "permission_modify"):
  1374. String permissions
  1375. Integer permission
  1376. String model_id
  1377. output("Which model do you want to change permissions of?")
  1378. model_id = get_model_id(input())
  1379. if (model_id != ""):
  1380. if (get_relation_to_model(user_id, model_id) == 0):
  1381. output("New permissions?")
  1382. permissions = input()
  1383. Boolean fail
  1384. Integer i
  1385. i = 0
  1386. if (string_len(permissions) != 3):
  1387. fail = True
  1388. while (i < 3):
  1389. permission = cast_s2i(string_get(permissions, i))
  1390. if (bool_or(permission < 0, permission > 2)):
  1391. fail = True
  1392. break!
  1393. i = i + 1
  1394. if (bool_not(fail)):
  1395. unset_attribute(core, model_id, "permissions")
  1396. instantiate_attribute(core, model_id, "permissions", permissions)
  1397. else:
  1398. output("Permissions must be a string of three characters with each character being a digit between 0 and 2")
  1399. else:
  1400. output("Permission denied!")
  1401. else:
  1402. output("No such model!")
  1403. elif (cmd == "permission_owner"):
  1404. String permissions
  1405. String model_id
  1406. String user_id
  1407. output("Which model do you want to change owner of?")
  1408. model_id = get_model_id(input())
  1409. if (model_id != ""):
  1410. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1411. output("New owner?")
  1412. user_id = get_user_id(input())
  1413. if (user_id != ""):
  1414. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1415. instantiate_link(core, "owner", "", model_id, user_id)
  1416. else:
  1417. output("No such user!")
  1418. else:
  1419. output("Permission denied!")
  1420. else:
  1421. output("No such model!")
  1422. elif (cmd == "permission_group"):
  1423. String permissions
  1424. String model_id
  1425. String group_id
  1426. output("Which model do you want to change permissions of?")
  1427. model_id = get_model_id(input())
  1428. if (model_id != ""):
  1429. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1430. output("New group?")
  1431. group_id = get_group_id(input())
  1432. if (group_id != ""):
  1433. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1434. instantiate_link(core, "group", "", model_id, group_id)
  1435. else:
  1436. output("No such group!")
  1437. else:
  1438. output("Permission denied!")
  1439. else:
  1440. output("No such model!")
  1441. elif (cmd == "group_create"):
  1442. // Create a new group and become its owner
  1443. String group_id
  1444. String name
  1445. output("Which group do you want to create?")
  1446. name = input()
  1447. group_id = get_group_id(name)
  1448. if (group_id == ""):
  1449. group_id = instantiate_node(core, "Group", "")
  1450. instantiate_attribute(core, group_id, "name", name)
  1451. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1452. instantiate_link(core, "owner", "", group_id, user_id)
  1453. output("Group created!")
  1454. else:
  1455. output("Group already exists")
  1456. elif (cmd == "group_delete"):
  1457. // Delete an existing group
  1458. String group_id
  1459. String name
  1460. output("Which group do you want to delete?")
  1461. name = input()
  1462. group_id = get_group_id(name)
  1463. if (group_id != ""):
  1464. if (allow_group_modify(user_id, group_id)):
  1465. model_delete_element(core, group_id)
  1466. else:
  1467. output("Permission denied")
  1468. else:
  1469. output("No such group")
  1470. elif (cmd == "group_owner_add"):
  1471. // Add an owner to your group
  1472. String group_id
  1473. String other_user_id
  1474. output("Which group do you want to add an owner to?")
  1475. group_id = get_group_id(input())
  1476. if (group_id != ""):
  1477. if (allow_group_modify(user_id, group_id)):
  1478. output("Which user do you want to make an owner?")
  1479. other_user_id = get_user_id(input())
  1480. if (other_user_id != ""):
  1481. Element overlap
  1482. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1483. if (read_nr_out(overlap) == 0):
  1484. instantiate_link(core, "owner", "", group_id, other_user_id)
  1485. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1486. if (read_nr_out(overlap) == 0):
  1487. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1488. output("New owner added to group!")
  1489. else:
  1490. output("User is already an owner!")
  1491. else:
  1492. output("No such user")
  1493. else:
  1494. output("Permission denied!")
  1495. else:
  1496. output("No such group")
  1497. elif (cmd == "group_owner_delete"):
  1498. // Remove an owner from your group
  1499. String group_id
  1500. String other_user_id
  1501. output("Which group do you want to disown someone from?")
  1502. group_id = get_group_id(input())
  1503. if (group_id != ""):
  1504. if (allow_group_modify(user_id, group_id)):
  1505. output("Which user do you want to disown?")
  1506. other_user_id = get_user_id(input())
  1507. if (other_user_id != ""):
  1508. Element overlap
  1509. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1510. if (read_nr_out(overlap) > 0):
  1511. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1512. if (read_nr_out(overlap) > 0):
  1513. model_delete_element(core, set_pop(overlap))
  1514. output("Disowned group from user!")
  1515. else:
  1516. output("User is not even an owner of the group!")
  1517. else:
  1518. output("User is not even a member of the group!")
  1519. else:
  1520. output("No such user")
  1521. else:
  1522. output("Permission denied!")
  1523. else:
  1524. output("No such group")
  1525. elif (cmd == "group_join"):
  1526. // Add someone to your group
  1527. String group_id
  1528. String other_user_id
  1529. output("Which group do you want to add someone to?")
  1530. group_id = get_group_id(input())
  1531. if (group_id != ""):
  1532. if (allow_group_modify(user_id, group_id)):
  1533. output("Which user do you want to add?")
  1534. other_user_id = get_user_id(input())
  1535. if (other_user_id != ""):
  1536. Element overlap
  1537. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1538. if (read_nr_out(overlap) == 0):
  1539. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1540. output("User added to the group!")
  1541. else:
  1542. output("User is already a member of the group!")
  1543. else:
  1544. output("No such user")
  1545. else:
  1546. output("Permission denied!")
  1547. else:
  1548. output("No such group")
  1549. elif (cmd == "group_kick"):
  1550. // Remove someone from your group
  1551. String group_id
  1552. String other_user_id
  1553. output("Which group do you want to kick someone from?")
  1554. group_id = get_group_id(input())
  1555. if (group_id != ""):
  1556. if (allow_group_modify(user_id, group_id)):
  1557. output("Which user do you want to kick?")
  1558. other_user_id = get_user_id(input())
  1559. if (other_user_id != ""):
  1560. Element overlap
  1561. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1562. if (read_nr_out(overlap) > 0):
  1563. model_delete_element(core, set_pop(overlap))
  1564. // Check if user was an owner as well
  1565. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1566. if (read_nr_out(overlap) > 0):
  1567. model_delete_element(core, set_pop(overlap))
  1568. output("User kicked!")
  1569. else:
  1570. output("User is not even a member of the group!")
  1571. else:
  1572. output("No such user")
  1573. else:
  1574. output("Permission denied!")
  1575. else:
  1576. output("No such group")
  1577. elif (cmd == "group_list"):
  1578. // List all groups you are a member of (and whether you are admin or not!)
  1579. Element groups
  1580. String group_id
  1581. String admin
  1582. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1583. while (read_nr_out(groups) > 0):
  1584. group_id = set_pop(groups)
  1585. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  1586. admin = " A "
  1587. else:
  1588. admin = " "
  1589. output(string_join(admin, read_attribute(core, group_id, "name")))
  1590. elif (cmd == "admin_promote"):
  1591. // Promote a user to admin status
  1592. if (is_admin(user_id)):
  1593. String other_user_id
  1594. output("Which user do you want to promote?")
  1595. other_user_id = get_user_id(input())
  1596. if (other_user_id != ""):
  1597. unset_attribute(core, other_user_id, "admin")
  1598. instantiate_attribute(core, other_user_id, "admin", True)
  1599. output("Permissions granted!")
  1600. else:
  1601. output("No such user!")
  1602. else:
  1603. output("Permission denied!")
  1604. elif (cmd == "admin_demote"):
  1605. // Demote a user to normal status
  1606. if (is_admin(user_id)):
  1607. String other_user_id
  1608. output("Which user do you want to demote?")
  1609. other_user_id = get_user_id(input())
  1610. if (other_user_id != ""):
  1611. unset_attribute(core, other_user_id, "admin")
  1612. instantiate_attribute(core, other_user_id, "admin", False)
  1613. output("Permissions revoked!")
  1614. else:
  1615. output("No such user!")
  1616. else:
  1617. output("Permission denied!")
  1618. elif (cmd == "self-destruct"):
  1619. // Delete user from Core Formalism
  1620. model_delete_element(core, user_id)
  1621. return !
  1622. elif (cmd == "exit"):
  1623. // Exit by actually removing the user and decoupling it from all of its models
  1624. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1625. // as the current user will have been deleted
  1626. return !
  1627. else:
  1628. output("Unknown command: " + cmd)
  1629. // We never get here!
  1630. return !