core_algorithm.alc 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  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. location = "models/" + cast_id2s(model)
  362. export_node(location, model["model"])
  363. // Change location in meta-data
  364. unset_attribute(core, model_id, "location")
  365. instantiate_attribute(core, model_id, "location", location)
  366. instanceOf_link = get_instanceOf_link(model_id)
  367. unset_attribute(core, instanceOf_link, "type_mapping")
  368. instantiate_attribute(core, instanceOf_link, "type_mapping", model["type_mapping"])
  369. return!
  370. Boolean function check_is_typed_by(model_id : String, metamodel_id : String):
  371. // TODO check if there is actually an instanceOf link between them
  372. // --> quick check!
  373. return True!
  374. Boolean function check_conformance(model_id : String):
  375. // TODO check if it actually conforms, considering that instanceOf link
  376. // --> in-depth check
  377. return True!
  378. Boolean function pm_finished(worklist : Element, pm : String):
  379. Element finished
  380. Integer cnt
  381. Integer i
  382. // Check if any of the "finish" elements are in the worklist
  383. // If so, we can already finish, and therefore will stop immediately
  384. finished = allInstances(pm, "Finish")
  385. i = 0
  386. cnt = read_nr_out(finished)
  387. while (i < cnt):
  388. // Check each finished element individually
  389. if (set_in(finished, dict_read(read_edge_dst(read_out(worklist, i)), 0))):
  390. return True!
  391. i = i + 1
  392. return False!
  393. Element function execute_operation(operation_id : String, input_models : Element, output_metamodels : Element):
  394. // Operations are always in-place and uses only a single metamodel
  395. // Therefore, we must:
  396. // 1) Find merged metamodel
  397. // 2) Merge the different source models and retype
  398. // 3) Perform the operation on the merged model
  399. // 4) Split the resulting model based on the target formalisms; if operation successful
  400. Element input_model
  401. String trace_link_id
  402. Element merged_model
  403. String merged_metamodel_id
  404. String ramified_metamodel_id
  405. Boolean result
  406. String exact_type
  407. Element trace_links
  408. String linktype
  409. String model_ID
  410. String key
  411. Element keys
  412. Element input_keys
  413. Element output_keys
  414. Element model_tuples
  415. String metamodel_name
  416. Element metamodel
  417. String metamodel_ID
  418. // 1) Find merged metamodel
  419. exact_type = read_type(core, operation_id)
  420. if (exact_type == "ModelTransformation"):
  421. linktype = "RAMified"
  422. ramified_metamodel_id = set_pop(followAssociation(core, operation_id, "instanceOf"))
  423. trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  424. elif (exact_type == "ManualOperation"):
  425. linktype = "operatesOn"
  426. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  427. elif (exact_type == "ActionLanguage"):
  428. linktype = "operatesOn"
  429. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  430. else:
  431. // Don't know how to execute this operation!
  432. return read_root()!
  433. merged_metamodel_id = ""
  434. while (read_nr_out(trace_links) > 0):
  435. trace_link_id = set_pop(trace_links)
  436. if (value_eq(read_attribute(core, trace_link_id, "type"), linktype)):
  437. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  438. if (merged_metamodel_id != ""):
  439. // 2) Merge source models
  440. model_tuples = create_node()
  441. while (read_nr_out(input_models) > 0):
  442. model_ID = get_model_id(set_pop(input_models))
  443. input_model = get_full_model(model_ID)
  444. metamodel_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_ID, "instanceOf")), "name")
  445. set_add(model_tuples, create_tuple(metamodel_name, input_model))
  446. merged_model = model_join(model_tuples, get_full_model(merged_metamodel_id), read_root())
  447. // 3) Transform
  448. if (exact_type == "ModelTransformation"):
  449. result = transform(merged_model, get_full_model(operation_id))
  450. elif (exact_type == "ManualOperation"):
  451. output("Please perform manual operation " + cast_v2s(read_attribute(core, operation_id, "name")))
  452. modify(merged_model, True)
  453. result = True
  454. elif (exact_type == "ActionLanguage"):
  455. Element func
  456. func = get_func_AL_model(get_full_model(operation_id))
  457. result = func(merged_model)
  458. else:
  459. log("ERROR")
  460. // 4) Split in different models depending on type
  461. if (result):
  462. model_tuples = create_node()
  463. while (read_nr_out(output_metamodels) > 0):
  464. metamodel_ID = get_model_id(set_pop(output_metamodels))
  465. metamodel_name = read_attribute(core, metamodel_ID, "name")
  466. metamodel = get_full_model(metamodel_ID)
  467. set_add(model_tuples, create_tuple(metamodel_name, metamodel))
  468. return model_split(merged_model, model_tuples, False)!
  469. else:
  470. return read_root()!
  471. else:
  472. output("Could not resolve intermediate merged metamodel")
  473. return read_root()!
  474. Boolean function enact_action(pm : Element, element : String, prefix : String, user_id : String):
  475. Boolean result
  476. String transformation_id
  477. Element lst
  478. String elem
  479. Element inputs
  480. Element outputs
  481. String type_name
  482. String exact_type
  483. Element trace_links
  484. Element output_mms
  485. Element consumes_link
  486. String name
  487. String value
  488. String elem_name
  489. Element keys
  490. String key
  491. inputs = create_node()
  492. outputs = create_node()
  493. // Read out the referenced element from the MvC
  494. transformation_id = get_model_id(read_attribute(pm, element, "name"))
  495. // Find all input model names
  496. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  497. while (read_nr_out(lst) > 0):
  498. value = read_attribute(pm, readAssociationDestination(pm, set_pop(lst)), "name")
  499. set_add(inputs, prefix + value)
  500. // Find all output model names and their metamodel
  501. lst = allAssociationDestinations(pm, element, "Produces")
  502. while (read_nr_out(lst) > 0):
  503. elem = set_pop(lst)
  504. type_name = read_attribute(pm, elem, "type")
  505. elem_name = read_attribute(pm, elem, "name")
  506. dict_add(outputs, type_name, prefix + elem_name)
  507. result = execute_operation(transformation_id, inputs, dict_keys(outputs))
  508. if (element_eq(result, read_root())):
  509. // Something went wrong!
  510. return False!
  511. else:
  512. log("Results: " + dict_to_string(result))
  513. keys = dict_keys(result)
  514. while (read_nr_out(keys) > 0):
  515. key = set_pop(keys)
  516. log("Expanding: " + key)
  517. log("New name: " + cast_v2s(outputs[key]))
  518. if (get_model_id(outputs[key]) == ""):
  519. // New model
  520. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  521. log("New model!")
  522. else:
  523. model_overwrite(result[key], get_model_id(outputs[key]))
  524. log("Overwrite!")
  525. return result!
  526. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  527. Element worklist
  528. String element
  529. String start
  530. String type
  531. Boolean result
  532. Element tuple
  533. Element counters
  534. Element join_nodes
  535. // Initialize Join counters
  536. counters = create_node()
  537. join_nodes = allInstances(pm, "Join")
  538. while (read_nr_out(join_nodes) > 0):
  539. dict_add(counters, set_pop(join_nodes), 0)
  540. // Create the worklist with the Start instance as first element
  541. worklist = create_node()
  542. set_add(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  543. while (bool_not(pm_finished(worklist, pm))):
  544. // Pop a random element from the list and execute it
  545. tuple = set_pop(worklist)
  546. element = tuple[0]
  547. result = tuple[1]
  548. log("Enacting " + cast_v2s(element))
  549. // Find the type (to see what to do with it)
  550. // this does not yet yield the type of transformation, if it is an Execution
  551. type = read_type(pm, element)
  552. if (type == "Start"):
  553. // Initial node, just progress to the next elements
  554. // Nothing to do here though, as we have just started
  555. result = True
  556. elif (type == "Finish"):
  557. // Should be impossible, as we would have ended...
  558. result = result
  559. elif (type == "Fork"):
  560. result = result
  561. elif (type == "Join"):
  562. // Only do this if all dependencies are fullfilled
  563. // So add to the counter of this Join
  564. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  565. // Now check whether we have enough tokens to execute the Join itself
  566. Integer required
  567. Integer got
  568. required = read_nr_out(allIncomingAssociationInstances(pm, element, "Next")) + read_nr_out(allIncomingAssociationInstances(pm, element, "Else"))
  569. got = counters[element]
  570. if (got == required):
  571. // Reset counter to 0
  572. dict_overwrite(counters, element, 0)
  573. // And continue
  574. else:
  575. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  576. continue!
  577. elif (type == "Exec"):
  578. // Execute a transformation
  579. // This the difficult part!
  580. result = enact_action(pm, element, prefix, user_id)
  581. elif (type == "Decision"):
  582. // If the previous result is true, we add the normal one, otherwise the false one
  583. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  584. if (bool_not(result)):
  585. // Apparently it is False, so map this to the "Else" branch
  586. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  587. continue!
  588. else:
  589. // Apparently it is True, so map this to the "Then" branch
  590. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  591. continue!
  592. // We have finished the execution, so add all outgoing edges to the worklist
  593. Element all_next
  594. all_next = allAssociationDestinations(pm, element, "Next")
  595. String next
  596. while (read_nr_out(all_next) > 0):
  597. next = set_pop(all_next)
  598. set_add(worklist, create_tuple(next, result))
  599. // Reached a finish element, so stop
  600. return !
  601. Void function user_function_skip_init(user_id : String):
  602. String cmd
  603. output("Welcome to the Model Management Interface v2.0!")
  604. output("Use the 'help' command for a list of possible commands")
  605. while (True):
  606. output("Ready for command...")
  607. cmd = input()
  608. if (cmd == "help"):
  609. output("Model operations")
  610. output(" model_add -- Add a new model")
  611. output(" model_modify -- Modify an existing model")
  612. output(" model_list -- List all models")
  613. output(" model_list_full -- List all models with full info")
  614. output(" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata")
  615. output(" verify -- Check whether a model conforms to its metamodel")
  616. output("")
  617. output("Transformation-specific operations")
  618. output(" transformation_add_MT_language -- Create a RAMified metamodel of a set of models")
  619. output(" transformation_add_MT -- Initialize a new model transformation")
  620. output(" transformation_add_AL -- Initialize a new action language transformation")
  621. output(" transformation_add_MANUAL -- Initialize a new manual transformation")
  622. output(" transformation_execute -- Execute a transformation on a set of input models")
  623. output(" transformation_list -- List all model transformations")
  624. output(" transformation_list_full -- List all model transformations with permissions")
  625. output(" transformation_detail -- List transformation details")
  626. output(" transformation_RAMify -- RAMify a metamodel (again)")
  627. output("")
  628. output("Process operations")
  629. output(" process_execute -- Execute a process model")
  630. output("")
  631. output("Model permission operations")
  632. output(" permission_modify -- Change model permissions")
  633. output(" permission_owner -- Change model owner")
  634. output(" permission_group -- Change model group")
  635. output("")
  636. output("Group operations")
  637. output(" group_create -- Create a group")
  638. output(" group_delete -- Delete a group")
  639. output(" group_owner_add -- Add group owner")
  640. output(" group_owner_delete -- Remove group owner")
  641. output(" group_join -- Add someone to your group")
  642. output(" group_kick -- Kick someone from your group")
  643. output(" group_list -- List all groups you are a member of")
  644. output("")
  645. output("Admin operations")
  646. output(" admin_promote -- Promote a user to admin status")
  647. output(" admin_demote -- Demote a user to normal status")
  648. output("")
  649. output("General operations")
  650. output(" self-destruct -- Remove current user and revoke all permissions ")
  651. output(" exit -- Kill the current task, while retaining user")
  652. elif (cmd == "model_add"):
  653. // Model addition operation, which uses model upload commands of the compiler
  654. String name
  655. String type
  656. String location
  657. String type_id
  658. Element new_model
  659. String new_model_id
  660. output("Creating new model!")
  661. output("Model type?")
  662. type_id = get_model_id(input())
  663. if (type_id != ""):
  664. // Type exists
  665. if (allow_read(user_id, type_id)):
  666. // And is readable
  667. output("Model name?")
  668. name = input()
  669. if (get_model_id(name) == ""):
  670. // Model doesn't exist yet
  671. output("Waiting for model constructors...")
  672. new_model = construct_model_raw(get_full_model(type_id))
  673. model_create(new_model, name, user_id, type_id, "Model")
  674. output("Model upload success!")
  675. else:
  676. output("Model with that name already exists!")
  677. else:
  678. output("Permission denied")
  679. else:
  680. output("Could not find type model!")
  681. elif (cmd == "process_execute"):
  682. // Execute a process model until it reaches termination
  683. String process_id
  684. output("Which process model do you want to execute?")
  685. process_id = get_model_id(input())
  686. if (process_id != ""):
  687. if (allow_read(user_id, process_id)):
  688. output("Model prefix to use?")
  689. enact_PM(get_full_model(process_id), input(), user_id)
  690. else:
  691. output("Permission denied")
  692. else:
  693. output("No such model")
  694. elif (cmd == "transformation_execute"):
  695. // Execute a transformation, whatever type it is
  696. // First we detect the type, so we know how to prepare for invocation
  697. String transformation_id
  698. String exact_type
  699. Element sources
  700. Element targets
  701. String source
  702. String target
  703. String name_id
  704. Element inputs
  705. Element outputs
  706. Element trace_links
  707. String target_model_name
  708. String source_model_name
  709. String source_model_ID
  710. Element result
  711. Element keys
  712. String key
  713. output("Which transformation do you want to execute?")
  714. transformation_id = get_model_id(input())
  715. if (transformation_id != ""):
  716. if (allow_read(user_id, transformation_id)):
  717. if (is_nominal_instance(core, transformation_id, "Transformation")):
  718. // Read out source and target links
  719. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  720. inputs = create_node()
  721. while (read_nr_out(sources) > 0):
  722. source = set_pop(sources)
  723. output(string_join("Which model to bind for source type ", read_attribute(core, source, "name")))
  724. source_model_name = input()
  725. source_model_ID = get_model_id(source_model_name)
  726. if (name_id != ""):
  727. if (allow_read(user_id, name_id)):
  728. // Check for conformance to the requested metamodel
  729. if (check_is_typed_by(source_model_ID, source)):
  730. if (check_conformance(source_model_ID)):
  731. set_add(inputs, source_model_ID)
  732. continue!
  733. else:
  734. output("Model has correct type but does not conform completely!")
  735. else:
  736. output("Model has different type!")
  737. else:
  738. output("Permission denied")
  739. else:
  740. output("No such model")
  741. // Retry this model type
  742. set_add(sources, source)
  743. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  744. outputs = create_node()
  745. while (read_nr_out(targets) > 0):
  746. target = set_pop(targets)
  747. output(string_join("Which model to create for target type ", read_attribute(core, target, "name")))
  748. target_model_name = input()
  749. if (get_model_id(target_model_name) == ""):
  750. // Doesn't exist yet, so we can easily create
  751. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  752. else:
  753. // Already exists, so we need to check for write access
  754. if (allow_write(user_id, get_model_id(target_model_name))):
  755. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  756. else:
  757. output("Permission denied; try again")
  758. set_add(targets, target)
  759. result = execute_operation(transformation_id, inputs, dict_keys(outputs))
  760. // Now write out the models again
  761. if (element_eq(result, read_root())):
  762. // Something went wrong!
  763. log("Transformation failed; discarding changes")
  764. else:
  765. keys = dict_keys(result)
  766. while (read_nr_out(keys) > 0):
  767. key = set_pop(keys)
  768. if (get_model_id(outputs[key]) == ""):
  769. // New model
  770. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  771. else:
  772. model_overwrite(result[key], get_model_id(outputs[key]))
  773. else:
  774. output("Model is not an executable transformation")
  775. else:
  776. output("Permission denied")
  777. else:
  778. output("No such transformation")
  779. elif (cmd == "verify"):
  780. // Check whether a model conforms to its specification (with the selected type mapping)
  781. String model_id
  782. String result
  783. output("Which model to verify?")
  784. model_id = get_model_id(input())
  785. if (model_id != ""):
  786. if (allow_read(user_id, model_id)):
  787. result = conformance_scd(get_full_model(model_id))
  788. output(result)
  789. else:
  790. output("Permission denied")
  791. else:
  792. output("No such model")
  793. elif (cmd == "model_overwrite"):
  794. // Overwrites an existing model without changing any metadata
  795. String model_id
  796. Element new_model
  797. output("Which model to overwrite?")
  798. model_id = get_model_id(input())
  799. if (model_id != ""):
  800. if (allow_write(user_id, model_id)):
  801. if (allow_read(user_id, set_pop(followAssociation(core, model_id, "instanceOf")))):
  802. output("Waiting for model constructors...")
  803. new_model = construct_model_raw(get_full_model(set_pop(followAssociation(core, model_id, "instanceOf"))))
  804. model_overwrite(new_model, model_id)
  805. output("Model overwrite success!")
  806. else:
  807. output("Permission denied")
  808. else:
  809. output("Permission denied")
  810. else:
  811. output("No such model")
  812. elif (cmd == "model_modify"):
  813. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  814. String model_id
  815. String type_id
  816. output("Which model do you want to modify?")
  817. model_id = get_model_id(input())
  818. if (model_id != ""):
  819. if (allow_read(user_id, model_id)):
  820. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  821. if (allow_read(user_id, type_id)):
  822. modify(get_full_model(model_id), allow_write(user_id, model_id))
  823. else:
  824. output("Permission denied")
  825. else:
  826. output("Permission denied")
  827. else:
  828. output("Could not find model!")
  829. elif (cmd == "model_delete"):
  830. // Delete a model and all of its related transformations
  831. String model_id
  832. output("=================================================")
  833. output("WARNING: Deletion is a very destructive operation")
  834. output(" as it also deletes all transformations ")
  835. output(" defined which make use of this model! ")
  836. output("=================================================")
  837. output("")
  838. output("Currently not supported!")
  839. elif (cmd == "model_list"):
  840. // List all models
  841. Element models
  842. String m
  843. models = allInstances(core, "Model")
  844. while (read_nr_out(models) > 0):
  845. m = set_pop(models)
  846. output(string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name")))
  847. elif (cmd == "model_list_full"):
  848. // List all models with full info
  849. Element models
  850. String m
  851. String permissions
  852. String owner
  853. String group
  854. String name
  855. String type
  856. models = allInstances(core, "Model")
  857. while (read_nr_out(models) > 0):
  858. m = set_pop(models)
  859. permissions = read_attribute(core, m, "permissions")
  860. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  861. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  862. name = read_attribute(core, m, "name")
  863. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  864. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)
  865. elif (cmd == "transformation_add_MT_language"):
  866. // Create a model transformation language from a set of input and output formalisms
  867. String name
  868. String model_id
  869. Element source
  870. Element target
  871. Element all_formalisms
  872. Element merged_formalism
  873. Element ramified_formalism
  874. String old_type_id
  875. String type_id
  876. String location
  877. String new_model_id
  878. old_type_id = ""
  879. // Read involved formalisms
  880. all_formalisms = create_node()
  881. output("Formalisms to include (terminate with empty string)?")
  882. name = input()
  883. while (name != ""):
  884. model_id = get_model_id(name)
  885. if (model_id != ""):
  886. if (allow_read(user_id, model_id)):
  887. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  888. if (bool_or(old_type_id == "", type_id == old_type_id)):
  889. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  890. old_type_id = type_id
  891. elif (old_type_id != type_id):
  892. // Already have a previous type_id and now another: CLASH
  893. output("Cannot add model as types not compatible with previous models; try again")
  894. else:
  895. output("Model not readable; try again")
  896. else:
  897. output("No such model; try again")
  898. name = input()
  899. // Merge all into a single metamodel
  900. if (read_nr_out(all_formalisms) > 0):
  901. output("Name of the RAMified transformation metamodel?")
  902. name = input()
  903. if (get_model_id(name) == ""):
  904. String merged_formalism_id
  905. String ramified_formalism_id
  906. String source_formalism_id
  907. String tracability_link
  908. // New location is available, so write
  909. merged_formalism = model_fuse(set_copy(all_formalisms))
  910. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  911. merged_formalism_id = get_model_id("__merged_" + name)
  912. // Add tracability links at this level
  913. while (read_nr_out(all_formalisms) > 0):
  914. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  915. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  916. instantiate_attribute(core, tracability_link, "type", "merged")
  917. // Merge complete, now RAMify!
  918. ramified_formalism = ramify(merged_formalism)
  919. model_create(ramified_formalism, name, user_id, type_id, "Model")
  920. ramified_formalism_id = get_model_id(name)
  921. // Add tracability link at this level
  922. tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
  923. instantiate_attribute(core, tracability_link, "type", "RAMified")
  924. else:
  925. output("Model already exists!")
  926. else:
  927. output("At least one formalism is required")
  928. elif (cmd == "transformation_RAMify"):
  929. // RAMify a metamodel
  930. String merged_model_id
  931. String target_model_name
  932. String target_model_id
  933. Element target_model
  934. String tracability_link
  935. output("Which metamodel do you want to RAMify?")
  936. merged_model_id = get_model_id(input())
  937. if (merged_model_id != ""):
  938. if (allow_read(user_id, merged_model_id)):
  939. output("Where do you want to store the RAMified metamodel?")
  940. target_model_name = input()
  941. target_model_id = get_model_id(target_model_name)
  942. if (target_model_id == ""):
  943. // New model, so everything is fine
  944. target_model = ramify(get_full_model(merged_model_id))
  945. model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
  946. target_model_id = get_model_id(target_model_name)
  947. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  948. instantiate_attribute(core, tracability_link, "type", "RAMified")
  949. else:
  950. // Existing model, so overwrite
  951. if (allow_write(user_id, target_model_id)):
  952. target_model = ramify(get_full_model(merged_model_id))
  953. model_overwrite(target_model, target_model_id)
  954. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
  955. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  956. instantiate_attribute(core, tracability_link, "type", "RAMified")
  957. else:
  958. output("Permission denied")
  959. else:
  960. output("Permission denied!")
  961. else:
  962. output("No such model")
  963. elif (bool_or(cmd == "transformation_add_MANUAL", cmd == "transformation_add_AL")):
  964. // Add a manual transformation model
  965. String model_id
  966. Element models
  967. Element source
  968. Element target
  969. String name
  970. Element all_formalisms
  971. Element merged_formalism
  972. String merged_formalism_id
  973. String source_formalism_id
  974. String tracability_link
  975. String type_id
  976. String old_type_id
  977. source = create_node()
  978. target = create_node()
  979. all_formalisms = create_node()
  980. type_id = ""
  981. old_type_id = ""
  982. output("Which metamodels do you want to use as source for the operation (empty string to finish)?")
  983. name = input()
  984. while (name != ""):
  985. model_id = get_model_id(name)
  986. if (model_id != ""):
  987. if (allow_read(user_id, model_id)):
  988. if (bool_not(set_in(source, model_id))):
  989. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  990. if (bool_or(old_type_id == "", type_id == old_type_id)):
  991. old_type_id = type_id
  992. set_add(source, model_id)
  993. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  994. elif (old_type_id != type_id):
  995. // Already have a previous type_id and now another: CLASH
  996. output("Cannot add model as types not compatible with previous models; try again")
  997. else:
  998. output("Model already selected as source")
  999. else:
  1000. output("Permission denied")
  1001. else:
  1002. output("No such model; try again")
  1003. name = input()
  1004. output("Which metamodels do you want to use as target for the operation (empty string to finish)?")
  1005. name = input()
  1006. while (name != ""):
  1007. model_id = get_model_id(name)
  1008. if (model_id != ""):
  1009. if (allow_read(user_id, model_id)):
  1010. if (bool_not(set_in(target, model_id))):
  1011. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1012. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1013. old_type_id = type_id
  1014. set_add(target, model_id)
  1015. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1016. elif (old_type_id != type_id):
  1017. // Already have a previous type_id and now another: CLASH
  1018. output("Cannot add model as types not compatible with previous models; try again")
  1019. else:
  1020. output("Model already selected as target")
  1021. else:
  1022. output("Permission denied")
  1023. else:
  1024. output("No such model; try again")
  1025. name = input()
  1026. output("Name of operation model?")
  1027. name = input()
  1028. if (get_model_id(name) == ""):
  1029. if (cmd == "transformation_add_MANUAL"):
  1030. // Finished with all information, now create the model itself!
  1031. model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), name, user_id, get_model_id("ManualOperation"), "ManualOperation")
  1032. model_id = get_model_id(name)
  1033. elif (cmd == "transformation_add_AL"):
  1034. // Finished with all information, now create the model itself!
  1035. output("Waiting for model constructors...")
  1036. add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + name, construct_function())
  1037. model_create(import_node("AL/" + name), name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
  1038. model_id = get_model_id(name)
  1039. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1040. // New location is available, so write
  1041. merged_formalism = model_fuse(set_copy(all_formalisms))
  1042. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  1043. merged_formalism_id = get_model_id("__merged_" + name)
  1044. // Add tracability links at this level
  1045. while (read_nr_out(all_formalisms) > 0):
  1046. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1047. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1048. instantiate_attribute(core, tracability_link, "type", "merged")
  1049. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1050. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1051. // Extend metadata with info on source and target
  1052. String link
  1053. String dst
  1054. while (read_nr_out(source) > 0):
  1055. dst = set_pop(source)
  1056. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1057. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1058. while (read_nr_out(target) > 0):
  1059. dst = set_pop(target)
  1060. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1061. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1062. else:
  1063. output("Model already exists")
  1064. elif (cmd == "transformation_add_MT"):
  1065. // Add a model transformation model
  1066. // Just a usual model instantiation, but need to add the source and target links based on user info
  1067. String ramified_metamodel_id
  1068. String model_id
  1069. Element models
  1070. Element links
  1071. String link_id
  1072. Element supported
  1073. Element source
  1074. Element target
  1075. String name
  1076. String new_model_id
  1077. String merged_link_id
  1078. Element links_merged
  1079. String merged_metamodel_id
  1080. source = create_node()
  1081. target = create_node()
  1082. supported = create_node()
  1083. output("RAMified metamodel to use?")
  1084. ramified_metamodel_id = get_model_id(input())
  1085. if (ramified_metamodel_id != ""):
  1086. if (allow_read(user_id, ramified_metamodel_id)):
  1087. output("Supported metamodels:")
  1088. links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  1089. while (read_nr_out(links) > 0):
  1090. link_id = set_pop(links)
  1091. merged_metamodel_id = readAssociationDestination(core, link_id)
  1092. if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
  1093. links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  1094. while (read_nr_out(links_merged) > 0):
  1095. merged_link_id = set_pop(links_merged)
  1096. if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
  1097. output(string_join(" ", read_attribute(core, readAssociationDestination(core, merged_link_id), "name")))
  1098. set_add(supported, readAssociationDestination(core, merged_link_id))
  1099. output("Which metamodels do you want to use as source for the operation (empty string to finish)?")
  1100. name = input()
  1101. while (name != ""):
  1102. model_id = get_model_id(name)
  1103. if (model_id != ""):
  1104. if (set_in(supported, model_id)):
  1105. if (bool_not(set_in(source, model_id))):
  1106. set_add(source, model_id)
  1107. else:
  1108. output("Model already selected as source")
  1109. else:
  1110. output("Model is not supported by RAMified metamodel!")
  1111. else:
  1112. output("No such model; try again")
  1113. name = input()
  1114. output("Which metamodels do you want to use as target for the operation (empty string to finish)?")
  1115. name = input()
  1116. while (name != ""):
  1117. model_id = get_model_id(name)
  1118. if (model_id != ""):
  1119. if (set_in(supported, model_id)):
  1120. if (bool_not(set_in(target, model_id))):
  1121. set_add(target, model_id)
  1122. else:
  1123. output("Model already selected as target")
  1124. else:
  1125. output("Model is not supported by RAMified metamodel!")
  1126. else:
  1127. output("No such model; try again")
  1128. name = input()
  1129. output("Name of new operation?")
  1130. name = input()
  1131. if (get_model_id(name) == ""):
  1132. String new_model
  1133. // Finished with all information, now create the model itself!
  1134. output("Waiting for model constructors...")
  1135. new_model = construct_model_raw(get_full_model(ramified_metamodel_id))
  1136. model_create(new_model, name, user_id, ramified_metamodel_id, "ModelTransformation")
  1137. model_id = get_model_id(name)
  1138. // Extend metadata with info on source and target
  1139. String link
  1140. String dst
  1141. while (read_nr_out(source) > 0):
  1142. dst = set_pop(source)
  1143. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1144. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1145. while (read_nr_out(target) > 0):
  1146. dst = set_pop(target)
  1147. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1148. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1149. else:
  1150. output("Model already exists")
  1151. else:
  1152. output("Permission denied")
  1153. else:
  1154. output("No such model")
  1155. elif (cmd == "transformation_list"):
  1156. // List all models
  1157. Element models
  1158. String m
  1159. String type
  1160. models = allInstances(core, "Transformation")
  1161. while (read_nr_out(models) > 0):
  1162. m = set_pop(models)
  1163. output(string_join(("[" + read_type(core, m)) + "]", string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name"))))
  1164. elif (cmd == "transformation_list_full"):
  1165. // List all models with full info
  1166. Element models
  1167. String m
  1168. String permissions
  1169. String owner
  1170. String group
  1171. String name
  1172. String type
  1173. models = allInstances(core, "Transformation")
  1174. while (read_nr_out(models) > 0):
  1175. m = set_pop(models)
  1176. permissions = read_attribute(core, m, "permissions")
  1177. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1178. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1179. name = read_attribute(core, m, "name")
  1180. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1181. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type)
  1182. elif (cmd == "permission_modify"):
  1183. String permissions
  1184. Integer permission
  1185. String model_id
  1186. output("Which model do you want to change permissions of?")
  1187. model_id = get_model_id(input())
  1188. if (model_id != ""):
  1189. if (get_relation_to_model(user_id, model_id) == 0):
  1190. output("New permissions?")
  1191. permissions = input()
  1192. Boolean fail
  1193. Integer i
  1194. i = 0
  1195. if (string_len(permissions) != 3):
  1196. fail = True
  1197. while (i < 3):
  1198. permission = cast_s2i(string_get(permissions, i))
  1199. if (bool_or(permission < 0, permission > 2)):
  1200. fail = True
  1201. break!
  1202. i = i + 1
  1203. if (bool_not(fail)):
  1204. unset_attribute(core, model_id, "permissions")
  1205. instantiate_attribute(core, model_id, "permissions", permissions)
  1206. else:
  1207. output("Permissions must be a string of three characters with each character being a digit between 0 and 2")
  1208. else:
  1209. output("Permission denied!")
  1210. else:
  1211. output("No such model!")
  1212. elif (cmd == "permission_owner"):
  1213. String permissions
  1214. String model_id
  1215. String user_id
  1216. output("Which model do you want to change owner of?")
  1217. model_id = get_model_id(input())
  1218. if (model_id != ""):
  1219. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1220. output("New owner?")
  1221. user_id = get_user_id(input())
  1222. if (user_id != ""):
  1223. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1224. instantiate_link(core, "owner", "", model_id, user_id)
  1225. else:
  1226. output("No such user!")
  1227. else:
  1228. output("Permission denied!")
  1229. else:
  1230. output("No such model!")
  1231. elif (cmd == "permission_group"):
  1232. String permissions
  1233. String model_id
  1234. String group_id
  1235. output("Which model do you want to change permissions of?")
  1236. model_id = get_model_id(input())
  1237. if (model_id != ""):
  1238. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1239. output("New group?")
  1240. group_id = get_group_id(input())
  1241. if (group_id != ""):
  1242. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1243. instantiate_link(core, "group", "", model_id, group_id)
  1244. else:
  1245. output("No such group!")
  1246. else:
  1247. output("Permission denied!")
  1248. else:
  1249. output("No such model!")
  1250. elif (cmd == "group_create"):
  1251. // Create a new group and become its owner
  1252. String group_id
  1253. String name
  1254. output("Which group do you want to create?")
  1255. name = input()
  1256. group_id = get_group_id(name)
  1257. if (group_id == ""):
  1258. group_id = instantiate_node(core, "Group", "")
  1259. instantiate_attribute(core, group_id, "name", name)
  1260. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1261. instantiate_link(core, "owner", "", group_id, user_id)
  1262. output("Group created!")
  1263. else:
  1264. output("Group already exists")
  1265. elif (cmd == "group_delete"):
  1266. // Delete an existing group
  1267. String group_id
  1268. String name
  1269. output("Which group do you want to delete?")
  1270. name = input()
  1271. group_id = get_group_id(name)
  1272. if (group_id != ""):
  1273. if (allow_group_modify(user_id, group_id)):
  1274. model_delete_element(core, group_id)
  1275. else:
  1276. output("Permission denied")
  1277. else:
  1278. output("No such group")
  1279. elif (cmd == "group_owner_add"):
  1280. // Add an owner to your group
  1281. String group_id
  1282. String other_user_id
  1283. output("Which group do you want to add an owner to?")
  1284. group_id = get_group_id(input())
  1285. if (group_id != ""):
  1286. if (allow_group_modify(user_id, group_id)):
  1287. output("Which user do you want to make an owner?")
  1288. other_user_id = get_user_id(input())
  1289. if (other_user_id != ""):
  1290. Element overlap
  1291. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1292. if (read_nr_out(overlap) == 0):
  1293. instantiate_link(core, "owner", "", group_id, other_user_id)
  1294. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1295. if (read_nr_out(overlap) == 0):
  1296. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1297. output("New owner added to group!")
  1298. else:
  1299. output("User is already an owner!")
  1300. else:
  1301. output("No such user")
  1302. else:
  1303. output("Permission denied!")
  1304. else:
  1305. output("No such group")
  1306. elif (cmd == "group_owner_delete"):
  1307. // Remove an owner from your group
  1308. String group_id
  1309. String other_user_id
  1310. output("Which group do you want to disown someone from?")
  1311. group_id = get_group_id(input())
  1312. if (group_id != ""):
  1313. if (allow_group_modify(user_id, group_id)):
  1314. output("Which user do you want to disown?")
  1315. other_user_id = get_user_id(input())
  1316. if (other_user_id != ""):
  1317. Element overlap
  1318. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1319. if (read_nr_out(overlap) > 0):
  1320. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1321. if (read_nr_out(overlap) > 0):
  1322. model_delete_element(core, set_pop(overlap))
  1323. output("Disowned group from user!")
  1324. else:
  1325. output("User is not even an owner of the group!")
  1326. else:
  1327. output("User is not even a member of the group!")
  1328. else:
  1329. output("No such user")
  1330. else:
  1331. output("Permission denied!")
  1332. else:
  1333. output("No such group")
  1334. elif (cmd == "group_join"):
  1335. // Add someone to your group
  1336. String group_id
  1337. String other_user_id
  1338. output("Which group do you want to add someone to?")
  1339. group_id = get_group_id(input())
  1340. if (group_id != ""):
  1341. if (allow_group_modify(user_id, group_id)):
  1342. output("Which user do you want to add?")
  1343. other_user_id = get_user_id(input())
  1344. if (other_user_id != ""):
  1345. Element overlap
  1346. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1347. if (read_nr_out(overlap) == 0):
  1348. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1349. output("User added to the group!")
  1350. else:
  1351. output("User is already a member of the group!")
  1352. else:
  1353. output("No such user")
  1354. else:
  1355. output("Permission denied!")
  1356. else:
  1357. output("No such group")
  1358. elif (cmd == "group_kick"):
  1359. // Remove someone from your group
  1360. String group_id
  1361. String other_user_id
  1362. output("Which group do you want to kick someone from?")
  1363. group_id = get_group_id(input())
  1364. if (group_id != ""):
  1365. if (allow_group_modify(user_id, group_id)):
  1366. output("Which user do you want to kick?")
  1367. other_user_id = get_user_id(input())
  1368. if (other_user_id != ""):
  1369. Element overlap
  1370. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1371. if (read_nr_out(overlap) > 0):
  1372. model_delete_element(core, set_pop(overlap))
  1373. // Check if user was an owner as well
  1374. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1375. if (read_nr_out(overlap) > 0):
  1376. model_delete_element(core, set_pop(overlap))
  1377. output("User kicked!")
  1378. else:
  1379. output("User is not even a member of the group!")
  1380. else:
  1381. output("No such user")
  1382. else:
  1383. output("Permission denied!")
  1384. else:
  1385. output("No such group")
  1386. elif (cmd == "group_list"):
  1387. // List all groups you are a member of (and whether you are admin or not!)
  1388. Element groups
  1389. String group_id
  1390. String admin
  1391. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1392. while (read_nr_out(groups) > 0):
  1393. group_id = set_pop(groups)
  1394. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  1395. admin = " A "
  1396. else:
  1397. admin = " "
  1398. output(string_join(admin, read_attribute(core, group_id, "name")))
  1399. elif (cmd == "admin_promote"):
  1400. // Promote a user to admin status
  1401. if (is_admin(user_id)):
  1402. String other_user_id
  1403. output("Which user do you want to promote?")
  1404. other_user_id = get_user_id(input())
  1405. if (other_user_id != ""):
  1406. unset_attribute(core, other_user_id, "admin")
  1407. instantiate_attribute(core, other_user_id, "admin", True)
  1408. output("Permissions granted!")
  1409. else:
  1410. output("No such user!")
  1411. else:
  1412. output("Permission denied!")
  1413. elif (cmd == "admin_demote"):
  1414. // Demote a user to normal status
  1415. if (is_admin(user_id)):
  1416. String other_user_id
  1417. output("Which user do you want to demote?")
  1418. other_user_id = get_user_id(input())
  1419. if (other_user_id != ""):
  1420. unset_attribute(core, other_user_id, "admin")
  1421. instantiate_attribute(core, other_user_id, "admin", False)
  1422. output("Permissions revoked!")
  1423. else:
  1424. output("No such user!")
  1425. else:
  1426. output("Permission denied!")
  1427. elif (cmd == "self-destruct"):
  1428. // Delete user from Core Formalism
  1429. model_delete_element(core, user_id)
  1430. return !
  1431. elif (cmd == "exit"):
  1432. // Exit by actually removing the user and decoupling it from all of its models
  1433. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1434. // as the current user will have been deleted
  1435. return !
  1436. else:
  1437. output("Unknown command: " + cmd)
  1438. // We never get here!
  1439. return !