core_algorithm.alc 66 KB

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