core_algorithm.alc 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  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. String core_model_location = "models/core"
  16. Element core = ?
  17. Element caches
  18. String function full_name(model_id : String):
  19. if (dict_in(caches["full_name"], model_id)):
  20. if (get_entry_id(caches["full_name"]) == model_id):
  21. return caches["full_name"]!
  22. // No cache, or out of date
  23. Element incoming
  24. String parent
  25. String parent_name
  26. incoming = allAssociationOrigins(core, model_id, "contains")
  27. if (set_len(incoming) > 0):
  28. parent = set_pop(incoming)
  29. parent_name = full_name(parent)
  30. dict_add(caches["full_name"], parent, parent_name)
  31. return string_join(parent_name + "/", read_attribute(core, model_id, "name"))!
  32. else:
  33. return ""!
  34. Void function initialize_core():
  35. // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
  36. add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
  37. return !
  38. Boolean function is_typed_by(model_id : String, metamodel_id : String):
  39. return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
  40. Element function get_instanceOf_links(model_id : String, metamodel_id : String):
  41. Element result
  42. Element options
  43. String elem
  44. result = set_create()
  45. options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  46. while (set_len(options) > 0):
  47. elem = set_pop(options)
  48. if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
  49. set_add(result, elem)
  50. return result!
  51. String function get_instanceOf_link(model_id : String, metamodel_id : String):
  52. Element all_links
  53. String choice
  54. all_links = get_instanceOf_links(model_id, metamodel_id)
  55. if (set_len(all_links) > 1):
  56. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  57. elif (set_len(all_links) == 0):
  58. log("No types found!")
  59. return read_root()!
  60. choice = set_pop(all_links)
  61. return choice!
  62. Element function get_full_model(model_id : String, metamodel_id : String):
  63. // TODO we are restricted to using SimpleClassDiagrams as M3 level, through this code!
  64. Element m
  65. Element all_links
  66. String choice
  67. choice = get_instanceOf_link(model_id, metamodel_id)
  68. m = dict_create()
  69. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  70. // TODO for now this is restricted to the fixed semantics
  71. // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
  72. dict_add(m, "semantics", get_entry_id("conformance_mv"))
  73. if (metamodel_id == model_id):
  74. // Found the meta-circular level, so we can stop!
  75. dict_add(m, "metamodel", m)
  76. else:
  77. Element mm
  78. mm = get_full_model(metamodel_id, get_entry_id("SimpleClassDiagrams"))
  79. if (element_eq(mm, read_root())):
  80. return read_root()!
  81. else:
  82. dict_add(m, "metamodel", mm)
  83. if (element_neq(choice, read_root())):
  84. if (set_len(allAssociationDestinations(core, choice, "typing")) == 1):
  85. // Add the preferred original type mapping
  86. dict_add(m, "type_mapping", import_node(read_attribute(core, set_pop(allAssociationDestinations(core, choice, "typing")), "location")))
  87. else:
  88. // Start from scratch
  89. dict_add(m, "type_mapping", new_type_mapping())
  90. else:
  91. // Start from scratch
  92. dict_add(m, "type_mapping", new_type_mapping())
  93. if (find_type_mapping(m)):
  94. // TODO store the found type model somewhere
  95. return m!
  96. else:
  97. log("No type mapping could be deduced!")
  98. log("Error for " + cast_v2s(read_attribute(core, model_id, "name")))
  99. log(" and type " + cast_v2s(read_attribute(core, metamodel_id, "name")))
  100. return read_root()!
  101. Integer function get_relation_to_model(user_id : String, model_id : String):
  102. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  103. // We are the owner
  104. return 0!
  105. else:
  106. String group_id
  107. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  108. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  109. // We are in the owning group
  110. return 1!
  111. else:
  112. // We are not related whatsoever
  113. return 2!
  114. Boolean function is_admin(user_id : String):
  115. if (read_attribute(core, user_id, "admin")):
  116. return True!
  117. else:
  118. return False!
  119. Boolean function allow_read(user_id : String, model_id : String):
  120. if (is_admin(user_id)):
  121. // Is admin, so always allow
  122. return True!
  123. else:
  124. // Check permissions
  125. String permission
  126. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  127. if (bool_or(permission == "1", permission == "2")):
  128. return True!
  129. else:
  130. return False!
  131. Boolean function allow_write(user_id : String, model_id : String):
  132. if (is_admin(user_id)):
  133. // Is admin, so always allow
  134. return True!
  135. else:
  136. // Check permissions
  137. String permission
  138. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  139. if (permission == "2"):
  140. return True!
  141. else:
  142. return False!
  143. Boolean function allow_change_metadata(user_id : String, model_id : String):
  144. if (is_admin(user_id)):
  145. // Is admin, so always allow
  146. return True!
  147. else:
  148. if (get_relation_to_model(user_id, model_id) == 0):
  149. // Only owner can chmod
  150. return True!
  151. else:
  152. return False!
  153. Boolean function allow_group_modify(user_id : String, group_id : String):
  154. if (is_admin(user_id)):
  155. // Is admin, so always allow
  156. return True!
  157. else:
  158. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  159. // We are an owner
  160. return True!
  161. else:
  162. return False!
  163. Boolean function check_login(user_id : String):
  164. String password
  165. String stored_password
  166. stored_password = read_attribute(core, user_id, "password")
  167. output("Password for existing user?")
  168. password = hash(input())
  169. return password == stored_password!
  170. Void function new_task():
  171. String username
  172. String user_id
  173. String password
  174. // Load in a hard-reference to the previously created model
  175. core = import_node(core_model_location)
  176. while (True):
  177. output("Log on as which user?")
  178. username = input()
  179. user_id = get_user_id(username)
  180. if (user_id == ""):
  181. // New user
  182. // Add user to Core Formalism
  183. user_id = instantiate_node(core, "User", "")
  184. instantiate_attribute(core, user_id, "name", username)
  185. instantiate_attribute(core, user_id, "admin", False)
  186. output("This is a new user: please give password!")
  187. password = hash(input())
  188. output("Please repeat the password")
  189. if (password == hash(input())):
  190. output("Passwords match!")
  191. instantiate_attribute(core, user_id, "password", password)
  192. break!
  193. else:
  194. output("Not the same password!")
  195. else:
  196. if (check_login(user_id)):
  197. break!
  198. else:
  199. output("Wrong password!")
  200. user_function_skip_init(user_id)
  201. // User destroyed already, so just stop execution
  202. return!
  203. String function get_entry_id(name : String):
  204. Element hierarchy_split
  205. String current
  206. Integer i
  207. Element elems
  208. String current_part
  209. String elem
  210. i = 0
  211. name = "/" + name
  212. hierarchy_split = string_split(name, "/")
  213. current = caches["models"][""]
  214. log("Reading " + name)
  215. log("Split up in: " + list_to_string(hierarchy_split))
  216. while (i < list_len(hierarchy_split)):
  217. current_part = list_read(hierarchy_split, i)
  218. // the initial current ("") will always be in the cache as root element
  219. if (bool_not(dict_in(caches["models"], current))):
  220. // This element is not cached, so cache completely!
  221. log("Miss for " + current_part)
  222. elems = allAssociationDestinations(core, current, "contains")
  223. while (set_len(elems) > 0):
  224. elem = set_pop(elems)
  225. dict_overwrite(caches["models"][current], read_attribute(core, elem, "name"), elem)
  226. dict_overwrite(caches["models"][current], "", current)
  227. log("Ready for access: " + current_part)
  228. if (dict_in(caches["models"][current], current_part)):
  229. current = caches["models"][current][current_part]
  230. log("SUCCESS: " + current)
  231. else:
  232. log("FAILED")
  233. return ""!
  234. return current!
  235. String function get_service_id(name : String):
  236. Element services
  237. String service
  238. services = allInstances(core, "Service")
  239. while (set_len(services) > 0):
  240. service = set_pop(services)
  241. if (value_eq(read_attribute(core, service, "name"), name)):
  242. return service!
  243. return ""!
  244. String function get_user_id(name : String):
  245. Element users
  246. String user
  247. users = allInstances(core, "User")
  248. while (set_len(users) > 0):
  249. user = set_pop(users)
  250. if (value_eq(read_attribute(core, user, "name"), name)):
  251. return user!
  252. return ""!
  253. String function get_group_id(name : String):
  254. Element groups
  255. String group
  256. groups = allInstances(core, "Group")
  257. while (set_len(groups) > 0):
  258. group = set_pop(groups)
  259. if (value_eq(read_attribute(core, group, "name"), name)):
  260. return group!
  261. return ""!
  262. String function store_entry(model_id : String, full_name : String, user_id : String):
  263. Element hierarchy
  264. Integer i
  265. String prev
  266. String elem
  267. String new_entry
  268. i = 0
  269. hierarchy = string_split(full_name, "/")
  270. prev = get_entry_id("")
  271. // Go through folders first
  272. while (i < list_len(hierarchy) - 1):
  273. elem = list_read(hierarchy, i)
  274. if (get_entry_id(elem) == ""):
  275. // Element does not exist yet!
  276. new_entry = instantiate_node(core, "Folder", "")
  277. instantiate_attribute(core, new_entry, "name", elem)
  278. instantiate_attribute(core, new_entry, "permissions", "200")
  279. instantiate_link(core, "contains", "", prev, new_entry)
  280. instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
  281. instantiate_link(core, "owner", "", new_entry, user_id)
  282. instantiate_link(core, "contains", "", prev, model_id)
  283. return list_pop_final(hierarchy)!
  284. String function export_typing(model : Element, name : String, user_id : String):
  285. String result
  286. result = instantiate_node(core, "TypeMapping", "")
  287. name = "type mappings/" + name
  288. // Create type mapping model
  289. String location
  290. location = "type_mappings/" + cast_id2s(model["type_mapping"])
  291. export_node(location, model["type_mapping"])
  292. String instance_of
  293. name = store_entry(result, name, get_user_id("admin"))
  294. instantiate_attribute(core, result, "name", name)
  295. instantiate_attribute(core, result, "location", location)
  296. instantiate_attribute(core, result, "permissions", "200")
  297. instantiate_link(core, "owner", "", result, user_id)
  298. instantiate_link(core, "group", "", result, get_group_id("nobody"))
  299. instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("TypeMapping"))
  300. instantiate_link(core, "semantics", "", instance_of, get_entry_id("conformance_mv"))
  301. return result!
  302. Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
  303. String location
  304. String model_id
  305. String instance_of
  306. // Create model itself
  307. location = "models/" + cast_id2s(model)
  308. export_node(location, model["model"])
  309. model_id = instantiate_node(core, kind, "")
  310. instantiate_attribute(core, model_id, "name", store_entry(model_id, name, user_id))
  311. instantiate_attribute(core, model_id, "location", location)
  312. instantiate_attribute(core, model_id, "permissions", "200")
  313. instantiate_link(core, "owner", "", model_id, user_id)
  314. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  315. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  316. instantiate_link(core, "semantics", "", instance_of, get_entry_id("conformance_mv"))
  317. // Create type mapping model
  318. instantiate_link(core, "typing", "", instance_of, export_typing(model, name, user_id))
  319. return!
  320. Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
  321. // TODO this should be more elegant than just hiding the old elements
  322. String location
  323. String instanceOf_link
  324. location = "models/" + cast_id2s(model)
  325. export_node(location, model["model"])
  326. // Change location in meta-data
  327. unset_attribute(core, model_id, "location")
  328. instantiate_attribute(core, model_id, "location", location)
  329. // Update the instanceOf relation of the context in which we are working
  330. String choice
  331. choice = get_instanceOf_link(model_id, metamodel_id)
  332. if (element_neq(choice, read_root())):
  333. // There was a link, so we remove it
  334. model_delete_element(core, choice)
  335. // Create a new instanceOf relation now
  336. String instance_of
  337. instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
  338. instantiate_link(core, "semantics", "", instance_of, get_entry_id("conformance_mv"))
  339. instantiate_link(core, "typing", "", instance_of, export_typing(model, full_name(model_id), get_user_id("admin")))
  340. return!
  341. Boolean function check_conformance(model_id : String):
  342. // TODO check if it actually conforms, considering that instanceOf link
  343. // --> in-depth check
  344. return True!
  345. Boolean function pm_finished(worklist : Element, pm : String):
  346. Element finished
  347. Integer cnt
  348. Integer i
  349. // Check if any of the "finish" elements are in the worklist
  350. // If so, we can already finish, and therefore will stop immediately
  351. finished = allInstances(pm, "Finish")
  352. worklist = set_copy(worklist)
  353. while (set_len(worklist) > 0):
  354. // Check each finished element individually
  355. if (set_in(finished, list_read(set_pop(worklist), 0))):
  356. return True!
  357. return False!
  358. Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
  359. // Operations are always in-place and uses only a single metamodel
  360. // Therefore, we must:
  361. // 1) Find merged metamodel
  362. // 2) Merge the different source models and retype
  363. // 3) Perform the operation on the merged model
  364. // 4) Split the resulting model based on the target formalisms; if operation successful
  365. Element input_model
  366. String trace_link_id
  367. Element merged_model
  368. String merged_metamodel_id
  369. String ramified_metamodel_id
  370. Boolean result
  371. String exact_type
  372. Element trace_links
  373. String model_ID
  374. String key
  375. Element keys
  376. Element input_keys
  377. Element output_keys
  378. Element model_tuples
  379. String metamodel_name
  380. Element metamodel
  381. String metamodel_ID
  382. Boolean tracability
  383. // 0) Find the signature of the operation
  384. Element input_metamodels
  385. Element output_metamodels
  386. Element iter
  387. String edge
  388. input_metamodels = dict_create()
  389. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  390. while (set_len(iter) > 0):
  391. edge = set_pop(iter)
  392. dict_add(input_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  393. output_metamodels = dict_create()
  394. iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
  395. while (set_len(iter) > 0):
  396. edge = set_pop(iter)
  397. dict_add(output_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  398. // 1) Find merged metamodel
  399. exact_type = read_type(core, operation_id)
  400. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  401. merged_metamodel_id = ""
  402. while (set_len(trace_links) > 0):
  403. trace_link_id = set_pop(trace_links)
  404. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  405. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  406. // 2) Merge source models
  407. if (merged_metamodel_id != ""):
  408. model_tuples = set_create()
  409. keys = dict_keys(input_models)
  410. while (set_len(keys) > 0):
  411. key = set_pop(keys)
  412. Element mm
  413. mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
  414. if (element_eq(mm, read_root())):
  415. log("Signature mismatch in operation for tag " + key)
  416. output("Signature mismatch in operation for tag " + key)
  417. return read_root()!
  418. set_add_node(model_tuples, create_tuple(key, mm))
  419. Element merged_metamodel
  420. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("SimpleClassDiagrams"))
  421. if (element_eq(merged_metamodel, read_root())):
  422. log("Merged metamodel in operation is not of type SimpleClassDiagrams")
  423. output("Merged metamodel in operation is not of type SimpleClassDiagrams")
  424. return read_root()!
  425. merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
  426. else:
  427. if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
  428. // Just skip the merge...
  429. Element m
  430. 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))]))
  431. if (element_eq(m, read_root())):
  432. log("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
  433. output("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
  434. return read_root()!
  435. merged_model = model_copy(m)
  436. elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
  437. merged_model = read_root()
  438. else:
  439. log("Could not resolve intermediate merged metamodel")
  440. output("Could not resolve intermediate merged metamodel")
  441. return read_root()!
  442. // 3) Transform
  443. if (exact_type == "ModelTransformation"):
  444. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  445. ramified_metamodel_id = ""
  446. while (set_len(trace_links) > 0):
  447. trace_link_id = set_pop(trace_links)
  448. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  449. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  450. Element operation
  451. operation = get_full_model(operation_id, ramified_metamodel_id)
  452. if (element_eq(operation, read_root())):
  453. log("Operation could not be typed by specified RAMified metamodel!")
  454. output("Operation could not be typed by specified RAMified metamodel!")
  455. return read_root()!
  456. result = transform(merged_model, operation)
  457. elif (exact_type == "ManualOperation"):
  458. output("Please perform manual operation " + cast_v2s(full_name(operation_id)))
  459. modify(merged_model, True)
  460. result = True
  461. elif (exact_type == "ActionLanguage"):
  462. Element func
  463. Element al
  464. al = get_full_model(operation_id, get_entry_id("ActionLanguage"))
  465. if (element_eq(al, read_root())):
  466. log("Action Language operation not typed by ActionLanguage metamodel!")
  467. output("Action Language operation not typed by ActionLanguage metamodel!")
  468. return read_root()!
  469. func = get_func_AL_model(al)
  470. result = func(merged_model)
  471. else:
  472. log("Unknown type of operation: " + exact_type)
  473. output("Unknown type of operation: " + exact_type)
  474. return read_root()!
  475. // 4) Split in different models depending on type
  476. if (element_neq(tracability_model, read_root())):
  477. tracability = True
  478. else:
  479. tracability = False
  480. if (result):
  481. model_tuples = set_create()
  482. keys = dict_keys(output_metamodels)
  483. while (set_len(keys) > 0):
  484. key = set_pop(keys)
  485. Element mm
  486. mm = get_full_model(get_entry_id(output_metamodels[key]), get_entry_id("SimpleClassDiagrams"))
  487. if (element_eq(mm, read_root())):
  488. log("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  489. output("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  490. return read_root()!
  491. set_add_node(model_tuples, create_tuple(key, mm))
  492. result = model_split(merged_model, model_tuples, tracability)
  493. if (tracability):
  494. Element new_tracability_model
  495. new_tracability_model = result["__tracability"]
  496. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  497. dict_overwrite(tracability_model, "type_mapping", new_tracability_model["type_mapping"])
  498. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  499. dict_delete(result, "__tracability")
  500. return result!
  501. else:
  502. log("Negative result of execution")
  503. return read_root()!
  504. Boolean function enact_action(pm : Element, element : String, prefix : String, user_id : String):
  505. Boolean result
  506. String transformation_id
  507. Element lst
  508. String elem
  509. Element inputs
  510. Element outputs
  511. String type_name
  512. String exact_type
  513. Element trace_links
  514. Element output_mms
  515. Element consumes_link
  516. String name
  517. String value
  518. String elem_name
  519. Element keys
  520. String key
  521. String consume
  522. String produce
  523. Element output_map
  524. inputs = dict_create()
  525. outputs = dict_create()
  526. output_map = dict_create()
  527. // Read out the referenced element from the MvC
  528. transformation_id = get_entry_id(read_attribute(pm, element, "name"))
  529. // Find all input model names
  530. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  531. while (set_len(lst) > 0):
  532. consume = set_pop(lst)
  533. value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
  534. dict_add(inputs, read_attribute(pm, consume, "name"), prefix + value)
  535. // Find all output model names and their metamodel
  536. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  537. while (set_len(lst) > 0):
  538. produce = set_pop(lst)
  539. elem = readAssociationDestination(pm, produce)
  540. type_name = read_attribute(pm, elem, "type")
  541. elem_name = read_attribute(pm, elem, "name")
  542. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  543. dict_add(output_map, read_attribute(pm, produce, "name"), prefix + elem_name)
  544. if read_type(core, transformation_id) == "ActionLanguage":
  545. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  546. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  547. elif read_type(core, transformation_id) == "ManualOperation":
  548. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  549. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  550. else:
  551. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  552. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  553. result = execute_operation(transformation_id, inputs, read_root())
  554. if (element_eq(result, read_root())):
  555. // Something went wrong!
  556. return False!
  557. else:
  558. keys = dict_keys(result)
  559. while (set_len(keys) > 0):
  560. key = set_pop(keys)
  561. if (get_entry_id(output_map[key]) == ""):
  562. // New model
  563. model_create(result[key], output_map[key], user_id, get_entry_id(key), "Model")
  564. else:
  565. model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
  566. return True!
  567. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  568. Element worklist
  569. String element
  570. String start
  571. String type
  572. Boolean result
  573. Element tuple
  574. Element counters
  575. Element join_nodes
  576. output("Success")
  577. // Initialize Join counters
  578. counters = dict_create()
  579. join_nodes = allInstances(pm, "Join")
  580. while (set_len(join_nodes) > 0):
  581. dict_add(counters, set_pop(join_nodes), 0)
  582. // Create the worklist with the Start instance as first element
  583. worklist = set_create()
  584. set_add_node(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  585. while (bool_not(pm_finished(worklist, pm))):
  586. // Pop a random element from the list and execute it
  587. tuple = set_pop(worklist)
  588. element = tuple[0]
  589. result = tuple[1]
  590. // Find the type (to see what to do with it)
  591. // this does not yet yield the type of transformation, if it is an Execution
  592. type = read_type(pm, element)
  593. if (type == "Start"):
  594. // Initial node, just progress to the next elements
  595. // Nothing to do here though, as we have just started
  596. result = True
  597. elif (type == "Finish"):
  598. // Should be impossible, as we would have ended...
  599. result = result
  600. elif (type == "Fork"):
  601. result = result
  602. elif (type == "Join"):
  603. // Only do this if all dependencies are fullfilled
  604. // So add to the counter of this Join
  605. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  606. // Now check whether we have enough tokens to execute the Join itself
  607. Integer required
  608. Integer got
  609. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  610. got = counters[element]
  611. if (got == required):
  612. // Reset counter to 0
  613. dict_overwrite(counters, element, 0)
  614. // And continue
  615. else:
  616. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  617. continue!
  618. elif (type == "Exec"):
  619. // Execute a transformation
  620. // This the difficult part!
  621. result = enact_action(pm, element, prefix, user_id)
  622. elif (type == "Decision"):
  623. // If the previous result is true, we add the normal one, otherwise the false one
  624. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  625. if (bool_not(result)):
  626. // Apparently it is False, so map this to the "Else" branch
  627. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  628. continue!
  629. else:
  630. // Apparently it is True, so map this to the "Then" branch
  631. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  632. continue!
  633. // We have finished the execution, so add all outgoing edges to the worklist
  634. Element all_next
  635. all_next = allAssociationDestinations(pm, element, "Next")
  636. String next
  637. while (set_len(all_next) > 0):
  638. next = set_pop(all_next)
  639. set_add_node(worklist, create_tuple(next, result))
  640. // Reached a finish element, so stop
  641. output("Success")
  642. return !
  643. String function cmd_help(user_id : String):
  644. String result
  645. result = ""
  646. result = result + ("Model operations\n")
  647. result = result + (" model_add -- Add a new model\n")
  648. result = result + (" model_modify -- Modify an existing model\n")
  649. result = result + (" model_list -- List all models\n")
  650. result = result + (" model_list_full -- List all models with full info\n")
  651. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  652. result = result + (" model_render -- Render a given model with a specified mapper\n")
  653. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  654. result = result + ("\n")
  655. result = result + ("Transformation-specific operations\n")
  656. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  657. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  658. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  659. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  660. result = result + (" transformation_list -- List all model transformations\n")
  661. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  662. result = result + (" transformation_detail -- List transformation details\n")
  663. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  664. result = result + ("\n")
  665. result = result + ("Process operations\n")
  666. result = result + (" process_execute -- Execute a process model\n")
  667. result = result + ("\n")
  668. result = result + ("Model permission operations\n")
  669. result = result + (" permission_modify -- Change model permissions\n")
  670. result = result + (" permission_owner -- Change model owner\n")
  671. result = result + (" permission_group -- Change model group\n")
  672. result = result + ("\n")
  673. result = result + ("Group operations\n")
  674. result = result + (" group_create -- Create a group\n")
  675. result = result + (" group_delete -- Delete a group\n")
  676. result = result + (" group_owner_add -- Add group owner\n")
  677. result = result + (" group_owner_delete -- Remove group owner\n")
  678. result = result + (" group_join -- Add someone to your group\n")
  679. result = result + (" group_kick -- Kick someone from your group\n")
  680. result = result + (" group_list -- List all groups you are a member of\n")
  681. result = result + ("\n")
  682. if (is_admin(user_id)):
  683. result = result + ("Admin operations\n")
  684. result = result + (" admin_promote -- Promote a user to admin status\n")
  685. result = result + (" admin_demote -- Demote a user to normal status\n")
  686. result = result + ("\n")
  687. result = result + ("General operations\n")
  688. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  689. result = result + (" exit -- Kill the current task, while retaining user\n")
  690. return result!
  691. String function cmd_model_add(user_id : String, type : String, name : String):
  692. // Model addition operation, which uses model upload commands of the compiler
  693. String location
  694. String type_id
  695. Element new_model
  696. String new_model_id
  697. type_id = get_entry_id(type)
  698. if (type_id != ""):
  699. // Type exists
  700. if (allow_read(user_id, type_id)):
  701. // And is readable
  702. if (get_entry_id(name) == ""):
  703. // Model doesn't exist yet
  704. Element mm
  705. mm = get_full_model(type_id, get_entry_id("SimpleClassDiagrams"))
  706. if (element_eq(mm, read_root())):
  707. return "Type is not typed by SimpleClassDiagrams: " + type!
  708. output("Waiting for model constructors...")
  709. new_model = construct_model_raw(mm)
  710. model_create(new_model, name, user_id, type_id, "Model")
  711. return "Success"!
  712. else:
  713. return "Model exists: " + name!
  714. else:
  715. return "Permission denied to model: " + type!
  716. else:
  717. return "Model not found: " + type!
  718. String function cmd_process_execute(user_id : String, process : String, prefix : String):
  719. // Execute a process model until it reaches termination
  720. String process_id
  721. process_id = get_entry_id(process)
  722. if (process_id != ""):
  723. if (allow_read(user_id, process_id)):
  724. Element pm
  725. pm = get_full_model(process_id, get_entry_id("ProcessModel"))
  726. if (element_eq(pm, read_root())):
  727. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  728. enact_PM(pm, prefix, user_id)
  729. return "Success"!
  730. else:
  731. return "Permission denied to model: " + process!
  732. else:
  733. return "Model not found: " + process!
  734. String function cmd_transformation_between(user_id : String, source_name : String, target_name : String):
  735. String source_id
  736. String target_id
  737. Element onSource
  738. Element onTarget
  739. Element result
  740. String transformation
  741. source_id = get_entry_id(source_name)
  742. if (source_id != ""):
  743. target_id = get_entry_id(target_name)
  744. if (target_id != ""):
  745. onSource = allAssociationOrigins(core, source_id, "transformInput")
  746. onTarget = allAssociationOrigins(core, target_id, "transformOutput")
  747. result = set_overlap(onSource, onTarget)
  748. String r
  749. r = "Success: "
  750. while (set_len(result) > 0):
  751. transformation = set_pop(result)
  752. if (allow_read(user_id, transformation)):
  753. r = r + string_join(full_name(transformation), "\n")
  754. return r!
  755. else:
  756. return "Model not found: " + target_name!
  757. else:
  758. return "Model not found: " + source_name!
  759. String function cmd_model_render(user_id : String, model_name : String, mapper_name : String):
  760. String model_ID
  761. String mapper_ID
  762. String rendered_name
  763. String tracability_name
  764. Element inputs
  765. Element output_map
  766. Element rendered_model
  767. Element tracability_model
  768. Element result
  769. Element out_links
  770. String link
  771. model_ID = get_entry_id(model_name)
  772. if (model_ID != ""):
  773. mapper_ID = get_entry_id(mapper_name)
  774. if (allow_read(user_id, model_ID)):
  775. if (mapper_ID != ""):
  776. if (allow_read(user_id, mapper_ID)):
  777. // Everything is fine; start the actual operation
  778. // Find metamodel to render to
  779. rendered_name = (("__RENDERED_" + model_name) + "__") + mapper_name
  780. tracability_name = (("__TRACABILITY_" + model_name) + "__") + mapper_name
  781. // Take the abstract syntax model and the previously rendered model
  782. inputs = dict_create()
  783. dict_add(inputs, "abstract", model_name)
  784. dict_add(inputs, "rendered", rendered_name)
  785. // Fetch the output types
  786. output_map = dict_create()
  787. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  788. while(set_len(out_links) > 0):
  789. link = set_pop(out_links)
  790. dict_add(output_map, read_attribute(core, link, "name"), full_name(readAssociationDestination(core, link)))
  791. if (get_entry_id(rendered_name) == ""):
  792. // Instantiate
  793. Element rendered
  794. rendered = get_full_model(get_entry_id(output_map["rendered"]), get_entry_id("SimpleClassDiagrams"))
  795. if (element_eq(rendered, read_root())):
  796. return "Rendered metamodel cannot conform to SimpleClassDiagrams"!
  797. rendered_model = instantiate_model(rendered)
  798. model_create(rendered_model, rendered_name, user_id, get_entry_id(output_map["rendered"]), "Model")
  799. // Tracability model won't exist either
  800. tracability_model = instantiate_model(get_full_model(get_entry_id("Tracability"), get_entry_id("SimpleClassDiagrams")))
  801. model_create(tracability_model, tracability_name, user_id, get_entry_id("Tracability"), "Model")
  802. else:
  803. // Read out tracability model
  804. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("Tracability"))
  805. if (element_eq(tracability_model, read_root())):
  806. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  807. // Do the operation itself!
  808. result = execute_operation(mapper_ID, inputs, tracability_model)
  809. // Overwrite the previous rendered model
  810. model_overwrite(result["rendered"], get_entry_id(rendered_name), get_entry_id(output_map["rendered"]))
  811. model_overwrite(result["abstract"], get_entry_id(model_name), get_entry_id(output_map["abstract"]))
  812. // Tracability updated in-place
  813. model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("Tracability"))
  814. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("Tracability"))
  815. if (element_eq(tracability_model, read_root())):
  816. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  817. // Also output the resulting model
  818. return "Success: " + JSON_print(get_full_model(get_entry_id(rendered_name), get_entry_id(output_map["rendered"])))!
  819. else:
  820. return "Permission denied to model: " + mapper_name!
  821. else:
  822. return "Model not found: " + mapper_name!
  823. else:
  824. return "Permission denied to model: " + model_name!
  825. else:
  826. return "Model not found: " + model_name!
  827. String function cmd_transformation_execute(user_id : String, transformation_name : String, source_models : Element, target_models : Element):
  828. // Execute a transformation, whatever type it is
  829. // First we detect the type, so we know how to prepare for invocation
  830. String transformation_id
  831. String exact_type
  832. Element sources
  833. Element targets
  834. String source
  835. String target
  836. Element inputs
  837. Element outputs
  838. Element output_map
  839. Element trace_links
  840. String target_model_name
  841. String source_model_name
  842. String source_model_ID
  843. Element result
  844. Element keys
  845. String key
  846. String assoc_name
  847. transformation_id = get_entry_id(transformation_name)
  848. if (transformation_id != ""):
  849. if (allow_read(user_id, transformation_id)):
  850. if (is_nominal_instance(core, transformation_id, "Transformation")):
  851. // Read out source and target links
  852. inputs = dict_create()
  853. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  854. while (set_len(sources) > 0):
  855. source = set_pop(sources)
  856. assoc_name = read_attribute(core, source, "name")
  857. if (dict_in(source_models, assoc_name)):
  858. source_model_name = source_models[assoc_name]
  859. else:
  860. return "Source model not bound: " + assoc_name!
  861. source_model_ID = get_entry_id(source_model_name)
  862. if (source_model_ID != ""):
  863. if (allow_read(user_id, source_model_ID)):
  864. // Check for conformance to the requested metamodel
  865. dict_add(inputs, assoc_name, source_model_name)
  866. continue!
  867. else:
  868. return "Permission denied to model: " + source_model_name!
  869. else:
  870. return "Model not found: " + source_model_name!
  871. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  872. outputs = dict_create()
  873. output_map = dict_create()
  874. while (set_len(targets) > 0):
  875. target = set_pop(targets)
  876. assoc_name = read_attribute(core, target, "name")
  877. if (dict_in(target_models, assoc_name)):
  878. target_model_name = target_models[assoc_name]
  879. else:
  880. return "Target model not bound: " + assoc_name!
  881. if (get_entry_id(target_model_name) == ""):
  882. // Doesn't exist yet, so we can easily create
  883. dict_add(output_map, assoc_name, full_name(target))
  884. dict_add(outputs, assoc_name, target_model_name)
  885. else:
  886. // Already exists, so we need to check for write access
  887. if (allow_write(user_id, get_entry_id(target_model_name))):
  888. dict_add(output_map, assoc_name, full_name(target))
  889. dict_add(outputs, assoc_name, target_model_name)
  890. else:
  891. return "Permission denied to model: " + target_model_name!
  892. if (read_type(core, transformation_id) == "ActionLanguage"):
  893. output("Success: ready for AL execution")
  894. elif (read_type(core, transformation_id) == "ManualOperation"):
  895. output("Success: ready for MANUAL execution")
  896. else:
  897. output("Success: ready for MT execution")
  898. result = execute_operation(transformation_id, inputs, read_root())
  899. // Now write out the models again
  900. if (element_eq(result, read_root())):
  901. // Something went wrong!
  902. return "Failure"!
  903. else:
  904. keys = dict_keys(result)
  905. while (set_len(keys) > 0):
  906. key = set_pop(keys)
  907. if (get_entry_id(outputs[key]) == ""):
  908. // New model
  909. model_create(result[key], outputs[key], user_id, get_entry_id(key), "Model")
  910. else:
  911. model_overwrite(result[key], get_entry_id(outputs[key]), get_entry_id(output_map[key]))
  912. return "Success"!
  913. else:
  914. return "Model is not executable: " + transformation_name!
  915. else:
  916. return "Permission denied to model: " + transformation_name!
  917. else:
  918. return "Model not found: " + transformation_name!
  919. String function cmd_verify(user_id : String, model_name : String, metamodel_name : String):
  920. // Check whether a model conforms to its specification (with the selected type mapping)
  921. String model_id
  922. String result
  923. Element inputs
  924. model_id = get_entry_id(model_name)
  925. if (model_id != ""):
  926. if (allow_read(user_id, model_id)):
  927. Element m
  928. m = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  929. if (element_eq(m, read_root())):
  930. return "No conformance relation can be found between these models"!
  931. return string_join("Success: ", conformance_scd(m))!
  932. else:
  933. return "Permission denied to model: " + model_name!
  934. else:
  935. return "Model not found: " + model_name!
  936. String function cmd_model_overwrite(user_id : String, model_name : String, metamodel_name : String):
  937. // Overwrites an existing model without changing any metadata
  938. String model_id
  939. String type_id
  940. Element new_model
  941. model_id = get_entry_id(model_name)
  942. if (model_id != ""):
  943. if (allow_write(user_id, model_id)):
  944. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  945. if (allow_read(user_id, type_id)):
  946. Element mm
  947. mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("SimpleClassDiagrams"))
  948. if (element_eq(mm, read_root())):
  949. return "Metamodel does not conform to SimpleClassDiagrams: " + metamodel_name!
  950. output("Waiting for model constructors...")
  951. new_model = construct_model_raw(mm)
  952. model_overwrite(new_model, model_id, metamodel_name)
  953. return "Success"!
  954. else:
  955. return string_join("Permission denied to model: ", full_name(type_id))!
  956. else:
  957. return "Permission denied to model: " + model_name!
  958. else:
  959. return "Model not found: " + model_name!
  960. String function cmd_model_modify(user_id : String, model_name : String, metamodel_name : String):
  961. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  962. String model_id
  963. String type_id
  964. model_id = get_entry_id(model_name)
  965. if (model_id != ""):
  966. if (allow_read(user_id, model_id)):
  967. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  968. if (allow_read(user_id, type_id)):
  969. Element new_model
  970. new_model = get_full_model(model_id, get_entry_id(metamodel_name))
  971. if (element_eq(new_model, read_root())):
  972. return "No conformance relation can be found between these models"!
  973. output("Success")
  974. modify(new_model, allow_write(user_id, model_id))
  975. if (allow_write(user_id, model_id)):
  976. // Overwrite the modified model
  977. model_overwrite(new_model, model_id, metamodel_name)
  978. return "Success"!
  979. else:
  980. return string_join("Permission denied to model: ", full_name(type_id))!
  981. else:
  982. return "Permission denied to model: " + model_name!
  983. else:
  984. return "Model not found: " + model_name!
  985. String function cmd_model_delete(user_id : String, model_name : String):
  986. String model_id
  987. model_id = get_entry_id(model_name)
  988. if (model_id != ""):
  989. if (allow_write(user_id, model_id)):
  990. model_delete_element(core, model_id)
  991. return "Success"!
  992. else:
  993. return "Permission denied to model: " + model_name!
  994. else:
  995. return "Model not found: " + model_name!
  996. String function cmd_model_list(location : String):
  997. // List all models
  998. Element models
  999. String result
  1000. String m
  1001. result = "Success: "
  1002. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1003. while (set_len(models) > 0):
  1004. m = set_pop(models)
  1005. result = result + string_join(string_join(" ", read_attribute(core, m, "name")), "\n")
  1006. return result!
  1007. String function cmd_model_list_full(location : String):
  1008. // List all models with full info
  1009. Element models
  1010. String m
  1011. String permissions
  1012. String owner
  1013. String group
  1014. String name
  1015. String type
  1016. String result
  1017. result = "Success: "
  1018. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1019. while (set_len(models) > 0):
  1020. m = set_pop(models)
  1021. permissions = read_attribute(core, m, "permissions")
  1022. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1023. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1024. name = read_attribute(core, m, "name")
  1025. result = result + ((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + "\n")
  1026. return result!
  1027. String function cmd_transformation_add_MANUAL(user_id : String, source_models : Element, target_models : Element, operation_name : String):
  1028. return transformation_add(user_id, source_models, target_models, operation_name, "manual")!
  1029. String function cmd_transformation_add_AL(user_id : String, source_models : Element, target_models : Element, operation_name : String):
  1030. return transformation_add(user_id, source_models, target_models, operation_name, "actionlanguage")!
  1031. String function transformation_add(user_id : String, source_models : Element, target_models : Element, operation_name : String, operation_type : String):
  1032. // Add a manual transformation model
  1033. String model_id
  1034. Element models
  1035. Element source
  1036. Element target
  1037. String name
  1038. Element all_formalisms
  1039. Element formalism_map
  1040. Element merged_formalism
  1041. String merged_formalism_id
  1042. String source_formalism_id
  1043. String tracability_link
  1044. Element fused
  1045. Element keys
  1046. String key
  1047. Element mm
  1048. source = dict_create()
  1049. target = dict_create()
  1050. all_formalisms = set_create()
  1051. formalism_map = set_create()
  1052. fused = set_create()
  1053. keys = dict_keys(source_models)
  1054. while (set_len(keys) > 0):
  1055. key = set_pop(keys)
  1056. name = source_models[key]
  1057. model_id = get_entry_id(name)
  1058. if (model_id != ""):
  1059. if (allow_read(user_id, model_id)):
  1060. if (bool_not(dict_in(source, key))):
  1061. dict_add(source, key, model_id)
  1062. mm = get_full_model(model_id, get_entry_id("SimpleClassDiagrams"))
  1063. if (element_eq(mm, read_root())):
  1064. return "Transformation source type not in SimpleClassDiagrams hierarchy: " + key!
  1065. if (bool_not(set_in(fused, key))):
  1066. set_add_node(formalism_map, create_tuple(key, mm))
  1067. set_add(fused, key)
  1068. if (bool_not(set_in(all_formalisms, model_id))):
  1069. set_add(all_formalisms, model_id)
  1070. else:
  1071. return "Name already selected for source: " + key!
  1072. else:
  1073. return "Permission denied to model: " + name!
  1074. else:
  1075. return "Model not found: " + name!
  1076. keys = dict_keys(target_models)
  1077. while (set_len(keys) > 0):
  1078. key = set_pop(keys)
  1079. name = target_models[key]
  1080. model_id = get_entry_id(name)
  1081. if (model_id != ""):
  1082. if (allow_read(user_id, model_id)):
  1083. if (bool_not(dict_in(target, key))):
  1084. dict_add(target, key, model_id)
  1085. mm = get_full_model(model_id, get_entry_id("SimpleClassDiagrams"))
  1086. if (element_eq(mm, read_root())):
  1087. return "Transformation target type not in SimpleClassDiagrams hierarchy: " + key!
  1088. if (bool_not(set_in(fused, key))):
  1089. set_add_node(formalism_map, create_tuple(key, mm))
  1090. set_add(fused, key)
  1091. if (bool_not(set_in(all_formalisms, model_id))):
  1092. set_add(all_formalisms, model_id)
  1093. else:
  1094. return "Name already selected for target: " + key!
  1095. else:
  1096. return "Permission denied to model: " + name!
  1097. else:
  1098. return "Model not found: " + name!
  1099. if (get_entry_id(operation_name) == ""):
  1100. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1101. // New location is available, so write
  1102. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1103. merged_formalism = model_fuse(formalism_map)
  1104. modify(merged_formalism, True)
  1105. if (operation_type == "manual"):
  1106. // Finished with all information, now create the model itself!
  1107. Element m
  1108. m = get_full_model(get_entry_id("ManualOperation"), get_entry_id("SimpleClassDiagrams"))
  1109. if (element_eq(m, read_root())):
  1110. log("Error when opening ManualOperation: no conformance relation found")
  1111. return "Error when opening ManualOperation: no conformance relation found"!
  1112. model_create(instantiate_model(m), operation_name, user_id, get_entry_id("ManualOperation"), "ManualOperation")
  1113. model_id = get_entry_id(operation_name)
  1114. elif (operation_type == "actionlanguage"):
  1115. // Finished with all information, now create the model itself!
  1116. output("Waiting for code constructors...")
  1117. add_code_model(get_full_model(get_entry_id("ActionLanguage"), get_entry_id("SimpleClassDiagrams")), "AL/" + operation_name, construct_function())
  1118. model_create(import_node("AL/" + operation_name), operation_name, user_id, get_entry_id("ActionLanguage"), "ActionLanguage")
  1119. model_id = get_entry_id(operation_name)
  1120. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1121. model_create(merged_formalism, "__merged_" + operation_name, user_id, get_entry_id("SimpleClassDiagrams"), "Model")
  1122. merged_formalism_id = get_entry_id("__merged_" + operation_name)
  1123. // Add tracability links at this level
  1124. while (set_len(all_formalisms) > 0):
  1125. source_formalism_id = set_pop(all_formalisms)
  1126. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1127. instantiate_attribute(core, tracability_link, "type", "merged")
  1128. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1129. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1130. // Extend metadata with info on source and target
  1131. String link
  1132. String dst
  1133. keys = dict_keys(source)
  1134. while (set_len(keys) > 0):
  1135. key = set_pop(keys)
  1136. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1137. instantiate_attribute(core, link, "name", key)
  1138. keys = dict_keys(target)
  1139. while (set_len(keys) > 0):
  1140. key = set_pop(keys)
  1141. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1142. instantiate_attribute(core, link, "name", key)
  1143. return "Success"!
  1144. else:
  1145. return "Model exists: " + operation_name!
  1146. String function cmd_transformation_add_MT(user_id : String, source_models : Element, target_models : Element, operation_name : String):
  1147. // Add a model transformation model
  1148. // Just a usual model instantiation, but need to add the source and target links based on user info
  1149. String ramified_metamodel_id
  1150. Element ramified_metamodel
  1151. String model_id
  1152. Element models
  1153. Element links
  1154. String link_id
  1155. Element supported
  1156. Element source
  1157. Element target
  1158. String name
  1159. String new_model_id
  1160. String merged_link_id
  1161. Element links_merged
  1162. String merged_formalism
  1163. Element keys
  1164. String key
  1165. Element mm
  1166. Element to_ramify
  1167. String source_formalism_id
  1168. String merged_formalism_id
  1169. String tracability_link
  1170. source = dict_create()
  1171. target = dict_create()
  1172. to_ramify = set_create()
  1173. keys = dict_keys(source_models)
  1174. while (set_len(keys) > 0):
  1175. key = set_pop(keys)
  1176. name = source_models[key]
  1177. model_id = get_entry_id(name)
  1178. if (model_id != ""):
  1179. if (allow_read(user_id, name)):
  1180. // Check whether or not it is SimpleClassDiagrams
  1181. if (is_typed_by(model_id, get_entry_id("SimpleClassDiagrams"))):
  1182. if (bool_not(dict_in(source, key))):
  1183. dict_add(source, key, model_id)
  1184. mm = get_full_model(model_id, get_entry_id("SimpleClassDiagrams"))
  1185. if (element_eq(mm, read_root())):
  1186. return "ModelTransformation source type not in SimpleClassDiagrams hierarchy: " + name!
  1187. set_add_node(to_ramify, create_tuple(key, mm))
  1188. else:
  1189. return "Name was already assigned a metamodel: " + key!
  1190. else:
  1191. return "Model not supported for RAMification: " + name!
  1192. else:
  1193. return "Permission denied: " + name!
  1194. else:
  1195. return "Model not found: " + name!
  1196. keys = dict_keys(target_models)
  1197. while (set_len(keys) > 0):
  1198. key = set_pop(keys)
  1199. name = target_models[key]
  1200. model_id = get_entry_id(name)
  1201. if (model_id != ""):
  1202. if (allow_read(user_id, name)):
  1203. if (is_typed_by(model_id, get_entry_id("SimpleClassDiagrams"))):
  1204. if (bool_not(dict_in(target, key))):
  1205. if (dict_in(source, key)):
  1206. if (value_eq(model_id, source[key])):
  1207. dict_add(target, key, model_id)
  1208. // Don't add to to_ramify, as it is already in there!
  1209. else:
  1210. return "Name in output cannot have different type than input: " + key!
  1211. else:
  1212. dict_add(target, key, model_id)
  1213. mm = get_full_model(model_id, get_entry_id("SimpleClassDiagrams"))
  1214. if (element_eq(mm, read_root())):
  1215. return "ModelTransformation target type not in SimpleClassDiagrams hierarchy: " + name!
  1216. set_add_node(to_ramify, create_tuple(key, mm))
  1217. else:
  1218. return "Name was already assigned a metamodel: " + key!
  1219. else:
  1220. return "Model not supported for RAMification: " + name!
  1221. else:
  1222. return "Permission denied: " + name!
  1223. else:
  1224. return "Model not found: " + name!
  1225. merged_formalism = model_fuse(to_ramify)
  1226. modify(merged_formalism, True)
  1227. ramified_metamodel = ramify(merged_formalism)
  1228. model_create(ramified_metamodel, "__RAM_" + operation_name, user_id, get_entry_id("SimpleClassDiagrams"), "Model")
  1229. ramified_metamodel_id = get_entry_id("__RAM_" + operation_name)
  1230. // Now use the RAMified model to create the instance
  1231. if (get_entry_id(operation_name) == ""):
  1232. String new_model
  1233. // Finished with all information, now create the model itself!
  1234. output("Waiting for model constructors...")
  1235. new_model = construct_model_raw(get_full_model(ramified_metamodel_id, get_entry_id("SimpleClassDiagrams")))
  1236. model_create(new_model, operation_name, user_id, ramified_metamodel_id, "ModelTransformation")
  1237. model_id = get_entry_id(operation_name)
  1238. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1239. // New location is available, so write
  1240. model_create(merged_formalism, "__merged_" + operation_name, user_id, get_entry_id("SimpleClassDiagrams"), "Model")
  1241. merged_formalism_id = get_entry_id("__merged_" + operation_name)
  1242. // Add tracability links at this level
  1243. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1244. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1245. // Add tracability links at this level
  1246. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1247. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1248. // Extend metadata with info on source and target
  1249. String link
  1250. String dst
  1251. keys = dict_keys(source)
  1252. while (set_len(keys) > 0):
  1253. key = set_pop(keys)
  1254. dst = source[key]
  1255. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1256. instantiate_attribute(core, link, "name", key)
  1257. keys = dict_keys(target)
  1258. while (set_len(keys) > 0):
  1259. key = set_pop(keys)
  1260. dst = target[key]
  1261. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1262. instantiate_attribute(core, link, "name", key)
  1263. return "Success"!
  1264. else:
  1265. return "Model exists: " + operation_name!
  1266. String function cmd_permission_modify(user_id : String, model_name : String, permissions : String):
  1267. Integer permission
  1268. String model_id
  1269. model_id = get_entry_id(model_name)
  1270. if (model_id != ""):
  1271. if (get_relation_to_model(user_id, model_id) == 0):
  1272. Boolean fail
  1273. Integer i
  1274. i = 0
  1275. if (string_len(permissions) != 3):
  1276. fail = True
  1277. while (i < 3):
  1278. permission = cast_s2i(string_get(permissions, i))
  1279. if (bool_or(permission < 0, permission > 2)):
  1280. fail = True
  1281. break!
  1282. i = i + 1
  1283. if (bool_not(fail)):
  1284. unset_attribute(core, model_id, "permissions")
  1285. instantiate_attribute(core, model_id, "permissions", permissions)
  1286. return "Success"!
  1287. else:
  1288. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1289. else:
  1290. return "Permission denied to model: " + model_name!
  1291. else:
  1292. return "Model not found: " + model_name!
  1293. String function cmd_permission_owner(user_id : String, model_name : String, new_user_name : String):
  1294. String model_id
  1295. String new_user_id
  1296. model_id = get_entry_id(model_name)
  1297. if (model_id != ""):
  1298. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1299. new_user_id = get_user_id(new_user_name)
  1300. if (new_user_id != ""):
  1301. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1302. instantiate_link(core, "owner", "", model_id, new_user_id)
  1303. return "Success"!
  1304. else:
  1305. return "No such user: " + new_user_name!
  1306. else:
  1307. return "Permission denied to model: " + model_name!
  1308. else:
  1309. return "Model not found: " + model_name!
  1310. String function cmd_permission_group(user_id : String, model_name : String, new_group_name : String):
  1311. String model_id
  1312. String group_id
  1313. model_id = get_entry_id(model_name)
  1314. if (model_id != ""):
  1315. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1316. group_id = get_group_id(new_group_name)
  1317. if (group_id != ""):
  1318. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1319. instantiate_link(core, "group", "", model_id, group_id)
  1320. return "Success"!
  1321. else:
  1322. return "No such group: " + new_group_name!
  1323. else:
  1324. return "Permission denied to model: " + model_name!
  1325. else:
  1326. return "Model not found: " + model_name!
  1327. String function cmd_group_create(user_id : String, group_name : String):
  1328. // Create a new group and become its owner
  1329. String group_id
  1330. String name
  1331. group_id = get_group_id(group_name)
  1332. if (group_id == ""):
  1333. group_id = instantiate_node(core, "Group", "")
  1334. instantiate_attribute(core, group_id, "name", group_name)
  1335. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1336. instantiate_link(core, "owner", "", group_id, user_id)
  1337. return "Success"!
  1338. else:
  1339. return "Group exists: " + group_name!
  1340. String function cmd_group_delete(user_id : String, group_name : String):
  1341. // Delete an existing group
  1342. String group_id
  1343. group_id = get_group_id(group_name)
  1344. if (group_id != ""):
  1345. if (allow_group_modify(user_id, group_id)):
  1346. model_delete_element(core, group_id)
  1347. return "Success"!
  1348. else:
  1349. return "Permission denied to group: " + group_name!
  1350. else:
  1351. return "Group not found: " + group_name!
  1352. String function cmd_group_owner_add(user_id : String, group_name : String, other_user_name : String):
  1353. // Add an owner to your group
  1354. String group_id
  1355. String other_user_id
  1356. group_id = get_group_id(group_name)
  1357. if (group_id != ""):
  1358. if (allow_group_modify(user_id, group_id)):
  1359. other_user_id = get_user_id(other_user_name)
  1360. if (other_user_id != ""):
  1361. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1362. instantiate_link(core, "owner", "", group_id, other_user_id)
  1363. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1364. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1365. return "Success"!
  1366. else:
  1367. return "User is already the owner!"!
  1368. else:
  1369. return "User not found: " + other_user_name!
  1370. else:
  1371. return "Permission denied to group: " + group_name!
  1372. else:
  1373. return "Group not found: " + group_name!
  1374. String function cmd_group_owner_delete(user_id : String, group_name : String, other_user_name : String):
  1375. // Remove an owner from your group
  1376. String group_id
  1377. String other_user_id
  1378. group_id = get_group_id(group_name)
  1379. if (group_id != ""):
  1380. if (allow_group_modify(user_id, group_id)):
  1381. other_user_id = get_user_id(other_user_name)
  1382. if (other_user_id != ""):
  1383. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1384. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1385. Element overlap
  1386. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1387. model_delete_element(core, set_pop(overlap))
  1388. return "Success"!
  1389. else:
  1390. return "User is not an owner of the group!"!
  1391. else:
  1392. return "User is not a member of the group!"!
  1393. else:
  1394. return "User not found: " + other_user_name!
  1395. else:
  1396. return "Permission denied to group: " + group_name!
  1397. else:
  1398. return "Group not found: " + group_name!
  1399. String function cmd_group_join(user_id : String, group_name : String, other_user_name : String):
  1400. // Add someone to your group
  1401. String group_id
  1402. String other_user_id
  1403. group_id = get_group_id(group_name)
  1404. if (group_id != ""):
  1405. if (allow_group_modify(user_id, group_id)):
  1406. other_user_id = get_user_id(other_user_name)
  1407. if (other_user_id != ""):
  1408. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1409. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1410. return "Success"!
  1411. else:
  1412. return "User is already a member of the group!"!
  1413. else:
  1414. return "User not found: " + other_user_name!
  1415. else:
  1416. return "Permission denied to group: " + group_name!
  1417. else:
  1418. return "Group not found: " + group_name!
  1419. String function cmd_group_kick(user_id : String, group_name : String, other_user_name : String):
  1420. // Remove someone from your group
  1421. String group_id
  1422. String other_user_id
  1423. group_id = get_group_id(group_name)
  1424. if (group_id != ""):
  1425. if (allow_group_modify(user_id, group_id)):
  1426. other_user_id = get_user_id(other_user_name)
  1427. if (other_user_id != ""):
  1428. Element overlap
  1429. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1430. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1431. model_delete_element(core,set_pop(overlap))
  1432. // Check if user was an owner as well
  1433. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1434. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1435. model_delete_element(core, set_pop(overlap))
  1436. return "Success"!
  1437. else:
  1438. return "User is not a member of the group!"!
  1439. else:
  1440. return "User not found: " + other_user_name!
  1441. else:
  1442. return "Permission denied to group: " + group_name!
  1443. else:
  1444. return "Group not found: " + group_name!
  1445. String function cmd_group_list(user_id : String):
  1446. // List all groups you are a member of (and whether you are admin or not!)
  1447. Element groups
  1448. String group_id
  1449. String admin
  1450. String result
  1451. result = ""
  1452. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1453. while (set_len(groups) > 0):
  1454. group_id = set_pop(groups)
  1455. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  1456. admin = " A "
  1457. else:
  1458. admin = " "
  1459. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1460. return result!
  1461. String function cmd_admin_promote(user_id : String, other_user_name : String):
  1462. // Promote a user to admin status
  1463. if (is_admin(user_id)):
  1464. String other_user_id
  1465. other_user_id = get_user_id(other_user_name)
  1466. if (other_user_id != ""):
  1467. unset_attribute(core, other_user_id, "admin")
  1468. instantiate_attribute(core, other_user_id, "admin", True)
  1469. return "Success"!
  1470. else:
  1471. return "User not found: " + other_user_name!
  1472. else:
  1473. return "Permission denied to administrate: " + other_user_name!
  1474. String function cmd_admin_demote(user_id : String, other_user_name : String):
  1475. // Demote a user to normal status
  1476. if (is_admin(user_id)):
  1477. String other_user_id
  1478. other_user_id = get_user_id(other_user_name)
  1479. if (other_user_id != ""):
  1480. unset_attribute(core, other_user_id, "admin")
  1481. instantiate_attribute(core, other_user_id, "admin", False)
  1482. return "Success"!
  1483. else:
  1484. return "User not found: " + other_user_name!
  1485. else:
  1486. return "Permission denied to administrate: " + other_user_name!
  1487. String function cmd_service_register(user_id : String, service_name : String):
  1488. // Active a service for this specific user
  1489. if (get_service_id(service_name) == ""):
  1490. String service
  1491. service = instantiate_node(core, "Service", "")
  1492. instantiate_attribute(core, service, "name", service_name)
  1493. instantiate_attribute(core, service, "port", get_taskname())
  1494. output("Success: " + get_taskname())
  1495. // Wait until we can stop the service
  1496. log("Waiting for service_stop")
  1497. while (cast_v2s(input()) != "\"service_stop\""):
  1498. output("Service is running on this task: stop it by sending 'service_stop'")
  1499. log("Finished")
  1500. model_delete_element(core, service)
  1501. // Service terminated
  1502. return "Success"!
  1503. else:
  1504. return "Service already exists: " + service_name!
  1505. String function cmd_user_password(user_id : String, user_name : String, new_password : String):
  1506. if (bool_or(user_id == get_user_id(user_name), is_admin(user_id))):
  1507. if (get_user_id(user_name) != ""):
  1508. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1509. return "Success"!
  1510. else:
  1511. return "No such user: " + user_name!
  1512. else:
  1513. return "Permission denied to user: " + user_name!
  1514. String function cmd_transformation_signature(user_id : String, transformation_name : String):
  1515. String model_id
  1516. model_id = get_entry_id(transformation_name)
  1517. if (model_id != ""):
  1518. if (is_nominal_instance(core, model_id, "Transformation")):
  1519. if (allow_read(user_id, transformation_name)):
  1520. String result
  1521. String elem
  1522. Element inputs
  1523. Element outputs
  1524. result = "Success: "
  1525. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1526. while (set_len(inputs) > 0):
  1527. elem = set_pop(inputs)
  1528. result = string_join(string_join(string_join(string_join("I ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1529. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1530. while (set_len(outputs) > 0):
  1531. elem = set_pop(outputs)
  1532. result = string_join(string_join(string_join(string_join("O ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1533. return result!
  1534. else:
  1535. return "Permission denied to operation: " + transformation_name!
  1536. else:
  1537. return "Model is not an operation: " + transformation_name!
  1538. else:
  1539. return "No such operation: " + transformation_name!
  1540. String function cmd_element_list_nice(user_id : String, model_name : String, metamodel_name : String):
  1541. if (get_entry_id(model_name) != ""):
  1542. if (allow_read(user_id, get_entry_id(model_name))):
  1543. Element mm
  1544. mm = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  1545. if (element_eq(mm, read_root())):
  1546. return "No conformance relation between these models"!
  1547. return "Success: " + JSON_print(mm)!
  1548. else:
  1549. return "Permission denied to model: " + model_name!
  1550. else:
  1551. return "No such model: " + model_name!
  1552. Void function user_function_skip_init(user_id : String):
  1553. String cmd
  1554. String result
  1555. caches = dict_create()
  1556. dict_add_fast(caches, "models", dict_create())
  1557. dict_add_fast(caches, "users", dict_create())
  1558. dict_add_fast(caches, "full_name", dict_create())
  1559. // Find root element
  1560. Element elems
  1561. String elem
  1562. elems = allInstances(core, "Folder")
  1563. while (set_len(elems) > 0):
  1564. elem = set_pop(elems)
  1565. if (value_eq(read_attribute(core, elem, "name"), "")):
  1566. if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
  1567. dict_add_fast(caches["models"], "", dict_create())
  1568. dict_add_fast(caches["models"][""], "", elem)
  1569. break!
  1570. output("Welcome to the Model Management Interface v2.0!")
  1571. output("Use the 'help' command for a list of possible commands")
  1572. while (True):
  1573. cmd = input()
  1574. if (cmd == "help"):
  1575. output(cmd_help(user_id))
  1576. elif (cmd == "model_add"):
  1577. output(cmd_model_add(user_id, single_input("Model type?"), single_input("Model name?")))
  1578. elif (cmd == "process_execute"):
  1579. output(cmd_process_execute(user_id, single_input("Process to execute?"), single_input("Model prefix to use?")))
  1580. elif (cmd == "transformation_between"):
  1581. output(cmd_transformation_between(user_id, single_input("Source type?"), single_input("Target type?")))
  1582. elif (cmd == "model_render"):
  1583. output(cmd_model_render(user_id, single_input("Model name?"), single_input("Mapper name?")))
  1584. elif (cmd == "transformation_execute"):
  1585. output(cmd_transformation_execute(user_id, single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
  1586. elif (cmd == "verify"):
  1587. result = cmd_verify(user_id, single_input("Model name?"), single_input("Metamodel name?"))
  1588. if (result != ""):
  1589. output(result)
  1590. elif (cmd == "model_overwrite"):
  1591. output(cmd_model_overwrite(user_id, single_input("Model name?"), single_input("Metamodel name?")))
  1592. elif (cmd == "model_modify"):
  1593. output(cmd_model_modify(user_id, single_input("Model name?"), single_input("Metamodel name?")))
  1594. elif (cmd == "model_delete"):
  1595. output(cmd_model_delete(user_id, single_input("Model name?")))
  1596. elif (cmd == "model_list"):
  1597. output(cmd_model_list(single_input("Location?")))
  1598. elif (cmd == "model_list_full"):
  1599. output(cmd_model_list_full(single_input("Location?")))
  1600. elif (cmd == "transformation_add_MANUAL"):
  1601. output(cmd_transformation_add_MANUAL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
  1602. elif (cmd == "transformation_add_AL"):
  1603. output(cmd_transformation_add_AL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
  1604. elif (cmd == "transformation_add_MT"):
  1605. output(cmd_transformation_add_MT(user_id, dict_input("Source model names?"), dict_input("Target models?"), single_input("Operation name?")))
  1606. elif (cmd == "permission_modify"):
  1607. output(cmd_permission_modify(user_id, single_input("Model name?"), single_input("Permissions?")))
  1608. elif (cmd == "permission_owner"):
  1609. output(cmd_permission_owner(user_id, single_input("Model name?"), single_input("New owning user?")))
  1610. elif (cmd == "permission_group"):
  1611. output(cmd_permission_group(user_id, single_input("Model name?"), single_input("New owning group?")))
  1612. elif (cmd == "group_create"):
  1613. output(cmd_group_create(user_id, single_input("New group name?")))
  1614. elif (cmd == "group_delete"):
  1615. output(cmd_group_delete(user_id, single_input("Group name?")))
  1616. elif (cmd == "group_owner_add"):
  1617. output(cmd_group_owner_add(user_id, single_input("Group name?"), single_input("User name?")))
  1618. elif (cmd == "group_owner_delete"):
  1619. output(cmd_group_owner_delete(user_id, single_input("Group name?"), single_input("User name?")))
  1620. elif (cmd == "group_join"):
  1621. output(cmd_group_join(user_id, single_input("Group name?"), single_input("User name?")))
  1622. elif (cmd == "group_kick"):
  1623. output(cmd_group_kick(user_id, single_input("Group name?"), single_input("User name?")))
  1624. elif (cmd == "group_list"):
  1625. output(cmd_group_list(user_id))
  1626. elif (cmd == "admin_promote"):
  1627. output(cmd_admin_promote(user_id, single_input("User name?")))
  1628. elif (cmd == "admin_demote"):
  1629. output(cmd_admin_demote(user_id, single_input("User name?")))
  1630. elif (cmd == "service_register"):
  1631. output(cmd_service_register(user_id, single_input("Service name?")))
  1632. elif (cmd == "user_password"):
  1633. output(cmd_user_password(user_id, single_input("User name?"), single_input("New password?")))
  1634. elif (cmd == "transformation_read_signature"):
  1635. output(cmd_transformation_signature(user_id, single_input("Transformation name?")))
  1636. elif (cmd == "element_list_nice"):
  1637. output(cmd_element_list_nice(user_id, single_input("Model name?"), single_input("Metamodel name?")))
  1638. elif (cmd == "verbose"):
  1639. set_verbose(True)
  1640. elif (cmd == "quiet"):
  1641. set_verbose(False)
  1642. elif (cmd == "self-destruct"):
  1643. // Delete user from Core Formalism
  1644. model_delete_element(core, user_id)
  1645. return !
  1646. elif (cmd == "exit"):
  1647. // Exit by actually removing the user and decoupling it from all of its models
  1648. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1649. // as the current user will have been deleted
  1650. return !
  1651. elif (cmd == "add_conformance"):
  1652. // TODO
  1653. cmd = "FAIL"
  1654. elif (cmd == "remove_conformance"):
  1655. // TODO
  1656. cmd = "FAIL"
  1657. elif (cmd == "user_name"):
  1658. // TODO
  1659. cmd = "FAIL"
  1660. elif (cmd == "service_poll"):
  1661. // TODO
  1662. cmd = "FAIL"
  1663. else:
  1664. output("Unknown command: " + cmd)
  1665. // We never get here!
  1666. return !