core_algorithm.alc 86 KB

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