core_algorithm.alc 86 KB

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