core_algorithm.alc 69 KB

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