core_algorithm.alc 61 KB

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