core_algorithm.alc 86 KB

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