core_algorithm.alc 64 KB

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