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