core_algorithm.alc 69 KB

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