core_algorithm.alc 87 KB

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