core_algorithm.alc 69 KB

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