core_algorithm.alc 65 KB

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