core_algorithm.alc 69 KB

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