core_algorithm.alc 87 KB

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