core_algorithm.alc 66 KB

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