core_algorithm.alc 65 KB

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