core_algorithm.alc 69 KB

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