core_algorithm.alc 69 KB

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