core_algorithm.alc 69 KB

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