core_algorithm.alc 89 KB

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