core_algorithm.alc 68 KB

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