core_algorithm.alc 90 KB

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