core_algorithm.alc 57 KB

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