core_algorithm.alc 62 KB

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