core_algorithm.alc 86 KB

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