core_algorithm.alc 87 KB

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