core_algorithm.alc 86 KB

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