Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Removed connectors, simplified asset attribute metadata

Christian Bauercb3741ff7445
diff --git a/README.md b/README.md
index 336ef62c8..cac8d757c 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Join us on the [community group](https://groups.google.com/forum/#!forum/openrem
## OpenRemote Projects
-* [Agent](https://github.com/openremote/openremote/agent) - Connects sensors and actuators to an IoT network and provides intelligence at the edge of the network. Co-locate agents with backend services or install on gateways, close to devices.
+* [Agent](https://github.com/openremote/openremote/agent) - Connects sensors and actuators to an IoT network and provides intelligence at the edge of the network. Co-locate agents with backend services or install agents on gateways, close to devices.
* [Manager](https://github.com/openremote/openremote/manager) - Provides IoT backend services and a web-based operations frontend and management application for agents and domain assets. Design custom data flow, rules, notifications, and build end-user interfaces.
diff --git a/container/src/main/java/org/openremote/container/util/MapAccess.java b/container/src/main/java/org/openremote/container/util/MapAccess.java
index d7d4be955..0eaf62d3f 100644
--- a/container/src/main/java/org/openremote/container/util/MapAccess.java
+++ b/container/src/main/java/org/openremote/container/util/MapAccess.java
@@ -22,16 +22,10 @@ package org.openremote.container.util;
import java.util.Map;
/**
- * Adds convenience getters to HashMap.
+ * Convenience functions for accessing {@link Map}.
*/
public class MapAccess {
- static public void putIfEmpty(Map<String, String> map, String variable, String value) {
- if (!map.containsKey(variable)) {
- map.put(variable, value);
- }
- }
-
static public String getString(Map<String, String> map, String key, String defaultValue) {
return map.containsKey(key) ? map.get(key) : defaultValue;
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
index fa1247f45..9275b3a14 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
@@ -118,7 +118,7 @@ public class AgentAttributesEditor extends AttributesEditor<AttributesEditor.Sty
}
container.getFormView().setFormBusy(false);
- refresh();
+ clearBuild();
});
}
@@ -138,6 +138,7 @@ public class AgentAttributesEditor extends AttributesEditor<AttributesEditor.Sty
return formLabel;
}
+ /* TODO
@Override
protected String getDescription(Attribute attribute) {
String description = super.getDescription(attribute);
@@ -146,6 +147,7 @@ public class AgentAttributesEditor extends AttributesEditor<AttributesEditor.Sty
}
return description;
}
+ */
@Override
public void buildAttributeFormGroups() {
@@ -155,10 +157,10 @@ public class AgentAttributesEditor extends AttributesEditor<AttributesEditor.Sty
}
@Override
- public void buildAndRender() {
+ public void build() {
container.getPanel().add(connectorDropDownGroup);
container.getPanel().add(actionsGroup);
- super.buildAndRender();
+ super.build();
}
@Override
@@ -200,7 +202,7 @@ public class AgentAttributesEditor extends AttributesEditor<AttributesEditor.Sty
agent.removeConnectorType();
refreshInventoryButton.setEnabled(false);
}
- refresh();
+ clearBuild();
}
protected void loadConnectors(Consumer<Connector[]> onSuccess) {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
index b7ebc587a..33c014aec 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
@@ -202,7 +202,7 @@ public class AssetActivity
public void onMapClicked(double lng, double lat) {
selectedCoordinates = new double[]{lng, lat};
view.showMapPopup(lng, lat, environment.getMessages().selectedLocation());
- view.setLocation(getLocation(selectedCoordinates));
+ view.setLocation(selectedCoordinates);
}
@Override
@@ -340,7 +340,7 @@ public class AssetActivity
view.setName(asset.getName());
view.setRealm(asset.getRealm());
view.setCreatedOn(asset.getCreatedOn());
- view.setLocation(getLocation(asset.getCoordinates()));
+ view.setLocation(asset.getCoordinates());
if (asset != null && asset.getId() != null) {
view.showFeaturesSelection(getFeature(asset));
view.flyTo(asset.getCoordinates());
@@ -395,6 +395,7 @@ public class AssetActivity
);
}
view.setAttributesEditor(attributesEditor);
+ attributesEditor.build();
}
protected void readFromView() {
@@ -424,11 +425,4 @@ public class AssetActivity
// TODO: Validation
}
- protected String getLocation(double[] coordinates) {
- if (coordinates != null && coordinates.length == 2) {
- return coordinates[0] + " " + coordinates[1];
- }
- return null;
- }
-
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
index 3f009af51..72ac18246 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
@@ -72,7 +72,7 @@ public interface AssetView extends AssetBrowsingView<AssetView.Presenter>, FormV
boolean isMapInitialised();
- void setLocation(String location);
+ void setLocation(double[] coordinates);
void refreshMap();
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
index 98ceae696..78d683149 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
@@ -40,6 +40,8 @@ import org.openremote.manager.shared.asset.AssetType;
import org.openremote.manager.shared.map.GeoJSON;
import javax.inject.Inject;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -290,9 +292,17 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
}
@Override
- public void setLocation(String location) {
- locationLabel.setText(location != null ? location : managerMessages.selectLocation());
- centerMapButton.setEnabled(location != null);
+ public void setLocation(double[] coordinates) {
+ if (coordinates != null && coordinates.length == 2) {
+ // TODO: This assumes 0 is Lng and 1 is Lat, which is true for PostGIS backend
+ // TODO: Because Lat/Lng is the 'right way', we flip it here for display
+ // TODO: Rounding to 5 decimals gives us precision of about 1 meter, should be enough
+ locationLabel.setText(round(coordinates[1], 5) + " " + round(coordinates[0], 5) + " Lat|Lng");
+ centerMapButton.setEnabled(true);
+ } else {
+ locationLabel.setText(managerMessages.selectLocation());
+ centerMapButton.setEnabled(false);
+ }
}
@Override
@@ -474,7 +484,6 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
public void setAttributesEditor(AttributesEditor editor) {
this.attributesEditor = editor;
attributesEditorContainer.clear();
- editor.buildAndRender();
}
/* ############################################################################ */
@@ -524,4 +533,8 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
attributesEditor.setOpaque(opaque);
submitButtonGroup.setOpaque(opaque);
}
+
+ protected String round(double d, int places) {
+ return new BigDecimal(d).setScale(places, RoundingMode.HALF_UP).toString();
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
index cb218b513..50b0dba33 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
@@ -97,9 +97,9 @@ public class DeviceAttributesEditor extends AttributesEditor<DeviceAttributesEdi
}
@Override
- public void buildAndRender() {
+ public void build() {
container.getPanel().add(deviceActionsGroup);
- super.buildAndRender();
+ super.build();
}
@Override
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
index 44ecafd84..2a5ae23cc 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
@@ -28,11 +28,13 @@ import org.openremote.manager.shared.Runnable;
import org.openremote.manager.shared.attribute.Attribute;
import org.openremote.manager.shared.attribute.AttributeType;
import org.openremote.manager.shared.attribute.Attributes;
-import org.openremote.manager.shared.attribute.MetadataElement;
+import org.openremote.manager.shared.attribute.MetadataItem;
import java.util.*;
import java.util.logging.Logger;
+import static org.openremote.manager.shared.asset.AssetAttributeMeta.*;
+
public class AttributesEditor<S extends AttributesEditor.Style> {
private static final Logger LOG = Logger.getLogger(AttributesEditor.class.getName());
@@ -112,7 +114,7 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
}
*/
- public void buildAndRender() {
+ public void build() {
formGroups.clear();
buildAttributeFormGroups();
for (FormGroup formGroup : formGroups.values()) {
@@ -120,9 +122,11 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
}
}
- public void refresh() {
- clearContainer();
- buildAndRender();
+ public void clearBuild() {
+ while (container.getPanel().getWidgetCount() > 0) {
+ container.getPanel().remove(0);
+ }
+ build();
}
public void setOpaque(boolean opaque) {
@@ -137,12 +141,6 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
/* ####################################################################### */
- protected void clearContainer() {
- while (container.getPanel().getWidgetCount() > 0) {
- container.getPanel().remove(0);
- }
- }
-
protected FormGroup createFormGroup(Attribute attribute) {
FormGroup formGroup = new FormGroup();
@@ -167,9 +165,9 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
);
}
- String description = getDescription(attribute);
+ MetadataItem description = getFirstMetadataItem(attribute, DESCRIPTION);
if (description != null) {
- formGroup.addInfolabel(new Label(description));
+ formGroup.addInfolabel(new Label(description.getValue().asString()));
}
return formGroup;
@@ -178,11 +176,9 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
protected FormLabel buildFormLabel(Attribute attribute) {
FormLabel formLabel = new FormLabel();
String label = attribute.getName();
- if (attribute.hasMetadataElement("label")) {
- MetadataElement metadataLabel = attribute.getMetadata().getElement("label");
- if (metadataLabel.getType().equals(AttributeType.STRING.getValue())) {
- label = metadataLabel.getValue().asString();
- }
+ MetadataItem labelItem = getFirstMetadataItem(attribute, LABEL);
+ if (labelItem != null) {
+ label = labelItem.getValue().asString();
}
formLabel.setText(TextUtil.ellipsize(label, 30));
formLabel.addStyleName("larger");
@@ -195,10 +191,10 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
protected FormInputText createStringEditor(S style, Attribute attribute, boolean readOnly) {
FormInputText input = createFormInputText(style.attributeStringEditor());
- MetadataElement defaultValue;
+ MetadataItem defaultValue;
if (attribute.getValue() != null) {
input.setValue(attribute.getValue().asString());
- } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ } else if ((defaultValue = getFirstMetadataItem(attribute, DEFAULT)) != null) {
input.setValue(defaultValue.getValue().asString());
}
@@ -217,10 +213,10 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
protected FormInputNumber createIntegerEditor(S style, Attribute attribute, boolean readOnly) {
FormInputNumber input = createFormInputNumber(style.attributeIntegerEditor());
- MetadataElement defaultValue;
+ MetadataItem defaultValue;
if (attribute.getValue() != null) {
input.setValue(attribute.getValue().asString());
- } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ } else if ((defaultValue = getFirstMetadataItem(attribute, DEFAULT)) != null) {
input.setValue(defaultValue.getValue().asString());
}
@@ -242,10 +238,10 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
protected FormInputText createFloatEditor(S style, Attribute attribute, boolean readOnly) {
FormInputText input = createFormInputText(style.attributeFloatEditor());
- MetadataElement defaultValue;
+ MetadataItem defaultValue;
if (attribute.getValue() != null) {
input.setValue(attribute.getValue().asString());
- } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ } else if ((defaultValue = getFirstMetadataItem(attribute, DEFAULT)) != null) {
input.setValue(defaultValue.getValue().asString());
}
@@ -268,10 +264,10 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
FormCheckBox input = createFormInputCheckBox(style.attributeBooleanEditor());
Boolean value = null;
- MetadataElement defaultValue;
+ MetadataItem defaultValue;
if (attribute.getValueAsBoolean() != null) {
value = attribute.getValueAsBoolean();
- } else if ((defaultValue = getDefaultValue(attribute)) != null) {
+ } else if ((defaultValue = getFirstMetadataItem(attribute, DEFAULT)) != null) {
defaultValue.getValue().asBoolean();
}
@@ -309,23 +305,6 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
/* ####################################################################### */
- protected String getDescription(Attribute attribute) {
- if (attribute.hasMetadataElement("description")) {
- MetadataElement metadataDescription = attribute.getMetadata().getElement("description");
- if (metadataDescription.getType().equals(AttributeType.STRING.getValue())) {
- return metadataDescription.getValue().asString();
- }
- }
- return null;
- }
-
- protected MetadataElement getDefaultValue(Attribute attribute) {
- if (attribute.hasMetadataElement("defaultValue")) {
- return attribute.getMetadata().getElement("defaultValue");
- }
- return null;
- }
-
protected boolean isDefaultReadOnly(Attribute attribute) {
return false;
}
diff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.html
index a4d72cad4..d1a61f6c3 100644
--- a/manager/client/src/main/webapp/css/style.html
+++ b/manager/client/src/main/webapp/css/style.html
@@ -135,7 +135,7 @@
}
.or-PushButtonIcon {
- margin-right: 0.4em;
+ margin: 0 0.4em;
}
.or-PushButton.or-PushButton-up-disabled {
diff --git a/manager/connector/controller2/build.gradle b/manager/connector/controller2/build.gradle
deleted file mode 100644
index 6a538c2aa..000000000
--- a/manager/connector/controller2/build.gradle
+++ /dev/null
@@ -1,10 +0,0 @@
-apply plugin: "java"
-
-dependencies {
-
- compile project(":container")
- compile project(":manager:shared")
-
- compile files("libs/orlibrary-0.3.1-SNAPSHOT.jar")
- compile files("libs/orentities-1.3.1-SNAPSHOT.jar")
-}
diff --git a/manager/connector/controller2/libs/orentities-1.3.1-SNAPSHOT-sources.jar b/manager/connector/controller2/libs/orentities-1.3.1-SNAPSHOT-sources.jar
deleted file mode 100644
index c7a305585..000000000
Binary files a/manager/connector/controller2/libs/orentities-1.3.1-SNAPSHOT-sources.jar and /dev/null differ
diff --git a/manager/connector/controller2/libs/orentities-1.3.1-SNAPSHOT.jar b/manager/connector/controller2/libs/orentities-1.3.1-SNAPSHOT.jar
deleted file mode 100644
index 9f9e1612a..000000000
Binary files a/manager/connector/controller2/libs/orentities-1.3.1-SNAPSHOT.jar and /dev/null differ
diff --git a/manager/connector/controller2/libs/orlibrary-0.3.1-SNAPSHOT-sources.jar b/manager/connector/controller2/libs/orlibrary-0.3.1-SNAPSHOT-sources.jar
deleted file mode 100644
index c2df2eeb6..000000000
Binary files a/manager/connector/controller2/libs/orlibrary-0.3.1-SNAPSHOT-sources.jar and /dev/null differ
diff --git a/manager/connector/controller2/libs/orlibrary-0.3.1-SNAPSHOT.jar b/manager/connector/controller2/libs/orlibrary-0.3.1-SNAPSHOT.jar
deleted file mode 100644
index 17d823b69..000000000
Binary files a/manager/connector/controller2/libs/orlibrary-0.3.1-SNAPSHOT.jar and /dev/null differ
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Adapter.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Adapter.java
deleted file mode 100644
index 46a485c4d..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Adapter.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.openremote.agent.controller2.model.ControllerState;
-import org.openremote.console.controller.Controller;
-import org.openremote.console.controller.ControllerConnectionStatus;
-import org.openremote.console.controller.auth.UserPasswordCredentials;
-import org.openremote.entities.controller.AsyncControllerCallback;
-import org.openremote.entities.controller.ControllerResponseCode;
-
-import java.net.URL;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Logger;
-
-public class Controller2Adapter {
-
- private static final Logger LOG = Logger.getLogger(Controller2Adapter.class.getName());
-
- final static protected long RECONNECT_DELAY_SECONDS = 5;
-
- final protected AtomicInteger referenceCount = new AtomicInteger(1);
-
- final protected URL url;
- final protected String username;
- final protected String password;
-
- final protected Controller controller;
- final protected ScheduledExecutorService connectionScheduler = Executors.newScheduledThreadPool(1);
- final protected AsyncControllerCallback<ControllerConnectionStatus> connectCallback;
-
- final protected ControllerState controllerState;
-
- protected volatile boolean connectionInProgress;
- protected volatile boolean forceDisconnect;
-
- public Controller2Adapter(URL url, String username, String password) {
- this(url, username, password, null);
- }
-
- public Controller2Adapter(URL url, String username, String password, Controller controller) {
- LOG.fine("Creating adapter: " + url);
- this.url = url;
- this.username = username;
- this.password = password;
-
- if (controller == null) {
- Controller.Builder cb = new Controller.Builder(url.toString());
- if (username != null && password != null) {
- cb.setCredentials(new UserPasswordCredentials(username, password));
- }
- // TODO: We poll the sensors of max. 25 devices per controller, 200 devices total!
- cb.setConnector(new Controller2HttpConnector(25, 200, 5000));
- controller = cb.build();
- }
- this.controller = controller;
- this.controllerState = new ControllerState(url.toString());
-
- connectCallback = new AsyncControllerCallback<ControllerConnectionStatus>() {
-
- @Override
- public void onFailure(ControllerResponseCode controllerResponseCode) {
- connectionInProgress = false;
- LOG.fine("Disconnected from the controller: " + url);
- LOG.fine("Disconnect reason: " + controllerResponseCode);
- if (!forceDisconnect) {
- doConnection(true);
- }
- }
-
- @Override
- public void onSuccess(ControllerConnectionStatus controllerConnectionStatus) {
- connectionInProgress = false;
- LOG.fine("Connected to the controller: " + url);
- if (!forceDisconnect) {
- // It is imperative that further initialization happens on a different thread: The
- // current thread is the HTTP client's worker thread and it can't be blocked if
- // you want to make further HTTP calls!
- connectionScheduler.schedule(() -> {
- getControllerState().initialize(Controller2Adapter.this.controller);
- }, 0, TimeUnit.SECONDS
- );
- }
- }
- };
-
- // Whenever a connection problem occurs the controller library will disconnect and call the connect
- // onFailure callback with a disconnected status; we then need to handle reconnection
- doConnection(false);
- }
-
- public int incrementReferenceCount() {
- return referenceCount.getAndIncrement();
- }
-
- public int decrementReferenceCount() {
- return referenceCount.decrementAndGet();
- }
-
- public URL getUrl() {
- return url;
- }
-
- public synchronized void close() {
- LOG.fine("Closing adapter: " + url);
- if (controller != null) {
- forceDisconnect = true;
- try {
- getControllerState().setInitialized(false);
- controller.disconnect();
- } catch (Exception ex) {
- LOG.warning("Ignoring error during adapter disconnect: " + ex);
- }
- }
- }
-
- public synchronized ControllerState getControllerState() {
- return controllerState;
- }
-
- protected void doConnection(boolean doDelay) {
- if (connectionInProgress || controller.isConnected()) {
- return;
- }
-
- connectionInProgress = true;
-
- // Push connection task onto separate thread to avoid blocking the caller when delaying reconnection
- connectionScheduler.schedule(
- () -> {
- LOG.fine("Connecting to controller: " + url);
- controller.connect(connectCallback);
- },
- doDelay ? RECONNECT_DELAY_SECONDS : 0L,
- TimeUnit.SECONDS
- );
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2AdapterManager.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2AdapterManager.java
deleted file mode 100644
index 5b32e5ee2..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2AdapterManager.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Lifecycle of a controller "session". The first endpoint in a route will open
- * the adapter. If all routes with endpoints are stopped, the adapter will be closed.
- */
-public interface Controller2AdapterManager {
-
- /**
- * This is a reference counting manager, one adapter for each adapter URL.
- */
- Controller2AdapterManager DEFAULT_MANAGER = new Controller2AdapterManager() {
- final protected List<Controller2Adapter> adapters = new ArrayList<>();
-
- @Override
- synchronized public Controller2Adapter openAdapter(URL url, String username, String password) {
- // If adapter exists, increment reference count and return
- for (Controller2Adapter adapter : adapters) {
- if (adapter.getUrl().equals(url)) {
- adapter.incrementReferenceCount();
- return adapter;
- }
- }
- Controller2Adapter adapter = new Controller2Adapter(url, username, password);
- adapters.add(adapter);
- return adapter;
- }
-
- @Override
- synchronized public void closeAdapter(Controller2Adapter adapter) {
- Iterator<Controller2Adapter> it = adapters.iterator();
- while (it.hasNext()) {
- Controller2Adapter next = it.next();
- if (next.getUrl().equals(adapter.getUrl())) {
- // Count references down, if zero, close and remove
- int referenceCount = adapter.decrementReferenceCount();
- if (referenceCount == 0) {
- adapter.close();
- it.remove();
- }
- break;
- }
- }
- }
- };
-
- Controller2Adapter openAdapter(URL url, String username, String password); // TODO: Add more options if needed
-
- void closeAdapter(Controller2Adapter adapter);
-}
\ No newline at end of file
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
deleted file mode 100644
index f9ebc7590..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.attribute.AttributeType;
-import org.openremote.manager.shared.attribute.Attributes;
-import org.openremote.manager.shared.connector.ConnectorComponent;
-import org.openremote.manager.shared.connector.ConnectorUtil;
-
-import java.net.URI;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-
-public class Controller2Component extends DefaultComponent implements ConnectorComponent {
-
- public static final String TYPE = "urn:openremote:connector:controller2";
- public static final String DISPLAY_NAME = "OpenRemote Controller";
- public static final String URI_SYNTAX = "'controller2://<IP or host name>:<port>/[discovery|inventory|read|write|listen/<deviceKey>][?username=username&password=secret&secure=true|false]";
- protected final Controller2AdapterManager adapterManager;
-
- public static final Attributes SETTINGS;
-
- static {
- SETTINGS = new Attributes();
- SETTINGS.put(ConnectorUtil.buildConnectorSetting(
- "host",
- AttributeType.STRING,
- "Host/IP Address",
- "The OR Controller network hostname or IP address",
- true
- ));
- SETTINGS.put(ConnectorUtil.buildConnectorSetting(
- "port",
- AttributeType.INTEGER,
- "Port",
- "The OR Controller network port number",
- true,
- "8688",
- null
- ));
- SETTINGS.put(ConnectorUtil.buildConnectorSetting(
- "username",
- AttributeType.STRING,
- "Username",
- "The OR Controller Username",
- false
- ));
- SETTINGS.put(ConnectorUtil.buildConnectorSetting(
- "password",
- AttributeType.STRING,
- "Password",
- "The OR Controller Password",
- false
- ));
- SETTINGS.put(ConnectorUtil.buildConnectorSetting(
- "secure",
- AttributeType.BOOLEAN,
- "Secure",
- "Use HTTPS",
- false
- ));
- }
-
- public Controller2Component(Controller2AdapterManager adapterManager) {
- this.adapterManager = adapterManager;
- }
-
- public Controller2Component() {
- this(Controller2AdapterManager.DEFAULT_MANAGER);
- }
-
- @Override
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- try {
- URI parsedUri = URI.create(uri);
-
- // TODO java.net.URI violates latest RFCs http://bugs.java.com/view_bug.do?bug_id=6587184
- if (parsedUri.getHost() == null)
- throw new IllegalArgumentException("Parsed host was empty, note that host names can not contain underscores");
-
- if (parsedUri.getPort() == -1)
- throw new IllegalArgumentException("Parsed port was empty");
-
- parameters.put("host", parsedUri.getHost());
- parameters.put("port", parsedUri.getPort());
-
- Path path = Paths.get(parsedUri.getPath());
-
- return new Controller2Endpoint(uri, this, adapterManager, path);
- } catch (Exception ex) {
- throw new IllegalArgumentException("Required URL in format of " + URI_SYNTAX, ex);
- }
- }
-
- @Override
- public String getType() {
- return TYPE;
- }
-
- @Override
- public String getDisplayName() {
- return DISPLAY_NAME;
- }
-
- @Override
- public Attributes getConnectorSettings() {
- return SETTINGS;
- }
-
- @Override
- public Collection<Capability> getConsumerCapabilities() {
- return Arrays.asList(
- Capability.inventory,
- Capability.listen
- );
- }
-
- @Override
- public Collection<Capability> getProducerCapabilities() {
- return Arrays.asList(
- Capability.discovery,
- Capability.inventory,
- Capability.read,
- Capability.write
- );
- }
-
- @Override
- public String buildConsumerEndpoint(Capability capability, String agentAssetId, Agent agent, String deviceKey) {
- String host = getAgentAttributeHost(agent.getAttributes());
- Integer port = getAgentAttributePort(agent.getAttributes());
- if (host == null || port == null) {
- throw new IllegalArgumentException("Host and port must be available in agent: " + agentAssetId);
- }
- String params = getEndpointParams(agent.getAttributes());
- switch (capability) {
- case inventory:
- return "controller2://" + host + ":" + port + "/inventory" + params;
- case listen:
- return "controller2://" + host + ":" + port + "/listen/" + deviceKey + params;
- }
- throw new UnsupportedOperationException("Can't build endpoint for capability: " + capability);
- }
-
- @Override
- public String buildProducerEndpoint(Capability capability, String agentAssetId, Agent agent) {
- String host = getAgentAttributeHost(agent.getAttributes());
- Integer port = getAgentAttributePort(agent.getAttributes());
- if (host == null || port == null) {
- throw new IllegalArgumentException("Host and port must be available in agent: " + agentAssetId);
- }
- String params = getEndpointParams(agent.getAttributes());
- switch (capability) {
- case discovery:
- return "controller2://" + host + ":" + port + "/discovery" + params;
- case inventory:
- return "controller2://" + host + ":" + port + "/inventory" + params;
- case read:
- return "controller2://" + host + ":" + port + "/read" + params;
- case write:
- return "controller2://" + host + ":" + port + "/write" + params;
- }
- throw new UnsupportedOperationException("Can't build endpoint for capability: " + capability);
- }
-
- protected String getAgentAttributeHost(Attributes agentAttributes) {
- return agentAttributes.hasAttribute("host") ? agentAttributes.get("host").getValueAsString() : null;
- }
-
- protected Integer getAgentAttributePort(Attributes agentAttributes) {
- return agentAttributes.hasAttribute("port") ? agentAttributes.get("port").getValueAsDouble().intValue() : null;
- }
-
- protected String getEndpointParams(Attributes agentAttributes) {
- Boolean secure = agentAttributes.hasAttribute("secure") ? agentAttributes.get("secure").getValueAsBoolean() : null;
- String username = agentAttributes.hasAttribute("username") ? agentAttributes.get("username").getValueAsString() : null;
- String password = agentAttributes.hasAttribute("password") ? agentAttributes.get("password").getValueAsString() : null;
- List<String> params = new ArrayList<>();
- if (secure != null)
- params.add("secure=" + secure);
- if (username != null)
- params.add("username=" + username);
- if (password != null)
- params.add("password=" + password);
- StringBuilder sb = new StringBuilder();
- if (params.size() > 0)
- sb.append("?");
- for (String param : params) {
- sb.append(param).append("&");
- }
- if (sb.length() > 1)
- sb.deleteCharAt(sb.length() - 1);
- return sb.toString();
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Consumer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Consumer.java
deleted file mode 100644
index 0cf762103..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Consumer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.util.URISupport;
-
-public class Controller2Consumer extends DefaultConsumer {
-
- public Controller2Consumer(Controller2Endpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
-
- @Override
- public Controller2Endpoint getEndpoint() {
- return (Controller2Endpoint) super.getEndpoint();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2DiscoveryProducer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2DiscoveryProducer.java
deleted file mode 100644
index a20118aa6..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2DiscoveryProducer.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.URISupport;
-
-public class Controller2DiscoveryProducer extends DefaultProducer {
-
- public Controller2DiscoveryProducer(Endpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- public Controller2Endpoint getEndpoint() {
- return (Controller2Endpoint) super.getEndpoint();
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- getEndpoint().getAdapter().getControllerState().triggerDiscovery();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java
deleted file mode 100644
index bbde9e8cf..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.impl.DefaultEndpoint;
-import org.openremote.manager.shared.connector.ConnectorComponent;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.file.Path;
-
-public class Controller2Endpoint extends DefaultEndpoint {
-
- final protected Controller2AdapterManager adapterManager;
- final protected ConnectorComponent.Capability capability;
-
- protected String host;
- protected Integer port;
- protected String username;
- protected String password;
- protected Boolean secure;
-
- protected String deviceKey;
-
- protected Controller2Adapter adapter;
-
- public Controller2Endpoint(String endpointUri, Controller2Component component, Controller2AdapterManager adapterManager, Path path) {
- super(endpointUri, component);
- this.adapterManager = adapterManager;
-
- if (path.getNameCount() <= 0) {
- throw new IllegalArgumentException(
- "Desired endpoint capability missing from endpoint URI path: " + endpointUri
- );
- }
-
- capability = ConnectorComponent.Capability.valueOf(path.getName(0).toString());
-
- if (capability == ConnectorComponent.Capability.listen) {
- if (path.getNameCount() < 2 || (deviceKey = path.getName(1).toString()).length() == 0) {
- throw new IllegalArgumentException(
- "Listen capability requires /" + ConnectorComponent.Capability.listen.name() + "/<deviceKey> in endpoint URI path: " + endpointUri
- );
- }
- }
- }
-
- public String getHost() {
- return host;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public Integer getPort() {
- return port;
- }
-
- public void setPort(Integer port) {
- this.port = port;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public Boolean getSecure() {
- return secure;
- }
-
- public void setSecure(Boolean secure) {
- this.secure = secure;
- }
-
- @Override
- public Controller2Component getComponent() {
- return (Controller2Component) super.getComponent();
- }
-
- @Override
- protected void doStop() throws Exception {
- super.doStop();
- if (adapter != null)
- adapterManager.closeAdapter(adapter);
- }
-
- @Override
- public Producer createProducer() throws Exception {
- switch(capability) {
- case discovery:
- return new Controller2DiscoveryProducer(this);
- case inventory:
- return new Controller2InventoryProducer(this);
- case read:
- return new Controller2ReadProducer(this);
- case write:
- return new Controller2WriteProducer(this);
- }
- throw new IllegalStateException("Unsupported producer capability: " + capability);
- }
-
- @Override
- public Consumer createConsumer(Processor processor) throws Exception {
- switch(capability) {
- case inventory:
- return new Controller2InventoryConsumer(this, processor);
- case listen:
- return new Controller2ListenConsumer(this, processor, deviceKey);
- }
- throw new IllegalStateException("Unsupported consumer capability: " + capability);
- }
-
- @Override
- public boolean isSingleton() {
- return false;
- }
-
- public Controller2Adapter getAdapter() {
- if (adapter == null) {
- try {
- String scheme = secure != null && secure ? "https" : "http";
- URL controllerUrl = new URL(scheme, getHost(), getPort(), "/controller");
- adapter = adapterManager.openAdapter(controllerUrl, username, password);
- if (adapter == null)
- throw new IllegalStateException("Manager did not open adapter: " + controllerUrl);
- } catch (MalformedURLException ex) {
- throw new RuntimeException("Invalid controller URL: " + ex);
- }
- }
- return adapter;
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2HttpConnector.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2HttpConnector.java
deleted file mode 100644
index ce6e060e1..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2HttpConnector.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * OpenRemote, the Home of the Digital Home.
- * Copyright 2008-2014, 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.agent.controller2;
-
-import com.ning.http.client.*;
-import org.openremote.console.controller.AsyncControllerDiscoveryCallback;
-import org.openremote.console.controller.ControllerConnectionStatus;
-import org.openremote.console.controller.auth.Credentials;
-import org.openremote.console.controller.connector.ControllerDiscoveryResponseHandler;
-import org.openremote.console.controller.connector.ControllerDiscoveryServer;
-import org.openremote.console.controller.connector.HttpConnector;
-import org.openremote.entities.controller.AsyncControllerCallback;
-import org.openremote.entities.controller.ControllerResponseCode;
-
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeoutException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * An asynchronous multi-threaded connector.
- */
-public class Controller2HttpConnector extends HttpConnector {
-
- private static final Logger LOG = Logger.getLogger(Controller2HttpConnector.class.getName());
-
- final protected AsyncHttpClient client;
- protected Realm authRealm;
-
- final protected ExecutorService discoveryThreadPool = Executors.newFixedThreadPool(3);
- protected ControllerDiscoveryServer discoveryServer;
-
- private AsyncControllerCallback<ControllerConnectionStatus> connectCallback;
-
- public Controller2HttpConnector(int maxConnectionsPerHost, int maxConnectionsTotal, int timeoutMillis) {
- AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
- builder
- .setAllowPoolingConnections(true)
- .setMaxConnectionsPerHost(maxConnectionsPerHost)
- .setMaxConnections(maxConnectionsTotal)
- .setConnectTimeout(timeoutMillis)
- .setRequestTimeout(timeoutMillis);
- client = new AsyncHttpClient(builder.build());
- }
-
- public void startDiscovery(int tcpPort, Integer discoveryDuration, ControllerDiscoveryResponseHandler responseHandler) {
- if (discoveryServer != null)
- return;
- discoveryServer = new ControllerDiscoveryServer(tcpPort, discoveryDuration, responseHandler);
- discoveryThreadPool.submit(discoveryServer);
- }
-
- @Override
- public void stopDiscovery() {
- if (discoveryServer != null) {
- discoveryServer.cancel();
- }
- discoveryServer = null;
- }
-
- @Override
- public boolean isDiscoveryRunning() {
- return discoveryServer != null;
- }
-
- @Override
- protected void doRequest(URI uri, Map<String, String> headers, String content,
- final ControllerCallback callback, Integer timeout) {
- if (callback.getCommand() == RestCommand.DISCOVERY) {
- int tcpPort = (Integer) callback.getData();
- startDiscovery(
- tcpPort,
- timeout,
- new ControllerDiscoveryResponseHandler() {
- @Override
- public void sendStartMessage() {
- // Called when discovery is started
- AsyncControllerDiscoveryCallback discoveryCallback = (AsyncControllerDiscoveryCallback) callback.getWrappedCallback();
- discoveryCallback.onDiscoveryStarted();
- }
-
- @Override
- public void sendFinishMessage() {
- // This will be called when discovery is stopped
- AsyncControllerDiscoveryCallback discoveryCallback = (AsyncControllerDiscoveryCallback) callback.getWrappedCallback();
- discoveryCallback.onDiscoveryStopped();
- }
-
- @Override
- public void sendSuccessMessage(byte[] responseBody) {
- // Called each time a controller is discovered
- handleResponse(callback, 0, null, responseBody);
- }
-
- @Override
- public void sendFailureMessage(Exception ex) {
- // Called when discovery cannot be started
- AsyncControllerDiscoveryCallback discoveryCallback = (AsyncControllerDiscoveryCallback) callback.getWrappedCallback();
- discoveryCallback.onStartDiscoveryFailed(ControllerResponseCode.UNKNOWN_ERROR);
- }
- }
- );
- return;
- }
-
- if (callback.getCommand() == RestCommand.STOP_DISCOVERY) {
- stopDiscovery();
- return;
- }
-
- if (callback.getCommand() == RestCommand.DISCONNECT) {
- doDisconnect();
- return;
- }
-
- boolean doHead = false;
- boolean doGet = false;
-
- if (callback.getCommand() == RestCommand.GET_RESOURCE_DETAILS) {
- doHead = true;
- }
-
- if (callback.getCommand() == RestCommand.GET_XML) {
- doGet = true;
- }
-
- AsyncCompletionHandler<Void> handler = new AsyncCompletionHandler<Void>() {
-
- @Override
- public Void onCompleted(Response response) throws Exception {
- LOG.fine("Response status: " + response.getStatusCode());
- if (response.getStatusCode() >= 300) {
- callback.getWrappedCallback().onFailure(
- ControllerResponseCode.getResponseCode(response.getStatusCode())
- );
- return null;
- }
-
- if (callback.getCommand() == RestCommand.LOGOUT) {
- authRealm = null;
- }
-
- if (callback.getCommand() == RestCommand.CONNECT) {
- connectCallback = (AsyncControllerCallback<ControllerConnectionStatus>) callback.getWrappedCallback();
- }
-
- Map<String, String> responseHeadersMap = new HashMap<>();
- Set<String> headerNames = response.getHeaders().keySet();
- for (String headerName : headerNames) {
- responseHeadersMap.put(headerName, response.getHeader(headerName));
-
- }
-
- byte[] responseBytes = response.getResponseBodyAsBytes();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Response body: " + (new String(responseBytes, Charset.forName("utf-8"))));
- }
-
- Controller2HttpConnector.this.handleResponse(
- callback,
- response.getStatusCode(),
- responseHeadersMap,
- responseBytes
- );
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- if (callback.getCommand() == RestCommand.DO_SENSOR_POLLING
- && t.getCause() != null && t.getCause() instanceof TimeoutException) {
- callback.getWrappedCallback().onSuccess(null);
- } else {
- LOG.log(Level.INFO, "Unknown request error", t);
- callback.getWrappedCallback().onFailure(ControllerResponseCode.UNKNOWN_ERROR);
- }
- }
- };
-
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Request body: " + content);
- }
-
- try {
- if (doHead) {
- LOG.fine("HEAD request: " + uri);
- client.prepareHead(uri.toString())
- .setRealm(authRealm)
- .setRequestTimeout(timeout > 0 ? timeout : client.getConfig().getRequestTimeout())
- .execute(handler);
- } else if (doGet) {
- LOG.fine("GET request: " + uri);
- client.prepareGet(uri.toString())
- .setHeaders(prepareHeaders(headers))
- .setRealm(authRealm)
- .setRequestTimeout(timeout > 0 ? timeout : client.getConfig().getRequestTimeout())
- .execute(handler);
- } else {
- LOG.fine("POST request: " + uri);
- AsyncHttpClient.BoundRequestBuilder request = client.preparePost(uri.toString())
- .setHeaders(prepareHeaders(headers))
- .setHeader("Accept", "application/json")
- .setRealm(authRealm)
- .setRequestTimeout(timeout > 0 ? timeout : client.getConfig().getRequestTimeout());
- if (content != null) {
- request.setHeader("Content-Type", "application/json")
- .setBody(content.getBytes(Charset.forName("utf-8")));
- }
- request.execute(handler);
- }
- } catch (Exception ex) {
- LOG.log(Level.INFO, "Error creating request: " + uri, ex);
- callback.getWrappedCallback().onFailure(ControllerResponseCode.UNKNOWN_ERROR);
- }
- }
-
- @Override
- public void setCredentials(Credentials credentials) {
- this.credentials = credentials;
- if (credentials != null) {
- this.authRealm = new Realm.RealmBuilder()
- .setPrincipal(credentials.getUsername())
- .setPassword(credentials.getPassword())
- .build();
- } else {
- this.authRealm = null;
- }
- }
-
- @Override
- public void logout(AsyncControllerCallback<Boolean> callback) {
- credentials = null;
- if (controllerUrl != null) {
- doRequest(buildRequestUri(RestCommand.LOGOUT), null, null, new ControllerCallback(
- RestCommand.LOGOUT, callback), getTimeout());
- } else {
- callback.onSuccess(true);
- }
- }
-
- protected void doDisconnect() {
- client.close();
- connected = false;
- if (connectCallback != null) {
- connectCallback.onFailure(ControllerResponseCode.DISCONNECTED);
- connectCallback = null;
- }
- }
-
- protected FluentCaseInsensitiveStringsMap prepareHeaders(Map<String, String> headers) {
- FluentCaseInsensitiveStringsMap result = new FluentCaseInsensitiveStringsMap();
- if (headers != null) {
- headers.forEach((key, value) -> {
- result.put(key, Collections.singletonList(value));
- });
- }
- return result;
- }
-}
\ No newline at end of file
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java
deleted file mode 100644
index fe667d31f..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.openremote.agent.controller2;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.openremote.agent.controller2.model.DeviceListener;
-import org.openremote.manager.shared.agent.InventoryModifiedEvent;
-import org.openremote.manager.shared.asset.Asset;
-
-import java.util.logging.Logger;
-
-import static org.openremote.manager.shared.agent.InventoryModifiedEvent.Cause.*;
-
-public class Controller2InventoryConsumer extends Controller2Consumer implements DeviceListener {
-
- private static final Logger LOG = Logger.getLogger(Controller2InventoryConsumer.class.getName());
-
- public Controller2InventoryConsumer(Controller2Endpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
-
- @Override
- synchronized protected void doStart() throws Exception {
- super.doStart();
- getEndpoint().getAdapter().getControllerState().addDeviceListener(this);
- }
-
- @Override
- synchronized protected void doStop() throws Exception {
- getEndpoint().getAdapter().getControllerState().removeDeviceListener(this);
- super.doStop();
- }
-
- @Override
- public void onDeviceAdded(Asset device) {
- if (!isStarted() && !isStarting()) {
- LOG.fine("Received device added event but consumer hasn't been started");
- return;
- }
-
- LOG.fine("Starting new exchange for added device: " + device);
- Exchange exchange = getEndpoint().createExchange();
- exchange.getIn().setBody(new InventoryModifiedEvent(device, PUT));
- processExchange(exchange);
- }
-
- @Override
- public void onDeviceRemoved(Asset device) {
- if (!isStarted() && !isStarting()) {
- LOG.fine("Received device removed event but consumer hasn't been started");
- return;
- }
-
- LOG.fine("Starting new exchange for removed device: " + device);
- Exchange exchange = getEndpoint().createExchange();
- exchange.getIn().setBody(new InventoryModifiedEvent(device, DELETE));
- processExchange(exchange);
- }
-
- @Override
- public void onDeviceUpdated(Asset device) {
- if (!isStarted() && !isStarting()) {
- LOG.fine("Received device updated event but consumer hasn't been started");
- return;
- }
-
- LOG.fine("Starting new exchange for updated device: " + device);
- Exchange exchange = getEndpoint().createExchange();
- exchange.getIn().setBody(new InventoryModifiedEvent(device, PUT));
- processExchange(exchange);
- }
-
- protected void processExchange(Exchange exchange) {
- try {
- getProcessor().process(exchange);
- } catch (Exception ex) {
- getExceptionHandler().handleException("Error processing exchange", exchange, ex);
- } finally {
- if (exchange.getException() != null) {
- getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
- }
- }
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryProducer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryProducer.java
deleted file mode 100644
index cb6fca910..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryProducer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.URISupport;
-
-import java.util.logging.Logger;
-
-public class Controller2InventoryProducer extends DefaultProducer {
-
- private static final Logger LOG = Logger.getLogger(Controller2InventoryProducer.class.getName());
-
- public Controller2InventoryProducer(Controller2Endpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- public Controller2Endpoint getEndpoint() {
- return (Controller2Endpoint) super.getEndpoint();
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- LOG.info("### TODO: Implement inventory producer (should support add, remove, update)");
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2ListenConsumer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2ListenConsumer.java
deleted file mode 100644
index b1b60e2cc..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2ListenConsumer.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.openremote.agent.controller2.model.SensorListener;
-
-import java.util.logging.Logger;
-
-public class Controller2ListenConsumer extends Controller2Consumer implements SensorListener {
-
- private static final Logger LOG = Logger.getLogger(Controller2ListenConsumer.class.getName());
-
- final protected String deviceKey;
-
- public Controller2ListenConsumer(Controller2Endpoint endpoint, Processor processor, String deviceKey) {
- super(endpoint, processor);
- this.deviceKey = deviceKey;
- }
-
- @Override
- synchronized protected void doStart() throws Exception {
- super.doStart();
- getEndpoint().getAdapter().getControllerState().addSensorListener(this);
- }
-
- @Override
- synchronized protected void doStop() throws Exception {
- getEndpoint().getAdapter().getControllerState().removeSensorListener(this);
- super.doStop();
- }
-
- @Override
- public String getDeviceKey() {
- return deviceKey;
- }
-
- @Override
- public void onUpdate(String resourceKey, Object newValue) {
- // Push value into message body and camel type converter can be used to
- // get value into the required type by the next processor in the route
- LOG.fine("Consuming state change from '" + deviceKey + " : " + resourceKey + "': " + newValue);
- Exchange exchange = getEndpoint().createExchange();
- exchange.getIn().setHeader(Controller2Component.HEADER_DEVICE_KEY, deviceKey);
- exchange.getIn().setHeader(Controller2Component.HEADER_DEVICE_RESOURCE_KEY, resourceKey);
- exchange.getIn().setBody(newValue);
- try {
- getProcessor().process(exchange);
- } catch (Exception ex) {
- getExceptionHandler().handleException("Error processing exchange", exchange, ex);
- } finally {
- if (exchange.getException() != null) {
- getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
- }
- }
- }
-
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2ReadProducer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2ReadProducer.java
deleted file mode 100644
index 5824ae493..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2ReadProducer.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.URISupport;
-
-import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_KEY;
-import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_RESOURCE_KEY;
-
-public class Controller2ReadProducer extends DefaultProducer {
-
- public Controller2ReadProducer(Controller2Endpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- public Controller2Endpoint getEndpoint() {
- return (Controller2Endpoint) super.getEndpoint();
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- String deviceKey = exchange.getIn().getHeader(HEADER_DEVICE_KEY, null, String.class);
- String resourceKey = exchange.getIn().getHeader(HEADER_DEVICE_RESOURCE_KEY, null, String.class);
- if (deviceKey == null || "".equals(deviceKey) || resourceKey == null || "".equals(resourceKey)) {
- throw new IllegalArgumentException(
- "Both device and resource key message headers must be defined for read producer"
- );
- }
-
- Object value = getEndpoint().getAdapter().getControllerState().readResource(deviceKey, resourceKey);
- exchange.getIn().setBody(value);
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2WriteProducer.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2WriteProducer.java
deleted file mode 100644
index 06d663a7c..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2WriteProducer.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.URISupport;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_KEY;
-import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_RESOURCE_KEY;
-
-public class Controller2WriteProducer extends DefaultProducer {
-
- private static final Logger LOG = Logger.getLogger(Controller2WriteProducer.class.getName());
-
- public Controller2WriteProducer(Controller2Endpoint endpoint) {
- super(endpoint);
- }
-
- @Override
- public Controller2Endpoint getEndpoint() {
- return (Controller2Endpoint) super.getEndpoint();
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- String deviceKey = exchange.getIn().getHeader(HEADER_DEVICE_KEY, null, String.class);
- String resourceKey = exchange.getIn().getHeader(HEADER_DEVICE_RESOURCE_KEY, null, String.class);
- if (deviceKey == null || "".equals(deviceKey) || resourceKey == null || "".equals(resourceKey)) {
- throw new IllegalArgumentException(
- "Both device and resource key message headers must be defined for write producer"
- );
- }
-
- Object commandValue = exchange.getIn().getBody();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Writing to '" + deviceKey + " : " + resourceKey+ "' with value: " + commandValue);
- }
- getEndpoint().getAdapter().getControllerState().writeResource(deviceKey, resourceKey, commandValue);
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/ControllerState.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/ControllerState.java
deleted file mode 100644
index 78d7df096..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/ControllerState.java
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-import org.openremote.console.controller.AsyncRegistrationCallback;
-import org.openremote.console.controller.Controller;
-import org.openremote.entities.controller.*;
-import org.openremote.manager.shared.Consumer;
-import org.openremote.manager.shared.device.DeviceAttributes;
-
-import java.util.*;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.CountDownLatch;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-public class ControllerState {
-
- private static final Logger LOG = Logger.getLogger(ControllerState.class.getName());
-
- final protected String controllerUrl;
-
- protected volatile boolean initialized = false;
- // TODO: The concurrency control of these data structures should be revisited when we deal with reconnect/refresh of devices
- final protected Map<String, DeviceMapping> deviceMap = new LinkedHashMap<>();
- final protected List<SensorListener> sensorListeners = new CopyOnWriteArrayList<>();
- final protected List<DeviceListener> deviceListeners = new CopyOnWriteArrayList<>();
- final protected List<DeviceListener> queuedDeviceListeners = new CopyOnWriteArrayList<>();
- final protected List<WriteResourceRequest> queuedWriteRequests = new CopyOnWriteArrayList<>();
-
- public ControllerState(String controllerUrl) {
- this.controllerUrl = controllerUrl;
- }
-
- public boolean isInitialized() {
- return initialized;
- }
-
- public void setInitialized(boolean initialized) {
- this.initialized = initialized;
- }
-
- public void initialize(Controller controller) {
- LOG.fine("Initializing controller state: " + controllerUrl);
- // TODO: Update the controller library to return futures
- // TODO: Resync the devices after disconnect/reconnect
- if (initialized)
- return;
-
- try {
- deviceMap.clear();
- updateDeviceMappings(controller, deviceMapping -> {
- String deviceKey = new DeviceAttributes(deviceMapping.getDeviceAsset().getAttributes()).getKey();
- LOG.fine("Updating device mapping: " + deviceKey);
- deviceMap.put(deviceKey, deviceMapping);
- });
- initialized = true;
- LOG.fine("Controller state initialized");
- } catch (InterruptedException e) {
- initialized = false;
- LOG.severe("Controller state initialization was interrupted");
- } catch (Exception ex) {
- initialized = false;
- // TODO: better error handling
- LOG.log(Level.SEVERE, "Controller state initialization failed", ex);
- }
-
- LOG.fine("Processing sensor listeners: " + sensorListeners.size());
- sensorListeners.forEach(this::processSensorListener);
-
- LOG.fine("Processing queued device listeners: " + queuedDeviceListeners.size());
- queuedDeviceListeners.stream().forEach(this::announceDevices);
- queuedDeviceListeners.clear();
-
- LOG.fine("Processing queued write requests: " + queuedWriteRequests.size());
- queuedWriteRequests.stream().forEach(this::processWriteRequest);
- queuedWriteRequests.clear();
-
- }
-
- public void addSensorListener(SensorListener listener) {
- if (listener != null && (listener.getDeviceKey() == null)) {
- LOG.warning("Ignoring invalid sensor listener (" + controllerUrl + "), missing device key: " + listener);
- return;
- }
- LOG.fine("Adding sensor listener (" + controllerUrl + "): " + listener);
- sensorListeners.add(listener);
- processSensorListener(listener);
- }
-
- public void removeSensorListener(SensorListener listener) {
- LOG.fine("Removing sensor listener (" + controllerUrl + "): " + listener);
- sensorListeners.remove(listener);
- if (listener.getDeviceKey() == null) {
- return;
- }
- // Unregister the handler
- DeviceMapping deviceMapping = deviceMap.get(listener.getDeviceKey());
-
- if (deviceMapping == null) {
- LOG.fine("Device key for sensor listener cannot be found so ignoring: " + listener.getDeviceKey());
- return;
- }
-
- deviceMapping.removeSensorListener(listener);
- }
-
- public void addDeviceListener(DeviceListener listener) {
- LOG.fine("Adding device listener (" + controllerUrl + "): " + listener);
- deviceListeners.add(listener);
-
- if (!initialized) {
- queuedDeviceListeners.add(listener);
- return;
- }
- announceDevices(listener);
- }
-
- public void removeDeviceListener(DeviceListener listener) {
- LOG.fine("Removing device listener (" + controllerUrl + "): " + listener);
- deviceListeners.remove(listener);
- }
-
-
- public void triggerDiscovery() {
- LOG.fine("Triggering discovery (" + controllerUrl + ")");
- deviceListeners.forEach(this::announceDevices);
- }
-
- public Object readResource(String deviceKey, String resourceKey) {
- LOG.fine("Reading resource (" + controllerUrl + "): " + deviceKey + "/" + resourceKey);
-
- DeviceMapping deviceMapping = deviceMap.get(deviceKey);
- if (deviceMapping == null) {
- LOG.info("Request to read to unknown device key '" + deviceKey + "' will be ignored");
- return null;
- }
-
- DeviceResourceMapping resourceMapping = deviceMapping.getResourceMap().get(resourceKey);
- if (resourceMapping == null) {
- LOG.info("Request to read to unknown resource key '" + resourceKey + "' will be ignored");
- return null;
- }
-
- if (resourceMapping.getSensor() == null) {
- LOG.info("Request to read non-sensor device resource '" + resourceKey + "' will be ignored");
- return null;
- }
-
- // TODO: This only reads the cached value?! It doesn't actually call a command on the controller...
- return resourceMapping.getSensor().getStringValue();
- }
-
- public void writeResource(String deviceKey, String resourceKey, Object resourceValue) {
- LOG.fine("Writing resource (" + controllerUrl + "): " + deviceKey + "/" + resourceKey + ": " + resourceValue);
-
- if (!initialized) {
- LOG.fine("Controller state not initialized, queuing write request");
- WriteResourceRequest writeRequest = new WriteResourceRequest();
- writeRequest.setDeviceKey(deviceKey);
- writeRequest.setResourceKey(resourceKey);
- writeRequest.setResourceValue(resourceValue);
- queuedWriteRequests.add(writeRequest);
- return;
- }
-
- processWriteRequest(new WriteResourceRequest(deviceKey, resourceKey, resourceValue));
- }
-
- /* ################################################################################## */
-
- protected void updateDeviceMappings(Controller controller, Consumer<DeviceMapping> onDeviceMappingUpdate) throws InterruptedException {
- List<String> deviceNames = new ArrayList<>();
- List<Controller.WidgetCommandInfo> widgetCommandInfos = new ArrayList<>();
-
- // All of the following blocks must be executed serially
- {
- final CountDownLatch latch = new CountDownLatch(1);
- // Get widget command information to allow capability
- // construction and writable resource resolution
- controller.getWidgetsCommandsInfo(new AsyncControllerCallback<List<Controller.WidgetCommandInfo>>() {
- @Override
- public void onFailure(ControllerResponseCode controllerResponseCode) {
- LOG.severe("Failed to get widget command info from the controller: " + controllerResponseCode);
- latch.countDown();
- }
-
- @Override
- public void onSuccess(List<Controller.WidgetCommandInfo> result) {
- LOG.fine("Got widget command info from controller");
- widgetCommandInfos.addAll(result);
- latch.countDown();
- }
- });
- latch.await();
- }
-
- {
- final CountDownLatch latch = new CountDownLatch(1);
- // Get device names available on this controller
- controller.getDeviceList(new AsyncControllerCallback<List<DeviceInfo>>() {
- @Override
- public void onFailure(ControllerResponseCode controllerResponseCode) {
- LOG.severe("Failed to get device list from the controller: " + controllerResponseCode);
- latch.countDown();
- }
-
- @Override
- public void onSuccess(List<DeviceInfo> deviceInfos) {
- LOG.fine("Got device list from controller");
- deviceNames.addAll(deviceInfos.stream().map(DeviceInfo::getName).collect(Collectors.toList()));
- latch.countDown();
- }
- });
- latch.await();
- }
-
- // Get each controller device and build the mapping
- for (String deviceName : deviceNames) {
- DeviceMapping mapping = new DeviceMapping();
-
- {
- final CountDownLatch latch = new CountDownLatch(1);
- controller.getDevice(deviceName, new AsyncControllerCallback<org.openremote.entities.controller.Device>() {
- @Override
- public void onFailure(ControllerResponseCode controllerResponseCode) {
- LOG.severe("Failed to get device '" + deviceName + "' from the controller: " + controllerResponseCode);
- latch.countDown();
- }
-
- @Override
- public void onSuccess(Device device) {
- LOG.fine("Got device '" + deviceName + "' from the controller");
- mapping.setDevice(device);
- latch.countDown();
- }
- });
- latch.await();
- }
-
- {
- final CountDownLatch latch = new CountDownLatch(1);
- // Register the device (so we get sensor change events and can send commands), this starts
- // the polling of sensor values - effectively long-lasting HTTP connection for each device!
- // TODO This will NOT scale! Well, depends on the internal implementation of our HTTP connector...
- if (mapping.getDevice() != null) {
- mapping.setRegistrationHandle(
- // TODO: Should be documented somewhere that this call blocks if the HTTP connector is not asynchronous
- controller.registerDevice(mapping.getDevice(), new AsyncRegistrationCallback() {
- @Override
- public void onFailure(ControllerResponseCode controllerResponseCode) {
- LOG.info("Failed to register device '" + deviceName + "' with the controller: " + controllerResponseCode);
- latch.countDown();
- }
-
- @Override
- public void onSuccess() {
- LOG.fine("Registered device '" + deviceName + "' with the controller");
- latch.countDown();
- }
- })
- );
- latch.await();
- }
- }
-
- mapping.update(widgetCommandInfos);
- onDeviceMappingUpdate.accept(mapping);
- }
- }
-
- protected void processSensorListener(SensorListener listener) {
- DeviceMapping deviceMapping = deviceMap.get(listener.getDeviceKey());
-
- if (deviceMapping == null) {
- LOG.fine("Device mapping for sensor listener cannot be found so ignoring, device key was: " + listener.getDeviceKey());
- return;
- }
-
- LOG.fine("Adding sensor listener to device mapping: " + listener.getDeviceKey());
- deviceMapping.addSensorListener(listener);
- }
-
- protected void announceDevices(DeviceListener listener) {
- LOG.fine("Announcing " + deviceMap.size() + " devices on listener: " + listener);
- deviceMap.values().stream().forEach(deviceMapping -> {
- listener.onDeviceAdded(deviceMapping.getDeviceAsset());
- });
- }
-
- protected void processWriteRequest(WriteResourceRequest request) {
- DeviceMapping deviceMapping = deviceMap.get(request.getDeviceKey());
- if (deviceMapping == null) {
- LOG.info("Request to write to unknown device key '" + request.getDeviceKey() + "' will be ignored");
- return;
- }
-
- DeviceResourceMapping resourceMapping = deviceMapping.getResourceMap().get(request.getResourceKey());
- if (resourceMapping == null) {
- LOG.info("Request to write to unknown resource key '" + request.getResourceKey() + "' will be ignored");
- return;
- }
-
- Command sendCommand = resourceMapping.getSendCommand1();
-
- Object resourceValue = request.getResourceValue();
- if (resourceValue != null && resourceMapping.getSendCommand2() != null) {
- // This is a switch the command to send varies depending on the value
- // (whoever invented this better not raise their hand...)
- switch (resourceValue.toString().toLowerCase(Locale.ROOT)) {
- case "off":
- case "false":
- resourceValue = "off";
- sendCommand = resourceMapping.getSendCommand2();
- break;
- case "on":
- case "true":
- resourceValue = "on";
- break;
- default:
- throw new IllegalArgumentException("Can't parse command value for boolean switch: " + resourceValue);
- }
- }
-
- if (sendCommand == null) {
- LOG.info("Unable to determine the command to send for " + request.getResourceValue() + " : " + request.getResourceKey());
- return;
- }
-
- LOG.fine("Sending command on '" + deviceMapping.getDevice().getName() + "': " + sendCommand.getName());
- // TODO: Callback handling? Should maybe just log something...
- deviceMapping.getDevice().sendCommand(
- sendCommand,
- (resourceValue != null ? resourceValue.toString() : null),
- new AsyncControllerCallback<CommandResponse>() {
- @Override
- public void onFailure(ControllerResponseCode controllerResponseCode) {
- // TODO Components should offer a route for logging, so we can store (error) events
- }
-
- @Override
- public void onSuccess(CommandResponse commandResponse) {
- // TODO Components should offer a route for logging, so we can store (succes) events
- }
- }
- );
- }
-
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceListener.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceListener.java
deleted file mode 100644
index 8a65d18fd..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceListener.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-import org.openremote.manager.shared.asset.Asset;
-
-/**
- * Used by IOT connectors to announce changes to devices.
- * When a gateway component starts it should announce all devices
- * that it is already aware of and connected to.
- */
-public interface DeviceListener {
-
- void onDeviceAdded(Asset device);
-
- // TODO Not used, implement!
- void onDeviceRemoved(Asset device);
-
- // TODO Not used, implement!
- void onDeviceUpdated(Asset device);
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceMapping.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceMapping.java
deleted file mode 100644
index 280cdffde..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceMapping.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-import org.openremote.console.controller.Controller;
-import org.openremote.console.controller.DeviceRegistrationHandle;
-import org.openremote.container.util.IdentifierUtil;
-import org.openremote.entities.controller.Command;
-import org.openremote.entities.controller.Device;
-import org.openremote.entities.controller.Sensor;
-import org.openremote.manager.shared.asset.Asset;
-import org.openremote.manager.shared.asset.AssetType;
-import org.openremote.manager.shared.attribute.AttributeType;
-import org.openremote.manager.shared.device.DeviceAttributes;
-import org.openremote.manager.shared.device.DeviceResource;
-
-import java.nio.charset.Charset;
-import java.util.*;
-import java.util.stream.Stream;
-
-/**
- * Contains the data to allow mapping between native device API and the component device API
- */
-public class DeviceMapping {
-
- protected Device device;
- protected Asset deviceAsset;
- protected DeviceRegistrationHandle registrationHandle;
- protected Map<String, DeviceResourceMapping> resourceMap = new HashMap<>();
-
- public void addSensorListener(SensorListener listener) {
- for (DeviceResourceMapping deviceResourceMapping : resourceMap.values()) {
- deviceResourceMapping.addSensorListener(listener);
- }
- }
-
- public void removeSensorListener(SensorListener listener) {
- for (DeviceResourceMapping deviceResourceMapping : resourceMap.values()) {
- deviceResourceMapping.removeSensorListener(listener);
- }
- }
-
- public Device getDevice() {
- return device;
- }
-
- public void setDevice(Device device) {
- this.device = device;
- }
-
- public Asset getDeviceAsset() {
- return deviceAsset;
- }
-
- public DeviceRegistrationHandle getRegistrationHandle() {
- return registrationHandle;
- }
-
- public void setRegistrationHandle(DeviceRegistrationHandle registrationHandle) {
- this.registrationHandle = registrationHandle;
- }
-
- public Map<String, DeviceResourceMapping> getResourceMap() {
- return resourceMap;
- }
-
- public void update(List<Controller.WidgetCommandInfo> widgetCommandInfos) {
- deviceAsset = null;
- Device device = getDevice();
-
- // Remove sensor change listeners from sensors
- // TODO Not sure this is necessary, as we always have fresh instances (Device, Sensor) during update...
- resourceMap.values().forEach(DeviceResourceMapping::detachSensorListeners);
-
- if (device != null) {
-
- // TODO Take first command protocol as the device type?
- // String deviceProtocol = device.getCommands().get(0).getProtocol().toUpperCase();
-
- deviceAsset = new Asset(device.getName(), AssetType.DEVICE);
-
- // TODO: Stable device identifier generation?
- deviceAsset.setId(
- IdentifierUtil.getEncodedHash(
- device.getName().toLowerCase(Locale.ROOT).getBytes(Charset.forName("utf-8"))
- )
- );
-
- DeviceAttributes deviceAttributes = new DeviceAttributes(deviceAsset.getAttributes());
- deviceAttributes.setKey(device.getName().toLowerCase(Locale.ROOT));
-
- if (device.getCommands() == null || device.getCommands().size() == 0) {
- return;
- }
-
- // TODO: Controller API needs to provide Make & model info for the device
- //deviceAttributes.setMakeAndModel();
-
-
- // Get Device resources and capabilities
- List<Integer> assignedCommands = new ArrayList<>();
-
- // Go through sensors - any used by slider and switch
- // widgets can be RW resources
- for (Sensor sensor : device.getSensors()) {
- Command sensorCommand = sensor.getCommand();
- assignedCommands.add(sensorCommand.getId());
- Controller.WidgetCommandInfo matchingWidgetInfo =
- widgetCommandInfos.stream()
- .filter(widgetCommandInfo -> widgetCommandInfo.getSensorId() == sensor.getId())
- .findFirst()
- .orElseGet(() -> null);
-
- AttributeType resourceType;
- DeviceResource.Access access;
- switch (sensor.getType()) {
- case SWITCH:
- resourceType = AttributeType.BOOLEAN;
- access = matchingWidgetInfo != null ? DeviceResource.Access.RW : DeviceResource.Access.R;
- break;
- case RANGE:
- case LEVEL:
- resourceType = AttributeType.INTEGER;
- access = matchingWidgetInfo != null ? DeviceResource.Access.RW : DeviceResource.Access.R;
- break;
- default:
- resourceType = AttributeType.STRING;
- access = DeviceResource.Access.R;
- break;
- }
-
- String deviceResourceKey = sensor.getName().toLowerCase(Locale.ROOT);
-
- DeviceResource deviceResource = new DeviceResource(
- sensor.getName(),
- deviceResourceKey,
- resourceType,
- access
- );
-
- DeviceResourceMapping resourceMapping = new DeviceResourceMapping(deviceResourceKey);
- resourceMapping.setResource(deviceResource);
- resourceMapping.setSensor(sensor);
- resourceMap.put(deviceResource.getValueAsString(), resourceMapping);
-
- deviceAttributes.put(deviceResource);
-
- if (matchingWidgetInfo != null) {
- if (matchingWidgetInfo.getCommandId1() > 0) {
- assignedCommands.add(matchingWidgetInfo.getCommandId1());
- resourceMapping.setSendCommand1(
- device.getCommands().stream()
- .filter(command -> command.getId() == matchingWidgetInfo.getCommandId1())
- .findFirst()
- .orElseGet(() -> null)
- );
- }
- if (matchingWidgetInfo.getCommandId2() > 0) {
- resourceMapping.setSendCommand2(
- device.getCommands().stream()
- .filter(command -> command.getId() == matchingWidgetInfo.getCommandId2())
- .findFirst()
- .orElseGet(() -> null)
- );
- assignedCommands.add(matchingWidgetInfo.getCommandId2());
- }
- }
- }
-
- // Add any commands not already covered as write resources
- // Assume they are W resources with null data type
- Stream<Command> unassignedCommands = device.getCommands().stream().filter(
- command -> !assignedCommands.contains(command.getId())
- );
-
- // TODO: All commands are of string type?
- unassignedCommands.forEach(command -> {
-
- String deviceResourceKey = command.getName().toLowerCase(Locale.ROOT);
-
- DeviceResource deviceResource = new DeviceResource(
- command.getName(),
- deviceResourceKey,
- AttributeType.STRING,
- DeviceResource.Access.W
- );
-
- DeviceResourceMapping resourceMapping = new DeviceResourceMapping(deviceResourceKey);
- resourceMapping.setResource(deviceResource);
- resourceMapping.setSendCommand1(command);
- getResourceMap().put(deviceResource.getValueAsString(), resourceMapping);
-
- deviceAttributes.put(deviceResource);
- });
-
- deviceAsset.setAttributes(deviceAttributes.getJsonObject());
- }
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceResourceMapping.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceResourceMapping.java
deleted file mode 100644
index d2dac1d1c..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/DeviceResourceMapping.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-import org.openremote.entities.controller.Command;
-import org.openremote.entities.controller.Sensor;
-import org.openremote.manager.shared.device.DeviceResource;
-
-/**
- * Contains the data to allow mapping between native command/sensor API and the component resource API
- */
-public class DeviceResourceMapping {
-
- protected DeviceResource resource;
- protected Sensor sensor;
- protected SensorPropertyChangeListener sensorPropertyChangeListener;
- protected Command sendCommand1;
- protected Command sendCommand2;
-
- public DeviceResourceMapping(String resourceKey) {
- sensorPropertyChangeListener = new SensorPropertyChangeListener(resourceKey);
- }
-
- public DeviceResource getResource() {
- return resource;
- }
-
- public void setResource(DeviceResource resource) {
- this.resource = resource;
- }
-
- public Sensor getSensor() {
- return sensor;
- }
-
- public void setSensor(Sensor sensor) {
- if (this.sensor != null) {
- this.sensor.removePropertyChangeListener(sensorPropertyChangeListener);
- }
- this.sensor = sensor;
- this.sensor.addPropertyChangeListener(sensorPropertyChangeListener);
- }
-
- public void addSensorListener(SensorListener sensorListener) {
- if (this.sensor != null) {
- sensorPropertyChangeListener.addListener(sensorListener);
- }
- }
-
- public void removeSensorListener(SensorListener sensorListener) {
- sensorPropertyChangeListener.removeListener(sensorListener);
- }
-
- public void detachSensorListeners() {
- if (this.sensor != null) {
- this.sensor.removePropertyChangeListener(sensorPropertyChangeListener);
- }
- }
-
- public Command getSendCommand1() {
- return sendCommand1;
- }
-
- public void setSendCommand1(Command sendCommand1) {
- this.sendCommand1 = sendCommand1;
- }
-
- public Command getSendCommand2() {
- return sendCommand2;
- }
-
- public void setSendCommand2(Command sendCommand2) {
- this.sendCommand2 = sendCommand2;
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/SensorListener.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/SensorListener.java
deleted file mode 100644
index 32f51976a..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/SensorListener.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-/**
- * Listen to all resource value updates of a given device.
- */
-public interface SensorListener {
-
- String getDeviceKey();
-
- void onUpdate(String resourceKey, Object obj);
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/SensorPropertyChangeListener.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/SensorPropertyChangeListener.java
deleted file mode 100644
index 80861bbcb..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/SensorPropertyChangeListener.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.logging.Logger;
-
-/**
- * Used to handle native sensor change callbacks and notify the component sensor listeners
- */
-public class SensorPropertyChangeListener implements PropertyChangeListener {
-
- private static final Logger LOG = Logger.getLogger(SensorPropertyChangeListener.class.getName());
-
- final protected List<SensorListener> listeners = new CopyOnWriteArrayList<>();
- final protected String resourceKey;
-
- public SensorPropertyChangeListener(String resourceKey) {
- this.resourceKey = resourceKey;
- }
-
- public void addListener(SensorListener listener) {
- listeners.add(listener);
- }
-
- public void removeListener(SensorListener listener) {
- listeners.remove(listener);
- }
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- LOG.fine("Propagating controller change event to " + listeners.size() + " sensor listeners: " + evt.getNewValue());
- listeners.stream().forEach(sensorListener -> {
- sensorListener.onUpdate(resourceKey, evt.getNewValue());
- });
- }
-}
diff --git a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/WriteResourceRequest.java b/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/WriteResourceRequest.java
deleted file mode 100644
index 6a5a65963..000000000
--- a/manager/connector/controller2/src/main/java/org/openremote/agent/controller2/model/WriteResourceRequest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2016, 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.agent.controller2.model;
-
-/**
- * Used to track write requests which occur whilst connect/reconnect is occurring
- */
-public class WriteResourceRequest {
-
- protected String deviceKey;
- protected String resourceKey;
- protected Object resourceValue;
-
- public WriteResourceRequest() {
- }
-
- public WriteResourceRequest(String deviceKey, String resourceKey, Object resourceValue) {
- this.deviceKey = deviceKey;
- this.resourceKey = resourceKey;
- this.resourceValue = resourceValue;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- public void setDeviceKey(String deviceKey) {
- this.deviceKey = deviceKey;
- }
-
- public String getResourceKey() {
- return resourceKey;
- }
-
- public void setResourceKey(String resourceKey) {
- this.resourceKey = resourceKey;
- }
-
- public Object getResourceValue() {
- return resourceValue;
- }
-
- public void setResourceValue(Object resourceValue) {
- this.resourceValue = resourceValue;
- }
-}
diff --git a/manager/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties b/manager/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties
deleted file mode 100644
index f5cc62f89..000000000
--- a/manager/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties
+++ /dev/null
@@ -1 +0,0 @@
-components=controller2
\ No newline at end of file
diff --git a/manager/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component/controller2 b/manager/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component/controller2
deleted file mode 100644
index 9ea7bcbbd..000000000
--- a/manager/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component/controller2
+++ /dev/null
@@ -1 +0,0 @@
-class=org.openremote.agent.controller2.Controller2Component
diff --git a/manager/server/build.gradle b/manager/server/build.gradle
index 3ed9aaaba..33b63f555 100644
--- a/manager/server/build.gradle
+++ b/manager/server/build.gradle
@@ -6,13 +6,8 @@ mainClassName = "org.openremote.manager.server.Server"
dependencies {
compile project(":container")
+ compile project(":agent")
compile project(":manager:shared")
- compile project(":manager:connector:controller2")
-
- compile "org.slf4j:slf4j-api:$slf4jVersion"
- compile "org.slf4j:slf4j-jdk14:$slf4jVersion"
- compile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
- compile "org.slf4j:log4j-over-slf4j:$slf4jVersion"
compile "org.xerial:sqlite-jdbc:$sqliteVersion"
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/DemoDataService.java b/manager/server/src/main/java/org/openremote/manager/server/DemoDataService.java
index a498de662..d7a911018 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/DemoDataService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/DemoDataService.java
@@ -21,10 +21,10 @@ package org.openremote.manager.server;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
+import elemental.json.Json;
import org.apache.log4j.Logger;
import org.keycloak.admin.client.resource.*;
import org.keycloak.representations.idm.*;
-import org.openremote.agent.controller2.Controller2Component;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.persistence.PersistenceService;
@@ -34,18 +34,22 @@ import org.openremote.manager.server.agent.ConnectorService;
import org.openremote.manager.server.asset.AssetService;
import org.openremote.manager.server.asset.ServerAsset;
import org.openremote.manager.server.security.ManagerIdentityService;
-import org.openremote.manager.shared.agent.Agent;
import org.openremote.manager.shared.asset.AssetType;
import org.openremote.manager.shared.attribute.Attribute;
+import org.openremote.manager.shared.attribute.AttributeType;
import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.attribute.Metadata;
import org.openremote.manager.shared.security.Tenant;
import rx.Observable;
import java.util.Arrays;
import java.util.List;
-import static org.openremote.container.util.MapAccess.*;
+import static org.openremote.container.util.MapAccess.getBoolean;
import static org.openremote.manager.shared.Constants.*;
+import static org.openremote.manager.shared.asset.AssetAttributeMeta.*;
+import static org.openremote.manager.shared.asset.AssetType.BUILDING;
+import static org.openremote.manager.shared.attribute.AttributeType.STRING;
import static rx.Observable.fromCallable;
public class DemoDataService implements ContainerService {
@@ -237,7 +241,31 @@ public class DemoDataService implements ContainerService {
smartOffice.setRealm(MASTER_REALM);
smartOffice.setName("Smart Office");
smartOffice.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
- smartOffice.setType(AssetType.BUILDING);
+ smartOffice.setType(BUILDING);
+ Attributes smartOfficeAttributes = new Attributes();
+ smartOfficeAttributes.put(
+ new Attribute("geoStreet", STRING, Json.create("Torenallee 20"))
+ .setMetadata(new Metadata()
+ .add(createMetadataItem(LABEL, Json.create("Street")))
+ .add(createMetadataItem(ABOUT, Json.create("http://project-haystack.org/tag/geoStreet")))
+ ),
+ new Attribute("geoPostalCode", AttributeType.INTEGER, Json.create(5617))
+ .setMetadata(new Metadata()
+ .add(createMetadataItem(LABEL, Json.create("Postal Code")))
+ .add(createMetadataItem(ABOUT, Json.create("http://project-haystack.org/tag/geoPostalCode")))
+ ),
+ new Attribute("geoCity", STRING, Json.create("Eindhoven"))
+ .setMetadata(new Metadata()
+ .add(createMetadataItem(LABEL, Json.create("City")))
+ .add(createMetadataItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCity")))
+ ),
+ new Attribute("geoCountry", STRING, Json.create("Netherlands"))
+ .setMetadata(new Metadata()
+ .add(createMetadataItem(LABEL, Json.create("Country")))
+ .add(createMetadataItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCountry")))
+ )
+ );
+ smartOffice.setAttributes(smartOfficeAttributes.getJsonObject());
smartOffice = assetService.merge(smartOffice);
ServerAsset groundfloor = new ServerAsset(smartOffice);
@@ -252,12 +280,12 @@ public class DemoDataService implements ContainerService {
lobby.setType(AssetType.ROOM);
lobby = assetService.merge(lobby);
+ /*
ServerAsset agentAsset = new ServerAsset(lobby);
agentAsset.setName("Demo Controller");
agentAsset.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
agentAsset.setType(AssetType.AGENT);
- /*
Agent agent = new Agent(new Attributes(), true);
agent.setEnabled(true);
agent.setConnectorType("urn:openremote:connector:controller2");
@@ -287,8 +315,8 @@ public class DemoDataService implements ContainerService {
LOG.info("Configured demo agent attributes: " + agent.getAttributes());
agentAsset = assetService.merge(agentAsset);
- */
DEMO_AGENT_ID = agentAsset.getId();
+ */
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentRoutes.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentRoutes.java
deleted file mode 100644
index 02975b7ec..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentRoutes.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Copyright 2016, 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.manager.server.agent;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.openremote.agent.controller2.Controller2Component;
-import org.openremote.container.message.MessageBrokerContext;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.agent.InventoryModifiedEvent;
-import org.openremote.manager.shared.asset.Asset;
-import org.openremote.manager.shared.connector.ConnectorComponent;
-import org.openremote.manager.shared.device.DeviceAttributes;
-
-import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.logging.Logger;
-
-import static org.openremote.manager.server.event.EventPredicates.isEventType;
-
-/**
- * The messaging routes of a running agent instance.
- *
- */
-public abstract class AgentRoutes {
-
- private static final Logger LOG = Logger.getLogger(AgentRoutes.class.getName());
-
- public static String PRODUCER_INVENTORY_ROUTE(String agentAssetId) {
- return "direct:urn:openremote:agent:inventory:" + agentAssetId;
- }
-
- public static String PRODUCER_DISCOVERY_ROUTE(String agentAssetId) {
- return "direct:urn:openremote:agent:discovery:" + agentAssetId;
- }
-
- public static String PRODUCER_READ_ROUTE(String agentAssetId) {
- return "direct:urn:openremote:agent:read:" + agentAssetId;
- }
-
- public static String PRODUCER_WRITE_ROUTE(String agentAssetId) {
- return "direct:urn:openremote:agent:write:" + agentAssetId;
- }
-
- final protected Set<String> agentRouteIds = new CopyOnWriteArraySet<>();
- final protected Set<String> deviceRouteIds = new CopyOnWriteArraySet<>();
- final protected Asset agentAsset;
- final protected Agent agent;
- final protected ConnectorComponent connectorComponent;
-
- public AgentRoutes(Asset agentAsset, Agent agent, ConnectorComponent connectorComponent) {
- this.agentAsset = agentAsset;
- this.agent = agent;
- this.connectorComponent = connectorComponent;
- }
-
- public Agent getAgent() {
- return agent;
- }
-
- public Asset getAgentAsset() {
- return agentAsset;
- }
-
- public RouteBuilder buildAgentRoutes() throws Exception {
- return new RouteBuilder() {
-
- String routeId;
- String endpointUri;
-
- @Override
- public void configure() throws Exception {
- for (ConnectorComponent.Capability capability : connectorComponent.getConsumerCapabilities()) {
- switch (capability) {
- case inventory:
- routeId = "Agent Inventory Consumer - " + agentAsset.getId();
- endpointUri = connectorComponent.buildConsumerEndpoint(capability, agentAsset.getId(), agent, null);
- if (endpointUri == null)
- throwCapabilityMismatchException(capability);
- from(endpointUri)
- .routeId(routeId)
- .filter(isEventType(InventoryModifiedEvent.class))
- .process(exchange -> {
- handleInventoryModified(
- exchange.getIn().getBody(InventoryModifiedEvent.class)
- );
- });
- agentRouteIds.add(routeId);
- break;
- }
- }
-
- for (ConnectorComponent.Capability capability : connectorComponent.getProducerCapabilities()) {
- switch (capability) {
- case discovery:
- routeId = "Agent Discovery Producer - " + agentAsset.getId();
- endpointUri = connectorComponent.buildProducerEndpoint(capability, agentAsset.getId(), agent);
- if (endpointUri == null)
- throwCapabilityMismatchException(capability);
- from(PRODUCER_DISCOVERY_ROUTE(agentAsset.getId()))
- .routeId(routeId)
- .to(endpointUri);
- agentRouteIds.add(routeId);
- break;
- case inventory:
- routeId = "Agent Inventory Producer - " + agentAsset.getId();
- endpointUri = connectorComponent.buildProducerEndpoint(capability, agentAsset.getId(), agent);
- if (endpointUri == null)
- throwCapabilityMismatchException(capability);
- from(PRODUCER_INVENTORY_ROUTE(agentAsset.getId()))
- .routeId(routeId)
- .to(endpointUri);
- agentRouteIds.add(routeId);
- break;
- case read:
- routeId = "Agent Read Producer - " + agentAsset.getId();
- endpointUri = connectorComponent.buildProducerEndpoint(capability, agentAsset.getId(), agent);
- if (endpointUri == null)
- throwCapabilityMismatchException(capability);
- from(PRODUCER_READ_ROUTE(agentAsset.getId()))
- .routeId(routeId)
- .to(endpointUri);
- agentRouteIds.add(routeId);
- break;
- case write:
- routeId = "Agent Write Producer - " + agentAsset.getId();
- endpointUri = connectorComponent.buildProducerEndpoint(capability, agentAsset.getId(), agent);
- if (endpointUri == null)
- throwCapabilityMismatchException(capability);
- from(PRODUCER_WRITE_ROUTE(agentAsset.getId()))
- .routeId(routeId)
- .to(endpointUri);
- agentRouteIds.add(routeId);
- break;
- }
- }
- }
- };
- }
-
- public RouteBuilder buildDeviceRoutes(Collection<Asset> deviceAssets) throws Exception {
- if (!connectorComponent.getConsumerCapabilities().contains(ConnectorComponent.Capability.listen)) {
- throw new IllegalArgumentException(
- "Connector does not support capability " + ConnectorComponent.Capability.listen + ": " + connectorComponent.getType()
- );
- }
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- for (Asset deviceAsset : deviceAssets) {
- DeviceAttributes deviceAttributes = new DeviceAttributes(deviceAsset.getAttributes());
- String deviceKey = deviceAttributes.getKey();
- String routeId = "Agent Listen Consumer - " + agentAsset.getId() + "(" + deviceKey + ")";
- String endpointUri = connectorComponent.buildConsumerEndpoint(
- ConnectorComponent.Capability.listen, agentAsset.getId(), agent, deviceKey
- );
- from(endpointUri)
- .routeId(routeId)
- .process(exchange -> {
- String receivedDeviceKey = exchange.getIn().getHeader(Controller2Component.HEADER_DEVICE_KEY, String.class);
- String receivedResourceKey = exchange.getIn().getHeader(Controller2Component.HEADER_DEVICE_RESOURCE_KEY, String.class);
- Object value = exchange.getIn().getBody();
- handleResourceValueUpdate(receivedDeviceKey, receivedResourceKey, value);
- });
- deviceRouteIds.add(routeId);
- }
- }
- };
- }
-
- public void stopAgentRoutes(MessageBrokerContext context) throws Exception {
- for (String agentRouteId : agentRouteIds) {
- LOG.fine("Stopping agent route: " + agentRouteId);
- context.stopRoute(agentRouteId);
- context.removeRoute(agentRouteId);
- }
- }
-
- public void stopDeviceRoutes(MessageBrokerContext context) throws Exception {
- for (String deviceRouteId : deviceRouteIds) {
- LOG.fine("Stopping agent device route: " + deviceRouteId);
- context.stopRoute(deviceRouteId);
- context.removeRoute(deviceRouteId);
- }
- }
-
- protected void throwCapabilityMismatchException(ConnectorComponent.Capability capability) {
- throw new IllegalStateException(
- "Capability '" + capability +"' announced but component didn't build endpoint: " + connectorComponent.getType()
- );
- }
-
- protected abstract void handleInventoryModified(InventoryModifiedEvent event);
-
- protected abstract void handleResourceValueUpdate(String deviceKey, String deviceResourceKey, Object value);
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
index 1059c1e44..210633259 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
@@ -19,47 +19,25 @@
*/
package org.openremote.manager.server.agent;
-import org.apache.camel.FailedToCreateRouteException;
import org.apache.camel.builder.RouteBuilder;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.message.MessageBrokerContext;
import org.openremote.container.message.MessageBrokerService;
-import org.openremote.container.persistence.PersistenceEvent;
-import org.openremote.container.util.IdentifierUtil;
import org.openremote.manager.server.asset.AssetService;
import org.openremote.manager.server.asset.ServerAsset;
-import org.openremote.manager.server.event.EventService;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.agent.DeviceResourceValueEvent;
-import org.openremote.manager.shared.agent.InventoryModifiedEvent;
-import org.openremote.manager.shared.asset.Asset;
-import org.openremote.manager.shared.asset.AssetInfo;
import org.openremote.manager.shared.asset.AssetType;
-import org.openremote.manager.shared.attribute.Attributes;
-import org.openremote.manager.shared.connector.ConnectorComponent;
-import java.nio.charset.Charset;
-import java.util.*;
-import java.util.logging.Level;
import java.util.logging.Logger;
-import static org.openremote.container.persistence.PersistenceEvent.Cause.UPDATE;
-import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_EVENT_TOPIC;
-import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForAssetType;
-import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;
-
public class AgentService extends RouteBuilder implements ContainerService {
private static final Logger LOG = Logger.getLogger(AgentService.class.getName());
- final protected Map<String, AgentRoutes> agentInstanceMap = new LinkedHashMap<>();
-
protected MessageBrokerService messageBrokerService;
protected MessageBrokerContext messageBrokerContext;
protected AssetService assetService;
protected ConnectorService connectorService;
- protected AgentServiceEventRoutes agentServiceEventRoutes;
@Override
public void init(Container container) throws Exception {
@@ -67,23 +45,6 @@ public class AgentService extends RouteBuilder implements ContainerService {
messageBrokerContext = messageBrokerService.getContext();
assetService = container.getService(AssetService.class);
connectorService = container.getService(ConnectorService.class);
-
- agentServiceEventRoutes = new AgentServiceEventRoutes(
- new DeviceResourceSubscriptions(container.getService(EventService.class))
- ) {
- @Override
- protected Asset getAsset(String assetId) {
- return assetService.get(assetId);
- }
-
- @Override
- protected void deleteAssetChildren(String parentAssetId) {
- assetService.deleteChildren(parentAssetId);
- }
- };
-
- messageBrokerService.getContext().addRoutes(this);
- messageBrokerService.getContext().addRoutes(agentServiceEventRoutes);
}
@Override
@@ -94,7 +55,7 @@ public class AgentService extends RouteBuilder implements ContainerService {
public void start(Container container) throws Exception {
ServerAsset[] agents = assetService.findByTypeInAllRealms(AssetType.AGENT.getValue());
LOG.fine("Configure agents in all realms:" + agents.length);
- reconfigureAgents(null, agents, null);
+ // reconfigureAgents(null, agents, null);
}
@Override
@@ -103,6 +64,7 @@ public class AgentService extends RouteBuilder implements ContainerService {
@Override
public void configure() throws Exception {
+ /*
// If any agent was modified in the database, reconfigure this service
from(PERSISTENCE_EVENT_TOPIC)
.filter(isPersistenceEventForEntityType(Asset.class))
@@ -114,8 +76,10 @@ public class AgentService extends RouteBuilder implements ContainerService {
LOG.fine("Reconfigure agents of realm '" + agent.getRealm() + "': " + agents.length);
reconfigureAgents(agent.getRealm(), agents, persistenceEvent.getCause() == UPDATE ? agent : null);
});
+ */
}
+ /*
protected void reconfigureAgents(String realm, ServerAsset[] agents, Asset updatedAgent) {
synchronized (agentInstanceMap) {
for (ServerAsset agentAsset : agents) {
@@ -259,21 +223,5 @@ public class AgentService extends RouteBuilder implements ContainerService {
}
}
}
-
- protected void startDeviceRoutes(Asset agentAsset, AgentRoutes agentRoutes) throws Exception {
- // We start listener routes for all device children of the agent asset
- // TODO: We should selectively enable this on a per-device basis
- List<Asset> deviceAssets = new ArrayList<>();
- AssetInfo[] agentChildren = assetService.getChildren(agentAsset.getId());
- for (AssetInfo agentChild : agentChildren) {
- if (agentChild.getWellKnownType() == AssetType.DEVICE) {
- deviceAssets.add(assetService.get(agentChild.getId()));
- }
- }
- messageBrokerContext.addRoutes(agentRoutes.buildDeviceRoutes(deviceAssets));
- }
-
- protected void stopDeviceRoutes(AgentRoutes agentRoutes) throws Exception {
- agentRoutes.stopDeviceRoutes(messageBrokerContext);
- }
+ */
}
\ No newline at end of file
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentServiceEventRoutes.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentServiceEventRoutes.java
deleted file mode 100644
index f7565debd..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentServiceEventRoutes.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2016, 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.manager.server.agent;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.ChoiceDefinition;
-import org.openremote.container.web.socket.UserPredicates;
-import org.openremote.manager.server.event.EventService;
-import org.openremote.manager.shared.agent.*;
-import org.openremote.manager.shared.asset.Asset;
-
-import java.util.logging.Logger;
-
-import static org.openremote.container.web.socket.UserPredicates.isUserInRole;
-import static org.openremote.manager.server.event.EventPredicates.isEventType;
-import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_KEY;
-import static org.openremote.manager.shared.connector.ConnectorComponent.HEADER_DEVICE_RESOURCE_KEY;
-
-/**
- * The messaging routes of all running agent instances, central dispatch.
- */
-public abstract class AgentServiceEventRoutes extends RouteBuilder {
-
- private static final Logger LOG = Logger.getLogger(AgentServiceEventRoutes.class.getName());
-
- final protected DeviceResourceSubscriptions deviceResourceSubscriptions;
-
- public AgentServiceEventRoutes(DeviceResourceSubscriptions deviceResourceSubscriptions) {
- this.deviceResourceSubscriptions = deviceResourceSubscriptions;
- }
-
- @Override
- public void configure() throws Exception {
- ChoiceDefinition incomingEventRoute =
- from(EventService.INCOMING_EVENT_QUEUE)
- .routeId("Agent Service Event Route")
- .choice();
- buildInventoryEventRoute(incomingEventRoute);
- buildDeviceEventRoute(incomingEventRoute);
- }
-
- public DeviceResourceSubscriptions getDeviceResourceSubscriptions() {
- return deviceResourceSubscriptions;
- }
-
- protected void buildInventoryEventRoute(ChoiceDefinition routeDefinition) {
- routeDefinition
- .when(isEventType(RefreshInventoryEvent.class))
- .choice()
- .when(isUserInRole("write:assets"))
- .process(exchange -> {
- String agentAssetId = exchange.getIn().getBody(RefreshInventoryEvent.class).getAgentId();
- Asset agentAsset = getAsset(agentAssetId);
- if (agentAsset == null)
- return;
- LOG.fine("Clearing inventory of agent: " + agentAssetId);
- deleteAssetChildren(agentAssetId);
-
- exchange.getIn().getHeaders().clear();
- exchange.getIn().setBody(null);
-
- exchange.getIn().setHeader(
- "routingSlip",
- AgentRoutes.PRODUCER_DISCOVERY_ROUTE(agentAssetId)
- );
- })
- .routingSlip(header("routingSlip")).ignoreInvalidEndpoints()
- .end()
- .otherwise()
- .to("log:org.openremote.event.forbidden?level=INFO&showAll=true&multiline=true")
- .endChoice();
- }
-
- protected void buildDeviceEventRoute(ChoiceDefinition routeDefinition) {
- routeDefinition
- .when(isEventType(SubscribeDeviceResourceUpdates.class))
- .choice()
- .when(UserPredicates.isUserInRole("read:assets"))
- .process(exchange -> {
- String sessionKey = EventService.getSessionKey(exchange);
- SubscribeDeviceResourceUpdates event = exchange.getIn().getBody(SubscribeDeviceResourceUpdates.class);
- Asset agentAsset = getAsset(event.getAgentId());
- if (agentAsset == null) {
- LOG.fine("Agent with identifier '" + event.getAgentId() + "' not found, ignoring subscription on session: " + sessionKey);
- return;
- }
- deviceResourceSubscriptions.addSubscription(sessionKey, event);
- })
- .otherwise()
- .to("log:org.openremote.event.forbidden?level=INFO&showAll=true&multiline=true")
- .endChoice()
-
- .when(isEventType(UnsubscribeDeviceResourceUpdates.class))
- .choice()
- .when(UserPredicates.isUserInRole("read:assets"))
- .process(exchange -> {
- String sessionKey = EventService.getSessionKey(exchange);
- UnsubscribeDeviceResourceUpdates event = exchange.getIn().getBody(UnsubscribeDeviceResourceUpdates.class);
- deviceResourceSubscriptions.removeSubscription(sessionKey, event);
- })
- .otherwise()
- .to("log:org.openremote.event.forbidden?level=INFO&showAll=true&multiline=true")
- .endChoice()
-
- .when(isEventType(DeviceResourceWrite.class))
- .choice()
- .when(UserPredicates.isUserInRole("write:assets"))
- .process(exchange -> {
- DeviceResourceWrite event = exchange.getIn().getBody(DeviceResourceWrite.class);
- LOG.fine("Processing: " + event);
- exchange.getIn().setHeader(
- "routingSlip",
- AgentRoutes.PRODUCER_WRITE_ROUTE(event.getAgentId())
- );
- exchange.getIn().setHeader(HEADER_DEVICE_KEY, event.getDeviceKey());
- exchange.getIn().setHeader(HEADER_DEVICE_RESOURCE_KEY, event.getDeviceResourceKey());
- exchange.getIn().setBody(event.getValue());
- })
- .routingSlip(header("routingSlip")).ignoreInvalidEndpoints()
- .end()
- .otherwise()
- .to("log:org.openremote.event.forbidden?level=INFO&showAll=true&multiline=true")
- .endChoice()
-
- .when(isEventType(DeviceResourceRead.class))
- .choice()
- .when(UserPredicates.isUserInRole("read:assets"))
- .process(exchange -> {
- DeviceResourceRead event = exchange.getIn().getBody(DeviceResourceRead.class);
- LOG.fine("Processing: " + event);
- exchange.getIn().setHeader(
- "routingSlip",
- AgentRoutes.PRODUCER_READ_ROUTE(event.getAgentId())
- );
- exchange.getIn().setHeader("agentId", event.getAgentId());
- exchange.getIn().setHeader(HEADER_DEVICE_KEY, event.getDeviceKey());
- exchange.getIn().setHeader(HEADER_DEVICE_RESOURCE_KEY, event.getDeviceResourceKey());
- })
- .routingSlip(header("routingSlip"))
- .ignoreInvalidEndpoints()
- .process(exchange -> {
- // TODO value conversion?
- if (exchange.getIn().getBody() != null) {
- DeviceResourceValueEvent event = new DeviceResourceValueEvent(
- exchange.getIn().getHeader("agentId", String.class),
- exchange.getIn().getHeader(HEADER_DEVICE_KEY, String.class),
- exchange.getIn().getHeader(HEADER_DEVICE_RESOURCE_KEY, String.class),
- exchange.getIn().getBody(String.class)
- );
- exchange.getIn().setBody(event);
- } else {
- LOG.fine("Read did not result in a value, ignoring");
- }
- })
- .to(EventService.OUTGOING_EVENT_QUEUE)
- .endChoice()
- .otherwise()
- .to("log:org.openremote.event.forbidden?level=INFO&showAll=true&multiline=true")
- .endChoice();
- }
-
- abstract protected Asset getAsset(String assetId);
-
- abstract protected void deleteAssetChildren(String parentAssetId);
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeMeta.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeMeta.java
new file mode 100644
index 000000000..39db6d0f8
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetAttributeMeta.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2016, 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.manager.shared.asset;
+
+import elemental.json.Json;
+import elemental.json.JsonString;
+import elemental.json.JsonValue;
+import org.openremote.manager.shared.attribute.Attribute;
+import org.openremote.manager.shared.attribute.MetadataItem;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Asset attribute meta item name is an arbitrary string. It should be URI. This enum contains
+ * the well-known URIs for functionality we want to depend on in our platform.
+ * <p>
+ * TODO https://people.eecs.berkeley.edu/~arka/papers/buildsys2015_metadatasurvey.pdf
+ */
+public enum AssetAttributeMeta {
+
+ /**
+ * A human-friendly string that can be displayed in UI instead of the raw attribute name.
+ */
+ LABEL("urn:openremote:asset:meta:label", false),
+
+ /**
+ * A human-friendly string describing the purpose of an attribute.
+ */
+ DESCRIPTION("urn:openremote:asset:meta:description", false),
+
+ /**
+ * Points to semantic description of the attribute, typically a URI.
+ */
+ ABOUT("urn:openremote:asset:meta:about"),
+
+ /**
+ * Default value that might be used when editing an attribute.
+ */
+ DEFAULT("urn:openremote:asset:meta:default", false);
+
+ final protected String name;
+ final protected boolean editable;
+
+ AssetAttributeMeta(String name, boolean editable) {
+ this.name = name;
+ this.editable = editable;
+ }
+
+ AssetAttributeMeta(String name) {
+ this(name, true);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isEditable() {
+ return editable;
+ }
+
+ public JsonString getJsonValue() {
+ return Json.create(getName());
+ }
+
+ public static AssetAttributeMeta[] editable() {
+ List<AssetAttributeMeta> list = new ArrayList<>();
+ for (AssetAttributeMeta meta : values()) {
+ if (meta.isEditable())
+ list.add(meta);
+ }
+ return list.toArray(new AssetAttributeMeta[list.size()]);
+ }
+
+ public static boolean isEditable(String name) {
+ try {
+ return AssetAttributeMeta.valueOf(name).isEditable();
+ } catch (IllegalArgumentException ex) {
+ return false;
+ }
+ }
+
+ public static MetadataItem createMetadataItem(AssetAttributeMeta name, JsonValue value) {
+ return new MetadataItem(name.getName(), value);
+ }
+
+ public static MetadataItem getFirstMetadataItem(Attribute attribute, AssetAttributeMeta meta) {
+ return attribute.hasMetadataItem(meta.getName())
+ ? attribute.getMetadata().first(meta.getName())
+ : null;
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java
index 58eb0db95..feaa91a21 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetType.java
@@ -1,3 +1,22 @@
+/*
+ * Copyright 2016, 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.manager.shared.asset;
import elemental.json.Json;
@@ -9,6 +28,8 @@ import java.util.List;
/**
* Asset type is an arbitrary string. It should be URI. This enum contains
* the well-known URIs for functionality we want to depend on in our platform.
+ *
+ * TODO https://people.eecs.berkeley.edu/~arka/papers/buildsys2015_metadatasurvey.pdf
*/
public enum AssetType {
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java
index 5348f78ec..e1450ee6e 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attribute.java
@@ -127,17 +127,17 @@ public class Attribute {
return jsonObject.hasKey("metadata");
}
- public boolean hasMetadataElement(String name) {
- return hasMetadata() && getMetadata().hasElement(name);
+ public boolean hasMetadataItem(String name) {
+ return hasMetadata() && getMetadata().contains(name);
}
public Metadata getMetadata() {
- return hasMetadata() ? new Metadata(jsonObject.getObject("metadata")) : null;
+ return hasMetadata() ? new Metadata(jsonObject.getArray("metadata")) : null;
}
public Attribute setMetadata(Metadata metadata) {
if (metadata != null) {
- jsonObject.put("metadata", metadata.getJsonObject());
+ jsonObject.put("metadata", metadata.getJsonArray());
} else if (jsonObject.hasKey("metadata")) {
jsonObject.remove("metadata");
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java
index 17a90f0ac..00701d7e9 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Metadata.java
@@ -20,64 +20,114 @@
package org.openremote.manager.shared.attribute;
import elemental.json.Json;
+import elemental.json.JsonArray;
import elemental.json.JsonObject;
+import org.openremote.manager.shared.Function;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
public class Metadata {
- final protected JsonObject jsonObject;
+ final protected JsonArray jsonArray;
public Metadata() {
- this(Json.createObject());
+ this(Json.createArray());
}
- public Metadata(JsonObject jsonObject) {
- this.jsonObject = jsonObject;
+ public Metadata(JsonArray jsonArray) {
+ this.jsonArray = jsonArray;
}
- public JsonObject getJsonObject() {
- return jsonObject;
+ public JsonArray getJsonArray() {
+ return jsonArray;
}
- public MetadataElement[] getElements() {
- Set<MetadataElement> elements = new LinkedHashSet<>();
+ public MetadataItem[] all() {
+ List<MetadataItem> list = asList();
+ return list.toArray(new MetadataItem[list.size()]);
+ }
+
+ public MetadataItem[] get(String name) {
+ List<MetadataItem> list = asList(
+ item -> item.getName().equals(name)
+ );
+ return list.toArray(new MetadataItem[list.size()]);
+ }
- String[] keys = jsonObject.keys();
- for (String key : keys) {
- MetadataElement element = new MetadataElement(key, jsonObject.getObject(key));
- elements.add(element);
+ public MetadataItem get(int index) {
+ return index > 0 && index < jsonArray.length()
+ ? new MetadataItem(jsonArray.getObject(index))
+ : null;
+ }
+
+ public MetadataItem first(String name) {
+ List<MetadataItem> list = asList();
+ for (MetadataItem item : list) {
+ if (item.getName().equals(name))
+ return item;
}
+ return null;
+ }
- return elements.toArray(new MetadataElement[elements.size()]);
+ public boolean contains(String name) {
+ return first(name) != null;
}
- public MetadataElement getElement(String name) {
- return hasElement(name) ? new MetadataElement(name, jsonObject.getObject(name)) : null;
+ public int indexOf(MetadataItem item) {
+ for (int i = 0; i < all().length; i++) {
+ MetadataItem metadataItem = all()[i];
+ if (metadataItem.getName().equals(item.getName()))
+ return i;
+ }
+ return -1;
}
- public boolean hasElement(String name) {
- return jsonObject.hasKey(name);
+ public Metadata add(MetadataItem item) {
+ jsonArray.set(jsonArray.length(), item.getJsonObject());
+ return this;
}
- public Metadata putElement(MetadataElement element) {
- jsonObject.put(element.getName(), element.getJsonObject());
+ public Metadata removeAll(String name) {
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JsonObject jsonObject = jsonArray.getObject(i);
+ MetadataItem item = new MetadataItem(jsonObject);
+ if (name.equals(item.getName()))
+ jsonArray.remove(i);
+ }
return this;
}
- public Metadata removeElement(String name) {
- if (jsonObject.hasKey(name))
- jsonObject.remove(name);
+ public Metadata remove(int index) {
+ if (index > 0 && index < jsonArray.length())
+ jsonArray.remove(index);
return this;
}
public Metadata copy() {
- return new Metadata(Json.parse(getJsonObject().toJson()));
+ return new Metadata((JsonArray) Json.parse(getJsonArray().toJson()));
+ }
+
+ protected List<MetadataItem> asList() {
+ return asList(null);
+ }
+
+ protected List<MetadataItem> asList(Function<MetadataItem, Boolean> filter) {
+ List<MetadataItem> list = new ArrayList<>();
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JsonObject jsonObject = jsonArray.getObject(i);
+ MetadataItem item = new MetadataItem(jsonObject);
+ if (filter == null) {
+ list.add(item);
+ } else if (filter.apply(item)) {
+ list.add(item);
+ }
+ }
+ return list;
}
@Override
public String toString() {
- return jsonObject.toJson();
+ return jsonArray.toJson();
}
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataItem.java
similarity index 61%
rename from manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataItem.java
index 4f9efdcea..caa5f6ee3 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataElement.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/MetadataItem.java
@@ -23,59 +23,53 @@ import elemental.json.Json;
import elemental.json.JsonObject;
import elemental.json.JsonValue;
-public class MetadataElement {
+public class MetadataItem {
- final protected String name;
final protected JsonObject jsonObject;
- public MetadataElement(String name) {
- this(name, Json.createObject());
+ public MetadataItem(JsonObject jsonObject) {
+ this.jsonObject = jsonObject;
}
- public MetadataElement(String name, String type) {
- this(name, Json.createObject());
- setType(type);
+ public MetadataItem(String name) {
+ this(name, null);
}
- public MetadataElement(String name, String type, JsonValue value) {
- this(name, Json.createObject());
- setType(type);
+ public MetadataItem(String name, JsonValue value) {
+ this.jsonObject = Json.createObject();
+ setName(name);
setValue(value);
}
- public MetadataElement(String name, JsonObject jsonObject) {
- this.name = name;
- this.jsonObject = jsonObject;
- }
-
public JsonObject getJsonObject() {
return jsonObject;
}
public String getName() {
- return name;
+ return jsonObject.hasKey("name") ? jsonObject.get("name").asString() : null;
}
- public JsonValue getValue() {
- return jsonObject.hasKey("value") ? jsonObject.get("value") : null;
- }
-
- public MetadataElement setValue(JsonValue value) {
- jsonObject.put("value", value);
+ public MetadataItem setName(String name) {
+ if (name == null || name.length() == 0)
+ throw new IllegalArgumentException("Name can not be empty");
+ jsonObject.put("name", name);
return this;
}
- public String getType() {
- return jsonObject.hasKey("type") ? jsonObject.get("type").asString() : null;
+ public JsonValue getValue() {
+ return jsonObject.hasKey("value") ? jsonObject.get("value") : null;
}
- public MetadataElement setType(String type) {
- jsonObject.put("type", type);
+ public MetadataItem setValue(JsonValue value) {
+ if (value != null) {
+ jsonObject.put("value", value);
+ }
return this;
}
- public MetadataElement copy() {
- return new MetadataElement(getName(), Json.parse(getJsonObject().toJson()));
+
+ public MetadataItem copy() {
+ return new MetadataItem(Json.parse(getJsonObject().toJson()));
}
@Override
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java
index 04d9c54ee..dd6eaff42 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java
@@ -19,11 +19,8 @@
*/
package org.openremote.manager.shared.connector;
-import elemental.json.Json;
import org.openremote.manager.shared.attribute.Attribute;
import org.openremote.manager.shared.attribute.AttributeType;
-import org.openremote.manager.shared.attribute.Metadata;
-import org.openremote.manager.shared.attribute.MetadataElement;
public class ConnectorUtil {
protected ConnectorUtil() {}
@@ -34,6 +31,7 @@ public class ConnectorUtil {
public static Attribute buildConnectorSetting(String attributeName, AttributeType type, String displayName, String description, boolean required, String defaultValue, String defaultValueNote) {
Attribute attribute = new Attribute(attributeName, type);
+ /*
attribute.setMetadata(new Metadata(Json.createObject()));
if (displayName != null && displayName.length() > 0) {
@@ -75,6 +73,7 @@ public class ConnectorUtil {
.setValue(Json.create(true))
);
}
+ */
return attribute;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceResource.java
index d273f8b72..4e5094ff7 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceResource.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceResource.java
@@ -23,8 +23,6 @@ import elemental.json.Json;
import elemental.json.JsonObject;
import org.openremote.manager.shared.attribute.Attribute;
import org.openremote.manager.shared.attribute.AttributeType;
-import org.openremote.manager.shared.attribute.Metadata;
-import org.openremote.manager.shared.attribute.MetadataElement;
/**
* An attribute of an asset that represents a device resource.
@@ -56,11 +54,14 @@ public class DeviceResource extends Attribute {
public static boolean isDeviceResource(Attribute attribute) {
// The given attribute must satisfy the API of this class
+ return false;
+/*
return attribute.hasMetadataElement(DEVICE_RESOURCE)
- && attribute.getMetadata().getElement(DEVICE_RESOURCE).getType().equals(DEVICE_RESOURCE_TYPE)
+ && attribute.getMetadata().getElement(DEVICE_RESOURCE).getName().equals(DEVICE_RESOURCE_TYPE)
&& AttributeType.isValid(attribute.getMetadata().getElement(DEVICE_RESOURCE).getValue().asString())
&& attribute.hasMetadataElement(ACCESS)
- && attribute.getMetadata().getElement(ACCESS).getType().equals(ACCESS_TYPE);
+ && attribute.getMetadata().getElement(ACCESS).getName().equals(ACCESS_TYPE);
+*/
}
public DeviceResource(Attribute attribute) {
@@ -73,6 +74,7 @@ public class DeviceResource extends Attribute {
public DeviceResource(String name, String key, AttributeType resourceType, Access access) {
super(name, AttributeType.STRING, Json.create(key));
+ /*
setMetadata(new Metadata()
.putElement(
new MetadataElement(DEVICE_RESOURCE, DEVICE_RESOURCE_TYPE, Json.create(resourceType.getValue()))
@@ -81,26 +83,37 @@ public class DeviceResource extends Attribute {
new MetadataElement(ACCESS, ACCESS_TYPE, Json.create(access.name()))
)
);
+ */
}
public AttributeType getResourceType() {
+ return null;
+/*
return getMetadata().hasElement(DEVICE_RESOURCE)
&& AttributeType.isValid(getMetadata().getElement(DEVICE_RESOURCE).getValue().asString())
? AttributeType.fromValue(getMetadata().getElement(DEVICE_RESOURCE).getValue().asString())
: null;
+*/
}
public Access getAccess() {
+ return null;
+/*
return getMetadata().hasElement(ACCESS)
? Access.valueOf(getMetadata().getElement(ACCESS).getValue().asString())
: null;
+*/
}
public boolean isPassive() {
+ return false;
+/*
return getMetadata().hasElement(PASSIVE) && getMetadata().getElement(PASSIVE).getValue().asBoolean();
+*/
}
public DeviceResource setPassive(boolean passive) {
+/*
if (passive) {
getMetadata().putElement(
new MetadataElement(PASSIVE, AttributeType.BOOLEAN.getValue(), Json.create(true))
@@ -108,14 +121,19 @@ public class DeviceResource extends Attribute {
} else {
getMetadata().removeElement(PASSIVE);
}
+*/
return this;
}
public boolean isConstant() {
+ return false;
+/*
return getMetadata().hasElement(CONSTANT) && getMetadata().getElement(CONSTANT).getValue().asBoolean();
+*/
}
public DeviceResource setConstant(boolean constant) {
+/*
if (constant) {
getMetadata().putElement(
new MetadataElement(CONSTANT, AttributeType.BOOLEAN.getValue(), Json.create(true))
@@ -123,6 +141,7 @@ public class DeviceResource extends Attribute {
} else {
getMetadata().removeElement(CONSTANT);
}
+*/
return this;
}
diff --git a/manager/test/build.gradle b/manager/test/build.gradle
index 3b0a3e1a6..8b6f67612 100644
--- a/manager/test/build.gradle
+++ b/manager/test/build.gradle
@@ -7,7 +7,6 @@ dependencies {
compile project(":manager:server")
compile project(":manager:client")
- compile project(":manager:connector:controller2")
compile "junit:junit:$junitVersion"
compile "org.spockframework:spock-core:$spockVersion"
diff --git a/manager/test/src/test/groovy/org/openremote/test/ngsi/EntityModelTest.groovy b/manager/test/src/test/groovy/org/openremote/test/ngsi/EntityModelTest.groovy
index e0cef06c3..8bba3b6f6 100644
--- a/manager/test/src/test/groovy/org/openremote/test/ngsi/EntityModelTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/ngsi/EntityModelTest.groovy
@@ -7,8 +7,11 @@ import org.openremote.manager.shared.ngsi.KeyValueEntity
import org.openremote.manager.shared.ngsi.Metadata
import org.openremote.manager.shared.ngsi.Model
import org.openremote.manager.shared.ngsi.ModelValidationError
+import spock.lang.Ignore
import spock.lang.Specification
+// TODO We don't use NGSI anymore
+@Ignore
class EntityModelTest extends Specification {
def "Invalid characters in NGSI fields"() {
@@ -74,11 +77,11 @@ class EntityModelTest extends Specification {
assert entity.hasAttribute("temperature");
def pressure = entity.getAttribute("pressure");
- assert pressure.getValue().asNumber() == 720;
- assert pressure.getMetadata().getElements().length == 0;
+ assert pressure.getName().asNumber() == 720;
+ assert pressure.getMetadata().all().length == 0;
def temperature = entity.getAttribute("temperature");
- assert temperature.getValue().asNumber() == new Double(26.5);
+ assert temperature.getName().asNumber() == new Double(26.5);
Metadata temperatureMetadata = temperature.getMetadata();
assert temperatureMetadata.getElements().length == 1;
@@ -123,9 +126,9 @@ class EntityModelTest extends Specification {
assert entity.hasAttribute("temperature");
def pressure = entity.getAttribute("pressure");
- assert pressure.getValue().asNumber() == 720;
+ assert pressure.getName().asNumber() == 720;
def temperature = entity.getAttribute("temperature");
- assert temperature.getValue().asNumber() == new Double(26.5);
+ assert temperature.getName().asNumber() == new Double(26.5);
}
}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index b93f0726c..1af28307d 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -7,5 +7,4 @@ include "postgresql",
"manager:shared",
"manager:server",
"manager:client",
- "manager:connector:controller2",
"manager:test"