core_algorithm.alc 86 KB

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