core_algorithm.alc 88 KB

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