core_algorithm.alc 85 KB

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