core_algorithm.alc 64 KB

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