core_algorithm.alc 69 KB

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