core_algorithm.alc 69 KB

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