core_algorithm.alc 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  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. while (read_nr_out(input_keys) > 0):
  529. key = set_pop(input_keys)
  530. model_join(merged_model, get_full_model(get_model_id(inputs[key])), string_join(types[key], "/"))
  531. // 3) Transform
  532. output("Please perform manual transformation " + cast_v2s(read_attribute(pm, element, "name")))
  533. modify(merged_model, True)
  534. // 4) Split in different files depending on type
  535. String desired_metamodel_id
  536. Element split_off_model
  537. output_keys = dict_keys(outputs)
  538. while (read_nr_out(output_keys) > 0):
  539. key = set_pop(output_keys)
  540. desired_metamodel_id = get_model_id(key)
  541. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  542. // Check if the destination model already exists
  543. if (get_model_id(outputs[key]) == ""):
  544. // New model
  545. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  546. else:
  547. // Model exists, so we overwrite
  548. model_overwrite(split_off_model, get_model_id(outputs[key]))
  549. else:
  550. output("Could not find merged metamodel")
  551. // TODO find out whether it succeeded or not
  552. result = True
  553. else:
  554. output("Did not know how to interpret model of type " + exact_type)
  555. return result!
  556. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  557. Element worklist
  558. String element
  559. String start
  560. String type
  561. Boolean result
  562. Element tuple
  563. Element counters
  564. Element join_nodes
  565. // Initialize Join counters
  566. counters = create_node()
  567. join_nodes = allInstances(pm, "ForkJoin")
  568. while (read_nr_out(join_nodes) > 0):
  569. dict_add(counters, set_pop(join_nodes), 0)
  570. // Create the worklist with the Start instance as first element
  571. worklist = create_node()
  572. set_add(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  573. while (bool_not(pm_finished(worklist, pm))):
  574. // Pop a random element from the list and execute it
  575. tuple = set_pop(worklist)
  576. element = tuple[0]
  577. result = tuple[1]
  578. log("Enacting " + cast_v2s(element))
  579. // Find the type (to see what to do with it)
  580. // this does not yet yield the type of transformation, if it is an Execution
  581. type = read_type(pm, element)
  582. if (type == "Start"):
  583. // Initial node, just progress to the next elements
  584. // Nothing to do here though, as we have just started
  585. result = True
  586. elif (type == "Finish"):
  587. // Should be impossible, as we would have ended...
  588. result = result
  589. elif (type == "ForkJoin"):
  590. // Only do this if all dependencies are fullfilled
  591. // So add to the counter of this Join
  592. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  593. // Now check whether we have enough tokens to execute the Join itself
  594. Integer required
  595. Integer got
  596. required = read_nr_out(allIncomingAssociationInstances(pm, element, "Next")) + read_nr_out(allIncomingAssociationInstances(pm, element, "Else"))
  597. got = counters[element]
  598. if (got == required):
  599. // Reset counter to 0
  600. dict_overwrite(counters, element, 0)
  601. // And continue
  602. else:
  603. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  604. continue!
  605. elif (type == "Exec"):
  606. // Execute a transformation
  607. // This the difficult part!
  608. result = enact_action(pm, element, prefix, user_id)
  609. elif (type == "Decision"):
  610. // If the previous result is true, we add the normal one, otherwise the false one
  611. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  612. if (bool_not(result)):
  613. // Apparently it is False, so map this to the "Else" branch
  614. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  615. continue!
  616. else:
  617. // Apparently it is True, so map this to the "Then" branch
  618. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  619. continue!
  620. // We have finished the execution, so add all outgoing edges to the worklist
  621. Element all_next
  622. all_next = allAssociationDestinations(pm, element, "Next")
  623. String next
  624. while (read_nr_out(all_next) > 0):
  625. next = set_pop(all_next)
  626. log("Adding to worklist: " + next)
  627. set_add(worklist, create_tuple(next, result))
  628. log("FINISHED")
  629. // Reached a finish element, so stop
  630. return !
  631. Void function user_function_skip_init(user_id : String):
  632. String cmd
  633. output("Welcome to the Model Management Interface v2.0!")
  634. output("Use the 'help' command for a list of possible commands")
  635. while (True):
  636. output("Ready for command...")
  637. cmd = input()
  638. if (cmd == "help"):
  639. output("Model operations")
  640. output(" model_add -- Add a new model")
  641. output(" model_modify -- Modify an existing model")
  642. output(" model_list -- List all models")
  643. output(" model_list_full -- List all models with full info")
  644. output(" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata")
  645. output(" verify -- Check whether a model conforms to its metamodel")
  646. output("")
  647. output("Transformation-specific operations")
  648. output(" transformation_add_MT_language -- Create a RAMified metamodel of a set of models")
  649. output(" transformation_add_MT -- Initialize a new model transformation")
  650. output(" transformation_add_AL -- Initialize a new action language transformation")
  651. output(" transformation_add_MANUAL -- Initialize a new manual transformation")
  652. output(" transformation_execute -- Execute a transformation on a set of input models")
  653. output(" transformation_list -- List all model transformations")
  654. output(" transformation_list_full -- List all model transformations with permissions")
  655. output(" transformation_detail -- List transformation details")
  656. output(" transformation_RAMify -- RAMify a metamodel (again)")
  657. output("")
  658. output("Process operations")
  659. output(" process_execute -- Execute a process model")
  660. output("")
  661. output("Model permission operations")
  662. output(" permission_modify -- Change model permissions")
  663. output(" permission_owner -- Change model owner")
  664. output(" permission_group -- Change model group")
  665. output("")
  666. output("Group operations")
  667. output(" group_create -- Create a group")
  668. output(" group_delete -- Delete a group")
  669. output(" group_owner_add -- Add group owner")
  670. output(" group_owner_delete -- Remove group owner")
  671. output(" group_join -- Add someone to your group")
  672. output(" group_kick -- Kick someone from your group")
  673. output(" group_list -- List all groups you are a member of")
  674. output("")
  675. output("Admin operations")
  676. output(" admin_promote -- Promote a user to admin status")
  677. output(" admin_demote -- Demote a user to normal status")
  678. output("")
  679. output("General operations")
  680. output(" self-destruct -- Remove current user and revoke all permissions ")
  681. output(" exit -- Kill the current task, while retaining user")
  682. elif (cmd == "model_add"):
  683. // Model addition operation, which uses model upload commands of the compiler
  684. String name
  685. String type
  686. String location
  687. String type_id
  688. Element new_model
  689. String new_model_id
  690. output("Creating new model!")
  691. output("Model type?")
  692. type_id = get_model_id(input())
  693. if (type_id != ""):
  694. // Type exists
  695. if (allow_read(user_id, type_id)):
  696. // And is readable
  697. output("Model name?")
  698. name = input()
  699. if (get_model_id(name) == ""):
  700. // Model doesn't exist yet
  701. output("Waiting for model constructors...")
  702. new_model = construct_model_raw(get_full_model(type_id))
  703. model_create(new_model, name, user_id, type_id, "Model")
  704. output("Model upload success!")
  705. else:
  706. output("Model with that name already exists!")
  707. else:
  708. output("Permission denied")
  709. else:
  710. output("Could not find type model!")
  711. elif (cmd == "process_execute"):
  712. // Execute a process model until it reaches termination
  713. String process_id
  714. output("Which process model do you want to execute?")
  715. process_id = get_model_id(input())
  716. if (process_id != ""):
  717. if (allow_read(user_id, process_id)):
  718. output("Model prefix to use?")
  719. enact_PM(get_full_model(process_id), input(), user_id)
  720. else:
  721. output("Permission denied")
  722. else:
  723. output("No such model")
  724. elif (cmd == "transformation_execute"):
  725. // Execute a transformation, whatever type it is
  726. // First we detect the type, so we know how to prepare for invocation
  727. String transformation_id
  728. String exact_type
  729. Element sources
  730. Element targets
  731. String source
  732. String target
  733. String name_id
  734. Element inputs
  735. Element outputs
  736. Element trace_links
  737. String target_model_name
  738. String source_model_name
  739. output("Which transformation do you want to execute?")
  740. transformation_id = get_model_id(input())
  741. if (transformation_id != ""):
  742. if (allow_read(user_id, transformation_id)):
  743. if (is_nominal_instance(core, transformation_id, "Transformation")):
  744. // Read out source and target links
  745. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  746. inputs = create_node()
  747. while (read_nr_out(sources) > 0):
  748. source = set_pop(sources)
  749. output(string_join("Which model to bind for source element ", read_attribute(core, source, "name")))
  750. source_model_name = input()
  751. name_id = get_model_id(source_model_name)
  752. if (name_id != ""):
  753. if (allow_read(user_id, name_id)):
  754. // Check for conformance to the specified metamodel!
  755. Element specified_model
  756. // TODO Maybe find out which conformance relation to use, as there might be multiple!
  757. if (check_is_typed_by(name_id, source)):
  758. if (check_conformance(name_id)):
  759. dict_add(inputs, read_attribute(core, source, "name"), source_model_name)
  760. else:
  761. output("Model has correct type but does not conform completely!")
  762. set_add(sources, source)
  763. else:
  764. output("Model has different type!")
  765. set_add(sources, source)
  766. else:
  767. output("Permission denied")
  768. set_add(sources, source)
  769. else:
  770. output("No such model")
  771. set_add(sources, source)
  772. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  773. outputs = create_node()
  774. while (read_nr_out(targets) > 0):
  775. target = set_pop(targets)
  776. output(string_join("Which model to create for target element ", read_attribute(core, target, "name")))
  777. target_model_name = input()
  778. if (get_model_id(target_model_name) == ""):
  779. // Doesn't exist yet, so we can easily create
  780. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  781. else:
  782. // Already exists, so we need to check for write access
  783. if (allow_write(user_id, get_model_id(target_model_name))):
  784. dict_add(outputs, read_attribute(core, target, "name"), target_model_name)
  785. else:
  786. output("Permission denied; try again")
  787. exact_type = read_type(core, transformation_id)
  788. if (exact_type == "ModelTransformation"):
  789. // Model transformation is always in-place and uses only a single metamodel
  790. // Therefore, we must:
  791. // 1) Create an empty model, instance of merged metamodel
  792. // 2) Merge the different source models and retype
  793. // 3) Perform the transformation on the merged model
  794. // 4) Split the resulting model based on the target formalisms
  795. //
  796. Element input_model
  797. Element schedule_model
  798. String trace_link_id
  799. Element merged_model
  800. String merged_metamodel_id
  801. String ramified_metamodel_id
  802. Boolean result
  803. schedule_model = get_full_model(transformation_id)
  804. // 1) Create empty instance of merged metamodel
  805. ramified_metamodel_id = set_pop(followAssociation(core, transformation_id, "instanceOf"))
  806. trace_links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  807. merged_metamodel_id = ""
  808. while (read_nr_out(trace_links) > 0):
  809. trace_link_id = set_pop(trace_links)
  810. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  811. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  812. if (merged_metamodel_id != ""):
  813. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  814. // 2) Merge source models
  815. String key
  816. Element keys
  817. Element input_keys
  818. Element output_keys
  819. input_keys = dict_keys(inputs)
  820. while (read_nr_out(input_keys) > 0):
  821. key = set_pop(input_keys)
  822. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  823. // 3) Transform
  824. result = transform(merged_model, schedule_model)
  825. output("Transformation executed with result: " + cast_v2s(result))
  826. // 4) Split in different files depending on type
  827. String desired_metamodel_id
  828. Element split_off_model
  829. output_keys = dict_keys(outputs)
  830. while (read_nr_out(output_keys) > 0):
  831. key = set_pop(output_keys)
  832. desired_metamodel_id = get_model_id(key)
  833. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  834. // Check if the destination model already exists
  835. if (get_model_id(outputs[key]) == ""):
  836. // New model
  837. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  838. else:
  839. // Model exists, so we overwrite
  840. model_overwrite(split_off_model, get_model_id(outputs[key]))
  841. else:
  842. output("Could not resolve intermediate merged metamodel")
  843. elif (exact_type == "ActionLanguage"):
  844. Element dictionary
  845. Element new_inputs
  846. Element input_keys
  847. Element output_keys
  848. Element result
  849. String key
  850. Element func
  851. // 1) Group source models in dictionary
  852. // --> This is just the "inputs" variable, but resolve all references
  853. new_inputs = create_node()
  854. input_keys = dict_keys(inputs)
  855. while (read_nr_out(input_keys) > 0):
  856. key = set_pop(input_keys)
  857. dict_add(new_inputs, key, get_full_model(get_model_id(inputs[key])))
  858. inputs = new_inputs
  859. // 2) Execute action language model
  860. func = get_func_AL_model(get_full_model(transformation_id))
  861. result = func(inputs)
  862. // 3) Split output dictionary back to seperate models
  863. output_keys = dict_keys(outputs)
  864. while (read_nr_out(output_keys) > 0):
  865. key = set_pop(output_keys)
  866. // Check if the destination model already exists
  867. if (get_model_id(outputs[key]) == ""):
  868. // New model
  869. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  870. else:
  871. // Model exists, so we overwrite
  872. model_overwrite(result[key], get_model_id(outputs[key]))
  873. elif (exact_type == "ManualOperation"):
  874. // Identical to model transformations, but give control to users for modification
  875. // 1) Create empty instance of merged metamodel
  876. Element input_model
  877. String trace_link_id
  878. Element merged_model
  879. String merged_metamodel_id
  880. trace_links = allOutgoingAssociationInstances(core, transformation_id, "tracability")
  881. merged_metamodel_id = ""
  882. while (read_nr_out(trace_links) > 0):
  883. trace_link_id = set_pop(trace_links)
  884. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  885. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  886. if (merged_metamodel_id != ""):
  887. merged_model = instantiate_model(get_full_model(merged_metamodel_id))
  888. // 2) Merge source models
  889. String key
  890. Element keys
  891. Element input_keys
  892. Element output_keys
  893. input_keys = dict_keys(inputs)
  894. while (read_nr_out(input_keys) > 0):
  895. key = set_pop(input_keys)
  896. model_join(merged_model, get_full_model(get_model_id(inputs[key])), key + "/")
  897. // 3) Transform
  898. modify(merged_model, True)
  899. // 4) Split in different files depending on type
  900. String desired_metamodel_id
  901. Element split_off_model
  902. output_keys = dict_keys(outputs)
  903. while (read_nr_out(output_keys) > 0):
  904. key = set_pop(output_keys)
  905. desired_metamodel_id = get_model_id(key)
  906. split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
  907. // Check if the destination model already exists
  908. if (get_model_id(outputs[key]) == ""):
  909. // New model
  910. model_create(split_off_model, outputs[key], user_id, desired_metamodel_id, "Model")
  911. else:
  912. // Model exists, so we overwrite
  913. model_overwrite(split_off_model, get_model_id(outputs[key]))
  914. else:
  915. output("Could not find merged metamodel")
  916. else:
  917. output("Did not know how to interpret model of type " + exact_type)
  918. else:
  919. output("Model is not an executable transformation")
  920. else:
  921. output("Permission denied")
  922. else:
  923. output("No such transformation")
  924. elif (cmd == "verify"):
  925. // Check whether a model conforms to its specification (with the selected type mapping)
  926. String model_id
  927. String result
  928. output("Which model to verify?")
  929. model_id = get_model_id(input())
  930. if (model_id != ""):
  931. if (allow_read(user_id, model_id)):
  932. result = conformance_scd(get_full_model(model_id))
  933. output(result)
  934. else:
  935. output("Permission denied")
  936. else:
  937. output("No such model")
  938. elif (cmd == "model_overwrite"):
  939. // Overwrites an existing model without changing any metadata
  940. String model_id
  941. Element new_model
  942. output("Which model to overwrite?")
  943. model_id = get_model_id(input())
  944. if (model_id != ""):
  945. if (allow_write(user_id, model_id)):
  946. if (allow_read(user_id, set_pop(followAssociation(core, model_id, "instanceOf")))):
  947. output("Waiting for model constructors...")
  948. new_model = construct_model_raw(get_full_model(set_pop(followAssociation(core, model_id, "instanceOf"))))
  949. model_overwrite(new_model, model_id)
  950. output("Model overwrite success!")
  951. else:
  952. output("Permission denied")
  953. else:
  954. output("Permission denied")
  955. else:
  956. output("No such model")
  957. elif (cmd == "model_modify"):
  958. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  959. String model_id
  960. String type_id
  961. output("Which model do you want to modify?")
  962. model_id = get_model_id(input())
  963. if (model_id != ""):
  964. if (allow_read(user_id, model_id)):
  965. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  966. if (allow_read(user_id, type_id)):
  967. modify(get_full_model(model_id), allow_write(user_id, model_id))
  968. else:
  969. output("Permission denied")
  970. else:
  971. output("Permission denied")
  972. else:
  973. output("Could not find model!")
  974. elif (cmd == "model_delete"):
  975. // Delete a model and all of its related transformations
  976. String model_id
  977. output("=================================================")
  978. output("WARNING: Deletion is a very destructive operation")
  979. output(" as it also deletes all transformations ")
  980. output(" defined which make use of this model! ")
  981. output("=================================================")
  982. output("")
  983. output("Currently not supported!")
  984. elif (cmd == "model_list"):
  985. // List all models
  986. Element models
  987. String m
  988. models = allInstances(core, "Model")
  989. while (read_nr_out(models) > 0):
  990. m = set_pop(models)
  991. output(string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(followAssociation(core, m, "instanceOf")), "name")))
  992. elif (cmd == "model_list_full"):
  993. // List all models with full info
  994. Element models
  995. String m
  996. String permissions
  997. String owner
  998. String group
  999. String name
  1000. String type
  1001. models = allInstances(core, "Model")
  1002. while (read_nr_out(models) > 0):
  1003. m = set_pop(models)
  1004. permissions = read_attribute(core, m, "permissions")
  1005. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1006. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1007. name = read_attribute(core, m, "name")
  1008. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1009. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)
  1010. elif (cmd == "transformation_add_MT_language"):
  1011. // Create a model transformation language from a set of input and output formalisms
  1012. String name
  1013. String model_id
  1014. Element source
  1015. Element target
  1016. Element all_formalisms
  1017. Element merged_formalism
  1018. Element ramified_formalism
  1019. String old_type_id
  1020. String type_id
  1021. String location
  1022. String new_model_id
  1023. old_type_id = ""
  1024. // Read involved formalisms
  1025. all_formalisms = create_node()
  1026. output("Formalisms to include (terminate with empty string)?")
  1027. name = input()
  1028. while (name != ""):
  1029. model_id = get_model_id(name)
  1030. if (model_id != ""):
  1031. if (allow_read(user_id, model_id)):
  1032. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1033. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1034. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1035. old_type_id = type_id
  1036. elif (old_type_id != type_id):
  1037. // Already have a previous type_id and now another: CLASH
  1038. output("Cannot add model as types not compatible with previous models; try again")
  1039. else:
  1040. output("Model not readable; try again")
  1041. else:
  1042. output("No such model; try again")
  1043. name = input()
  1044. // Merge all into a single metamodel
  1045. if (read_nr_out(all_formalisms) > 0):
  1046. output("Name of the RAMified transformation metamodel?")
  1047. name = input()
  1048. if (get_model_id(name) == ""):
  1049. String merged_formalism_id
  1050. String ramified_formalism_id
  1051. String source_formalism_id
  1052. String tracability_link
  1053. // New location is available, so write
  1054. merged_formalism = model_fuse(set_copy(all_formalisms))
  1055. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  1056. merged_formalism_id = get_model_id("__merged_" + name)
  1057. // Add tracability links at this level
  1058. while (read_nr_out(all_formalisms) > 0):
  1059. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1060. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1061. instantiate_attribute(core, tracability_link, "type", "merged")
  1062. // Merge complete, now RAMify!
  1063. ramified_formalism = ramify(merged_formalism)
  1064. model_create(ramified_formalism, name, user_id, type_id, "Model")
  1065. ramified_formalism_id = get_model_id(name)
  1066. // Add tracability link at this level
  1067. tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
  1068. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1069. else:
  1070. output("Model already exists!")
  1071. else:
  1072. output("At least one formalism is required")
  1073. elif (cmd == "transformation_RAMify"):
  1074. // RAMify a metamodel
  1075. String merged_model_id
  1076. String target_model_name
  1077. String target_model_id
  1078. Element target_model
  1079. String tracability_link
  1080. output("Which metamodel do you want to RAMify?")
  1081. merged_model_id = get_model_id(input())
  1082. if (merged_model_id != ""):
  1083. if (allow_read(user_id, merged_model_id)):
  1084. output("Where do you want to store the RAMified metamodel?")
  1085. target_model_name = input()
  1086. target_model_id = get_model_id(target_model_name)
  1087. if (target_model_id == ""):
  1088. // New model, so everything is fine
  1089. target_model = ramify(get_full_model(merged_model_id))
  1090. model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
  1091. target_model_id = get_model_id(target_model_name)
  1092. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1093. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1094. else:
  1095. // Existing model, so overwrite
  1096. if (allow_write(user_id, target_model_id)):
  1097. target_model = ramify(get_full_model(merged_model_id))
  1098. model_overwrite(target_model, target_model_id)
  1099. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
  1100. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1101. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1102. else:
  1103. output("Permission denied")
  1104. else:
  1105. output("Permission denied!")
  1106. else:
  1107. output("No such model")
  1108. elif (cmd == "transformation_add_MANUAL"):
  1109. // Add a manual transformation model
  1110. output("Which metamodels do you want to use as source for the manual operation (empty string to finish)?")
  1111. String model_id
  1112. Element models
  1113. Element source
  1114. Element target
  1115. String name
  1116. Element all_formalisms
  1117. Element merged_formalism
  1118. String merged_formalism_id
  1119. String source_formalism_id
  1120. String tracability_link
  1121. String type_id
  1122. String old_type_id
  1123. name = input()
  1124. source = create_node()
  1125. target = create_node()
  1126. all_formalisms = create_node()
  1127. type_id = ""
  1128. old_type_id = ""
  1129. while (name != ""):
  1130. model_id = get_model_id(name)
  1131. if (model_id != ""):
  1132. if (allow_read(user_id, model_id)):
  1133. if (bool_not(set_in(source, model_id))):
  1134. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1135. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1136. old_type_id = type_id
  1137. set_add(source, model_id)
  1138. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1139. output("Model added as source")
  1140. elif (old_type_id != type_id):
  1141. // Already have a previous type_id and now another: CLASH
  1142. output("Cannot add model as types not compatible with previous models; try again")
  1143. else:
  1144. output("Model already selected as source")
  1145. else:
  1146. output("Permission denied")
  1147. else:
  1148. output("No such model; try again")
  1149. name = input()
  1150. output("Which metamodels do you want to use as target for the manual operation (empty string to finish)?")
  1151. name = input()
  1152. while (name != ""):
  1153. model_id = get_model_id(name)
  1154. if (model_id != ""):
  1155. if (allow_read(user_id, model_id)):
  1156. if (bool_not(set_in(target, model_id))):
  1157. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1158. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1159. old_type_id = type_id
  1160. set_add(target, model_id)
  1161. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1162. output("Model added as target")
  1163. elif (old_type_id != type_id):
  1164. // Already have a previous type_id and now another: CLASH
  1165. output("Cannot add model as types not compatible with previous models; try again")
  1166. else:
  1167. output("Model already selected as target")
  1168. else:
  1169. output("Permission denied")
  1170. else:
  1171. output("No such model; try again")
  1172. name = input()
  1173. output("Name of Manual operation model?")
  1174. name = input()
  1175. if (get_model_id(name) == ""):
  1176. // Finished with all information, now create the model itself!
  1177. model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), name, user_id, get_model_id("ManualOperation"), "ManualOperation")
  1178. model_id = get_model_id(name)
  1179. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1180. // New location is available, so write
  1181. merged_formalism = model_fuse(set_copy(all_formalisms))
  1182. model_create(merged_formalism, "__merged_" + name, user_id, type_id, "Model")
  1183. merged_formalism_id = get_model_id("__merged_" + name)
  1184. // Add tracability links at this level
  1185. while (read_nr_out(all_formalisms) > 0):
  1186. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1187. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1188. instantiate_attribute(core, tracability_link, "type", "merged")
  1189. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1190. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1191. // Extend metadata with info on source and target
  1192. String link
  1193. String dst
  1194. while (read_nr_out(source) > 0):
  1195. dst = set_pop(source)
  1196. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1197. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1198. while (read_nr_out(target) > 0):
  1199. dst = set_pop(target)
  1200. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1201. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1202. else:
  1203. output("Model already exists")
  1204. elif (cmd == "transformation_add_AL"):
  1205. // Add an action language transformation model
  1206. output("Which metamodels do you want to use as source for the action code (empty string to finish)?")
  1207. String model_id
  1208. Element models
  1209. Element source
  1210. Element target
  1211. String name
  1212. name = input()
  1213. source = create_node()
  1214. target = create_node()
  1215. while (name != ""):
  1216. model_id = get_model_id(name)
  1217. if (model_id != ""):
  1218. if (bool_not(set_in(source, model_id))):
  1219. set_add(source, model_id)
  1220. output("Model added as source")
  1221. else:
  1222. output("Model already selected as source")
  1223. else:
  1224. output("No such model; try again")
  1225. name = input()
  1226. output("Which metamodels do you want to use as target for the action code (empty string to finish)?")
  1227. name = input()
  1228. while (name != ""):
  1229. model_id = get_model_id(name)
  1230. if (model_id != ""):
  1231. if (bool_not(set_in(target, model_id))):
  1232. set_add(target, model_id)
  1233. output("Model added as target")
  1234. else:
  1235. output("Model already selected as target")
  1236. else:
  1237. output("No such model; try again")
  1238. name = input()
  1239. output("Name of Action Language model?")
  1240. name = input()
  1241. if (get_model_id(name) == ""):
  1242. // Finished with all information, now create the model itself!
  1243. output("Waiting for model constructors...")
  1244. add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + name, construct_function())
  1245. model_create(import_node("AL/" + name), name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
  1246. model_id = get_model_id(name)
  1247. // Extend metadata with info on source and target
  1248. String link
  1249. String dst
  1250. while (read_nr_out(source) > 0):
  1251. dst = set_pop(source)
  1252. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1253. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1254. while (read_nr_out(target) > 0):
  1255. dst = set_pop(target)
  1256. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1257. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1258. else:
  1259. output("Model already exists")
  1260. elif (cmd == "transformation_add_MT"):
  1261. // Add a model transformation model
  1262. // Just a usual model instantiation, but need to add the source and target links based on user info
  1263. String ramified_metamodel_id
  1264. String model_id
  1265. Element models
  1266. Element links
  1267. String link_id
  1268. Element supported
  1269. Element source
  1270. Element target
  1271. String name
  1272. String new_model_id
  1273. String merged_link_id
  1274. Element links_merged
  1275. String merged_metamodel_id
  1276. source = create_node()
  1277. target = create_node()
  1278. supported = create_node()
  1279. output("RAMified metamodel to use?")
  1280. ramified_metamodel_id = get_model_id(input())
  1281. if (ramified_metamodel_id != ""):
  1282. if (allow_read(user_id, ramified_metamodel_id)):
  1283. output("Supported metamodels:")
  1284. links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  1285. while (read_nr_out(links) > 0):
  1286. link_id = set_pop(links)
  1287. merged_metamodel_id = readAssociationDestination(core, link_id)
  1288. if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
  1289. links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  1290. while (read_nr_out(links_merged) > 0):
  1291. merged_link_id = set_pop(links_merged)
  1292. if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
  1293. output(string_join(" ", read_attribute(core, readAssociationDestination(core, merged_link_id), "name")))
  1294. set_add(supported, readAssociationDestination(core, merged_link_id))
  1295. output("")
  1296. output("Which ones do you want to use as source (empty string to finish)?")
  1297. name = input()
  1298. while (name != ""):
  1299. model_id = get_model_id(name)
  1300. if (model_id != ""):
  1301. if (set_in(supported, model_id)):
  1302. if (bool_not(set_in(source, model_id))):
  1303. set_add(source, model_id)
  1304. output("Model added as source")
  1305. else:
  1306. output("Model already selected as source")
  1307. else:
  1308. output("Model is not supported by RAMified metamodel!")
  1309. else:
  1310. output("No such model; try again")
  1311. name = input()
  1312. output("Which ones do you want to use as target (empty string to finish)?")
  1313. name = input()
  1314. while (name != ""):
  1315. model_id = get_model_id(name)
  1316. if (model_id != ""):
  1317. if (set_in(supported, model_id)):
  1318. if (bool_not(set_in(target, model_id))):
  1319. set_add(target, model_id)
  1320. output("Model added as target")
  1321. else:
  1322. output("Model already selected as target")
  1323. else:
  1324. output("Model is not supported by RAMified metamodel!")
  1325. else:
  1326. output("No such model; try again")
  1327. name = input()
  1328. output("Name of new transformation?")
  1329. name = input()
  1330. if (get_model_id(name) == ""):
  1331. String new_model
  1332. // Finished with all information, now create the model itself!
  1333. output("Waiting for model constructors...")
  1334. new_model = construct_model_raw(get_full_model(ramified_metamodel_id))
  1335. model_create(new_model, name, user_id, ramified_metamodel_id, "ModelTransformation")
  1336. model_id = get_model_id(name)
  1337. // Extend metadata with info on source and target
  1338. String link
  1339. String dst
  1340. while (read_nr_out(source) > 0):
  1341. dst = set_pop(source)
  1342. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1343. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1344. while (read_nr_out(target) > 0):
  1345. dst = set_pop(target)
  1346. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1347. instantiate_attribute(core, link, "name", read_attribute(core, dst, "name"))
  1348. else:
  1349. output("Model already exists")
  1350. else:
  1351. output("Permission denied")
  1352. else:
  1353. output("No such model")
  1354. elif (cmd == "transformation_list"):
  1355. // List all models
  1356. Element models
  1357. String m
  1358. String type
  1359. models = allInstances(core, "Transformation")
  1360. while (read_nr_out(models) > 0):
  1361. m = set_pop(models)
  1362. 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"))))
  1363. elif (cmd == "transformation_list_full"):
  1364. // List all models with full info
  1365. Element models
  1366. String m
  1367. String permissions
  1368. String owner
  1369. String group
  1370. String name
  1371. String type
  1372. models = allInstances(core, "Transformation")
  1373. while (read_nr_out(models) > 0):
  1374. m = set_pop(models)
  1375. permissions = read_attribute(core, m, "permissions")
  1376. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1377. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1378. name = read_attribute(core, m, "name")
  1379. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1380. output(((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type)
  1381. elif (cmd == "permission_modify"):
  1382. String permissions
  1383. Integer permission
  1384. String model_id
  1385. output("Which model do you want to change permissions of?")
  1386. model_id = get_model_id(input())
  1387. if (model_id != ""):
  1388. if (get_relation_to_model(user_id, model_id) == 0):
  1389. output("New permissions?")
  1390. permissions = input()
  1391. Boolean fail
  1392. Integer i
  1393. i = 0
  1394. if (string_len(permissions) != 3):
  1395. fail = True
  1396. while (i < 3):
  1397. permission = cast_s2i(string_get(permissions, i))
  1398. if (bool_or(permission < 0, permission > 2)):
  1399. fail = True
  1400. break!
  1401. i = i + 1
  1402. if (bool_not(fail)):
  1403. unset_attribute(core, model_id, "permissions")
  1404. instantiate_attribute(core, model_id, "permissions", permissions)
  1405. else:
  1406. output("Permissions must be a string of three characters with each character being a digit between 0 and 2")
  1407. else:
  1408. output("Permission denied!")
  1409. else:
  1410. output("No such model!")
  1411. elif (cmd == "permission_owner"):
  1412. String permissions
  1413. String model_id
  1414. String user_id
  1415. output("Which model do you want to change owner of?")
  1416. model_id = get_model_id(input())
  1417. if (model_id != ""):
  1418. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1419. output("New owner?")
  1420. user_id = get_user_id(input())
  1421. if (user_id != ""):
  1422. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1423. instantiate_link(core, "owner", "", model_id, user_id)
  1424. else:
  1425. output("No such user!")
  1426. else:
  1427. output("Permission denied!")
  1428. else:
  1429. output("No such model!")
  1430. elif (cmd == "permission_group"):
  1431. String permissions
  1432. String model_id
  1433. String group_id
  1434. output("Which model do you want to change permissions of?")
  1435. model_id = get_model_id(input())
  1436. if (model_id != ""):
  1437. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1438. output("New group?")
  1439. group_id = get_group_id(input())
  1440. if (group_id != ""):
  1441. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1442. instantiate_link(core, "group", "", model_id, group_id)
  1443. else:
  1444. output("No such group!")
  1445. else:
  1446. output("Permission denied!")
  1447. else:
  1448. output("No such model!")
  1449. elif (cmd == "group_create"):
  1450. // Create a new group and become its owner
  1451. String group_id
  1452. String name
  1453. output("Which group do you want to create?")
  1454. name = input()
  1455. group_id = get_group_id(name)
  1456. if (group_id == ""):
  1457. group_id = instantiate_node(core, "Group", "")
  1458. instantiate_attribute(core, group_id, "name", name)
  1459. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1460. instantiate_link(core, "owner", "", group_id, user_id)
  1461. output("Group created!")
  1462. else:
  1463. output("Group already exists")
  1464. elif (cmd == "group_delete"):
  1465. // Delete an existing group
  1466. String group_id
  1467. String name
  1468. output("Which group do you want to delete?")
  1469. name = input()
  1470. group_id = get_group_id(name)
  1471. if (group_id != ""):
  1472. if (allow_group_modify(user_id, group_id)):
  1473. model_delete_element(core, group_id)
  1474. else:
  1475. output("Permission denied")
  1476. else:
  1477. output("No such group")
  1478. elif (cmd == "group_owner_add"):
  1479. // Add an owner to your group
  1480. String group_id
  1481. String other_user_id
  1482. output("Which group do you want to add an owner to?")
  1483. group_id = get_group_id(input())
  1484. if (group_id != ""):
  1485. if (allow_group_modify(user_id, group_id)):
  1486. output("Which user do you want to make an owner?")
  1487. other_user_id = get_user_id(input())
  1488. if (other_user_id != ""):
  1489. Element overlap
  1490. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1491. if (read_nr_out(overlap) == 0):
  1492. instantiate_link(core, "owner", "", group_id, other_user_id)
  1493. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1494. if (read_nr_out(overlap) == 0):
  1495. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1496. output("New owner added to group!")
  1497. else:
  1498. output("User is already an owner!")
  1499. else:
  1500. output("No such user")
  1501. else:
  1502. output("Permission denied!")
  1503. else:
  1504. output("No such group")
  1505. elif (cmd == "group_owner_delete"):
  1506. // Remove an owner from your group
  1507. String group_id
  1508. String other_user_id
  1509. output("Which group do you want to disown someone from?")
  1510. group_id = get_group_id(input())
  1511. if (group_id != ""):
  1512. if (allow_group_modify(user_id, group_id)):
  1513. output("Which user do you want to disown?")
  1514. other_user_id = get_user_id(input())
  1515. if (other_user_id != ""):
  1516. Element overlap
  1517. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1518. if (read_nr_out(overlap) > 0):
  1519. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1520. if (read_nr_out(overlap) > 0):
  1521. model_delete_element(core, set_pop(overlap))
  1522. output("Disowned group from user!")
  1523. else:
  1524. output("User is not even an owner of the group!")
  1525. else:
  1526. output("User is not even a member of the group!")
  1527. else:
  1528. output("No such user")
  1529. else:
  1530. output("Permission denied!")
  1531. else:
  1532. output("No such group")
  1533. elif (cmd == "group_join"):
  1534. // Add someone to your group
  1535. String group_id
  1536. String other_user_id
  1537. output("Which group do you want to add someone to?")
  1538. group_id = get_group_id(input())
  1539. if (group_id != ""):
  1540. if (allow_group_modify(user_id, group_id)):
  1541. output("Which user do you want to add?")
  1542. other_user_id = get_user_id(input())
  1543. if (other_user_id != ""):
  1544. Element overlap
  1545. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1546. if (read_nr_out(overlap) == 0):
  1547. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1548. output("User added to the group!")
  1549. else:
  1550. output("User is already a member of the group!")
  1551. else:
  1552. output("No such user")
  1553. else:
  1554. output("Permission denied!")
  1555. else:
  1556. output("No such group")
  1557. elif (cmd == "group_kick"):
  1558. // Remove someone from your group
  1559. String group_id
  1560. String other_user_id
  1561. output("Which group do you want to kick someone from?")
  1562. group_id = get_group_id(input())
  1563. if (group_id != ""):
  1564. if (allow_group_modify(user_id, group_id)):
  1565. output("Which user do you want to kick?")
  1566. other_user_id = get_user_id(input())
  1567. if (other_user_id != ""):
  1568. Element overlap
  1569. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1570. if (read_nr_out(overlap) > 0):
  1571. model_delete_element(core, set_pop(overlap))
  1572. // Check if user was an owner as well
  1573. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1574. if (read_nr_out(overlap) > 0):
  1575. model_delete_element(core, set_pop(overlap))
  1576. output("User kicked!")
  1577. else:
  1578. output("User is not even a member of the group!")
  1579. else:
  1580. output("No such user")
  1581. else:
  1582. output("Permission denied!")
  1583. else:
  1584. output("No such group")
  1585. elif (cmd == "group_list"):
  1586. // List all groups you are a member of (and whether you are admin or not!)
  1587. Element groups
  1588. String group_id
  1589. String admin
  1590. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1591. while (read_nr_out(groups) > 0):
  1592. group_id = set_pop(groups)
  1593. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  1594. admin = " A "
  1595. else:
  1596. admin = " "
  1597. output(string_join(admin, read_attribute(core, group_id, "name")))
  1598. elif (cmd == "admin_promote"):
  1599. // Promote a user to admin status
  1600. if (is_admin(user_id)):
  1601. String other_user_id
  1602. output("Which user do you want to promote?")
  1603. other_user_id = get_user_id(input())
  1604. if (other_user_id != ""):
  1605. unset_attribute(core, other_user_id, "admin")
  1606. instantiate_attribute(core, other_user_id, "admin", True)
  1607. output("Permissions granted!")
  1608. else:
  1609. output("No such user!")
  1610. else:
  1611. output("Permission denied!")
  1612. elif (cmd == "admin_demote"):
  1613. // Demote a user to normal status
  1614. if (is_admin(user_id)):
  1615. String other_user_id
  1616. output("Which user do you want to demote?")
  1617. other_user_id = get_user_id(input())
  1618. if (other_user_id != ""):
  1619. unset_attribute(core, other_user_id, "admin")
  1620. instantiate_attribute(core, other_user_id, "admin", False)
  1621. output("Permissions revoked!")
  1622. else:
  1623. output("No such user!")
  1624. else:
  1625. output("Permission denied!")
  1626. elif (cmd == "self-destruct"):
  1627. // Delete user from Core Formalism
  1628. model_delete_element(core, user_id)
  1629. return !
  1630. elif (cmd == "exit"):
  1631. // Exit by actually removing the user and decoupling it from all of its models
  1632. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1633. // as the current user will have been deleted
  1634. return !
  1635. else:
  1636. output("Unknown command: " + cmd)
  1637. // We never get here!
  1638. return !