core_algorithm.alc 65 KB

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