core_algorithm.alc 69 KB

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