From bd364725a0e86c30009e123bdf3ad786926c3ea8 Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 09:58:44 +0100 Subject: [PATCH 1/9] implemented dropdown menu for all bt creation related actions in behaviors tab --- app/components/behaviors/action-bar.js | 4 +++ app/components/ui/menu-bar/create-button.js | 23 ++++++++++++++++ .../components/ui/buttons/create-button.css | 27 +++++++++++++++++++ .../components/ui/buttons/input-button.css | 8 +++++- .../components/behaviors/action-bar.hbs | 27 ++++++++++++++----- .../components/ui/menu-bar/create-button.hbs | 4 +++ 6 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 app/components/ui/menu-bar/create-button.js create mode 100644 app/styles/components/ui/buttons/create-button.css create mode 100644 app/templates/components/ui/menu-bar/create-button.hbs diff --git a/app/components/behaviors/action-bar.js b/app/components/behaviors/action-bar.js index a473d639..b10f81a4 100644 --- a/app/components/behaviors/action-bar.js +++ b/app/components/behaviors/action-bar.js @@ -83,6 +83,10 @@ export default Component.extend({ this.get('dataBus').cloneBT(); }, + generateAgent() { + console.log("Generate Agent!"); + }, + sort() { graphOperations.updateGraph(globals.cy); }, diff --git a/app/components/ui/menu-bar/create-button.js b/app/components/ui/menu-bar/create-button.js new file mode 100644 index 00000000..aa6c7d33 --- /dev/null +++ b/app/components/ui/menu-bar/create-button.js @@ -0,0 +1,23 @@ +/* + * Created on Tue Nov 10 2020 + * + * The MIT License (MIT) + * Copyright (c) 2020 André Antakli, Alex Grethen (German Research Center for Artificial Intelligence, DFKI). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import Component from "@ember/component"; + +export default class UiMenuBarImportButtonComponent extends Component {} diff --git a/app/styles/components/ui/buttons/create-button.css b/app/styles/components/ui/buttons/create-button.css new file mode 100644 index 00000000..40adee3f --- /dev/null +++ b/app/styles/components/ui/buttons/create-button.css @@ -0,0 +1,27 @@ +:global(.create-bt-agt)::before { + font-size: 15px; + color: #000; +} + +:global(.createBT .create-bt-agt), +:global(.cloneBT .create-bt-agt), +:global(.generateAgent .create-bt-agt) { + padding: 10px 16px; + width: 120pt !important; + color: #000 !important; + text-align: left; + background-color: #f0f0f0 !important; +} + +:global(.createBT i), +:global(.cloneBT i), +:global(.generateAgent i) { + padding-left: 10px; + color: #000; +} + +:global(.createBT .create-bt-agt):hover, +:global(.cloneBT .create-bt-agt):hover, +:global(.generateAgent .create-bt-agt):hover { + background-color: rgba(0, 0, 0, 0.0) !important; +} diff --git a/app/styles/components/ui/buttons/input-button.css b/app/styles/components/ui/buttons/input-button.css index 40b1a462..07f3b7ee 100644 --- a/app/styles/components/ui/buttons/input-button.css +++ b/app/styles/components/ui/buttons/input-button.css @@ -8,6 +8,12 @@ color: #000; } +:global(.loadFile input), +:global(.loadRepo input), +:global(.loadBT input) { + background-color: #f0f0f0 !important; +} + :global(.loadFile i), :global(.loadBT i), :global(.loadRepo i) { @@ -18,7 +24,7 @@ :global(.loadPropertyFile) { background: #E9E9E9; border-radius: 5px; - heigt: 50px; + height: 50px; margin: 5px 1px 5px 0; position: relative; } diff --git a/app/templates/components/behaviors/action-bar.hbs b/app/templates/components/behaviors/action-bar.hbs index a0178ee3..ba377fff 100644 --- a/app/templates/components/behaviors/action-bar.hbs +++ b/app/templates/components/behaviors/action-bar.hbs @@ -33,15 +33,30 @@ fileName=this.btFileName icon="download" }} -{{/ui/menu-bar/dropdown}} - {{ui/menu-bar/button + {{/ui/menu-bar/dropdown}} + {{#ui/menu-bar/dropdown label="Create" - onClick=(action "createBehavior") + class="action-bar" + }} + {{ui/menu-bar/create-button + label="Create BT" + class="createBT" + compAction=(action "createBehavior") + icon="plus square" + }} + {{ui/menu-bar/create-button + label="Clone BT" + class="cloneBT" + compAction=(action "cloneBehavior") + icon="clone" }} -{{ui/menu-bar/button - label="Clone" - onClick=(action "cloneBehavior") + {{ui/menu-bar/create-button + label="Generate Agent" + class="generateAgent" + compAction=(action "generateAgent") + icon="user plus" }} + {{/ui/menu-bar/dropdown}} {{ui/menu-bar/button label="Sort" onClick=(action "sort") diff --git a/app/templates/components/ui/menu-bar/create-button.hbs b/app/templates/components/ui/menu-bar/create-button.hbs new file mode 100644 index 00000000..84d32ccd --- /dev/null +++ b/app/templates/components/ui/menu-bar/create-button.hbs @@ -0,0 +1,4 @@ + + From 0aeebb6e0d33a5cc2b97ca2cfc50d5fa832a38c0 Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 09:59:10 +0100 Subject: [PATCH 2/9] fixed issue with exporting or downloading AJAN-packages --- app/helpers/home/triplestore-listing.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/helpers/home/triplestore-listing.js b/app/helpers/home/triplestore-listing.js index 80e262d1..8f255312 100644 --- a/app/helpers/home/triplestore-listing.js +++ b/app/helpers/home/triplestore-listing.js @@ -368,12 +368,7 @@ function loadRdfGraphZipData(zipFile, triplestore, ajax) { function loadAgentRdfGraphData(ajax, triplestore, onend) { let repo = (triplestore || "http://localhost:8090/rdf4j/repositories") + globals.agentsRepository; - agtActions.getAgentFromServer(ajax, repo).then(addRDFDataToGraph) - .then(agtActions.getBehaviorsFromServer(ajax, repo).then(addRDFDataToGraph) - .then(agtActions.getEventsFromServer(ajax, repo).then(addRDFDataToGraph) - .then(agtActions.getEndpointsFromServer(ajax, repo).then(addRDFDataToGraph) - .then(agtActions.getGoalsFromServer(ajax, repo).then(addRDFDataToGraph) - .then(onend))))); + agtActions.getFromServer(ajax, repo).then(addRDFDataToGraph).then(onend); } function addRDFDataToGraph(rdfData) { @@ -415,7 +410,7 @@ function showImportDialog(ajax, triplestore, zipFile, matches) { rdfGraph.addAll(zipFile.agents.import.quads); agtActions.saveAgentGraph(ajax, triplestore + globals.agentsRepository, null); } else if (zipFile.agents.import) { - sendFile(triplestore + globals.agentsRepository, zipFile.agents.import.raw); + sendFile(ajax, triplestore + globals.agentsRepository, zipFile.agents.import.raw); } console.log(matches.behaviors); if (matches.behaviors.length > 0) { @@ -425,7 +420,7 @@ function showImportDialog(ajax, triplestore, zipFile, matches) { rdfGraph.addAll(zipFile.behaviors.import.quads); btActions.saveGraph(ajax, triplestore + globals.behaviorsRepository, null); } else if (zipFile.behaviors.import) { - sendFile(triplestore + globals.behaviorsRepository, zipFile.behaviors.import.raw); + sendFile(ajax, triplestore + globals.behaviorsRepository, zipFile.behaviors.import.raw); } $("#save-confirmation").trigger("showToast"); }, zipFile.info.input); From 7bb2233e26e22739e6151da95563d958f57ff006 Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 09:59:41 +0100 Subject: [PATCH 3/9] introduced icons for agent-components --- app/styles/components/agents/agent-graph.css | 6 +-- .../components/agents/agent-behavior.hbs | 5 +- .../components/agents/agent-endpoint.hbs | 5 +- .../components/agents/agent-event.hbs | 5 +- .../components/agents/agent-goal.hbs | 5 +- .../components/agents/agent-graph.hbs | 47 +++++++++++++------ .../components/agents/agent-item.hbs | 5 +- 7 files changed, 56 insertions(+), 22 deletions(-) diff --git a/app/styles/components/agents/agent-graph.css b/app/styles/components/agents/agent-graph.css index dc48756f..e81a9481 100644 --- a/app/styles/components/agents/agent-graph.css +++ b/app/styles/components/agents/agent-graph.css @@ -47,7 +47,7 @@ width: 25px; height: 25px; float: left; - margin-right: 10px; + padding-right: 25px; } .agent-list-item button { @@ -79,7 +79,7 @@ background: #d1d1e0; } -:global(#agents-overview .item.active i) { +:global(#agents-overview .item.active .agent-list-item-marker) { width: 0; height: 0; margin-right: -10px; @@ -89,7 +89,7 @@ border-color: transparent transparent transparent #ececff; } -:global(#agents-overview .item.active:hover i) { +:global(#agents-overview .item.active:hover .agent-list-item-marker) { border-color: transparent transparent transparent #d1d1e0; } diff --git a/app/templates/components/agents/agent-behavior.hbs b/app/templates/components/agents/agent-behavior.hbs index 1344efe5..ec70b0e5 100644 --- a/app/templates/components/agents/agent-behavior.hbs +++ b/app/templates/components/agents/agent-behavior.hbs @@ -1,7 +1,10 @@
-
{{activeBehavior.label}}
+
+ + {{activeBehavior.label}} +
diff --git a/app/templates/components/agents/agent-endpoint.hbs b/app/templates/components/agents/agent-endpoint.hbs index 49880d2f..c2f4f226 100644 --- a/app/templates/components/agents/agent-endpoint.hbs +++ b/app/templates/components/agents/agent-endpoint.hbs @@ -1,5 +1,8 @@
-
{{activeEndpoint.label}}
+
+ + {{activeEndpoint.label}} +
diff --git a/app/templates/components/agents/agent-event.hbs b/app/templates/components/agents/agent-event.hbs index 1842a842..af4c329c 100644 --- a/app/templates/components/agents/agent-event.hbs +++ b/app/templates/components/agents/agent-event.hbs @@ -1,6 +1,9 @@
-
{{activeEvent.label}}
+
+ + {{activeEvent.label}} +
diff --git a/app/templates/components/agents/agent-goal.hbs b/app/templates/components/agents/agent-goal.hbs index efa3c72c..35bcd011 100644 --- a/app/templates/components/agents/agent-goal.hbs +++ b/app/templates/components/agents/agent-goal.hbs @@ -1,6 +1,9 @@
-
{{activeGoal.label}}
+
+ + {{activeGoal.label}} +
diff --git a/app/templates/components/agents/agent-graph.hbs b/app/templates/components/agents/agent-graph.hbs index 35da9e2a..e0a4ee79 100644 --- a/app/templates/components/agents/agent-graph.hbs +++ b/app/templates/components/agents/agent-graph.hbs @@ -18,10 +18,11 @@ {{#each this.availableAgents as |value|}}
  • - +
  • {{/each}} @@ -41,8 +42,11 @@ {{#each this.availableBehaviors.initial as |value|}} {{#if value.uri}}
  • - - + +
  • {{/if}} {{/each}} @@ -62,8 +66,11 @@ {{#each this.availableBehaviors.final as |value|}} {{#if value.uri}}
  • - - + +
  • {{/if}} {{/each}} @@ -82,8 +89,11 @@
      {{#each this.availableBehaviors.regular as |value|}}
    • - - + +
    • {{/each}}
    @@ -102,8 +112,11 @@
      {{#each this.availableEndpoints as |value|}}
    • - - + +
    • {{/each}}
    @@ -120,8 +133,11 @@
      {{#each this.availableEvents as |value|}}
    • - - + +
    • {{/each}}
    @@ -139,8 +155,11 @@ {{#each this.availableGoals as |value|}}
  • - - + +
  • {{/each}} diff --git a/app/templates/components/agents/agent-item.hbs b/app/templates/components/agents/agent-item.hbs index ff55f4fc..1f61096b 100644 --- a/app/templates/components/agents/agent-item.hbs +++ b/app/templates/components/agents/agent-item.hbs @@ -1,5 +1,8 @@
    -
    {{activeAgent.label}}
    +
    + + {{activeAgent.label}} +
    From fefc2ff7a1a806a2f4b052228fe3a7bf23b7173d Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 13:36:47 +0100 Subject: [PATCH 4/9] refactored agentsRDFProducer --- app/helpers/RDFServices/agentsRDFProducer.js | 53 +------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/app/helpers/RDFServices/agentsRDFProducer.js b/app/helpers/RDFServices/agentsRDFProducer.js index 9dcb9cb2..375743c1 100644 --- a/app/helpers/RDFServices/agentsRDFProducer.js +++ b/app/helpers/RDFServices/agentsRDFProducer.js @@ -18,9 +18,8 @@ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import {ACTN, SPIN, RDF, RDFS, HTTP, XSD, AGENTS} from "ajan-editor/helpers/RDFServices/vocabulary"; +import {RDF, RDFS, AGENTS} from "ajan-editor/helpers/RDFServices/vocabulary"; import rdfGraph from "ajan-editor/helpers/RDFServices/RDF-graph"; -import rdfManager from "ajan-editor/helpers/RDFServices/RDF-manager"; import rdfFact from "ajan-editor/helpers/RDFServices/RDF-factory"; export default { @@ -31,54 +30,4 @@ export default { function createAgent(definition) { rdfGraph.add(rdfFact.quad(definition.uri, RDF.type,AGENTS.AgentTemplate )); rdfGraph.add(rdfFact.quadLiteral(definition.uri, RDFS.label, definition.label)); - -} - -function createVariables(rootUri, definition) { - let root = rdfFact.blankNode(); - rdfGraph.add(rdfFact.quad(rootUri, ACTN.variables, root)); - definition.forEach(function(item, index, arr) { - let first = rdfFact.blankNode(); - rdfGraph.add(rdfFact.quad(root, RDF.first, first)); - createVariable(first, item); - item.pointerUri = first.value; - if (index < arr.length) { - let rest = rdfFact.blankNode(); - rdfGraph.add(rdfFact.quad(root, RDF.rest, rest)); - root = rest; - } else { - rdfGraph.add(rdfFact.quad(root, RDF.rest, RDF.nil)); - } - }); -} - -function appendVariable(root, variable, list) { - var last_element = list[list.length-1]; - variable.pointerUri = rdfManager.listInsert(root,last_element.pointerUri); -} - -function createVariable(root, definition) { - rdfGraph.add(rdfFact.quad(root, RDF.type, ACTN.ActionVariable)); - rdfGraph.add(rdfFact.quadLiteral(root, SPIN.varName, definition.var, XSD.string)); -} - -function createBinding(type, rootUri, definition) { - if (type === "abort") { - rdfGraph.add(rdfFact.quad(rootUri, ACTN.abortBinding, definition.uri)); - } else { - rdfGraph.add(rdfFact.quad(rootUri, ACTN.runBinding, definition.uri)); - } - rdfGraph.add(rdfFact.quad(definition.uri, RDF.type, ACTN.Binding)); - rdfGraph.add(rdfFact.quad(definition.uri, RDF.type, HTTP.Request)); - rdfGraph.add(rdfFact.quadLiteral(definition.uri, HTTP.version, definition.version, XSD.string)); - rdfGraph.add(rdfFact.quadLiteral(definition.uri, HTTP.mthd, definition.mthd, XSD.anyURI)); - rdfGraph.add(rdfFact.quadLiteral(definition.uri, HTTP.uri, definition.requestUri, XSD.anyURI)); - if(definition.payload != null) - createPayload(definition.uri, definition.payload); -} - -function createPayload(rootUri, definition) { - rdfGraph.add(rdfFact.quad(rootUri, HTTP.body, definition.uri)); - rdfGraph.add(rdfFact.quad(definition.uri, RDF.type, ACTN.Payload)); - rdfGraph.add(rdfFact.quadLiteral(definition.uri, ACTN.sparql, definition.sparql, XSD.string)); } From 81f4069af0c70f2e7a663bcd0cbc6b4b84151b56 Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 13:37:52 +0100 Subject: [PATCH 5/9] generating Agent Definition regarding nodes of selected BT --- app/components/behaviors/behavior-graph.js | 121 +++++++++++++++++- .../properties/parameter/event-field.js | 4 +- app/helpers/RDFServices/vocabulary.js | 1 + 3 files changed, 121 insertions(+), 5 deletions(-) diff --git a/app/components/behaviors/behavior-graph.js b/app/components/behaviors/behavior-graph.js index 626ff808..b6f0fccb 100644 --- a/app/components/behaviors/behavior-graph.js +++ b/app/components/behaviors/behavior-graph.js @@ -19,6 +19,7 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import actions from "ajan-editor/helpers/behaviors/actions"; +import actionsAgnt from "ajan-editor/helpers/agents/actions"; import {cleanDOM} from "ajan-editor/helpers/graph/cy-cleanup"; import Ember from "ember"; import events from "ajan-editor/helpers/behaviors/event-bindings"; @@ -26,6 +27,8 @@ import globals from "ajan-editor/helpers/global-parameters"; import nodeDefs from "ajan-editor/helpers/RDFServices/node-definitions/common"; import rdfGraph from "ajan-editor/helpers/RDFServices/RDF-graph"; import rdfManager from "ajan-editor/helpers/RDFServices/RDF-manager"; +import utility from "ajan-editor/helpers/RDFServices/utility"; +import { AGENTS, XSD, RDF, RDFS } from "ajan-editor/helpers/RDFServices/vocabulary"; import Split from "npm:split.js"; let $ = Ember.$; @@ -43,6 +46,9 @@ export default Ember.Component.extend({ cytoscapeService: Ember.inject.service("behaviors/cytoscape"), dataBus: Ember.inject.service(), availableBTs: undefined, + availableEvents: undefined, + availableBehaviors: undefined, + availableEndpoints: undefined, cyRef: undefined, init() { @@ -127,10 +133,11 @@ function initializeSplitPanes() { } function loadNodeDefinitionsThenGraph() { - nodeDefs(ajax, cy).then(loadRdfGraphData); + nodeDefs(ajax, cy).then(loadBTRdfGraphData); + loadAgentsRdfGraphData(); } -function loadRdfGraphData() { +function loadBTRdfGraphData() { let repo = (localStorage.currentStore || "http://localhost:8090/rdf4j/repositories") + "/" + @@ -150,10 +157,118 @@ function rdfDataHasLoaded(rdfData) { } function setAvailableBTs() { - let behaviorTrees = actions.getBehaviorTrees(); + let behaviorTrees = actions.getBehaviorTrees(); that.set("availableBTs", behaviorTrees); } +function loadAgentsRdfGraphData() { + let repo = (localStorage.currentStore || "http://localhost:8090/rdf4j/repositories") + + globals.agentsRepository; + actionsAgnt.getFromServer(ajax, repo) + .then(setAvailableBehaviors) + .then(setAvailableEvents) + .then(setAvailableEndpoints); +} + +function setAvailableBehaviors() { + let behaviorsLists = actionsAgnt.getBehaviors(); + that.set("availableBehaviors", behaviorsLists.regular); + console.log(that.get("availableBehaviors")); +} + +function setAvailableEvents() { + let eventLists = actionsAgnt.getEvents(); + that.set("availableEvents", eventLists); + console.log(that.get("availableEvents")); +} + +function setAvailableEndpoints() { + let endpointList = actionsAgnt.getEndpoints(); + that.set("availableEndpoints", endpointList); + console.log(that.get("availableEndpoints")); + generateAgent(); +} + +function generateAgent() { + let agentRepo = (localStorage.currentStore || "http://localhost:8090/rdf4j/repositories/") + "agents"; + let selected = localStorage.getItem("bt-selected"); + let selectedBt = that.get("availableBTs").filter(item => item.uri == selected); + console.log(selectedBt); + let includedEvents = new Array(); + selectedBt[0].nodes.forEach(function (item) { + addEventURI(item, includedEvents); + }); + let includedBehaviors = getBehaviors(includedEvents); + let includedEndpoints = getEndpoints(includedEvents); + let agentDef = getNewAgentDefinition(agentRepo, selectedBt[0], includedEvents, includedBehaviors, includedEndpoints); + console.log(agentDef); + actionsAgnt.createAgent(agentDef); +} + +function addEventURI(item, events) { + let addableUri = ""; + if (item.category == "GoalProducer") { + addableUri = getGoalURI(item.uri); + } else if (item.category == "EventProducer" || item.category == "HandleMappingEvent" || item.category == "HandleEvent" || item.category == "HandleQueueEvent") { + addableUri = getEventURI(item.uri); + } + if (addableUri != "" && !events.includes(addableUri)) { + events.push(addableUri); + } +} + +function getGoalURI(uri) { + return rdfGraph.getObject(uri, AGENTS.goal).value; +} + +function getEventURI(uri) { + return rdfGraph.getObject(uri, AGENTS.event).value; +} + +function getBehaviors(includedEvents) { + let addableBehaviors = {}; + addableBehaviors = new Array(); + let behaviors = that.get("availableBehaviors"); + includedEvents.forEach(function (event) { + behaviors.forEach(function (bhvs) { + bhvs.triggers.forEach(function (item) { + if (item.uri == event && !addableBehaviors.includes(event)) { + addableBehaviors.push(bhvs.uri); + } + }) + }); + }); + return addableBehaviors; +} + +function getEndpoints(includedEvents) { + let addableEndpoints = new Array(); + let endpoints = that.get("availableEndpoints"); + includedEvents.forEach(function (event) { + endpoints.forEach(function (endpt) { + endpt.events.forEach(function (item) { + if (item.uri == event && !addableEndpoints.includes(event)) { + addableEndpoints.push(endpt.uri); + } + }) + }); + }); + return addableEndpoints; +} + +function getNewAgentDefinition(repo, bt, includedEvents, includedBehaviors, includedEndpoints) { + let agent = {}; + console.log(bt); + agent.uri = repo + "#AG_" + bt.name + "_" + utility.generateUUID(); + agent.type = AGENTS.AgentTemplate; + agent.label = bt.name + " AgentTemplate"; + agent.name = "AgentTemplate"; + agent.behaviors = includedBehaviors; + agent.events = includedEvents; + agent.endpoints = includedEndpoints; + return agent; +} + function createBT(bt) { that.get("availableBTs").push(bt); that.dataBus.save(); diff --git a/app/components/behaviors/properties/parameter/event-field.js b/app/components/behaviors/properties/parameter/event-field.js index 87981542..604c1164 100644 --- a/app/components/behaviors/properties/parameter/event-field.js +++ b/app/components/behaviors/properties/parameter/event-field.js @@ -39,7 +39,7 @@ export default Component.extend({ this._super(...arguments); that = this; initializeGlobals(this); - loadActionsRdfGraphData(); + loadAgentsRdfGraphData(); }, selectedChanged: observer("selected", function () { @@ -66,7 +66,7 @@ function initializeAjax() { globals.ajax = ajax; } -function loadActionsRdfGraphData() { +function loadAgentsRdfGraphData() { let repo = (localStorage.currentStore || "http://localhost:8090/rdf4j/repositories") + globals.agentsRepository; actionsAgnt.getFromServer(ajax, repo).then(setAvailableEvents); diff --git a/app/helpers/RDFServices/vocabulary.js b/app/helpers/RDFServices/vocabulary.js index c83740bd..26884dc4 100644 --- a/app/helpers/RDFServices/vocabulary.js +++ b/app/helpers/RDFServices/vocabulary.js @@ -212,6 +212,7 @@ let AGENTS = { Goal: "http://www.ajan.de/ajan-ns#Goal", Variable: "http://www.ajan.de/ajan-ns#Variable", event: "http://www.ajan.de/ajan-ns#event", + goal: "http://www.ajan.de/ajan-ns#goal", agentKnowledge: "http://www.ajan.de/ajan-ns#agentKnowledge", endpoint: "http://www.ajan.de/ajan-ns#endpoint", initialBehavior: "http://www.ajan.de/ajan-ns#initialBehavior", From 03c8b43aafc38b3ac53d645b7d985bb3c17e657f Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 16:54:37 +0100 Subject: [PATCH 6/9] reading out event, behaviors and endpoints, generate new agent template as well as generic endpoint, event and behavior and saving it into agents repo --- app/components/behaviors/action-bar.js | 1 + app/components/behaviors/behavior-graph.js | 72 +++++++++++++++++--- app/helpers/RDFServices/agentsRDFProducer.js | 67 +++++++++++++++++- app/helpers/RDFServices/queries.js | 8 +++ app/helpers/agents/actions.js | 1 + app/helpers/behaviors/actions.js | 3 +- app/helpers/behaviors/actions/ajax.js | 56 +++++++++++++++ app/services/data-bus.js | 4 ++ 8 files changed, 199 insertions(+), 13 deletions(-) diff --git a/app/components/behaviors/action-bar.js b/app/components/behaviors/action-bar.js index b10f81a4..3fb1d432 100644 --- a/app/components/behaviors/action-bar.js +++ b/app/components/behaviors/action-bar.js @@ -85,6 +85,7 @@ export default Component.extend({ generateAgent() { console.log("Generate Agent!"); + this.get('dataBus').generateAgent(); }, sort() { diff --git a/app/components/behaviors/behavior-graph.js b/app/components/behaviors/behavior-graph.js index b6f0fccb..faecacf9 100644 --- a/app/components/behaviors/behavior-graph.js +++ b/app/components/behaviors/behavior-graph.js @@ -57,6 +57,9 @@ export default Ember.Component.extend({ this.get('dataBus').on('addBT', function (bt) { createBT(bt); }); + this.get('dataBus').on('generateAgent', function (bt) { + generateAgent(); + }); this.get('dataBus').on('cloneBT', function () { cloneBT(); }); @@ -173,20 +176,16 @@ function loadAgentsRdfGraphData() { function setAvailableBehaviors() { let behaviorsLists = actionsAgnt.getBehaviors(); that.set("availableBehaviors", behaviorsLists.regular); - console.log(that.get("availableBehaviors")); } function setAvailableEvents() { let eventLists = actionsAgnt.getEvents(); that.set("availableEvents", eventLists); - console.log(that.get("availableEvents")); } function setAvailableEndpoints() { let endpointList = actionsAgnt.getEndpoints(); that.set("availableEndpoints", endpointList); - console.log(that.get("availableEndpoints")); - generateAgent(); } function generateAgent() { @@ -200,9 +199,25 @@ function generateAgent() { }); let includedBehaviors = getBehaviors(includedEvents); let includedEndpoints = getEndpoints(includedEvents); - let agentDef = getNewAgentDefinition(agentRepo, selectedBt[0], includedEvents, includedBehaviors, includedEndpoints); + let agentDef = {}; + agentDef.event = getNewEventDefinition(agentRepo, selectedBt[0], includedEvents); + agentDef.behavior = getNewBehaviorDefinition(agentRepo, selectedBt[0], agentDef.event, includedBehaviors); + agentDef.endpoint = getNewEndpointDefinition(agentRepo, selectedBt[0], agentDef.event, includedEndpoints); + agentDef.template = getNewAgentDefinition(agentRepo, selectedBt[0], includedEvents, includedBehaviors, includedEndpoints); console.log(agentDef); - actionsAgnt.createAgent(agentDef); + let stringRDF = actionsAgnt.createAgentRDFString(agentDef); + saveGeneratedAgent(agentRepo, stringRDF); +} + +function saveGeneratedAgent(repo, stringRDF) { + try { + actions.saveAgentGraph(globals.ajax, repo, stringRDF); + } catch (e) { + $("#error-message").trigger("showToast", [ + "Error while saving generated Agent" + ]); + throw e; + } } function addEventURI(item, events) { @@ -256,12 +271,49 @@ function getEndpoints(includedEvents) { return addableEndpoints; } -function getNewAgentDefinition(repo, bt, includedEvents, includedBehaviors, includedEndpoints) { +function getNewEventDefinition(repo, btDef, includedEvents) { + let event = {}; + event.type = AGENTS.Event; + event.uri = repo + "#EV_" + utility.generateUUID(); + event.label = btDef.name + " Event"; + event.name = "Event"; + includedEvents.push(event.uri); + return event; +} + +function getNewEndpointDefinition(repo, btDef, event, includedEndpoints) { + let endpoint = {}; + endpoint.uri = repo + "#EP_" + utility.generateUUID(); + endpoint.type = AGENTS.Endpoint; + endpoint.name = "Endpoint"; + endpoint.label = btDef.name + " Endpoint"; + endpoint.capability = "execute"; + endpoint.events = [event]; + includedEndpoints.push(endpoint.uri); + return endpoint; +} + +function getNewBehaviorDefinition(repo, btDef, event, includedBehaviors) { + let behavior = {}; + behavior.uri = repo + "#BE_" + utility.generateUUID(); + behavior.type = AGENTS.Behavior; + behavior.label = btDef.name + " Behavior"; + behavior.behavior = "Behavior"; + behavior.triggers = [event]; + let bt = {}; + bt.label = btDef.name; + bt.uri = btDef.uri; + behavior.bt = bt; + behavior.clearEKB = false; + includedBehaviors.push(behavior.uri); + return behavior; +} + +function getNewAgentDefinition(repo, btDef, includedEvents, includedBehaviors, includedEndpoints) { let agent = {}; - console.log(bt); - agent.uri = repo + "#AG_" + bt.name + "_" + utility.generateUUID(); + agent.uri = repo + "#AG_" + btDef.name + "_" + utility.generateUUID(); agent.type = AGENTS.AgentTemplate; - agent.label = bt.name + " AgentTemplate"; + agent.label = btDef.name + " AgentTemplate"; agent.name = "AgentTemplate"; agent.behaviors = includedBehaviors; agent.events = includedEvents; diff --git a/app/helpers/RDFServices/agentsRDFProducer.js b/app/helpers/RDFServices/agentsRDFProducer.js index 375743c1..113caa13 100644 --- a/app/helpers/RDFServices/agentsRDFProducer.js +++ b/app/helpers/RDFServices/agentsRDFProducer.js @@ -21,13 +21,76 @@ import {RDF, RDFS, AGENTS} from "ajan-editor/helpers/RDFServices/vocabulary"; import rdfGraph from "ajan-editor/helpers/RDFServices/RDF-graph"; import rdfFact from "ajan-editor/helpers/RDFServices/RDF-factory"; +import rdf from "npm:rdf-ext"; export default { - createAgent: createAgent + createAgent: createAgent, + createAgentRDFString: createAgentRDFString }; // editing ajan function createAgent(definition) { - rdfGraph.add(rdfFact.quad(definition.uri, RDF.type,AGENTS.AgentTemplate )); + rdfGraph.add(rdfFact.quad(definition.uri, RDF.type, AGENTS.AgentTemplate)); rdfGraph.add(rdfFact.quadLiteral(definition.uri, RDFS.label, definition.label)); } + +function createAgentRDFString(definition) { + let quads = rdf.dataset(); + createTeamplateQuads(quads, definition.template); + createEventQuads(quads, definition.event); + createBehaviorQuads(quads, definition.behavior); + createEndpointQuads(quads, definition.endpoint); + return rdfGraph.toString(quads); +} + +function createTeamplateQuads(quads, template) { + quads.add(rdfFact.quad(template.uri, RDF.type, AGENTS.AgentTemplate)); + quads.add(rdfFact.quadLiteral(template.uri, RDFS.label, template.label)); + if (template.events.length > 0) { + addEvents(quads, template) + } + if (template.behaviors.length > 0) { + addBehaviors(quads, template) + } + if (template.endpoints.length > 0) { + addEndpoints(quads, template) + } +} + +function createEventQuads(quads, event) { + quads.add(rdfFact.quad(event.uri, RDF.type, AGENTS.Event)); + quads.add(rdfFact.quadLiteral(event.uri, RDFS.label, event.label)); +} + +function createBehaviorQuads(quads, behavior) { + quads.add(rdfFact.quad(behavior.uri, RDF.type, AGENTS.Behavior)); + quads.add(rdfFact.quadLiteral(behavior.uri, RDFS.label, behavior.label)); + quads.add(rdfFact.quad(behavior.uri, AGENTS.bt, behavior.bt.uri)); + quads.add(rdfFact.quad(behavior.uri, AGENTS.trigger, behavior.triggers[0].uri)); + quads.add(rdfFact.quadLiteral(behavior.uri, AGENTS.clearEKB, behavior.clearEKB)); +} + +function createEndpointQuads(quads, endpoint) { + quads.add(rdfFact.quad(endpoint.uri, RDF.type, AGENTS.Endpoint)); + quads.add(rdfFact.quadLiteral(endpoint.uri, RDFS.label, endpoint.label)); + quads.add(rdfFact.quad(endpoint.uri, AGENTS.event, endpoint.events[0].uri)); + quads.add(rdfFact.quadLiteral(endpoint.uri, AGENTS.capability, endpoint.capability)); +} + +function addEvents(quads, definition) { + definition.events.forEach(function (event) { + quads.add(rdfFact.quad(definition.uri, AGENTS.event, event)); + }) +} + +function addBehaviors(quads, definition) { + definition.behaviors.forEach(function (behavior) { + quads.add(rdfFact.quad(definition.uri, AGENTS.behavior, behavior)); + }) +} + +function addEndpoints(quads, definition) { + definition.endpoints.forEach(function (endpoint) { + quads.add(rdfFact.quad(definition.uri, AGENTS.endpoint, endpoint)); + }) +} diff --git a/app/helpers/RDFServices/queries.js b/app/helpers/RDFServices/queries.js index 0e1b7123..271099d7 100644 --- a/app/helpers/RDFServices/queries.js +++ b/app/helpers/RDFServices/queries.js @@ -30,6 +30,14 @@ WHERE {?s ?p ?o}`, ); }, + insert: function (str) { + return ( + `INSERT DATA{` + + str + + `}` + ); + }, + update: function(str) { return ( `DELETE { ?s ?p ?o } WHERE { ?s ?p ?o }; diff --git a/app/helpers/agents/actions.js b/app/helpers/agents/actions.js index b230a385..8b4888d3 100644 --- a/app/helpers/agents/actions.js +++ b/app/helpers/agents/actions.js @@ -52,6 +52,7 @@ export default { createDefaultGoal: createDefaultGoal, createAgent: agentProducer.createAgent, + createAgentRDFString: agentProducer.createAgentRDFString, createInitialBehavior: behaviorProducer.createInitialBehavior, createFinalBehavior: behaviorProducer.createFinalBehavior, createBehavior: behaviorProducer.createBehavior, diff --git a/app/helpers/behaviors/actions.js b/app/helpers/behaviors/actions.js index f63d68b5..6bc8ceb5 100644 --- a/app/helpers/behaviors/actions.js +++ b/app/helpers/behaviors/actions.js @@ -32,7 +32,8 @@ export default { // AJAX related Actions getFromServer: ajaxActions.getFromServer, getBehaviorTrees: ajaxActions.getBehaviorTrees, - saveGraph, + saveGraph, + saveAgentGraph: ajaxActions.saveAgentGraph, restoreSaved: ajaxActions.restoreSaved, // Graph Actions diff --git a/app/helpers/behaviors/actions/ajax.js b/app/helpers/behaviors/actions/ajax.js index 9cdc4c69..86d5f32f 100644 --- a/app/helpers/behaviors/actions/ajax.js +++ b/app/helpers/behaviors/actions/ajax.js @@ -48,6 +48,11 @@ export default { .then((token) => updateBehaviorsRepo(ajax, tripleStoreRepository, token)); }, + saveAgentGraph: function (ajax, tripleStoreRepository, agentDefinition) { + Promise.resolve(tokenizer.resolveToken(ajax, localStorage.currentStore)) + .then((token) => saveAgentDefinition(ajax, tripleStoreRepository, token, agentDefinition)); + }, + restoreSaved: function (ajax, tripleStoreRepository) { Promise.resolve(tokenizer.resolveToken(ajax, localStorage.currentStore)) .then((token) => restoreSavedRepo(ajax, tripleStoreRepository, token)); @@ -171,6 +176,57 @@ function updateBehaviorsRepo(ajax, tripleStoreRepository, token) { rdfGraph.unsavedChanges = false; } +function saveAgentDefinition(ajax, tripleStoreRepository, token, agentDefinition) { + console.log("Saving to agent definition in store: ", tripleStoreRepository); + + let postDestination = tripleStoreRepository + "/statements"; + let rdfString = rdfGraph.toString(); + console.log(rdfString); + let query = SparqlQueries.insert(agentDefinition); + let dataString = $.param({ update: query }); + + ajax + .post(postDestination, { + contentType: "application/x-www-form-urlencoded; charset=utf-8", + headers: getHeaders(token), + // SPARQL query + data: dataString + }) + .then(response => { + $("#save-confirmation").trigger("showToast"); + }) + .catch(function (error) { + if (isServerError(error)) { + ajax + .post(postDestination, { + contentType: "application/x-www-form-urlencoded; charset=utf-8", + headers: getHeaders(token), + // SPARQL query + data: restoredItem + }) + .then( + function (data) { + // On accept + console.log("Request success", data); + }, + function (jqXHR) { + // On reject + console.log("Request failed", jqXHR); + } + ); + + return; + } else { + tokenizer.removeToken(localStorage.currentStore); + Promise.resolve(tokenizer.resolveToken(ajax, localStorage.currentStore)) + .then((token) => saveAgentDefinition(ajax, tripleStoreRepository, token, agentDefinition)); + } + throw error; + }); + + rdfGraph.unsavedChanges = false; +} + function restoreSavedRepo(ajax, tripleStoreRepository, token) { let postDestination = tripleStoreRepository + "/statements"; let restoreID = "rdf_graph_saved_T-" + t; diff --git a/app/services/data-bus.js b/app/services/data-bus.js index 472dae93..9e790b8a 100644 --- a/app/services/data-bus.js +++ b/app/services/data-bus.js @@ -25,6 +25,10 @@ export default Ember.Service.extend(Ember.Evented, { this.trigger('createBT'); }, + generateAgent() { + this.trigger('generateAgent'); + }, + cloneBT(label) { this.trigger('cloneBT'); }, From 2a9475cf85079bb3f55cf01a1cea04f80298f266 Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 17:52:37 +0100 Subject: [PATCH 7/9] refactoring and adding only behaviors to the agent template if selected behavior is not included --- app/components/behaviors/behavior-graph.js | 64 +++----------------- app/helpers/RDFServices/agentsRDFProducer.js | 10 ++- app/helpers/agents/actions.js | 57 ++++++++++++++++- 3 files changed, 70 insertions(+), 61 deletions(-) diff --git a/app/components/behaviors/behavior-graph.js b/app/components/behaviors/behavior-graph.js index faecacf9..b220f73e 100644 --- a/app/components/behaviors/behavior-graph.js +++ b/app/components/behaviors/behavior-graph.js @@ -197,13 +197,13 @@ function generateAgent() { selectedBt[0].nodes.forEach(function (item) { addEventURI(item, includedEvents); }); - let includedBehaviors = getBehaviors(includedEvents); + let includedBehaviors = getBehaviors(selectedBt[0], includedEvents); let includedEndpoints = getEndpoints(includedEvents); let agentDef = {}; - agentDef.event = getNewEventDefinition(agentRepo, selectedBt[0], includedEvents); - agentDef.behavior = getNewBehaviorDefinition(agentRepo, selectedBt[0], agentDef.event, includedBehaviors); - agentDef.endpoint = getNewEndpointDefinition(agentRepo, selectedBt[0], agentDef.event, includedEndpoints); - agentDef.template = getNewAgentDefinition(agentRepo, selectedBt[0], includedEvents, includedBehaviors, includedEndpoints); + agentDef.event = actionsAgnt.createDefinedEvent(agentRepo, selectedBt[0], includedEvents); + agentDef.behavior = actionsAgnt.createDefinedBehavior(agentRepo, selectedBt[0], includedEvents, includedBehaviors); + agentDef.endpoint = actionsAgnt.createDefinedEndpoint(agentRepo, selectedBt[0], agentDef.event, includedEndpoints); + agentDef.template = actionsAgnt.createDefinedAgent(agentRepo, selectedBt[0], includedEvents, includedBehaviors, includedEndpoints); console.log(agentDef); let stringRDF = actionsAgnt.createAgentRDFString(agentDef); saveGeneratedAgent(agentRepo, stringRDF); @@ -240,14 +240,14 @@ function getEventURI(uri) { return rdfGraph.getObject(uri, AGENTS.event).value; } -function getBehaviors(includedEvents) { +function getBehaviors(bt, includedEvents) { let addableBehaviors = {}; addableBehaviors = new Array(); let behaviors = that.get("availableBehaviors"); includedEvents.forEach(function (event) { behaviors.forEach(function (bhvs) { bhvs.triggers.forEach(function (item) { - if (item.uri == event && !addableBehaviors.includes(event)) { + if (item.uri == event && !addableBehaviors.includes(event) && bhvs.bt.uri != bt.uri) { addableBehaviors.push(bhvs.uri); } }) @@ -271,56 +271,6 @@ function getEndpoints(includedEvents) { return addableEndpoints; } -function getNewEventDefinition(repo, btDef, includedEvents) { - let event = {}; - event.type = AGENTS.Event; - event.uri = repo + "#EV_" + utility.generateUUID(); - event.label = btDef.name + " Event"; - event.name = "Event"; - includedEvents.push(event.uri); - return event; -} - -function getNewEndpointDefinition(repo, btDef, event, includedEndpoints) { - let endpoint = {}; - endpoint.uri = repo + "#EP_" + utility.generateUUID(); - endpoint.type = AGENTS.Endpoint; - endpoint.name = "Endpoint"; - endpoint.label = btDef.name + " Endpoint"; - endpoint.capability = "execute"; - endpoint.events = [event]; - includedEndpoints.push(endpoint.uri); - return endpoint; -} - -function getNewBehaviorDefinition(repo, btDef, event, includedBehaviors) { - let behavior = {}; - behavior.uri = repo + "#BE_" + utility.generateUUID(); - behavior.type = AGENTS.Behavior; - behavior.label = btDef.name + " Behavior"; - behavior.behavior = "Behavior"; - behavior.triggers = [event]; - let bt = {}; - bt.label = btDef.name; - bt.uri = btDef.uri; - behavior.bt = bt; - behavior.clearEKB = false; - includedBehaviors.push(behavior.uri); - return behavior; -} - -function getNewAgentDefinition(repo, btDef, includedEvents, includedBehaviors, includedEndpoints) { - let agent = {}; - agent.uri = repo + "#AG_" + btDef.name + "_" + utility.generateUUID(); - agent.type = AGENTS.AgentTemplate; - agent.label = btDef.name + " AgentTemplate"; - agent.name = "AgentTemplate"; - agent.behaviors = includedBehaviors; - agent.events = includedEvents; - agent.endpoints = includedEndpoints; - return agent; -} - function createBT(bt) { that.get("availableBTs").push(bt); that.dataBus.save(); diff --git a/app/helpers/RDFServices/agentsRDFProducer.js b/app/helpers/RDFServices/agentsRDFProducer.js index 113caa13..e4323af4 100644 --- a/app/helpers/RDFServices/agentsRDFProducer.js +++ b/app/helpers/RDFServices/agentsRDFProducer.js @@ -18,7 +18,7 @@ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import {RDF, RDFS, AGENTS} from "ajan-editor/helpers/RDFServices/vocabulary"; +import { RDF, RDFS, AGENTS, XSD} from "ajan-editor/helpers/RDFServices/vocabulary"; import rdfGraph from "ajan-editor/helpers/RDFServices/RDF-graph"; import rdfFact from "ajan-editor/helpers/RDFServices/RDF-factory"; import rdf from "npm:rdf-ext"; @@ -66,8 +66,12 @@ function createBehaviorQuads(quads, behavior) { quads.add(rdfFact.quad(behavior.uri, RDF.type, AGENTS.Behavior)); quads.add(rdfFact.quadLiteral(behavior.uri, RDFS.label, behavior.label)); quads.add(rdfFact.quad(behavior.uri, AGENTS.bt, behavior.bt.uri)); - quads.add(rdfFact.quad(behavior.uri, AGENTS.trigger, behavior.triggers[0].uri)); - quads.add(rdfFact.quadLiteral(behavior.uri, AGENTS.clearEKB, behavior.clearEKB)); + console.log(behavior.triggers); + behavior.triggers.forEach(function (event) { + quads.add(rdfFact.quad(behavior.uri, AGENTS.trigger, event)); + }) + console.log(behavior.clearEKB); + quads.add(rdfFact.quadLiteral(behavior.uri, AGENTS.clearEKB, behavior.clearEKB, XSD.boolean)); } function createEndpointQuads(quads, endpoint) { diff --git a/app/helpers/agents/actions.js b/app/helpers/agents/actions.js index 8b4888d3..c4e50439 100644 --- a/app/helpers/agents/actions.js +++ b/app/helpers/agents/actions.js @@ -43,12 +43,16 @@ export default { deleteGoal: deleteGoal, deleteVariable: deleteVariable, - createDefaultAgent: createDefaultAgent, + createDefaultAgent: createDefaultAgent, + createDefinedAgent: createDefinedAgent, createDefaultInitialBehavior: createDefaultInitialBehavior, createDefaultFinalBehavior: createDefaultFinalBehavior, createDefaultBehavior: createDefaultBehavior, + createDefinedBehavior: createDefinedBehavior, createDefaultEvent: createDefaultEvent, + createDefinedEvent: createDefinedEvent, createDefaultEndpoint: createDefaultEndpoint, + createDefinedEndpoint: createDefinedEndpoint, createDefaultGoal: createDefaultGoal, createAgent: agentProducer.createAgent, @@ -136,6 +140,18 @@ function createDefaultAgent(repo) { return agent; } +function createDefinedAgent(repo, btDef, includedEvents, includedBehaviors, includedEndpoints) { + let agent = {}; + agent.uri = repo + "#AG_" + btDef.name + "_" + utility.generateUUID(); + agent.type = AGENTS.AgentTemplate; + agent.label = btDef.name + " AgentTemplate"; + agent.name = "AgentTemplate"; + agent.behaviors = includedBehaviors; + agent.events = includedEvents; + agent.endpoints = includedEndpoints; + return agent; +} + function createDefaultInitialBehavior(repo) { let behavior = {}; behavior.uri = repo + "agents#IB_" + utility.generateUUID(); @@ -179,6 +195,23 @@ function createDefaultBehavior(repo) { return behavior; } +function createDefinedBehavior(repo, btDef, events, includedBehaviors) { + console.log(events); + let behavior = {}; + behavior.uri = repo + "#BE_" + utility.generateUUID(); + behavior.type = AGENTS.Behavior; + behavior.label = btDef.name + " Behavior"; + behavior.behavior = "Behavior"; + behavior.triggers = events; + let bt = {}; + bt.label = btDef.name; + bt.uri = btDef.uri; + behavior.bt = bt; + behavior.clearEKB = false; + includedBehaviors.push(behavior.uri); + return behavior; +} + function createDefaultEvent(repo) { let event = {}; event.type = AGENTS.Event; @@ -188,6 +221,16 @@ function createDefaultEvent(repo) { return event; } +function createDefinedEvent(repo, btDef, includedEvents) { + let event = {}; + event.type = AGENTS.Event; + event.uri = repo + "#EV_" + utility.generateUUID(); + event.label = btDef.name + " Event"; + event.name = "Event"; + includedEvents.push(event.uri); + return event; +} + function createDefaultEndpoint(repo) { let endpoint = {}; endpoint.uri = repo + "agents#EP_" + utility.generateUUID(); @@ -199,6 +242,18 @@ function createDefaultEndpoint(repo) { return endpoint; } +function createDefinedEndpoint(repo, btDef, event, includedEndpoints) { + let endpoint = {}; + endpoint.uri = repo + "#EP_" + utility.generateUUID(); + endpoint.type = AGENTS.Endpoint; + endpoint.name = "Endpoint"; + endpoint.label = btDef.name + " Endpoint"; + endpoint.capability = "execute"; + endpoint.events = [event]; + includedEndpoints.push(endpoint.uri); + return endpoint; +} + function createDefaultGoal(repo) { let goal = {}; goal.uri = repo + "agents#GO_" + utility.generateUUID(); From a5e8dd8e18ff5af970bcf61249414b52d85c57fb Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Mon, 20 Feb 2023 18:30:21 +0100 Subject: [PATCH 8/9] fixed issue not recognizing GoalProducers and ProduceEvent --- app/components/behaviors/behavior-graph.js | 20 ++++++++++++++------ app/helpers/agents/actions.js | 7 ++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/components/behaviors/behavior-graph.js b/app/components/behaviors/behavior-graph.js index b220f73e..b91955dc 100644 --- a/app/components/behaviors/behavior-graph.js +++ b/app/components/behaviors/behavior-graph.js @@ -193,7 +193,9 @@ function generateAgent() { let selected = localStorage.getItem("bt-selected"); let selectedBt = that.get("availableBTs").filter(item => item.uri == selected); console.log(selectedBt); - let includedEvents = new Array(); + let includedEvents = {}; + includedEvents.all = new Array(); + includedEvents.handle = new Array(); selectedBt[0].nodes.forEach(function (item) { addEventURI(item, includedEvents); }); @@ -222,13 +224,19 @@ function saveGeneratedAgent(repo, stringRDF) { function addEventURI(item, events) { let addableUri = ""; + console.log(item); if (item.category == "GoalProducer") { addableUri = getGoalURI(item.uri); - } else if (item.category == "EventProducer" || item.category == "HandleMappingEvent" || item.category == "HandleEvent" || item.category == "HandleQueueEvent") { + } else if (item.category == "ProduceEvent") { addableUri = getEventURI(item.uri); + } else if (item.category == "HandleMappingEvent" || item.category == "HandleEvent" || item.category == "HandleQueueEvent") { + addableUri = getEventURI(item.uri); + if (addableUri != "" && !events.handle.includes(addableUri)) { + events.handle.push(addableUri); + } } - if (addableUri != "" && !events.includes(addableUri)) { - events.push(addableUri); + if (addableUri != "" && !events.all.includes(addableUri)) { + events.all.push(addableUri); } } @@ -244,7 +252,7 @@ function getBehaviors(bt, includedEvents) { let addableBehaviors = {}; addableBehaviors = new Array(); let behaviors = that.get("availableBehaviors"); - includedEvents.forEach(function (event) { + includedEvents.all.forEach(function (event) { behaviors.forEach(function (bhvs) { bhvs.triggers.forEach(function (item) { if (item.uri == event && !addableBehaviors.includes(event) && bhvs.bt.uri != bt.uri) { @@ -259,7 +267,7 @@ function getBehaviors(bt, includedEvents) { function getEndpoints(includedEvents) { let addableEndpoints = new Array(); let endpoints = that.get("availableEndpoints"); - includedEvents.forEach(function (event) { + includedEvents.all.forEach(function (event) { endpoints.forEach(function (endpt) { endpt.events.forEach(function (item) { if (item.uri == event && !addableEndpoints.includes(event)) { diff --git a/app/helpers/agents/actions.js b/app/helpers/agents/actions.js index c4e50439..34013e87 100644 --- a/app/helpers/agents/actions.js +++ b/app/helpers/agents/actions.js @@ -147,7 +147,7 @@ function createDefinedAgent(repo, btDef, includedEvents, includedBehaviors, incl agent.label = btDef.name + " AgentTemplate"; agent.name = "AgentTemplate"; agent.behaviors = includedBehaviors; - agent.events = includedEvents; + agent.events = includedEvents.all; agent.endpoints = includedEndpoints; return agent; } @@ -202,7 +202,7 @@ function createDefinedBehavior(repo, btDef, events, includedBehaviors) { behavior.type = AGENTS.Behavior; behavior.label = btDef.name + " Behavior"; behavior.behavior = "Behavior"; - behavior.triggers = events; + behavior.triggers = events.handle; let bt = {}; bt.label = btDef.name; bt.uri = btDef.uri; @@ -227,7 +227,8 @@ function createDefinedEvent(repo, btDef, includedEvents) { event.uri = repo + "#EV_" + utility.generateUUID(); event.label = btDef.name + " Event"; event.name = "Event"; - includedEvents.push(event.uri); + includedEvents.handle.push(event.uri); + includedEvents.all.push(event.uri); return event; } From 36297c08202e03190707ed95a13c8eb3dc3defaf Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Tue, 21 Feb 2023 10:06:37 +0100 Subject: [PATCH 9/9] fixed issue using wrong node.category for GoalProducers --- app/components/behaviors/behavior-graph.js | 41 +++++++++++++------- app/helpers/RDFServices/agentsRDFProducer.js | 2 - 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/app/components/behaviors/behavior-graph.js b/app/components/behaviors/behavior-graph.js index b91955dc..3b73c0c8 100644 --- a/app/components/behaviors/behavior-graph.js +++ b/app/components/behaviors/behavior-graph.js @@ -193,12 +193,8 @@ function generateAgent() { let selected = localStorage.getItem("bt-selected"); let selectedBt = that.get("availableBTs").filter(item => item.uri == selected); console.log(selectedBt); - let includedEvents = {}; - includedEvents.all = new Array(); - includedEvents.handle = new Array(); - selectedBt[0].nodes.forEach(function (item) { - addEventURI(item, includedEvents); - }); + let includedEvents = { all: new Array(), handle: new Array(), produce: new Array()}; + getEvents(includedEvents, selectedBt[0], that.get("availableBehaviors").filter(item => item.bt.uri != selectedBt[0].uri), true); let includedBehaviors = getBehaviors(selectedBt[0], includedEvents); let includedEndpoints = getEndpoints(includedEvents); let agentDef = {}; @@ -222,20 +218,40 @@ function saveGeneratedAgent(repo, stringRDF) { } } -function addEventURI(item, events) { +function getEvents(includedEvents, bt, behaviors, root) { + bt.nodes.forEach(function (item) { + addEventURI(item, includedEvents, root); + }); + behaviors.forEach(function (bhvs) { + bhvs.triggers.forEach(function (event) { + if (includedEvents.produce.includes(event.uri)) { + bhvs.triggers.forEach(function (triggers) { + includedEvents.all.push(triggers.uri); + }); + let newBt = that.get("availableBTs").filter(item => item.uri == bhvs.bt.uri); + console.log("Visit BT: " + newBt[0].uri); + getEvents(includedEvents, newBt[0], behaviors.filter(item => item.uri != bhvs.uri), false); + } + }); + }); + return includedEvents; +} + +function addEventURI(item, events, root) { let addableUri = ""; - console.log(item); - if (item.category == "GoalProducer") { + if (item.category == "ProduceGoal") { addableUri = getGoalURI(item.uri); + events.produce.push(addableUri); } else if (item.category == "ProduceEvent") { addableUri = getEventURI(item.uri); + events.produce.push(addableUri); } else if (item.category == "HandleMappingEvent" || item.category == "HandleEvent" || item.category == "HandleQueueEvent") { addableUri = getEventURI(item.uri); - if (addableUri != "" && !events.handle.includes(addableUri)) { + if (root && addableUri != "" && !events.handle.includes(addableUri)) { events.handle.push(addableUri); } } - if (addableUri != "" && !events.all.includes(addableUri)) { + if (that.get("availableEvents").filter(item => item.uri == addableUri).length > 0 && addableUri != "" && !events.all.includes(addableUri)) { events.all.push(addableUri); } } @@ -249,8 +265,7 @@ function getEventURI(uri) { } function getBehaviors(bt, includedEvents) { - let addableBehaviors = {}; - addableBehaviors = new Array(); + let addableBehaviors = new Array(); let behaviors = that.get("availableBehaviors"); includedEvents.all.forEach(function (event) { behaviors.forEach(function (bhvs) { diff --git a/app/helpers/RDFServices/agentsRDFProducer.js b/app/helpers/RDFServices/agentsRDFProducer.js index e4323af4..e3f56e05 100644 --- a/app/helpers/RDFServices/agentsRDFProducer.js +++ b/app/helpers/RDFServices/agentsRDFProducer.js @@ -66,11 +66,9 @@ function createBehaviorQuads(quads, behavior) { quads.add(rdfFact.quad(behavior.uri, RDF.type, AGENTS.Behavior)); quads.add(rdfFact.quadLiteral(behavior.uri, RDFS.label, behavior.label)); quads.add(rdfFact.quad(behavior.uri, AGENTS.bt, behavior.bt.uri)); - console.log(behavior.triggers); behavior.triggers.forEach(function (event) { quads.add(rdfFact.quad(behavior.uri, AGENTS.trigger, event)); }) - console.log(behavior.clearEKB); quads.add(rdfFact.quadLiteral(behavior.uri, AGENTS.clearEKB, behavior.clearEKB, XSD.boolean)); }