core_algorithm.alc 67 KB

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