core_algorithm.alc 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450
  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. include "compiler.alh"
  16. include "random.alh"
  17. String core_model_location = "models/core"
  18. Element core = ?
  19. String current_user_id
  20. Element caches
  21. Element pm_tasks = ?
  22. String function get_foldername(name : String):
  23. Element result
  24. result = string_split(name, "/")
  25. list_pop_final(result)
  26. if (list_len(result) == 0):
  27. return ""!
  28. // 'result' now contains a list of entries which we have to join with the seperator
  29. String str
  30. str = list_pop(result, 0)
  31. while (list_len(result) > 0):
  32. str = string_join(str + "/", list_pop(result, 0))
  33. return str!
  34. String function get_filename(name : String):
  35. return list_pop_final(string_split(name, "/"))!
  36. String function full_name(model_id : String):
  37. return read_attribute(core, model_id, "name")!
  38. Void function initialize_core():
  39. // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
  40. add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
  41. return !
  42. Boolean function is_typed_by(model_id : String, metamodel_id : String):
  43. return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
  44. Element function get_instanceOf_links(model_id : String, metamodel_id : String):
  45. Element result
  46. Element options
  47. String elem
  48. result = set_create()
  49. options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  50. while (set_len(options) > 0):
  51. elem = set_pop(options)
  52. if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
  53. set_add(result, elem)
  54. return result!
  55. String function get_instanceOf_link(model_id : String, metamodel_id : String):
  56. Element all_links
  57. String choice
  58. all_links = get_instanceOf_links(model_id, metamodel_id)
  59. if (set_len(all_links) > 1):
  60. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  61. elif (set_len(all_links) == 0):
  62. log("No types found!")
  63. log("Source model: " + cast_value(read_attribute(core, model_id, "name")))
  64. log("Target meta-model: " + cast_value(read_attribute(core, metamodel_id, "name")))
  65. return read_root()!
  66. choice = set_pop(all_links)
  67. return choice!
  68. Element function get_full_model(model_id : String, metamodel_id : String):
  69. // TODO we are restricted to using formalisms/SimpleClassDiagrams as M3 level, through this code!
  70. Element m
  71. Element all_links
  72. String choice
  73. choice = get_instanceOf_link(model_id, metamodel_id)
  74. m = dict_create()
  75. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  76. // TODO for now this is restricted to the fixed semantics
  77. // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
  78. dict_add(m, "semantics", get_entry_id("models/conformance_mv"))
  79. if (metamodel_id == model_id):
  80. // Found the meta-circular level, so we can stop!
  81. dict_add(m, "metamodel", m)
  82. else:
  83. Element mm
  84. mm = get_full_model(metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  85. if (element_eq(mm, read_root())):
  86. return read_root()!
  87. else:
  88. dict_add(m, "metamodel", mm)
  89. if (element_neq(choice, read_root())):
  90. Element types
  91. types = allAssociationDestinations(core, choice, "typing")
  92. if (set_len(types) == 1):
  93. // Add the preferred original type mapping
  94. set_type_mapping(m, import_node(read_attribute(core, set_pop(types), "location")))
  95. else:
  96. // Start from scratch
  97. new_type_mapping(m)
  98. else:
  99. // Start from scratch
  100. new_type_mapping(m)
  101. if (find_type_mapping(m)):
  102. // TODO store the found type model somewhere
  103. return m!
  104. else:
  105. log("No type mapping could be deduced!")
  106. log("Error for " + cast_value(read_attribute(core, model_id, "name")))
  107. log(" and type " + cast_value(read_attribute(core, metamodel_id, "name")))
  108. return read_root()!
  109. Integer function get_relation_to_model(user_id : String, model_id : String):
  110. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  111. // We are the owner
  112. return 0!
  113. else:
  114. String group_id
  115. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  116. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  117. // We are in the owning group
  118. return 1!
  119. else:
  120. // We are not related whatsoever
  121. return 2!
  122. Boolean function is_admin(user_id : String):
  123. if (read_attribute(core, user_id, "admin")):
  124. return True!
  125. else:
  126. return False!
  127. Boolean function allow_read(user_id : String, model_id : String):
  128. if (is_admin(user_id)):
  129. // Is admin, so always allow
  130. return True!
  131. else:
  132. // Check permissions
  133. String permission
  134. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  135. if (bool_or(permission == "1", permission == "2")):
  136. return True!
  137. else:
  138. return False!
  139. Boolean function allow_write(user_id : String, model_id : String):
  140. if (is_admin(user_id)):
  141. // Is admin, so always allow
  142. return True!
  143. else:
  144. // Check permissions
  145. String permission
  146. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  147. if (permission == "2"):
  148. return True!
  149. else:
  150. return False!
  151. Boolean function allow_change_metadata(user_id : String, model_id : String):
  152. if (is_admin(user_id)):
  153. // Is admin, so always allow
  154. return True!
  155. else:
  156. if (get_relation_to_model(user_id, model_id) == 0):
  157. // Only owner can chmod
  158. return True!
  159. else:
  160. return False!
  161. Boolean function allow_group_modify(user_id : String, group_id : String):
  162. if (is_admin(user_id)):
  163. // Is admin, so always allow
  164. return True!
  165. else:
  166. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  167. // We are an owner
  168. return True!
  169. else:
  170. return False!
  171. Boolean function check_login(user_id : String):
  172. String password
  173. String stored_password
  174. stored_password = read_attribute(core, user_id, "password")
  175. output("Password for existing user?")
  176. password = hash(input())
  177. return password == stored_password!
  178. Void function new_task():
  179. String username
  180. String user_id
  181. String password
  182. // Load in a hard-reference to the previously created model
  183. core = import_node(core_model_location)
  184. while (True):
  185. output("Log on as which user?")
  186. username = input()
  187. user_id = get_user_id(username)
  188. if (user_id == ""):
  189. // New user
  190. // Add user to Core Formalism
  191. user_id = instantiate_node(core, "User", "")
  192. instantiate_attribute(core, user_id, "name", username)
  193. instantiate_attribute(core, user_id, "admin", False)
  194. output("This is a new user: please give password!")
  195. password = hash(input())
  196. output("Please repeat the password")
  197. if (password == hash(input())):
  198. output("Passwords match!")
  199. instantiate_attribute(core, user_id, "password", password)
  200. break!
  201. else:
  202. output("Not the same password!")
  203. else:
  204. if (check_login(user_id)):
  205. break!
  206. else:
  207. output("Wrong password!")
  208. user_function_skip_init(user_id)
  209. // User destroyed already, so just stop execution
  210. return!
  211. String function get_entry_id(name : String):
  212. Element hierarchy_split
  213. String current
  214. Integer i
  215. Element elems
  216. String current_part
  217. String elem
  218. Boolean found
  219. if (name == ""):
  220. return caches["root"]!
  221. if (dict_in(caches["models"], name)):
  222. if (dict_in(core, caches["models"])):
  223. if (full_name(caches["models"][name]) == name):
  224. return caches["models"][name]!
  225. current = get_entry_id(get_foldername(name))
  226. if (current == ""):
  227. return ""!
  228. if (current_part != ""):
  229. elems = allAssociationDestinations(core, current, "contains")
  230. while (set_len(elems) > 0):
  231. elem = set_pop(elems)
  232. dict_overwrite(caches["models"], read_attribute(core, elem, "name"), elem)
  233. if (value_eq(name, read_attribute(core, elem, "name"))):
  234. return elem!
  235. else:
  236. return current!
  237. return ""!
  238. String function get_service_id(name : String):
  239. core = import_node(core_model_location)
  240. Element services
  241. String service
  242. services = allInstances(core, "Service")
  243. while (set_len(services) > 0):
  244. service = set_pop(services)
  245. if (value_eq(read_attribute(core, service, "name"), name)):
  246. return service!
  247. return ""!
  248. String function get_user_id(name : String):
  249. Element users
  250. String user
  251. users = allInstances(core, "User")
  252. while (set_len(users) > 0):
  253. user = set_pop(users)
  254. if (value_eq(read_attribute(core, user, "name"), name)):
  255. return user!
  256. return ""!
  257. String function get_group_id(name : String):
  258. Element groups
  259. String group
  260. groups = allInstances(core, "Group")
  261. while (set_len(groups) > 0):
  262. group = set_pop(groups)
  263. if (value_eq(read_attribute(core, group, "name"), name)):
  264. return group!
  265. return ""!
  266. String function create_folders(user_id : String, folder_name : String):
  267. Element hierarchy
  268. Integer i
  269. String prev
  270. String elem
  271. String new_entry
  272. String cummul
  273. if (get_entry_id(folder_name) != ""):
  274. // Folders already exist, so don't iterate
  275. return get_entry_id(folder_name)!
  276. i = 0
  277. hierarchy = string_split(folder_name, "/")
  278. prev = get_entry_id("")
  279. cummul = ""
  280. // Go through folders first
  281. while (i < list_len(hierarchy)):
  282. elem = list_read(hierarchy, i)
  283. if (cummul == ""):
  284. cummul = elem
  285. else:
  286. cummul = string_join(cummul + "/", elem)
  287. if (get_entry_id(cummul) == ""):
  288. if (allow_write(user_id, prev)):
  289. // Element does not exist yet!
  290. new_entry = instantiate_node(core, "Folder", "")
  291. instantiate_attribute(core, new_entry, "name", cummul)
  292. instantiate_attribute(core, new_entry, "permissions", "200")
  293. instantiate_link(core, "contains", "", prev, new_entry)
  294. instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
  295. instantiate_link(core, "owner", "", new_entry, user_id)
  296. else:
  297. return read_root()!
  298. prev = get_entry_id(cummul)
  299. i = i + 1
  300. return prev!
  301. String function store_entry(model_id : String, full_name : String, user_id : String):
  302. String prev
  303. if (get_entry_id(full_name) != ""):
  304. // Delete any old models
  305. model_delete(get_entry_id(full_name))
  306. prev = create_folders(user_id, get_foldername(full_name))
  307. instantiate_link(core, "contains", "", prev, model_id)
  308. return full_name!
  309. String function export_typing(model : Element, name : String):
  310. String result
  311. result = instantiate_node(core, "TypeMapping", "")
  312. name = "type mappings/" + name
  313. // Create type mapping model
  314. String location
  315. location = "type mappings/" + cast_id(get_type_mapping(model))
  316. export_node(location, get_type_mapping(model))
  317. String instance_of
  318. name = store_entry(result, name, get_user_id("admin"))
  319. instantiate_attribute(core, result, "name", name)
  320. instantiate_attribute(core, result, "location", location)
  321. instantiate_attribute(core, result, "permissions", "200")
  322. instantiate_link(core, "owner", "", result, current_user_id)
  323. instantiate_link(core, "group", "", result, get_group_id("nobody"))
  324. instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("formalisms/TypeMapping"))
  325. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  326. return result!
  327. Void function model_create(model : Element, name : String, type_id : String, kind : String):
  328. String location
  329. String model_id
  330. String instance_of
  331. // Create model itself
  332. location = "models/" + cast_id(model)
  333. export_node(location, model["model"])
  334. model_id = instantiate_node(core, kind, "")
  335. instantiate_attribute(core, model_id, "name", store_entry(model_id, name, current_user_id))
  336. instantiate_attribute(core, model_id, "location", location)
  337. instantiate_attribute(core, model_id, "permissions", "200")
  338. instantiate_link(core, "owner", "", model_id, current_user_id)
  339. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  340. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  341. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  342. // Create type mapping model
  343. instantiate_link(core, "typing", "", instance_of, export_typing(model, name))
  344. return!
  345. Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
  346. // TODO this should be more elegant than just hiding the old elements
  347. String location
  348. String instanceOf_link
  349. location = "models/" + cast_id(model)
  350. export_node(location, model["model"])
  351. // Change location in meta-data
  352. unset_attribute(core, model_id, "location")
  353. instantiate_attribute(core, model_id, "location", location)
  354. // Update the instanceOf relation of the context in which we are working
  355. String choice
  356. choice = get_instanceOf_link(model_id, metamodel_id)
  357. if (element_neq(choice, read_root())):
  358. // There was a link, so we remove it
  359. // First remove the type mapping it referred to
  360. Element tl
  361. tl = allAssociationDestinations(core, choice, "typing")
  362. while (set_len(tl) > 0):
  363. model_delete_element(core, set_pop(tl))
  364. // Now delete the element itself
  365. model_delete_element(core, choice)
  366. // Create a new instanceOf relation now
  367. String instance_of
  368. instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
  369. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  370. instantiate_link(core, "typing", "", instance_of, export_typing(model, full_name(model_id)))
  371. return!
  372. Boolean function check_conformance(model_id : String):
  373. // TODO check if it actually conforms, considering that instanceOf link
  374. // --> in-depth check
  375. return True!
  376. Element function merge_models(models_dict : Element, operation_name : String):
  377. core = import_node(core_model_location)
  378. // 0) Find operation signature
  379. Element input_metamodels
  380. Element iter
  381. String edge
  382. String operation_id
  383. operation_id = get_entry_id(operation_name)
  384. input_metamodels = dict_create()
  385. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  386. while (set_len(iter) > 0):
  387. edge = set_pop(iter)
  388. dict_add(input_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
  389. String merged_metamodel_id
  390. String trace_link_id
  391. Element trace_links
  392. // 1) Find merged metamodel
  393. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  394. merged_metamodel_id = ""
  395. while (set_len(trace_links) > 0):
  396. trace_link_id = set_pop(trace_links)
  397. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  398. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  399. // 2) Merge source models
  400. if (merged_metamodel_id != ""):
  401. Element model_tuples
  402. Element keys
  403. String key
  404. Element mm
  405. model_tuples = set_create()
  406. keys = dict_keys(models_dict)
  407. while (set_len(keys) > 0):
  408. key = set_pop(keys)
  409. mm = get_full_model(get_entry_id(models_dict[key]), get_entry_id(input_metamodels[key]))
  410. if (element_eq(mm, read_root())):
  411. log("Signature mismatch in operation for tag " + key)
  412. output("Signature mismatch in operation for tag " + key)
  413. return read_root()!
  414. set_add_node(model_tuples, create_tuple(key, mm))
  415. Element merged_metamodel
  416. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("SimpleClassDiagrams"))
  417. if (element_eq(merged_metamodel, read_root())):
  418. log("Merged metamodel in operation is not of type SimpleClassDiagrams")
  419. output("Merged metamodel in operation is not of type SimpleClassDiagrams")
  420. return read_root()!
  421. return model_join(model_tuples, merged_metamodel, read_root())!
  422. else:
  423. return read_root()!
  424. Element function split_model(model : Element, metamodels_dict : Element):
  425. core = import_node(core_model_location)
  426. Element model_tuples
  427. Element keys
  428. String key
  429. Element mm
  430. model_tuples = set_create()
  431. keys = dict_keys(metamodels_dict)
  432. while (set_len(keys) > 0):
  433. key = set_pop(keys)
  434. mm = get_full_model(get_entry_id(metamodels_dict[key]), get_entry_id("SimpleClassDiagrams"))
  435. if (element_eq(mm, read_root())):
  436. log("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  437. output("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  438. return read_root()!
  439. set_add_node(model_tuples, create_tuple(key, mm))
  440. return model_split(model, model_tuples, read_root())!
  441. Element function get_model(model_name : String, metamodel_name : String):
  442. core = import_node(core_model_location)
  443. return get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))!
  444. Void function store_model(model_name : String, metamodel_name : String, model : Element):
  445. core = import_node(core_model_location)
  446. if (get_entry_id(model_name) == ""):
  447. // New model
  448. model_create(model, model_name, get_entry_id(metamodel_name), "Model")
  449. else:
  450. model_overwrite(model, get_entry_id(model_name), get_entry_id(metamodel_name))
  451. return!
  452. String function get_ramified_metamodel(model_name : String):
  453. core = import_node(core_model_location)
  454. String operation_id
  455. Element trace_links
  456. String merged_metamodel_id
  457. String trace_link_id
  458. String ramified_metamodel_id
  459. operation_id = get_entry_id(model_name)
  460. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  461. merged_metamodel_id = ""
  462. while (set_len(trace_links) > 0):
  463. trace_link_id = set_pop(trace_links)
  464. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  465. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  466. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  467. ramified_metamodel_id = ""
  468. while (set_len(trace_links) > 0):
  469. trace_link_id = set_pop(trace_links)
  470. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  471. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  472. return read_attribute(core, ramified_metamodel_id, "name")!
  473. return read_root()!
  474. Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
  475. // Operations are always in-place and uses only a single metamodel
  476. // Therefore, we must:
  477. // 1) Find merged metamodel
  478. // 2) Merge the different source models and retype
  479. // 3) Perform the operation on the merged model
  480. // 4) Split the resulting model based on the target formalisms; if operation successful
  481. Element input_model
  482. String trace_link_id
  483. Element merged_model
  484. String merged_metamodel_id
  485. String ramified_metamodel_id
  486. Boolean result
  487. String exact_type
  488. Element trace_links
  489. String model_ID
  490. String key
  491. Element keys
  492. Element input_keys
  493. Element output_keys
  494. Element model_tuples
  495. String metamodel_name
  496. Element metamodel
  497. String metamodel_ID
  498. Boolean tracability
  499. // 0) Find the signature of the operation
  500. Element input_metamodels
  501. Element output_metamodels
  502. Element iter
  503. String edge
  504. input_metamodels = dict_create()
  505. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  506. while (set_len(iter) > 0):
  507. edge = set_pop(iter)
  508. dict_add(input_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  509. output_metamodels = dict_create()
  510. iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
  511. while (set_len(iter) > 0):
  512. edge = set_pop(iter)
  513. dict_add(output_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  514. // 1) Find merged metamodel
  515. exact_type = read_type(core, operation_id)
  516. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  517. merged_metamodel_id = ""
  518. while (set_len(trace_links) > 0):
  519. trace_link_id = set_pop(trace_links)
  520. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  521. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  522. // 2) Merge source models
  523. if (merged_metamodel_id != ""):
  524. model_tuples = set_create()
  525. keys = dict_keys(input_models)
  526. while (set_len(keys) > 0):
  527. key = set_pop(keys)
  528. Element mm
  529. mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
  530. if (element_eq(mm, read_root())):
  531. log("Signature mismatch in operation for tag " + key)
  532. output("Signature mismatch in operation for tag " + key)
  533. return read_root()!
  534. set_add_node(model_tuples, create_tuple(key, mm))
  535. Element merged_metamodel
  536. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  537. if (element_eq(merged_metamodel, read_root())):
  538. log("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  539. output("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  540. return read_root()!
  541. merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
  542. else:
  543. if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
  544. // Just skip the merge...
  545. Element m
  546. m = get_full_model(get_entry_id(input_models[set_pop(dict_keys(input_models))]), get_entry_id(input_metamodels[set_pop(dict_keys(input_metamodels))]))
  547. if (element_eq(m, read_root())):
  548. log("Signature mismatch in operation for tag " + cast_value(set_pop(dict_keys(input_models))))
  549. output("Signature mismatch in operation for tag " + cast_value(set_pop(dict_keys(input_models))))
  550. return read_root()!
  551. merged_model = model_copy(m)
  552. elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
  553. merged_model = read_root()
  554. else:
  555. log("Could not resolve intermediate merged metamodel")
  556. output("Could not resolve intermediate merged metamodel")
  557. return read_root()!
  558. // 3) Transform
  559. if (exact_type == "ModelTransformation"):
  560. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  561. ramified_metamodel_id = ""
  562. while (set_len(trace_links) > 0):
  563. trace_link_id = set_pop(trace_links)
  564. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  565. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  566. Element operation
  567. operation = get_full_model(operation_id, ramified_metamodel_id)
  568. if (element_eq(operation, read_root())):
  569. log("Operation could not be typed by specified RAMified metamodel!")
  570. output("Operation could not be typed by specified RAMified metamodel!")
  571. return read_root()!
  572. result = transform(merged_model, operation)
  573. elif (exact_type == "ManualOperation"):
  574. output("Please perform manual operation " + cast_value(full_name(operation_id)))
  575. String model_name
  576. model_name = ""
  577. while (get_entry_id(model_name) != ""):
  578. model_name = ".tmp/" + random_string(20)
  579. model_create(merged_model, model_name, merged_metamodel_id, "Model")
  580. log("Transforming...")
  581. // We want to modify, so modify
  582. do_spawn_modify(model_name, True)
  583. merged_model = get_full_model(get_entry_id(model_name), merged_metamodel_id)
  584. //model_delete(get_entry_id(model_name))
  585. result = True
  586. elif (exact_type == "ActionLanguage"):
  587. Element func
  588. Element al
  589. al = get_full_model(operation_id, get_entry_id("formalisms/ActionLanguage"))
  590. if (element_eq(al, read_root())):
  591. log("Action Language operation not typed by ActionLanguage metamodel!")
  592. output("Action Language operation not typed by ActionLanguage metamodel!")
  593. return read_root()!
  594. func = get_func_AL_model(al)
  595. result = func(merged_model)
  596. else:
  597. log("Unknown type of operation: " + exact_type)
  598. output("Unknown type of operation: " + exact_type)
  599. return read_root()!
  600. // 4) Split in different models depending on type
  601. if (element_neq(tracability_model, read_root())):
  602. tracability = True
  603. else:
  604. tracability = False
  605. if (result):
  606. model_tuples = set_create()
  607. keys = dict_keys(output_metamodels)
  608. while (set_len(keys) > 0):
  609. key = set_pop(keys)
  610. Element mm
  611. mm = get_full_model(get_entry_id(output_metamodels[key]), get_entry_id("formalisms/SimpleClassDiagrams"))
  612. if (element_eq(mm, read_root())):
  613. log("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  614. output("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  615. return read_root()!
  616. set_add_node(model_tuples, create_tuple(key, mm))
  617. result = model_split(merged_model, model_tuples, tracability)
  618. if (tracability):
  619. Element new_tracability_model
  620. new_tracability_model = result["__tracability"]
  621. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  622. set_type_mapping(tracability_model, get_type_mapping(new_tracability_model))
  623. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  624. dict_delete(result, "__tracability")
  625. return result!
  626. else:
  627. log("Negative result of execution")
  628. return read_root()!
  629. Boolean function enact_action(pm : Element, element : String, mapping : Element):
  630. Boolean result
  631. String transformation_id
  632. Element lst
  633. String elem
  634. Element inputs
  635. Element outputs
  636. String type_name
  637. String exact_type
  638. Element trace_links
  639. Element output_mms
  640. Element consumes_link
  641. String name
  642. String value
  643. String elem_name
  644. Element keys
  645. String key
  646. String consume
  647. String produce
  648. Element output_map
  649. inputs = dict_create()
  650. outputs = dict_create()
  651. output_map = dict_create()
  652. // Read out the referenced element from the MvC
  653. transformation_id = get_entry_id(read_attribute(pm, element, "name"))
  654. // Find all input model names
  655. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  656. while (set_len(lst) > 0):
  657. consume = set_pop(lst)
  658. value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
  659. dict_add(inputs, read_attribute(pm, consume, "name"), mapping[value])
  660. // Find all output model names and their metamodel
  661. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  662. while (set_len(lst) > 0):
  663. produce = set_pop(lst)
  664. elem = readAssociationDestination(pm, produce)
  665. type_name = read_attribute(pm, elem, "type")
  666. elem_name = read_attribute(pm, elem, "name")
  667. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  668. dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
  669. if read_type(core, transformation_id) == "ActionLanguage":
  670. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  671. output("Success: ready for AL execution")
  672. elif read_type(core, transformation_id) == "ManualOperation":
  673. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  674. output("Success: ready for MANUAL execution")
  675. else:
  676. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  677. output("Success: ready for MT execution")
  678. result = execute_operation(transformation_id, inputs, read_root())
  679. if (element_eq(result, read_root())):
  680. // Something went wrong!
  681. return False!
  682. else:
  683. keys = dict_keys(outputs)
  684. while (set_len(keys) > 0):
  685. key = set_pop(keys)
  686. if (get_entry_id(output_map[key]) == ""):
  687. // New model
  688. model_create(result[key], output_map[key], get_entry_id(outputs[key]), "Model")
  689. else:
  690. model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
  691. return True!
  692. Element function PM_signature(pm : Element):
  693. Element all_data
  694. Element result
  695. String entry
  696. result = dict_create()
  697. all_data = allInstances(pm, "Data")
  698. while (set_len(all_data) > 0):
  699. entry = set_pop(all_data)
  700. dict_add(result, cast_string(read_attribute(pm, entry, "name")), cast_string(read_attribute(pm, entry, "type")))
  701. return result!
  702. Void function enact_PM_activity(activity_to_task : Element, task_to_result : Element, pm : Element, element : String, mapping : Element):
  703. Boolean result
  704. pm_tasks = activity_to_task
  705. set_add(activity_to_task[element], get_taskname())
  706. result = enact_action(pm, element, mapping)
  707. dict_add_fast(task_to_result, get_taskname(), result)
  708. return!
  709. Void function enact_PM(pm : Element, mapping : Element):
  710. Element worklist
  711. String element
  712. String type
  713. Boolean result
  714. Element tuple
  715. Element counters
  716. Element join_nodes
  717. Element exec_nodes
  718. Element keys
  719. String key
  720. output("Success")
  721. // For all entries in the signature, not in the mapping, we add a mock location
  722. Element signature
  723. String mock_location
  724. Element mock_locations
  725. mock_locations = set_create()
  726. signature = PM_signature(pm)
  727. keys = dict_keys(signature)
  728. while (set_len(keys) > 0):
  729. key = set_pop(keys)
  730. if (bool_not(dict_in(mapping, key))):
  731. // Add mock location
  732. mock_location = ""
  733. while (get_entry_id(mock_location) != ""):
  734. mock_location = ".tmp/" + random_string(10)
  735. dict_add(mapping, key, mock_location)
  736. set_add(mock_locations, mock_location)
  737. // Initialize Join counters
  738. counters = dict_create()
  739. join_nodes = allInstances(pm, "Join")
  740. while (set_len(join_nodes) > 0):
  741. dict_add(counters, set_pop(join_nodes), 0)
  742. // Initialize activity to task dictionary with empty sets
  743. Element activity_to_task
  744. Element task_to_activity
  745. Element task_to_result
  746. activity_to_task = dict_create()
  747. task_to_activity = dict_create()
  748. task_to_result = dict_create()
  749. exec_nodes = allInstances(pm, "Exec")
  750. while (set_len(exec_nodes) > 0):
  751. dict_add(activity_to_task, set_pop(exec_nodes), set_create())
  752. // Create the worklist with the Start instance as first element
  753. worklist = set_create()
  754. set_add(worklist, set_pop(allInstances(pm, "Start")))
  755. // Keep on iterating until we reach finish
  756. while (True):
  757. // Check if there are PM elements to expand
  758. if (set_len(worklist) > 0):
  759. // There is something we can do, so do it!
  760. element = set_pop(worklist)
  761. // Find the type (to see what to do with it)
  762. // this does not yet yield the type of transformation, if it is an Execution
  763. type = read_type(pm, element)
  764. // Some types have nothing to do, such as start and fork
  765. // Therefore, they are not mentioned in the following conditional
  766. if (type == "Finish"):
  767. // We have finished, so terminate
  768. break!
  769. elif (type == "Join"):
  770. // Only do this if all dependencies are fullfilled
  771. // So add to the counter of this Join
  772. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  773. // Now check whether we have enough tokens to execute the Join itself
  774. Integer required
  775. Integer got
  776. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  777. got = counters[element]
  778. if (got == required):
  779. // Reset counter to 0
  780. dict_overwrite(counters, element, 0)
  781. // And continue
  782. else:
  783. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  784. continue!
  785. elif (type == "Exec"):
  786. // Execute a transformation
  787. // This the difficult part!
  788. Element args
  789. String taskname
  790. args = list_create()
  791. list_append(args, activity_to_task)
  792. list_append(args, task_to_result)
  793. list_append(args, pm)
  794. list_append(args, element)
  795. list_append(args, mapping)
  796. taskname = spawn(enact_PM_activity, args)
  797. output(taskname + " : " + cast_string(read_attribute(pm, element, "name")))
  798. dict_add(task_to_activity, taskname, element)
  799. continue!
  800. // We have finished the execution, so add all outgoing edges to the worklist
  801. Element all_next
  802. all_next = allAssociationDestinations(pm, element, "Next")
  803. String next
  804. while (set_len(all_next) > 0):
  805. next = set_pop(all_next)
  806. set_add(worklist, next)
  807. else:
  808. // No new tasks to spawn, so go and check on all running activities
  809. if (dict_len(task_to_result) > 0):
  810. // There are outputs!
  811. Element keys
  812. String task
  813. keys = dict_keys(task_to_result)
  814. while (set_len(keys) > 0):
  815. task = set_pop(keys)
  816. result = task_to_result[task]
  817. Element all_next
  818. all_next = allAssociationDestinations(pm, task_to_activity[task], "Next")
  819. String next
  820. while (set_len(all_next) > 0):
  821. next = set_pop(all_next)
  822. if (read_type(pm, next) == "Decision"):
  823. // Got decision node, so expand immediately
  824. if (result):
  825. set_add(worklist, set_pop(allAssociationDestinations(pm, next, "Then")))
  826. else:
  827. set_add(worklist, set_pop(allAssociationDestinations(pm, next, "Else")))
  828. else:
  829. // Other node, so just append for further processing
  830. set_add(worklist, next)
  831. set_remove(activity_to_task[task_to_activity[task]], task)
  832. dict_delete(task_to_result, task)
  833. dict_delete(task_to_activity, task)
  834. else:
  835. // No finished activities either, so we sleep for some time
  836. sleep(0.1)
  837. // Remove all mock locations again
  838. while (set_len(mock_locations) > 0):
  839. model_delete(get_entry_id(set_pop(mock_locations)))
  840. return !
  841. String function cmd_help():
  842. String result
  843. result = ""
  844. result = result + ("Model operations\n")
  845. result = result + (" model_add -- Add a new model\n")
  846. result = result + (" model_modify -- Modify an existing model\n")
  847. result = result + (" model_list -- List all models\n")
  848. result = result + (" model_list_full -- List all models with full info\n")
  849. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  850. result = result + (" model_render -- Render a given model with a specified mapper\n")
  851. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  852. result = result + ("\n")
  853. result = result + ("Transformation-specific operations\n")
  854. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  855. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  856. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  857. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  858. result = result + (" transformation_list -- List all model transformations\n")
  859. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  860. result = result + (" transformation_detail -- List transformation details\n")
  861. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  862. result = result + ("\n")
  863. result = result + ("Process operations\n")
  864. result = result + (" process_execute -- Execute a process model\n")
  865. result = result + ("\n")
  866. result = result + ("Model permission operations\n")
  867. result = result + (" permission_modify -- Change model permissions\n")
  868. result = result + (" permission_owner -- Change model owner\n")
  869. result = result + (" permission_group -- Change model group\n")
  870. result = result + ("\n")
  871. result = result + ("Group operations\n")
  872. result = result + (" group_create -- Create a group\n")
  873. result = result + (" group_delete -- Delete a group\n")
  874. result = result + (" group_owner_add -- Add group owner\n")
  875. result = result + (" group_owner_delete -- Remove group owner\n")
  876. result = result + (" group_join -- Add someone to your group\n")
  877. result = result + (" group_kick -- Kick someone from your group\n")
  878. result = result + (" group_list -- List all groups you are a member of\n")
  879. result = result + ("\n")
  880. if (is_admin(current_user_id)):
  881. result = result + ("Admin operations\n")
  882. result = result + (" admin_promote -- Promote a user to admin status\n")
  883. result = result + (" admin_demote -- Demote a user to normal status\n")
  884. result = result + ("\n")
  885. result = result + ("General operations\n")
  886. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  887. result = result + (" exit -- Kill the current task, while retaining user\n")
  888. return result!
  889. String function cmd_model_add(type : String, name : String, code : String):
  890. // Model addition operation, which uses model upload commands of the compiler
  891. String location
  892. String type_id
  893. Element new_model
  894. String new_model_id
  895. type_id = get_entry_id(type)
  896. if (type_id != ""):
  897. // Type exists
  898. if (allow_read(current_user_id, type_id)):
  899. // And is readable
  900. if (get_entry_id(get_foldername(name)) != ""):
  901. // Folder doesn't exist yet!
  902. if (allow_write(current_user_id, get_entry_id(get_foldername(name)))):
  903. // Folder is writable
  904. if (get_entry_id(name) == ""):
  905. // Model doesn't exist yet
  906. Element mm
  907. mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  908. if (element_eq(mm, read_root())):
  909. return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
  910. new_model = compile_model(code, mm)
  911. if (element_eq(new_model, read_root())):
  912. return "Compilation error"!
  913. model_create(new_model, name, type_id, "Model")
  914. return "Success"!
  915. else:
  916. return "Model exists: " + name!
  917. else:
  918. return "Permission denied to folder: " + get_foldername(name)!
  919. else:
  920. return "No such folder: " + get_foldername(name)!
  921. else:
  922. return "Permission denied to model: " + type!
  923. else:
  924. return "Model not found: " + type!
  925. String function cmd_process_execute(process : String, mapping : Element):
  926. // Execute a process model until it reaches termination
  927. String process_id
  928. process_id = get_entry_id(process)
  929. if (process_id != ""):
  930. if (allow_read(current_user_id, process_id)):
  931. Element pm
  932. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  933. if (element_eq(pm, read_root())):
  934. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  935. enact_PM(pm, mapping)
  936. return "Success"!
  937. else:
  938. return "Permission denied to model: " + process!
  939. else:
  940. return "Model not found: " + process!
  941. String function cmd_process_signature(process : String):
  942. // Execute a process model until it reaches termination
  943. String process_id
  944. String result
  945. Element signature
  946. Element keys
  947. String key
  948. process_id = get_entry_id(process)
  949. if (process_id != ""):
  950. if (allow_read(current_user_id, process_id)):
  951. Element pm
  952. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  953. if (element_eq(pm, read_root())):
  954. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  955. result = "Success: "
  956. signature = PM_signature(pm)
  957. keys = dict_keys(signature)
  958. while (set_len(keys) > 0):
  959. key = set_pop(keys)
  960. result = result + key + " : " + cast_string(signature[key]) + "\n"
  961. return result!
  962. else:
  963. return "Permission denied to model: " + process!
  964. else:
  965. return "Model not found: " + process!
  966. String function cmd_transformation_between(source_dict : String, target_dict : String):
  967. Element result
  968. Element subresult
  969. String tag
  970. String mm
  971. String mm_id
  972. Element links
  973. String link
  974. Element keys
  975. result = allInstances(core, "Transformation")
  976. // Iterate over all inputs
  977. keys = dict_keys(source_dict)
  978. while (set_len(keys) > 0):
  979. subresult = set_create()
  980. tag = set_pop(keys)
  981. mm = source_dict[tag]
  982. mm_id = get_entry_id(mm)
  983. if (mm_id != ""):
  984. links = allIncomingAssociationInstances(core, mm_id, "transformInput")
  985. while (set_len(links) > 0):
  986. link = set_pop(links)
  987. if (value_eq(read_attribute(core, link, "name"), tag)):
  988. // Correct tag, so make transformation a possibility
  989. set_add(subresult, readAssociationSource(core, link))
  990. else:
  991. return "Model not found: " + mm!
  992. // Got a set of subresults now, which we use to find the overlap
  993. result = set_overlap(result, subresult)
  994. keys = dict_keys(target_dict)
  995. while (set_len(keys) > 0):
  996. subresult = set_create()
  997. tag = set_pop(keys)
  998. mm = target_dict[tag]
  999. mm_id = get_entry_id(mm)
  1000. if (mm_id != ""):
  1001. links = allIncomingAssociationInstances(core, mm_id, "transformOutput")
  1002. while (set_len(links) > 0):
  1003. link = set_pop(links)
  1004. if (value_eq(read_attribute(core, link, "name"), tag)):
  1005. // Correct tag, so make transformation a possibility
  1006. set_add(subresult, readAssociationSource(core, link))
  1007. else:
  1008. return "Model not found: " + mm!
  1009. // Got a set of subresults now, which we use to find the overlap
  1010. result = set_overlap(result, subresult)
  1011. String r
  1012. String transformation
  1013. r = "Success: "
  1014. while (set_len(result) > 0):
  1015. transformation = set_pop(result)
  1016. if (allow_read(current_user_id, transformation)):
  1017. r = r + string_join(full_name(transformation), "\n")
  1018. return r!
  1019. String function cmd_model_rendered(model_name : String, mapper_name : String):
  1020. Element trace_links
  1021. String rendered
  1022. String trace_link_id
  1023. String allowed_rendered
  1024. Element trace_links_2
  1025. String trace_link_2_id
  1026. allowed_rendered = "Success: "
  1027. trace_links = allOutgoingAssociationInstances(core, get_entry_id(model_name), "tracability")
  1028. while (set_len(trace_links) > 0):
  1029. trace_link_id = set_pop(trace_links)
  1030. if (value_eq(read_attribute(core, trace_link_id, "type"), "CS_perceptualized")):
  1031. rendered = readAssociationDestination(core, trace_link_id)
  1032. trace_links_2 = allOutgoingAssociationInstances(core, rendered, "tracability")
  1033. while (set_len(trace_links_2) > 0):
  1034. trace_link_2_id = set_pop(trace_links_2)
  1035. if (value_eq(read_attribute(core, readAssociationDestination(core, trace_link_2_id), "name"), mapper_name)):
  1036. if (value_eq(read_attribute(core, trace_link_2_id, "type"), "CS_mapper")):
  1037. allowed_rendered = string_join(allowed_rendered, read_attribute(core, rendered, "name")) + "\n"
  1038. return allowed_rendered!
  1039. String function cmd_model_render(model_name : String, mapper_name : String, rendered_name : String):
  1040. String model_ID
  1041. String mapper_ID
  1042. String tracability_name
  1043. Element inputs
  1044. Element output_map
  1045. Element rendered_model
  1046. Element tracability_model
  1047. Element result
  1048. Element out_links
  1049. String link
  1050. String ID_rendered_M
  1051. String ID_rendered_MM
  1052. String ID_SCD
  1053. String ID_tracability_MM
  1054. String ID_tracability_M
  1055. model_ID = get_entry_id(model_name)
  1056. if (model_ID != ""):
  1057. mapper_ID = get_entry_id(mapper_name)
  1058. if (allow_read(current_user_id, model_ID)):
  1059. if (mapper_ID != ""):
  1060. if (allow_read(current_user_id, mapper_ID)):
  1061. // Everything is fine; start the actual operation
  1062. // Find metamodel to render to
  1063. tracability_name = "tracability/" + rendered_name
  1064. // Take the abstract syntax model and the previously rendered model
  1065. inputs = dict_create()
  1066. dict_add(inputs, "abstract", model_name)
  1067. dict_add(inputs, "rendered", rendered_name)
  1068. // Fetch the output types
  1069. output_map = dict_create()
  1070. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  1071. while(set_len(out_links) > 0):
  1072. link = set_pop(out_links)
  1073. dict_add(output_map, read_attribute(core, link, "name"), full_name(readAssociationDestination(core, link)))
  1074. ID_rendered_MM = get_entry_id(output_map["rendered"])
  1075. ID_SCD = get_entry_id("formalisms/SimpleClassDiagrams")
  1076. ID_tracability_MM = get_entry_id("formalisms/Tracability")
  1077. ID_tracability_M = get_entry_id(tracability_name)
  1078. ID_rendered_M = get_entry_id(rendered_name)
  1079. if (ID_rendered_M == ""):
  1080. // Instantiate
  1081. Element rendered
  1082. rendered = get_full_model(ID_rendered_MM, ID_SCD)
  1083. if (element_eq(rendered, read_root())):
  1084. return "Rendered metamodel doesn't conform to formalisms/SimpleClassDiagrams"!
  1085. rendered_model = instantiate_model(rendered)
  1086. model_create(rendered_model, rendered_name, ID_rendered_MM, "Model")
  1087. // Tracability model won't exist either
  1088. tracability_model = instantiate_model(get_full_model(ID_tracability_MM, ID_SCD))
  1089. model_create(tracability_model, tracability_name, ID_tracability_MM, "Model")
  1090. ID_rendered_M = get_entry_id(rendered_name)
  1091. ID_tracability_M = get_entry_id(tracability_name)
  1092. else:
  1093. // Read out tracability model
  1094. tracability_model = get_full_model(ID_tracability_M, ID_tracability_MM)
  1095. if (element_eq(tracability_model, read_root())):
  1096. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1097. // Do the operation itself!
  1098. result = execute_operation(mapper_ID, inputs, tracability_model)
  1099. // Overwrite the previous rendered model
  1100. model_overwrite(result["rendered"], ID_rendered_M, ID_rendered_MM)
  1101. // Tracability updated in-place
  1102. model_overwrite(tracability_model, ID_tracability_M, ID_tracability_MM)
  1103. if (element_eq(tracability_model, read_root())):
  1104. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1105. // Link all information in the megamodel
  1106. String tr_link
  1107. tr_link = instantiate_link(core, "tracability", "", get_entry_id(model_name), ID_rendered_M)
  1108. instantiate_attribute(core, tr_link, "type", "CS_perceptualized")
  1109. tr_link = instantiate_link(core, "tracability", "", ID_rendered_M, get_entry_id(mapper_name))
  1110. instantiate_attribute(core, tr_link, "type", "CS_mapper")
  1111. // Output the resulting model
  1112. String value
  1113. value = JSON_print(result["rendered"])
  1114. return ("Success: " + value) !
  1115. else:
  1116. return "Permission denied to model: " + mapper_name!
  1117. else:
  1118. return "Model not found: " + mapper_name!
  1119. else:
  1120. return "Permission denied to model: " + model_name!
  1121. else:
  1122. return "Model not found: " + model_name!
  1123. Boolean function do_spawn_modify(model_name : String, write : Boolean):
  1124. log("Spawned task for " + model_name)
  1125. log("Taskname: " + get_taskname())
  1126. output("Please edit this model before sending next input: " + model_name)
  1127. log("OK, waiting for input")
  1128. input()
  1129. log("SPAWN MODIFY ENDED")
  1130. return False!
  1131. Boolean function do_spawn_activity(transformation_id : String, tracability_name : String, inputs : Element, outputs : Element, output_map : Element):
  1132. Element lst
  1133. Element returnvalue
  1134. String taskname
  1135. lst = list_create()
  1136. returnvalue = set_create()
  1137. list_append(lst, returnvalue)
  1138. list_append(lst, transformation_id)
  1139. list_append(lst, tracability_name)
  1140. list_append(lst, inputs)
  1141. list_append(lst, outputs)
  1142. list_append(lst, output_map)
  1143. taskname = spawn(spawn_activity, lst)
  1144. output("Spawned activity on task: " + taskname)
  1145. log("Spawned activity")
  1146. while (set_len(returnvalue) == 0):
  1147. sleep(0.1)
  1148. log("Activity terminated!")
  1149. output("Finished task: " + taskname)
  1150. return cast_boolean(set_pop(returnvalue))!
  1151. Void function spawn_activity(returnvalue : Element, transformation_id : String, tracability_name : String, inputs : Element, outputs : Element, output_map : Element):
  1152. Element result
  1153. Element keys
  1154. String key
  1155. if (read_type(core, transformation_id) == "ActionLanguage"):
  1156. output("Success: ready for AL execution")
  1157. elif (read_type(core, transformation_id) == "ManualOperation"):
  1158. output("Success: ready for MANUAL execution")
  1159. else:
  1160. output("Success: ready for MT execution")
  1161. // Do tracability
  1162. Element tracability_model
  1163. if (tracability_name != ""):
  1164. // Check if exists
  1165. if (get_entry_id(tracability_name) == ""):
  1166. // No, so create
  1167. tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
  1168. model_create(tracability_model, tracability_name, get_entry_id("formalisms/Tracability"), "Model")
  1169. else:
  1170. // Yes, so read out
  1171. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1172. else:
  1173. tracability_model = read_root()
  1174. result = execute_operation(transformation_id, inputs, tracability_model)
  1175. // Flush tracability again, just to be sure
  1176. if (tracability_name != ""):
  1177. model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1178. // Now write out the models again
  1179. if (element_eq(result, read_root())):
  1180. // Something went wrong!
  1181. set_add(returnvalue, False)
  1182. output("Failure")
  1183. else:
  1184. keys = dict_keys(outputs)
  1185. while (set_len(keys) > 0):
  1186. key = set_pop(keys)
  1187. log("Writing away model with key " + cast_string(key))
  1188. log("Output map: " + dict_to_string(output_map))
  1189. log("Outputs: " + dict_to_string(outputs))
  1190. if (get_entry_id(outputs[key]) == ""):
  1191. // New model
  1192. model_create(result[key], outputs[key], get_entry_id(output_map[key]), "Model")
  1193. else:
  1194. model_overwrite(result[key], get_entry_id(outputs[key]), get_entry_id(output_map[key]))
  1195. set_add(returnvalue, True)
  1196. output("Success")
  1197. sleep(5)
  1198. return!
  1199. String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element, tracability_name : String):
  1200. // Execute a transformation, whatever type it is
  1201. // First we detect the type, so we know how to prepare for invocation
  1202. String transformation_id
  1203. String exact_type
  1204. Element sources
  1205. Element targets
  1206. String source
  1207. String target
  1208. Element inputs
  1209. Element outputs
  1210. Element output_map
  1211. Element trace_links
  1212. String target_model_name
  1213. String source_model_name
  1214. String source_model_ID
  1215. String assoc_name
  1216. transformation_id = get_entry_id(transformation_name)
  1217. if (transformation_id != ""):
  1218. if (allow_read(current_user_id, transformation_id)):
  1219. if (is_nominal_instance(core, transformation_id, "Transformation")):
  1220. // Read out source and target links
  1221. inputs = dict_create()
  1222. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  1223. while (set_len(sources) > 0):
  1224. source = set_pop(sources)
  1225. assoc_name = read_attribute(core, source, "name")
  1226. if (dict_in(source_models, assoc_name)):
  1227. source_model_name = source_models[assoc_name]
  1228. else:
  1229. return "Source model not bound: " + assoc_name!
  1230. source_model_ID = get_entry_id(source_model_name)
  1231. if (source_model_ID != ""):
  1232. if (allow_read(current_user_id, source_model_ID)):
  1233. // Check for conformance to the requested metamodel
  1234. dict_add(inputs, assoc_name, source_model_name)
  1235. continue!
  1236. else:
  1237. return "Permission denied to model: " + source_model_name!
  1238. else:
  1239. return "Model not found: " + source_model_name!
  1240. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  1241. outputs = dict_create()
  1242. output_map = dict_create()
  1243. while (set_len(targets) > 0):
  1244. target = set_pop(targets)
  1245. assoc_name = read_attribute(core, target, "name")
  1246. if (dict_in(target_models, assoc_name)):
  1247. target_model_name = target_models[assoc_name]
  1248. if (get_entry_id(target_model_name) == ""):
  1249. // Doesn't exist yet, so we can easily create
  1250. if (get_entry_id(get_foldername(target_model_name)) == ""):
  1251. return "Folder not found: " + get_foldername(target_model_name)!
  1252. else:
  1253. if (allow_write(current_user_id, get_entry_id(get_foldername(target_model_name)))):
  1254. dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
  1255. dict_add(outputs, assoc_name, target_model_name)
  1256. else:
  1257. return "Permission denied to folder: " + get_foldername(target_model_name)!
  1258. else:
  1259. // Already exists, so we need to check for write access
  1260. if (allow_write(current_user_id, get_entry_id(target_model_name))):
  1261. dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
  1262. dict_add(outputs, assoc_name, target_model_name)
  1263. else:
  1264. return "Permission denied to model: " + target_model_name!
  1265. if (do_spawn_activity(transformation_id, tracability_name, inputs, outputs, output_map)):
  1266. return "Success"!
  1267. else:
  1268. return "Failure"!
  1269. else:
  1270. return "Model is not executable: " + transformation_name!
  1271. else:
  1272. return "Permission denied to model: " + transformation_name!
  1273. else:
  1274. return "Model not found: " + transformation_name!
  1275. String function cmd_verify(model_name : String, metamodel_name : String):
  1276. // Check whether a model conforms to its specification (with the selected type mapping)
  1277. String model_id
  1278. String result
  1279. Element inputs
  1280. model_id = get_entry_id(model_name)
  1281. if (model_id != ""):
  1282. if (allow_read(current_user_id, model_id)):
  1283. if (get_entry_id(metamodel_name) != ""):
  1284. if (allow_read(current_user_id, get_entry_id(metamodel_name))):
  1285. Element m
  1286. m = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  1287. if (element_eq(m, read_root())):
  1288. return "No conformance relation can be found between these models"!
  1289. return string_join("Success: ", conformance_scd(m))!
  1290. else:
  1291. return "Permission denied to model: " + metamodel_name!
  1292. else:
  1293. return "Model not found: " + metamodel_name!
  1294. else:
  1295. return "Permission denied to model: " + model_name!
  1296. else:
  1297. return "Model not found: " + model_name!
  1298. String function cmd_model_overwrite(model_name : String, metamodel_name : String):
  1299. // Overwrites an existing model without changing any metadata
  1300. String model_id
  1301. String type_id
  1302. Element new_model
  1303. model_id = get_entry_id(model_name)
  1304. if (model_id != ""):
  1305. if (allow_write(current_user_id, model_id)):
  1306. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1307. if (allow_read(current_user_id, type_id)):
  1308. Element mm
  1309. mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1310. if (element_eq(mm, read_root())):
  1311. return "Metamodel does not conform to formalisms/SimpleClassDiagrams: " + metamodel_name!
  1312. log("Overwriting...")
  1313. output("Waiting for model constructors...")
  1314. new_model = compile_model(input(), mm)
  1315. if (element_eq(new_model, read_root())):
  1316. return "Compilation error"!
  1317. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  1318. return "Success"!
  1319. else:
  1320. return string_join("Permission denied to model: ", full_name(type_id))!
  1321. else:
  1322. return "Permission denied to model: " + model_name!
  1323. else:
  1324. return "Model not found: " + model_name!
  1325. String function cmd_model_modify(model_name : String, metamodel_name : String):
  1326. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  1327. String model_id
  1328. String type_id
  1329. model_id = get_entry_id(model_name)
  1330. if (model_id != ""):
  1331. if (allow_read(current_user_id, model_id)):
  1332. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1333. if (allow_read(current_user_id, type_id)):
  1334. Element new_model
  1335. new_model = get_full_model(model_id, get_entry_id(metamodel_name))
  1336. if (element_eq(new_model, read_root())):
  1337. return "No conformance relation can be found between these models"!
  1338. modify(new_model, allow_write(current_user_id, model_id))
  1339. if (allow_write(current_user_id, model_id)):
  1340. // Overwrite the modified model
  1341. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  1342. return "Success"!
  1343. else:
  1344. return string_join("Permission denied to model: ", full_name(type_id))!
  1345. else:
  1346. return "Permission denied to model: " + model_name!
  1347. else:
  1348. return "Model not found: " + model_name!
  1349. Void function model_delete(model_id : String):
  1350. if (read_type(core, model_id) == "Folder"):
  1351. // Folder, so delete all containing elements as well!
  1352. Element elems
  1353. elems = allAssociationDestinations(core, model_id, "contains")
  1354. while (set_len(elems) > 0):
  1355. model_delete(set_pop(elems))
  1356. // Delete self
  1357. model_delete_element(core, model_id)
  1358. else:
  1359. // Only delete this element
  1360. model_delete_element(core, model_id)
  1361. return!
  1362. String function cmd_model_delete(model_name : String):
  1363. String model_id
  1364. model_id = get_entry_id(model_name)
  1365. if (model_id != ""):
  1366. if (allow_write(current_user_id, model_id)):
  1367. model_delete(model_id)
  1368. return "Success"!
  1369. else:
  1370. return "Permission denied to model: " + model_name!
  1371. else:
  1372. return "Model not found: " + model_name!
  1373. String function cmd_model_list(location : String):
  1374. // List all models
  1375. if (get_entry_id(location) != ""):
  1376. if (allow_read(current_user_id, get_entry_id(location))):
  1377. Element models
  1378. String result
  1379. String m
  1380. result = "Success: "
  1381. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1382. while (set_len(models) > 0):
  1383. m = set_pop(models)
  1384. if (is_nominal_instance(core, m, "Folder")):
  1385. result = result + (get_filename(read_attribute(core, m, "name")) + "/\n")
  1386. else:
  1387. result = result + (get_filename(read_attribute(core, m, "name")) + "\n")
  1388. return result!
  1389. else:
  1390. return "Permission denied to folder: " + location!
  1391. else:
  1392. return "Location not found: " + location!
  1393. String function cmd_model_list_full(location : String):
  1394. // List all models with full info
  1395. if (get_entry_id(location) != ""):
  1396. if (allow_read(current_user_id, get_entry_id(location))):
  1397. Element models
  1398. String m
  1399. String permissions
  1400. String owner
  1401. String group
  1402. String name
  1403. String type
  1404. String result
  1405. result = "Success: "
  1406. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1407. while (set_len(models) > 0):
  1408. m = set_pop(models)
  1409. permissions = read_attribute(core, m, "permissions")
  1410. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1411. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1412. if (is_nominal_instance(core, m, "Folder")):
  1413. name = get_filename(read_attribute(core, m, "name")) + "/"
  1414. else:
  1415. name = get_filename(read_attribute(core, m, "name"))
  1416. result = result + permissions + " " + owner + " " + group + " " + name + "\n"
  1417. return result!
  1418. else:
  1419. return "Permission denied to folder: " + location!
  1420. else:
  1421. return "Location not found: " + location!
  1422. String function cmd_transformation_add_MANUAL(source_models : Element, target_models : Element, operation_name : String):
  1423. return transformation_add(source_models, target_models, operation_name, "manual")!
  1424. String function cmd_transformation_add_AL(source_models : Element, target_models : Element, operation_name : String):
  1425. return transformation_add(source_models, target_models, operation_name, "actionlanguage")!
  1426. String function transformation_add(source_models : Element, target_models : Element, operation_name : String, operation_type : String):
  1427. // Add a manual transformation model
  1428. String model_id
  1429. Element models
  1430. Element source
  1431. Element target
  1432. String name
  1433. Element all_formalisms
  1434. Element formalism_map
  1435. Element merged_formalism
  1436. String merged_formalism_id
  1437. String source_formalism_id
  1438. String tracability_link
  1439. Element fused
  1440. Element keys
  1441. String key
  1442. Element mm
  1443. source = dict_create()
  1444. target = dict_create()
  1445. all_formalisms = set_create()
  1446. formalism_map = set_create()
  1447. fused = set_create()
  1448. keys = dict_keys(source_models)
  1449. while (set_len(keys) > 0):
  1450. key = set_pop(keys)
  1451. name = source_models[key]
  1452. model_id = get_entry_id(name)
  1453. if (model_id != ""):
  1454. if (allow_read(current_user_id, model_id)):
  1455. if (bool_not(dict_in(source, key))):
  1456. dict_add(source, key, model_id)
  1457. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1458. if (element_eq(mm, read_root())):
  1459. return "Transformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1460. if (bool_not(set_in(fused, key))):
  1461. set_add_node(formalism_map, create_tuple(key, mm))
  1462. set_add(fused, key)
  1463. if (bool_not(set_in(all_formalisms, model_id))):
  1464. set_add(all_formalisms, model_id)
  1465. else:
  1466. return "Name already selected for source: " + key!
  1467. else:
  1468. return "Permission denied to model: " + name!
  1469. else:
  1470. return "Model not found: " + name!
  1471. keys = dict_keys(target_models)
  1472. while (set_len(keys) > 0):
  1473. key = set_pop(keys)
  1474. name = target_models[key]
  1475. model_id = get_entry_id(name)
  1476. if (model_id != ""):
  1477. if (allow_read(current_user_id, model_id)):
  1478. if (bool_not(dict_in(target, key))):
  1479. dict_add(target, key, model_id)
  1480. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1481. if (element_eq(mm, read_root())):
  1482. return "Transformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1483. if (bool_not(set_in(fused, key))):
  1484. set_add_node(formalism_map, create_tuple(key, mm))
  1485. set_add(fused, key)
  1486. if (bool_not(set_in(all_formalisms, model_id))):
  1487. set_add(all_formalisms, model_id)
  1488. else:
  1489. return "Name already selected for target: " + key!
  1490. else:
  1491. return "Permission denied to model: " + name!
  1492. else:
  1493. return "Model not found: " + name!
  1494. if (get_entry_id(operation_name) == ""):
  1495. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1496. // New location is available, so write
  1497. if (dict_len(source_models) + dict_len(target_models) > 0):
  1498. merged_formalism = model_fuse(formalism_map)
  1499. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1500. do_spawn_modify("merged/" + operation_name, True)
  1501. merged_formalism = get_full_model(get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1502. if (operation_type == "manual"):
  1503. if (dict_len(source_models) + dict_len(target_models) == 0):
  1504. return "Manual activity needs at least one formalism in its input or output signature!"!
  1505. // Finished with all information, now create the model itself!
  1506. Element m
  1507. m = get_full_model(get_entry_id("formalisms/ManualOperation"), get_entry_id("formalisms/SimpleClassDiagrams"))
  1508. if (element_eq(m, read_root())):
  1509. log("Error when opening ManualOperation: no conformance relation found")
  1510. return "Error when opening ManualOperation: no conformance relation found"!
  1511. model_create(instantiate_model(m), operation_name, get_entry_id("formalisms/ManualOperation"), "ManualOperation")
  1512. model_id = get_entry_id(operation_name)
  1513. elif (operation_type == "actionlanguage"):
  1514. // Finished with all information, now create the model itself!
  1515. output("Waiting for code constructors...")
  1516. Element compiled
  1517. compiled = compile_code(input())
  1518. if (element_eq(compiled, read_root())):
  1519. return "Compilation error"!
  1520. add_code_model(get_full_model(get_entry_id("formalisms/ActionLanguage"), get_entry_id("formalisms/SimpleClassDiagrams")), "AL/" + operation_name, compiled)
  1521. model_create(import_node("AL/" + operation_name), operation_name, get_entry_id("formalisms/ActionLanguage"), "ActionLanguage")
  1522. model_id = get_entry_id(operation_name)
  1523. if (dict_len(source_models) + dict_len(target_models) > 0):
  1524. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1525. // Add tracability links at this level
  1526. while (set_len(all_formalisms) > 0):
  1527. source_formalism_id = set_pop(all_formalisms)
  1528. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1529. instantiate_attribute(core, tracability_link, "type", "merged")
  1530. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1531. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1532. // Extend metadata with info on source and target
  1533. String link
  1534. String dst
  1535. keys = dict_keys(source)
  1536. while (set_len(keys) > 0):
  1537. key = set_pop(keys)
  1538. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1539. instantiate_attribute(core, link, "name", key)
  1540. keys = dict_keys(target)
  1541. while (set_len(keys) > 0):
  1542. key = set_pop(keys)
  1543. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1544. instantiate_attribute(core, link, "name", key)
  1545. return "Success"!
  1546. else:
  1547. return "Model exists: " + operation_name!
  1548. String function cmd_transformation_add_MT(source_models : Element, target_models : Element, operation_name : String):
  1549. // Add a model transformation model
  1550. // Just a usual model instantiation, but need to add the source and target links based on user info
  1551. String ramified_metamodel_id
  1552. Element ramified_metamodel
  1553. String model_id
  1554. Element models
  1555. Element links
  1556. String link_id
  1557. Element supported
  1558. Element source
  1559. Element target
  1560. String name
  1561. String new_model_id
  1562. String merged_link_id
  1563. Element links_merged
  1564. String merged_formalism
  1565. Element keys
  1566. String key
  1567. Element mm
  1568. Element to_ramify
  1569. String source_formalism_id
  1570. String merged_formalism_id
  1571. String tracability_link
  1572. source = dict_create()
  1573. target = dict_create()
  1574. to_ramify = set_create()
  1575. if (dict_len(source_models) + dict_len(target_models) == 0):
  1576. return "Model transformation needs at least one formalism in its input or output signature!"!
  1577. keys = dict_keys(source_models)
  1578. while (set_len(keys) > 0):
  1579. key = set_pop(keys)
  1580. name = source_models[key]
  1581. model_id = get_entry_id(name)
  1582. if (model_id != ""):
  1583. if (allow_read(current_user_id, name)):
  1584. // Check whether or not it is formalisms/SimpleClassDiagrams
  1585. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1586. if (bool_not(dict_in(source, key))):
  1587. dict_add(source, key, model_id)
  1588. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1589. if (element_eq(mm, read_root())):
  1590. return "ModelTransformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1591. set_add_node(to_ramify, create_tuple(key, mm))
  1592. else:
  1593. return "Name was already assigned a metamodel: " + key!
  1594. else:
  1595. return "Model not supported for RAMification: " + name!
  1596. else:
  1597. return "Permission denied: " + name!
  1598. else:
  1599. return "Model not found: " + name!
  1600. keys = dict_keys(target_models)
  1601. while (set_len(keys) > 0):
  1602. key = set_pop(keys)
  1603. name = target_models[key]
  1604. model_id = get_entry_id(name)
  1605. if (model_id != ""):
  1606. if (allow_read(current_user_id, name)):
  1607. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1608. if (bool_not(dict_in(target, key))):
  1609. if (dict_in(source, key)):
  1610. if (value_eq(model_id, source[key])):
  1611. dict_add(target, key, model_id)
  1612. // Don't add to to_ramify, as it is already in there!
  1613. else:
  1614. return "Name in output cannot have different type than input: " + key!
  1615. else:
  1616. dict_add(target, key, model_id)
  1617. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1618. if (element_eq(mm, read_root())):
  1619. return "ModelTransformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1620. set_add_node(to_ramify, create_tuple(key, mm))
  1621. else:
  1622. return "Name was already assigned a metamodel: " + key!
  1623. else:
  1624. return "Model not supported for RAMification: " + name!
  1625. else:
  1626. return "Permission denied: " + name!
  1627. else:
  1628. return "Model not found: " + name!
  1629. merged_formalism = model_fuse(to_ramify)
  1630. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1631. do_spawn_modify("merged/" + operation_name, True)
  1632. merged_formalism = get_full_model(get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1633. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1634. ramified_metamodel = ramify(merged_formalism)
  1635. model_create(ramified_metamodel, "RAMified/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1636. ramified_metamodel_id = get_entry_id("RAMified/" + operation_name)
  1637. // Now use the RAMified model to create the instance
  1638. if (get_entry_id(operation_name) == ""):
  1639. String new_model
  1640. // Finished with all information, now create the model itself!
  1641. output("Waiting for model constructors...")
  1642. new_model = compile_model(input(), get_full_model(ramified_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams")))
  1643. if (element_eq(new_model, read_root())):
  1644. return "Compilation error"!
  1645. model_create(new_model, operation_name, ramified_metamodel_id, "ModelTransformation")
  1646. model_id = get_entry_id(operation_name)
  1647. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1648. // New location is available, so write
  1649. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1650. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1651. // Add tracability links at this level
  1652. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1653. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1654. // Add tracability links at this level
  1655. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1656. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1657. // Extend metadata with info on source and target
  1658. String link
  1659. String dst
  1660. keys = dict_keys(source)
  1661. while (set_len(keys) > 0):
  1662. key = set_pop(keys)
  1663. dst = source[key]
  1664. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1665. instantiate_attribute(core, link, "name", key)
  1666. keys = dict_keys(target)
  1667. while (set_len(keys) > 0):
  1668. key = set_pop(keys)
  1669. dst = target[key]
  1670. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1671. instantiate_attribute(core, link, "name", key)
  1672. return "Success"!
  1673. else:
  1674. return "Model exists: " + operation_name!
  1675. String function cmd_permission_modify(model_name : String, permissions : String):
  1676. Integer permission
  1677. String model_id
  1678. model_id = get_entry_id(model_name)
  1679. if (model_id != ""):
  1680. if (get_relation_to_model(current_user_id, model_id) == 0):
  1681. Boolean fail
  1682. Integer i
  1683. i = 0
  1684. if (string_len(permissions) != 3):
  1685. fail = True
  1686. while (i < 3):
  1687. permission = cast_integer(string_get(permissions, i))
  1688. if (bool_or(permission < 0, permission > 2)):
  1689. fail = True
  1690. break!
  1691. i = i + 1
  1692. if (bool_not(fail)):
  1693. unset_attribute(core, model_id, "permissions")
  1694. instantiate_attribute(core, model_id, "permissions", permissions)
  1695. return "Success"!
  1696. else:
  1697. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1698. else:
  1699. return "Permission denied to model: " + model_name!
  1700. else:
  1701. return "Model not found: " + model_name!
  1702. String function cmd_permission_owner(model_name : String, new_user_name : String):
  1703. String model_id
  1704. String new_user_id
  1705. model_id = get_entry_id(model_name)
  1706. if (model_id != ""):
  1707. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1708. new_user_id = get_user_id(new_user_name)
  1709. if (new_user_id != ""):
  1710. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1711. instantiate_link(core, "owner", "", model_id, new_user_id)
  1712. return "Success"!
  1713. else:
  1714. return "No such user: " + new_user_name!
  1715. else:
  1716. return "Permission denied to model: " + model_name!
  1717. else:
  1718. return "Model not found: " + model_name!
  1719. String function cmd_permission_group(model_name : String, new_group_name : String):
  1720. String model_id
  1721. String group_id
  1722. model_id = get_entry_id(model_name)
  1723. if (model_id != ""):
  1724. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1725. group_id = get_group_id(new_group_name)
  1726. if (group_id != ""):
  1727. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1728. instantiate_link(core, "group", "", model_id, group_id)
  1729. return "Success"!
  1730. else:
  1731. return "No such group: " + new_group_name!
  1732. else:
  1733. return "Permission denied to model: " + model_name!
  1734. else:
  1735. return "Model not found: " + model_name!
  1736. String function cmd_group_create(group_name : String):
  1737. // Create a new group and become its owner
  1738. String group_id
  1739. String name
  1740. group_id = get_group_id(group_name)
  1741. if (group_id == ""):
  1742. group_id = instantiate_node(core, "Group", "")
  1743. instantiate_attribute(core, group_id, "name", group_name)
  1744. instantiate_link(core, "belongsTo", "", current_user_id, group_id)
  1745. instantiate_link(core, "owner", "", group_id, current_user_id)
  1746. return "Success"!
  1747. else:
  1748. return "Group exists: " + group_name!
  1749. String function cmd_group_delete(group_name : String):
  1750. // Delete an existing group
  1751. String group_id
  1752. group_id = get_group_id(group_name)
  1753. if (group_id != ""):
  1754. if (allow_group_modify(current_user_id, group_id)):
  1755. model_delete_element(core, group_id)
  1756. return "Success"!
  1757. else:
  1758. return "Permission denied to group: " + group_name!
  1759. else:
  1760. return "Group not found: " + group_name!
  1761. String function cmd_group_owner_add(group_name : String, other_user_name : String):
  1762. // Add an owner to your group
  1763. String group_id
  1764. String other_user_id
  1765. group_id = get_group_id(group_name)
  1766. if (group_id != ""):
  1767. if (allow_group_modify(current_user_id, group_id)):
  1768. other_user_id = get_user_id(other_user_name)
  1769. if (other_user_id != ""):
  1770. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1771. instantiate_link(core, "owner", "", group_id, other_user_id)
  1772. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1773. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1774. return "Success"!
  1775. else:
  1776. return "User is already the owner!"!
  1777. else:
  1778. return "User not found: " + other_user_name!
  1779. else:
  1780. return "Permission denied to group: " + group_name!
  1781. else:
  1782. return "Group not found: " + group_name!
  1783. String function cmd_group_owner_delete(group_name : String, other_user_name : String):
  1784. // Remove an owner from your group
  1785. String group_id
  1786. String other_user_id
  1787. group_id = get_group_id(group_name)
  1788. if (group_id != ""):
  1789. if (allow_group_modify(current_user_id, group_id)):
  1790. other_user_id = get_user_id(other_user_name)
  1791. if (other_user_id != ""):
  1792. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1793. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1794. Element overlap
  1795. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1796. model_delete_element(core, set_pop(overlap))
  1797. return "Success"!
  1798. else:
  1799. return "User is not an owner of the group!"!
  1800. else:
  1801. return "User is not a member of the group!"!
  1802. else:
  1803. return "User not found: " + other_user_name!
  1804. else:
  1805. return "Permission denied to group: " + group_name!
  1806. else:
  1807. return "Group not found: " + group_name!
  1808. String function cmd_group_join(group_name : String, other_user_name : String):
  1809. // Add someone to your group
  1810. String group_id
  1811. String other_user_id
  1812. group_id = get_group_id(group_name)
  1813. if (group_id != ""):
  1814. if (allow_group_modify(current_user_id, group_id)):
  1815. other_user_id = get_user_id(other_user_name)
  1816. if (other_user_id != ""):
  1817. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1818. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1819. return "Success"!
  1820. else:
  1821. return "User is already a member of the group!"!
  1822. else:
  1823. return "User not found: " + other_user_name!
  1824. else:
  1825. return "Permission denied to group: " + group_name!
  1826. else:
  1827. return "Group not found: " + group_name!
  1828. String function cmd_group_kick(group_name : String, other_user_name : String):
  1829. // Remove someone from your group
  1830. String group_id
  1831. String other_user_id
  1832. group_id = get_group_id(group_name)
  1833. if (group_id != ""):
  1834. if (allow_group_modify(current_user_id, group_id)):
  1835. other_user_id = get_user_id(other_user_name)
  1836. if (other_user_id != ""):
  1837. Element overlap
  1838. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1839. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1840. model_delete_element(core,set_pop(overlap))
  1841. // Check if user was an owner as well
  1842. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1843. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1844. model_delete_element(core, set_pop(overlap))
  1845. return "Success"!
  1846. else:
  1847. return "User is not a member of the group!"!
  1848. else:
  1849. return "User not found: " + other_user_name!
  1850. else:
  1851. return "Permission denied to group: " + group_name!
  1852. else:
  1853. return "Group not found: " + group_name!
  1854. String function cmd_group_list():
  1855. // List all groups you are a member of (and whether you are admin or not!)
  1856. Element groups
  1857. String group_id
  1858. String admin
  1859. String result
  1860. result = ""
  1861. groups = allAssociationDestinations(core, current_user_id, "belongsTo")
  1862. while (set_len(groups) > 0):
  1863. group_id = set_pop(groups)
  1864. if (set_in(allAssociationDestinations(core, group_id, "owner"), current_user_id)):
  1865. admin = " A "
  1866. else:
  1867. admin = " "
  1868. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1869. return result!
  1870. String function cmd_admin_promote(other_user_name : String):
  1871. // Promote a user to admin status
  1872. if (is_admin(current_user_id)):
  1873. String other_user_id
  1874. other_user_id = get_user_id(other_user_name)
  1875. if (other_user_id != ""):
  1876. unset_attribute(core, other_user_id, "admin")
  1877. instantiate_attribute(core, other_user_id, "admin", True)
  1878. return "Success"!
  1879. else:
  1880. return "User not found: " + other_user_name!
  1881. else:
  1882. return "Permission denied to administrate: " + other_user_name!
  1883. String function cmd_admin_demote(other_user_name : String):
  1884. // Demote a user to normal status
  1885. if (is_admin(current_user_id)):
  1886. String other_user_id
  1887. other_user_id = get_user_id(other_user_name)
  1888. if (other_user_id != ""):
  1889. unset_attribute(core, other_user_id, "admin")
  1890. instantiate_attribute(core, other_user_id, "admin", False)
  1891. return "Success"!
  1892. else:
  1893. return "User not found: " + other_user_name!
  1894. else:
  1895. return "Permission denied to administrate: " + other_user_name!
  1896. String function cmd_service_register(service_name : String):
  1897. // Active a service for this specific user
  1898. if (get_service_id(service_name) == ""):
  1899. String service
  1900. service = instantiate_node(core, "Service", "")
  1901. instantiate_attribute(core, service, "name", service_name)
  1902. instantiate_attribute(core, service, "port", get_taskname())
  1903. output("Success: " + get_taskname())
  1904. // Wait until we can stop the service
  1905. while (cast_value(input()) != "\"service_stop\""):
  1906. output("Service is running on this task: stop it by sending 'service_stop'")
  1907. model_delete_element(core, service)
  1908. // Service terminated
  1909. return "Success"!
  1910. else:
  1911. return "Service already exists: " + service_name!
  1912. String function cmd_user_password(user_name : String, new_password : String):
  1913. if (bool_or(current_user_id == get_user_id(user_name), is_admin(current_user_id))):
  1914. if (get_user_id(user_name) != ""):
  1915. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1916. return "Success"!
  1917. else:
  1918. return "No such user: " + user_name!
  1919. else:
  1920. return "Permission denied to user: " + user_name!
  1921. String function cmd_transformation_signature(transformation_name : String):
  1922. String model_id
  1923. model_id = get_entry_id(transformation_name)
  1924. if (model_id != ""):
  1925. if (is_nominal_instance(core, model_id, "Transformation")):
  1926. if (allow_read(current_user_id, transformation_name)):
  1927. String result
  1928. String elem
  1929. Element inputs
  1930. Element outputs
  1931. result = "Success: "
  1932. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1933. while (set_len(inputs) > 0):
  1934. elem = set_pop(inputs)
  1935. result = string_join(string_join(string_join(string_join(result + "I ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1936. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1937. while (set_len(outputs) > 0):
  1938. elem = set_pop(outputs)
  1939. result = string_join(string_join(string_join(string_join(result + "O ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1940. return result!
  1941. else:
  1942. return "Permission denied to operation: " + transformation_name!
  1943. else:
  1944. return "Model is not an operation: " + transformation_name!
  1945. else:
  1946. return "No such operation: " + transformation_name!
  1947. String function cmd_model_types(model_name : String):
  1948. if (get_entry_id(model_name) != ""):
  1949. String model_id
  1950. model_id = get_entry_id(model_name)
  1951. Element types
  1952. String type
  1953. String result
  1954. result = "Success: "
  1955. types = allAssociationDestinations(core, model_id, "instanceOf")
  1956. while (set_len(types) > 0):
  1957. type = set_pop(types)
  1958. result = string_join(result, full_name(type) + "\n")
  1959. return result!
  1960. else:
  1961. return "No such model: " + model_name!
  1962. String function cmd_folder_create(folder_name : String):
  1963. if (get_entry_id(folder_name) == ""):
  1964. if (element_neq(create_folders(current_user_id, folder_name), read_root())):
  1965. return "Success"!
  1966. else:
  1967. return "Permission denied to folder: " + folder_name!
  1968. else:
  1969. return "Folder alreay exists: " + folder_name!
  1970. String function cmd_conformance_add(model_name : String, metamodel_name : String):
  1971. // Create a new instanceOf relation now
  1972. String instance_of
  1973. instance_of = instantiate_link(core, "instanceOf", "", get_entry_id(model_name), get_entry_id(metamodel_name))
  1974. return "Success"!
  1975. Void function user_function_skip_init(user_id : String):
  1976. String cmd
  1977. String result
  1978. current_user_id = user_id
  1979. caches = dict_create()
  1980. dict_add_fast(caches, "models", dict_create())
  1981. dict_add_fast(caches, "users", dict_create())
  1982. dict_add_fast(caches, "full_name", dict_create())
  1983. // Find root element
  1984. Element elems
  1985. String elem
  1986. elems = allInstances(core, "Folder")
  1987. while (set_len(elems) > 0):
  1988. elem = set_pop(elems)
  1989. if (value_eq(read_attribute(core, elem, "name"), "")):
  1990. if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
  1991. dict_add_fast(caches, "root", elem)
  1992. break!
  1993. output("Welcome to the Model Management Interface v2.0!")
  1994. output("Use the 'help' command for a list of possible commands")
  1995. while (True):
  1996. cmd = input()
  1997. if (cmd == "help"):
  1998. output(cmd_help())
  1999. elif (cmd == "model_add"):
  2000. output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
  2001. elif (cmd == "process_execute"):
  2002. output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
  2003. elif (cmd == "process_signature"):
  2004. output(cmd_process_signature(single_input("Process to execute?")))
  2005. elif (cmd == "transformation_between"):
  2006. output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
  2007. elif (cmd == "model_render"):
  2008. output(cmd_model_render(single_input("Model name?"), single_input("Mapper name?"), single_input("Rendered name?")))
  2009. elif (cmd == "model_rendered"):
  2010. output(cmd_model_rendered(single_input("Model name?"), single_input("Mapper name?")))
  2011. elif (cmd == "transformation_execute"):
  2012. output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?"), single_input("Tracability model?")))
  2013. elif (cmd == "verify"):
  2014. result = cmd_verify(single_input("Model name?"), single_input("Metamodel name?"))
  2015. if (result != ""):
  2016. output(result)
  2017. elif (cmd == "model_overwrite"):
  2018. output(cmd_model_overwrite(single_input("Model name?"), single_input("Metamodel name?")))
  2019. elif (cmd == "model_modify"):
  2020. output(cmd_model_modify(single_input("Model name?"), single_input("Metamodel name?")))
  2021. elif (cmd == "model_delete"):
  2022. output(cmd_model_delete(single_input("Model name?")))
  2023. elif (cmd == "model_list"):
  2024. output(cmd_model_list(single_input("Location?")))
  2025. elif (cmd == "model_list_full"):
  2026. output(cmd_model_list_full(single_input("Location?")))
  2027. elif (cmd == "transformation_add_MANUAL"):
  2028. output(cmd_transformation_add_MANUAL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  2029. elif (cmd == "transformation_add_AL"):
  2030. output(cmd_transformation_add_AL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  2031. elif (cmd == "transformation_add_MT"):
  2032. output(cmd_transformation_add_MT(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  2033. elif (cmd == "permission_modify"):
  2034. output(cmd_permission_modify(single_input("Model name?"), single_input("Permissions?")))
  2035. elif (cmd == "permission_owner"):
  2036. output(cmd_permission_owner(single_input("Model name?"), single_input("New owning user?")))
  2037. elif (cmd == "permission_group"):
  2038. output(cmd_permission_group(single_input("Model name?"), single_input("New owning group?")))
  2039. elif (cmd == "group_create"):
  2040. output(cmd_group_create(single_input("New group name?")))
  2041. elif (cmd == "group_delete"):
  2042. output(cmd_group_delete(single_input("Group name?")))
  2043. elif (cmd == "group_owner_add"):
  2044. output(cmd_group_owner_add(single_input("Group name?"), single_input("User name?")))
  2045. elif (cmd == "group_owner_delete"):
  2046. output(cmd_group_owner_delete(single_input("Group name?"), single_input("User name?")))
  2047. elif (cmd == "group_join"):
  2048. output(cmd_group_join(single_input("Group name?"), single_input("User name?")))
  2049. elif (cmd == "group_kick"):
  2050. output(cmd_group_kick(single_input("Group name?"), single_input("User name?")))
  2051. elif (cmd == "group_list"):
  2052. output(cmd_group_list())
  2053. elif (cmd == "admin_promote"):
  2054. output(cmd_admin_promote(single_input("User name?")))
  2055. elif (cmd == "admin_demote"):
  2056. output(cmd_admin_demote(single_input("User name?")))
  2057. elif (cmd == "service_register"):
  2058. output(cmd_service_register(single_input("Service name?")))
  2059. elif (cmd == "user_password"):
  2060. output(cmd_user_password(single_input("User name?"), single_input("New password?")))
  2061. elif (cmd == "transformation_read_signature"):
  2062. output(cmd_transformation_signature(single_input("Transformation name?")))
  2063. elif (cmd == "verbose"):
  2064. set_verbose(True)
  2065. elif (cmd == "quiet"):
  2066. set_verbose(False)
  2067. elif (cmd == "self-destruct"):
  2068. // Delete user from Core Formalism
  2069. model_delete_element(core, user_id)
  2070. return !
  2071. elif (cmd == "user_logout"):
  2072. // TODO
  2073. cmd = "FAIL"
  2074. elif (cmd == "exit"):
  2075. // Exit by actually removing the user and decoupling it from all of its models
  2076. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  2077. // as the current user will have been deleted
  2078. return !
  2079. elif (cmd == "folder_create"):
  2080. output(cmd_folder_create(single_input("Folder name?")))
  2081. elif (cmd == "add_conformance"):
  2082. log("Adding conformance relation...")
  2083. output(cmd_conformance_add(single_input("Model name?"), single_input("Metamodel name?")))
  2084. log("Added!")
  2085. elif (cmd == "remove_conformance"):
  2086. // TODO
  2087. cmd = "FAIL"
  2088. elif (cmd == "user_name"):
  2089. // TODO
  2090. cmd = "FAIL"
  2091. elif (cmd == "service_poll"):
  2092. // TODO
  2093. cmd = "FAIL"
  2094. elif (cmd == "model_types"):
  2095. output(cmd_model_types(single_input("Model name?")))
  2096. else:
  2097. output("Unknown command: " + cmd)
  2098. // We never get here!
  2099. return !