core_algorithm.alc 48 KB

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