core_algorithm.alc 88 KB

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