core_algorithm.alc 68 KB

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