core_algorithm.alc 87 KB

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