100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Work on app designer
Christian Bauer8021cb0c0168
diff --git a/container/src/main/java/org/openremote/container/persistence/package-info.java b/container/src/main/java/org/openremote/container/persistence/package-info.javaindex 26ec21450..c4e4fac6c 100644--- a/container/src/main/java/org/openremote/container/persistence/package-info.java+++ b/container/src/main/java/org/openremote/container/persistence/package-info.java@@ -30,6 +30,10 @@@org.hibernate.annotations.TypeDef(name = Constants.PERSISTENCE_JSON_ARRAY_TYPE,typeClass = ModelArrayValuePersistentType.class+ ),+ @org.hibernate.annotations.TypeDef(+ name = Constants.PERSISTENCE_STRING_ARRAY_TYPE,+ typeClass = ArrayUserType.class)})diff --git a/manager/test/src/test/groovy/org/openremote/test/flow/FlowModelTest.groovy b/manager/test/src/test/groovy/org/openremote/test/flow/FlowModelTest.groovynew file mode 100644index 000000000..6a54c43d2--- /dev/null+++ b/manager/test/src/test/groovy/org/openremote/test/flow/FlowModelTest.groovy@@ -0,0 +1,34 @@+package org.openremote.test.flow++import org.openremote.model.flow.Flow+import org.openremote.model.flow.Node+import org.openremote.model.flow.Wire+import org.openremote.test.ManagerContainerTrait+import spock.lang.Specification++class FlowModelTest extends Specification implements ManagerContainerTrait {++ def "Ignore duplicate wires"() {++ given: "a flow"+ Flow flow = new Flow("Test Flow", "123")++ when: "duplicate wires are added"+ flow.addWire(new Wire("a", "b"))+ flow.addWire(new Wire("a", "b"))++ then: "only one wire should be present"+ flow.getWires().length == 1++ }++ def "Throw when duplicate constructor wires"() {++ when: "duplicate wires are provided as constructor arguments"+ new Flow("foo", "123", new Node[0], [new Wire("a", "b"), new Wire("a", "b")] as Wire[])++ then: "an exception should be thrown"+ thrown(IllegalArgumentException)+ }++}diff --git a/model/src/main/java/org/openremote/model/Constants.java b/model/src/main/java/org/openremote/model/Constants.javaindex 075909d49..5cc2e7fc5 100644--- a/model/src/main/java/org/openremote/model/Constants.java+++ b/model/src/main/java/org/openremote/model/Constants.java@@ -32,6 +32,7 @@ public interface Constants {String PERSISTENCE_JSON_VALUE_TYPE = "json_value";String PERSISTENCE_JSON_OBJECT_TYPE = "json_object";String PERSISTENCE_JSON_ARRAY_TYPE = "json_array";+ String PERSISTENCE_STRING_ARRAY_TYPE = "string_array";String NAMESPACE = "urn:openremote";String PROTOCOL_NAMESPACE = NAMESPACE + ":protocol";String ASSET_NAMESPACE = NAMESPACE + ":asset";diff --git a/model/src/main/java/org/openremote/model/flow/EditorSettings.java b/model/src/main/java/org/openremote/model/flow/EditorSettings.javanew file mode 100644index 000000000..c5e5463a5--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/EditorSettings.java@@ -0,0 +1,111 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;++import javax.persistence.Column;+import javax.persistence.EnumType;+import javax.persistence.Enumerated;+import javax.validation.constraints.NotNull;++import static org.openremote.model.Constants.PERSISTENCE_STRING_ARRAY_TYPE;++@JsType+public class EditorSettings {++ @NotNull+ @Column(name = "EDITOR_TYPE_LABEL", nullable = false)+ public String typeLabel = "Unknown Type";++ @NotNull+ @Column(name = "EDITOR_NODE_COLOR", nullable = false)+ @Enumerated(EnumType.STRING)+ public NodeColor nodeColor = NodeColor.DEFAULT;++ @NotNull+ @Column(name = "EDITOR_POSITION_X", nullable = false)+ public double positionX;++ @NotNull+ @Column(name = "EDITOR_POSITION_Y", nullable = false)+ public double positionY;++ @Column(name = "EDITOR_COMPONENTS", columnDefinition = "text[]")+ @org.hibernate.annotations.Type(type = PERSISTENCE_STRING_ARRAY_TYPE)+ public String[] components;++ @JsIgnore+ public EditorSettings() {+ }++ @JsIgnore+ public EditorSettings(String typeLabel) {+ this.typeLabel = typeLabel;+ }++ @JsIgnore+ public EditorSettings(String typeLabel, NodeColor nodeColor) {+ this.typeLabel = typeLabel;+ this.nodeColor = nodeColor;+ }++ public String getTypeLabel() {+ return typeLabel;+ }++ public void setTypeLabel(String typeLabel) {+ this.typeLabel = typeLabel;+ }++ public NodeColor getNodeColor() {+ return nodeColor;+ }++ public void setNodeColor(NodeColor nodeColor) {+ this.nodeColor = nodeColor;+ }++ public double getPositionX() {+ return positionX;+ }++ public void setPositionX(double positionX) {+ this.positionX = positionX;+ }++ public double getPositionY() {+ return positionY;+ }++ public void setPositionY(double positionY) {+ this.positionY = positionY;+ }++ public String[] getComponents() {+ return components;+ }++ public void setComponents(String[] components) {+ this.components = components;+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/Flow.java b/model/src/main/java/org/openremote/model/flow/Flow.javanew file mode 100644index 000000000..bd768e11f--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/Flow.java@@ -0,0 +1,418 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;++import javax.persistence.*;+import java.util.*;++@JsType+@Entity+@Table(name = "FLOW")+public class Flow extends FlowObject {++ public static final String TYPE = "urn:openremote:flow";++ @Version+ public int version;++ @JsIgnore+ @Column(name = "CREATED_ON")+ @Temporal(TemporalType.TIMESTAMP)+ public Date createdOn = new Date();++ @Transient+ public Node[] nodes = new Node[0];++ @Transient+ public Wire[] wires = new Wire[0];++ @Transient+ public FlowDependency[] superDependencies = new FlowDependency[0];++ @Transient+ public FlowDependency[] subDependencies = new FlowDependency[0];++ @JsIgnore+ protected Flow() {+ }++ @JsIgnore+ public Flow(String label, String id) {+ super(label, id, TYPE);+ }++ @JsIgnore+ public Flow(String label, String id, Node... nodes) {+ this(label, id);+ this.nodes = nodes;+ }++ @JsIgnore+ public Flow(String label, String id, Node[] nodes, Wire[] wires) {+ this(label, id);+ this.nodes = nodes;+ this.wires = wires;+ if (wires != null) {+ // Consistency check, important to avoid duplicate wires+ Set<Wire> wireSet = new HashSet<>(Arrays.asList(wires));+ if (wireSet.size() != wires.length)+ throw new IllegalArgumentException("Duplicate wires: " + Arrays.toString(wires));+ }+ }++ @JsIgnore+ public Date getCreatedOn() {+ return createdOn;+ }++ public Node[] getNodes() {+ return nodes;+ }++ public Node[] findNodes(String type) {+ List<Node> collection = new ArrayList<>(Arrays.asList(getNodes()));+ Iterator<Node> it = collection.iterator();+ while (it.hasNext()) {+ Node node = it.next();+ if (!node.isOfType(type))+ it.remove();+ }+ return collection.toArray(new Node[collection.size()]);+ }++ public Node[] findConsumerProducerNodes() {+ Set<Node> collection = new HashSet<>();+ for (Node node : getNodes()) {+ if (node.isOfTypeConsumerOrProducer())+ collection.add(node);+ }+ return collection.toArray(new Node[collection.size()]);+ }++ public Node[] findClientWidgetNodes() {+ Set<Node> collection = new HashSet<>();+ for (Node node : getNodes()) {+ if (node.isClientWidget())+ collection.add(node);+ }+ return collection.toArray(new Node[collection.size()]);+ }++ public void addNode(Node node) {+ Set<Node> collection = new HashSet<>(Arrays.asList(getNodes()));+ collection.add(node);+ this.nodes = collection.toArray(new Node[collection.size()]);+ }++ public Wire[] removeNode(Node node) {+ Set<Node> collection = new HashSet<>(Arrays.asList(getNodes()));+ collection.remove(node);+ this.nodes = collection.toArray(new Node[collection.size()]);+ return removeWiresOf(node);+ }++ public Node[] removeProducerConsumerNodes() {+ Set<Node> collection = new HashSet<>(Arrays.asList(getNodes()));+ Node[] consumersProducers = findConsumerProducerNodes();+ for (Node consumersProducer : consumersProducers) {+ removeNode(consumersProducer);+ }+ return collection.toArray(new Node[collection.size()]);+ }++ public void clearDependencies() {+ setSuperDependencies(new FlowDependency[0]);+ setSubDependencies(new FlowDependency[0]);+ }++ public FlowDependency[] getSuperDependencies() {+ return superDependencies;+ }++ public void setSuperDependencies(FlowDependency[] superDependencies) {+ this.superDependencies = superDependencies;+ }++ public FlowDependency[] getSubDependencies() {+ return subDependencies;+ }++ public void setSubDependencies(FlowDependency[] subDependencies) {+ this.subDependencies = subDependencies;+ }++ public FlowDependency findSubDependency(Node subflowNode) {+ for (FlowDependency subDependency : getSubDependencies()) {+ if (subDependency.getId().equals(subflowNode.getSubflowId()))+ return subDependency;+ }+ return null;+ }++ public FlowDependency[] getDirectSuperDependencies() {+ List<FlowDependency> list = new ArrayList<>();+ for (FlowDependency flowDependency : getSuperDependencies()) {+ if (flowDependency.getLevel() == 0)+ list.add(flowDependency);+ }+ return list.toArray(new FlowDependency[list.size()]);+ }++ public boolean hasDirectWiredSuperDependencies() {+ for (FlowDependency superDependency : getDirectSuperDependencies()) {+ if (superDependency.isWired())+ return true;+ }+ return false;+ }++ public Wire[] getWires() {+ return wires;+ }++ public Wire addWireBetweenSlots(Slot sourceSlot, Slot sinkSlot) {+ return addWire(new Wire(sourceSlot.getId(), sinkSlot.getId()));+ }++ public Wire addWire(Wire wire) {+ for (Wire existing : getWires()) {+ if (existing.equals(wire))+ return null;+ }+ List<Wire> list = new ArrayList<>(Arrays.asList(getWires()));+ list.add(wire);+ this.wires = list.toArray(new Wire[list.size()]);+ return wire;+ }++ public Wire removeWire(Wire wire) {+ Wire removed = null;+ ArrayList<Wire> collection = new ArrayList<>(Arrays.asList(getWires()));+ Iterator<Wire> it = collection.iterator();+ while (it.hasNext()) {+ if (it.next().equals(wire)) {+ removed = wire;+ it.remove();+ }+ }+ this.wires = collection.toArray(new Wire[collection.size()]);+ return removed;+ }++ public Wire removeWireBetweenSlots(Slot sourceSlot, Slot sinkSlot) {+ Wire removed = null;+ ArrayList<Wire> collection = new ArrayList<>(Arrays.asList(getWires()));+ Iterator<Wire> it = collection.iterator();+ while (it.hasNext()) {+ Wire wire = it.next();+ if (wire.getSourceId().equals(sourceSlot.getId())+ && wire.getSinkId().equals(sinkSlot.getId())) {+ it.remove();+ removed = wire;+ }+ }+ this.wires = collection.toArray(new Wire[collection.size()]);+ return removed;+ }++ public Wire[] removeWiresOf(Node node) {+ Set<Wire> collection = new HashSet<>();+ for (Slot slot : node.getSlots()) {+ Wire[] wires = findWiresAttachedToSlot(slot.getId());+ for (Wire wire : wires) {+ collection.add(removeWire(wire));+ }+ }+ return collection.toArray(new Wire[collection.size()]);+ }++ public Slot findSlot(String slotId) {+ for (Node node : getNodes()) {+ Slot slot = node.findSlot(slotId);+ if (slot != null)+ return slot;+ }+ return null;+ }++ public boolean removeSlot(Node node, String slotId) {+ if (findNode(node.getId()) == null)+ throw new IllegalStateException("Node not in flow: " + node);+ Slot slot = node.findSlot(slotId);+ if (slot == null)+ return false;+ List<Slot> collection = new ArrayList<>();+ collection.addAll(Arrays.asList(node.getSlots()));+ Iterator<Slot> it = collection.iterator();+ boolean removed = false;+ while (it.hasNext()) {+ Slot next = it.next();+ if (next.getId().equals(slotId)) {+ removed = true;+ it.remove();+ Wire[] wires = findWiresAttachedToSlot(next.getId());+ for (Wire wire : wires) {+ removeWire(wire);+ }+ break;+ }+ }+ node.setSlots(collection.toArray(new Slot[collection.size()]));+ return removed;+ }++ public boolean hasWires(String slotId) {+ for (Wire wire : getWires()) {+ if (wire.getSourceId().equals(slotId))+ return true;+ if (wire.getSinkId().equals(slotId))+ return true;+ }+ return false;+ }++ public Wire[] findWiresAttachedToSlot(String slotId) {+ List<Wire> list = new ArrayList<>();+ for (Wire wire : getWires()) {+ if (wire.getSourceId().equals(slotId) || wire.getSinkId().equals(slotId))+ list.add(wire);+ }+ return list.toArray(new Wire[list.size()]);+ }++ public Wire[] findWiresForSource(String slotId) {+ List<Wire> list = new ArrayList<>();+ for (Wire wire : getWires()) {+ if (wire.getSourceId().equals(slotId))+ list.add(wire);+ }+ return list.toArray(new Wire[list.size()]);+ }++ public Wire[] findWiresForSink(String slotId) {+ List<Wire> list = new ArrayList<>();+ for (Wire wire : getWires()) {+ if (wire.getSinkId().equals(slotId))+ list.add(wire);+ }+ return list.toArray(new Wire[list.size()]);+ }++ public Node findNode(String nodeId) {+ for (Node node : getNodes()) {+ if (node.getId().equals(nodeId))+ return node;+ }+ return null;+ }++ public Node[] findSubflowNodes() {+ Set<Node> collection = new HashSet<>();+ for (Node node : getNodes()) {+ if (node.isOfType(Node.TYPE_SUBFLOW))+ collection.add(node);+ }+ return collection.toArray(new Node[collection.size()]);+ }++ public Slot[] findSlotsWithoutPeer(Node subflowNode, Flow flow, boolean onlyWiredSlots) {+ if (!subflowNode.isOfTypeSubflow() || !flow.getId().equals(subflowNode.getSubflowId()))+ throw new IllegalArgumentException(+ "Node '" + subflowNode + "' is not a subflow node using: " + flow+ );+ List<Slot> list = new ArrayList<>();++ Slot[] slots = subflowNode.getSlots();+ for (Slot slot : slots) {+ // Is there a wire attached?+ boolean wireAttachedToSlot = findWiresAttachedToSlot(slot.getId()).length > 0;+ if (!wireAttachedToSlot) {+ // Not going to be a problem, this slot can be removed or updated silently+ if (!onlyWiredSlots)+ list.add(slot);+ continue;+ }++ // Do we still have the peer linked to the slot in the given flow?+ boolean peerMissing = flow.findSlot(slot.getPeerId()) == null;++ // If we no longer have its peer, then the slot and all its attached wires are broken+ if (peerMissing)+ list.add(slot);+ }+ return list.toArray(new Slot[list.size()]);+ }++ public Wire[] findWiresAttachedToNode(Node node) {+ Set<Wire> collection = new HashSet<>();+ for (Slot slot : node.getSlots()) {+ collection.addAll(Arrays.asList(findWiresAttachedToSlot(slot.getId())));+ }+ return collection.toArray(new Wire[collection.size()]);+ }++ public Wire[] findWiresBetween(Node a, Node b) {+ Set<Wire> collection = new HashSet<>();+ for (Wire wire : getWires()) {+ Node sourceOwner = findOwnerNode(wire.getSourceId());+ Node sinkOwner = findOwnerNode(wire.getSinkId());+ if ((sourceOwner.getId().equals(a.getId()) && sinkOwner.getId().equals(b.getId()))+ || (sourceOwner.getId().equals(b.getId()) && sinkOwner.getId().equals(a.getId()))) {+ collection.add(wire);+ }+ }+ return collection.toArray(new Wire[collection.size()]);+ }++ public Node findOwnerNode(String slotId) {+ for (Node node : getNodes()) {+ Slot slot = node.findSlot(slotId);+ if (slot != null)+ return node;+ }+ return null;+ }++ @JsIgnore+ public void printWires(StringBuilder sb) {+ sb.append("\n").append("Wires of ").append(this).append(" => ").append(getWires().length).append("\n");+ printWires(sb, getWires());+ }++ @JsIgnore+ public void printWires(StringBuilder sb, Wire[] wires) {+ for (Wire wire : wires) {+ sb.append("--------------------------------------------------------------------------------------------");+ sb.append("\n");+ Node sourceNode = findOwnerNode(wire.getSourceId());+ Node sinkNode = findOwnerNode(wire.getSinkId());+ sb.append(sourceNode).append(" => ").append(sinkNode);+ sb.append("\n");+ Slot sourceSlot = findSlot(wire.getSourceId());+ Slot sinkSlot = findSlot(wire.getSinkId());+ sb.append(sourceSlot).append(" => ").append(sinkSlot);+ sb.append("\n");+ }+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/FlowDependency.java b/model/src/main/java/org/openremote/model/flow/FlowDependency.javanew file mode 100644index 000000000..9ffc5782f--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/FlowDependency.java@@ -0,0 +1,85 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;++@JsType+public class FlowDependency extends FlowObject {++ public Flow flow; // Optional, only in fully materialized dependency tree+ public int level;+ public boolean wired; // Super-dependencies might be only using this flow or have actual wires (hard dependency)+ public boolean peersInvalid; // Wired super-dependencies might have broken wires if we are missing consumers/producers peers++ @JsIgnore+ protected FlowDependency() {+ }++ @JsIgnore+ public FlowDependency(String label, String id, String type) {+ super(label, id, type);+ }++ @JsIgnore+ public FlowDependency(String label, String id, String type, int level, boolean wired, boolean peersInvalid) {+ this(label, id, type, null, level);+ this.wired = wired;+ this.peersInvalid = peersInvalid;+ }++ @JsIgnore+ public FlowDependency(String label, String id, String type, Flow flow, int level) {+ super(label, id, type);+ this.flow = flow;+ this.level = level;+ }++ @Override+ public String getDefaultedLabel() {+ return isLabelEmpty() ? "Unnamed Flow" : getLabel();+ }++ public Flow getFlow() {+ return flow;+ }++ public void setFlow(Flow flow) {+ this.flow = flow;+ }++ public int getLevel() {+ return level;+ }++ public void setLevel(int level) {+ this.level = level;+ }++ public boolean isWired() {+ return wired;+ }++ public boolean isPeersInvalid() {+ return peersInvalid;+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/FlowDependencyResolver.java b/model/src/main/java/org/openremote/model/flow/FlowDependencyResolver.javanew file mode 100644index 000000000..3a2897551--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/FlowDependencyResolver.java@@ -0,0 +1,223 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import java.util.*;++public abstract class FlowDependencyResolver {++ public void populateDependencies(Flow flow, boolean hydrate) {+ flow.clearDependencies();++ List<FlowDependency> superDependencies = new ArrayList<>();+ populateSuperDependencies(flow, 0, superDependencies);+ Collections.reverse(superDependencies);+ flow.setSuperDependencies(superDependencies.toArray(new FlowDependency[superDependencies.size()]));++ List<FlowDependency> subDependencies = new ArrayList<>();+ populateSubDependencies(flow, hydrate, 0, subDependencies);+ flow.setSubDependencies(subDependencies.toArray(new FlowDependency[subDependencies.size()]));+ }++ public void updateDependencies(Flow flow, boolean flowWillBeDeleted) {+ if (flowWillBeDeleted)+ flow.removeProducerConsumerNodes();++ flow.clearDependencies();+ populateDependencies(flow, false);++ for (FlowDependency superDependency : flow.getDirectSuperDependencies()) {+ Flow superFlow = findFlow(superDependency.getId());++ boolean superFlowModified = false;+ boolean superFlowShouldBeStopped = false;++ for (Node subflowNode : superFlow.findSubflowNodes()) {+ if (!subflowNode.getSubflowId().equals(flow.getId()))+ continue;++ if (flowWillBeDeleted) {+ // Easy case, the flow will be deleted, so delete subflow node and all its wires+ superFlow.removeNode(subflowNode);+ superFlowModified = true;+ superFlowShouldBeStopped = true;+ } else {++ // Find slots we no longer have and delete them and their wires (also include any slots without wires)+ Slot[] slotsWithoutPeer = superFlow.findSlotsWithoutPeer(subflowNode, flow, false);+ for (Slot slotWithoutPeer : slotsWithoutPeer) {++ // Slots with a property path must be ignored, they are not mapped to peers by definition+ if (slotWithoutPeer.getPropertyPath() != null)+ continue;++ if (superFlow.removeSlot(subflowNode, slotWithoutPeer.getId())) {+ superFlowModified = true;+ superFlowShouldBeStopped = true;+ }+ }++ // All other slots which are still valid, update the label+ for (Slot subflowSlot : subflowNode.getSlots()) {++ // Slots with a property path must be ignored, they are not mapped to peers by definition+ if (subflowSlot.getPropertyPath() != null)+ continue;++ Node peerNode = flow.findOwnerNode(subflowSlot.getPeerId());+ if (peerNode.getLabel() != null && !peerNode.getLabel().equals(subflowSlot.getLabel())) {+ subflowSlot.setLabel(peerNode.getLabel());+ superFlowModified = true;+ superFlowShouldBeStopped = false;+ }+ }++ // Add new slots for any new consumers/producers+ List<Slot> newSlots = new ArrayList<>();+ Node[] consumers = flow.findNodes(Node.TYPE_CONSUMER);+ for (Node consumer : consumers) {+ Slot firstSink = consumer.findSlots(Slot.TYPE_SINK)[0];+ if (subflowNode.findSlotWithPeer(firstSink.getId()) == null)+ newSlots.add(new Slot(generateGlobalUniqueId(), firstSink, consumer.getLabel()));+ }+ Node[] producers = flow.findNodes(Node.TYPE_PRODUCER);+ for (Node producer : producers) {+ Slot firstSource = producer.findSlots(Slot.TYPE_SOURCE)[0];+ if (subflowNode.findSlotWithPeer(firstSource.getId()) == null)+ newSlots.add(new Slot(generateGlobalUniqueId(), firstSource, producer.getLabel()));+ }+ if (newSlots.size() > 0) {+ subflowNode.addSlots(newSlots.toArray(new Slot[newSlots.size()]));+ superFlowModified = true;+ superFlowShouldBeStopped = false;+ }+ }+ }++ if (superFlowModified) {+ superFlow.clearDependencies();+ if (superFlowShouldBeStopped)+ stopFlowIfRunning(superFlow);+ storeFlow(superFlow);+ }+ }+ }++ protected void populateSuperDependencies(Flow flow, int level, List<FlowDependency> dependencyList) {++ Flow[] subflowDependents = findSubflowDependents(flow.getId());++ for (Flow subflowDependent : subflowDependents) {++ // Is this dependency breakable (wires attached?) or already broken (invalid peers?)+ boolean flowHasWiresAttached = false;+ boolean flowHasInvalidPeers = false;++ Node[] subflowNodes = subflowDependent.findSubflowNodes();++ for (Node subflowNode : subflowNodes) {+ if (!subflowNode.getSubflowId().equals(flow.getId()))+ continue;++ // Is the subflow node attached to any other node or does nobody care if we replace it silently?+ boolean nodeHasWires = subflowDependent.findWiresAttachedToNode(subflowNode).length > 0;++ // Are any of its (wired) slot peers no longer in the current flow?+ boolean nodeHasMissingPeers = false;+ if (nodeHasWires) {+ nodeHasMissingPeers = subflowDependent.findSlotsWithoutPeer(subflowNode, flow, true).length > 0;+ }++ flowHasWiresAttached = flowHasWiresAttached || nodeHasWires;+ flowHasInvalidPeers = flowHasInvalidPeers || nodeHasMissingPeers;+ }++ dependencyList.add(+ new FlowDependency(+ subflowDependent.getLabel(),+ subflowDependent.getId(),+ subflowDependent.getType(),+ level,+ flowHasWiresAttached,+ flowHasInvalidPeers+ )+ );++ populateSuperDependencies(subflowDependent, level + 1, dependencyList);+ }+ }++ protected void populateSubDependencies(Flow flow, boolean hydrate, int level, List<FlowDependency> dependencyList) {++ Set<String> added = new HashSet<>();++ Node[] subflowNodes = flow.findSubflowNodes();++ for (Node subflowNode : subflowNodes) {+ Flow subflow = findFlow(subflowNode.getSubflowId());++ if (subflow == null)+ throw new IllegalStateException(+ "Missing subflow dependency '" + subflowNode.getSubflowId() + "': in " + subflowNode+ );++ // Do we have a loop?+ if (subflow.getId().equals(flow.getId())) {+ throw new IllegalStateException(+ "Loop detected, can't have flow as its own subflow: " + flow+ );+ }+ for (FlowDependency superDependency : flow.getSuperDependencies()) {+ if (subflow.getId().equals(superDependency.getId())) {+ throw new IllegalStateException(+ "Loop detected in '" + flow + "', subflow is also super dependency: " + subflow+ );+ }+ }++ if (!added.contains(subflow.getId())) {+ dependencyList.add(+ new FlowDependency(+ subflow.getLabel(),+ subflow.getId(),+ subflow.getType(),+ hydrate ? subflow : null,+ level+ )+ );+ added.add(subflow.getId());+ populateSubDependencies(subflow, hydrate, level + 1, dependencyList);+ }++ }+ }++ protected abstract String generateGlobalUniqueId();++ protected abstract Flow findFlow(String flowId);++ protected abstract Flow[] findSubflowDependents(String flowId);++ protected abstract void stopFlowIfRunning(Flow flow);++ protected abstract void storeFlow(Flow flow);++}\ No newline at end of filediff --git a/model/src/main/java/org/openremote/model/flow/FlowObject.java b/model/src/main/java/org/openremote/model/flow/FlowObject.javanew file mode 100644index 000000000..6dba5c12f--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/FlowObject.java@@ -0,0 +1,110 @@+//+// Source code recreated from a .class file by IntelliJ IDEA+// (powered by Fernflower decompiler)+//++package org.openremote.model.flow;++import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;+import org.openremote.model.IdentifiableEntity;++import javax.persistence.Column;+import javax.persistence.GeneratedValue;+import javax.persistence.Id;+import javax.persistence.MappedSuperclass;+import javax.validation.constraints.NotNull;+import javax.validation.constraints.Size;++import static org.openremote.model.Constants.PERSISTENCE_UNIQUE_ID_GENERATOR;++@JsType+@MappedSuperclass+public class FlowObject implements IdentifiableEntity {++ @Id+ @Column(name = "ID", length = 43) // TODO Is this ideal long-term for reads when keys must be distributed on cluster?+ @GeneratedValue(generator = PERSISTENCE_UNIQUE_ID_GENERATOR)+ public String id;++ @NotNull+ @Size(min = 3, max = 255)+ @Column(name = "MODEL_TYPE")+ public String type;++ @Column(name = "LABEL", nullable = true)+ public String label;++ @JsIgnore+ protected FlowObject() {+ }++ @JsIgnore+ public FlowObject(String id, String type, String label) {+ this.id = id;+ this.type = type;+ this.label = label;+ }++ @Override+ public String getId() {+ return this.id;+ }++ @Override+ public void setId(String id) {+ this.id = id;+ }++ public String getType() {+ return this.type;+ }++ public boolean isOfType(String type) {+ return this.getType().equals(type);+ }++ public String toTypeIdString() {+ return this.type + ':' + this.id;+ }++ public String getLabel() {+ return this.label;+ }++ public void setLabel(String label) {+ this.label = label;+ }++ public boolean isLabelEmpty() {+ return this.getLabel() == null || this.getLabel().length() == 0;+ }++ public String getDefaultedLabel() {+ return this.isLabelEmpty() ? "Unnamed " + this.getClass().getSimpleName() : this.getLabel();+ }++ public boolean equals(Object o) {+ if (this == o) {+ return true;+ } else if (o != null && this.getClass() == o.getClass()) {+ FlowObject that = (FlowObject) o;+ return this.getId().equals(that.getId());+ } else {+ return false;+ }+ }++ public int hashCode() {+ return this.id.hashCode();+ }++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "id='" + id + '\'' ++ ", type='" + type + '\'' ++ ", label='" + label + '\'' ++ '}';+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/Node.java b/model/src/main/java/org/openremote/model/flow/Node.javanew file mode 100644index 000000000..7d58377a4--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/Node.java@@ -0,0 +1,256 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import com.fasterxml.jackson.annotation.JsonIgnore;+import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;++import javax.persistence.*;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.List;++import static org.openremote.model.Constants.PERSISTENCE_STRING_ARRAY_TYPE;++@JsType+@Entity+@Table(name = "NODE")+public class Node extends FlowObject {++ public static final String TYPE_SUBFLOW = "urn:openremote:flow:node:subflow";+ public static final String TYPE_SUBFLOW_LABEL = "Subflow";++ public static final String TYPE_CONSUMER = "urn:openremote:flow:node:consumer";+ public static final String TYPE_CONSUMER_LABEL = "Sink";++ public static final String TYPE_PRODUCER = "urn:openremote:flow:node:producer";+ public static final String TYPE_PRODUCER_LABEL = "Source";++ @Transient+ public Slot[] slots = new Slot[0];++ @ManyToOne(fetch = FetchType.LAZY)+ @JoinColumn(name = "FLOW_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_NODE_FLOW_ID"))+ @org.hibernate.annotations.OnDelete(+ action = org.hibernate.annotations.OnDeleteAction.CASCADE+ )+ @JsIgnore+ @JsonIgnore+ public Flow flow;++ // TODO Should this be FK constrained?+ @Column(name = "SUBFLOW_ID", nullable = true)+ public String subflowId;++ @Column(name = "CLIENT_ACCESS", nullable = false)+ public boolean clientAccess;++ @Column(name = "CLIENT_WIDGET", nullable = false)+ public boolean clientWidget;++ @Column(name = "ROUTE_PRE_ENDPOINT", nullable = true)+ public String preEndpoint;++ @Column(name = "ROUTE_POST_ENDPOINT", nullable = true)+ public String postEndpoint;++ @Embedded+ public EditorSettings editorSettings = new EditorSettings();++ @Column(name = "NODE_PROPERTIES", nullable = true, length = 1048576) // TODO 1MB?+ public String properties;++ @Column(name = "PERSISTENT_PROPERTY_PATHS", nullable = true, columnDefinition = "text[]")+ @org.hibernate.annotations.Type(type = PERSISTENCE_STRING_ARRAY_TYPE)+ public String[] persistentPropertyPaths;++ @JsIgnore+ protected Node() {+ }++ @JsIgnore+ public Node(String label, String id, String type) {+ super(label, id, type);+ }++ @JsIgnore+ public Node(String label, String id, String type, String subflowId) {+ super(label, id, type);+ if (!isOfTypeSubflow()) {+ throw new IllegalArgumentException(+ "Node with subflow identifier must be of type: " + TYPE_SUBFLOW+ );+ }+ this.subflowId = subflowId;+ }++ public boolean isOfTypeSubflow() {+ return isOfType(TYPE_SUBFLOW);+ }++ public boolean isOfTypeConsumerOrProducer() {+ return isOfType(TYPE_CONSUMER) || isOfType(TYPE_PRODUCER);+ }++ public String getSubflowId() {+ return subflowId;+ }++ public void setSubflowId(String subflowId) {+ this.subflowId = subflowId;+ }++ public Slot[] getSlots() {+ return slots;+ }++ public void setSlots(Slot[] slots) {+ this.slots = slots;+ }++ public boolean isClientAccess() {+ return clientAccess;+ }++ public void setClientAccess(boolean clientAccess) {+ this.clientAccess = clientAccess;+ }++ public boolean isClientWidget() {+ return clientWidget;+ }++ public void setClientWidget(boolean clientWidget) {+ this.clientWidget = clientWidget;+ }++ public String getPreEndpoint() {+ return preEndpoint;+ }++ public void setPreEndpoint(String preEndpoint) {+ this.preEndpoint = preEndpoint;+ }++ public String getPostEndpoint() {+ return postEndpoint;+ }++ public void setPostEndpoint(String postEndpoint) {+ this.postEndpoint = postEndpoint;+ }++ public EditorSettings getEditorSettings() {+ return editorSettings;+ }++ public void setEditorSettings(EditorSettings editorSettings) {+ this.editorSettings = editorSettings;+ }++ public String getProperties() {+ return properties;+ }++ public void setProperties(String properties) {+ this.properties = properties;+ }++ public String[] getPersistentPropertyPaths() {+ return persistentPropertyPaths;+ }++ public void setPersistentPropertyPaths(String[] persistentPropertyPaths) {+ this.persistentPropertyPaths = persistentPropertyPaths;+ }++ public void addSlots(Slot... newSlots) {+ List<Slot> list = new ArrayList<>();+ list.addAll(Arrays.asList(getSlots()));+ list.addAll(Arrays.asList(newSlots));+ setSlots(list.toArray(new Slot[list.size()]));+ }++ public Slot findSlot(String slotId) {+ for (Slot slot : getSlots()) {+ if (slot.getId().equals(slotId))+ return slot;+ }+ return null;+ }++ public Slot[] findSlots(String type) {+ List<Slot> list = new ArrayList<>();+ for (Slot slot : getSlots()) {+ if (slot.isOfType(type))+ list.add(slot);+ }+ return list.toArray(new Slot[list.size()]);+ }++ public Slot findSlotWithPeer(String peerId) {+ for (Slot slot : getSlots()) {+ if (slot.getPeerId() != null && slot.getPeerId().equals(peerId))+ return slot;+ }+ return null;+ }++ public Slot[] findAllConnectableSlots() {+ return findConnectableSlots(null);+ }++ public Slot[] findConnectableSlots(String type) {+ List<Slot> list = new ArrayList<>();+ for (Slot slot : getSlots()) {+ if ((type == null || slot.isOfType(type)) && slot.isConnectable())+ list.add(slot);+ }+ return list.toArray(new Slot[list.size()]);+ }++ public Slot[] findNonPropertySlots(String type) {+ List<Slot> list = new ArrayList<>();+ for (Slot slot : getSlots()) {+ if (slot.isOfType(type) && slot.getPropertyPath() == null)+ list.add(slot);+ }+ return list.toArray(new Slot[list.size()]);+ }++ public Slot[] findPropertySlots() {+ List<Slot> list = new ArrayList<>();+ for (Slot slot : getSlots()) {+ if (slot.getPropertyPath() != null)+ list.add(slot);+ }+ return list.toArray(new Slot[list.size()]);+ }++ public Slot findSlotByPosition(int position, String type) {+ if (position > getSlots().length - 1)+ return null;+ if (getSlots()[position].isOfType(type))+ return getSlots()[position];+ return null;+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/NodeColor.java b/model/src/main/java/org/openremote/model/flow/NodeColor.javanew file mode 100644index 000000000..4ad962fd1--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/NodeColor.java@@ -0,0 +1,33 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import jsinterop.annotations.JsType;++@JsType+public enum NodeColor {++ DEFAULT,+ ASSET,+ VIRTUAL,+ CONSOLE++}diff --git a/model/src/main/java/org/openremote/model/flow/Slot.java b/model/src/main/java/org/openremote/model/flow/Slot.javanew file mode 100644index 000000000..1908b3150--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/Slot.java@@ -0,0 +1,132 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import com.fasterxml.jackson.annotation.JsonIgnore;+import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;++import javax.persistence.*;++@JsType+@Entity+@Table(name = "SLOT")+public class Slot extends FlowObject {++ public static final String TYPE_SINK = "urn:openremote:flow:slot:sink";+ public static final String TYPE_SOURCE = "urn:openremote:flow:slot:source";++ @ManyToOne(fetch = FetchType.LAZY)+ @JoinColumn(name = "NODE_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_SLOT_NODE_ID"))+ @org.hibernate.annotations.OnDelete(+ action = org.hibernate.annotations.OnDeleteAction.CASCADE+ )+ @JsIgnore+ @JsonIgnore+ public Node node;++ @Column(name = "CONNECTABLE", nullable = false)+ public boolean connectable = true;++ @Column(name = "PEER_ID")+ public String peerId;++ @Column(name = "PROPERTY_PATH")+ public String propertyPath;++ @JsIgnore+ protected Slot() {+ }++ @JsIgnore+ public Slot(String id, String type) {+ super(null, id, type);+ }++ @JsIgnore+ public Slot(String label, String id, String type) {+ this(label, id, type, null);+ }++ @JsIgnore+ public Slot(String label, String id, String type, String propertyPath) {+ this(label, id, type, true, null, propertyPath);+ }++ @JsIgnore+ public Slot(String id, String type, boolean connectable) {+ this(null, id, type, connectable);+ }++ @JsIgnore+ public Slot(String label, String id, String type, boolean connectable) {+ this(label, id, type, connectable, null, null);+ }++ @JsIgnore+ public Slot(String id, Slot peer, String label) {+ this(label, id, peer.getType(), true, peer.getId(), null);+ }++ @JsIgnore+ public Slot(String label, String id, String type, boolean connectable, String peerId, String propertyPath) {+ super(label, id, type);+ this.connectable = connectable;+ this.peerId = peerId;+ this.propertyPath = propertyPath;+ }++ public boolean isConnectable() {+ return connectable;+ }++ public void setConnectable(boolean connectable) {+ this.connectable = connectable;+ }++ public String getPeerId() {+ return peerId;+ }++ public void setPeerId(String peerId) {+ this.peerId = peerId;+ }++ public String getPropertyPath() {+ return propertyPath;+ }++ public void setPropertyPath(String propertyPath) {+ this.propertyPath = propertyPath;+ }++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "label='" + getLabel() + '\'' ++ ", id=" + getId() ++ ", type=" + getType() ++ ", connectable=" + isConnectable() ++ ", peerId=" + getPeerId() ++ ", propertyPath=" + getPropertyPath() ++ '}';+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/Wire.java b/model/src/main/java/org/openremote/model/flow/Wire.javanew file mode 100644index 000000000..27339e85b--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/Wire.java@@ -0,0 +1,150 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow;++import com.fasterxml.jackson.annotation.JsonIgnore;+import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;++import javax.persistence.Column;+import javax.persistence.Entity;+import javax.persistence.IdClass;+import javax.persistence.Table;+import javax.validation.constraints.NotNull;+import java.io.Serializable;++@JsType+@IdClass(Wire.Id.class)+@Entity+@Table(name = "WIRE")+public class Wire {++ public static class Id implements Serializable {++ public String sourceId;+ public String sinkId;+ public String flowId;++ public Id() {+ }++ public Id(String sourceId, String sinkId) {+ this.sourceId = sourceId;+ this.sinkId = sinkId;+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;++ Id id = (Id) o;++ if (sourceId != null ? !sourceId.equals(id.sourceId) : id.sourceId != null) return false;+ if (sinkId != null ? !sinkId.equals(id.sinkId) : id.sinkId != null) return false;+ return !(flowId != null ? !flowId.equals(id.flowId) : id.flowId != null);++ }++ @Override+ public int hashCode() {+ int result = sourceId != null ? sourceId.hashCode() : 0;+ result = 31 * result + (sinkId != null ? sinkId.hashCode() : 0);+ result = 31 * result + (flowId != null ? flowId.hashCode() : 0);+ return result;+ }+ }++ @javax.persistence.Id+ @NotNull+ @Column(name = "SOURCE_NODE_ID")+ public String sourceId;++ @javax.persistence.Id+ @NotNull+ @Column(name = "SINK_NODE_ID")+ public String sinkId;++ @javax.persistence.Id+ @NotNull+ @Column(name = "FLOW_ID")+ @JsIgnore+ @JsonIgnore+ public String flowId;++ @JsIgnore+ protected Wire() {+ }++ @JsIgnore+ public Wire(Slot source, Slot sink) {+ this(source.getId(), sink.getId());+ }++ @JsIgnore+ public Wire(String sourceId, String sinkId) {+ this.sourceId = sourceId;+ this.sinkId = sinkId;+ }++ public String getSourceId() {+ return sourceId;+ }++ public String getSinkId() {+ return sinkId;+ }++ public boolean equalsSlots(Slot sourceSlot, Slot sinkSlot) {+ return !(sourceSlot == null || sinkSlot == null)+ && equalsSlotIds(sourceSlot.getId(), sinkSlot.getId());+ }++ public boolean equalsSlotIds(String sourceId, String sinkId) {+ return getSourceId().equals(sourceId) && getSinkId().equals(sinkId);+ }++ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;++ Wire wire = (Wire) o;++ if (sourceId != null ? !sourceId.equals(wire.sourceId) : wire.sourceId != null) return false;+ return !(sinkId != null ? !sinkId.equals(wire.sinkId) : wire.sinkId != null);+ }++ @Override+ public int hashCode() {+ int result = sourceId != null ? sourceId.hashCode() : 0;+ result = 31 * result + (sinkId != null ? sinkId.hashCode() : 0);+ return result;+ }++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "sourceId='" + sourceId + '\'' ++ ", sinkId='" + sinkId + '\'' ++ '}';+ }+}\ No newline at end of filediff --git a/model/src/main/java/org/openremote/model/flow/catalog/AssetNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/AssetNodeDescriptor.javanew file mode 100644index 000000000..0af21ffa3--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/AssetNodeDescriptor.java@@ -0,0 +1,79 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.flow.catalog;++import org.openremote.model.flow.Node;+import org.openremote.model.flow.NodeColor;+import org.openremote.model.flow.Slot;+import org.openremote.model.flow.catalog.CatalogCategory;+import org.openremote.model.flow.catalog.NodeDescriptor;++import java.util.List;+import java.util.function.Supplier;++public class AssetNodeDescriptor extends NodeDescriptor {++ public static final String TYPE = "urn:openremote:flow:node:asset";+ public static final String TYPE_LABEL = "Asset";++ @Override+ public CatalogCategory getCatalogCategory() {+ return null;+ }++ @Override+ public String getType() {+ return TYPE;+ }++ @Override+ public String getTypeLabel() {+ return TYPE_LABEL;+ }++ @Override+ public NodeColor getColor() {+ return NodeColor.ASSET;+ }++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientAccess(true);+ return node;+ }++ @Override+ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ super.addSlots(slots, idGenerator);+ slots.add(new Slot(idGenerator.get(), Slot.TYPE_SOURCE));+ }++ @Override+ protected void addPersistentPropertyPaths(List<String> propertyPaths) {+ super.addPersistentPropertyPaths(propertyPaths);+ }++ @Override+ public void addEditorComponents(List<String> editorComponents) {+ super.addEditorComponents(editorComponents);+ editorComponents.add("or-node-editor-asset");+ }+}\ No newline at end of filediff --git a/model/src/main/java/org/openremote/model/flow/catalog/CatalogCategory.java b/model/src/main/java/org/openremote/model/flow/catalog/CatalogCategory.javanew file mode 100644index 000000000..78e951874--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/CatalogCategory.java@@ -0,0 +1,48 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog;++import jsinterop.annotations.JsType;++@JsType+public enum CatalogCategory {++ WIDGETS("Widgets"),+ WIRING("Flow Wiring"),+ PROCESSORS("Processors");++ final public String label;++ CatalogCategory(String label) {+ this.label = label;+ }++ public String getLabel() {+ return label;+ }++ @Override+ public String toString() {+ return "CatalogCategory{" ++ "label='" + label + '\'' ++ "} " + super.toString();+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/CatalogItem.java b/model/src/main/java/org/openremote/model/flow/catalog/CatalogItem.javanew file mode 100644index 000000000..cb9a28ae2--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/CatalogItem.java@@ -0,0 +1,91 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog;++import jsinterop.annotations.JsIgnore;+import jsinterop.annotations.JsType;+import org.openremote.model.flow.NodeColor;++@JsType+public class CatalogItem {++ public String label;++ public CatalogCategory category;++ public String nodeType;++ public NodeColor nodeColor;++ @JsIgnore+ protected CatalogItem() {+ }++ @JsIgnore+ public CatalogItem(String label, CatalogCategory category, String nodeType, NodeColor nodeColor) {+ this.label = label;+ this.category = category;+ this.nodeType = nodeType;+ this.nodeColor = nodeColor;+ }++ public String getLabel() {+ return label;+ }++ public void setLabel(String label) {+ this.label = label;+ }++ public CatalogCategory getCategory() {+ return category;+ }++ public void setCategory(CatalogCategory category) {+ this.category = category;+ }++ public String getNodeType() {+ return nodeType;+ }++ public void setNodeType(String nodeType) {+ this.nodeType = nodeType;+ }++ public NodeColor getNodeColor() {+ return nodeColor;+ }++ public void setNodeColor(NodeColor nodeColor) {+ this.nodeColor = nodeColor;+ }++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "label='" + label + '\'' ++ ", category=" + category ++ ", nodeType=" + nodeType ++ '}';+ }++}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/ConsoleNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/ConsoleNodeDescriptor.javanew file mode 100644index 000000000..5e202797b--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/ConsoleNodeDescriptor.java@@ -0,0 +1,43 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog;+++import org.openremote.model.flow.Node;+import org.openremote.model.flow.NodeColor;+import org.openremote.model.flow.catalog.NodeDescriptor;++import java.util.function.Supplier;++public abstract class ConsoleNodeDescriptor extends NodeDescriptor {++ @Override+ public NodeColor getColor() {+ return NodeColor.CONSOLE;+ }++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientAccess(true);+ return node;+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/NodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/NodeDescriptor.javanew file mode 100644index 000000000..2fbd9b7b4--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/NodeDescriptor.java@@ -0,0 +1,110 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog;++import org.openremote.model.flow.Node;+import org.openremote.model.flow.NodeColor;+import org.openremote.model.flow.Slot;+import org.openremote.model.value.ObjectValue;+import org.openremote.model.value.Values;++import java.util.ArrayList;+import java.util.List;+import java.util.function.Supplier;+++public abstract class NodeDescriptor {++ abstract public String getType();++ abstract public String getTypeLabel();++ public CatalogCategory getCatalogCategory() {+ return CatalogCategory.PROCESSORS;+ }++ public NodeColor getColor() {+ return NodeColor.DEFAULT;+ }++ public Node initialize(Node node, Supplier<String> idGenerator) {++ List<Slot> slots = new ArrayList<>();+ addSlots(slots, idGenerator);+ node.setSlots(slots.toArray(new Slot[slots.size()]));++ node.getEditorSettings().setTypeLabel(getTypeLabel());+ node.getEditorSettings().setNodeColor(getColor());++ List<String> editorComponents = new ArrayList<>();+ addEditorComponents(editorComponents);+ node.getEditorSettings().setComponents(editorComponents.toArray(new String[editorComponents.size()]));++ ObjectValue initialProperties = getInitialProperties();+ try {+ if (initialProperties != null) {+ node.setProperties(initialProperties.toJson());+ } else {+ ObjectValue properties = Values.createObject();+ configureInitialProperties(properties);+ if (properties.hasKeys()) {+ node.setProperties(properties.toJson());+ }+ }+ } catch (Exception ex) {+ throw new RuntimeException("Error writing initial properties of: " + getType(), ex);+ }++ List<String> persistentPaths = new ArrayList<>();+ addPersistentPropertyPaths(persistentPaths);+ if (persistentPaths.size() > 0) {+ node.setPersistentPropertyPaths(persistentPaths.toArray(new String[persistentPaths.size()]));+ }++ return node;+ }++ public List<String> getPersistentPropertyPaths() {+ List<String> persistentPaths = new ArrayList<>();+ addPersistentPropertyPaths(persistentPaths);+ return persistentPaths;+ }++ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ // Subclass+ }++ public void addEditorComponents(List<String> editorComponents) {+ // Subclass+ }++ protected void configureInitialProperties(ObjectValue properties) {+ // Subclass+ }++ protected void addPersistentPropertyPaths(List<String> propertyPaths) {+ // Subclass+ }++ protected ObjectValue getInitialProperties() {+ return null;+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/WidgetNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/WidgetNodeDescriptor.javanew file mode 100644index 000000000..a501c6f51--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/WidgetNodeDescriptor.java@@ -0,0 +1,98 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog;+++import org.openremote.model.flow.Node;+import org.openremote.model.flow.Slot;+import org.openremote.model.flow.catalog.CatalogCategory;+import org.openremote.model.flow.catalog.ConsoleNodeDescriptor;+import org.openremote.model.value.ObjectValue;+import org.openremote.model.value.Values;++import java.util.Arrays;+import java.util.List;+import java.util.function.Supplier;++/**+ * TODO Deploy this as a JSON file + some HTML files to create a widget+ */+public abstract class WidgetNodeDescriptor extends ConsoleNodeDescriptor {++ public static final String PROPERTY_COMPONENT = "component";+ public static final String WIDGET_EDITOR_COMPONENT = "or-node-editor-widget";++ public static final ObjectValue WIDGET_INITIAL_PROPERTIES = Values.createObject()+ .put("positionX", 25)+ .put("positionY", 25)+ .put("positionZ", 0)+ .put("opacity", 1.0);++ public static final String[] WIDGET_PERSISTENT_PROPERTY_PATHS = new String[]{+ "component",+ "positionX",+ "positionY",+ "positionZ",+ "opacity"+ };++ @Override+ public CatalogCategory getCatalogCategory() {+ return CatalogCategory.WIDGETS;+ }++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientWidget(true);+ return node;+ }++ @Override+ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ super.addSlots(slots, idGenerator);+ slots.add(new Slot("Position X", idGenerator.get(), Slot.TYPE_SINK, "positionX"));+ slots.add(new Slot("Position Y", idGenerator.get(), Slot.TYPE_SINK, "positionY"));+ slots.add(new Slot("Position Z", idGenerator.get(), Slot.TYPE_SINK, "positionZ"));+ slots.add(new Slot("Opacity", idGenerator.get(), Slot.TYPE_SINK, "opacity"));+ slots.add(new Slot("Position X", idGenerator.get(), Slot.TYPE_SOURCE, "positionX"));+ slots.add(new Slot("Position Y", idGenerator.get(), Slot.TYPE_SOURCE, "positionY"));+ slots.add(new Slot("Position Z", idGenerator.get(), Slot.TYPE_SOURCE, "positionZ"));+ slots.add(new Slot("Opacity", idGenerator.get(), Slot.TYPE_SOURCE, "opacity"));+ }++ @Override+ public void addEditorComponents(List<String> editorComponents) {+ super.addEditorComponents(editorComponents);+ editorComponents.add(WIDGET_EDITOR_COMPONENT);+ }++ @Override+ protected ObjectValue getInitialProperties() {+ return WIDGET_INITIAL_PROPERTIES;+ }++ @Override+ protected void addPersistentPropertyPaths(List<String> propertyPaths) {+ super.addPersistentPropertyPaths(propertyPaths);+ propertyPaths.addAll(Arrays.asList(WIDGET_PERSISTENT_PROPERTY_PATHS));+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/console/ScreenNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/console/ScreenNodeDescriptor.javanew file mode 100644index 000000000..a38e34620--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/console/ScreenNodeDescriptor.java@@ -0,0 +1,93 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.flow.catalog.console;++import org.openremote.model.flow.Node;+import org.openremote.model.flow.Slot;+import org.openremote.model.flow.catalog.CatalogCategory;+import org.openremote.model.flow.catalog.ConsoleNodeDescriptor;+import org.openremote.model.flow.catalog.WidgetNodeDescriptor;+import org.openremote.model.value.ObjectValue;+import org.openremote.model.value.Values;++import java.util.List;+import java.util.function.Supplier;++public class ScreenNodeDescriptor extends ConsoleNodeDescriptor {++ public static final String TYPE = "urn:openremote:widget:screen";+ public static final String TYPE_LABEL = "Screen";++ public static final String WIDGET_COMPONENT = "or-console-widget-screen";+ public static final String EDITOR_COMPONENT = "or-node-editor-screen";++ public static final ObjectValue SCREEN_INITIAL_PROPERTIES = Values.createObject()+ .put(WidgetNodeDescriptor.PROPERTY_COMPONENT, WIDGET_COMPONENT)+ .put("backgroundColor", "#aaa")+ .put("textColor", "white");++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientWidget(true);+ return node;+ }++ @Override+ public CatalogCategory getCatalogCategory() {+ return CatalogCategory.WIDGETS;+ }++ @Override+ public String getType() {+ return TYPE;+ }++ @Override+ public String getTypeLabel() {+ return TYPE_LABEL;+ }++ @Override+ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ slots.add(new Slot("Background Color", idGenerator.get(), Slot.TYPE_SINK, "backgroundColor"));+ slots.add(new Slot("Text Color", idGenerator.get(), Slot.TYPE_SINK, "textColor"));+ super.addSlots(slots, idGenerator);+ }++ @Override+ public void addEditorComponents(List<String> editorComponents) {+ super.addEditorComponents(editorComponents);+ editorComponents.add(EDITOR_COMPONENT);+ }++ @Override+ protected ObjectValue getInitialProperties() {+ return SCREEN_INITIAL_PROPERTIES;+ }++ @Override+ protected void addPersistentPropertyPaths(List<String> propertyPaths) {+ super.addPersistentPropertyPaths(propertyPaths);+ propertyPaths.add(WidgetNodeDescriptor.PROPERTY_COMPONENT);+ propertyPaths.add("backgroundColor");+ propertyPaths.add("textColor");+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/console/TextLabelNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/console/TextLabelNodeDescriptor.javanew file mode 100644index 000000000..b399f7418--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/console/TextLabelNodeDescriptor.java@@ -0,0 +1,80 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog.console;++import org.openremote.model.flow.Slot;+import org.openremote.model.flow.catalog.WidgetNodeDescriptor;+import org.openremote.model.value.ObjectValue;++import java.util.List;+import java.util.function.Supplier;++public class TextLabelNodeDescriptor extends WidgetNodeDescriptor {++ public static final String TYPE = "urn:openremote:widget:textlabel";+ public static final String TYPE_LABEL = "Text Label";++ public static final String COMPONENT = "or-console-widget-textlabel";++ public static final ObjectValue TEXT_LABEL_INITIAL_PROPERTIES = WIDGET_INITIAL_PROPERTIES.deepCopy()+ .put(PROPERTY_COMPONENT, COMPONENT)+ .put("emptyValue", "(EMPTY LABEL)")+ .put("fontSizePixels", 15)+ .put("textColor", "#ddd");++ @Override+ public String getType() {+ return TYPE;+ }++ @Override+ public String getTypeLabel() {+ return TYPE_LABEL;+ }++ @Override+ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ slots.add(new Slot("Text", idGenerator.get(), Slot.TYPE_SINK, "text"));+ slots.add(new Slot("Text", idGenerator.get(), Slot.TYPE_SOURCE, "text"));+ slots.add(new Slot("Color", idGenerator.get(), Slot.TYPE_SINK, "textColor"));+ slots.add(new Slot("Font Size", idGenerator.get(), Slot.TYPE_SINK, "fontSizePixels"));+ super.addSlots(slots, idGenerator);+ }++ @Override+ public void addEditorComponents(List<String> editorComponents) {+ super.addEditorComponents(editorComponents);+ editorComponents.add("or-node-editor-textlabel");+ }++ @Override+ protected ObjectValue getInitialProperties() {+ return TEXT_LABEL_INITIAL_PROPERTIES;+ }++ @Override+ protected void addPersistentPropertyPaths(List<String> propertyPaths) {+ super.addPersistentPropertyPaths(propertyPaths);+ propertyPaths.add("emptyValue");+ propertyPaths.add("fontSizePixels");+ propertyPaths.add("textColor");+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/virtual/SubflowNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/virtual/SubflowNodeDescriptor.javanew file mode 100644index 000000000..b060ee7f7--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/virtual/SubflowNodeDescriptor.java@@ -0,0 +1,67 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.flow.catalog.virtual;++import org.openremote.model.flow.Node;+import org.openremote.model.flow.NodeColor;+import org.openremote.model.flow.catalog.CatalogCategory;+import org.openremote.model.flow.catalog.WidgetNodeDescriptor;+import org.openremote.model.value.ObjectValue;++import java.util.function.Supplier;++public class SubflowNodeDescriptor extends WidgetNodeDescriptor {++ public static final String WIDGET_COMPONENT = "or-console-widget-composite";++ @Override+ public NodeColor getColor() {+ return NodeColor.VIRTUAL;+ }++ @Override+ public CatalogCategory getCatalogCategory() {+ return null;+ }++ @Override+ public String getType() {+ return Node.TYPE_SUBFLOW;+ }++ @Override+ public String getTypeLabel() {+ return Node.TYPE_SUBFLOW_LABEL;+ }++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientAccess(true);+ return node;+ }++ @Override+ protected ObjectValue getInitialProperties() {+ return WIDGET_INITIAL_PROPERTIES.deepCopy()+ .put(PROPERTY_COMPONENT, WIDGET_COMPONENT);+ }++}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualConsumerNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualConsumerNodeDescriptor.javanew file mode 100644index 000000000..3368b1209--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualConsumerNodeDescriptor.java@@ -0,0 +1,53 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.flow.catalog.virtual;++import org.openremote.model.flow.Node;+import org.openremote.model.flow.Slot;++import java.util.List;+import java.util.function.Supplier;++public class VirtualConsumerNodeDescriptor extends VirtualNodeDescriptor {++ @Override+ public String getType() {+ return Node.TYPE_CONSUMER;+ }++ @Override+ public String getTypeLabel() {+ return Node.TYPE_CONSUMER_LABEL;+ }++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientAccess(true);+ return node;+ }++ @Override+ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ super.addSlots(slots, idGenerator);+ slots.add(new Slot(idGenerator.get(), Slot.TYPE_SINK, false));+ slots.add(new Slot(idGenerator.get(), Slot.TYPE_SOURCE));+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualNodeDescriptor.javanew file mode 100644index 000000000..9989eb2ea--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualNodeDescriptor.java@@ -0,0 +1,39 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */++package org.openremote.model.flow.catalog.virtual;+++import org.openremote.model.flow.NodeColor;+import org.openremote.model.flow.catalog.CatalogCategory;+import org.openremote.model.flow.catalog.NodeDescriptor;++public abstract class VirtualNodeDescriptor extends NodeDescriptor {++ @Override+ public NodeColor getColor() {+ return NodeColor.VIRTUAL;+ }++ @Override+ public CatalogCategory getCatalogCategory() {+ return CatalogCategory.WIRING;+ }+}diff --git a/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualProducerNodeDescriptor.java b/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualProducerNodeDescriptor.javanew file mode 100644index 000000000..299d60686--- /dev/null+++ b/model/src/main/java/org/openremote/model/flow/catalog/virtual/VirtualProducerNodeDescriptor.java@@ -0,0 +1,53 @@+/*+ * Copyright 2015, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.model.flow.catalog.virtual;++import org.openremote.model.flow.Node;+import org.openremote.model.flow.Slot;++import java.util.List;+import java.util.function.Supplier;++public class VirtualProducerNodeDescriptor extends VirtualNodeDescriptor {++ @Override+ public String getType() {+ return Node.TYPE_PRODUCER;+ }++ @Override+ public String getTypeLabel() {+ return Node.TYPE_PRODUCER_LABEL;+ }++ @Override+ public Node initialize(Node node, Supplier<String> idGenerator) {+ node = super.initialize(node, idGenerator);+ node.setClientAccess(true);+ return node;+ }++ @Override+ public void addSlots(List<Slot> slots, Supplier<String> idGenerator) {+ super.addSlots(slots, idGenerator);+ slots.add(new Slot(idGenerator.get(), Slot.TYPE_SINK));+ slots.add(new Slot(idGenerator.get(), Slot.TYPE_SOURCE, false));+ }+}diff --git a/model/src/main/java/org/openremote/model/value/ObjectValue.java b/model/src/main/java/org/openremote/model/value/ObjectValue.javaindex 69abac59b..92ee11632 100644--- a/model/src/main/java/org/openremote/model/value/ObjectValue.java+++ b/model/src/main/java/org/openremote/model/value/ObjectValue.java@@ -60,6 +60,8 @@ public interface ObjectValue extends Value {boolean hasKey(String key);+ boolean hasKeys();+ObjectValue put(String key, Value value);ObjectValue put(String key, String value);diff --git a/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.java b/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.javaindex abf700069..397ae7623 100644--- a/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.java+++ b/model/src/main/java/org/openremote/model/value/impl/ObjectValueImpl.java@@ -95,6 +95,11 @@ public class ObjectValueImpl extends ValueImpl implements ObjectValue {return map.containsKey(key);}+ @Override+ public boolean hasKeys() {+ return !map.isEmpty();+ }+@Overridepublic ObjectValue put(String key, Value value) {if (value == null) {