core_algorithm.alc 66 KB

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