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