core_algorithm.alc 68 KB

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