core_algorithm.alc 88 KB

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