core_algorithm.alc 68 KB

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