core_algorithm.alc 89 KB

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