core_algorithm.alc 65 KB

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