core_algorithm.alc 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  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. model_create(merged_model, model_name, merged_metamodel_id, "Model")
  592. output("Operating on: " + cast_string(model_name))
  593. // We want to modify, so modify
  594. modify(merged_model, True)
  595. //model_delete(get_entry_id(model_name))
  596. result = True
  597. elif (exact_type == "ActionLanguage"):
  598. Element func
  599. Element al
  600. al = get_full_model(operation_id, get_entry_id("formalisms/ActionLanguage"))
  601. if (element_eq(al, read_root())):
  602. log("Action Language operation not typed by ActionLanguage metamodel!")
  603. output("Action Language operation not typed by ActionLanguage metamodel!")
  604. return read_root()!
  605. func = get_func_AL_model(al)
  606. result = func(merged_model)
  607. else:
  608. log("Unknown type of operation: " + exact_type)
  609. output("Unknown type of operation: " + exact_type)
  610. return read_root()!
  611. // 4) Split in different models depending on type
  612. if (element_neq(tracability_model, read_root())):
  613. tracability = True
  614. else:
  615. tracability = False
  616. if (result):
  617. model_tuples = set_create()
  618. keys = dict_keys(output_metamodels)
  619. while (set_len(keys) > 0):
  620. key = set_pop(keys)
  621. Element mm
  622. mm = get_full_model(get_entry_id(output_metamodels[key]), get_entry_id("formalisms/SimpleClassDiagrams"))
  623. if (element_eq(mm, read_root())):
  624. log("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  625. output("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  626. return read_root()!
  627. set_add_node(model_tuples, create_tuple(key, mm))
  628. result = model_split(merged_model, model_tuples, tracability)
  629. if (tracability):
  630. Element new_tracability_model
  631. new_tracability_model = result["__tracability"]
  632. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  633. set_type_mapping(tracability_model, get_type_mapping(new_tracability_model))
  634. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  635. dict_delete(result, "__tracability")
  636. return result!
  637. else:
  638. log("Negative result of execution")
  639. return read_root()!
  640. Boolean function enact_action(pm : Element, element : String, mapping : Element):
  641. Boolean result
  642. String transformation_id
  643. Element lst
  644. String elem
  645. Element inputs
  646. Element outputs
  647. String type_name
  648. String exact_type
  649. Element trace_links
  650. Element output_mms
  651. Element consumes_link
  652. String name
  653. String value
  654. String elem_name
  655. Element keys
  656. String key
  657. String consume
  658. String produce
  659. Element output_map
  660. inputs = dict_create()
  661. outputs = dict_create()
  662. output_map = dict_create()
  663. // Read out the referenced element from the MvC
  664. transformation_id = get_entry_id(read_attribute(pm, element, "name"))
  665. // Find all input model names
  666. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  667. while (set_len(lst) > 0):
  668. consume = set_pop(lst)
  669. value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
  670. dict_add(inputs, read_attribute(pm, consume, "name"), mapping[value])
  671. // Find all output model names and their metamodel
  672. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  673. while (set_len(lst) > 0):
  674. produce = set_pop(lst)
  675. elem = readAssociationDestination(pm, produce)
  676. type_name = read_attribute(pm, elem, "type")
  677. elem_name = read_attribute(pm, elem, "name")
  678. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  679. dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
  680. if read_type(core, transformation_id) == "ActionLanguage":
  681. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  682. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  683. elif read_type(core, transformation_id) == "ManualOperation":
  684. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  685. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  686. else:
  687. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  688. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  689. result = execute_operation(transformation_id, inputs, read_root())
  690. if (element_eq(result, read_root())):
  691. // Something went wrong!
  692. return False!
  693. else:
  694. keys = dict_keys(outputs)
  695. while (set_len(keys) > 0):
  696. key = set_pop(keys)
  697. if (get_entry_id(output_map[key]) == ""):
  698. // New model
  699. model_create(result[key], output_map[key], get_entry_id(outputs[key]), "Model")
  700. else:
  701. model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
  702. return True!
  703. Element function PM_signature(pm : Element):
  704. Element all_data
  705. Element result
  706. String entry
  707. result = dict_create()
  708. all_data = allInstances(pm, "Data")
  709. while (set_len(all_data) > 0):
  710. entry = set_pop(all_data)
  711. dict_add(result, cast_string(read_attribute(pm, entry, "name")), cast_string(read_attribute(pm, entry, "type")))
  712. return result!
  713. Void function enact_PM(pm : Element, mapping : Element):
  714. Element worklist
  715. String element
  716. String type
  717. Boolean result
  718. Element tuple
  719. Element counters
  720. Element join_nodes
  721. Element keys
  722. String key
  723. output("Success")
  724. // For all entries in the signature, not in the mapping, we add a mock location
  725. Element signature
  726. String mock_location
  727. Element mock_locations
  728. mock_locations = set_create()
  729. signature = PM_signature(pm)
  730. keys = dict_keys(signature)
  731. while (set_len(keys) > 0):
  732. key = set_pop(keys)
  733. if (bool_not(dict_in(mapping, key))):
  734. // Add mock location
  735. mock_location = ""
  736. while (get_entry_id(mock_location) != ""):
  737. mock_location = ".tmp/" + random_string(10)
  738. dict_add(mapping, key, mock_location)
  739. set_add(mock_locations, mock_location)
  740. // Initialize Join counters
  741. counters = dict_create()
  742. join_nodes = allInstances(pm, "Join")
  743. while (set_len(join_nodes) > 0):
  744. dict_add(counters, set_pop(join_nodes), 0)
  745. // Create the worklist with the Start instance as first element
  746. worklist = set_create()
  747. set_add_node(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  748. while (bool_not(pm_finished(worklist, pm))):
  749. // Pop a random element from the list and execute it
  750. tuple = set_pop(worklist)
  751. element = tuple[0]
  752. result = tuple[1]
  753. // Find the type (to see what to do with it)
  754. // this does not yet yield the type of transformation, if it is an Execution
  755. type = read_type(pm, element)
  756. if (type == "Start"):
  757. // Initial node, just progress to the next elements
  758. // Nothing to do here though, as we have just started
  759. result = True
  760. elif (type == "Finish"):
  761. // Should be impossible, as we would have ended...
  762. result = result
  763. elif (type == "Fork"):
  764. result = result
  765. elif (type == "Join"):
  766. // Only do this if all dependencies are fullfilled
  767. // So add to the counter of this Join
  768. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  769. // Now check whether we have enough tokens to execute the Join itself
  770. Integer required
  771. Integer got
  772. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  773. got = counters[element]
  774. if (got == required):
  775. // Reset counter to 0
  776. dict_overwrite(counters, element, 0)
  777. // And continue
  778. else:
  779. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  780. continue!
  781. elif (type == "Exec"):
  782. // Execute a transformation
  783. // This the difficult part!
  784. result = enact_action(pm, element, mapping)
  785. output("Success")
  786. elif (type == "Decision"):
  787. // If the previous result is true, we add the normal one, otherwise the false one
  788. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  789. if (bool_not(result)):
  790. // Apparently it is False, so map this to the "Else" branch
  791. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  792. continue!
  793. else:
  794. // Apparently it is True, so map this to the "Then" branch
  795. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  796. continue!
  797. // We have finished the execution, so add all outgoing edges to the worklist
  798. Element all_next
  799. all_next = allAssociationDestinations(pm, element, "Next")
  800. String next
  801. while (set_len(all_next) > 0):
  802. next = set_pop(all_next)
  803. set_add_node(worklist, create_tuple(next, result))
  804. // Reached a finish element, so stop
  805. // Remove all mock locations again
  806. while (set_len(mock_locations) > 0):
  807. model_delete(get_entry_id(set_pop(mock_locations)))
  808. return !
  809. String function cmd_help():
  810. String result
  811. result = ""
  812. result = result + ("Model operations\n")
  813. result = result + (" model_add -- Add a new model\n")
  814. result = result + (" model_modify -- Modify an existing model\n")
  815. result = result + (" model_list -- List all models\n")
  816. result = result + (" model_list_full -- List all models with full info\n")
  817. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  818. result = result + (" model_render -- Render a given model with a specified mapper\n")
  819. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  820. result = result + ("\n")
  821. result = result + ("Transformation-specific operations\n")
  822. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  823. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  824. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  825. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  826. result = result + (" transformation_list -- List all model transformations\n")
  827. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  828. result = result + (" transformation_detail -- List transformation details\n")
  829. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  830. result = result + ("\n")
  831. result = result + ("Process operations\n")
  832. result = result + (" process_execute -- Execute a process model\n")
  833. result = result + ("\n")
  834. result = result + ("Model permission operations\n")
  835. result = result + (" permission_modify -- Change model permissions\n")
  836. result = result + (" permission_owner -- Change model owner\n")
  837. result = result + (" permission_group -- Change model group\n")
  838. result = result + ("\n")
  839. result = result + ("Group operations\n")
  840. result = result + (" group_create -- Create a group\n")
  841. result = result + (" group_delete -- Delete a group\n")
  842. result = result + (" group_owner_add -- Add group owner\n")
  843. result = result + (" group_owner_delete -- Remove group owner\n")
  844. result = result + (" group_join -- Add someone to your group\n")
  845. result = result + (" group_kick -- Kick someone from your group\n")
  846. result = result + (" group_list -- List all groups you are a member of\n")
  847. result = result + ("\n")
  848. if (is_admin(current_user_id)):
  849. result = result + ("Admin operations\n")
  850. result = result + (" admin_promote -- Promote a user to admin status\n")
  851. result = result + (" admin_demote -- Demote a user to normal status\n")
  852. result = result + ("\n")
  853. result = result + ("General operations\n")
  854. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  855. result = result + (" exit -- Kill the current task, while retaining user\n")
  856. return result!
  857. String function cmd_model_add(type : String, name : String, code : String):
  858. // Model addition operation, which uses model upload commands of the compiler
  859. String location
  860. String type_id
  861. Element new_model
  862. String new_model_id
  863. type_id = get_entry_id(type)
  864. if (type_id != ""):
  865. // Type exists
  866. if (allow_read(current_user_id, type_id)):
  867. // And is readable
  868. if (get_entry_id(get_foldername(name)) != ""):
  869. // Folder doesn't exist yet!
  870. if (allow_write(current_user_id, get_entry_id(get_foldername(name)))):
  871. // Folder is writable
  872. if (get_entry_id(name) == ""):
  873. // Model doesn't exist yet
  874. Element mm
  875. mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  876. if (element_eq(mm, read_root())):
  877. return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
  878. new_model = compile_model(code, mm)
  879. if (element_eq(new_model, read_root())):
  880. return "Compilation error"!
  881. model_create(new_model, name, type_id, "Model")
  882. return "Success"!
  883. else:
  884. return "Model exists: " + name!
  885. else:
  886. return "Permission denied to folder: " + get_foldername(name)!
  887. else:
  888. return "No such folder: " + get_foldername(name)!
  889. else:
  890. return "Permission denied to model: " + type!
  891. else:
  892. return "Model not found: " + type!
  893. String function cmd_process_execute(process : String, mapping : Element):
  894. // Execute a process model until it reaches termination
  895. String process_id
  896. process_id = get_entry_id(process)
  897. if (process_id != ""):
  898. if (allow_read(current_user_id, process_id)):
  899. Element pm
  900. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  901. if (element_eq(pm, read_root())):
  902. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  903. enact_PM(pm, mapping)
  904. return "Success"!
  905. else:
  906. return "Permission denied to model: " + process!
  907. else:
  908. return "Model not found: " + process!
  909. String function cmd_process_signature(process : String):
  910. // Execute a process model until it reaches termination
  911. String process_id
  912. String result
  913. Element signature
  914. Element keys
  915. String key
  916. process_id = get_entry_id(process)
  917. if (process_id != ""):
  918. if (allow_read(current_user_id, process_id)):
  919. Element pm
  920. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  921. if (element_eq(pm, read_root())):
  922. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  923. result = "Success: "
  924. signature = PM_signature(pm)
  925. keys = dict_keys(signature)
  926. while (set_len(keys) > 0):
  927. key = set_pop(keys)
  928. result = result + key + " : " + cast_string(signature[key]) + "\n"
  929. return result!
  930. else:
  931. return "Permission denied to model: " + process!
  932. else:
  933. return "Model not found: " + process!
  934. String function cmd_transformation_between(source_dict : String, target_dict : String):
  935. Element result
  936. Element subresult
  937. String tag
  938. String mm
  939. String mm_id
  940. Element links
  941. String link
  942. Element keys
  943. result = allInstances(core, "Transformation")
  944. // Iterate over all inputs
  945. keys = dict_keys(source_dict)
  946. while (set_len(keys) > 0):
  947. subresult = set_create()
  948. tag = set_pop(keys)
  949. mm = source_dict[tag]
  950. mm_id = get_entry_id(mm)
  951. if (mm_id != ""):
  952. links = allIncomingAssociationInstances(core, mm_id, "transformInput")
  953. while (set_len(links) > 0):
  954. link = set_pop(links)
  955. if (value_eq(read_attribute(core, link, "name"), tag)):
  956. // Correct tag, so make transformation a possibility
  957. set_add(subresult, readAssociationSource(core, link))
  958. else:
  959. return "Model not found: " + mm!
  960. // Got a set of subresults now, which we use to find the overlap
  961. result = set_overlap(result, subresult)
  962. keys = dict_keys(target_dict)
  963. while (set_len(keys) > 0):
  964. subresult = set_create()
  965. tag = set_pop(keys)
  966. mm = target_dict[tag]
  967. mm_id = get_entry_id(mm)
  968. if (mm_id != ""):
  969. links = allIncomingAssociationInstances(core, mm_id, "transformOutput")
  970. while (set_len(links) > 0):
  971. link = set_pop(links)
  972. if (value_eq(read_attribute(core, link, "name"), tag)):
  973. // Correct tag, so make transformation a possibility
  974. set_add(subresult, readAssociationSource(core, link))
  975. else:
  976. return "Model not found: " + mm!
  977. // Got a set of subresults now, which we use to find the overlap
  978. result = set_overlap(result, subresult)
  979. String r
  980. String transformation
  981. r = "Success: "
  982. while (set_len(result) > 0):
  983. transformation = set_pop(result)
  984. if (allow_read(current_user_id, transformation)):
  985. r = r + string_join(full_name(transformation), "\n")
  986. return r!
  987. String function cmd_model_rendered(model_name : String, mapper_name : String):
  988. Element trace_links
  989. String rendered
  990. String trace_link_id
  991. String allowed_rendered
  992. Element trace_links_2
  993. String trace_link_2_id
  994. allowed_rendered = "Success: "
  995. trace_links = allOutgoingAssociationInstances(core, get_entry_id(model_name), "tracability")
  996. while (set_len(trace_links) > 0):
  997. trace_link_id = set_pop(trace_links)
  998. if (value_eq(read_attribute(core, trace_link_id, "type"), "CS_perceptualized")):
  999. rendered = readAssociationDestination(core, trace_link_id)
  1000. trace_links_2 = allOutgoingAssociationInstances(core, rendered, "tracability")
  1001. while (set_len(trace_links_2) > 0):
  1002. trace_link_2_id = set_pop(trace_links_2)
  1003. if (value_eq(read_attribute(core, readAssociationDestination(core, trace_link_2_id), "name"), mapper_name)):
  1004. if (value_eq(read_attribute(core, trace_link_2_id, "type"), "CS_mapper")):
  1005. allowed_rendered = string_join(allowed_rendered, read_attribute(core, rendered, "name")) + "\n"
  1006. return allowed_rendered!
  1007. String function cmd_model_render(model_name : String, mapper_name : String, rendered_name : String):
  1008. String model_ID
  1009. String mapper_ID
  1010. String tracability_name
  1011. Element inputs
  1012. Element output_map
  1013. Element rendered_model
  1014. Element tracability_model
  1015. Element result
  1016. Element out_links
  1017. String link
  1018. String ID_rendered_M
  1019. String ID_rendered_MM
  1020. String ID_SCD
  1021. String ID_tracability_MM
  1022. String ID_tracability_M
  1023. model_ID = get_entry_id(model_name)
  1024. if (model_ID != ""):
  1025. mapper_ID = get_entry_id(mapper_name)
  1026. if (allow_read(current_user_id, model_ID)):
  1027. if (mapper_ID != ""):
  1028. if (allow_read(current_user_id, mapper_ID)):
  1029. // Everything is fine; start the actual operation
  1030. // Find metamodel to render to
  1031. tracability_name = "tracability/" + rendered_name
  1032. // Take the abstract syntax model and the previously rendered model
  1033. inputs = dict_create()
  1034. dict_add(inputs, "abstract", model_name)
  1035. dict_add(inputs, "rendered", rendered_name)
  1036. // Fetch the output types
  1037. output_map = dict_create()
  1038. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  1039. while(set_len(out_links) > 0):
  1040. link = set_pop(out_links)
  1041. dict_add(output_map, read_attribute(core, link, "name"), full_name(readAssociationDestination(core, link)))
  1042. ID_rendered_MM = get_entry_id(output_map["rendered"])
  1043. ID_SCD = get_entry_id("formalisms/SimpleClassDiagrams")
  1044. ID_tracability_MM = get_entry_id("formalisms/Tracability")
  1045. ID_tracability_M = get_entry_id(tracability_name)
  1046. ID_rendered_M = get_entry_id(rendered_name)
  1047. if (ID_rendered_M == ""):
  1048. // Instantiate
  1049. Element rendered
  1050. rendered = get_full_model(ID_rendered_MM, ID_SCD)
  1051. if (element_eq(rendered, read_root())):
  1052. return "Rendered metamodel doesn't conform to formalisms/SimpleClassDiagrams"!
  1053. rendered_model = instantiate_model(rendered)
  1054. model_create(rendered_model, rendered_name, ID_rendered_MM, "Model")
  1055. // Tracability model won't exist either
  1056. tracability_model = instantiate_model(get_full_model(ID_tracability_MM, ID_SCD))
  1057. model_create(tracability_model, tracability_name, ID_tracability_MM, "Model")
  1058. ID_rendered_M = get_entry_id(rendered_name)
  1059. ID_tracability_M = get_entry_id(tracability_name)
  1060. else:
  1061. // Read out tracability model
  1062. tracability_model = get_full_model(ID_tracability_M, ID_tracability_MM)
  1063. if (element_eq(tracability_model, read_root())):
  1064. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1065. // Do the operation itself!
  1066. result = execute_operation(mapper_ID, inputs, tracability_model)
  1067. // Overwrite the previous rendered model
  1068. model_overwrite(result["rendered"], ID_rendered_M, ID_rendered_MM)
  1069. // Tracability updated in-place
  1070. model_overwrite(tracability_model, ID_tracability_M, ID_tracability_MM)
  1071. if (element_eq(tracability_model, read_root())):
  1072. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1073. // Link all information in the megamodel
  1074. String tr_link
  1075. tr_link = instantiate_link(core, "tracability", "", get_entry_id(model_name), ID_rendered_M)
  1076. instantiate_attribute(core, tr_link, "type", "CS_perceptualized")
  1077. tr_link = instantiate_link(core, "tracability", "", ID_rendered_M, get_entry_id(mapper_name))
  1078. instantiate_attribute(core, tr_link, "type", "CS_mapper")
  1079. // Output the resulting model
  1080. String value
  1081. value = JSON_print(result["rendered"])
  1082. return ("Success: " + value) !
  1083. else:
  1084. return "Permission denied to model: " + mapper_name!
  1085. else:
  1086. return "Model not found: " + mapper_name!
  1087. else:
  1088. return "Permission denied to model: " + model_name!
  1089. else:
  1090. return "Model not found: " + model_name!
  1091. String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element, tracability_name : String):
  1092. // Execute a transformation, whatever type it is
  1093. // First we detect the type, so we know how to prepare for invocation
  1094. String transformation_id
  1095. String exact_type
  1096. Element sources
  1097. Element targets
  1098. String source
  1099. String target
  1100. Element inputs
  1101. Element outputs
  1102. Element output_map
  1103. Element trace_links
  1104. String target_model_name
  1105. String source_model_name
  1106. String source_model_ID
  1107. Element result
  1108. Element keys
  1109. String key
  1110. String assoc_name
  1111. transformation_id = get_entry_id(transformation_name)
  1112. if (transformation_id != ""):
  1113. if (allow_read(current_user_id, transformation_id)):
  1114. if (is_nominal_instance(core, transformation_id, "Transformation")):
  1115. // Read out source and target links
  1116. inputs = dict_create()
  1117. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  1118. while (set_len(sources) > 0):
  1119. source = set_pop(sources)
  1120. assoc_name = read_attribute(core, source, "name")
  1121. if (dict_in(source_models, assoc_name)):
  1122. source_model_name = source_models[assoc_name]
  1123. else:
  1124. return "Source model not bound: " + assoc_name!
  1125. source_model_ID = get_entry_id(source_model_name)
  1126. if (source_model_ID != ""):
  1127. if (allow_read(current_user_id, source_model_ID)):
  1128. // Check for conformance to the requested metamodel
  1129. dict_add(inputs, assoc_name, source_model_name)
  1130. continue!
  1131. else:
  1132. return "Permission denied to model: " + source_model_name!
  1133. else:
  1134. return "Model not found: " + source_model_name!
  1135. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  1136. outputs = dict_create()
  1137. output_map = dict_create()
  1138. while (set_len(targets) > 0):
  1139. target = set_pop(targets)
  1140. assoc_name = read_attribute(core, target, "name")
  1141. if (dict_in(target_models, assoc_name)):
  1142. target_model_name = target_models[assoc_name]
  1143. if (get_entry_id(target_model_name) == ""):
  1144. // Doesn't exist yet, so we can easily create
  1145. if (get_entry_id(get_foldername(target_model_name)) == ""):
  1146. return "Folder not found: " + get_foldername(target_model_name)!
  1147. else:
  1148. if (allow_write(current_user_id, get_entry_id(get_foldername(target_model_name)))):
  1149. dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
  1150. dict_add(outputs, assoc_name, target_model_name)
  1151. else:
  1152. return "Permission denied to folder: " + get_foldername(target_model_name)!
  1153. else:
  1154. // Already exists, so we need to check for write access
  1155. if (allow_write(current_user_id, get_entry_id(target_model_name))):
  1156. dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
  1157. dict_add(outputs, assoc_name, target_model_name)
  1158. else:
  1159. return "Permission denied to model: " + target_model_name!
  1160. if (read_type(core, transformation_id) == "ActionLanguage"):
  1161. output("Success: ready for AL execution")
  1162. elif (read_type(core, transformation_id) == "ManualOperation"):
  1163. output("Success: ready for MANUAL execution")
  1164. else:
  1165. output("Success: ready for MT execution")
  1166. // Do tracability
  1167. Element tracability_model
  1168. if (tracability_name != ""):
  1169. // Check if exists
  1170. if (get_entry_id(tracability_name) == ""):
  1171. // No, so create
  1172. tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
  1173. model_create(tracability_model, tracability_name, get_entry_id("formalisms/Tracability"), "Model")
  1174. else:
  1175. // Yes, so read out
  1176. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1177. else:
  1178. tracability_model = read_root()
  1179. result = execute_operation(transformation_id, inputs, tracability_model)
  1180. // Flush tracability again, just to be sure
  1181. if (tracability_name != ""):
  1182. model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1183. // Now write out the models again
  1184. if (element_eq(result, read_root())):
  1185. // Something went wrong!
  1186. return "Failure"!
  1187. else:
  1188. keys = dict_keys(outputs)
  1189. while (set_len(keys) > 0):
  1190. key = set_pop(keys)
  1191. log("Writing away model with key " + cast_string(key))
  1192. log("Output map: " + dict_to_string(output_map))
  1193. log("Outputs: " + dict_to_string(outputs))
  1194. if (get_entry_id(outputs[key]) == ""):
  1195. // New model
  1196. log("New model!")
  1197. model_create(result[key], outputs[key], get_entry_id(output_map[key]), "Model")
  1198. else:
  1199. log("Existing model!")
  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. output("Operating on: merged/" + operation_name)
  1433. modify(merged_formalism, True)
  1434. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1435. if (operation_type == "manual"):
  1436. // Finished with all information, now create the model itself!
  1437. Element m
  1438. m = get_full_model(get_entry_id("formalisms/ManualOperation"), get_entry_id("formalisms/SimpleClassDiagrams"))
  1439. if (element_eq(m, read_root())):
  1440. log("Error when opening ManualOperation: no conformance relation found")
  1441. return "Error when opening ManualOperation: no conformance relation found"!
  1442. model_create(instantiate_model(m), operation_name, get_entry_id("formalisms/ManualOperation"), "ManualOperation")
  1443. model_id = get_entry_id(operation_name)
  1444. elif (operation_type == "actionlanguage"):
  1445. // Finished with all information, now create the model itself!
  1446. output("Waiting for code constructors...")
  1447. Element compiled
  1448. compiled = compile_code(input())
  1449. if (element_eq(compiled, read_root())):
  1450. return "Compilation error"!
  1451. add_code_model(get_full_model(get_entry_id("formalisms/ActionLanguage"), get_entry_id("formalisms/SimpleClassDiagrams")), "AL/" + operation_name, compiled)
  1452. model_create(import_node("AL/" + operation_name), operation_name, get_entry_id("formalisms/ActionLanguage"), "ActionLanguage")
  1453. model_id = get_entry_id(operation_name)
  1454. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1455. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1456. // Add tracability links at this level
  1457. while (set_len(all_formalisms) > 0):
  1458. source_formalism_id = set_pop(all_formalisms)
  1459. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1460. instantiate_attribute(core, tracability_link, "type", "merged")
  1461. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1462. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1463. // Extend metadata with info on source and target
  1464. String link
  1465. String dst
  1466. keys = dict_keys(source)
  1467. while (set_len(keys) > 0):
  1468. key = set_pop(keys)
  1469. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1470. instantiate_attribute(core, link, "name", key)
  1471. keys = dict_keys(target)
  1472. while (set_len(keys) > 0):
  1473. key = set_pop(keys)
  1474. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1475. instantiate_attribute(core, link, "name", key)
  1476. return "Success"!
  1477. else:
  1478. return "Model exists: " + operation_name!
  1479. String function cmd_transformation_add_MT(source_models : Element, target_models : Element, operation_name : String):
  1480. // Add a model transformation model
  1481. // Just a usual model instantiation, but need to add the source and target links based on user info
  1482. String ramified_metamodel_id
  1483. Element ramified_metamodel
  1484. String model_id
  1485. Element models
  1486. Element links
  1487. String link_id
  1488. Element supported
  1489. Element source
  1490. Element target
  1491. String name
  1492. String new_model_id
  1493. String merged_link_id
  1494. Element links_merged
  1495. String merged_formalism
  1496. Element keys
  1497. String key
  1498. Element mm
  1499. Element to_ramify
  1500. String source_formalism_id
  1501. String merged_formalism_id
  1502. String tracability_link
  1503. source = dict_create()
  1504. target = dict_create()
  1505. to_ramify = set_create()
  1506. keys = dict_keys(source_models)
  1507. while (set_len(keys) > 0):
  1508. key = set_pop(keys)
  1509. name = source_models[key]
  1510. model_id = get_entry_id(name)
  1511. if (model_id != ""):
  1512. if (allow_read(current_user_id, name)):
  1513. // Check whether or not it is formalisms/SimpleClassDiagrams
  1514. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1515. if (bool_not(dict_in(source, key))):
  1516. dict_add(source, key, model_id)
  1517. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1518. if (element_eq(mm, read_root())):
  1519. return "ModelTransformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1520. set_add_node(to_ramify, create_tuple(key, mm))
  1521. else:
  1522. return "Name was already assigned a metamodel: " + key!
  1523. else:
  1524. return "Model not supported for RAMification: " + name!
  1525. else:
  1526. return "Permission denied: " + name!
  1527. else:
  1528. return "Model not found: " + name!
  1529. keys = dict_keys(target_models)
  1530. while (set_len(keys) > 0):
  1531. key = set_pop(keys)
  1532. name = target_models[key]
  1533. model_id = get_entry_id(name)
  1534. if (model_id != ""):
  1535. if (allow_read(current_user_id, name)):
  1536. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1537. if (bool_not(dict_in(target, key))):
  1538. if (dict_in(source, key)):
  1539. if (value_eq(model_id, source[key])):
  1540. dict_add(target, key, model_id)
  1541. // Don't add to to_ramify, as it is already in there!
  1542. else:
  1543. return "Name in output cannot have different type than input: " + key!
  1544. else:
  1545. dict_add(target, key, model_id)
  1546. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1547. if (element_eq(mm, read_root())):
  1548. return "ModelTransformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1549. set_add_node(to_ramify, create_tuple(key, mm))
  1550. else:
  1551. return "Name was already assigned a metamodel: " + key!
  1552. else:
  1553. return "Model not supported for RAMification: " + name!
  1554. else:
  1555. return "Permission denied: " + name!
  1556. else:
  1557. return "Model not found: " + name!
  1558. merged_formalism = model_fuse(to_ramify)
  1559. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1560. output("Operating on: merged/" + operation_name)
  1561. modify(merged_formalism, True)
  1562. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1563. ramified_metamodel = ramify(merged_formalism)
  1564. model_create(ramified_metamodel, "RAMified/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1565. ramified_metamodel_id = get_entry_id("RAMified/" + operation_name)
  1566. // Now use the RAMified model to create the instance
  1567. if (get_entry_id(operation_name) == ""):
  1568. String new_model
  1569. // Finished with all information, now create the model itself!
  1570. output("Waiting for model constructors...")
  1571. new_model = compile_model(input(), get_full_model(ramified_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams")))
  1572. if (element_eq(new_model, read_root())):
  1573. return "Compilation error"!
  1574. model_create(new_model, operation_name, ramified_metamodel_id, "ModelTransformation")
  1575. model_id = get_entry_id(operation_name)
  1576. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1577. // New location is available, so write
  1578. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1579. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1580. // Add tracability links at this level
  1581. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1582. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1583. // Add tracability links at this level
  1584. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1585. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1586. // Extend metadata with info on source and target
  1587. String link
  1588. String dst
  1589. keys = dict_keys(source)
  1590. while (set_len(keys) > 0):
  1591. key = set_pop(keys)
  1592. dst = source[key]
  1593. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1594. instantiate_attribute(core, link, "name", key)
  1595. keys = dict_keys(target)
  1596. while (set_len(keys) > 0):
  1597. key = set_pop(keys)
  1598. dst = target[key]
  1599. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1600. instantiate_attribute(core, link, "name", key)
  1601. return "Success"!
  1602. else:
  1603. return "Model exists: " + operation_name!
  1604. String function cmd_permission_modify(model_name : String, permissions : String):
  1605. Integer permission
  1606. String model_id
  1607. model_id = get_entry_id(model_name)
  1608. if (model_id != ""):
  1609. if (get_relation_to_model(current_user_id, model_id) == 0):
  1610. Boolean fail
  1611. Integer i
  1612. i = 0
  1613. if (string_len(permissions) != 3):
  1614. fail = True
  1615. while (i < 3):
  1616. permission = cast_integer(string_get(permissions, i))
  1617. if (bool_or(permission < 0, permission > 2)):
  1618. fail = True
  1619. break!
  1620. i = i + 1
  1621. if (bool_not(fail)):
  1622. unset_attribute(core, model_id, "permissions")
  1623. instantiate_attribute(core, model_id, "permissions", permissions)
  1624. return "Success"!
  1625. else:
  1626. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1627. else:
  1628. return "Permission denied to model: " + model_name!
  1629. else:
  1630. return "Model not found: " + model_name!
  1631. String function cmd_permission_owner(model_name : String, new_user_name : String):
  1632. String model_id
  1633. String new_user_id
  1634. model_id = get_entry_id(model_name)
  1635. if (model_id != ""):
  1636. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1637. new_user_id = get_user_id(new_user_name)
  1638. if (new_user_id != ""):
  1639. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1640. instantiate_link(core, "owner", "", model_id, new_user_id)
  1641. return "Success"!
  1642. else:
  1643. return "No such user: " + new_user_name!
  1644. else:
  1645. return "Permission denied to model: " + model_name!
  1646. else:
  1647. return "Model not found: " + model_name!
  1648. String function cmd_permission_group(model_name : String, new_group_name : String):
  1649. String model_id
  1650. String group_id
  1651. model_id = get_entry_id(model_name)
  1652. if (model_id != ""):
  1653. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1654. group_id = get_group_id(new_group_name)
  1655. if (group_id != ""):
  1656. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1657. instantiate_link(core, "group", "", model_id, group_id)
  1658. return "Success"!
  1659. else:
  1660. return "No such group: " + new_group_name!
  1661. else:
  1662. return "Permission denied to model: " + model_name!
  1663. else:
  1664. return "Model not found: " + model_name!
  1665. String function cmd_group_create(group_name : String):
  1666. // Create a new group and become its owner
  1667. String group_id
  1668. String name
  1669. group_id = get_group_id(group_name)
  1670. if (group_id == ""):
  1671. group_id = instantiate_node(core, "Group", "")
  1672. instantiate_attribute(core, group_id, "name", group_name)
  1673. instantiate_link(core, "belongsTo", "", current_user_id, group_id)
  1674. instantiate_link(core, "owner", "", group_id, current_user_id)
  1675. return "Success"!
  1676. else:
  1677. return "Group exists: " + group_name!
  1678. String function cmd_group_delete(group_name : String):
  1679. // Delete an existing group
  1680. String group_id
  1681. group_id = get_group_id(group_name)
  1682. if (group_id != ""):
  1683. if (allow_group_modify(current_user_id, group_id)):
  1684. model_delete_element(core, group_id)
  1685. return "Success"!
  1686. else:
  1687. return "Permission denied to group: " + group_name!
  1688. else:
  1689. return "Group not found: " + group_name!
  1690. String function cmd_group_owner_add(group_name : String, other_user_name : String):
  1691. // Add an owner to your group
  1692. String group_id
  1693. String other_user_id
  1694. group_id = get_group_id(group_name)
  1695. if (group_id != ""):
  1696. if (allow_group_modify(current_user_id, group_id)):
  1697. other_user_id = get_user_id(other_user_name)
  1698. if (other_user_id != ""):
  1699. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1700. instantiate_link(core, "owner", "", group_id, other_user_id)
  1701. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1702. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1703. return "Success"!
  1704. else:
  1705. return "User is already the owner!"!
  1706. else:
  1707. return "User not found: " + other_user_name!
  1708. else:
  1709. return "Permission denied to group: " + group_name!
  1710. else:
  1711. return "Group not found: " + group_name!
  1712. String function cmd_group_owner_delete(group_name : String, other_user_name : String):
  1713. // Remove an owner from your group
  1714. String group_id
  1715. String other_user_id
  1716. group_id = get_group_id(group_name)
  1717. if (group_id != ""):
  1718. if (allow_group_modify(current_user_id, group_id)):
  1719. other_user_id = get_user_id(other_user_name)
  1720. if (other_user_id != ""):
  1721. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1722. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1723. Element overlap
  1724. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1725. model_delete_element(core, set_pop(overlap))
  1726. return "Success"!
  1727. else:
  1728. return "User is not an owner of the group!"!
  1729. else:
  1730. return "User is not a member of the group!"!
  1731. else:
  1732. return "User not found: " + other_user_name!
  1733. else:
  1734. return "Permission denied to group: " + group_name!
  1735. else:
  1736. return "Group not found: " + group_name!
  1737. String function cmd_group_join(group_name : String, other_user_name : String):
  1738. // Add someone to your group
  1739. String group_id
  1740. String other_user_id
  1741. group_id = get_group_id(group_name)
  1742. if (group_id != ""):
  1743. if (allow_group_modify(current_user_id, group_id)):
  1744. other_user_id = get_user_id(other_user_name)
  1745. if (other_user_id != ""):
  1746. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1747. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1748. return "Success"!
  1749. else:
  1750. return "User is already a member of the group!"!
  1751. else:
  1752. return "User not found: " + other_user_name!
  1753. else:
  1754. return "Permission denied to group: " + group_name!
  1755. else:
  1756. return "Group not found: " + group_name!
  1757. String function cmd_group_kick(group_name : String, other_user_name : String):
  1758. // Remove someone from your group
  1759. String group_id
  1760. String other_user_id
  1761. group_id = get_group_id(group_name)
  1762. if (group_id != ""):
  1763. if (allow_group_modify(current_user_id, group_id)):
  1764. other_user_id = get_user_id(other_user_name)
  1765. if (other_user_id != ""):
  1766. Element overlap
  1767. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1768. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1769. model_delete_element(core,set_pop(overlap))
  1770. // Check if user was an owner as well
  1771. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1772. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1773. model_delete_element(core, set_pop(overlap))
  1774. return "Success"!
  1775. else:
  1776. return "User is not a member of the group!"!
  1777. else:
  1778. return "User not found: " + other_user_name!
  1779. else:
  1780. return "Permission denied to group: " + group_name!
  1781. else:
  1782. return "Group not found: " + group_name!
  1783. String function cmd_group_list():
  1784. // List all groups you are a member of (and whether you are admin or not!)
  1785. Element groups
  1786. String group_id
  1787. String admin
  1788. String result
  1789. result = ""
  1790. groups = allAssociationDestinations(core, current_user_id, "belongsTo")
  1791. while (set_len(groups) > 0):
  1792. group_id = set_pop(groups)
  1793. if (set_in(allAssociationDestinations(core, group_id, "owner"), current_user_id)):
  1794. admin = " A "
  1795. else:
  1796. admin = " "
  1797. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1798. return result!
  1799. String function cmd_admin_promote(other_user_name : String):
  1800. // Promote a user to admin status
  1801. if (is_admin(current_user_id)):
  1802. String other_user_id
  1803. other_user_id = get_user_id(other_user_name)
  1804. if (other_user_id != ""):
  1805. unset_attribute(core, other_user_id, "admin")
  1806. instantiate_attribute(core, other_user_id, "admin", True)
  1807. return "Success"!
  1808. else:
  1809. return "User not found: " + other_user_name!
  1810. else:
  1811. return "Permission denied to administrate: " + other_user_name!
  1812. String function cmd_admin_demote(other_user_name : String):
  1813. // Demote a user to normal status
  1814. if (is_admin(current_user_id)):
  1815. String other_user_id
  1816. other_user_id = get_user_id(other_user_name)
  1817. if (other_user_id != ""):
  1818. unset_attribute(core, other_user_id, "admin")
  1819. instantiate_attribute(core, other_user_id, "admin", False)
  1820. return "Success"!
  1821. else:
  1822. return "User not found: " + other_user_name!
  1823. else:
  1824. return "Permission denied to administrate: " + other_user_name!
  1825. String function cmd_service_register(service_name : String):
  1826. // Active a service for this specific user
  1827. if (get_service_id(service_name) == ""):
  1828. String service
  1829. service = instantiate_node(core, "Service", "")
  1830. instantiate_attribute(core, service, "name", service_name)
  1831. instantiate_attribute(core, service, "port", get_taskname())
  1832. output("Success: " + get_taskname())
  1833. // Wait until we can stop the service
  1834. while (cast_value(input()) != "\"service_stop\""):
  1835. output("Service is running on this task: stop it by sending 'service_stop'")
  1836. model_delete_element(core, service)
  1837. // Service terminated
  1838. return "Success"!
  1839. else:
  1840. return "Service already exists: " + service_name!
  1841. String function cmd_user_password(user_name : String, new_password : String):
  1842. if (bool_or(current_user_id == get_user_id(user_name), is_admin(current_user_id))):
  1843. if (get_user_id(user_name) != ""):
  1844. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1845. return "Success"!
  1846. else:
  1847. return "No such user: " + user_name!
  1848. else:
  1849. return "Permission denied to user: " + user_name!
  1850. String function cmd_transformation_signature(transformation_name : String):
  1851. String model_id
  1852. model_id = get_entry_id(transformation_name)
  1853. if (model_id != ""):
  1854. if (is_nominal_instance(core, model_id, "Transformation")):
  1855. if (allow_read(current_user_id, transformation_name)):
  1856. String result
  1857. String elem
  1858. Element inputs
  1859. Element outputs
  1860. result = "Success: "
  1861. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1862. while (set_len(inputs) > 0):
  1863. elem = set_pop(inputs)
  1864. result = string_join(string_join(string_join(string_join(result + "I ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1865. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1866. while (set_len(outputs) > 0):
  1867. elem = set_pop(outputs)
  1868. result = string_join(string_join(string_join(string_join(result + "O ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1869. return result!
  1870. else:
  1871. return "Permission denied to operation: " + transformation_name!
  1872. else:
  1873. return "Model is not an operation: " + transformation_name!
  1874. else:
  1875. return "No such operation: " + transformation_name!
  1876. String function cmd_model_types(model_name : String):
  1877. if (get_entry_id(model_name) != ""):
  1878. String model_id
  1879. model_id = get_entry_id(model_name)
  1880. Element types
  1881. String type
  1882. String result
  1883. result = "Success: "
  1884. types = allAssociationDestinations(core, model_id, "instanceOf")
  1885. while (set_len(types) > 0):
  1886. type = set_pop(types)
  1887. result = string_join(result, full_name(type) + "\n")
  1888. return result!
  1889. else:
  1890. return "No such model: " + model_name!
  1891. String function cmd_folder_create(folder_name : String):
  1892. if (get_entry_id(folder_name) == ""):
  1893. if (element_neq(create_folders(current_user_id, folder_name), read_root())):
  1894. return "Success"!
  1895. else:
  1896. return "Permission denied to folder: " + folder_name!
  1897. else:
  1898. return "Folder alreay exists: " + folder_name!
  1899. String function cmd_conformance_add(model_name : String, metamodel_name : String):
  1900. // Create a new instanceOf relation now
  1901. String instance_of
  1902. instance_of = instantiate_link(core, "instanceOf", "", get_entry_id(model_name), get_entry_id(metamodel_name))
  1903. return "Success"!
  1904. Void function user_function_skip_init(user_id : String):
  1905. String cmd
  1906. String result
  1907. current_user_id = user_id
  1908. caches = dict_create()
  1909. dict_add_fast(caches, "models", dict_create())
  1910. dict_add_fast(caches, "users", dict_create())
  1911. dict_add_fast(caches, "full_name", dict_create())
  1912. // Find root element
  1913. Element elems
  1914. String elem
  1915. elems = allInstances(core, "Folder")
  1916. while (set_len(elems) > 0):
  1917. elem = set_pop(elems)
  1918. if (value_eq(read_attribute(core, elem, "name"), "")):
  1919. if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
  1920. dict_add_fast(caches, "root", elem)
  1921. break!
  1922. output("Welcome to the Model Management Interface v2.0!")
  1923. output("Use the 'help' command for a list of possible commands")
  1924. while (True):
  1925. cmd = input()
  1926. if (cmd == "help"):
  1927. output(cmd_help())
  1928. elif (cmd == "model_add"):
  1929. output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
  1930. elif (cmd == "process_execute"):
  1931. output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
  1932. elif (cmd == "process_signature"):
  1933. output(cmd_process_signature(single_input("Process to execute?")))
  1934. elif (cmd == "transformation_between"):
  1935. output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
  1936. elif (cmd == "model_render"):
  1937. output(cmd_model_render(single_input("Model name?"), single_input("Mapper name?"), single_input("Rendered name?")))
  1938. elif (cmd == "model_rendered"):
  1939. output(cmd_model_rendered(single_input("Model name?"), single_input("Mapper name?")))
  1940. elif (cmd == "transformation_execute"):
  1941. output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?"), single_input("Tracability model?")))
  1942. elif (cmd == "verify"):
  1943. result = cmd_verify(single_input("Model name?"), single_input("Metamodel name?"))
  1944. if (result != ""):
  1945. output(result)
  1946. elif (cmd == "model_overwrite"):
  1947. output(cmd_model_overwrite(single_input("Model name?"), single_input("Metamodel name?")))
  1948. elif (cmd == "model_modify"):
  1949. output(cmd_model_modify(single_input("Model name?"), single_input("Metamodel name?")))
  1950. elif (cmd == "model_delete"):
  1951. output(cmd_model_delete(single_input("Model name?")))
  1952. elif (cmd == "model_list"):
  1953. output(cmd_model_list(single_input("Location?")))
  1954. elif (cmd == "model_list_full"):
  1955. output(cmd_model_list_full(single_input("Location?")))
  1956. elif (cmd == "transformation_add_MANUAL"):
  1957. output(cmd_transformation_add_MANUAL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  1958. elif (cmd == "transformation_add_AL"):
  1959. output(cmd_transformation_add_AL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  1960. elif (cmd == "transformation_add_MT"):
  1961. output(cmd_transformation_add_MT(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  1962. elif (cmd == "permission_modify"):
  1963. output(cmd_permission_modify(single_input("Model name?"), single_input("Permissions?")))
  1964. elif (cmd == "permission_owner"):
  1965. output(cmd_permission_owner(single_input("Model name?"), single_input("New owning user?")))
  1966. elif (cmd == "permission_group"):
  1967. output(cmd_permission_group(single_input("Model name?"), single_input("New owning group?")))
  1968. elif (cmd == "group_create"):
  1969. output(cmd_group_create(single_input("New group name?")))
  1970. elif (cmd == "group_delete"):
  1971. output(cmd_group_delete(single_input("Group name?")))
  1972. elif (cmd == "group_owner_add"):
  1973. output(cmd_group_owner_add(single_input("Group name?"), single_input("User name?")))
  1974. elif (cmd == "group_owner_delete"):
  1975. output(cmd_group_owner_delete(single_input("Group name?"), single_input("User name?")))
  1976. elif (cmd == "group_join"):
  1977. output(cmd_group_join(single_input("Group name?"), single_input("User name?")))
  1978. elif (cmd == "group_kick"):
  1979. output(cmd_group_kick(single_input("Group name?"), single_input("User name?")))
  1980. elif (cmd == "group_list"):
  1981. output(cmd_group_list())
  1982. elif (cmd == "admin_promote"):
  1983. output(cmd_admin_promote(single_input("User name?")))
  1984. elif (cmd == "admin_demote"):
  1985. output(cmd_admin_demote(single_input("User name?")))
  1986. elif (cmd == "service_register"):
  1987. output(cmd_service_register(single_input("Service name?")))
  1988. elif (cmd == "user_password"):
  1989. output(cmd_user_password(single_input("User name?"), single_input("New password?")))
  1990. elif (cmd == "transformation_read_signature"):
  1991. output(cmd_transformation_signature(single_input("Transformation name?")))
  1992. elif (cmd == "verbose"):
  1993. set_verbose(True)
  1994. elif (cmd == "quiet"):
  1995. set_verbose(False)
  1996. elif (cmd == "self-destruct"):
  1997. // Delete user from Core Formalism
  1998. model_delete_element(core, user_id)
  1999. return !
  2000. elif (cmd == "user_logout"):
  2001. // TODO
  2002. cmd = "FAIL"
  2003. elif (cmd == "exit"):
  2004. // Exit by actually removing the user and decoupling it from all of its models
  2005. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  2006. // as the current user will have been deleted
  2007. return !
  2008. elif (cmd == "folder_create"):
  2009. output(cmd_folder_create(single_input("Folder name?")))
  2010. elif (cmd == "add_conformance"):
  2011. log("Adding conformance relation...")
  2012. output(cmd_conformance_add(single_input("Model name?"), single_input("Metamodel name?")))
  2013. log("Added!")
  2014. elif (cmd == "remove_conformance"):
  2015. // TODO
  2016. cmd = "FAIL"
  2017. elif (cmd == "user_name"):
  2018. // TODO
  2019. cmd = "FAIL"
  2020. elif (cmd == "service_poll"):
  2021. // TODO
  2022. cmd = "FAIL"
  2023. elif (cmd == "model_types"):
  2024. output(cmd_model_types(single_input("Model name?")))
  2025. else:
  2026. output("Unknown command: " + cmd)
  2027. // We never get here!
  2028. return !