core_algorithm.alc 69 KB

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