core_algorithm.alc 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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. String coreM_model_location = "models/core"
  16. Void function main():
  17. // Initialize the Core Formalism
  18. String core_model
  19. String core_formalism_model
  20. String scd_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. String scd_location
  28. scd_location = "models/SimpleClassDiagrams"
  29. scd = import_node(scd_location)
  30. // Create the Model itself and make public
  31. core_formalism = import_node(core_location)
  32. core = instantiate_model(core_formalism)
  33. export_node(core_model_location, core)
  34. export_node(coreM_model_location, core["model"])
  35. // Switch all new users to the user_function
  36. // This accesses the bootstrap level, so do not change this unless you know what you are doing
  37. Element root
  38. Element prev
  39. root = read_root()
  40. root = root["__hierarchy"]["__IP"]
  41. while (value_neq(root, !call)):
  42. prev = root
  43. root = root["next"]
  44. dict_delete(prev, "next")
  45. dict_add(prev, "next", user_function["body"])
  46. // Create admin group
  47. admin_group = instantiate_node(core, "Group", "")
  48. instantiate_attribute(core, admin_group, "name", "admin")
  49. // Create nobody group
  50. nobody_group = instantiate_node(core, "Group", "")
  51. instantiate_attribute(core, nobody_group, "name", "nobody")
  52. // Create admin user
  53. admin_user = instantiate_node(core, "User", "")
  54. output("Desired username for admin user?")
  55. instantiate_attribute(core, admin_user, "name", input())
  56. instantiate_attribute(core, admin_user, "admin", True)
  57. String password
  58. while (True):
  59. output("Desired password for admin user?")
  60. password = hash(input())
  61. output("Please repeat the password")
  62. if (password == hash(input())):
  63. output("Passwords match!")
  64. instantiate_attribute(core, admin_user, "password", password)
  65. break!
  66. else:
  67. output("Not the same password, please try again!")
  68. // Create link between admin user and group
  69. instantiate_link(core, "ownedBy", "", admin_group, admin_user)
  70. instantiate_link(core, "belongsTo", "", admin_user, admin_group)
  71. // Add the SimpleClassDiagrams formalism already
  72. scd_model = instantiate_node(core, "Model", "")
  73. instantiate_attribute(core, scd_model, "name", "SimpleClassDiagrams")
  74. instantiate_attribute(core, scd_model, "location", scd_location + "/model")
  75. instantiate_attribute(core, scd_model, "permissions", "221")
  76. instance_of = instantiate_link(core, "instanceOf", "", scd_model, scd_model)
  77. instantiate_attribute(core, instance_of, "type_mapping", scd["type_mapping"])
  78. // Make necessary links for the formalism to the owners
  79. instantiate_link(core, "group", "", scd_model, admin_group)
  80. instantiate_link(core, "owner", "", scd_model, admin_user)
  81. // Add the core formalism already
  82. core_formalism_model = instantiate_node(core, "Model", "")
  83. instantiate_attribute(core, core_formalism_model, "name", "CoreFormalism")
  84. instantiate_attribute(core, core_formalism_model, "location", core_location + "/model")
  85. instantiate_attribute(core, core_formalism_model, "permissions", "221")
  86. instance_of = instantiate_link(core, "instanceOf", "", core_formalism_model, scd_model)
  87. instantiate_attribute(core, instance_of, "type_mapping", core_formalism["type_mapping"])
  88. // Make necessary links for the formalism to the owners
  89. instantiate_link(core, "group", "", core_formalism_model, admin_group)
  90. instantiate_link(core, "owner", "", core_formalism_model, admin_user)
  91. // Add the core model
  92. core_model = instantiate_node(core, "Model", "")
  93. instantiate_attribute(core, core_model, "name", "core")
  94. instantiate_attribute(core, core_model, "location", coreM_model_location)
  95. instantiate_attribute(core, core_model, "permissions", "200")
  96. instance_of = instantiate_link(core, "instanceOf", "", core_model, core_formalism_model)
  97. instantiate_attribute(core, instance_of, "type_mapping", core["type_mapping"])
  98. // Make necessary links for the formalism to the owners
  99. instantiate_link(core, "group", "", core_model, admin_group)
  100. instantiate_link(core, "owner", "", core_model, admin_user)
  101. // Call this for ourselves as well
  102. log("MvC is ready!")
  103. user_function_skip_init(admin_user)
  104. // Done, so finish up
  105. // Admin user will have been deleted by the user_function as usual
  106. // Note that if there are no admin users left, it will be very difficult to manage, as nobody will have admin permissions!
  107. return !
  108. String function get_instanceOf_link(model_id : String):
  109. Element all_links
  110. String choice
  111. all_links = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  112. if (read_nr_out(all_links) > 1):
  113. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  114. elif (read_nr_out(all_links) == 0):
  115. log("ERROR: untyped model!")
  116. choice = set_pop(allOutgoingAssociationInstances(core, model_id, "instanceOf"))
  117. return choice!
  118. Element function get_full_model(model_id : String):
  119. Element m
  120. Element all_links
  121. String choice
  122. choice = get_instanceOf_link(model_id)
  123. m = create_node()
  124. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  125. dict_add(m, "type_mapping", read_attribute(core, choice, "type_mapping"))
  126. if (readAssociationDestination(core, choice) == model_id):
  127. // Found the meta-circular level, so we can stop!
  128. dict_add(m, "metamodel", m)
  129. else:
  130. dict_add(m, "metamodel", get_full_model(readAssociationDestination(core, choice)))
  131. return m!
  132. Integer function get_relation_to_model(user_id : String, model_id : String):
  133. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  134. // We are the owner
  135. return 0!
  136. else:
  137. String group_id
  138. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  139. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  140. // We are in the owning group
  141. return 1!
  142. else:
  143. // We are not related whatsoever
  144. return 2!
  145. Boolean function is_admin(user_id : String):
  146. if (read_attribute(core, user_id, "admin")):
  147. return True!
  148. else:
  149. return False!
  150. Boolean function allow_read(user_id : String, model_id : String):
  151. if (is_admin(user_id)):
  152. // Is admin, so always allow
  153. return True!
  154. else:
  155. // Check permissions
  156. String permission
  157. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  158. if (bool_or(permission == "1", permission == "2")):
  159. return True!
  160. else:
  161. return False!
  162. Boolean function allow_write(user_id : String, model_id : String):
  163. if (is_admin(user_id)):
  164. // Is admin, so always allow
  165. return True!
  166. else:
  167. // Check permissions
  168. String permission
  169. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  170. if (permission == "2"):
  171. return True!
  172. else:
  173. return False!
  174. Boolean function allow_change_metadata(user_id : String, model_id : String):
  175. if (is_admin(user_id)):
  176. // Is admin, so always allow
  177. return True!
  178. else:
  179. if (get_relation_to_model(user_id, model_id) == 0):
  180. // Only owner can chmod
  181. return True!
  182. else:
  183. return False!
  184. Boolean function allow_group_modify(user_id : String, group_id : String):
  185. if (is_admin(user_id)):
  186. // Is admin, so always allow
  187. return True!
  188. else:
  189. if (read_nr_out(set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))) > 0):
  190. // We are an owner
  191. return True!
  192. else:
  193. return False!
  194. Boolean function check_login(user_id : String):
  195. String password
  196. String stored_password
  197. stored_password = read_attribute(core, user_id, "password")
  198. output("Password for existing user?")
  199. password = hash(input())
  200. return password == stored_password!
  201. Element function extract_ftg(user_id : String):
  202. // Extract your personal FTG, showing only the readable models that can be opened
  203. // This function does the actual projection of transformations
  204. // TODO: Only keep transformations satisfying some properties!
  205. return create_node()!
  206. Element function user_function():
  207. String username
  208. String user_id
  209. String password
  210. // Load in all global variables, as this code is hotloaded!
  211. Element root
  212. root = read_root()
  213. root = root["__hierarchy"]["objects"]
  214. exec(root["bootstrap/modelling.alc"]["initializers"])
  215. exec(root["bootstrap/library.alc"]["initializers"])
  216. exec(root["bootstrap/constructors.alc"]["initializers"])
  217. exec(root["bootstrap/object_operations.alc"]["initializers"])
  218. exec(root["core/mini_modify.alc"]["initializers"])
  219. exec(root["bootstrap/model_management.alc"]["initializers"])
  220. exec(root["bootstrap/ramify.alc"]["initializers"])
  221. exec(root["bootstrap/transform.alc"]["initializers"])
  222. exec(root["bootstrap/conformance_scd.alc"]["initializers"])
  223. exec(root["core/core_algorithm.alc"]["initializers"])
  224. // Load in a hard-reference to the previously created model
  225. core = import_node(core_model_location)
  226. output("Log on as which user?")
  227. username = input()
  228. user_id = get_user_id(username)
  229. if (user_id == ""):
  230. // New user
  231. // Add user to Core Formalism
  232. user_id = instantiate_node(core, "User", "")
  233. instantiate_attribute(core, user_id, "name", username)
  234. instantiate_attribute(core, user_id, "admin", False)
  235. while (True):
  236. output("This is a new user: please give password!")
  237. password = hash(input())
  238. output("Please repeat the password")
  239. if (password == hash(input())):
  240. output("Passwords match!")
  241. output("User created")
  242. instantiate_attribute(core, user_id, "password", password)
  243. break!
  244. else:
  245. output("Not the same password, please try again!")
  246. // Now call with user created
  247. user_function_skip_init(user_id)
  248. else:
  249. while (bool_not(check_login(user_id))):
  250. output("Wrong password! Try again")
  251. user_function_skip_init(user_id)
  252. // User destroyed already, so just stop execution
  253. // TODO return a fresh node as otherwise the compiler doesn't take this
  254. return create_node()!
  255. String function get_model_id(name : String):
  256. Element models
  257. String model
  258. models = allInstances(core, "Model")
  259. while (read_nr_out(models) > 0):
  260. model = set_pop(models)
  261. if (value_eq(name, read_attribute(core, model, "name"))):
  262. return model!
  263. return ""!
  264. String function get_user_id(name : String):
  265. Element users
  266. String user
  267. users = allInstances(core, "User")
  268. while (read_nr_out(users) > 0):
  269. user = set_pop(users)
  270. if (value_eq(read_attribute(core, user, "name"), name)):
  271. return user!
  272. return ""!
  273. String function get_group_id(name : String):
  274. Element groups
  275. String group
  276. groups = allInstances(core, "Group")
  277. while (read_nr_out(groups) > 0):
  278. group = set_pop(groups)
  279. if (value_eq(read_attribute(core, group, "name"), name)):
  280. return group!
  281. return ""!
  282. Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
  283. String location
  284. String model_id
  285. String instance_of
  286. location = "/models/" + cast_id2s(model)
  287. export_node(location, model["model"])
  288. // Manage meta-info
  289. model_id = instantiate_node(core, kind, "")
  290. instantiate_attribute(core, model_id, "name", name)
  291. instantiate_attribute(core, model_id, "location", location)
  292. instantiate_attribute(core, model_id, "permissions", "200")
  293. instantiate_link(core, "owner", "", model_id, user_id)
  294. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  295. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  296. instantiate_attribute(core, instance_of, "type_mapping", model["type_mapping"])
  297. return!
  298. Void function model_overwrite(model : Element, model_id : String):
  299. String location
  300. String instanceOf_link
  301. location = "/models/" + cast_id2s(model)
  302. export_node(location, model["model"])
  303. // Change location in meta-data
  304. unset_attribute(core, model_id, "location")
  305. instantiate_attribute(core, model_id, "location", location)
  306. instanceOf_link = get_instanceOf_link(model_id)
  307. unset_attribute(core, instanceOf_link, "type_mapping")
  308. instantiate_attribute(core, instanceOf_link, "type_mapping", model["type_mapping"])
  309. return!
  310. Boolean function check_is_typed_by(model_id : String, metamodel_id : String):
  311. // TODO check if there is actually an instanceOf link between them
  312. // --> quick check!
  313. return True!
  314. Boolean function check_conformance(model_id : String):
  315. // TODO check if it actually conforms, considering that instanceOf link
  316. // --> in-depth check
  317. return True!
  318. Void function user_function_skip_init(user_id : String):
  319. String cmd
  320. output("Welcome to the Model Management Interface v2.0!")
  321. output("Use the 'help' command for a list of possible commands")
  322. while (True):
  323. output("Ready for command...")
  324. cmd = input()
  325. if (cmd == "help"):
  326. output("Model operations")
  327. output(" model_add -- Add a new model")
  328. output(" model_modify -- Modify an existing model")
  329. output(" model_delete -- [TODO] Delete a model and all related transformations")
  330. output(" model_list -- List all models")
  331. output(" model_list_full -- List all models with full info")
  332. output(" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata")
  333. output("")
  334. output("Transformation-specific operations")
  335. output(" transformation_add_MT_language -- Create a RAMified metamodel of a set of models")
  336. output(" transformation_add_MT -- Initialize a new model transformation")
  337. output(" transformation_add_AL -- [TODO] Initialize a new action language transformation")
  338. output(" transformation_add_EXT -- [TODO] Initialize a new external tool transformation")
  339. output(" transformation_add_MANUAL -- [TODO] Initialize a new manual transformation")
  340. output(" transformation_execute -- Execute a transformation on a set of input models")
  341. output(" transformation_list -- List all model transformations")
  342. output(" transformation_list_full -- List all model transformations with permissions")
  343. output(" transformation_detail -- List transformation details")
  344. output(" transformation_RAMify -- RAMify a metamodel (again)")
  345. output("")
  346. output("Model permission operations")
  347. output(" permission_modify -- Change model permissions")
  348. output(" permission_owner -- Change model owner")
  349. output(" permission_group -- Change model group")
  350. output("")
  351. output("Group operations")
  352. output(" group_create -- Create a group")
  353. output(" group_delete -- Delete a group")
  354. output(" group_owner_add -- Add group owner")
  355. output(" group_owner_delete -- Remove group owner")
  356. output(" group_join -- Add someone to your group")
  357. output(" group_kick -- Kick someone from your group")
  358. output(" group_list -- List all groups you are a member of")
  359. output("")
  360. output("Admin operations")
  361. output(" admin_promote -- Promote a user to admin status")
  362. output(" admin_demote -- Demote a user to normal status")
  363. output("")
  364. output("General operations")
  365. output(" self-destruct -- Remove current user and revoke all permissions ")
  366. output(" exit -- Kill the current task, while retaining user")
  367. elif (cmd == "model_add"):
  368. // Model addition operation, which uses model upload commands of the compiler
  369. String name
  370. String type
  371. String location
  372. String type_id
  373. Element new_model
  374. String new_model_id
  375. output("Creating new model!")
  376. output("Model type?")
  377. type_id = get_model_id(input())
  378. if (type_id != ""):
  379. // Type exists
  380. if (allow_read(user_id, type_id)):
  381. // And is readable
  382. output("Model name?")
  383. name = input()
  384. if (get_model_id(name) == ""):
  385. // Model doesn't exist yet
  386. output("Waiting for model constructors...")
  387. new_model = construct_model_raw(get_full_model(type_id))
  388. model_create(new_model, name, user_id, type_id, "Model")
  389. output("Model upload success!")
  390. else:
  391. output("Model with that name already exists!")
  392. else:
  393. output("Permission denied")
  394. else:
  395. output("Could not find type model!")
  396. elif (cmd == "transformation_execute"):
  397. // Execute a transformation, whatever type it is
  398. // First we detect the type, so we know how to prepare for invocation
  399. String transformation_id
  400. String exact_type
  401. Element sources
  402. Element targets
  403. String source
  404. String target
  405. String name_id
  406. Element inputs
  407. Element outputs
  408. Element trace_links
  409. String target_model_name
  410. String source_model_name
  411. output("Which transformation do you want to execute?")
  412. transformation_id = get_model_id(input())
  413. if (transformation_id != ""):
  414. if (allow_read(user_id, transformation_id)):
  415. if (is_nominal_instance(core, transformation_id, "Transformation")):
  416. // Read out source and target links
  417. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  418. inputs = create_node()
  419. while (read_nr_out(sources) > 0):
  420. source = set_pop(sources)
  421. output(string_join("Which model to bind for source element ", read_attribute(core, source, "name")))
  422. source_model_name = input()
  423. name_id = get_model_id(source_model_name)
  424. if (name_id != ""):
  425. if (allow_read(user_id, name_id)):
  426. // Check for conformance to the specified metamodel!
  427. Element specified_model
  428. // TODO Maybe find out which conformance relation to use, as there might be multiple!
  429. if (check_is_typed_by(name_id, source)):
  430. if (check_conformance(name_id)):
  431. dict_add(inputs, read_attribute(core, source, "name"), source_model_name)
  432. else:
  433. output("Model has correct type but does not conform completely!")
  434. set_add(sources, source)
  435. else:
  436. output("Model has different type!")
  437. set_add(sources, source)
  438. else:
  439. output("Permission denied")
  440. set_add(sources, source)
  441. else:
  442. output("No such model")
  443. set_add(sources, source)
  444. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  445. outputs = create_node()
  446. while (read_nr_out(targets) > 0):
  447. target = set_pop(targets)
  448. output(string_join("Which model to create for target element ", read_attribute(core, target, "name")))
  449. target_model_name = input()
  450. if (get_model_id(target_model_name) == ""):
  451. // Doesn't exist yet, so we can easily create
  452. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  453. else:
  454. // Already exists, so we need to check for write access
  455. if (allow_write(user_id, get_model_id(target_model_name))):
  456. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  457. else:
  458. output("Permission denied; try again")
  459. exact_type = read_type(core, transformation_id)
  460. if (exact_type == "ModelTransformation"):
  461. // Model transformation is always in-place and uses only a single metamodel
  462. // Therefore, we must:
  463. // 1) Create an empty model, instance of merged metamodel
  464. // 2) Merge the different source models and retype
  465. // 3) Perform the transformation on the merged model
  466. // 4) Split the resulting model based on the target formalisms
  467. //
  468. // There is one exception: if the target model is bound to a source model, that model is overwritten
  469. // This allows for some optimizations when it is a simple in-place transformation (skip model copy, join, and split)
  470. // First check for this exception, as it is much faster
  471. Element input_model
  472. Element schedule_model
  473. String trace_link_id
  474. Element merged_model
  475. String merged_metamodel_id
  476. String ramified_metamodel_id
  477. Boolean result
  478. schedule_model = get_full_model(transformation_id)
  479. // 1) Create empty instance of merged metamodel
  480. ramified_metamodel_id = set_pop(followAssociation(core, transformation_id, "instanceOf"))
  481. trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  482. merged_metamodel_id = ""
  483. while (read_nr_out(trace_links) > 0):
  484. trace_link_id = set_pop(trace_links)
  485. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  486. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  487. if (merged_metamodel_id != ""):
  488. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  489. // 2) Merge source models
  490. String key
  491. Element keys
  492. Element input_keys
  493. Element output_keys
  494. input_keys = dict_keys(inputs)
  495. while (read_nr_out(input_keys) > 0):
  496. key = set_pop(input_keys)
  497. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  498. // 3) Transform
  499. log("EXECUTE TRANSFORMATION " + cast_e2s(read_attribute(core, transformation_id, "name")))
  500. result = transform(merged_model, schedule_model)
  501. output("Transformation executed with result: " + cast_v2s(result))
  502. // 4) Split in different files depending on type
  503. String desired_metamodel_id
  504. Element split_off_model
  505. output_keys = dict_keys(outputs)
  506. while (read_nr_out(output_keys) > 0):
  507. key = set_pop(output_keys)
  508. desired_metamodel_id = get_model_id(key)
  509. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  510. // Check if the destination model already exists
  511. if (get_model_id(outputs[key]) == ""):
  512. // New model
  513. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  514. else:
  515. // Model exists, so we overwrite
  516. model_overwrite(split_off_model, get_model_id(outputs[key]))
  517. else:
  518. output("Could not resolve intermediate merged metamodel")
  519. elif (exact_type == "ActionLanguage"):
  520. output("Action Language execution starts!")
  521. action_model = get_full_model(transformation_id)
  522. // 1) Group source models in dictionary
  523. input_keys = dict_keys(inputs)
  524. while (read_nr_out(input_keys) > 0):
  525. key = set_pop(input_keys)
  526. // 2) Execute action language model
  527. func = get_func_AL_model(action_model)
  528. // 3) Split output dictionary back to seperate models
  529. output_keys = dict_keys(outputs)
  530. while (read_nr_out(output_keys) > 0):
  531. key = set_pop(output_keys)
  532. else:
  533. output("Did not know how to interpret model of type " + exact_type)
  534. else:
  535. output("Model is not an executable transformation")
  536. else:
  537. output("Permission denied")
  538. else:
  539. output("No such transformation")
  540. elif (cmd == "model_overwrite"):
  541. // Overwrites an existing model without changing any metadata
  542. String model_id
  543. Element new_model
  544. output("Which model to overwrite?")
  545. model_id = get_model_id(input())
  546. if (model_id != ""):
  547. if (allow_write(user_id, model_id)):
  548. if (allow_read(user_id, set_pop(followAssociation(core, model_id, "instanceOf")))):
  549. output("Waiting for model constructors...")
  550. new_model = construct_model_raw(get_full_model(set_pop(followAssociation(core, model_id, "instanceOf"))))
  551. model_overwrite(new_model, model_id)
  552. output("Model overwrite success!")
  553. else:
  554. output("Permission denied")
  555. else:
  556. output("Permission denied")
  557. else:
  558. output("No such model")
  559. elif (cmd == "model_modify"):
  560. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  561. String model_id
  562. String type_id
  563. output("Which model do you want to modify?")
  564. model_id = get_model_id(input())
  565. if (model_id != ""):
  566. if (allow_read(user_id, model_id)):
  567. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  568. if (allow_read(user_id, type_id)):
  569. modify(get_full_model(model_id), allow_write(user_id, model_id))
  570. else:
  571. output("Permission denied")
  572. else:
  573. output("Permission denied")
  574. else:
  575. output("Could not find model!")
  576. elif (cmd == "model_delete"):
  577. // Delete a model and all of its related transformations
  578. String model_id
  579. output("=================================================")
  580. output("WARNING: Deletion is a very destructive operation")
  581. output(" as it also deletes all transformations ")
  582. output(" defined which make use of this model! ")
  583. output("=================================================")
  584. output("")
  585. output("Currently not supported!")
  586. elif (cmd == "model_list"):
  587. // List all models
  588. Element models
  589. String m
  590. models = allInstances(core, "Model")
  591. while (read_nr_out(models) > 0):
  592. m = set_pop(models)
  593. output(string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name")))
  594. elif (cmd == "model_list_full"):
  595. // List all models with full info
  596. Element models
  597. String m
  598. String permissions
  599. String owner
  600. String group
  601. String name
  602. String type
  603. models = allInstances(core, "Model")
  604. while (read_nr_out(models) > 0):
  605. m = set_pop(models)
  606. permissions = read_attribute(core, m, "permissions")
  607. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  608. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  609. name = read_attribute(core, m, "name")
  610. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  611. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)
  612. elif (cmd == "transformation_add_MT_language"):
  613. // Create a model transformation language from a set of input and output formalisms
  614. String name
  615. String model_id
  616. Element source
  617. Element target
  618. Element all_formalisms
  619. Element merged_formalism
  620. Element ramified_formalism
  621. String old_type_id
  622. String type_id
  623. String location
  624. String new_model_id
  625. old_type_id = ""
  626. log("Adding MT language")
  627. // Read involved formalisms
  628. all_formalisms = create_node()
  629. output("Formalisms to include (terminate with empty string)?")
  630. name = input()
  631. while (name != ""):
  632. model_id = get_model_id(name)
  633. if (model_id != ""):
  634. if (allow_read(user_id, model_id)):
  635. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  636. if (bool_or(old_type_id == "", type_id == old_type_id)):
  637. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  638. old_type_id = type_id
  639. elif (old_type_id != type_id):
  640. // Already have a previous type_id and now another: CLASH
  641. output("Cannot add model as types not compatible with previous models; try again")
  642. else:
  643. output("Model not readable; try again")
  644. else:
  645. output("No such model; try again")
  646. name = input()
  647. // Merge both into a single metamodel
  648. if (read_nr_out(all_formalisms) > 0):
  649. output("Name of the RAMified transformation metamodel?")
  650. name = input()
  651. if (get_model_id(name) == ""):
  652. String merged_formalism_id
  653. String ramified_formalism_id
  654. String source_formalism_id
  655. String tracability_link
  656. // New location is available, so write
  657. log("FUSE")
  658. merged_formalism = model_fuse(set_copy(all_formalisms))
  659. log("Fuse OK")
  660. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  661. merged_formalism_id = get_model_id("__merged_" + name)
  662. // Add tracability links at this level
  663. while (read_nr_out(all_formalisms) > 0):
  664. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  665. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  666. instantiate_attribute(core, tracability_link, "type", "merged")
  667. // Merge complete, now RAMify!
  668. log("RAM")
  669. ramified_formalism = ramify(merged_formalism)
  670. log("RAMed")
  671. model_create(ramified_formalism, name, user_id, type_id, "Model")
  672. ramified_formalism_id = get_model_id(name)
  673. // Add tracability link at this level
  674. tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
  675. instantiate_attribute(core, tracability_link, "type", "RAMified")
  676. else:
  677. output("Model already exists!")
  678. else:
  679. output("At least one formalism is required")
  680. elif (cmd == "transformation_RAMify"):
  681. // RAMify a metamodel
  682. String merged_model_id
  683. String target_model_name
  684. String target_model_id
  685. Element target_model
  686. String tracability_link
  687. output("Which metamodel do you want to RAMify?")
  688. merged_model_id = get_model_id(input())
  689. if (merged_model_id != ""):
  690. if (allow_read(user_id, merged_model_id)):
  691. output("Where do you want to store the RAMified metamodel?")
  692. target_model_name = input()
  693. target_model_id = get_model_id(target_model_name)
  694. if (target_model_id == ""):
  695. // New model, so everything is fine
  696. target_model = ramify(get_full_model(merged_model_id))
  697. model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
  698. target_model_id = get_model_id(target_model_name)
  699. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  700. instantiate_attribute(core, tracability_link, "type", "RAMified")
  701. else:
  702. // Existing model, so overwrite
  703. if (allow_write(user_id, target_model_id)):
  704. target_model = ramify(get_full_model(merged_model_id))
  705. model_overwrite(target_model, target_model_id)
  706. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
  707. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  708. instantiate_attribute(core, tracability_link, "type", "RAMified")
  709. else:
  710. output("Permission denied")
  711. else:
  712. output("Permission denied!")
  713. else:
  714. output("No such model")
  715. elif (cmd == "transformation_add_AL"):
  716. // Add an action language transformation model
  717. output("Which metamodels do you want to use as source for the action code (empty string to finish)?")
  718. name = input()
  719. while (name != ""):
  720. model_id = get_model_id(name)
  721. if (model_id != ""):
  722. if (set_in(supported, model_id)):
  723. if (bool_not(set_in(source, model_id))):
  724. set_add(source, model_id)
  725. output("Model added as source")
  726. else:
  727. output("Model already selected as source")
  728. else:
  729. output("Model is not supported by RAMified metamodel!")
  730. else:
  731. output("No such model; try again")
  732. name = input()
  733. output("Which metamodels do you want to use as target for the action code (empty string to finish)?")
  734. name = input()
  735. while (name != ""):
  736. model_id = get_model_id(name)
  737. if (model_id != ""):
  738. if (set_in(supported, model_id)):
  739. if (bool_not(set_in(target, model_id))):
  740. set_add(target, model_id)
  741. output("Model added as target")
  742. else:
  743. output("Model already selected as target")
  744. else:
  745. output("Model is not supported by RAMified metamodel!")
  746. else:
  747. output("No such model; try again")
  748. name = input()
  749. output("Name of Action Language model?")
  750. name = input()
  751. if (get_model_id(name) == ""):
  752. String new_model
  753. // Finished with all information, now create the model itself!
  754. output("Waiting for model constructors...")
  755. new_model = construct_model_raw(import_node("models/ActionLanguage"))
  756. model_create(new_model, name, user_id, ramified_metamodel_id, "ActionLanguage")
  757. model_id = get_model_id(name)
  758. // Extend metadata with info on source and target
  759. String link
  760. String dst
  761. while (read_nr_out(source) > 0):
  762. dst = set_pop(source)
  763. link = instantiate_link(core, "transformInput", "", model_id, dst)
  764. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  765. while (read_nr_out(target) > 0):
  766. dst = set_pop(target)
  767. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  768. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  769. else:
  770. output("Model already exists")
  771. elif (cmd == "transformation_add_MT"):
  772. // Add a model transformation model
  773. // Just a usual model instantiation, but need to add the source and target links based on user info
  774. String ramified_metamodel_id
  775. String model_id
  776. Element models
  777. Element links
  778. String link_id
  779. Element supported
  780. Element source
  781. Element target
  782. String name
  783. String new_model_id
  784. String merged_link_id
  785. Element links_merged
  786. String merged_metamodel_id
  787. source = create_node()
  788. target = create_node()
  789. supported = create_node()
  790. output("RAMified metamodel to use?")
  791. ramified_metamodel_id = get_model_id(input())
  792. if (ramified_metamodel_id != ""):
  793. if (allow_read(user_id, ramified_metamodel_id)):
  794. output("Supported metamodels:")
  795. links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  796. while (read_nr_out(links) > 0):
  797. link_id = set_pop(links)
  798. merged_metamodel_id = readAssociationDestination(core, link_id)
  799. if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
  800. links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  801. while (read_nr_out(links_merged) > 0):
  802. merged_link_id = set_pop(links_merged)
  803. if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
  804. output(string_join(" ", read_attribute(core, readAssociationDestination(core, merged_link_id), "name")))
  805. set_add(supported, readAssociationDestination(core, merged_link_id))
  806. output("")
  807. output("Which ones do you want to use as source (empty string to finish)?")
  808. name = input()
  809. while (name != ""):
  810. model_id = get_model_id(name)
  811. if (model_id != ""):
  812. if (set_in(supported, model_id)):
  813. if (bool_not(set_in(source, model_id))):
  814. set_add(source, model_id)
  815. output("Model added as source")
  816. else:
  817. output("Model already selected as source")
  818. else:
  819. output("Model is not supported by RAMified metamodel!")
  820. else:
  821. output("No such model; try again")
  822. name = input()
  823. output("Which ones do you want to use as target (empty string to finish)?")
  824. name = input()
  825. while (name != ""):
  826. model_id = get_model_id(name)
  827. if (model_id != ""):
  828. if (set_in(supported, model_id)):
  829. if (bool_not(set_in(target, model_id))):
  830. set_add(target, model_id)
  831. output("Model added as target")
  832. else:
  833. output("Model already selected as target")
  834. else:
  835. output("Model is not supported by RAMified metamodel!")
  836. else:
  837. output("No such model; try again")
  838. name = input()
  839. output("Name of new transformation?")
  840. name = input()
  841. if (get_model_id(name) == ""):
  842. String new_model
  843. // Finished with all information, now create the model itself!
  844. output("Waiting for model constructors...")
  845. new_model = construct_model_raw(get_full_model(ramified_metamodel_id))
  846. model_create(new_model, name, user_id, ramified_metamodel_id, "ModelTransformation")
  847. model_id = get_model_id(name)
  848. // Extend metadata with info on source and target
  849. String link
  850. String dst
  851. while (read_nr_out(source) > 0):
  852. dst = set_pop(source)
  853. link = instantiate_link(core, "transformInput", "", model_id, dst)
  854. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  855. while (read_nr_out(target) > 0):
  856. dst = set_pop(target)
  857. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  858. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  859. else:
  860. output("Model already exists")
  861. else:
  862. output("Permission denied")
  863. else:
  864. output("No such model")
  865. elif (cmd == "transformation_list"):
  866. // List all models
  867. Element models
  868. String m
  869. String type
  870. models = allInstances(core, "Transformation")
  871. while (read_nr_out(models) > 0):
  872. m = set_pop(models)
  873. 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"))))
  874. elif (cmd == "transformation_list_full"):
  875. // List all models with full info
  876. Element models
  877. String m
  878. String permissions
  879. String owner
  880. String group
  881. String name
  882. String type
  883. models = allInstances(core, "Transformation")
  884. while (read_nr_out(models) > 0):
  885. m = set_pop(models)
  886. permissions = read_attribute(core, m, "permissions")
  887. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  888. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  889. name = read_attribute(core, m, "name")
  890. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  891. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type)
  892. elif (cmd == "permission_modify"):
  893. String permissions
  894. Integer permission
  895. String model_id
  896. output("Which model do you want to change permissions of?")
  897. model_id = get_model_id(input())
  898. if (model_id != ""):
  899. if (get_relation_to_model(user_id, model_id) == 0):
  900. output("New permissions?")
  901. permissions = input()
  902. Boolean fail
  903. Integer i
  904. i = 0
  905. if (string_len(permissions) != 3):
  906. fail = True
  907. while (i < 3):
  908. permission = cast_s2i(string_get(permissions, i))
  909. if (bool_or(permission < 0, permission > 2)):
  910. fail = True
  911. break!
  912. i = i + 1
  913. if (bool_not(fail)):
  914. unset_attribute(core, model_id, "permissions")
  915. instantiate_attribute(core, model_id, "permissions", permissions)
  916. else:
  917. output("Permissions must be a string of three characters with each character being a digit between 0 and 2")
  918. else:
  919. output("Permission denied!")
  920. else:
  921. output("No such model!")
  922. elif (cmd == "permission_owner"):
  923. String permissions
  924. String model_id
  925. String user_id
  926. output("Which model do you want to change owner of?")
  927. model_id = get_model_id(input())
  928. if (model_id != ""):
  929. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  930. output("New owner?")
  931. user_id = get_user_id(input())
  932. if (user_id != ""):
  933. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  934. instantiate_link(core, "owner", "", model_id, user_id)
  935. else:
  936. output("No such user!")
  937. else:
  938. output("Permission denied!")
  939. else:
  940. output("No such model!")
  941. elif (cmd == "permission_group"):
  942. String permissions
  943. String model_id
  944. String group_id
  945. output("Which model do you want to change permissions of?")
  946. model_id = get_model_id(input())
  947. if (model_id != ""):
  948. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  949. output("New group?")
  950. group_id = get_group_id(input())
  951. if (group_id != ""):
  952. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  953. instantiate_link(core, "group", "", model_id, group_id)
  954. else:
  955. output("No such group!")
  956. else:
  957. output("Permission denied!")
  958. else:
  959. output("No such model!")
  960. elif (cmd == "group_create"):
  961. // Create a new group and become its owner
  962. String group_id
  963. String name
  964. output("Which group do you want to create?")
  965. name = input()
  966. group_id = get_group_id(name)
  967. if (group_id == ""):
  968. group_id = instantiate_node(core, "Group", "")
  969. instantiate_attribute(core, group_id, "name", name)
  970. instantiate_link(core, "belongsTo", "", user_id, group_id)
  971. instantiate_link(core, "owner", "", group_id, user_id)
  972. output("Group created!")
  973. else:
  974. output("Group already exists")
  975. elif (cmd == "group_delete"):
  976. // Delete an existing group
  977. String group_id
  978. String name
  979. output("Which group do you want to delete?")
  980. name = input()
  981. group_id = get_group_id(name)
  982. if (group_id != ""):
  983. if (allow_group_modify(user_id, group_id)):
  984. model_delete_element(core, group_id)
  985. else:
  986. output("Permission denied")
  987. else:
  988. output("No such group")
  989. elif (cmd == "group_owner_add"):
  990. // Add an owner to your group
  991. String group_id
  992. String other_user_id
  993. output("Which group do you want to add an owner to?")
  994. group_id = get_group_id(input())
  995. if (group_id != ""):
  996. if (allow_group_modify(user_id, group_id)):
  997. output("Which user do you want to make an owner?")
  998. other_user_id = get_user_id(input())
  999. if (other_user_id != ""):
  1000. Element overlap
  1001. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1002. if (read_nr_out(overlap) == 0):
  1003. instantiate_link(core, "owner", "", group_id, other_user_id)
  1004. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1005. if (read_nr_out(overlap) == 0):
  1006. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1007. output("New owner added to group!")
  1008. else:
  1009. output("User is already an owner!")
  1010. else:
  1011. output("No such user")
  1012. else:
  1013. output("Permission denied!")
  1014. else:
  1015. output("No such group")
  1016. elif (cmd == "group_owner_delete"):
  1017. // Remove an owner from your group
  1018. String group_id
  1019. String other_user_id
  1020. output("Which group do you want to disown someone from?")
  1021. group_id = get_group_id(input())
  1022. if (group_id != ""):
  1023. if (allow_group_modify(user_id, group_id)):
  1024. output("Which user do you want to disown?")
  1025. other_user_id = get_user_id(input())
  1026. if (other_user_id != ""):
  1027. Element overlap
  1028. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1029. if (read_nr_out(overlap) > 0):
  1030. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1031. if (read_nr_out(overlap) > 0):
  1032. model_delete_element(core, set_pop(overlap))
  1033. output("Disowned group from user!")
  1034. else:
  1035. output("User is not even an owner of the group!")
  1036. else:
  1037. output("User is not even a member of the group!")
  1038. else:
  1039. output("No such user")
  1040. else:
  1041. output("Permission denied!")
  1042. else:
  1043. output("No such group")
  1044. elif (cmd == "group_join"):
  1045. // Add someone to your group
  1046. String group_id
  1047. String other_user_id
  1048. output("Which group do you want to add someone to?")
  1049. group_id = get_group_id(input())
  1050. if (group_id != ""):
  1051. if (allow_group_modify(user_id, group_id)):
  1052. output("Which user do you want to add?")
  1053. other_user_id = get_user_id(input())
  1054. if (other_user_id != ""):
  1055. Element overlap
  1056. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1057. if (read_nr_out(overlap) == 0):
  1058. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1059. output("User added to the group!")
  1060. else:
  1061. output("User is already a member of the group!")
  1062. else:
  1063. output("No such user")
  1064. else:
  1065. output("Permission denied!")
  1066. else:
  1067. output("No such group")
  1068. elif (cmd == "group_kick"):
  1069. // Remove someone from your group
  1070. String group_id
  1071. String other_user_id
  1072. output("Which group do you want to kick someone from?")
  1073. group_id = get_group_id(input())
  1074. if (group_id != ""):
  1075. if (allow_group_modify(user_id, group_id)):
  1076. output("Which user do you want to kick?")
  1077. other_user_id = get_user_id(input())
  1078. if (other_user_id != ""):
  1079. Element overlap
  1080. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1081. if (read_nr_out(overlap) > 0):
  1082. model_delete_element(core, set_pop(overlap))
  1083. // Check if user was an owner as well
  1084. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1085. if (read_nr_out(overlap) > 0):
  1086. model_delete_element(core, set_pop(overlap))
  1087. output("User kicked!")
  1088. else:
  1089. output("User is not even a member of the group!")
  1090. else:
  1091. output("No such user")
  1092. else:
  1093. output("Permission denied!")
  1094. else:
  1095. output("No such group")
  1096. elif (cmd == "group_list"):
  1097. // List all groups you are a member of (and whether you are admin or not!)
  1098. Element groups
  1099. String group_id
  1100. String admin
  1101. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1102. while (read_nr_out(groups) > 0):
  1103. group_id = set_pop(groups)
  1104. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  1105. admin = " A "
  1106. else:
  1107. admin = " "
  1108. output(string_join(admin, read_attribute(core, group_id, "name")))
  1109. elif (cmd == "admin_promote"):
  1110. // Promote a user to admin status
  1111. if (is_admin(user_id)):
  1112. String other_user_id
  1113. output("Which user do you want to promote?")
  1114. other_user_id = get_user_id(input())
  1115. if (other_user_id != ""):
  1116. unset_attribute(core, other_user_id, "admin")
  1117. instantiate_attribute(core, other_user_id, "admin", True)
  1118. output("Permissions granted!")
  1119. else:
  1120. output("No such user!")
  1121. else:
  1122. output("Permission denied!")
  1123. elif (cmd == "admin_demote"):
  1124. // Demote a user to normal status
  1125. if (is_admin(user_id)):
  1126. String other_user_id
  1127. output("Which user do you want to demote?")
  1128. other_user_id = get_user_id(input())
  1129. if (other_user_id != ""):
  1130. unset_attribute(core, other_user_id, "admin")
  1131. instantiate_attribute(core, other_user_id, "admin", False)
  1132. output("Permissions revoked!")
  1133. else:
  1134. output("No such user!")
  1135. else:
  1136. output("Permission denied!")
  1137. elif (cmd == "self-destruct"):
  1138. // Delete user from Core Formalism
  1139. model_delete_element(core, user_id)
  1140. return !
  1141. elif (cmd == "exit"):
  1142. // Exit by actually removing the user and decoupling it from all of its models
  1143. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1144. // as the current user will have been deleted
  1145. return !
  1146. else:
  1147. output("Unknown command: " + cmd)
  1148. // We never get here!
  1149. return !