core_algorithm.alc 67 KB

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