core_algorithm.alc 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377
  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. include "utils.alh"
  13. include "conformance_finding.alh"
  14. include "typing.alh"
  15. include "compiler.alh"
  16. include "random.alh"
  17. String core_model_location = "models/core"
  18. Element core = ?
  19. String current_user_id
  20. Element caches
  21. String function get_foldername(name : String):
  22. Element result
  23. result = string_split(name, "/")
  24. list_pop_final(result)
  25. if (list_len(result) == 0):
  26. return ""!
  27. // 'result' now contains a list of entries which we have to join with the seperator
  28. String str
  29. str = list_pop(result, 0)
  30. while (list_len(result) > 0):
  31. str = string_join(str + "/", list_pop(result, 0))
  32. return str!
  33. String function get_filename(name : String):
  34. return list_pop_final(string_split(name, "/"))!
  35. String function full_name(model_id : String):
  36. return read_attribute(core, model_id, "name")!
  37. Void function initialize_core():
  38. // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
  39. add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
  40. return !
  41. Boolean function is_typed_by(model_id : String, metamodel_id : String):
  42. return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
  43. Element function get_instanceOf_links(model_id : String, metamodel_id : String):
  44. Element result
  45. Element options
  46. String elem
  47. result = set_create()
  48. options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  49. while (set_len(options) > 0):
  50. elem = set_pop(options)
  51. if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
  52. set_add(result, elem)
  53. return result!
  54. String function get_instanceOf_link(model_id : String, metamodel_id : String):
  55. Element all_links
  56. String choice
  57. all_links = get_instanceOf_links(model_id, metamodel_id)
  58. if (set_len(all_links) > 1):
  59. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  60. elif (set_len(all_links) == 0):
  61. log("No types found!")
  62. log("Source model: " + cast_value(read_attribute(core, model_id, "name")))
  63. log("Target meta-model: " + cast_value(read_attribute(core, metamodel_id, "name")))
  64. return read_root()!
  65. choice = set_pop(all_links)
  66. return choice!
  67. Element function get_full_model(model_id : String, metamodel_id : String):
  68. // TODO we are restricted to using formalisms/SimpleClassDiagrams as M3 level, through this code!
  69. Element m
  70. Element all_links
  71. String choice
  72. choice = get_instanceOf_link(model_id, metamodel_id)
  73. m = dict_create()
  74. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  75. // TODO for now this is restricted to the fixed semantics
  76. // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
  77. dict_add(m, "semantics", get_entry_id("models/conformance_mv"))
  78. if (metamodel_id == model_id):
  79. // Found the meta-circular level, so we can stop!
  80. dict_add(m, "metamodel", m)
  81. else:
  82. Element mm
  83. mm = get_full_model(metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  84. if (element_eq(mm, read_root())):
  85. return read_root()!
  86. else:
  87. dict_add(m, "metamodel", mm)
  88. if (element_neq(choice, read_root())):
  89. Element types
  90. types = allAssociationDestinations(core, choice, "typing")
  91. if (set_len(types) == 1):
  92. // Add the preferred original type mapping
  93. set_type_mapping(m, import_node(read_attribute(core, set_pop(types), "location")))
  94. else:
  95. // Start from scratch
  96. new_type_mapping(m)
  97. else:
  98. // Start from scratch
  99. new_type_mapping(m)
  100. if (find_type_mapping(m)):
  101. // TODO store the found type model somewhere
  102. return m!
  103. else:
  104. log("No type mapping could be deduced!")
  105. log("Error for " + cast_value(read_attribute(core, model_id, "name")))
  106. log(" and type " + cast_value(read_attribute(core, metamodel_id, "name")))
  107. return read_root()!
  108. Integer function get_relation_to_model(user_id : String, model_id : String):
  109. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  110. // We are the owner
  111. return 0!
  112. else:
  113. String group_id
  114. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  115. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  116. // We are in the owning group
  117. return 1!
  118. else:
  119. // We are not related whatsoever
  120. return 2!
  121. Boolean function is_admin(user_id : String):
  122. if (read_attribute(core, user_id, "admin")):
  123. return True!
  124. else:
  125. return False!
  126. Boolean function allow_read(user_id : String, model_id : String):
  127. if (is_admin(user_id)):
  128. // Is admin, so always allow
  129. return True!
  130. else:
  131. // Check permissions
  132. String permission
  133. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  134. if (bool_or(permission == "1", permission == "2")):
  135. return True!
  136. else:
  137. return False!
  138. Boolean function allow_write(user_id : String, model_id : String):
  139. if (is_admin(user_id)):
  140. // Is admin, so always allow
  141. return True!
  142. else:
  143. // Check permissions
  144. String permission
  145. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  146. if (permission == "2"):
  147. return True!
  148. else:
  149. return False!
  150. Boolean function allow_change_metadata(user_id : String, model_id : String):
  151. if (is_admin(user_id)):
  152. // Is admin, so always allow
  153. return True!
  154. else:
  155. if (get_relation_to_model(user_id, model_id) == 0):
  156. // Only owner can chmod
  157. return True!
  158. else:
  159. return False!
  160. Boolean function allow_group_modify(user_id : String, group_id : String):
  161. if (is_admin(user_id)):
  162. // Is admin, so always allow
  163. return True!
  164. else:
  165. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  166. // We are an owner
  167. return True!
  168. else:
  169. return False!
  170. Boolean function check_login(user_id : String):
  171. String password
  172. String stored_password
  173. stored_password = read_attribute(core, user_id, "password")
  174. output("Password for existing user?")
  175. password = hash(input())
  176. return password == stored_password!
  177. Void function new_task():
  178. String username
  179. String user_id
  180. String password
  181. // Load in a hard-reference to the previously created model
  182. core = import_node(core_model_location)
  183. while (True):
  184. output("Log on as which user?")
  185. username = input()
  186. user_id = get_user_id(username)
  187. if (user_id == ""):
  188. // New user
  189. // Add user to Core Formalism
  190. user_id = instantiate_node(core, "User", "")
  191. instantiate_attribute(core, user_id, "name", username)
  192. instantiate_attribute(core, user_id, "admin", False)
  193. output("This is a new user: please give password!")
  194. password = hash(input())
  195. output("Please repeat the password")
  196. if (password == hash(input())):
  197. output("Passwords match!")
  198. instantiate_attribute(core, user_id, "password", password)
  199. break!
  200. else:
  201. output("Not the same password!")
  202. else:
  203. if (check_login(user_id)):
  204. break!
  205. else:
  206. output("Wrong password!")
  207. user_function_skip_init(user_id)
  208. // User destroyed already, so just stop execution
  209. return!
  210. String function get_entry_id(name : String):
  211. Element hierarchy_split
  212. String current
  213. Integer i
  214. Element elems
  215. String current_part
  216. String elem
  217. Boolean found
  218. if (name == ""):
  219. return caches["root"]!
  220. if (dict_in(caches["models"], name)):
  221. if (dict_in(core, caches["models"])):
  222. if (full_name(caches["models"][name]) == name):
  223. return caches["models"][name]!
  224. current = get_entry_id(get_foldername(name))
  225. if (current == ""):
  226. return ""!
  227. if (current_part != ""):
  228. elems = allAssociationDestinations(core, current, "contains")
  229. while (set_len(elems) > 0):
  230. elem = set_pop(elems)
  231. dict_overwrite(caches["models"], read_attribute(core, elem, "name"), elem)
  232. if (value_eq(name, read_attribute(core, elem, "name"))):
  233. return elem!
  234. else:
  235. return current!
  236. return ""!
  237. String function get_service_id(name : String):
  238. core = import_node(core_model_location)
  239. Element services
  240. String service
  241. services = allInstances(core, "Service")
  242. while (set_len(services) > 0):
  243. service = set_pop(services)
  244. if (value_eq(read_attribute(core, service, "name"), name)):
  245. return service!
  246. return ""!
  247. String function get_user_id(name : String):
  248. Element users
  249. String user
  250. users = allInstances(core, "User")
  251. while (set_len(users) > 0):
  252. user = set_pop(users)
  253. if (value_eq(read_attribute(core, user, "name"), name)):
  254. return user!
  255. return ""!
  256. String function get_group_id(name : String):
  257. Element groups
  258. String group
  259. groups = allInstances(core, "Group")
  260. while (set_len(groups) > 0):
  261. group = set_pop(groups)
  262. if (value_eq(read_attribute(core, group, "name"), name)):
  263. return group!
  264. return ""!
  265. String function create_folders(user_id : String, folder_name : String):
  266. Element hierarchy
  267. Integer i
  268. String prev
  269. String elem
  270. String new_entry
  271. String cummul
  272. if (get_entry_id(folder_name) != ""):
  273. // Folders already exist, so don't iterate
  274. return get_entry_id(folder_name)!
  275. i = 0
  276. hierarchy = string_split(folder_name, "/")
  277. prev = get_entry_id("")
  278. cummul = ""
  279. // Go through folders first
  280. while (i < list_len(hierarchy)):
  281. elem = list_read(hierarchy, i)
  282. if (cummul == ""):
  283. cummul = elem
  284. else:
  285. cummul = string_join(cummul + "/", elem)
  286. if (get_entry_id(cummul) == ""):
  287. if (allow_write(user_id, prev)):
  288. // Element does not exist yet!
  289. new_entry = instantiate_node(core, "Folder", "")
  290. instantiate_attribute(core, new_entry, "name", cummul)
  291. instantiate_attribute(core, new_entry, "permissions", "200")
  292. instantiate_link(core, "contains", "", prev, new_entry)
  293. instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
  294. instantiate_link(core, "owner", "", new_entry, user_id)
  295. else:
  296. return read_root()!
  297. prev = get_entry_id(cummul)
  298. i = i + 1
  299. return prev!
  300. String function store_entry(model_id : String, full_name : String, user_id : String):
  301. String prev
  302. if (get_entry_id(full_name) != ""):
  303. // Delete any old models
  304. model_delete(get_entry_id(full_name))
  305. prev = create_folders(user_id, get_foldername(full_name))
  306. instantiate_link(core, "contains", "", prev, model_id)
  307. return full_name!
  308. String function export_typing(model : Element, name : String):
  309. String result
  310. result = instantiate_node(core, "TypeMapping", "")
  311. name = "type mappings/" + name
  312. // Create type mapping model
  313. String location
  314. location = "type mappings/" + cast_id(get_type_mapping(model))
  315. export_node(location, get_type_mapping(model))
  316. String instance_of
  317. name = store_entry(result, name, get_user_id("admin"))
  318. instantiate_attribute(core, result, "name", name)
  319. instantiate_attribute(core, result, "location", location)
  320. instantiate_attribute(core, result, "permissions", "200")
  321. instantiate_link(core, "owner", "", result, current_user_id)
  322. instantiate_link(core, "group", "", result, get_group_id("nobody"))
  323. instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("formalisms/TypeMapping"))
  324. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  325. return result!
  326. Void function model_create(model : Element, name : String, type_id : String, kind : String):
  327. String location
  328. String model_id
  329. String instance_of
  330. // Create model itself
  331. location = "models/" + cast_id(model)
  332. export_node(location, model["model"])
  333. model_id = instantiate_node(core, kind, "")
  334. instantiate_attribute(core, model_id, "name", store_entry(model_id, name, current_user_id))
  335. instantiate_attribute(core, model_id, "location", location)
  336. instantiate_attribute(core, model_id, "permissions", "200")
  337. instantiate_link(core, "owner", "", model_id, current_user_id)
  338. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  339. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  340. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  341. // Create type mapping model
  342. instantiate_link(core, "typing", "", instance_of, export_typing(model, name))
  343. return!
  344. Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
  345. // TODO this should be more elegant than just hiding the old elements
  346. String location
  347. String instanceOf_link
  348. location = "models/" + cast_id(model)
  349. export_node(location, model["model"])
  350. // Change location in meta-data
  351. unset_attribute(core, model_id, "location")
  352. instantiate_attribute(core, model_id, "location", location)
  353. // Update the instanceOf relation of the context in which we are working
  354. String choice
  355. choice = get_instanceOf_link(model_id, metamodel_id)
  356. if (element_neq(choice, read_root())):
  357. // There was a link, so we remove it
  358. // First remove the type mapping it referred to
  359. Element tl
  360. tl = allAssociationDestinations(core, choice, "typing")
  361. while (set_len(tl) > 0):
  362. model_delete_element(core, set_pop(tl))
  363. // Now delete the element itself
  364. model_delete_element(core, choice)
  365. // Create a new instanceOf relation now
  366. String instance_of
  367. instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
  368. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  369. instantiate_link(core, "typing", "", instance_of, export_typing(model, full_name(model_id)))
  370. return!
  371. Boolean function check_conformance(model_id : String):
  372. // TODO check if it actually conforms, considering that instanceOf link
  373. // --> in-depth check
  374. return True!
  375. Boolean function pm_finished(worklist : Element, pm : String):
  376. Element finished
  377. Integer cnt
  378. Integer i
  379. // Check if any of the "finish" elements are in the worklist
  380. // If so, we can already finish, and therefore will stop immediately
  381. finished = allInstances(pm, "Finish")
  382. worklist = set_copy(worklist)
  383. while (set_len(worklist) > 0):
  384. // Check each finished element individually
  385. if (set_in(finished, list_read(set_pop(worklist), 0))):
  386. return True!
  387. return False!
  388. Element function merge_models(models_dict : Element, operation_name : String):
  389. core = import_node(core_model_location)
  390. // 0) Find operation signature
  391. Element input_metamodels
  392. Element iter
  393. String edge
  394. String operation_id
  395. operation_id = get_entry_id(operation_name)
  396. input_metamodels = dict_create()
  397. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  398. while (set_len(iter) > 0):
  399. edge = set_pop(iter)
  400. dict_add(input_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
  401. String merged_metamodel_id
  402. String trace_link_id
  403. Element trace_links
  404. // 1) Find merged metamodel
  405. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  406. merged_metamodel_id = ""
  407. while (set_len(trace_links) > 0):
  408. trace_link_id = set_pop(trace_links)
  409. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  410. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  411. // 2) Merge source models
  412. if (merged_metamodel_id != ""):
  413. Element model_tuples
  414. Element keys
  415. String key
  416. Element mm
  417. model_tuples = set_create()
  418. keys = dict_keys(models_dict)
  419. while (set_len(keys) > 0):
  420. key = set_pop(keys)
  421. mm = get_full_model(get_entry_id(models_dict[key]), get_entry_id(input_metamodels[key]))
  422. if (element_eq(mm, read_root())):
  423. log("Signature mismatch in operation for tag " + key)
  424. output("Signature mismatch in operation for tag " + key)
  425. return read_root()!
  426. set_add_node(model_tuples, create_tuple(key, mm))
  427. Element merged_metamodel
  428. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("SimpleClassDiagrams"))
  429. if (element_eq(merged_metamodel, read_root())):
  430. log("Merged metamodel in operation is not of type SimpleClassDiagrams")
  431. output("Merged metamodel in operation is not of type SimpleClassDiagrams")
  432. return read_root()!
  433. return model_join(model_tuples, merged_metamodel, read_root())!
  434. else:
  435. return read_root()!
  436. Element function split_model(model : Element, metamodels_dict : Element):
  437. core = import_node(core_model_location)
  438. Element model_tuples
  439. Element keys
  440. String key
  441. Element mm
  442. model_tuples = set_create()
  443. keys = dict_keys(metamodels_dict)
  444. while (set_len(keys) > 0):
  445. key = set_pop(keys)
  446. mm = get_full_model(get_entry_id(metamodels_dict[key]), get_entry_id("SimpleClassDiagrams"))
  447. if (element_eq(mm, read_root())):
  448. log("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  449. output("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  450. return read_root()!
  451. set_add_node(model_tuples, create_tuple(key, mm))
  452. return model_split(model, model_tuples, read_root())!
  453. Element function get_model(model_name : String, metamodel_name : String):
  454. core = import_node(core_model_location)
  455. return get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))!
  456. Void function store_model(model_name : String, metamodel_name : String, model : Element):
  457. core = import_node(core_model_location)
  458. if (get_entry_id(model_name) == ""):
  459. // New model
  460. model_create(model, model_name, get_entry_id(metamodel_name), "Model")
  461. else:
  462. model_overwrite(model, get_entry_id(model_name), get_entry_id(metamodel_name))
  463. return!
  464. String function get_ramified_metamodel(model_name : String):
  465. core = import_node(core_model_location)
  466. String operation_id
  467. Element trace_links
  468. String merged_metamodel_id
  469. String trace_link_id
  470. String ramified_metamodel_id
  471. operation_id = get_entry_id(model_name)
  472. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  473. merged_metamodel_id = ""
  474. while (set_len(trace_links) > 0):
  475. trace_link_id = set_pop(trace_links)
  476. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  477. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  478. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  479. ramified_metamodel_id = ""
  480. while (set_len(trace_links) > 0):
  481. trace_link_id = set_pop(trace_links)
  482. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  483. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  484. return read_attribute(core, ramified_metamodel_id, "name")!
  485. return read_root()!
  486. Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
  487. // Operations are always in-place and uses only a single metamodel
  488. // Therefore, we must:
  489. // 1) Find merged metamodel
  490. // 2) Merge the different source models and retype
  491. // 3) Perform the operation on the merged model
  492. // 4) Split the resulting model based on the target formalisms; if operation successful
  493. Element input_model
  494. String trace_link_id
  495. Element merged_model
  496. String merged_metamodel_id
  497. String ramified_metamodel_id
  498. Boolean result
  499. String exact_type
  500. Element trace_links
  501. String model_ID
  502. String key
  503. Element keys
  504. Element input_keys
  505. Element output_keys
  506. Element model_tuples
  507. String metamodel_name
  508. Element metamodel
  509. String metamodel_ID
  510. Boolean tracability
  511. // 0) Find the signature of the operation
  512. Element input_metamodels
  513. Element output_metamodels
  514. Element iter
  515. String edge
  516. input_metamodels = dict_create()
  517. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  518. while (set_len(iter) > 0):
  519. edge = set_pop(iter)
  520. dict_add(input_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  521. output_metamodels = dict_create()
  522. iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
  523. while (set_len(iter) > 0):
  524. edge = set_pop(iter)
  525. dict_add(output_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  526. // 1) Find merged metamodel
  527. exact_type = read_type(core, operation_id)
  528. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  529. merged_metamodel_id = ""
  530. while (set_len(trace_links) > 0):
  531. trace_link_id = set_pop(trace_links)
  532. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  533. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  534. // 2) Merge source models
  535. if (merged_metamodel_id != ""):
  536. model_tuples = set_create()
  537. keys = dict_keys(input_models)
  538. while (set_len(keys) > 0):
  539. key = set_pop(keys)
  540. Element mm
  541. mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
  542. if (element_eq(mm, read_root())):
  543. log("Signature mismatch in operation for tag " + key)
  544. output("Signature mismatch in operation for tag " + key)
  545. return read_root()!
  546. set_add_node(model_tuples, create_tuple(key, mm))
  547. Element merged_metamodel
  548. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  549. if (element_eq(merged_metamodel, read_root())):
  550. log("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  551. output("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  552. return read_root()!
  553. merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
  554. else:
  555. if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
  556. // Just skip the merge...
  557. Element m
  558. m = get_full_model(get_entry_id(input_models[set_pop(dict_keys(input_models))]), get_entry_id(input_metamodels[set_pop(dict_keys(input_metamodels))]))
  559. if (element_eq(m, read_root())):
  560. log("Signature mismatch in operation for tag " + cast_value(set_pop(dict_keys(input_models))))
  561. output("Signature mismatch in operation for tag " + cast_value(set_pop(dict_keys(input_models))))
  562. return read_root()!
  563. merged_model = model_copy(m)
  564. elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
  565. merged_model = read_root()
  566. else:
  567. log("Could not resolve intermediate merged metamodel")
  568. output("Could not resolve intermediate merged metamodel")
  569. return read_root()!
  570. // 3) Transform
  571. if (exact_type == "ModelTransformation"):
  572. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  573. ramified_metamodel_id = ""
  574. while (set_len(trace_links) > 0):
  575. trace_link_id = set_pop(trace_links)
  576. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  577. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  578. Element operation
  579. operation = get_full_model(operation_id, ramified_metamodel_id)
  580. if (element_eq(operation, read_root())):
  581. log("Operation could not be typed by specified RAMified metamodel!")
  582. output("Operation could not be typed by specified RAMified metamodel!")
  583. return read_root()!
  584. result = transform(merged_model, operation)
  585. elif (exact_type == "ManualOperation"):
  586. output("Please perform manual operation " + cast_value(full_name(operation_id)))
  587. String model_name
  588. model_name = ""
  589. while (get_entry_id(model_name) != ""):
  590. model_name = ".tmp/" + random_string(20)
  591. model_create(merged_model, model_name, merged_metamodel_id, "Model")
  592. output("Operating on: " + cast_string(model_name))
  593. // We want to modify, so modify
  594. if (modify(merged_model, True)):
  595. // Overwrite the merged model
  596. model_overwrite(merged_model, get_entry_id(model_name), merged_metamodel_id)
  597. else:
  598. // Reload the merged model
  599. merged_model = get_full_model(get_entry_id(model_name), merged_metamodel_id)
  600. //model_delete(get_entry_id(model_name))
  601. result = True
  602. elif (exact_type == "ActionLanguage"):
  603. Element func
  604. Element al
  605. al = get_full_model(operation_id, get_entry_id("formalisms/ActionLanguage"))
  606. if (element_eq(al, read_root())):
  607. log("Action Language operation not typed by ActionLanguage metamodel!")
  608. output("Action Language operation not typed by ActionLanguage metamodel!")
  609. return read_root()!
  610. func = get_func_AL_model(al)
  611. result = func(merged_model)
  612. else:
  613. log("Unknown type of operation: " + exact_type)
  614. output("Unknown type of operation: " + exact_type)
  615. return read_root()!
  616. // 4) Split in different models depending on type
  617. if (element_neq(tracability_model, read_root())):
  618. tracability = True
  619. else:
  620. tracability = False
  621. if (result):
  622. model_tuples = set_create()
  623. keys = dict_keys(output_metamodels)
  624. while (set_len(keys) > 0):
  625. key = set_pop(keys)
  626. Element mm
  627. mm = get_full_model(get_entry_id(output_metamodels[key]), get_entry_id("formalisms/SimpleClassDiagrams"))
  628. if (element_eq(mm, read_root())):
  629. log("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  630. output("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  631. return read_root()!
  632. set_add_node(model_tuples, create_tuple(key, mm))
  633. result = model_split(merged_model, model_tuples, tracability)
  634. if (tracability):
  635. Element new_tracability_model
  636. new_tracability_model = result["__tracability"]
  637. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  638. set_type_mapping(tracability_model, get_type_mapping(new_tracability_model))
  639. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  640. dict_delete(result, "__tracability")
  641. return result!
  642. else:
  643. log("Negative result of execution")
  644. return read_root()!
  645. Boolean function enact_action(pm : Element, element : String, mapping : Element):
  646. Boolean result
  647. String transformation_id
  648. Element lst
  649. String elem
  650. Element inputs
  651. Element outputs
  652. String type_name
  653. String exact_type
  654. Element trace_links
  655. Element output_mms
  656. Element consumes_link
  657. String name
  658. String value
  659. String elem_name
  660. Element keys
  661. String key
  662. String consume
  663. String produce
  664. Element output_map
  665. inputs = dict_create()
  666. outputs = dict_create()
  667. output_map = dict_create()
  668. // Read out the referenced element from the MvC
  669. transformation_id = get_entry_id(read_attribute(pm, element, "name"))
  670. // Find all input model names
  671. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  672. while (set_len(lst) > 0):
  673. consume = set_pop(lst)
  674. value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
  675. dict_add(inputs, read_attribute(pm, consume, "name"), mapping[value])
  676. // Find all output model names and their metamodel
  677. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  678. while (set_len(lst) > 0):
  679. produce = set_pop(lst)
  680. elem = readAssociationDestination(pm, produce)
  681. type_name = read_attribute(pm, elem, "type")
  682. elem_name = read_attribute(pm, elem, "name")
  683. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  684. dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
  685. if read_type(core, transformation_id) == "ActionLanguage":
  686. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  687. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  688. elif read_type(core, transformation_id) == "ManualOperation":
  689. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  690. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  691. else:
  692. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  693. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  694. result = execute_operation(transformation_id, inputs, read_root())
  695. if (element_eq(result, read_root())):
  696. // Something went wrong!
  697. return False!
  698. else:
  699. keys = dict_keys(outputs)
  700. while (set_len(keys) > 0):
  701. key = set_pop(keys)
  702. if (get_entry_id(output_map[key]) == ""):
  703. // New model
  704. model_create(result[key], output_map[key], get_entry_id(outputs[key]), "Model")
  705. else:
  706. model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
  707. return True!
  708. Element function PM_signature(pm : Element):
  709. Element all_data
  710. Element result
  711. String entry
  712. result = dict_create()
  713. all_data = allInstances(pm, "Data")
  714. while (set_len(all_data) > 0):
  715. entry = set_pop(all_data)
  716. dict_add(result, cast_string(read_attribute(pm, entry, "name")), cast_string(read_attribute(pm, entry, "type")))
  717. return result!
  718. Void function enact_PM(pm : Element, mapping : Element):
  719. Element worklist
  720. String element
  721. String type
  722. Boolean result
  723. Element tuple
  724. Element counters
  725. Element join_nodes
  726. Element keys
  727. String key
  728. output("Success")
  729. // For all entries in the signature, not in the mapping, we add a mock location
  730. Element signature
  731. String mock_location
  732. Element mock_locations
  733. mock_locations = set_create()
  734. signature = PM_signature(pm)
  735. keys = dict_keys(signature)
  736. while (set_len(keys) > 0):
  737. key = set_pop(keys)
  738. if (bool_not(dict_in(mapping, key))):
  739. // Add mock location
  740. mock_location = ""
  741. while (get_entry_id(mock_location) != ""):
  742. mock_location = ".tmp/" + random_string(10)
  743. dict_add(mapping, key, mock_location)
  744. set_add(mock_locations, mock_location)
  745. // Initialize Join counters
  746. counters = dict_create()
  747. join_nodes = allInstances(pm, "Join")
  748. while (set_len(join_nodes) > 0):
  749. dict_add(counters, set_pop(join_nodes), 0)
  750. // Create the worklist with the Start instance as first element
  751. worklist = set_create()
  752. set_add_node(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  753. while (bool_not(pm_finished(worklist, pm))):
  754. // Pop a random element from the list and execute it
  755. tuple = set_pop(worklist)
  756. element = tuple[0]
  757. result = tuple[1]
  758. // Find the type (to see what to do with it)
  759. // this does not yet yield the type of transformation, if it is an Execution
  760. type = read_type(pm, element)
  761. if (type == "Start"):
  762. // Initial node, just progress to the next elements
  763. // Nothing to do here though, as we have just started
  764. result = True
  765. elif (type == "Finish"):
  766. // Should be impossible, as we would have ended...
  767. result = result
  768. elif (type == "Fork"):
  769. result = result
  770. elif (type == "Join"):
  771. // Only do this if all dependencies are fullfilled
  772. // So add to the counter of this Join
  773. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  774. // Now check whether we have enough tokens to execute the Join itself
  775. Integer required
  776. Integer got
  777. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  778. got = counters[element]
  779. if (got == required):
  780. // Reset counter to 0
  781. dict_overwrite(counters, element, 0)
  782. // And continue
  783. else:
  784. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  785. continue!
  786. elif (type == "Exec"):
  787. // Execute a transformation
  788. // This the difficult part!
  789. result = enact_action(pm, element, mapping)
  790. output("Success")
  791. elif (type == "Decision"):
  792. // If the previous result is true, we add the normal one, otherwise the false one
  793. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  794. if (bool_not(result)):
  795. // Apparently it is False, so map this to the "Else" branch
  796. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  797. continue!
  798. else:
  799. // Apparently it is True, so map this to the "Then" branch
  800. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  801. continue!
  802. // We have finished the execution, so add all outgoing edges to the worklist
  803. Element all_next
  804. all_next = allAssociationDestinations(pm, element, "Next")
  805. String next
  806. while (set_len(all_next) > 0):
  807. next = set_pop(all_next)
  808. set_add_node(worklist, create_tuple(next, result))
  809. // Reached a finish element, so stop
  810. // Remove all mock locations again
  811. while (set_len(mock_locations) > 0):
  812. model_delete(get_entry_id(set_pop(mock_locations)))
  813. return !
  814. String function cmd_help():
  815. String result
  816. result = ""
  817. result = result + ("Model operations\n")
  818. result = result + (" model_add -- Add a new model\n")
  819. result = result + (" model_modify -- Modify an existing model\n")
  820. result = result + (" model_list -- List all models\n")
  821. result = result + (" model_list_full -- List all models with full info\n")
  822. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  823. result = result + (" model_render -- Render a given model with a specified mapper\n")
  824. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  825. result = result + ("\n")
  826. result = result + ("Transformation-specific operations\n")
  827. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  828. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  829. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  830. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  831. result = result + (" transformation_list -- List all model transformations\n")
  832. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  833. result = result + (" transformation_detail -- List transformation details\n")
  834. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  835. result = result + ("\n")
  836. result = result + ("Process operations\n")
  837. result = result + (" process_execute -- Execute a process model\n")
  838. result = result + ("\n")
  839. result = result + ("Model permission operations\n")
  840. result = result + (" permission_modify -- Change model permissions\n")
  841. result = result + (" permission_owner -- Change model owner\n")
  842. result = result + (" permission_group -- Change model group\n")
  843. result = result + ("\n")
  844. result = result + ("Group operations\n")
  845. result = result + (" group_create -- Create a group\n")
  846. result = result + (" group_delete -- Delete a group\n")
  847. result = result + (" group_owner_add -- Add group owner\n")
  848. result = result + (" group_owner_delete -- Remove group owner\n")
  849. result = result + (" group_join -- Add someone to your group\n")
  850. result = result + (" group_kick -- Kick someone from your group\n")
  851. result = result + (" group_list -- List all groups you are a member of\n")
  852. result = result + ("\n")
  853. if (is_admin(current_user_id)):
  854. result = result + ("Admin operations\n")
  855. result = result + (" admin_promote -- Promote a user to admin status\n")
  856. result = result + (" admin_demote -- Demote a user to normal status\n")
  857. result = result + ("\n")
  858. result = result + ("General operations\n")
  859. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  860. result = result + (" exit -- Kill the current task, while retaining user\n")
  861. return result!
  862. String function cmd_model_add(type : String, name : String, code : String):
  863. // Model addition operation, which uses model upload commands of the compiler
  864. String location
  865. String type_id
  866. Element new_model
  867. String new_model_id
  868. type_id = get_entry_id(type)
  869. if (type_id != ""):
  870. // Type exists
  871. if (allow_read(current_user_id, type_id)):
  872. // And is readable
  873. if (get_entry_id(get_foldername(name)) != ""):
  874. // Folder doesn't exist yet!
  875. if (allow_write(current_user_id, get_entry_id(get_foldername(name)))):
  876. // Folder is writable
  877. if (get_entry_id(name) == ""):
  878. // Model doesn't exist yet
  879. Element mm
  880. mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  881. if (element_eq(mm, read_root())):
  882. return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
  883. new_model = compile_model(code, mm)
  884. if (element_eq(new_model, read_root())):
  885. return "Compilation error"!
  886. model_create(new_model, name, type_id, "Model")
  887. return "Success"!
  888. else:
  889. return "Model exists: " + name!
  890. else:
  891. return "Permission denied to folder: " + get_foldername(name)!
  892. else:
  893. return "No such folder: " + get_foldername(name)!
  894. else:
  895. return "Permission denied to model: " + type!
  896. else:
  897. return "Model not found: " + type!
  898. String function cmd_process_execute(process : String, mapping : Element):
  899. // Execute a process model until it reaches termination
  900. String process_id
  901. process_id = get_entry_id(process)
  902. if (process_id != ""):
  903. if (allow_read(current_user_id, process_id)):
  904. Element pm
  905. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  906. if (element_eq(pm, read_root())):
  907. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  908. enact_PM(pm, mapping)
  909. return "Success"!
  910. else:
  911. return "Permission denied to model: " + process!
  912. else:
  913. return "Model not found: " + process!
  914. String function cmd_process_signature(process : String):
  915. // Execute a process model until it reaches termination
  916. String process_id
  917. String result
  918. Element signature
  919. Element keys
  920. String key
  921. process_id = get_entry_id(process)
  922. if (process_id != ""):
  923. if (allow_read(current_user_id, process_id)):
  924. Element pm
  925. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  926. if (element_eq(pm, read_root())):
  927. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  928. result = "Success: "
  929. signature = PM_signature(pm)
  930. keys = dict_keys(signature)
  931. while (set_len(keys) > 0):
  932. key = set_pop(keys)
  933. result = result + key + " : " + cast_string(signature[key]) + "\n"
  934. return result!
  935. else:
  936. return "Permission denied to model: " + process!
  937. else:
  938. return "Model not found: " + process!
  939. String function cmd_transformation_between(source_dict : String, target_dict : String):
  940. Element result
  941. Element subresult
  942. String tag
  943. String mm
  944. String mm_id
  945. Element links
  946. String link
  947. Element keys
  948. result = allInstances(core, "Transformation")
  949. // Iterate over all inputs
  950. keys = dict_keys(source_dict)
  951. while (set_len(keys) > 0):
  952. subresult = set_create()
  953. tag = set_pop(keys)
  954. mm = source_dict[tag]
  955. mm_id = get_entry_id(mm)
  956. if (mm_id != ""):
  957. links = allIncomingAssociationInstances(core, mm_id, "transformInput")
  958. while (set_len(links) > 0):
  959. link = set_pop(links)
  960. if (value_eq(read_attribute(core, link, "name"), tag)):
  961. // Correct tag, so make transformation a possibility
  962. set_add(subresult, readAssociationSource(core, link))
  963. else:
  964. return "Model not found: " + mm!
  965. // Got a set of subresults now, which we use to find the overlap
  966. result = set_overlap(result, subresult)
  967. keys = dict_keys(target_dict)
  968. while (set_len(keys) > 0):
  969. subresult = set_create()
  970. tag = set_pop(keys)
  971. mm = target_dict[tag]
  972. mm_id = get_entry_id(mm)
  973. if (mm_id != ""):
  974. links = allIncomingAssociationInstances(core, mm_id, "transformOutput")
  975. while (set_len(links) > 0):
  976. link = set_pop(links)
  977. if (value_eq(read_attribute(core, link, "name"), tag)):
  978. // Correct tag, so make transformation a possibility
  979. set_add(subresult, readAssociationSource(core, link))
  980. else:
  981. return "Model not found: " + mm!
  982. // Got a set of subresults now, which we use to find the overlap
  983. result = set_overlap(result, subresult)
  984. String r
  985. String transformation
  986. r = "Success: "
  987. while (set_len(result) > 0):
  988. transformation = set_pop(result)
  989. if (allow_read(current_user_id, transformation)):
  990. r = r + string_join(full_name(transformation), "\n")
  991. return r!
  992. String function cmd_model_rendered(model_name : String, mapper_name : String):
  993. Element trace_links
  994. String rendered
  995. String trace_link_id
  996. String allowed_rendered
  997. Element trace_links_2
  998. String trace_link_2_id
  999. allowed_rendered = "Success: "
  1000. trace_links = allOutgoingAssociationInstances(core, get_entry_id(model_name), "tracability")
  1001. while (set_len(trace_links) > 0):
  1002. trace_link_id = set_pop(trace_links)
  1003. if (value_eq(read_attribute(core, trace_link_id, "type"), "CS_perceptualized")):
  1004. rendered = readAssociationDestination(core, trace_link_id)
  1005. trace_links_2 = allOutgoingAssociationInstances(core, rendered, "tracability")
  1006. while (set_len(trace_links_2) > 0):
  1007. trace_link_2_id = set_pop(trace_links_2)
  1008. if (value_eq(read_attribute(core, readAssociationDestination(core, trace_link_2_id), "name"), mapper_name)):
  1009. if (value_eq(read_attribute(core, trace_link_2_id, "type"), "CS_mapper")):
  1010. allowed_rendered = string_join(allowed_rendered, read_attribute(core, rendered, "name")) + "\n"
  1011. return allowed_rendered!
  1012. String function cmd_model_render(model_name : String, mapper_name : String, rendered_name : String):
  1013. String model_ID
  1014. String mapper_ID
  1015. String tracability_name
  1016. Element inputs
  1017. Element output_map
  1018. Element rendered_model
  1019. Element tracability_model
  1020. Element result
  1021. Element out_links
  1022. String link
  1023. String ID_rendered_M
  1024. String ID_rendered_MM
  1025. String ID_SCD
  1026. String ID_tracability_MM
  1027. String ID_tracability_M
  1028. model_ID = get_entry_id(model_name)
  1029. if (model_ID != ""):
  1030. mapper_ID = get_entry_id(mapper_name)
  1031. if (allow_read(current_user_id, model_ID)):
  1032. if (mapper_ID != ""):
  1033. if (allow_read(current_user_id, mapper_ID)):
  1034. // Everything is fine; start the actual operation
  1035. // Find metamodel to render to
  1036. tracability_name = "tracability/" + rendered_name
  1037. // Take the abstract syntax model and the previously rendered model
  1038. inputs = dict_create()
  1039. dict_add(inputs, "abstract", model_name)
  1040. dict_add(inputs, "rendered", rendered_name)
  1041. // Fetch the output types
  1042. output_map = dict_create()
  1043. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  1044. while(set_len(out_links) > 0):
  1045. link = set_pop(out_links)
  1046. dict_add(output_map, read_attribute(core, link, "name"), full_name(readAssociationDestination(core, link)))
  1047. ID_rendered_MM = get_entry_id(output_map["rendered"])
  1048. ID_SCD = get_entry_id("formalisms/SimpleClassDiagrams")
  1049. ID_tracability_MM = get_entry_id("formalisms/Tracability")
  1050. ID_tracability_M = get_entry_id(tracability_name)
  1051. ID_rendered_M = get_entry_id(rendered_name)
  1052. if (ID_rendered_M == ""):
  1053. // Instantiate
  1054. Element rendered
  1055. rendered = get_full_model(ID_rendered_MM, ID_SCD)
  1056. if (element_eq(rendered, read_root())):
  1057. return "Rendered metamodel doesn't conform to formalisms/SimpleClassDiagrams"!
  1058. rendered_model = instantiate_model(rendered)
  1059. model_create(rendered_model, rendered_name, ID_rendered_MM, "Model")
  1060. // Tracability model won't exist either
  1061. tracability_model = instantiate_model(get_full_model(ID_tracability_MM, ID_SCD))
  1062. model_create(tracability_model, tracability_name, ID_tracability_MM, "Model")
  1063. ID_rendered_M = get_entry_id(rendered_name)
  1064. ID_tracability_M = get_entry_id(tracability_name)
  1065. else:
  1066. // Read out tracability model
  1067. tracability_model = get_full_model(ID_tracability_M, ID_tracability_MM)
  1068. if (element_eq(tracability_model, read_root())):
  1069. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1070. // Do the operation itself!
  1071. result = execute_operation(mapper_ID, inputs, tracability_model)
  1072. // Overwrite the previous rendered model
  1073. model_overwrite(result["rendered"], ID_rendered_M, ID_rendered_MM)
  1074. // Tracability updated in-place
  1075. model_overwrite(tracability_model, ID_tracability_M, ID_tracability_MM)
  1076. if (element_eq(tracability_model, read_root())):
  1077. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1078. // Link all information in the megamodel
  1079. String tr_link
  1080. tr_link = instantiate_link(core, "tracability", "", get_entry_id(model_name), ID_rendered_M)
  1081. instantiate_attribute(core, tr_link, "type", "CS_perceptualized")
  1082. tr_link = instantiate_link(core, "tracability", "", ID_rendered_M, get_entry_id(mapper_name))
  1083. instantiate_attribute(core, tr_link, "type", "CS_mapper")
  1084. // Output the resulting model
  1085. String value
  1086. value = JSON_print(result["rendered"])
  1087. return ("Success: " + value) !
  1088. else:
  1089. return "Permission denied to model: " + mapper_name!
  1090. else:
  1091. return "Model not found: " + mapper_name!
  1092. else:
  1093. return "Permission denied to model: " + model_name!
  1094. else:
  1095. return "Model not found: " + model_name!
  1096. String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element, tracability_name : String):
  1097. // Execute a transformation, whatever type it is
  1098. // First we detect the type, so we know how to prepare for invocation
  1099. String transformation_id
  1100. String exact_type
  1101. Element sources
  1102. Element targets
  1103. String source
  1104. String target
  1105. Element inputs
  1106. Element outputs
  1107. Element output_map
  1108. Element trace_links
  1109. String target_model_name
  1110. String source_model_name
  1111. String source_model_ID
  1112. Element result
  1113. Element keys
  1114. String key
  1115. String assoc_name
  1116. transformation_id = get_entry_id(transformation_name)
  1117. if (transformation_id != ""):
  1118. if (allow_read(current_user_id, transformation_id)):
  1119. if (is_nominal_instance(core, transformation_id, "Transformation")):
  1120. // Read out source and target links
  1121. inputs = dict_create()
  1122. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  1123. while (set_len(sources) > 0):
  1124. source = set_pop(sources)
  1125. assoc_name = read_attribute(core, source, "name")
  1126. if (dict_in(source_models, assoc_name)):
  1127. source_model_name = source_models[assoc_name]
  1128. else:
  1129. return "Source model not bound: " + assoc_name!
  1130. source_model_ID = get_entry_id(source_model_name)
  1131. if (source_model_ID != ""):
  1132. if (allow_read(current_user_id, source_model_ID)):
  1133. // Check for conformance to the requested metamodel
  1134. dict_add(inputs, assoc_name, source_model_name)
  1135. continue!
  1136. else:
  1137. return "Permission denied to model: " + source_model_name!
  1138. else:
  1139. return "Model not found: " + source_model_name!
  1140. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  1141. outputs = dict_create()
  1142. output_map = dict_create()
  1143. while (set_len(targets) > 0):
  1144. target = set_pop(targets)
  1145. assoc_name = read_attribute(core, target, "name")
  1146. if (dict_in(target_models, assoc_name)):
  1147. target_model_name = target_models[assoc_name]
  1148. if (get_entry_id(target_model_name) == ""):
  1149. // Doesn't exist yet, so we can easily create
  1150. if (get_entry_id(get_foldername(target_model_name)) == ""):
  1151. return "Folder not found: " + get_foldername(target_model_name)!
  1152. else:
  1153. if (allow_write(current_user_id, get_entry_id(get_foldername(target_model_name)))):
  1154. dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
  1155. dict_add(outputs, assoc_name, target_model_name)
  1156. else:
  1157. return "Permission denied to folder: " + get_foldername(target_model_name)!
  1158. else:
  1159. // Already exists, so we need to check for write access
  1160. if (allow_write(current_user_id, get_entry_id(target_model_name))):
  1161. dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
  1162. dict_add(outputs, assoc_name, target_model_name)
  1163. else:
  1164. return "Permission denied to model: " + target_model_name!
  1165. if (read_type(core, transformation_id) == "ActionLanguage"):
  1166. output("Success: ready for AL execution")
  1167. elif (read_type(core, transformation_id) == "ManualOperation"):
  1168. output("Success: ready for MANUAL execution")
  1169. else:
  1170. output("Success: ready for MT execution")
  1171. // Do tracability
  1172. Element tracability_model
  1173. if (tracability_name != ""):
  1174. // Check if exists
  1175. if (get_entry_id(tracability_name) == ""):
  1176. // No, so create
  1177. tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
  1178. model_create(tracability_model, tracability_name, get_entry_id("formalisms/Tracability"), "Model")
  1179. else:
  1180. // Yes, so read out
  1181. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1182. else:
  1183. tracability_model = read_root()
  1184. result = execute_operation(transformation_id, inputs, tracability_model)
  1185. // Flush tracability again, just to be sure
  1186. if (tracability_name != ""):
  1187. model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1188. // Now write out the models again
  1189. if (element_eq(result, read_root())):
  1190. // Something went wrong!
  1191. return "Failure"!
  1192. else:
  1193. keys = dict_keys(outputs)
  1194. while (set_len(keys) > 0):
  1195. key = set_pop(keys)
  1196. log("Writing away model with key " + cast_string(key))
  1197. log("Output map: " + dict_to_string(output_map))
  1198. log("Outputs: " + dict_to_string(outputs))
  1199. if (get_entry_id(outputs[key]) == ""):
  1200. // New model
  1201. log("New model!")
  1202. model_create(result[key], outputs[key], get_entry_id(output_map[key]), "Model")
  1203. else:
  1204. log("Existing model!")
  1205. model_overwrite(result[key], get_entry_id(outputs[key]), get_entry_id(output_map[key]))
  1206. return "Success"!
  1207. else:
  1208. return "Model is not executable: " + transformation_name!
  1209. else:
  1210. return "Permission denied to model: " + transformation_name!
  1211. else:
  1212. return "Model not found: " + transformation_name!
  1213. String function cmd_verify(model_name : String, metamodel_name : String):
  1214. // Check whether a model conforms to its specification (with the selected type mapping)
  1215. String model_id
  1216. String result
  1217. Element inputs
  1218. model_id = get_entry_id(model_name)
  1219. if (model_id != ""):
  1220. if (allow_read(current_user_id, model_id)):
  1221. if (get_entry_id(metamodel_name) != ""):
  1222. if (allow_read(current_user_id, get_entry_id(metamodel_name))):
  1223. Element m
  1224. m = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  1225. if (element_eq(m, read_root())):
  1226. return "No conformance relation can be found between these models"!
  1227. return string_join("Success: ", conformance_scd(m))!
  1228. else:
  1229. return "Permission denied to model: " + metamodel_name!
  1230. else:
  1231. return "Model not found: " + metamodel_name!
  1232. else:
  1233. return "Permission denied to model: " + model_name!
  1234. else:
  1235. return "Model not found: " + model_name!
  1236. String function cmd_model_overwrite(model_name : String, metamodel_name : String):
  1237. // Overwrites an existing model without changing any metadata
  1238. String model_id
  1239. String type_id
  1240. Element new_model
  1241. model_id = get_entry_id(model_name)
  1242. if (model_id != ""):
  1243. if (allow_write(current_user_id, model_id)):
  1244. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1245. if (allow_read(current_user_id, type_id)):
  1246. Element mm
  1247. mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1248. if (element_eq(mm, read_root())):
  1249. return "Metamodel does not conform to formalisms/SimpleClassDiagrams: " + metamodel_name!
  1250. output("Waiting for model constructors...")
  1251. new_model = compile_model(input(), mm)
  1252. if (element_eq(new_model, read_root())):
  1253. return "Compilation error"!
  1254. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  1255. return "Success"!
  1256. else:
  1257. return string_join("Permission denied to model: ", full_name(type_id))!
  1258. else:
  1259. return "Permission denied to model: " + model_name!
  1260. else:
  1261. return "Model not found: " + model_name!
  1262. String function cmd_model_modify(model_name : String, metamodel_name : String):
  1263. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  1264. String model_id
  1265. String type_id
  1266. model_id = get_entry_id(model_name)
  1267. if (model_id != ""):
  1268. if (allow_read(current_user_id, model_id)):
  1269. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1270. if (allow_read(current_user_id, type_id)):
  1271. Element new_model
  1272. new_model = get_full_model(model_id, get_entry_id(metamodel_name))
  1273. if (element_eq(new_model, read_root())):
  1274. return "No conformance relation can be found between these models"!
  1275. modify(new_model, allow_write(current_user_id, model_id))
  1276. if (allow_write(current_user_id, model_id)):
  1277. // Overwrite the modified model
  1278. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  1279. return "Success"!
  1280. else:
  1281. return string_join("Permission denied to model: ", full_name(type_id))!
  1282. else:
  1283. return "Permission denied to model: " + model_name!
  1284. else:
  1285. return "Model not found: " + model_name!
  1286. Void function model_delete(model_id : String):
  1287. if (read_type(core, model_id) == "Folder"):
  1288. // Folder, so delete all containing elements as well!
  1289. Element elems
  1290. elems = allAssociationDestinations(core, model_id, "contains")
  1291. while (set_len(elems) > 0):
  1292. model_delete(set_pop(elems))
  1293. // Delete self
  1294. model_delete_element(core, model_id)
  1295. else:
  1296. // Only delete this element
  1297. model_delete_element(core, model_id)
  1298. return!
  1299. String function cmd_model_delete(model_name : String):
  1300. String model_id
  1301. model_id = get_entry_id(model_name)
  1302. if (model_id != ""):
  1303. if (allow_write(current_user_id, model_id)):
  1304. model_delete(model_id)
  1305. return "Success"!
  1306. else:
  1307. return "Permission denied to model: " + model_name!
  1308. else:
  1309. return "Model not found: " + model_name!
  1310. String function cmd_model_list(location : String):
  1311. // List all models
  1312. if (get_entry_id(location) != ""):
  1313. if (allow_read(current_user_id, get_entry_id(location))):
  1314. Element models
  1315. String result
  1316. String m
  1317. result = "Success: "
  1318. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1319. while (set_len(models) > 0):
  1320. m = set_pop(models)
  1321. if (is_nominal_instance(core, m, "Folder")):
  1322. result = result + (get_filename(read_attribute(core, m, "name")) + "/\n")
  1323. else:
  1324. result = result + (get_filename(read_attribute(core, m, "name")) + "\n")
  1325. return result!
  1326. else:
  1327. return "Permission denied to folder: " + location!
  1328. else:
  1329. return "Location not found: " + location!
  1330. String function cmd_model_list_full(location : String):
  1331. // List all models with full info
  1332. if (get_entry_id(location) != ""):
  1333. if (allow_read(current_user_id, get_entry_id(location))):
  1334. Element models
  1335. String m
  1336. String permissions
  1337. String owner
  1338. String group
  1339. String name
  1340. String type
  1341. String result
  1342. result = "Success: "
  1343. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1344. while (set_len(models) > 0):
  1345. m = set_pop(models)
  1346. permissions = read_attribute(core, m, "permissions")
  1347. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1348. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1349. if (is_nominal_instance(core, m, "Folder")):
  1350. name = get_filename(read_attribute(core, m, "name")) + "/"
  1351. else:
  1352. name = get_filename(read_attribute(core, m, "name"))
  1353. result = result + permissions + " " + owner + " " + group + " " + name + "\n"
  1354. return result!
  1355. else:
  1356. return "Permission denied to folder: " + location!
  1357. else:
  1358. return "Location not found: " + location!
  1359. String function cmd_transformation_add_MANUAL(source_models : Element, target_models : Element, operation_name : String):
  1360. return transformation_add(source_models, target_models, operation_name, "manual")!
  1361. String function cmd_transformation_add_AL(source_models : Element, target_models : Element, operation_name : String):
  1362. return transformation_add(source_models, target_models, operation_name, "actionlanguage")!
  1363. String function transformation_add(source_models : Element, target_models : Element, operation_name : String, operation_type : String):
  1364. // Add a manual transformation model
  1365. String model_id
  1366. Element models
  1367. Element source
  1368. Element target
  1369. String name
  1370. Element all_formalisms
  1371. Element formalism_map
  1372. Element merged_formalism
  1373. String merged_formalism_id
  1374. String source_formalism_id
  1375. String tracability_link
  1376. Element fused
  1377. Element keys
  1378. String key
  1379. Element mm
  1380. source = dict_create()
  1381. target = dict_create()
  1382. all_formalisms = set_create()
  1383. formalism_map = set_create()
  1384. fused = set_create()
  1385. keys = dict_keys(source_models)
  1386. while (set_len(keys) > 0):
  1387. key = set_pop(keys)
  1388. name = source_models[key]
  1389. model_id = get_entry_id(name)
  1390. if (model_id != ""):
  1391. if (allow_read(current_user_id, model_id)):
  1392. if (bool_not(dict_in(source, key))):
  1393. dict_add(source, key, model_id)
  1394. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1395. if (element_eq(mm, read_root())):
  1396. return "Transformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1397. if (bool_not(set_in(fused, key))):
  1398. set_add_node(formalism_map, create_tuple(key, mm))
  1399. set_add(fused, key)
  1400. if (bool_not(set_in(all_formalisms, model_id))):
  1401. set_add(all_formalisms, model_id)
  1402. else:
  1403. return "Name already selected for source: " + key!
  1404. else:
  1405. return "Permission denied to model: " + name!
  1406. else:
  1407. return "Model not found: " + name!
  1408. keys = dict_keys(target_models)
  1409. while (set_len(keys) > 0):
  1410. key = set_pop(keys)
  1411. name = target_models[key]
  1412. model_id = get_entry_id(name)
  1413. if (model_id != ""):
  1414. if (allow_read(current_user_id, model_id)):
  1415. if (bool_not(dict_in(target, key))):
  1416. dict_add(target, key, model_id)
  1417. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1418. if (element_eq(mm, read_root())):
  1419. return "Transformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1420. if (bool_not(set_in(fused, key))):
  1421. set_add_node(formalism_map, create_tuple(key, mm))
  1422. set_add(fused, key)
  1423. if (bool_not(set_in(all_formalisms, model_id))):
  1424. set_add(all_formalisms, model_id)
  1425. else:
  1426. return "Name already selected for target: " + key!
  1427. else:
  1428. return "Permission denied to model: " + name!
  1429. else:
  1430. return "Model not found: " + name!
  1431. if (get_entry_id(operation_name) == ""):
  1432. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1433. // New location is available, so write
  1434. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1435. merged_formalism = model_fuse(formalism_map)
  1436. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1437. output("Operating on: merged/" + operation_name)
  1438. if (modify(merged_formalism, True)):
  1439. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1440. else:
  1441. merged_formalism = get_full_model(get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1442. if (operation_type == "manual"):
  1443. // Finished with all information, now create the model itself!
  1444. Element m
  1445. m = get_full_model(get_entry_id("formalisms/ManualOperation"), get_entry_id("formalisms/SimpleClassDiagrams"))
  1446. if (element_eq(m, read_root())):
  1447. log("Error when opening ManualOperation: no conformance relation found")
  1448. return "Error when opening ManualOperation: no conformance relation found"!
  1449. model_create(instantiate_model(m), operation_name, get_entry_id("formalisms/ManualOperation"), "ManualOperation")
  1450. model_id = get_entry_id(operation_name)
  1451. elif (operation_type == "actionlanguage"):
  1452. // Finished with all information, now create the model itself!
  1453. output("Waiting for code constructors...")
  1454. Element compiled
  1455. compiled = compile_code(input())
  1456. if (element_eq(compiled, read_root())):
  1457. return "Compilation error"!
  1458. add_code_model(get_full_model(get_entry_id("formalisms/ActionLanguage"), get_entry_id("formalisms/SimpleClassDiagrams")), "AL/" + operation_name, compiled)
  1459. model_create(import_node("AL/" + operation_name), operation_name, get_entry_id("formalisms/ActionLanguage"), "ActionLanguage")
  1460. model_id = get_entry_id(operation_name)
  1461. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1462. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1463. // Add tracability links at this level
  1464. while (set_len(all_formalisms) > 0):
  1465. source_formalism_id = set_pop(all_formalisms)
  1466. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1467. instantiate_attribute(core, tracability_link, "type", "merged")
  1468. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1469. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1470. // Extend metadata with info on source and target
  1471. String link
  1472. String dst
  1473. keys = dict_keys(source)
  1474. while (set_len(keys) > 0):
  1475. key = set_pop(keys)
  1476. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1477. instantiate_attribute(core, link, "name", key)
  1478. keys = dict_keys(target)
  1479. while (set_len(keys) > 0):
  1480. key = set_pop(keys)
  1481. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1482. instantiate_attribute(core, link, "name", key)
  1483. return "Success"!
  1484. else:
  1485. return "Model exists: " + operation_name!
  1486. String function cmd_transformation_add_MT(source_models : Element, target_models : Element, operation_name : String):
  1487. // Add a model transformation model
  1488. // Just a usual model instantiation, but need to add the source and target links based on user info
  1489. String ramified_metamodel_id
  1490. Element ramified_metamodel
  1491. String model_id
  1492. Element models
  1493. Element links
  1494. String link_id
  1495. Element supported
  1496. Element source
  1497. Element target
  1498. String name
  1499. String new_model_id
  1500. String merged_link_id
  1501. Element links_merged
  1502. String merged_formalism
  1503. Element keys
  1504. String key
  1505. Element mm
  1506. Element to_ramify
  1507. String source_formalism_id
  1508. String merged_formalism_id
  1509. String tracability_link
  1510. source = dict_create()
  1511. target = dict_create()
  1512. to_ramify = set_create()
  1513. if (dict_len(source_models) + dict_len(target_models) == 0):
  1514. return "Model transformation needs at least one formalism in its input or output signature!"!
  1515. keys = dict_keys(source_models)
  1516. while (set_len(keys) > 0):
  1517. key = set_pop(keys)
  1518. name = source_models[key]
  1519. model_id = get_entry_id(name)
  1520. if (model_id != ""):
  1521. if (allow_read(current_user_id, name)):
  1522. // Check whether or not it is formalisms/SimpleClassDiagrams
  1523. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1524. if (bool_not(dict_in(source, key))):
  1525. dict_add(source, key, model_id)
  1526. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1527. if (element_eq(mm, read_root())):
  1528. return "ModelTransformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1529. set_add_node(to_ramify, create_tuple(key, mm))
  1530. else:
  1531. return "Name was already assigned a metamodel: " + key!
  1532. else:
  1533. return "Model not supported for RAMification: " + name!
  1534. else:
  1535. return "Permission denied: " + name!
  1536. else:
  1537. return "Model not found: " + name!
  1538. keys = dict_keys(target_models)
  1539. while (set_len(keys) > 0):
  1540. key = set_pop(keys)
  1541. name = target_models[key]
  1542. model_id = get_entry_id(name)
  1543. if (model_id != ""):
  1544. if (allow_read(current_user_id, name)):
  1545. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1546. if (bool_not(dict_in(target, key))):
  1547. if (dict_in(source, key)):
  1548. if (value_eq(model_id, source[key])):
  1549. dict_add(target, key, model_id)
  1550. // Don't add to to_ramify, as it is already in there!
  1551. else:
  1552. return "Name in output cannot have different type than input: " + key!
  1553. else:
  1554. dict_add(target, key, model_id)
  1555. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1556. if (element_eq(mm, read_root())):
  1557. return "ModelTransformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1558. set_add_node(to_ramify, create_tuple(key, mm))
  1559. else:
  1560. return "Name was already assigned a metamodel: " + key!
  1561. else:
  1562. return "Model not supported for RAMification: " + name!
  1563. else:
  1564. return "Permission denied: " + name!
  1565. else:
  1566. return "Model not found: " + name!
  1567. merged_formalism = model_fuse(to_ramify)
  1568. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1569. output("Operating on: merged/" + operation_name)
  1570. if (modify(merged_formalism, True)):
  1571. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1572. else:
  1573. merged_formalism = get_full_model(get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1574. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1575. ramified_metamodel = ramify(merged_formalism)
  1576. model_create(ramified_metamodel, "RAMified/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1577. ramified_metamodel_id = get_entry_id("RAMified/" + operation_name)
  1578. // Now use the RAMified model to create the instance
  1579. if (get_entry_id(operation_name) == ""):
  1580. String new_model
  1581. // Finished with all information, now create the model itself!
  1582. output("Waiting for model constructors...")
  1583. new_model = compile_model(input(), get_full_model(ramified_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams")))
  1584. if (element_eq(new_model, read_root())):
  1585. return "Compilation error"!
  1586. model_create(new_model, operation_name, ramified_metamodel_id, "ModelTransformation")
  1587. model_id = get_entry_id(operation_name)
  1588. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1589. // New location is available, so write
  1590. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1591. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1592. // Add tracability links at this level
  1593. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1594. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1595. // Add tracability links at this level
  1596. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1597. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1598. // Extend metadata with info on source and target
  1599. String link
  1600. String dst
  1601. keys = dict_keys(source)
  1602. while (set_len(keys) > 0):
  1603. key = set_pop(keys)
  1604. dst = source[key]
  1605. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1606. instantiate_attribute(core, link, "name", key)
  1607. keys = dict_keys(target)
  1608. while (set_len(keys) > 0):
  1609. key = set_pop(keys)
  1610. dst = target[key]
  1611. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1612. instantiate_attribute(core, link, "name", key)
  1613. return "Success"!
  1614. else:
  1615. return "Model exists: " + operation_name!
  1616. String function cmd_permission_modify(model_name : String, permissions : String):
  1617. Integer permission
  1618. String model_id
  1619. model_id = get_entry_id(model_name)
  1620. if (model_id != ""):
  1621. if (get_relation_to_model(current_user_id, model_id) == 0):
  1622. Boolean fail
  1623. Integer i
  1624. i = 0
  1625. if (string_len(permissions) != 3):
  1626. fail = True
  1627. while (i < 3):
  1628. permission = cast_integer(string_get(permissions, i))
  1629. if (bool_or(permission < 0, permission > 2)):
  1630. fail = True
  1631. break!
  1632. i = i + 1
  1633. if (bool_not(fail)):
  1634. unset_attribute(core, model_id, "permissions")
  1635. instantiate_attribute(core, model_id, "permissions", permissions)
  1636. return "Success"!
  1637. else:
  1638. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1639. else:
  1640. return "Permission denied to model: " + model_name!
  1641. else:
  1642. return "Model not found: " + model_name!
  1643. String function cmd_permission_owner(model_name : String, new_user_name : String):
  1644. String model_id
  1645. String new_user_id
  1646. model_id = get_entry_id(model_name)
  1647. if (model_id != ""):
  1648. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1649. new_user_id = get_user_id(new_user_name)
  1650. if (new_user_id != ""):
  1651. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1652. instantiate_link(core, "owner", "", model_id, new_user_id)
  1653. return "Success"!
  1654. else:
  1655. return "No such user: " + new_user_name!
  1656. else:
  1657. return "Permission denied to model: " + model_name!
  1658. else:
  1659. return "Model not found: " + model_name!
  1660. String function cmd_permission_group(model_name : String, new_group_name : String):
  1661. String model_id
  1662. String group_id
  1663. model_id = get_entry_id(model_name)
  1664. if (model_id != ""):
  1665. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1666. group_id = get_group_id(new_group_name)
  1667. if (group_id != ""):
  1668. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1669. instantiate_link(core, "group", "", model_id, group_id)
  1670. return "Success"!
  1671. else:
  1672. return "No such group: " + new_group_name!
  1673. else:
  1674. return "Permission denied to model: " + model_name!
  1675. else:
  1676. return "Model not found: " + model_name!
  1677. String function cmd_group_create(group_name : String):
  1678. // Create a new group and become its owner
  1679. String group_id
  1680. String name
  1681. group_id = get_group_id(group_name)
  1682. if (group_id == ""):
  1683. group_id = instantiate_node(core, "Group", "")
  1684. instantiate_attribute(core, group_id, "name", group_name)
  1685. instantiate_link(core, "belongsTo", "", current_user_id, group_id)
  1686. instantiate_link(core, "owner", "", group_id, current_user_id)
  1687. return "Success"!
  1688. else:
  1689. return "Group exists: " + group_name!
  1690. String function cmd_group_delete(group_name : String):
  1691. // Delete an existing group
  1692. String group_id
  1693. group_id = get_group_id(group_name)
  1694. if (group_id != ""):
  1695. if (allow_group_modify(current_user_id, group_id)):
  1696. model_delete_element(core, group_id)
  1697. return "Success"!
  1698. else:
  1699. return "Permission denied to group: " + group_name!
  1700. else:
  1701. return "Group not found: " + group_name!
  1702. String function cmd_group_owner_add(group_name : String, other_user_name : String):
  1703. // Add an owner to your group
  1704. String group_id
  1705. String other_user_id
  1706. group_id = get_group_id(group_name)
  1707. if (group_id != ""):
  1708. if (allow_group_modify(current_user_id, group_id)):
  1709. other_user_id = get_user_id(other_user_name)
  1710. if (other_user_id != ""):
  1711. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1712. instantiate_link(core, "owner", "", group_id, other_user_id)
  1713. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1714. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1715. return "Success"!
  1716. else:
  1717. return "User is already the owner!"!
  1718. else:
  1719. return "User not found: " + other_user_name!
  1720. else:
  1721. return "Permission denied to group: " + group_name!
  1722. else:
  1723. return "Group not found: " + group_name!
  1724. String function cmd_group_owner_delete(group_name : String, other_user_name : String):
  1725. // Remove an owner from your group
  1726. String group_id
  1727. String other_user_id
  1728. group_id = get_group_id(group_name)
  1729. if (group_id != ""):
  1730. if (allow_group_modify(current_user_id, group_id)):
  1731. other_user_id = get_user_id(other_user_name)
  1732. if (other_user_id != ""):
  1733. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1734. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1735. Element overlap
  1736. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1737. model_delete_element(core, set_pop(overlap))
  1738. return "Success"!
  1739. else:
  1740. return "User is not an owner of the group!"!
  1741. else:
  1742. return "User is not a member of the group!"!
  1743. else:
  1744. return "User not found: " + other_user_name!
  1745. else:
  1746. return "Permission denied to group: " + group_name!
  1747. else:
  1748. return "Group not found: " + group_name!
  1749. String function cmd_group_join(group_name : String, other_user_name : String):
  1750. // Add someone to your group
  1751. String group_id
  1752. String other_user_id
  1753. group_id = get_group_id(group_name)
  1754. if (group_id != ""):
  1755. if (allow_group_modify(current_user_id, group_id)):
  1756. other_user_id = get_user_id(other_user_name)
  1757. if (other_user_id != ""):
  1758. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1759. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1760. return "Success"!
  1761. else:
  1762. return "User is already a member of the group!"!
  1763. else:
  1764. return "User not found: " + other_user_name!
  1765. else:
  1766. return "Permission denied to group: " + group_name!
  1767. else:
  1768. return "Group not found: " + group_name!
  1769. String function cmd_group_kick(group_name : String, other_user_name : String):
  1770. // Remove someone from your group
  1771. String group_id
  1772. String other_user_id
  1773. group_id = get_group_id(group_name)
  1774. if (group_id != ""):
  1775. if (allow_group_modify(current_user_id, group_id)):
  1776. other_user_id = get_user_id(other_user_name)
  1777. if (other_user_id != ""):
  1778. Element overlap
  1779. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1780. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1781. model_delete_element(core,set_pop(overlap))
  1782. // Check if user was an owner as well
  1783. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1784. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1785. model_delete_element(core, set_pop(overlap))
  1786. return "Success"!
  1787. else:
  1788. return "User is not a member of the group!"!
  1789. else:
  1790. return "User not found: " + other_user_name!
  1791. else:
  1792. return "Permission denied to group: " + group_name!
  1793. else:
  1794. return "Group not found: " + group_name!
  1795. String function cmd_group_list():
  1796. // List all groups you are a member of (and whether you are admin or not!)
  1797. Element groups
  1798. String group_id
  1799. String admin
  1800. String result
  1801. result = ""
  1802. groups = allAssociationDestinations(core, current_user_id, "belongsTo")
  1803. while (set_len(groups) > 0):
  1804. group_id = set_pop(groups)
  1805. if (set_in(allAssociationDestinations(core, group_id, "owner"), current_user_id)):
  1806. admin = " A "
  1807. else:
  1808. admin = " "
  1809. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1810. return result!
  1811. String function cmd_admin_promote(other_user_name : String):
  1812. // Promote a user to admin status
  1813. if (is_admin(current_user_id)):
  1814. String other_user_id
  1815. other_user_id = get_user_id(other_user_name)
  1816. if (other_user_id != ""):
  1817. unset_attribute(core, other_user_id, "admin")
  1818. instantiate_attribute(core, other_user_id, "admin", True)
  1819. return "Success"!
  1820. else:
  1821. return "User not found: " + other_user_name!
  1822. else:
  1823. return "Permission denied to administrate: " + other_user_name!
  1824. String function cmd_admin_demote(other_user_name : String):
  1825. // Demote a user to normal status
  1826. if (is_admin(current_user_id)):
  1827. String other_user_id
  1828. other_user_id = get_user_id(other_user_name)
  1829. if (other_user_id != ""):
  1830. unset_attribute(core, other_user_id, "admin")
  1831. instantiate_attribute(core, other_user_id, "admin", False)
  1832. return "Success"!
  1833. else:
  1834. return "User not found: " + other_user_name!
  1835. else:
  1836. return "Permission denied to administrate: " + other_user_name!
  1837. String function cmd_service_register(service_name : String):
  1838. // Active a service for this specific user
  1839. if (get_service_id(service_name) == ""):
  1840. String service
  1841. service = instantiate_node(core, "Service", "")
  1842. instantiate_attribute(core, service, "name", service_name)
  1843. instantiate_attribute(core, service, "port", get_taskname())
  1844. output("Success: " + get_taskname())
  1845. // Wait until we can stop the service
  1846. while (cast_value(input()) != "\"service_stop\""):
  1847. output("Service is running on this task: stop it by sending 'service_stop'")
  1848. model_delete_element(core, service)
  1849. // Service terminated
  1850. return "Success"!
  1851. else:
  1852. return "Service already exists: " + service_name!
  1853. String function cmd_user_password(user_name : String, new_password : String):
  1854. if (bool_or(current_user_id == get_user_id(user_name), is_admin(current_user_id))):
  1855. if (get_user_id(user_name) != ""):
  1856. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1857. return "Success"!
  1858. else:
  1859. return "No such user: " + user_name!
  1860. else:
  1861. return "Permission denied to user: " + user_name!
  1862. String function cmd_transformation_signature(transformation_name : String):
  1863. String model_id
  1864. model_id = get_entry_id(transformation_name)
  1865. if (model_id != ""):
  1866. if (is_nominal_instance(core, model_id, "Transformation")):
  1867. if (allow_read(current_user_id, transformation_name)):
  1868. String result
  1869. String elem
  1870. Element inputs
  1871. Element outputs
  1872. result = "Success: "
  1873. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1874. while (set_len(inputs) > 0):
  1875. elem = set_pop(inputs)
  1876. result = string_join(string_join(string_join(string_join(result + "I ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1877. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1878. while (set_len(outputs) > 0):
  1879. elem = set_pop(outputs)
  1880. result = string_join(string_join(string_join(string_join(result + "O ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1881. return result!
  1882. else:
  1883. return "Permission denied to operation: " + transformation_name!
  1884. else:
  1885. return "Model is not an operation: " + transformation_name!
  1886. else:
  1887. return "No such operation: " + transformation_name!
  1888. String function cmd_model_types(model_name : String):
  1889. if (get_entry_id(model_name) != ""):
  1890. String model_id
  1891. model_id = get_entry_id(model_name)
  1892. Element types
  1893. String type
  1894. String result
  1895. result = "Success: "
  1896. types = allAssociationDestinations(core, model_id, "instanceOf")
  1897. while (set_len(types) > 0):
  1898. type = set_pop(types)
  1899. result = string_join(result, full_name(type) + "\n")
  1900. return result!
  1901. else:
  1902. return "No such model: " + model_name!
  1903. String function cmd_folder_create(folder_name : String):
  1904. if (get_entry_id(folder_name) == ""):
  1905. if (element_neq(create_folders(current_user_id, folder_name), read_root())):
  1906. return "Success"!
  1907. else:
  1908. return "Permission denied to folder: " + folder_name!
  1909. else:
  1910. return "Folder alreay exists: " + folder_name!
  1911. String function cmd_conformance_add(model_name : String, metamodel_name : String):
  1912. // Create a new instanceOf relation now
  1913. String instance_of
  1914. instance_of = instantiate_link(core, "instanceOf", "", get_entry_id(model_name), get_entry_id(metamodel_name))
  1915. return "Success"!
  1916. Void function user_function_skip_init(user_id : String):
  1917. String cmd
  1918. String result
  1919. current_user_id = user_id
  1920. caches = dict_create()
  1921. dict_add_fast(caches, "models", dict_create())
  1922. dict_add_fast(caches, "users", dict_create())
  1923. dict_add_fast(caches, "full_name", dict_create())
  1924. // Find root element
  1925. Element elems
  1926. String elem
  1927. elems = allInstances(core, "Folder")
  1928. while (set_len(elems) > 0):
  1929. elem = set_pop(elems)
  1930. if (value_eq(read_attribute(core, elem, "name"), "")):
  1931. if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
  1932. dict_add_fast(caches, "root", elem)
  1933. break!
  1934. output("Welcome to the Model Management Interface v2.0!")
  1935. output("Use the 'help' command for a list of possible commands")
  1936. while (True):
  1937. cmd = input()
  1938. if (cmd == "help"):
  1939. output(cmd_help())
  1940. elif (cmd == "model_add"):
  1941. output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
  1942. elif (cmd == "process_execute"):
  1943. output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
  1944. elif (cmd == "process_signature"):
  1945. output(cmd_process_signature(single_input("Process to execute?")))
  1946. elif (cmd == "transformation_between"):
  1947. output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
  1948. elif (cmd == "model_render"):
  1949. output(cmd_model_render(single_input("Model name?"), single_input("Mapper name?"), single_input("Rendered name?")))
  1950. elif (cmd == "model_rendered"):
  1951. output(cmd_model_rendered(single_input("Model name?"), single_input("Mapper name?")))
  1952. elif (cmd == "transformation_execute"):
  1953. output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?"), single_input("Tracability model?")))
  1954. elif (cmd == "verify"):
  1955. result = cmd_verify(single_input("Model name?"), single_input("Metamodel name?"))
  1956. if (result != ""):
  1957. output(result)
  1958. elif (cmd == "model_overwrite"):
  1959. output(cmd_model_overwrite(single_input("Model name?"), single_input("Metamodel name?")))
  1960. elif (cmd == "model_modify"):
  1961. output(cmd_model_modify(single_input("Model name?"), single_input("Metamodel name?")))
  1962. elif (cmd == "model_delete"):
  1963. output(cmd_model_delete(single_input("Model name?")))
  1964. elif (cmd == "model_list"):
  1965. output(cmd_model_list(single_input("Location?")))
  1966. elif (cmd == "model_list_full"):
  1967. output(cmd_model_list_full(single_input("Location?")))
  1968. elif (cmd == "transformation_add_MANUAL"):
  1969. output(cmd_transformation_add_MANUAL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  1970. elif (cmd == "transformation_add_AL"):
  1971. output(cmd_transformation_add_AL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  1972. elif (cmd == "transformation_add_MT"):
  1973. output(cmd_transformation_add_MT(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  1974. elif (cmd == "permission_modify"):
  1975. output(cmd_permission_modify(single_input("Model name?"), single_input("Permissions?")))
  1976. elif (cmd == "permission_owner"):
  1977. output(cmd_permission_owner(single_input("Model name?"), single_input("New owning user?")))
  1978. elif (cmd == "permission_group"):
  1979. output(cmd_permission_group(single_input("Model name?"), single_input("New owning group?")))
  1980. elif (cmd == "group_create"):
  1981. output(cmd_group_create(single_input("New group name?")))
  1982. elif (cmd == "group_delete"):
  1983. output(cmd_group_delete(single_input("Group name?")))
  1984. elif (cmd == "group_owner_add"):
  1985. output(cmd_group_owner_add(single_input("Group name?"), single_input("User name?")))
  1986. elif (cmd == "group_owner_delete"):
  1987. output(cmd_group_owner_delete(single_input("Group name?"), single_input("User name?")))
  1988. elif (cmd == "group_join"):
  1989. output(cmd_group_join(single_input("Group name?"), single_input("User name?")))
  1990. elif (cmd == "group_kick"):
  1991. output(cmd_group_kick(single_input("Group name?"), single_input("User name?")))
  1992. elif (cmd == "group_list"):
  1993. output(cmd_group_list())
  1994. elif (cmd == "admin_promote"):
  1995. output(cmd_admin_promote(single_input("User name?")))
  1996. elif (cmd == "admin_demote"):
  1997. output(cmd_admin_demote(single_input("User name?")))
  1998. elif (cmd == "service_register"):
  1999. output(cmd_service_register(single_input("Service name?")))
  2000. elif (cmd == "user_password"):
  2001. output(cmd_user_password(single_input("User name?"), single_input("New password?")))
  2002. elif (cmd == "transformation_read_signature"):
  2003. output(cmd_transformation_signature(single_input("Transformation name?")))
  2004. elif (cmd == "verbose"):
  2005. set_verbose(True)
  2006. elif (cmd == "quiet"):
  2007. set_verbose(False)
  2008. elif (cmd == "self-destruct"):
  2009. // Delete user from Core Formalism
  2010. model_delete_element(core, user_id)
  2011. return !
  2012. elif (cmd == "user_logout"):
  2013. // TODO
  2014. cmd = "FAIL"
  2015. elif (cmd == "exit"):
  2016. // Exit by actually removing the user and decoupling it from all of its models
  2017. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  2018. // as the current user will have been deleted
  2019. return !
  2020. elif (cmd == "folder_create"):
  2021. output(cmd_folder_create(single_input("Folder name?")))
  2022. elif (cmd == "add_conformance"):
  2023. log("Adding conformance relation...")
  2024. output(cmd_conformance_add(single_input("Model name?"), single_input("Metamodel name?")))
  2025. log("Added!")
  2026. elif (cmd == "remove_conformance"):
  2027. // TODO
  2028. cmd = "FAIL"
  2029. elif (cmd == "user_name"):
  2030. // TODO
  2031. cmd = "FAIL"
  2032. elif (cmd == "service_poll"):
  2033. // TODO
  2034. cmd = "FAIL"
  2035. elif (cmd == "model_types"):
  2036. output(cmd_model_types(single_input("Model name?")))
  2037. else:
  2038. output("Unknown command: " + cmd)
  2039. // We never get here!
  2040. return !