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