core_algorithm.alc 90 KB

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