core_algorithm.alc 67 KB

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