core_algorithm.alc 64 KB

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