core_algorithm.alc 66 KB

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