core_algorithm.alc 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  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. if read_type(core, transformation_id) == "ActionLanguage":
  525. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  526. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  527. elif read_type(core, transformation_id) == "ManualOperation":
  528. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  529. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  530. else:
  531. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  532. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  533. result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
  534. if (element_eq(result, read_root())):
  535. // Something went wrong!
  536. return False!
  537. else:
  538. keys = dict_keys(result)
  539. while (read_nr_out(keys) > 0):
  540. key = set_pop(keys)
  541. if (get_model_id(outputs[key]) == ""):
  542. // New model
  543. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  544. else:
  545. model_overwrite(result[key], get_model_id(outputs[key]))
  546. return True!
  547. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  548. Element worklist
  549. String element
  550. String start
  551. String type
  552. Boolean result
  553. Element tuple
  554. Element counters
  555. Element join_nodes
  556. output("Success")
  557. // Initialize Join counters
  558. counters = create_node()
  559. join_nodes = allInstances(pm, "Join")
  560. while (read_nr_out(join_nodes) > 0):
  561. dict_add(counters, set_pop(join_nodes), 0)
  562. // Create the worklist with the Start instance as first element
  563. worklist = create_node()
  564. set_add(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  565. while (bool_not(pm_finished(worklist, pm))):
  566. // Pop a random element from the list and execute it
  567. tuple = set_pop(worklist)
  568. element = tuple[0]
  569. result = tuple[1]
  570. // Find the type (to see what to do with it)
  571. // this does not yet yield the type of transformation, if it is an Execution
  572. type = read_type(pm, element)
  573. if (type == "Start"):
  574. // Initial node, just progress to the next elements
  575. // Nothing to do here though, as we have just started
  576. result = True
  577. elif (type == "Finish"):
  578. // Should be impossible, as we would have ended...
  579. result = result
  580. elif (type == "Fork"):
  581. result = result
  582. elif (type == "Join"):
  583. // Only do this if all dependencies are fullfilled
  584. // So add to the counter of this Join
  585. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  586. // Now check whether we have enough tokens to execute the Join itself
  587. Integer required
  588. Integer got
  589. required = read_nr_out(allIncomingAssociationInstances(pm, element, "Next")) + read_nr_out(allIncomingAssociationInstances(pm, element, "Else"))
  590. got = counters[element]
  591. if (got == required):
  592. // Reset counter to 0
  593. dict_overwrite(counters, element, 0)
  594. // And continue
  595. else:
  596. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  597. continue!
  598. elif (type == "Exec"):
  599. // Execute a transformation
  600. // This the difficult part!
  601. result = enact_action(pm, element, prefix, user_id)
  602. elif (type == "Decision"):
  603. // If the previous result is true, we add the normal one, otherwise the false one
  604. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  605. if (bool_not(result)):
  606. // Apparently it is False, so map this to the "Else" branch
  607. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  608. continue!
  609. else:
  610. // Apparently it is True, so map this to the "Then" branch
  611. set_add(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  612. continue!
  613. // We have finished the execution, so add all outgoing edges to the worklist
  614. Element all_next
  615. all_next = allAssociationDestinations(pm, element, "Next")
  616. String next
  617. while (read_nr_out(all_next) > 0):
  618. next = set_pop(all_next)
  619. set_add(worklist, create_tuple(next, result))
  620. // Reached a finish element, so stop
  621. output("Success")
  622. return !
  623. String function cmd_help(user_id : String):
  624. String result
  625. result = ""
  626. result = result + ("Model operations\n")
  627. result = result + (" model_add -- Add a new model\n")
  628. result = result + (" model_modify -- Modify an existing model\n")
  629. result = result + (" model_list -- List all models\n")
  630. result = result + (" model_list_full -- List all models with full info\n")
  631. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  632. result = result + (" model_render -- Render a given model with a specified mapper\n")
  633. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  634. result = result + ("\n")
  635. result = result + ("Transformation-specific operations\n")
  636. result = result + (" transformation_add_MT_language -- Create a RAMified metamodel of a set of models\n")
  637. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  638. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  639. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  640. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  641. result = result + (" transformation_list -- List all model transformations\n")
  642. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  643. result = result + (" transformation_detail -- List transformation details\n")
  644. result = result + (" transformation_RAMify -- RAMify a metamodel (again)\n")
  645. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  646. result = result + ("\n")
  647. result = result + ("Process operations\n")
  648. result = result + (" process_execute -- Execute a process model\n")
  649. result = result + ("\n")
  650. result = result + ("Model permission operations\n")
  651. result = result + (" permission_modify -- Change model permissions\n")
  652. result = result + (" permission_owner -- Change model owner\n")
  653. result = result + (" permission_group -- Change model group\n")
  654. result = result + ("\n")
  655. result = result + ("Group operations\n")
  656. result = result + (" group_create -- Create a group\n")
  657. result = result + (" group_delete -- Delete a group\n")
  658. result = result + (" group_owner_add -- Add group owner\n")
  659. result = result + (" group_owner_delete -- Remove group owner\n")
  660. result = result + (" group_join -- Add someone to your group\n")
  661. result = result + (" group_kick -- Kick someone from your group\n")
  662. result = result + (" group_list -- List all groups you are a member of\n")
  663. result = result + ("\n")
  664. if (is_admin(user_id)):
  665. result = result + ("Admin operations\n")
  666. result = result + (" admin_promote -- Promote a user to admin status\n")
  667. result = result + (" admin_demote -- Demote a user to normal status\n")
  668. result = result + ("\n")
  669. result = result + ("General operations\n")
  670. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  671. result = result + (" exit -- Kill the current task, while retaining user\n")
  672. return result!
  673. String function cmd_model_add(user_id : String, type : String, name : String):
  674. // Model addition operation, which uses model upload commands of the compiler
  675. String location
  676. String type_id
  677. Element new_model
  678. String new_model_id
  679. type_id = get_model_id(type)
  680. if (type_id != ""):
  681. // Type exists
  682. if (allow_read(user_id, type_id)):
  683. // And is readable
  684. if (get_model_id(name) == ""):
  685. // Model doesn't exist yet
  686. output("Waiting for model constructors...")
  687. new_model = construct_model_raw(get_full_model(type_id))
  688. model_create(new_model, name, user_id, type_id, "Model")
  689. return "Success"!
  690. else:
  691. return "Model exists: " + name!
  692. else:
  693. return "Permission denied to model: " + type!
  694. else:
  695. return "Model not found: " + type!
  696. String function cmd_process_execute(user_id : String, process : String, prefix : String):
  697. // Execute a process model until it reaches termination
  698. String process_id
  699. process_id = get_model_id(process)
  700. if (process_id != ""):
  701. if (allow_read(user_id, process_id)):
  702. enact_PM(get_full_model(process_id), prefix, user_id)
  703. return "Success"!
  704. else:
  705. return "Permission denied to model: " + process!
  706. else:
  707. return "Model not found: " + process!
  708. String function cmd_transformation_between(user_id : String, source_name : String, target_name : String):
  709. String source_id
  710. String target_id
  711. Element onSource
  712. Element onTarget
  713. Element result
  714. String transformation
  715. source_id = get_model_id(source_name)
  716. if (source_id != ""):
  717. target_id = get_model_id(target_name)
  718. if (target_id != ""):
  719. onSource = allAssociationOrigins(core, source_id, "transformInput")
  720. onTarget = allAssociationOrigins(core, target_id, "transformOutput")
  721. result = set_overlap(onSource, onTarget)
  722. String r
  723. r = "Success: "
  724. while (read_nr_out(result) > 0):
  725. transformation = set_pop(result)
  726. if (allow_read(user_id, transformation)):
  727. r = r + string_join(read_attribute(core, transformation, "name"), "\n")
  728. return r!
  729. else:
  730. return "Model not found: " + target_name!
  731. else:
  732. return "Model not found: " + source_name!
  733. String function cmd_model_render(user_id : String, model_name : String, mapper_name : String):
  734. String model_ID
  735. String mapper_ID
  736. String rendered_name
  737. String tracability_name
  738. String type_ID
  739. Element inputs
  740. Element outputs
  741. Element rendered_model
  742. Element tracability_model
  743. Element result
  744. Element out_links
  745. Element in_links
  746. model_ID = get_model_id(model_name)
  747. if (model_ID != ""):
  748. mapper_ID = get_model_id(mapper_name)
  749. if (allow_read(user_id, model_ID)):
  750. if (mapper_ID != ""):
  751. if (allow_read(user_id, mapper_ID)):
  752. // Everything is fine; start the actual operation
  753. // Find metamodel to render to
  754. rendered_name = (("__RENDERED_" + model_name) + "__") + mapper_name
  755. tracability_name = (("__TRACABILITY_" + model_name) + "__") + mapper_name
  756. // Take the abstract syntax model and the previously rendered model
  757. inputs = create_node()
  758. set_add(inputs, model_name)
  759. set_add(inputs, rendered_name)
  760. // Generate a new rendered model only (no write to original model!)
  761. outputs = create_node()
  762. out_links = allAssociationDestinations(core, mapper_ID, "transformOutput")
  763. in_links = allAssociationDestinations(core, mapper_ID, "transformInput")
  764. while(read_nr_out(out_links) > 0):
  765. type_ID = set_pop(out_links)
  766. if (bool_not(set_in(in_links, type_ID))):
  767. // It is not the AS model, but another one (the MM_rendered)
  768. break!
  769. // Add the model itself as output as well, as otherwise tracability links get messed up!
  770. set_add(outputs, read_attribute(core, set_pop(allAssociationDestinations(core, get_model_id(model_name), "instanceOf")), "name"))
  771. set_add(outputs, read_attribute(core, type_ID, "name"))
  772. // Rendered model doesn't exist yet, so create first
  773. if (get_model_id(rendered_name) == ""):
  774. // Rendered model doesn't exist yet, so create first!
  775. rendered_model = instantiate_model(get_full_model(type_ID))
  776. model_create(rendered_model, rendered_name, user_id, type_ID, "Model")
  777. // Tracability model won't exist either
  778. tracability_model = instantiate_model(get_full_model(get_model_id("Tracability")))
  779. model_create(tracability_model, tracability_name, user_id, get_model_id("Tracability"), "Model")
  780. else:
  781. // Read out tracability model
  782. tracability_model = get_full_model(get_model_id(tracability_name))
  783. // Do the operation itself!
  784. result = execute_operation(mapper_ID, inputs, outputs, tracability_model)
  785. // Overwrite the previous rendered model
  786. model_overwrite(result[read_attribute(core, type_ID, "name")], get_model_id(rendered_name))
  787. // Tracability updated in-place
  788. model_overwrite(tracability_model, get_model_id(tracability_name))
  789. tracability_model = get_full_model(get_model_id(tracability_name))
  790. // Also output the resulting model
  791. return "Success: " + JSON_print(get_full_model(get_model_id(rendered_name)))!
  792. else:
  793. return "Permission denied to model: " + mapper_name!
  794. else:
  795. return "Model not found: " + mapper_name!
  796. else:
  797. return "Permission denied to model: " + model_name!
  798. else:
  799. return "Model not found: " + model_name!
  800. String function cmd_transformation_execute(user_id : String, transformation_name : String, source_models : Element, target_models : Element):
  801. // Execute a transformation, whatever type it is
  802. // First we detect the type, so we know how to prepare for invocation
  803. String transformation_id
  804. String exact_type
  805. Element sources
  806. Element targets
  807. String source
  808. String target
  809. Element inputs
  810. Element outputs
  811. Element trace_links
  812. String target_model_name
  813. String source_model_name
  814. String source_model_ID
  815. Element result
  816. Element keys
  817. String key
  818. transformation_id = get_model_id(transformation_name)
  819. if (transformation_id != ""):
  820. if (allow_read(user_id, transformation_id)):
  821. if (is_nominal_instance(core, transformation_id, "Transformation")):
  822. // Read out source and target links
  823. inputs = create_node()
  824. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  825. while (read_nr_out(sources) > 0):
  826. source = set_pop(sources)
  827. if (dict_in(source_models, read_attribute(core, readAssociationDestination(core, source), "name"))):
  828. source_model_name = source_models[read_attribute(core, readAssociationDestination(core, source), "name")]
  829. else:
  830. return string_join("Source model not bound: ", read_attribute(core, readAssociationDestination(core, source), "name"))!
  831. source_model_ID = get_model_id(source_model_name)
  832. if (source_model_ID != ""):
  833. if (allow_read(user_id, source_model_ID)):
  834. // Check for conformance to the requested metamodel
  835. if (check_is_typed_by(source_model_ID, source)):
  836. if (check_conformance(source_model_ID)):
  837. set_add(inputs, source_model_name)
  838. continue!
  839. else:
  840. return "Incorrectly typed model: " + source_model_name!
  841. else:
  842. return "Incorrectly typed model: " + source_model_name!
  843. else:
  844. return "Permission denied to model: " + source_model_name!
  845. else:
  846. return "Model not found: " + source_model_name!
  847. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  848. outputs = create_node()
  849. while (read_nr_out(targets) > 0):
  850. target = set_pop(targets)
  851. if (dict_in(target_models, read_attribute(core, readAssociationDestination(core, target), "name"))):
  852. target_model_name = target_models[read_attribute(core, readAssociationDestination(core, target), "name")]
  853. else:
  854. return string_join("Target model not bound: ", read_attribute(core, readAssociationDestination(core, target), "name"))!
  855. if (get_model_id(target_model_name) == ""):
  856. // Doesn't exist yet, so we can easily create
  857. dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
  858. else:
  859. // Already exists, so we need to check for write access
  860. if (allow_write(user_id, get_model_id(target_model_name))):
  861. dict_add(outputs, read_attribute(core, readAssociationDestination(core, target), "name"), target_model_name)
  862. else:
  863. return "Permission denied to model: " + target_model_name!
  864. if (read_type(core, transformation_id) == "ActionLanguage"):
  865. output("Success: ready for AL execution")
  866. elif (read_type(core, transformation_id) == "ManualOperation"):
  867. output("Success: ready for MANUAL execution")
  868. else:
  869. output("Success: ready for MT execution")
  870. result = execute_operation(transformation_id, inputs, dict_keys(outputs), read_root())
  871. // Now write out the models again
  872. if (element_eq(result, read_root())):
  873. // Something went wrong!
  874. return "Failure"!
  875. else:
  876. keys = dict_keys(result)
  877. while (read_nr_out(keys) > 0):
  878. key = set_pop(keys)
  879. if (get_model_id(outputs[key]) == ""):
  880. // New model
  881. model_create(result[key], outputs[key], user_id, get_model_id(key), "Model")
  882. else:
  883. model_overwrite(result[key], get_model_id(outputs[key]))
  884. return "Success"!
  885. else:
  886. return "Model is not executable: " + transformation_name!
  887. else:
  888. return "Permission denied to model: " + transformation_name!
  889. else:
  890. return "Model not found: " + transformation_name!
  891. String function cmd_verify(user_id : String, model_name : String):
  892. // Check whether a model conforms to its specification (with the selected type mapping)
  893. String model_id
  894. String result
  895. model_id = get_model_id(model_name)
  896. if (model_id != ""):
  897. if (allow_read(user_id, model_id)):
  898. result = conformance_scd(get_full_model(model_id))
  899. return "Success: " + result!
  900. else:
  901. return "Permission denied to model: " + model_name!
  902. else:
  903. return "Model not found: " + model_name!
  904. String function cmd_model_overwrite(user_id : String, model_name : String):
  905. // Overwrites an existing model without changing any metadata
  906. String model_id
  907. String type_id
  908. Element new_model
  909. model_id = get_model_id(model_name)
  910. if (model_id != ""):
  911. if (allow_write(user_id, model_id)):
  912. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  913. if (allow_read(user_id, type_id)):
  914. output("Waiting for model constructors...")
  915. new_model = construct_model_raw(get_full_model(set_pop(allAssociationDestinations(core, model_id, "instanceOf"))))
  916. model_overwrite(new_model, model_id)
  917. return "Success"!
  918. else:
  919. return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
  920. else:
  921. return "Permission denied to model: " + model_name!
  922. else:
  923. return "Model not found: " + model_name!
  924. String function cmd_model_modify(user_id : String, model_name : String):
  925. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  926. String model_id
  927. String type_id
  928. model_id = get_model_id(model_name)
  929. if (model_id != ""):
  930. if (allow_read(user_id, model_id)):
  931. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  932. if (allow_read(user_id, type_id)):
  933. output("Success")
  934. modify(get_full_model(model_id), allow_write(user_id, model_id))
  935. return "Success"!
  936. else:
  937. return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
  938. else:
  939. return "Permission denied to model: " + model_name!
  940. else:
  941. return "Model not found: " + model_name!
  942. String function cmd_model_delete(user_id : String, model_name : String):
  943. String model_id
  944. model_id = get_model_id(model_name)
  945. if (model_id != ""):
  946. if (allow_write(user_id, model_id)):
  947. model_delete_element(core, model_id)
  948. return "Success"!
  949. else:
  950. return "Permission denied to model: " + model_name!
  951. else:
  952. return "Model not found: " + model_name!
  953. String function cmd_model_list():
  954. // List all models
  955. Element models
  956. String result
  957. String m
  958. result = "Success: "
  959. models = allInstances(core, "Model")
  960. while (read_nr_out(models) > 0):
  961. m = set_pop(models)
  962. result = (result + string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))) + "\n"
  963. return result!
  964. String function cmd_model_list_full():
  965. // List all models with full info
  966. Element models
  967. String m
  968. String permissions
  969. String owner
  970. String group
  971. String name
  972. String type
  973. String result
  974. result = "Success: "
  975. models = allInstances(core, "Model")
  976. while (read_nr_out(models) > 0):
  977. m = set_pop(models)
  978. permissions = read_attribute(core, m, "permissions")
  979. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  980. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  981. name = read_attribute(core, m, "name")
  982. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  983. result = (result + (((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)) + "\n"
  984. return result!
  985. String function cmd_transformation_add_MT_language(user_id : String, model_names : Element, RAMified_name : String):
  986. // Create a model transformation language from a set of input and output formalisms
  987. String model_name
  988. String model_id
  989. Element source
  990. Element target
  991. Element all_formalisms
  992. Element merged_formalism
  993. Element ramified_formalism
  994. String type_id
  995. String location
  996. String new_model_id
  997. String type_name
  998. // Read involved formalisms
  999. all_formalisms = create_node()
  1000. while (read_nr_out(model_names) > 0):
  1001. model_name = set_pop(model_names)
  1002. model_id = get_model_id(model_name)
  1003. if (model_id != ""):
  1004. if (allow_read(user_id, model_id)):
  1005. type_name = read_attribute(core, set_pop(allAssociationDestinations(core, model_id, "instanceOf")), "name")
  1006. type_id = get_model_id(type_name)
  1007. if (type_name != "SimpleClassDiagrams"):
  1008. return "Can only RAMify models of type SimpleClassDiagrams"!
  1009. else:
  1010. set_add(all_formalisms, create_tuple(model_name, get_full_model(model_id)))
  1011. else:
  1012. return "Permission denied to model: " + model_name!
  1013. else:
  1014. return "Model not found: " + model_name!
  1015. // Merge all into a single metamodel
  1016. if (read_nr_out(all_formalisms) > 0):
  1017. if (get_model_id(RAMified_name) == ""):
  1018. String merged_formalism_id
  1019. String ramified_formalism_id
  1020. String source_formalism_id
  1021. String tracability_link
  1022. // New location is available, so write
  1023. merged_formalism = model_fuse(set_copy(all_formalisms))
  1024. model_create(merged_formalism, "__merged_" + RAMified_name, user_id, type_id, "Model")
  1025. merged_formalism_id = get_model_id("__merged_" + RAMified_name)
  1026. // Add tracability links at this level
  1027. while (read_nr_out(all_formalisms) > 0):
  1028. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1029. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1030. instantiate_attribute(core, tracability_link, "type", "merged")
  1031. // Merge complete, now RAMify!
  1032. ramified_formalism = ramify(merged_formalism)
  1033. model_create(ramified_formalism, RAMified_name, user_id, type_id, "Model")
  1034. ramified_formalism_id = get_model_id(RAMified_name)
  1035. // Add tracability link at this level
  1036. tracability_link = instantiate_link(core, "tracability", "", ramified_formalism_id, merged_formalism_id)
  1037. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1038. return "Success"!
  1039. else:
  1040. return "Model exists: " + RAMified_name!
  1041. else:
  1042. return "At least one formalism is required"!
  1043. String function cmd_transformation_RAMify(user_id : String, merged_model_name : String, target_model_name : String):
  1044. // RAMify a metamodel
  1045. String merged_model_id
  1046. String target_model_id
  1047. Element target_model
  1048. String tracability_link
  1049. merged_model_id = get_model_id(merged_model_name)
  1050. if (merged_model_id != ""):
  1051. if (allow_read(user_id, merged_model_id)):
  1052. target_model_id = get_model_id(target_model_name)
  1053. if (target_model_id == ""):
  1054. // New model, so everything is fine
  1055. target_model = ramify(get_full_model(merged_model_id))
  1056. model_create(target_model, target_model_name, user_id, set_pop(allAssociationDestinations(core, merged_model_id, "instanceOf")), "Model")
  1057. target_model_id = get_model_id(target_model_name)
  1058. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1059. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1060. else:
  1061. // Existing model, so overwrite
  1062. if (allow_write(user_id, target_model_id)):
  1063. target_model = ramify(get_full_model(merged_model_id))
  1064. model_overwrite(target_model, target_model_id)
  1065. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, target_model_id, "tracability")))
  1066. tracability_link = instantiate_link(core, "tracability", "", target_model_id, merged_model_id)
  1067. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1068. else:
  1069. return "Permission denied to model: " + target_model_name!
  1070. return "Success"!
  1071. else:
  1072. return "Permission denied to model: " + merged_model_name!
  1073. else:
  1074. return "Model not found: " + merged_model_name!
  1075. String function cmd_transformation_add_MANUAL(user_id : String, source_model_names : Element, target_model_names : Element, operation_name : String):
  1076. return transformation_add(user_id, source_model_names, target_model_names, operation_name, "manual")!
  1077. String function cmd_transformation_add_AL(user_id : String, source_model_names : Element, target_model_names : Element, operation_name : String):
  1078. return transformation_add(user_id, source_model_names, target_model_names, operation_name, "actionlanguage")!
  1079. String function transformation_add(user_id : String, source_model_names : Element, target_model_names : Element, operation_name : String, operation_type : String):
  1080. // Add a manual transformation model
  1081. String model_id
  1082. Element models
  1083. Element source
  1084. Element target
  1085. String name
  1086. Element all_formalisms
  1087. Element merged_formalism
  1088. String merged_formalism_id
  1089. String source_formalism_id
  1090. String tracability_link
  1091. String type_id
  1092. String old_type_id
  1093. source = create_node()
  1094. target = create_node()
  1095. all_formalisms = create_node()
  1096. type_id = ""
  1097. old_type_id = ""
  1098. while (read_nr_out(source_model_names) > 0):
  1099. name = set_pop(source_model_names)
  1100. model_id = get_model_id(name)
  1101. if (model_id != ""):
  1102. if (allow_read(user_id, model_id)):
  1103. if (bool_not(set_in(source, model_id))):
  1104. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1105. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1106. old_type_id = type_id
  1107. set_add(source, model_id)
  1108. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1109. elif (old_type_id != type_id):
  1110. // Already have a previous type_id and now another: CLASH
  1111. return "Cannot add model as type not compatible with previous models: " + name!
  1112. else:
  1113. return "Model already selected as source: " + name!
  1114. else:
  1115. return "Permission denied to model: " + name!
  1116. else:
  1117. return "Model not found: " + name!
  1118. while (read_nr_out(target_model_names) > 0):
  1119. name = set_pop(target_model_names)
  1120. model_id = get_model_id(name)
  1121. if (model_id != ""):
  1122. if (allow_read(user_id, model_id)):
  1123. if (bool_not(set_in(target, model_id))):
  1124. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1125. if (bool_or(old_type_id == "", type_id == old_type_id)):
  1126. old_type_id = type_id
  1127. set_add(target, model_id)
  1128. set_add(all_formalisms, create_tuple(name, get_full_model(model_id)))
  1129. elif (old_type_id != type_id):
  1130. // Already have a previous type_id and now another: CLASH
  1131. return "Cannot add mdoel as type not compatible with previous models: " + name!
  1132. else:
  1133. return "Model already selected as target: " + name!
  1134. else:
  1135. return "Permission denied to model: " + name!
  1136. else:
  1137. return "Model not found: " + name!
  1138. if (get_model_id(operation_name) == ""):
  1139. if (operation_type == "manual"):
  1140. // Finished with all information, now create the model itself!
  1141. model_create(instantiate_model(get_full_model(get_model_id("ManualOperation"))), operation_name, user_id, get_model_id("ManualOperation"), "ManualOperation")
  1142. model_id = get_model_id(operation_name)
  1143. elif (operation_type == "actionlanguage"):
  1144. // Finished with all information, now create the model itself!
  1145. output("Waiting for code constructors...")
  1146. add_code_model(get_full_model(get_model_id("ActionLanguage")), "AL/" + operation_name, construct_function())
  1147. model_create(import_node("AL/" + operation_name), operation_name, user_id, get_model_id("ActionLanguage"), "ActionLanguage")
  1148. model_id = get_model_id(operation_name)
  1149. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1150. // New location is available, so write
  1151. merged_formalism = model_fuse(set_copy(all_formalisms))
  1152. model_create(merged_formalism, "__merged_" + operation_name, user_id, type_id, "Model")
  1153. merged_formalism_id = get_model_id("__merged_" + operation_name)
  1154. // Add tracability links at this level
  1155. while (read_nr_out(all_formalisms) > 0):
  1156. source_formalism_id = get_model_id(list_read(set_pop(all_formalisms), 0))
  1157. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1158. instantiate_attribute(core, tracability_link, "type", "merged")
  1159. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1160. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1161. // Extend metadata with info on source and target
  1162. String link
  1163. String dst
  1164. while (read_nr_out(source) > 0):
  1165. dst = set_pop(source)
  1166. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1167. while (read_nr_out(target) > 0):
  1168. dst = set_pop(target)
  1169. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1170. return "Success"!
  1171. else:
  1172. return "Model exists: " + operation_name!
  1173. String function cmd_transformation_add_MT(user_id : String, RAMified_metamodel_name : String, source_models : Element, target_models : Element, operation_name : String):
  1174. // Add a model transformation model
  1175. // Just a usual model instantiation, but need to add the source and target links based on user info
  1176. String ramified_metamodel_id
  1177. String model_id
  1178. Element models
  1179. Element links
  1180. String link_id
  1181. Element supported
  1182. Element source
  1183. Element target
  1184. String name
  1185. String new_model_id
  1186. String merged_link_id
  1187. Element links_merged
  1188. String merged_metamodel_id
  1189. source = create_node()
  1190. target = create_node()
  1191. supported = create_node()
  1192. ramified_metamodel_id = get_model_id(RAMified_metamodel_name)
  1193. if (ramified_metamodel_id != ""):
  1194. if (allow_read(user_id, ramified_metamodel_id)):
  1195. links = allOutgoingAssociationInstances(core, ramified_metamodel_id, "tracability")
  1196. while (read_nr_out(links) > 0):
  1197. link_id = set_pop(links)
  1198. merged_metamodel_id = readAssociationDestination(core, link_id)
  1199. if (value_eq(read_attribute(core, link_id, "type"), "RAMified")):
  1200. links_merged = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  1201. while (read_nr_out(links_merged) > 0):
  1202. merged_link_id = set_pop(links_merged)
  1203. if (value_eq(read_attribute(core, merged_link_id, "type"), "merged")):
  1204. set_add(supported, readAssociationDestination(core, merged_link_id))
  1205. while (read_nr_out(source_models) > 0):
  1206. name = set_pop(source_models)
  1207. model_id = get_model_id(name)
  1208. if (model_id != ""):
  1209. if (set_in(supported, model_id)):
  1210. if (bool_not(set_in(source, model_id))):
  1211. set_add(source, model_id)
  1212. else:
  1213. return "Model already selected: " + name!
  1214. else:
  1215. return "Model not supported by RAMified metamodel: " + name!
  1216. else:
  1217. return "Model not found: " + name!
  1218. while (read_nr_out(target_models) > 0):
  1219. name = set_pop(target_models)
  1220. model_id = get_model_id(name)
  1221. if (model_id != ""):
  1222. if (set_in(supported, model_id)):
  1223. if (bool_not(set_in(target, model_id))):
  1224. set_add(target, model_id)
  1225. else:
  1226. return "Model already selected: " + name!
  1227. else:
  1228. return "Model not supported by RAMified metamodel: " + name!
  1229. else:
  1230. return "Model not found: " + name!
  1231. if (get_model_id(operation_name) == ""):
  1232. String new_model
  1233. // Finished with all information, now create the model itself!
  1234. output("Waiting for model constructors...")
  1235. new_model = construct_model_raw(get_full_model(ramified_metamodel_id))
  1236. model_create(new_model, operation_name, user_id, ramified_metamodel_id, "ModelTransformation")
  1237. model_id = get_model_id(operation_name)
  1238. // Extend metadata with info on source and target
  1239. String link
  1240. String dst
  1241. while (read_nr_out(source) > 0):
  1242. dst = set_pop(source)
  1243. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1244. while (read_nr_out(target) > 0):
  1245. dst = set_pop(target)
  1246. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1247. return "Success"!
  1248. else:
  1249. return "Model exists: " + operation_name!
  1250. else:
  1251. return "Permission denied to model: " + operation_name!
  1252. else:
  1253. return "Model not found: " + operation_name!
  1254. String function cmd_transformation_list():
  1255. // List all models
  1256. Element models
  1257. String m
  1258. String type
  1259. String result
  1260. result = "Success: "
  1261. models = allInstances(core, "Transformation")
  1262. while (read_nr_out(models) > 0):
  1263. m = set_pop(models)
  1264. 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")
  1265. return result!
  1266. String function cmd_transformation_list_full():
  1267. // List all models with full info
  1268. Element models
  1269. String m
  1270. String permissions
  1271. String owner
  1272. String group
  1273. String name
  1274. String type
  1275. String result
  1276. result = ""
  1277. models = allInstances(core, "Transformation")
  1278. while (read_nr_out(models) > 0):
  1279. m = set_pop(models)
  1280. permissions = read_attribute(core, m, "permissions")
  1281. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1282. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1283. name = read_attribute(core, m, "name")
  1284. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1285. result = result + ((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type) + "\n")
  1286. return result!
  1287. String function cmd_permission_modify(user_id : String, model_name : String, permissions : String):
  1288. Integer permission
  1289. String model_id
  1290. model_id = get_model_id(model_name)
  1291. if (model_id != ""):
  1292. if (get_relation_to_model(user_id, model_id) == 0):
  1293. Boolean fail
  1294. Integer i
  1295. i = 0
  1296. if (string_len(permissions) != 3):
  1297. fail = True
  1298. while (i < 3):
  1299. permission = cast_s2i(string_get(permissions, i))
  1300. if (bool_or(permission < 0, permission > 2)):
  1301. fail = True
  1302. break!
  1303. i = i + 1
  1304. if (bool_not(fail)):
  1305. unset_attribute(core, model_id, "permissions")
  1306. instantiate_attribute(core, model_id, "permissions", permissions)
  1307. return "Success"!
  1308. else:
  1309. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1310. else:
  1311. return "Permission denied to model: " + model_name!
  1312. else:
  1313. return "Model not found: " + model_name!
  1314. String function cmd_permission_owner(user_id : String, model_name : String, new_user_name : String):
  1315. String model_id
  1316. String new_user_id
  1317. model_id = get_model_id(model_name)
  1318. if (model_id != ""):
  1319. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1320. new_user_id = get_user_id(new_user_name)
  1321. if (new_user_id != ""):
  1322. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1323. instantiate_link(core, "owner", "", model_id, new_user_id)
  1324. return "Success"!
  1325. else:
  1326. return "No such user: " + new_user_name!
  1327. else:
  1328. return "Permission denied to model: " + model_name!
  1329. else:
  1330. return "Model not found: " + model_name!
  1331. String function cmd_permission_group(user_id : String, model_name : String, new_group_name : String):
  1332. String model_id
  1333. String group_id
  1334. model_id = get_model_id(model_name)
  1335. if (model_id != ""):
  1336. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1337. group_id = get_group_id(new_group_name)
  1338. if (group_id != ""):
  1339. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1340. instantiate_link(core, "group", "", model_id, group_id)
  1341. return "Success"!
  1342. else:
  1343. return "No such group: " + new_group_name!
  1344. else:
  1345. return "Permission denied to model: " + model_name!
  1346. else:
  1347. return "Model not found: " + model_name!
  1348. String function cmd_group_create(user_id : String, group_name : String):
  1349. // Create a new group and become its owner
  1350. String group_id
  1351. String name
  1352. group_id = get_group_id(group_name)
  1353. if (group_id == ""):
  1354. group_id = instantiate_node(core, "Group", "")
  1355. instantiate_attribute(core, group_id, "name", group_name)
  1356. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1357. instantiate_link(core, "owner", "", group_id, user_id)
  1358. return "Success"!
  1359. else:
  1360. return "Group exists: " + group_name!
  1361. String function cmd_group_delete(user_id : String, group_name : String):
  1362. // Delete an existing group
  1363. String group_id
  1364. group_id = get_group_id(group_name)
  1365. if (group_id != ""):
  1366. if (allow_group_modify(user_id, group_id)):
  1367. model_delete_element(core, group_id)
  1368. return "Success"!
  1369. else:
  1370. return "Permission denied to group: " + group_name!
  1371. else:
  1372. return "Group not found: " + group_name!
  1373. String function cmd_group_owner_add(user_id : String, group_name : String, other_user_name : String):
  1374. // Add an owner to your group
  1375. String group_id
  1376. String other_user_id
  1377. group_id = get_group_id(group_name)
  1378. if (group_id != ""):
  1379. if (allow_group_modify(user_id, group_id)):
  1380. other_user_id = get_user_id(other_user_name)
  1381. if (other_user_id != ""):
  1382. Element overlap
  1383. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1384. if (read_nr_out(overlap) == 0):
  1385. instantiate_link(core, "owner", "", group_id, other_user_id)
  1386. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1387. if (read_nr_out(overlap) == 0):
  1388. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1389. return "Success"!
  1390. else:
  1391. return "User is already the owner!"!
  1392. else:
  1393. return "User not found: " + other_user_name!
  1394. else:
  1395. return "Permission denied to group: " + group_name!
  1396. else:
  1397. return "Group not found: " + group_name!
  1398. String function cmd_group_owner_delete(user_id : String, group_name : String, other_user_name : String):
  1399. // Remove an owner from your group
  1400. String group_id
  1401. String other_user_id
  1402. group_id = get_group_id(group_name)
  1403. if (group_id != ""):
  1404. if (allow_group_modify(user_id, group_id)):
  1405. other_user_id = get_user_id(other_user_name)
  1406. if (other_user_id != ""):
  1407. Element overlap
  1408. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1409. if (read_nr_out(overlap) > 0):
  1410. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1411. if (read_nr_out(overlap) > 0):
  1412. model_delete_element(core, set_pop(overlap))
  1413. return "Success"!
  1414. else:
  1415. return "User is not an owner of the group!"!
  1416. else:
  1417. return "User is not a member of the group!"!
  1418. else:
  1419. return "User not found: " + other_user_name!
  1420. else:
  1421. return "Permission denied to group: " + group_name!
  1422. else:
  1423. return "Group not found: " + group_name!
  1424. String function cmd_group_join(user_id : String, group_name : String, other_user_name : String):
  1425. // Add someone to your group
  1426. String group_id
  1427. String other_user_id
  1428. group_id = get_group_id(group_name)
  1429. if (group_id != ""):
  1430. if (allow_group_modify(user_id, group_id)):
  1431. other_user_id = get_user_id(other_user_name)
  1432. if (other_user_id != ""):
  1433. Element overlap
  1434. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1435. if (read_nr_out(overlap) == 0):
  1436. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1437. return "Success"!
  1438. else:
  1439. return "User is already a member of the group!"!
  1440. else:
  1441. return "User not found: " + other_user_name!
  1442. else:
  1443. return "Permission denied to group: " + group_name!
  1444. else:
  1445. return "Group not found: " + group_name!
  1446. String function cmd_group_kick(user_id : String, group_name : String, other_user_name : String):
  1447. // Remove someone from your group
  1448. String group_id
  1449. String other_user_id
  1450. group_id = get_group_id(group_name)
  1451. if (group_id != ""):
  1452. if (allow_group_modify(user_id, group_id)):
  1453. other_user_id = get_user_id(other_user_name)
  1454. if (other_user_id != ""):
  1455. Element overlap
  1456. overlap = set_overlap(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  1457. if (read_nr_out(overlap) > 0):
  1458. model_delete_element(core, set_pop(overlap))
  1459. // Check if user was an owner as well
  1460. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1461. if (read_nr_out(overlap) > 0):
  1462. model_delete_element(core, set_pop(overlap))
  1463. return "Success"!
  1464. else:
  1465. return "User is not a member of the group!"!
  1466. else:
  1467. return "User not found: " + other_user_name!
  1468. else:
  1469. return "Permission denied to group: " + group_name!
  1470. else:
  1471. return "Group not found: " + group_name!
  1472. String function cmd_group_list(user_id : String):
  1473. // List all groups you are a member of (and whether you are admin or not!)
  1474. Element groups
  1475. String group_id
  1476. String admin
  1477. String result
  1478. result = ""
  1479. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1480. while (read_nr_out(groups) > 0):
  1481. group_id = set_pop(groups)
  1482. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  1483. admin = " A "
  1484. else:
  1485. admin = " "
  1486. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1487. return result!
  1488. String function cmd_admin_promote(user_id : String, other_user_name : String):
  1489. // Promote a user to admin status
  1490. if (is_admin(user_id)):
  1491. String other_user_id
  1492. other_user_id = get_user_id(other_user_name)
  1493. if (other_user_id != ""):
  1494. unset_attribute(core, other_user_id, "admin")
  1495. instantiate_attribute(core, other_user_id, "admin", True)
  1496. return "Success"!
  1497. else:
  1498. return "User not found: " + other_user_name!
  1499. else:
  1500. return "Permission denied to administrate: " + other_user_name!
  1501. String function cmd_admin_demote(user_id : String, other_user_name : String):
  1502. // Demote a user to normal status
  1503. if (is_admin(user_id)):
  1504. String other_user_id
  1505. other_user_id = get_user_id(other_user_name)
  1506. if (other_user_id != ""):
  1507. unset_attribute(core, other_user_id, "admin")
  1508. instantiate_attribute(core, other_user_id, "admin", False)
  1509. return "Success"!
  1510. else:
  1511. return "User not found: " + other_user_name!
  1512. else:
  1513. return "Permission denied to administrate: " + other_user_name!
  1514. Void function user_function_skip_init(user_id : String):
  1515. String cmd
  1516. output("Welcome to the Model Management Interface v2.0!")
  1517. output("Use the 'help' command for a list of possible commands")
  1518. while (True):
  1519. cmd = input()
  1520. if (cmd == "help"):
  1521. output(cmd_help(user_id))
  1522. elif (cmd == "model_add"):
  1523. output(cmd_model_add(user_id, single_input("Model type?"), single_input("Model name?")))
  1524. elif (cmd == "process_execute"):
  1525. output(cmd_process_execute(user_id, single_input("Process to execute?"), single_input("Model prefix to use?")))
  1526. elif (cmd == "transformation_between"):
  1527. output(cmd_transformation_between(user_id, single_input("Source type?"), single_input("Target type?")))
  1528. elif (cmd == "model_render"):
  1529. output(cmd_model_render(user_id, single_input("Model name?"), single_input("Mapper name?")))
  1530. elif (cmd == "transformation_execute"):
  1531. output(cmd_transformation_execute(user_id, single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
  1532. elif (cmd == "verify"):
  1533. output(cmd_verify(user_id, single_input("Model name?")))
  1534. elif (cmd == "model_overwrite"):
  1535. output(cmd_model_overwrite(user_id, single_input("Model name?")))
  1536. elif (cmd == "model_modify"):
  1537. output(cmd_model_modify(user_id, single_input("Model name?")))
  1538. elif (cmd == "model_delete"):
  1539. output(cmd_model_delete(user_id, single_input("Model name?")))
  1540. elif (cmd == "model_list"):
  1541. output(cmd_model_list())
  1542. elif (cmd == "model_list_full"):
  1543. output(cmd_model_list_full())
  1544. elif (cmd == "transformation_add_MT_language"):
  1545. output(cmd_transformation_add_MT_language(user_id, set_input("Metamodel names?"), single_input("RAMified metamodel name?")))
  1546. elif (cmd == "transformation_RAMify"):
  1547. output(cmd_transformation_RAMify(user_id, single_input("Metamodel name?"), single_input("Target metamodel name?")))
  1548. elif (cmd == "transformation_add_MANUAL"):
  1549. output(cmd_transformation_add_MANUAL(user_id, set_input("Source model names?"), set_input("Target model names?"), single_input("Operation name?")))
  1550. elif (cmd == "transformation_add_AL"):
  1551. output(cmd_transformation_add_AL(user_id, set_input("Source model names?"), set_input("Target model names?"), single_input("Operation name?")))
  1552. elif (cmd == "transformation_add_MT"):
  1553. 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?")))
  1554. elif (cmd == "transformation_list"):
  1555. output(cmd_transformation_list())
  1556. elif (cmd == "transformation_list_full"):
  1557. output(cmd_transformation_list_full())
  1558. elif (cmd == "permission_modify"):
  1559. output(cmd_permission_modify(user_id, single_input("Model name?"), single_input("Permissions?")))
  1560. elif (cmd == "permission_owner"):
  1561. output(cmd_permission_owner(user_id, single_input("Model name?"), single_input("New owning user?")))
  1562. elif (cmd == "permission_group"):
  1563. output(cmd_permission_group(user_id, single_input("Model name?"), single_input("New owning group?")))
  1564. elif (cmd == "group_create"):
  1565. output(cmd_group_create(user_id, single_input("New group name?")))
  1566. elif (cmd == "group_delete"):
  1567. output(cmd_group_delete(user_id, single_input("Group name?")))
  1568. elif (cmd == "group_owner_add"):
  1569. output(cmd_group_owner_add(user_id, single_input("Group name?"), single_input("User name?")))
  1570. elif (cmd == "group_owner_delete"):
  1571. output(cmd_group_owner_delete(user_id, single_input("Group name?"), single_input("User name?")))
  1572. elif (cmd == "group_join"):
  1573. output(cmd_group_join(user_id, single_input("Group name?"), single_input("User name?")))
  1574. elif (cmd == "group_kick"):
  1575. output(cmd_group_kick(user_id, single_input("Group name?"), single_input("User name?")))
  1576. elif (cmd == "group_list"):
  1577. output(cmd_group_list(user_id))
  1578. elif (cmd == "admin_promote"):
  1579. output(cmd_admin_promote(user_id, single_input("User name?")))
  1580. elif (cmd == "admin_demote"):
  1581. output(cmd_admin_demote(user_id, single_input("User name?")))
  1582. elif (cmd == "verbose"):
  1583. set_verbose(True)
  1584. elif (cmd == "quiet"):
  1585. set_verbose(False)
  1586. elif (cmd == "self-destruct"):
  1587. // Delete user from Core Formalism
  1588. model_delete_element(core, user_id)
  1589. return !
  1590. elif (cmd == "exit"):
  1591. // Exit by actually removing the user and decoupling it from all of its models
  1592. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1593. // as the current user will have been deleted
  1594. return !
  1595. else:
  1596. output("Unknown command: " + cmd)
  1597. // We never get here!
  1598. return !