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