core_algorithm.alc 69 KB

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