core_algorithm.alc 69 KB

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