core_algorithm.alc 66 KB

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