core_algorithm.alc 88 KB

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