core_algorithm.alc 83 KB

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