core_algorithm.alc 87 KB

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