core_algorithm.alc 71 KB

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