core_algorithm.alc 62 KB

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