core_algorithm.alc 88 KB

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