core_algorithm.alc 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  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. String core_model_location = "models/core"
  16. Element core = ?
  17. Element caches
  18. String function full_name(model_id : String):
  19. //if (dict_in(caches["full_name"], model_id)):
  20. // if (get_entry_id(caches["full_name"][model_id]) == model_id):
  21. // return caches["full_name"]!
  22. // No cache, or out of date
  23. Element incoming
  24. String parent
  25. String parent_name
  26. incoming = allAssociationOrigins(core, model_id, "contains")
  27. if (set_len(incoming) > 0):
  28. parent = set_pop(incoming)
  29. parent_name = full_name(parent)
  30. //dict_add(caches["full_name"], parent, parent_name)
  31. return string_join(parent_name + "/", read_attribute(core, model_id, "name"))!
  32. else:
  33. return ""!
  34. Void function initialize_core():
  35. // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
  36. add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
  37. return !
  38. Boolean function is_typed_by(model_id : String, metamodel_id : String):
  39. return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
  40. Element function get_instanceOf_links(model_id : String, metamodel_id : String):
  41. Element result
  42. Element options
  43. String elem
  44. result = set_create()
  45. options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  46. while (set_len(options) > 0):
  47. elem = set_pop(options)
  48. if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
  49. set_add(result, elem)
  50. return result!
  51. String function get_instanceOf_link(model_id : String, metamodel_id : String):
  52. Element all_links
  53. String choice
  54. all_links = get_instanceOf_links(model_id, metamodel_id)
  55. if (set_len(all_links) > 1):
  56. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  57. elif (set_len(all_links) == 0):
  58. log("No types found!")
  59. return read_root()!
  60. choice = set_pop(all_links)
  61. return choice!
  62. Element function get_full_model(model_id : String, metamodel_id : String):
  63. // TODO we are restricted to using formalisms/SimpleClassDiagrams as M3 level, through this code!
  64. Element m
  65. Element all_links
  66. String choice
  67. choice = get_instanceOf_link(model_id, metamodel_id)
  68. m = dict_create()
  69. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  70. // TODO for now this is restricted to the fixed semantics
  71. // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
  72. dict_add(m, "semantics", get_entry_id("models/conformance_mv"))
  73. if (metamodel_id == model_id):
  74. // Found the meta-circular level, so we can stop!
  75. dict_add(m, "metamodel", m)
  76. else:
  77. Element mm
  78. mm = get_full_model(metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  79. if (element_eq(mm, read_root())):
  80. return read_root()!
  81. else:
  82. dict_add(m, "metamodel", mm)
  83. if (element_neq(choice, read_root())):
  84. if (set_len(allAssociationDestinations(core, choice, "typing")) == 1):
  85. // Add the preferred original type mapping
  86. dict_add(m, "type_mapping", import_node(read_attribute(core, set_pop(allAssociationDestinations(core, choice, "typing")), "location")))
  87. else:
  88. // Start from scratch
  89. dict_add(m, "type_mapping", new_type_mapping())
  90. else:
  91. // Start from scratch
  92. dict_add(m, "type_mapping", new_type_mapping())
  93. if (find_type_mapping(m)):
  94. // TODO store the found type model somewhere
  95. return m!
  96. else:
  97. log("No type mapping could be deduced!")
  98. log("Error for " + cast_v2s(read_attribute(core, model_id, "name")))
  99. log(" and type " + cast_v2s(read_attribute(core, metamodel_id, "name")))
  100. return read_root()!
  101. Integer function get_relation_to_model(user_id : String, model_id : String):
  102. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  103. // We are the owner
  104. return 0!
  105. else:
  106. String group_id
  107. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  108. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  109. // We are in the owning group
  110. return 1!
  111. else:
  112. // We are not related whatsoever
  113. return 2!
  114. Boolean function is_admin(user_id : String):
  115. if (read_attribute(core, user_id, "admin")):
  116. return True!
  117. else:
  118. return False!
  119. Boolean function allow_read(user_id : String, model_id : String):
  120. if (is_admin(user_id)):
  121. // Is admin, so always allow
  122. return True!
  123. else:
  124. // Check permissions
  125. String permission
  126. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  127. if (bool_or(permission == "1", permission == "2")):
  128. return True!
  129. else:
  130. return False!
  131. Boolean function allow_write(user_id : String, model_id : String):
  132. if (is_admin(user_id)):
  133. // Is admin, so always allow
  134. return True!
  135. else:
  136. // Check permissions
  137. String permission
  138. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  139. if (permission == "2"):
  140. return True!
  141. else:
  142. return False!
  143. Boolean function allow_change_metadata(user_id : String, model_id : String):
  144. if (is_admin(user_id)):
  145. // Is admin, so always allow
  146. return True!
  147. else:
  148. if (get_relation_to_model(user_id, model_id) == 0):
  149. // Only owner can chmod
  150. return True!
  151. else:
  152. return False!
  153. Boolean function allow_group_modify(user_id : String, group_id : String):
  154. if (is_admin(user_id)):
  155. // Is admin, so always allow
  156. return True!
  157. else:
  158. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  159. // We are an owner
  160. return True!
  161. else:
  162. return False!
  163. Boolean function check_login(user_id : String):
  164. String password
  165. String stored_password
  166. stored_password = read_attribute(core, user_id, "password")
  167. output("Password for existing user?")
  168. password = hash(input())
  169. return password == stored_password!
  170. Void function new_task():
  171. String username
  172. String user_id
  173. String password
  174. // Load in a hard-reference to the previously created model
  175. core = import_node(core_model_location)
  176. while (True):
  177. output("Log on as which user?")
  178. username = input()
  179. user_id = get_user_id(username)
  180. if (user_id == ""):
  181. // New user
  182. // Add user to Core Formalism
  183. user_id = instantiate_node(core, "User", "")
  184. instantiate_attribute(core, user_id, "name", username)
  185. instantiate_attribute(core, user_id, "admin", False)
  186. output("This is a new user: please give password!")
  187. password = hash(input())
  188. output("Please repeat the password")
  189. if (password == hash(input())):
  190. output("Passwords match!")
  191. instantiate_attribute(core, user_id, "password", password)
  192. break!
  193. else:
  194. output("Not the same password!")
  195. else:
  196. if (check_login(user_id)):
  197. break!
  198. else:
  199. output("Wrong password!")
  200. user_function_skip_init(user_id)
  201. // User destroyed already, so just stop execution
  202. return!
  203. String function get_entry_id(name : String):
  204. Element hierarchy_split
  205. String current
  206. Integer i
  207. Element elems
  208. String current_part
  209. String elem
  210. Boolean found
  211. i = 0
  212. //log("Searching for " + name)
  213. hierarchy_split = string_split(name, "/")
  214. current = caches["root"]
  215. Element dict
  216. while (i < list_len(hierarchy_split)):
  217. current_part = list_read(hierarchy_split, i)
  218. if (current_part != ""):
  219. dict = dict_create()
  220. found = False
  221. elems = allAssociationDestinations(core, current, "contains")
  222. while (set_len(elems) > 0):
  223. elem = set_pop(elems)
  224. if (value_eq(read_attribute(core, elem, "name"), current_part)):
  225. current = elem
  226. found = True
  227. break!
  228. if (bool_not(found)):
  229. return ""!
  230. i = i + 1
  231. return current!
  232. String function get_service_id(name : String):
  233. Element services
  234. String service
  235. services = allInstances(core, "Service")
  236. while (set_len(services) > 0):
  237. service = set_pop(services)
  238. if (value_eq(read_attribute(core, service, "name"), name)):
  239. return service!
  240. return ""!
  241. String function get_user_id(name : String):
  242. Element users
  243. String user
  244. users = allInstances(core, "User")
  245. while (set_len(users) > 0):
  246. user = set_pop(users)
  247. if (value_eq(read_attribute(core, user, "name"), name)):
  248. return user!
  249. return ""!
  250. String function get_group_id(name : String):
  251. Element groups
  252. String group
  253. groups = allInstances(core, "Group")
  254. while (set_len(groups) > 0):
  255. group = set_pop(groups)
  256. if (value_eq(read_attribute(core, group, "name"), name)):
  257. return group!
  258. return ""!
  259. String function store_entry(model_id : String, full_name : String, user_id : String):
  260. Element hierarchy
  261. Integer i
  262. String prev
  263. String elem
  264. String new_entry
  265. String cummul
  266. i = 0
  267. hierarchy = string_split(full_name, "/")
  268. prev = get_entry_id("")
  269. cummul = ""
  270. // Go through folders first
  271. while (i < list_len(hierarchy) - 1):
  272. elem = list_read(hierarchy, i)
  273. cummul = string_join(cummul + "/", elem)
  274. if (get_entry_id(cummul) == ""):
  275. // Element does not exist yet!
  276. new_entry = instantiate_node(core, "Folder", "")
  277. instantiate_attribute(core, new_entry, "name", elem)
  278. instantiate_attribute(core, new_entry, "permissions", "200")
  279. instantiate_link(core, "contains", "", prev, new_entry)
  280. instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
  281. instantiate_link(core, "owner", "", new_entry, user_id)
  282. prev = get_entry_id(cummul)
  283. i = i + 1
  284. instantiate_link(core, "contains", "", prev, model_id)
  285. return list_pop_final(hierarchy)!
  286. String function export_typing(model : Element, name : String, user_id : String):
  287. String result
  288. result = instantiate_node(core, "TypeMapping", "")
  289. name = "type mappings/" + name
  290. // Create type mapping model
  291. String location
  292. location = "type mappings/" + cast_id2s(model["type_mapping"])
  293. export_node(location, model["type_mapping"])
  294. String instance_of
  295. name = store_entry(result, name, get_user_id("admin"))
  296. instantiate_attribute(core, result, "name", name)
  297. instantiate_attribute(core, result, "location", location)
  298. instantiate_attribute(core, result, "permissions", "200")
  299. instantiate_link(core, "owner", "", result, user_id)
  300. instantiate_link(core, "group", "", result, get_group_id("nobody"))
  301. instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("formalisms/TypeMapping"))
  302. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  303. return result!
  304. Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
  305. String location
  306. String model_id
  307. String instance_of
  308. // Create model itself
  309. location = "models/" + cast_id2s(model)
  310. export_node(location, model["model"])
  311. model_id = instantiate_node(core, kind, "")
  312. instantiate_attribute(core, model_id, "name", store_entry(model_id, name, user_id))
  313. instantiate_attribute(core, model_id, "location", location)
  314. instantiate_attribute(core, model_id, "permissions", "200")
  315. log("Owner")
  316. instantiate_link(core, "owner", "", model_id, user_id)
  317. log("Group")
  318. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  319. log("type_id")
  320. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  321. log("Semantics")
  322. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  323. // Create type mapping model
  324. log("Typing")
  325. instantiate_link(core, "typing", "", instance_of, export_typing(model, name, user_id))
  326. return!
  327. Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
  328. // TODO this should be more elegant than just hiding the old elements
  329. String location
  330. String instanceOf_link
  331. location = "models/" + cast_id2s(model)
  332. export_node(location, model["model"])
  333. // Change location in meta-data
  334. unset_attribute(core, model_id, "location")
  335. instantiate_attribute(core, model_id, "location", location)
  336. // Update the instanceOf relation of the context in which we are working
  337. String choice
  338. log("Updating instanceOf in model_overwrite")
  339. choice = get_instanceOf_link(model_id, metamodel_id)
  340. if (element_neq(choice, read_root())):
  341. // There was a link, so we remove it
  342. model_delete_element(core, choice)
  343. // Create a new instanceOf relation now
  344. String instance_of
  345. instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
  346. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  347. instantiate_link(core, "typing", "", instance_of, export_typing(model, full_name(model_id), get_user_id("admin")))
  348. return!
  349. Boolean function check_conformance(model_id : String):
  350. // TODO check if it actually conforms, considering that instanceOf link
  351. // --> in-depth check
  352. return True!
  353. Boolean function pm_finished(worklist : Element, pm : String):
  354. Element finished
  355. Integer cnt
  356. Integer i
  357. // Check if any of the "finish" elements are in the worklist
  358. // If so, we can already finish, and therefore will stop immediately
  359. finished = allInstances(pm, "Finish")
  360. worklist = set_copy(worklist)
  361. while (set_len(worklist) > 0):
  362. // Check each finished element individually
  363. if (set_in(finished, list_read(set_pop(worklist), 0))):
  364. return True!
  365. return False!
  366. Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
  367. // Operations are always in-place and uses only a single metamodel
  368. // Therefore, we must:
  369. // 1) Find merged metamodel
  370. // 2) Merge the different source models and retype
  371. // 3) Perform the operation on the merged model
  372. // 4) Split the resulting model based on the target formalisms; if operation successful
  373. Element input_model
  374. String trace_link_id
  375. Element merged_model
  376. String merged_metamodel_id
  377. String ramified_metamodel_id
  378. Boolean result
  379. String exact_type
  380. Element trace_links
  381. String model_ID
  382. String key
  383. Element keys
  384. Element input_keys
  385. Element output_keys
  386. Element model_tuples
  387. String metamodel_name
  388. Element metamodel
  389. String metamodel_ID
  390. Boolean tracability
  391. // 0) Find the signature of the operation
  392. Element input_metamodels
  393. Element output_metamodels
  394. Element iter
  395. String edge
  396. input_metamodels = dict_create()
  397. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  398. while (set_len(iter) > 0):
  399. edge = set_pop(iter)
  400. dict_add(input_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  401. output_metamodels = dict_create()
  402. iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
  403. while (set_len(iter) > 0):
  404. edge = set_pop(iter)
  405. dict_add(output_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  406. // 1) Find merged metamodel
  407. exact_type = read_type(core, operation_id)
  408. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  409. merged_metamodel_id = ""
  410. while (set_len(trace_links) > 0):
  411. trace_link_id = set_pop(trace_links)
  412. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  413. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  414. // 2) Merge source models
  415. if (merged_metamodel_id != ""):
  416. model_tuples = set_create()
  417. keys = dict_keys(input_models)
  418. while (set_len(keys) > 0):
  419. key = set_pop(keys)
  420. Element mm
  421. mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
  422. if (element_eq(mm, read_root())):
  423. log("Signature mismatch in operation for tag " + key)
  424. output("Signature mismatch in operation for tag " + key)
  425. return read_root()!
  426. set_add_node(model_tuples, create_tuple(key, mm))
  427. Element merged_metamodel
  428. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  429. if (element_eq(merged_metamodel, read_root())):
  430. log("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  431. output("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  432. return read_root()!
  433. merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
  434. else:
  435. if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
  436. // Just skip the merge...
  437. Element m
  438. 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))]))
  439. if (element_eq(m, read_root())):
  440. log("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
  441. output("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
  442. return read_root()!
  443. merged_model = model_copy(m)
  444. elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
  445. merged_model = read_root()
  446. else:
  447. log("Could not resolve intermediate merged metamodel")
  448. output("Could not resolve intermediate merged metamodel")
  449. return read_root()!
  450. // 3) Transform
  451. if (exact_type == "ModelTransformation"):
  452. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  453. ramified_metamodel_id = ""
  454. while (set_len(trace_links) > 0):
  455. trace_link_id = set_pop(trace_links)
  456. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  457. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  458. Element operation
  459. operation = get_full_model(operation_id, ramified_metamodel_id)
  460. if (element_eq(operation, read_root())):
  461. log("Operation could not be typed by specified RAMified metamodel!")
  462. output("Operation could not be typed by specified RAMified metamodel!")
  463. return read_root()!
  464. result = transform(merged_model, operation)
  465. elif (exact_type == "ManualOperation"):
  466. output("Please perform manual operation " + cast_v2s(full_name(operation_id)))
  467. modify(merged_model, True)
  468. result = True
  469. elif (exact_type == "ActionLanguage"):
  470. Element func
  471. Element al
  472. al = get_full_model(operation_id, get_entry_id("formalisms/ActionLanguage"))
  473. if (element_eq(al, read_root())):
  474. log("Action Language operation not typed by ActionLanguage metamodel!")
  475. output("Action Language operation not typed by ActionLanguage metamodel!")
  476. return read_root()!
  477. func = get_func_AL_model(al)
  478. result = func(merged_model)
  479. else:
  480. log("Unknown type of operation: " + exact_type)
  481. output("Unknown type of operation: " + exact_type)
  482. return read_root()!
  483. // 4) Split in different models depending on type
  484. if (element_neq(tracability_model, read_root())):
  485. tracability = True
  486. else:
  487. tracability = False
  488. if (result):
  489. model_tuples = set_create()
  490. keys = dict_keys(output_metamodels)
  491. while (set_len(keys) > 0):
  492. key = set_pop(keys)
  493. Element mm
  494. mm = get_full_model(get_entry_id(output_metamodels[key]), get_entry_id("formalisms/SimpleClassDiagrams"))
  495. if (element_eq(mm, read_root())):
  496. log("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  497. output("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  498. return read_root()!
  499. set_add_node(model_tuples, create_tuple(key, mm))
  500. result = model_split(merged_model, model_tuples, tracability)
  501. if (tracability):
  502. Element new_tracability_model
  503. new_tracability_model = result["__tracability"]
  504. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  505. dict_overwrite(tracability_model, "type_mapping", new_tracability_model["type_mapping"])
  506. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  507. dict_delete(result, "__tracability")
  508. return result!
  509. else:
  510. log("Negative result of execution")
  511. return read_root()!
  512. Boolean function enact_action(pm : Element, element : String, prefix : String, user_id : String):
  513. Boolean result
  514. String transformation_id
  515. Element lst
  516. String elem
  517. Element inputs
  518. Element outputs
  519. String type_name
  520. String exact_type
  521. Element trace_links
  522. Element output_mms
  523. Element consumes_link
  524. String name
  525. String value
  526. String elem_name
  527. Element keys
  528. String key
  529. String consume
  530. String produce
  531. Element output_map
  532. inputs = dict_create()
  533. outputs = dict_create()
  534. output_map = dict_create()
  535. // Read out the referenced element from the MvC
  536. transformation_id = get_entry_id(read_attribute(pm, element, "name"))
  537. // Find all input model names
  538. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  539. while (set_len(lst) > 0):
  540. consume = set_pop(lst)
  541. value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
  542. dict_add(inputs, read_attribute(pm, consume, "name"), prefix + value)
  543. // Find all output model names and their metamodel
  544. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  545. while (set_len(lst) > 0):
  546. produce = set_pop(lst)
  547. elem = readAssociationDestination(pm, produce)
  548. type_name = read_attribute(pm, elem, "type")
  549. elem_name = read_attribute(pm, elem, "name")
  550. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  551. dict_add(output_map, read_attribute(pm, produce, "name"), prefix + elem_name)
  552. if read_type(core, transformation_id) == "ActionLanguage":
  553. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  554. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  555. elif read_type(core, transformation_id) == "ManualOperation":
  556. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  557. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  558. else:
  559. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  560. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  561. result = execute_operation(transformation_id, inputs, read_root())
  562. if (element_eq(result, read_root())):
  563. // Something went wrong!
  564. return False!
  565. else:
  566. keys = dict_keys(result)
  567. while (set_len(keys) > 0):
  568. key = set_pop(keys)
  569. if (get_entry_id(output_map[key]) == ""):
  570. // New model
  571. model_create(result[key], output_map[key], user_id, get_entry_id(outputs[key]), "Model")
  572. else:
  573. model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
  574. return True!
  575. Void function enact_PM(pm : Element, prefix : String, user_id : String):
  576. Element worklist
  577. String element
  578. String start
  579. String type
  580. Boolean result
  581. Element tuple
  582. Element counters
  583. Element join_nodes
  584. output("Success")
  585. // Initialize Join counters
  586. counters = dict_create()
  587. join_nodes = allInstances(pm, "Join")
  588. while (set_len(join_nodes) > 0):
  589. dict_add(counters, set_pop(join_nodes), 0)
  590. // Create the worklist with the Start instance as first element
  591. worklist = set_create()
  592. set_add_node(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  593. while (bool_not(pm_finished(worklist, pm))):
  594. // Pop a random element from the list and execute it
  595. tuple = set_pop(worklist)
  596. element = tuple[0]
  597. result = tuple[1]
  598. // Find the type (to see what to do with it)
  599. // this does not yet yield the type of transformation, if it is an Execution
  600. type = read_type(pm, element)
  601. if (type == "Start"):
  602. // Initial node, just progress to the next elements
  603. // Nothing to do here though, as we have just started
  604. result = True
  605. elif (type == "Finish"):
  606. // Should be impossible, as we would have ended...
  607. result = result
  608. elif (type == "Fork"):
  609. result = result
  610. elif (type == "Join"):
  611. // Only do this if all dependencies are fullfilled
  612. // So add to the counter of this Join
  613. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  614. // Now check whether we have enough tokens to execute the Join itself
  615. Integer required
  616. Integer got
  617. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  618. got = counters[element]
  619. if (got == required):
  620. // Reset counter to 0
  621. dict_overwrite(counters, element, 0)
  622. // And continue
  623. else:
  624. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  625. continue!
  626. elif (type == "Exec"):
  627. // Execute a transformation
  628. // This the difficult part!
  629. result = enact_action(pm, element, prefix, user_id)
  630. elif (type == "Decision"):
  631. // If the previous result is true, we add the normal one, otherwise the false one
  632. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  633. if (bool_not(result)):
  634. // Apparently it is False, so map this to the "Else" branch
  635. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  636. continue!
  637. else:
  638. // Apparently it is True, so map this to the "Then" branch
  639. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  640. continue!
  641. // We have finished the execution, so add all outgoing edges to the worklist
  642. Element all_next
  643. all_next = allAssociationDestinations(pm, element, "Next")
  644. String next
  645. while (set_len(all_next) > 0):
  646. next = set_pop(all_next)
  647. set_add_node(worklist, create_tuple(next, result))
  648. // Reached a finish element, so stop
  649. output("Success")
  650. return !
  651. String function cmd_help(user_id : String):
  652. String result
  653. result = ""
  654. result = result + ("Model operations\n")
  655. result = result + (" model_add -- Add a new model\n")
  656. result = result + (" model_modify -- Modify an existing model\n")
  657. result = result + (" model_list -- List all models\n")
  658. result = result + (" model_list_full -- List all models with full info\n")
  659. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  660. result = result + (" model_render -- Render a given model with a specified mapper\n")
  661. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  662. result = result + ("\n")
  663. result = result + ("Transformation-specific operations\n")
  664. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  665. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  666. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  667. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  668. result = result + (" transformation_list -- List all model transformations\n")
  669. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  670. result = result + (" transformation_detail -- List transformation details\n")
  671. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  672. result = result + ("\n")
  673. result = result + ("Process operations\n")
  674. result = result + (" process_execute -- Execute a process model\n")
  675. result = result + ("\n")
  676. result = result + ("Model permission operations\n")
  677. result = result + (" permission_modify -- Change model permissions\n")
  678. result = result + (" permission_owner -- Change model owner\n")
  679. result = result + (" permission_group -- Change model group\n")
  680. result = result + ("\n")
  681. result = result + ("Group operations\n")
  682. result = result + (" group_create -- Create a group\n")
  683. result = result + (" group_delete -- Delete a group\n")
  684. result = result + (" group_owner_add -- Add group owner\n")
  685. result = result + (" group_owner_delete -- Remove group owner\n")
  686. result = result + (" group_join -- Add someone to your group\n")
  687. result = result + (" group_kick -- Kick someone from your group\n")
  688. result = result + (" group_list -- List all groups you are a member of\n")
  689. result = result + ("\n")
  690. if (is_admin(user_id)):
  691. result = result + ("Admin operations\n")
  692. result = result + (" admin_promote -- Promote a user to admin status\n")
  693. result = result + (" admin_demote -- Demote a user to normal status\n")
  694. result = result + ("\n")
  695. result = result + ("General operations\n")
  696. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  697. result = result + (" exit -- Kill the current task, while retaining user\n")
  698. return result!
  699. String function cmd_model_add(user_id : String, type : String, name : String):
  700. // Model addition operation, which uses model upload commands of the compiler
  701. String location
  702. String type_id
  703. Element new_model
  704. String new_model_id
  705. type_id = get_entry_id(type)
  706. if (type_id != ""):
  707. // Type exists
  708. if (allow_read(user_id, type_id)):
  709. // And is readable
  710. if (get_entry_id(name) == ""):
  711. // Model doesn't exist yet
  712. Element mm
  713. mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  714. if (element_eq(mm, read_root())):
  715. return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
  716. output("Waiting for model constructors...")
  717. new_model = construct_model_raw(mm)
  718. model_create(new_model, name, user_id, type_id, "Model")
  719. return "Success"!
  720. else:
  721. return "Model exists: " + name!
  722. else:
  723. return "Permission denied to model: " + type!
  724. else:
  725. return "Model not found: " + type!
  726. String function cmd_process_execute(user_id : String, process : String, prefix : String):
  727. // Execute a process model until it reaches termination
  728. String process_id
  729. process_id = get_entry_id(process)
  730. if (process_id != ""):
  731. if (allow_read(user_id, process_id)):
  732. Element pm
  733. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  734. if (element_eq(pm, read_root())):
  735. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  736. enact_PM(pm, prefix, user_id)
  737. return "Success"!
  738. else:
  739. return "Permission denied to model: " + process!
  740. else:
  741. return "Model not found: " + process!
  742. String function cmd_transformation_between(user_id : String, source_name : String, target_name : String):
  743. String source_id
  744. String target_id
  745. Element onSource
  746. Element onTarget
  747. Element result
  748. String transformation
  749. source_id = get_entry_id(source_name)
  750. if (source_id != ""):
  751. target_id = get_entry_id(target_name)
  752. if (target_id != ""):
  753. onSource = allAssociationOrigins(core, source_id, "transformInput")
  754. onTarget = allAssociationOrigins(core, target_id, "transformOutput")
  755. result = set_overlap(onSource, onTarget)
  756. String r
  757. r = "Success: "
  758. while (set_len(result) > 0):
  759. transformation = set_pop(result)
  760. if (allow_read(user_id, transformation)):
  761. r = r + string_join(full_name(transformation), "\n")
  762. return r!
  763. else:
  764. return "Model not found: " + target_name!
  765. else:
  766. return "Model not found: " + source_name!
  767. String function cmd_model_render(user_id : String, model_name : String, mapper_name : String):
  768. String model_ID
  769. String mapper_ID
  770. String rendered_name
  771. String tracability_name
  772. Element inputs
  773. Element output_map
  774. Element rendered_model
  775. Element tracability_model
  776. Element result
  777. Element out_links
  778. String link
  779. model_ID = get_entry_id(model_name)
  780. if (model_ID != ""):
  781. mapper_ID = get_entry_id(mapper_name)
  782. if (allow_read(user_id, model_ID)):
  783. if (mapper_ID != ""):
  784. if (allow_read(user_id, mapper_ID)):
  785. // Everything is fine; start the actual operation
  786. // Find metamodel to render to
  787. rendered_name = ("rendered/" + model_name) + mapper_name
  788. tracability_name = ("tracability/" + model_name) + mapper_name
  789. // Take the abstract syntax model and the previously rendered model
  790. inputs = dict_create()
  791. dict_add(inputs, "abstract", model_name)
  792. dict_add(inputs, "rendered", rendered_name)
  793. // Fetch the output types
  794. output_map = dict_create()
  795. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  796. while(set_len(out_links) > 0):
  797. link = set_pop(out_links)
  798. dict_add(output_map, read_attribute(core, link, "name"), full_name(readAssociationDestination(core, link)))
  799. if (get_entry_id(rendered_name) == ""):
  800. // Instantiate
  801. Element rendered
  802. rendered = get_full_model(get_entry_id(output_map["rendered"]), get_entry_id("formalisms/SimpleClassDiagrams"))
  803. if (element_eq(rendered, read_root())):
  804. return "Rendered metamodel cannot conform to formalisms/SimpleClassDiagrams"!
  805. rendered_model = instantiate_model(rendered)
  806. model_create(rendered_model, rendered_name, user_id, get_entry_id(output_map["rendered"]), "Model")
  807. // Tracability model won't exist either
  808. tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
  809. model_create(tracability_model, tracability_name, user_id, get_entry_id("formalisms/Tracability"), "Model")
  810. else:
  811. // Read out tracability model
  812. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  813. if (element_eq(tracability_model, read_root())):
  814. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  815. // Do the operation itself!
  816. result = execute_operation(mapper_ID, inputs, tracability_model)
  817. // Overwrite the previous rendered model
  818. model_overwrite(result["rendered"], get_entry_id(rendered_name), get_entry_id(output_map["rendered"]))
  819. model_overwrite(result["abstract"], get_entry_id(model_name), get_entry_id(output_map["abstract"]))
  820. // Tracability updated in-place
  821. model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  822. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  823. if (element_eq(tracability_model, read_root())):
  824. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  825. // Also output the resulting model
  826. return "Success: " + JSON_print(get_full_model(get_entry_id(rendered_name), get_entry_id(output_map["rendered"])))!
  827. else:
  828. return "Permission denied to model: " + mapper_name!
  829. else:
  830. return "Model not found: " + mapper_name!
  831. else:
  832. return "Permission denied to model: " + model_name!
  833. else:
  834. return "Model not found: " + model_name!
  835. String function cmd_transformation_execute(user_id : String, transformation_name : String, source_models : Element, target_models : Element):
  836. // Execute a transformation, whatever type it is
  837. // First we detect the type, so we know how to prepare for invocation
  838. String transformation_id
  839. String exact_type
  840. Element sources
  841. Element targets
  842. String source
  843. String target
  844. Element inputs
  845. Element outputs
  846. Element output_map
  847. Element trace_links
  848. String target_model_name
  849. String source_model_name
  850. String source_model_ID
  851. Element result
  852. Element keys
  853. String key
  854. String assoc_name
  855. transformation_id = get_entry_id(transformation_name)
  856. if (transformation_id != ""):
  857. if (allow_read(user_id, transformation_id)):
  858. if (is_nominal_instance(core, transformation_id, "Transformation")):
  859. // Read out source and target links
  860. inputs = dict_create()
  861. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  862. while (set_len(sources) > 0):
  863. source = set_pop(sources)
  864. assoc_name = read_attribute(core, source, "name")
  865. if (dict_in(source_models, assoc_name)):
  866. source_model_name = source_models[assoc_name]
  867. else:
  868. return "Source model not bound: " + assoc_name!
  869. source_model_ID = get_entry_id(source_model_name)
  870. if (source_model_ID != ""):
  871. if (allow_read(user_id, source_model_ID)):
  872. // Check for conformance to the requested metamodel
  873. dict_add(inputs, assoc_name, source_model_name)
  874. continue!
  875. else:
  876. return "Permission denied to model: " + source_model_name!
  877. else:
  878. return "Model not found: " + source_model_name!
  879. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  880. outputs = dict_create()
  881. output_map = dict_create()
  882. while (set_len(targets) > 0):
  883. target = set_pop(targets)
  884. assoc_name = read_attribute(core, target, "name")
  885. if (dict_in(target_models, assoc_name)):
  886. target_model_name = target_models[assoc_name]
  887. else:
  888. return "Target model not bound: " + assoc_name!
  889. if (get_entry_id(target_model_name) == ""):
  890. // Doesn't exist yet, so we can easily create
  891. dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
  892. dict_add(outputs, assoc_name, target_model_name)
  893. else:
  894. // Already exists, so we need to check for write access
  895. if (allow_write(user_id, get_entry_id(target_model_name))):
  896. dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
  897. dict_add(outputs, assoc_name, target_model_name)
  898. else:
  899. return "Permission denied to model: " + target_model_name!
  900. if (read_type(core, transformation_id) == "ActionLanguage"):
  901. output("Success: ready for AL execution")
  902. elif (read_type(core, transformation_id) == "ManualOperation"):
  903. output("Success: ready for MANUAL execution")
  904. else:
  905. output("Success: ready for MT execution")
  906. result = execute_operation(transformation_id, inputs, read_root())
  907. // Now write out the models again
  908. if (element_eq(result, read_root())):
  909. // Something went wrong!
  910. return "Failure"!
  911. else:
  912. keys = dict_keys(result)
  913. while (set_len(keys) > 0):
  914. key = set_pop(keys)
  915. if (get_entry_id(outputs[key]) == ""):
  916. // New model
  917. log("Creating new model " + cast_v2s(outputs[key]))
  918. log(" typed by " + cast_v2s(output_map[key]))
  919. model_create(result[key], outputs[key], user_id, get_entry_id(output_map[key]), "Model")
  920. else:
  921. model_overwrite(result[key], get_entry_id(outputs[key]), get_entry_id(output_map[key]))
  922. return "Success"!
  923. else:
  924. return "Model is not executable: " + transformation_name!
  925. else:
  926. return "Permission denied to model: " + transformation_name!
  927. else:
  928. return "Model not found: " + transformation_name!
  929. String function cmd_verify(user_id : String, model_name : String, metamodel_name : String):
  930. // Check whether a model conforms to its specification (with the selected type mapping)
  931. String model_id
  932. String result
  933. Element inputs
  934. model_id = get_entry_id(model_name)
  935. if (model_id != ""):
  936. if (allow_read(user_id, model_id)):
  937. Element m
  938. m = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  939. if (element_eq(m, read_root())):
  940. return "No conformance relation can be found between these models"!
  941. return string_join("Success: ", conformance_scd(m))!
  942. else:
  943. return "Permission denied to model: " + model_name!
  944. else:
  945. return "Model not found: " + model_name!
  946. String function cmd_model_overwrite(user_id : String, model_name : String, metamodel_name : String):
  947. // Overwrites an existing model without changing any metadata
  948. String model_id
  949. String type_id
  950. Element new_model
  951. model_id = get_entry_id(model_name)
  952. if (model_id != ""):
  953. if (allow_write(user_id, model_id)):
  954. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  955. if (allow_read(user_id, type_id)):
  956. Element mm
  957. mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  958. if (element_eq(mm, read_root())):
  959. return "Metamodel does not conform to formalisms/SimpleClassDiagrams: " + metamodel_name!
  960. output("Waiting for model constructors...")
  961. new_model = construct_model_raw(mm)
  962. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  963. return "Success"!
  964. else:
  965. return string_join("Permission denied to model: ", full_name(type_id))!
  966. else:
  967. return "Permission denied to model: " + model_name!
  968. else:
  969. return "Model not found: " + model_name!
  970. String function cmd_model_modify(user_id : String, model_name : String, metamodel_name : String):
  971. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  972. String model_id
  973. String type_id
  974. model_id = get_entry_id(model_name)
  975. if (model_id != ""):
  976. if (allow_read(user_id, model_id)):
  977. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  978. if (allow_read(user_id, type_id)):
  979. Element new_model
  980. new_model = get_full_model(model_id, get_entry_id(metamodel_name))
  981. if (element_eq(new_model, read_root())):
  982. return "No conformance relation can be found between these models"!
  983. output("Success")
  984. modify(new_model, allow_write(user_id, model_id))
  985. if (allow_write(user_id, model_id)):
  986. // Overwrite the modified model
  987. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  988. return "Success"!
  989. else:
  990. return string_join("Permission denied to model: ", full_name(type_id))!
  991. else:
  992. return "Permission denied to model: " + model_name!
  993. else:
  994. return "Model not found: " + model_name!
  995. String function cmd_model_delete(user_id : String, model_name : String):
  996. String model_id
  997. model_id = get_entry_id(model_name)
  998. if (model_id != ""):
  999. if (allow_write(user_id, model_id)):
  1000. model_delete_element(core, model_id)
  1001. return "Success"!
  1002. else:
  1003. return "Permission denied to model: " + model_name!
  1004. else:
  1005. return "Model not found: " + model_name!
  1006. String function cmd_model_list(location : String):
  1007. // List all models
  1008. if (get_entry_id(location) != ""):
  1009. Element models
  1010. String result
  1011. String m
  1012. result = "Success: "
  1013. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1014. while (set_len(models) > 0):
  1015. m = set_pop(models)
  1016. if (is_nominal_instance(core, m, "Folder")):
  1017. result = result + string_join(read_attribute(core, m, "name"), "/\n")
  1018. else:
  1019. result = result + string_join(read_attribute(core, m, "name"), "\n")
  1020. return result!
  1021. else:
  1022. return "Location not found: " + location!
  1023. String function cmd_model_list_full(location : String):
  1024. // List all models with full info
  1025. if (get_entry_id(location) != ""):
  1026. Element models
  1027. String m
  1028. String permissions
  1029. String owner
  1030. String group
  1031. String name
  1032. String type
  1033. String result
  1034. result = "Success: "
  1035. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1036. while (set_len(models) > 0):
  1037. m = set_pop(models)
  1038. permissions = read_attribute(core, m, "permissions")
  1039. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1040. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1041. if (is_nominal_instance(core, m, "Folder")):
  1042. name = string_join(read_attribute(core, m, "name"), "/")
  1043. else:
  1044. name = read_attribute(core, m, "name")
  1045. result = result + (((((((permissions + " ") + owner) + " ") + group) + " ") + name) + "\n")
  1046. return result!
  1047. else:
  1048. return "Location not found: " + location!
  1049. String function cmd_transformation_add_MANUAL(user_id : String, source_models : Element, target_models : Element, operation_name : String):
  1050. return transformation_add(user_id, source_models, target_models, operation_name, "manual")!
  1051. String function cmd_transformation_add_AL(user_id : String, source_models : Element, target_models : Element, operation_name : String):
  1052. return transformation_add(user_id, source_models, target_models, operation_name, "actionlanguage")!
  1053. String function transformation_add(user_id : String, source_models : Element, target_models : Element, operation_name : String, operation_type : String):
  1054. // Add a manual transformation model
  1055. String model_id
  1056. Element models
  1057. Element source
  1058. Element target
  1059. String name
  1060. Element all_formalisms
  1061. Element formalism_map
  1062. Element merged_formalism
  1063. String merged_formalism_id
  1064. String source_formalism_id
  1065. String tracability_link
  1066. Element fused
  1067. Element keys
  1068. String key
  1069. Element mm
  1070. source = dict_create()
  1071. target = dict_create()
  1072. all_formalisms = set_create()
  1073. formalism_map = set_create()
  1074. fused = set_create()
  1075. keys = dict_keys(source_models)
  1076. while (set_len(keys) > 0):
  1077. key = set_pop(keys)
  1078. name = source_models[key]
  1079. model_id = get_entry_id(name)
  1080. if (model_id != ""):
  1081. if (allow_read(user_id, model_id)):
  1082. if (bool_not(dict_in(source, key))):
  1083. dict_add(source, key, model_id)
  1084. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1085. if (element_eq(mm, read_root())):
  1086. return "Transformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1087. if (bool_not(set_in(fused, key))):
  1088. set_add_node(formalism_map, create_tuple(key, mm))
  1089. set_add(fused, key)
  1090. if (bool_not(set_in(all_formalisms, model_id))):
  1091. set_add(all_formalisms, model_id)
  1092. else:
  1093. return "Name already selected for source: " + key!
  1094. else:
  1095. return "Permission denied to model: " + name!
  1096. else:
  1097. return "Model not found: " + name!
  1098. keys = dict_keys(target_models)
  1099. while (set_len(keys) > 0):
  1100. key = set_pop(keys)
  1101. name = target_models[key]
  1102. model_id = get_entry_id(name)
  1103. if (model_id != ""):
  1104. if (allow_read(user_id, model_id)):
  1105. if (bool_not(dict_in(target, key))):
  1106. dict_add(target, key, model_id)
  1107. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1108. if (element_eq(mm, read_root())):
  1109. return "Transformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1110. if (bool_not(set_in(fused, key))):
  1111. set_add_node(formalism_map, create_tuple(key, mm))
  1112. set_add(fused, key)
  1113. if (bool_not(set_in(all_formalisms, model_id))):
  1114. set_add(all_formalisms, model_id)
  1115. else:
  1116. return "Name already selected for target: " + key!
  1117. else:
  1118. return "Permission denied to model: " + name!
  1119. else:
  1120. return "Model not found: " + name!
  1121. if (get_entry_id(operation_name) == ""):
  1122. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1123. // New location is available, so write
  1124. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1125. merged_formalism = model_fuse(formalism_map)
  1126. modify(merged_formalism, True)
  1127. if (operation_type == "manual"):
  1128. // Finished with all information, now create the model itself!
  1129. Element m
  1130. m = get_full_model(get_entry_id("formalisms/ManualOperation"), get_entry_id("formalisms/SimpleClassDiagrams"))
  1131. if (element_eq(m, read_root())):
  1132. log("Error when opening ManualOperation: no conformance relation found")
  1133. return "Error when opening ManualOperation: no conformance relation found"!
  1134. model_create(instantiate_model(m), operation_name, user_id, get_entry_id("formalisms/ManualOperation"), "ManualOperation")
  1135. model_id = get_entry_id(operation_name)
  1136. elif (operation_type == "actionlanguage"):
  1137. // Finished with all information, now create the model itself!
  1138. output("Waiting for code constructors...")
  1139. add_code_model(get_full_model(get_entry_id("formalisms/ActionLanguage"), get_entry_id("formalisms/SimpleClassDiagrams")), "AL/" + operation_name, construct_function())
  1140. model_create(import_node("AL/" + operation_name), operation_name, user_id, get_entry_id("formalisms/ActionLanguage"), "ActionLanguage")
  1141. model_id = get_entry_id(operation_name)
  1142. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1143. model_create(merged_formalism, "merged/" + operation_name, user_id, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1144. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1145. // Add tracability links at this level
  1146. while (set_len(all_formalisms) > 0):
  1147. source_formalism_id = set_pop(all_formalisms)
  1148. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1149. instantiate_attribute(core, tracability_link, "type", "merged")
  1150. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1151. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1152. // Extend metadata with info on source and target
  1153. String link
  1154. String dst
  1155. keys = dict_keys(source)
  1156. while (set_len(keys) > 0):
  1157. key = set_pop(keys)
  1158. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1159. instantiate_attribute(core, link, "name", key)
  1160. keys = dict_keys(target)
  1161. while (set_len(keys) > 0):
  1162. key = set_pop(keys)
  1163. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1164. instantiate_attribute(core, link, "name", key)
  1165. return "Success"!
  1166. else:
  1167. return "Model exists: " + operation_name!
  1168. String function cmd_transformation_add_MT(user_id : String, source_models : Element, target_models : Element, operation_name : String):
  1169. // Add a model transformation model
  1170. // Just a usual model instantiation, but need to add the source and target links based on user info
  1171. String ramified_metamodel_id
  1172. Element ramified_metamodel
  1173. String model_id
  1174. Element models
  1175. Element links
  1176. String link_id
  1177. Element supported
  1178. Element source
  1179. Element target
  1180. String name
  1181. String new_model_id
  1182. String merged_link_id
  1183. Element links_merged
  1184. String merged_formalism
  1185. Element keys
  1186. String key
  1187. Element mm
  1188. Element to_ramify
  1189. String source_formalism_id
  1190. String merged_formalism_id
  1191. String tracability_link
  1192. source = dict_create()
  1193. target = dict_create()
  1194. to_ramify = set_create()
  1195. keys = dict_keys(source_models)
  1196. while (set_len(keys) > 0):
  1197. key = set_pop(keys)
  1198. name = source_models[key]
  1199. model_id = get_entry_id(name)
  1200. if (model_id != ""):
  1201. if (allow_read(user_id, name)):
  1202. // Check whether or not it is formalisms/SimpleClassDiagrams
  1203. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1204. if (bool_not(dict_in(source, key))):
  1205. dict_add(source, key, model_id)
  1206. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1207. if (element_eq(mm, read_root())):
  1208. return "ModelTransformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1209. set_add_node(to_ramify, create_tuple(key, mm))
  1210. else:
  1211. return "Name was already assigned a metamodel: " + key!
  1212. else:
  1213. return "Model not supported for RAMification: " + name!
  1214. else:
  1215. return "Permission denied: " + name!
  1216. else:
  1217. return "Model not found: " + name!
  1218. keys = dict_keys(target_models)
  1219. while (set_len(keys) > 0):
  1220. key = set_pop(keys)
  1221. name = target_models[key]
  1222. model_id = get_entry_id(name)
  1223. if (model_id != ""):
  1224. if (allow_read(user_id, name)):
  1225. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1226. if (bool_not(dict_in(target, key))):
  1227. if (dict_in(source, key)):
  1228. if (value_eq(model_id, source[key])):
  1229. dict_add(target, key, model_id)
  1230. // Don't add to to_ramify, as it is already in there!
  1231. else:
  1232. return "Name in output cannot have different type than input: " + key!
  1233. else:
  1234. dict_add(target, key, model_id)
  1235. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1236. if (element_eq(mm, read_root())):
  1237. return "ModelTransformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1238. set_add_node(to_ramify, create_tuple(key, mm))
  1239. else:
  1240. return "Name was already assigned a metamodel: " + key!
  1241. else:
  1242. return "Model not supported for RAMification: " + name!
  1243. else:
  1244. return "Permission denied: " + name!
  1245. else:
  1246. return "Model not found: " + name!
  1247. merged_formalism = model_fuse(to_ramify)
  1248. modify(merged_formalism, True)
  1249. ramified_metamodel = ramify(merged_formalism)
  1250. model_create(ramified_metamodel, "RAMified/" + operation_name, user_id, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1251. ramified_metamodel_id = get_entry_id("RAMified/" + operation_name)
  1252. // Now use the RAMified model to create the instance
  1253. if (get_entry_id(operation_name) == ""):
  1254. String new_model
  1255. // Finished with all information, now create the model itself!
  1256. output("Waiting for model constructors...")
  1257. new_model = construct_model_raw(get_full_model(ramified_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams")))
  1258. model_create(new_model, operation_name, user_id, ramified_metamodel_id, "ModelTransformation")
  1259. model_id = get_entry_id(operation_name)
  1260. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1261. // New location is available, so write
  1262. model_create(merged_formalism, "merged/" + operation_name, user_id, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1263. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1264. // Add tracability links at this level
  1265. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1266. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1267. // Add tracability links at this level
  1268. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1269. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1270. // Extend metadata with info on source and target
  1271. String link
  1272. String dst
  1273. keys = dict_keys(source)
  1274. while (set_len(keys) > 0):
  1275. key = set_pop(keys)
  1276. dst = source[key]
  1277. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1278. instantiate_attribute(core, link, "name", key)
  1279. keys = dict_keys(target)
  1280. while (set_len(keys) > 0):
  1281. key = set_pop(keys)
  1282. dst = target[key]
  1283. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1284. instantiate_attribute(core, link, "name", key)
  1285. return "Success"!
  1286. else:
  1287. return "Model exists: " + operation_name!
  1288. String function cmd_permission_modify(user_id : String, model_name : String, permissions : String):
  1289. Integer permission
  1290. String model_id
  1291. model_id = get_entry_id(model_name)
  1292. if (model_id != ""):
  1293. if (get_relation_to_model(user_id, model_id) == 0):
  1294. Boolean fail
  1295. Integer i
  1296. i = 0
  1297. if (string_len(permissions) != 3):
  1298. fail = True
  1299. while (i < 3):
  1300. permission = cast_s2i(string_get(permissions, i))
  1301. if (bool_or(permission < 0, permission > 2)):
  1302. fail = True
  1303. break!
  1304. i = i + 1
  1305. if (bool_not(fail)):
  1306. unset_attribute(core, model_id, "permissions")
  1307. instantiate_attribute(core, model_id, "permissions", permissions)
  1308. return "Success"!
  1309. else:
  1310. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1311. else:
  1312. return "Permission denied to model: " + model_name!
  1313. else:
  1314. return "Model not found: " + model_name!
  1315. String function cmd_permission_owner(user_id : String, model_name : String, new_user_name : String):
  1316. String model_id
  1317. String new_user_id
  1318. model_id = get_entry_id(model_name)
  1319. if (model_id != ""):
  1320. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1321. new_user_id = get_user_id(new_user_name)
  1322. if (new_user_id != ""):
  1323. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1324. instantiate_link(core, "owner", "", model_id, new_user_id)
  1325. return "Success"!
  1326. else:
  1327. return "No such user: " + new_user_name!
  1328. else:
  1329. return "Permission denied to model: " + model_name!
  1330. else:
  1331. return "Model not found: " + model_name!
  1332. String function cmd_permission_group(user_id : String, model_name : String, new_group_name : String):
  1333. String model_id
  1334. String group_id
  1335. model_id = get_entry_id(model_name)
  1336. if (model_id != ""):
  1337. if (bool_or(get_relation_to_model(user_id, model_id) == 0, is_admin(user_id))):
  1338. group_id = get_group_id(new_group_name)
  1339. if (group_id != ""):
  1340. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1341. instantiate_link(core, "group", "", model_id, group_id)
  1342. return "Success"!
  1343. else:
  1344. return "No such group: " + new_group_name!
  1345. else:
  1346. return "Permission denied to model: " + model_name!
  1347. else:
  1348. return "Model not found: " + model_name!
  1349. String function cmd_group_create(user_id : String, group_name : String):
  1350. // Create a new group and become its owner
  1351. String group_id
  1352. String name
  1353. group_id = get_group_id(group_name)
  1354. if (group_id == ""):
  1355. group_id = instantiate_node(core, "Group", "")
  1356. instantiate_attribute(core, group_id, "name", group_name)
  1357. instantiate_link(core, "belongsTo", "", user_id, group_id)
  1358. instantiate_link(core, "owner", "", group_id, user_id)
  1359. return "Success"!
  1360. else:
  1361. return "Group exists: " + group_name!
  1362. String function cmd_group_delete(user_id : String, group_name : String):
  1363. // Delete an existing group
  1364. String group_id
  1365. group_id = get_group_id(group_name)
  1366. if (group_id != ""):
  1367. if (allow_group_modify(user_id, group_id)):
  1368. model_delete_element(core, group_id)
  1369. return "Success"!
  1370. else:
  1371. return "Permission denied to group: " + group_name!
  1372. else:
  1373. return "Group not found: " + group_name!
  1374. String function cmd_group_owner_add(user_id : String, group_name : String, other_user_name : String):
  1375. // Add an owner to your group
  1376. String group_id
  1377. String other_user_id
  1378. group_id = get_group_id(group_name)
  1379. if (group_id != ""):
  1380. if (allow_group_modify(user_id, group_id)):
  1381. other_user_id = get_user_id(other_user_name)
  1382. if (other_user_id != ""):
  1383. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1384. instantiate_link(core, "owner", "", group_id, other_user_id)
  1385. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1386. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1387. return "Success"!
  1388. else:
  1389. return "User is already the owner!"!
  1390. else:
  1391. return "User not found: " + other_user_name!
  1392. else:
  1393. return "Permission denied to group: " + group_name!
  1394. else:
  1395. return "Group not found: " + group_name!
  1396. String function cmd_group_owner_delete(user_id : String, group_name : String, other_user_name : String):
  1397. // Remove an owner from your group
  1398. String group_id
  1399. String other_user_id
  1400. group_id = get_group_id(group_name)
  1401. if (group_id != ""):
  1402. if (allow_group_modify(user_id, group_id)):
  1403. other_user_id = get_user_id(other_user_name)
  1404. if (other_user_id != ""):
  1405. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1406. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1407. Element overlap
  1408. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1409. model_delete_element(core, set_pop(overlap))
  1410. return "Success"!
  1411. else:
  1412. return "User is not an owner of the group!"!
  1413. else:
  1414. return "User is not a member of the group!"!
  1415. else:
  1416. return "User not found: " + other_user_name!
  1417. else:
  1418. return "Permission denied to group: " + group_name!
  1419. else:
  1420. return "Group not found: " + group_name!
  1421. String function cmd_group_join(user_id : String, group_name : String, other_user_name : String):
  1422. // Add someone to your group
  1423. String group_id
  1424. String other_user_id
  1425. group_id = get_group_id(group_name)
  1426. if (group_id != ""):
  1427. if (allow_group_modify(user_id, group_id)):
  1428. other_user_id = get_user_id(other_user_name)
  1429. if (other_user_id != ""):
  1430. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1431. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1432. return "Success"!
  1433. else:
  1434. return "User is already a member of the group!"!
  1435. else:
  1436. return "User not found: " + other_user_name!
  1437. else:
  1438. return "Permission denied to group: " + group_name!
  1439. else:
  1440. return "Group not found: " + group_name!
  1441. String function cmd_group_kick(user_id : String, group_name : String, other_user_name : String):
  1442. // Remove someone from your group
  1443. String group_id
  1444. String other_user_id
  1445. group_id = get_group_id(group_name)
  1446. if (group_id != ""):
  1447. if (allow_group_modify(user_id, group_id)):
  1448. other_user_id = get_user_id(other_user_name)
  1449. if (other_user_id != ""):
  1450. Element overlap
  1451. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1452. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1453. model_delete_element(core,set_pop(overlap))
  1454. // Check if user was an owner as well
  1455. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1456. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1457. model_delete_element(core, set_pop(overlap))
  1458. return "Success"!
  1459. else:
  1460. return "User is not a member of the group!"!
  1461. else:
  1462. return "User not found: " + other_user_name!
  1463. else:
  1464. return "Permission denied to group: " + group_name!
  1465. else:
  1466. return "Group not found: " + group_name!
  1467. String function cmd_group_list(user_id : String):
  1468. // List all groups you are a member of (and whether you are admin or not!)
  1469. Element groups
  1470. String group_id
  1471. String admin
  1472. String result
  1473. result = ""
  1474. groups = allAssociationDestinations(core, user_id, "belongsTo")
  1475. while (set_len(groups) > 0):
  1476. group_id = set_pop(groups)
  1477. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  1478. admin = " A "
  1479. else:
  1480. admin = " "
  1481. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1482. return result!
  1483. String function cmd_admin_promote(user_id : String, other_user_name : String):
  1484. // Promote a user to admin status
  1485. if (is_admin(user_id)):
  1486. String other_user_id
  1487. other_user_id = get_user_id(other_user_name)
  1488. if (other_user_id != ""):
  1489. unset_attribute(core, other_user_id, "admin")
  1490. instantiate_attribute(core, other_user_id, "admin", True)
  1491. return "Success"!
  1492. else:
  1493. return "User not found: " + other_user_name!
  1494. else:
  1495. return "Permission denied to administrate: " + other_user_name!
  1496. String function cmd_admin_demote(user_id : String, other_user_name : String):
  1497. // Demote a user to normal status
  1498. if (is_admin(user_id)):
  1499. String other_user_id
  1500. other_user_id = get_user_id(other_user_name)
  1501. if (other_user_id != ""):
  1502. unset_attribute(core, other_user_id, "admin")
  1503. instantiate_attribute(core, other_user_id, "admin", False)
  1504. return "Success"!
  1505. else:
  1506. return "User not found: " + other_user_name!
  1507. else:
  1508. return "Permission denied to administrate: " + other_user_name!
  1509. String function cmd_service_register(user_id : String, service_name : String):
  1510. // Active a service for this specific user
  1511. if (get_service_id(service_name) == ""):
  1512. String service
  1513. service = instantiate_node(core, "Service", "")
  1514. instantiate_attribute(core, service, "name", service_name)
  1515. instantiate_attribute(core, service, "port", get_taskname())
  1516. output("Success: " + get_taskname())
  1517. // Wait until we can stop the service
  1518. log("Waiting for service_stop")
  1519. while (cast_v2s(input()) != "\"service_stop\""):
  1520. output("Service is running on this task: stop it by sending 'service_stop'")
  1521. log("Finished")
  1522. model_delete_element(core, service)
  1523. // Service terminated
  1524. return "Success"!
  1525. else:
  1526. return "Service already exists: " + service_name!
  1527. String function cmd_user_password(user_id : String, user_name : String, new_password : String):
  1528. if (bool_or(user_id == get_user_id(user_name), is_admin(user_id))):
  1529. if (get_user_id(user_name) != ""):
  1530. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1531. return "Success"!
  1532. else:
  1533. return "No such user: " + user_name!
  1534. else:
  1535. return "Permission denied to user: " + user_name!
  1536. String function cmd_transformation_signature(user_id : String, transformation_name : String):
  1537. String model_id
  1538. model_id = get_entry_id(transformation_name)
  1539. if (model_id != ""):
  1540. if (is_nominal_instance(core, model_id, "Transformation")):
  1541. if (allow_read(user_id, transformation_name)):
  1542. String result
  1543. String elem
  1544. Element inputs
  1545. Element outputs
  1546. result = "Success: "
  1547. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1548. while (set_len(inputs) > 0):
  1549. elem = set_pop(inputs)
  1550. result = string_join(string_join(string_join(string_join("I ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1551. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1552. while (set_len(outputs) > 0):
  1553. elem = set_pop(outputs)
  1554. result = string_join(string_join(string_join(string_join("O ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1555. return result!
  1556. else:
  1557. return "Permission denied to operation: " + transformation_name!
  1558. else:
  1559. return "Model is not an operation: " + transformation_name!
  1560. else:
  1561. return "No such operation: " + transformation_name!
  1562. String function cmd_element_list_nice(user_id : String, model_name : String, metamodel_name : String):
  1563. if (get_entry_id(model_name) != ""):
  1564. if (allow_read(user_id, get_entry_id(model_name))):
  1565. Element mm
  1566. mm = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  1567. if (element_eq(mm, read_root())):
  1568. return "No conformance relation between these models"!
  1569. return "Success: " + JSON_print(mm)!
  1570. else:
  1571. return "Permission denied to model: " + model_name!
  1572. else:
  1573. return "No such model: " + model_name!
  1574. Void function user_function_skip_init(user_id : String):
  1575. String cmd
  1576. String result
  1577. caches = dict_create()
  1578. dict_add_fast(caches, "models", dict_create())
  1579. dict_add_fast(caches, "users", dict_create())
  1580. dict_add_fast(caches, "full_name", dict_create())
  1581. // Find root element
  1582. Element elems
  1583. String elem
  1584. elems = allInstances(core, "Folder")
  1585. while (set_len(elems) > 0):
  1586. elem = set_pop(elems)
  1587. if (value_eq(read_attribute(core, elem, "name"), "")):
  1588. if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
  1589. dict_add_fast(caches, "root", elem)
  1590. break!
  1591. output("Welcome to the Model Management Interface v2.0!")
  1592. output("Use the 'help' command for a list of possible commands")
  1593. while (True):
  1594. cmd = input()
  1595. if (cmd == "help"):
  1596. output(cmd_help(user_id))
  1597. elif (cmd == "model_add"):
  1598. output(cmd_model_add(user_id, single_input("Model type?"), single_input("Model name?")))
  1599. elif (cmd == "process_execute"):
  1600. output(cmd_process_execute(user_id, single_input("Process to execute?"), single_input("Model prefix to use?")))
  1601. elif (cmd == "transformation_between"):
  1602. output(cmd_transformation_between(user_id, single_input("Source type?"), single_input("Target type?")))
  1603. elif (cmd == "model_render"):
  1604. output(cmd_model_render(user_id, single_input("Model name?"), single_input("Mapper name?")))
  1605. elif (cmd == "transformation_execute"):
  1606. output(cmd_transformation_execute(user_id, single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
  1607. elif (cmd == "verify"):
  1608. result = cmd_verify(user_id, single_input("Model name?"), single_input("Metamodel name?"))
  1609. if (result != ""):
  1610. output(result)
  1611. elif (cmd == "model_overwrite"):
  1612. output(cmd_model_overwrite(user_id, single_input("Model name?"), single_input("Metamodel name?")))
  1613. elif (cmd == "model_modify"):
  1614. output(cmd_model_modify(user_id, single_input("Model name?"), single_input("Metamodel name?")))
  1615. elif (cmd == "model_delete"):
  1616. output(cmd_model_delete(user_id, single_input("Model name?")))
  1617. elif (cmd == "model_list"):
  1618. output(cmd_model_list(single_input("Location?")))
  1619. elif (cmd == "model_list_full"):
  1620. output(cmd_model_list_full(single_input("Location?")))
  1621. elif (cmd == "transformation_add_MANUAL"):
  1622. output(cmd_transformation_add_MANUAL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
  1623. elif (cmd == "transformation_add_AL"):
  1624. output(cmd_transformation_add_AL(user_id, dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
  1625. elif (cmd == "transformation_add_MT"):
  1626. output(cmd_transformation_add_MT(user_id, dict_input("Source model names?"), dict_input("Target models?"), single_input("Operation name?")))
  1627. elif (cmd == "permission_modify"):
  1628. output(cmd_permission_modify(user_id, single_input("Model name?"), single_input("Permissions?")))
  1629. elif (cmd == "permission_owner"):
  1630. output(cmd_permission_owner(user_id, single_input("Model name?"), single_input("New owning user?")))
  1631. elif (cmd == "permission_group"):
  1632. output(cmd_permission_group(user_id, single_input("Model name?"), single_input("New owning group?")))
  1633. elif (cmd == "group_create"):
  1634. output(cmd_group_create(user_id, single_input("New group name?")))
  1635. elif (cmd == "group_delete"):
  1636. output(cmd_group_delete(user_id, single_input("Group name?")))
  1637. elif (cmd == "group_owner_add"):
  1638. output(cmd_group_owner_add(user_id, single_input("Group name?"), single_input("User name?")))
  1639. elif (cmd == "group_owner_delete"):
  1640. output(cmd_group_owner_delete(user_id, single_input("Group name?"), single_input("User name?")))
  1641. elif (cmd == "group_join"):
  1642. output(cmd_group_join(user_id, single_input("Group name?"), single_input("User name?")))
  1643. elif (cmd == "group_kick"):
  1644. output(cmd_group_kick(user_id, single_input("Group name?"), single_input("User name?")))
  1645. elif (cmd == "group_list"):
  1646. output(cmd_group_list(user_id))
  1647. elif (cmd == "admin_promote"):
  1648. output(cmd_admin_promote(user_id, single_input("User name?")))
  1649. elif (cmd == "admin_demote"):
  1650. output(cmd_admin_demote(user_id, single_input("User name?")))
  1651. elif (cmd == "service_register"):
  1652. output(cmd_service_register(user_id, single_input("Service name?")))
  1653. elif (cmd == "user_password"):
  1654. output(cmd_user_password(user_id, single_input("User name?"), single_input("New password?")))
  1655. elif (cmd == "transformation_read_signature"):
  1656. output(cmd_transformation_signature(user_id, single_input("Transformation name?")))
  1657. elif (cmd == "element_list_nice"):
  1658. output(cmd_element_list_nice(user_id, single_input("Model name?"), single_input("Metamodel name?")))
  1659. elif (cmd == "verbose"):
  1660. set_verbose(True)
  1661. elif (cmd == "quiet"):
  1662. set_verbose(False)
  1663. elif (cmd == "self-destruct"):
  1664. // Delete user from Core Formalism
  1665. model_delete_element(core, user_id)
  1666. return !
  1667. elif (cmd == "exit"):
  1668. // Exit by actually removing the user and decoupling it from all of its models
  1669. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1670. // as the current user will have been deleted
  1671. return !
  1672. elif (cmd == "add_conformance"):
  1673. // TODO
  1674. cmd = "FAIL"
  1675. elif (cmd == "remove_conformance"):
  1676. // TODO
  1677. cmd = "FAIL"
  1678. elif (cmd == "user_name"):
  1679. // TODO
  1680. cmd = "FAIL"
  1681. elif (cmd == "service_poll"):
  1682. // TODO
  1683. cmd = "FAIL"
  1684. else:
  1685. output("Unknown command: " + cmd)
  1686. // We never get here!
  1687. return !