core_algorithm.alc 69 KB

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