core_algorithm.alc 58 KB

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