Skip to content

armgit / core

Public Imported from GitHub
0

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

Added ConnectorComponent interface for agent connectors and changed connector initialisation to use interface methods

Rich Turner00488c54eae3
diff --git a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
index fdab685cb..11a040816 100644
--- a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
+++ b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Component.java
@@ -19,21 +19,61 @@
*/
package org.openremote.agent.controller2;
+import elemental.json.Json;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
+import org.openremote.manager.shared.attribute.AttributeType;
+import org.openremote.manager.shared.connector.ConnectorComponent;
+import org.openremote.manager.shared.connector.ConnectorUtil;
+import org.openremote.manager.shared.device.InventoryCapabilities;
+import org.openremote.manager.shared.attribute.Attributes;
import java.net.URI;
import java.util.Map;
-public class Controller2Component extends UriEndpointComponent {
-
+public class Controller2Component extends UriEndpointComponent 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>/([<device URI>/<resource URI>]|[discovery|inventory])[?username=username&password=secret]";
-
public static final String HEADER_DEVICE_URI = Controller2Component.class.getCanonicalName() + ".HEADER_DEVICE_URI";
public static final String HEADER_RESOURCE_URI = Controller2Component.class.getCanonicalName() + ".HEADER_RESOURCE_URI";
public static final String HEADER_COMMAND_VALUE = Controller2Component.class.getCanonicalName() + ".HEADER_COMMAND_VALUE";
-
protected final Controller2Adapter.Manager adapterManager;
+ protected static final Attributes agentSettings;
+
+ static {
+ agentSettings = new Attributes();
+ agentSettings.add(ConnectorUtil.buildConnectorSetting(
+ "host",
+ AttributeType.STRING,
+ "Host/IP Address",
+ "The OR Controller network hostname or IP address",
+ true
+ ));
+ agentSettings.add(ConnectorUtil.buildConnectorSetting(
+ "port",
+ AttributeType.INTEGER,
+ "Port",
+ "The OR Controller network port number",
+ true,
+ "8868",
+ null
+ ));
+ agentSettings.add(ConnectorUtil.buildConnectorSetting(
+ "username",
+ AttributeType.STRING,
+ "Username",
+ "The OR Controller Username",
+ false
+ ));
+ agentSettings.add(ConnectorUtil.buildConnectorSetting(
+ "password",
+ AttributeType.STRING,
+ "Password",
+ "The OR Controller Password",
+ false
+ ));
+ }
public Controller2Component(Controller2Adapter.Manager adapterManager) {
super(Controller2Endpoint.class);
@@ -59,4 +99,70 @@ public class Controller2Component extends UriEndpointComponent {
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 boolean supportsAgentDiscovery() {
+ return true;
+ }
+
+ @Override
+ public Attributes getAgentSettings() {
+ return agentSettings;
+ }
+
+ @Override
+ public Attributes getAgentDiscoverySettings() {
+ return null;
+ }
+
+ @Override
+ public InventoryCapabilities getCapabilities(Attributes agentSettings) {
+ return null;
+ }
+
+ @Override
+ public String getAgentStatusUri(Attributes agentSettings) {
+ return null;
+ }
+
+ @Override
+ public String getDeviceInventoryUri(Attributes agentSettings) {
+ return null;
+ }
+
+ @Override
+ public String getDeviceDiscoveryUri(Attributes agentSettings) {
+ return null;
+ }
+
+ @Override
+ public String getDevicesUri(Attributes agentSettings) {
+ return null;
+ }
+
+ @Override
+ public String getDeviceMonitorUri(Attributes agentSettings) {
+ return null;
+ }
+
+ @Override
+ public String getAgentDiscoveryUri(Attributes discoverySettings) {
+ return null;
+ }
+
+ @Override
+ public boolean supportsDeviceMonitoring(Attributes agentSettings) {
+ return false;
+ }
}
diff --git a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java
index 6a8fdca91..6bce1610f 100644
--- a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java
+++ b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2Endpoint.java
@@ -130,6 +130,8 @@ public class Controller2Endpoint extends DefaultEndpoint {
adapterManager.closeAdapter(adapter);
}
+
+
@Override
public Producer createProducer() throws Exception {
if (isDiscovery) {
diff --git a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java
index 542a4d0e5..59b97a497 100644
--- a/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java
+++ b/connector/controller2/src/main/java/org/openremote/agent/controller2/Controller2InventoryConsumer.java
@@ -6,10 +6,10 @@ import org.openremote.manager.shared.device.Device;
import java.util.logging.Logger;
-import static org.openremote.manager.shared.connector.ConnectorInventory.Action.ADD;
-import static org.openremote.manager.shared.connector.ConnectorInventory.Action.REMOVE;
-import static org.openremote.manager.shared.connector.ConnectorInventory.Action.UPDATE;
-import static org.openremote.manager.shared.connector.ConnectorInventory.HEADER_DEVICE_ACTION;
+import static org.openremote.manager.shared.device.DeviceInventory.Action.ADD;
+import static org.openremote.manager.shared.device.DeviceInventory.Action.REMOVE;
+import static org.openremote.manager.shared.device.DeviceInventory.Action.UPDATE;
+import static org.openremote.manager.shared.device.DeviceInventory.HEADER_DEVICE_ACTION;
public class Controller2InventoryConsumer extends Controller2Consumer implements Controller2Adapter.DeviceListener {
diff --git a/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties b/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties
index be281173f..f5cc62f89 100644
--- a/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties
+++ b/connector/controller2/src/main/resources/META-INF/services/org/apache/camel/component.properties
@@ -1,4 +1 @@
-components=controller2
-openremote-connector-type=urn:openremote:connector:controller2
-openremote-connector-supports-discovery=true
-openremote-connector-supports-inventory=true
\ No newline at end of file
+components=controller2
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java
index ba236d72a..9208d1ebc 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgent.java
@@ -21,6 +21,7 @@ package org.openremote.manager.client.admin.agent;
import org.openremote.manager.client.admin.AdminContent;
import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorImpl;
public interface AdminAgent extends AdminContent {
@@ -34,7 +35,7 @@ public interface AdminAgent extends AdminContent {
void cancel();
- void onConnectorSelected(Connector connector);
+ void onConnectorSelected(ConnectorImpl connector);
}
void setPresenter(Presenter presenter);
@@ -49,9 +50,9 @@ public interface AdminAgent extends AdminContent {
void clearFormMessagesSuccess();
- void setConnectors(Connector[] connectors);
+ void setConnectors(ConnectorImpl[] connectors);
- void setAssignedConnector(Connector connector);
+ void setAssignedConnector(ConnectorImpl connector);
void setName(String name);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java
index fc11d99df..812abae34 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentActivity.java
@@ -34,7 +34,9 @@ import org.openremote.manager.shared.Runnable;
import org.openremote.manager.shared.agent.Agent;
import org.openremote.manager.shared.agent.AgentResource;
import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorImpl;
import org.openremote.manager.shared.connector.ConnectorResource;
+import org.openremote.manager.shared.connector.ConnectorUtil;
import org.openremote.manager.shared.event.ui.ShowInfoEvent;
import javax.inject.Inject;
@@ -60,13 +62,13 @@ public class AdminAgentActivity
final protected ConnectorArrayMapper connectorArrayMapper;
protected String id;
- protected Connector[] connectors;
+ protected ConnectorImpl[] connectors;
protected Agent agent;
- protected Connector assignedConnector;
+ protected ConnectorImpl assignedConnector;
// This is a dummy we use when the Agent's assigned connector is not installed
- protected final Connector notFoundConnector = new Connector();
- protected final String notFoundConnectorId = "NOT_FOUND_CONNECTOR_ID";
+ protected final ConnectorImpl notFoundConnector = new ConnectorImpl();
+ protected final String notFoundConnectorType = "NOT_FOUND_CONNECTOR";
@Inject
public AdminAgentActivity(AdminView adminView,
@@ -92,7 +94,7 @@ public class AdminAgentActivity
this.agentMapper = agentMapper;
this.connectorArrayMapper = connectorArrayMapper;
- notFoundConnector.setId(notFoundConnectorId);
+ notFoundConnector.setType(notFoundConnectorType);
}
@Override
@@ -220,7 +222,7 @@ public class AdminAgentActivity
}
@Override
- public void onConnectorSelected(Connector connector) {
+ public void onConnectorSelected(ConnectorImpl connector) {
assignedConnector = connector;
adminContent.setAssignedConnector(connector);
}
@@ -271,7 +273,7 @@ public class AdminAgentActivity
protected void findAssignedConnector() {
assignedConnector = null;
if (agent != null && agent.getConnectorType() != null) {
- for (Connector connector : connectors) {
+ for (ConnectorImpl connector : connectors) {
if (connector.getType().equals(agent.getConnectorType())) {
assignedConnector = connector;
break;
@@ -280,7 +282,7 @@ public class AdminAgentActivity
if (assignedConnector != null) {
assignedConnector.readSettings(agent);
} else if (!Agent.NO_CONNECTOR_ASSIGNED_TYPE.equals(agent.getConnectorType())){
- notFoundConnector.setName(
+ notFoundConnector.setDisplayName(
agent.getConnectorType() + " (" + managerMessages.connectorNotInstalled() + ")"
);
assignedConnector = notFoundConnector;
@@ -290,7 +292,7 @@ public class AdminAgentActivity
protected void setAssignedConnector() {
if (assignedConnector != null) {
- if (!assignedConnector.getId().equals(notFoundConnectorId)) {
+ if (!assignedConnector.getType().equals(notFoundConnectorType)) {
agent.setConnectorType(assignedConnector.getType());
assignedConnector.writeSettings(agent);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java
index 629722e5a..92b04285d 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AdminAgentImpl.java
@@ -33,6 +33,7 @@ import org.openremote.manager.client.widget.FormGroup;
import org.openremote.manager.client.widget.PushButton;
import org.openremote.manager.shared.attribute.Attributes;
import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorImpl;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -76,7 +77,7 @@ public class AdminAgentImpl extends AttributesFormView implements AdminAgent {
SimpleCheckBox enabledCheckBox;
@UiField(provided = true)
- ValueListBox<Connector> connectorListBox;
+ ValueListBox<ConnectorImpl> connectorListBox;
@UiField
FlowPanel attributesContainer;
@@ -98,12 +99,12 @@ public class AdminAgentImpl extends AttributesFormView implements AdminAgent {
@Inject
public AdminAgentImpl(ManagerMessages managerMessages) {
- connectorListBox = new ValueListBox<>(new AbstractRenderer<Connector>() {
+ connectorListBox = new ValueListBox<>(new AbstractRenderer<ConnectorImpl>() {
@Override
- public String render(Connector connector) {
+ public String render(ConnectorImpl connector) {
if (connector == null)
return managerMessages.noConnectorAssigned();
- return connector.getName();
+ return connector.getDisplayName();
}
});
@@ -111,7 +112,7 @@ public class AdminAgentImpl extends AttributesFormView implements AdminAgent {
initWidget(ui.createAndBindUi(this));
connectorListBox.addValueChangeHandler(event -> {
- Connector connector = event.getValue();
+ ConnectorImpl connector = event.getValue();
if (presenter != null) {
presenter.onConnectorSelected(connector);
}
@@ -131,20 +132,21 @@ public class AdminAgentImpl extends AttributesFormView implements AdminAgent {
}
@Override
- public void setConnectors(Connector[] connectors) {
+ public void setConnectors(ConnectorImpl[] connectors) {
connectorListBox.setAcceptableValues(Arrays.asList(connectors));
}
@Override
- public void setAssignedConnector(Connector connector) {
+ public void setAssignedConnector(ConnectorImpl connector) {
connectorListBox.setValue(connector);
attributesContainer.clear();
if (connector != null) {
+
FormGroup[] attributeFormGroups = createAttributeFormGroups(
style.connectorAttributeTextBox(),
- new Attributes(connector.getSettings())
+ connector.getAgentSettings()
);
for (FormGroup attributeFormGroup : attributeFormGroups) {
attributesContainer.add(attributeFormGroup);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AttributesMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AttributesMapper.java
new file mode 100644
index 000000000..d1889e88c
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/AttributesMapper.java
@@ -0,0 +1,35 @@
+/*
+ * 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.client.admin.agent;
+
+import com.github.nmorel.gwtjackson.client.ObjectMapper;
+import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
+import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;
+import org.openremote.manager.shared.agent.Agent;
+import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.http.EntityReader;
+import org.openremote.manager.shared.http.EntityWriter;
+
+@JsonMixIns({@JsonMixIns.JsonMixIn(target = Attributes.class, mixIn = DefaultJsonMixin.class)})
+public interface AttributesMapper
+ extends ObjectMapper<Attributes>,
+ EntityReader<Attributes>,
+ EntityWriter<Attributes> {
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java
index e8d26494b..22bbed874 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/agent/ConnectorArrayMapper.java
@@ -22,13 +22,13 @@ package org.openremote.manager.client.admin.agent;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;
-import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorImpl;
import org.openremote.manager.shared.http.EntityReader;
import org.openremote.manager.shared.http.EntityWriter;
-@JsonMixIns({@JsonMixIns.JsonMixIn(target = Connector.class, mixIn = DefaultJsonMixin.class)})
+@JsonMixIns({@JsonMixIns.JsonMixIn(target = ConnectorImpl.class, mixIn = DefaultJsonMixin.class)})
public interface ConnectorArrayMapper
- extends ObjectMapper<Connector[]>,
- EntityReader<Connector[]>,
- EntityWriter<Connector[]> {
+ extends ObjectMapper<ConnectorImpl[]>,
+ EntityReader<ConnectorImpl[]>,
+ EntityWriter<ConnectorImpl[]> {
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java
index 876b67d33..a60098ddc 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java
@@ -20,7 +20,9 @@
package org.openremote.manager.server.agent;
import org.openremote.container.web.WebResource;
+import org.openremote.manager.shared.connector.ConnectorComponent;
import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorImpl;
import org.openremote.manager.shared.connector.ConnectorResource;
import org.openremote.manager.shared.http.RequestParams;
@@ -37,8 +39,12 @@ public class ConnectorResourceImpl extends WebResource implements ConnectorResou
@Override
public Connector[] getConnectors(@BeanParam RequestParams requestParams) {
- Collection<Connector> connectors = connectorService.getConnectors().values();
- return connectors.toArray(new Connector[connectors.size()]);
+ Collection<ConnectorComponent> connectors = connectorService.getConnectors().values();
+
+ return connectors
+ .stream()
+ .map(c -> new ConnectorImpl(c.getType(), c.getDisplayName(), c.supportsAgentDiscovery(), c.getAgentSettings(), c.getAgentDiscoverySettings()))
+ .toArray(size -> new Connector[size]);
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java
index 4fbed7c0e..7eb11fa52 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java
@@ -35,7 +35,7 @@ import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.util.IdentifierUtil;
import org.openremote.container.web.WebService;
import org.openremote.manager.shared.attribute.*;
-import org.openremote.manager.shared.connector.Connector;
+import org.openremote.manager.shared.connector.ConnectorComponent;
import javax.validation.constraints.NotNull;
import java.lang.reflect.Field;
@@ -48,7 +48,7 @@ public class ConnectorService implements ContainerService {
private static final Logger LOG = Logger.getLogger(ConnectorService.class.getName());
- final protected Map<String, Connector> connectors = new LinkedHashMap<>();
+ final protected Map<String, ConnectorComponent> connectors = new LinkedHashMap<>();
@Override
public void init(Container container) throws Exception {
@@ -73,206 +73,47 @@ public class ConnectorService implements ContainerService {
}
- public Map<String, Connector> getConnectors() {
+ public Map<String, ConnectorComponent> getConnectors() {
return connectors;
}
- public Connector getConnectorByType(String connectorType) {
- for (Connector connector : connectors.values()) {
+ public ConnectorComponent getConnectorByType(String connectorType) {
+ for (ConnectorComponent connector : connectors.values()) {
if (connector.getType().equals(connectorType))
return connector;
}
return null;
}
- public String getConnectorComponent(Connector connector) {
- for (Map.Entry<String, Connector> entry : connectors.entrySet()) {
- if (entry.getValue().getType().equals(connector.getType())) {
- return entry.getKey();
- }
- }
- return null;
- }
-
protected void findConnectors(CamelContext context) throws Exception {
for (Map.Entry<String, Properties> entry : CamelContextHelper.findComponents(context).entrySet()) {
- String connectorComponentName = entry.getKey();
-
- Properties properties = entry.getValue();
- Object connectorType = properties.get(Connector.PROPERTY_TYPE);
- if (connectorType != null) {
- Component component = context.getComponent(connectorComponentName);
- if (component == null) {
- throw new IllegalStateException(
- "Configured component for connector '" + connectorType + "' not available in context: " + connectorComponentName
- );
- }
- if (component instanceof UriEndpointComponent) {
- UriEndpointComponent uriEndpointComponent = (UriEndpointComponent) component;
+ String connectorComponentName = entry.getKey();
+ Component component = context.getComponent(connectorComponentName);
- Connector connector = createConnector(
- connectorComponentName,
- properties,
- uriEndpointComponent
- );
+ if (component instanceof ConnectorComponent) {
+ ConnectorComponent connector = (ConnectorComponent)component;
- for (Connector existingConnector : connectors.values()) {
- if (existingConnector.getType().equals(connector.getType())) {
- throw new IllegalStateException(
- "Duplicate connector types are not allowed: " + connector.getType()
- );
- }
+ for (ConnectorComponent existingConnector : connectors.values()) {
+ if (existingConnector.getType().equals(connector.getType())) {
+ throw new IllegalStateException(
+ "Duplicate connector types are not allowed: " + connector.getType()
+ );
}
-
- LOG.info(
- "Configured connector component '" + connectorComponentName + "' of type: " + connectorType
- );
-
- connectors.put(connectorComponentName, connector);
-
- } else {
- LOG.warning(
- "Component should implement " +
- UriEndpointComponent.class.getName() + ": " + entry.getKey()
- );
}
- }
- }
- }
- protected Connector createConnector(String connectorComponentName,
- Properties componentProperties,
- UriEndpointComponent component) {
+ LOG.info(
+ "Configured connector component '" + connectorComponentName + "' of type: " + connector.getType()
+ );
- LOG.fine("Creating connector: " + connectorComponentName);
- Connector connector = new Connector(IdentifierUtil.generateGlobalUniqueId());
- connector.setType(componentProperties.get(Connector.PROPERTY_TYPE).toString());
-
- UriEndpoint uriEndpoint = component.getEndpointClass().getAnnotation(UriEndpoint.class);
- if (uriEndpoint == null) {
- throw new RuntimeException(
- "The @UriEndpoint annotation is required on the component endpoint class: " + component.getEndpointClass()
- );
- }
- if (uriEndpoint.title() == null) {
- throw new RuntimeException(
- "The @UriEndpoint annotation requires the title attribute on the component endpoint class: " + component.getEndpointClass()
- );
- }
- connector.setName(uriEndpoint.title());
-
- if (uriEndpoint.syntax() != null) {
- connector.setSyntax(uriEndpoint.syntax());
- }
-
- Object supportsDiscovery = componentProperties.get(Connector.PROPERTY_SUPPORTS_DISCOVERY);
- if (supportsDiscovery != null) {
- connector.setSupportsDiscovery(Boolean.valueOf(supportsDiscovery.toString()));
- }
-
- Object supportsInventory = componentProperties.get(Connector.PROPERTY_SUPPORTS_INVENTORY);
- if (supportsInventory != null) {
- connector.setSupportsInventory(Boolean.valueOf(supportsInventory.toString()));
- }
-
- Attributes settings = buildConnectorSettings(
- connectorComponentName,
- component.createComponentConfiguration(),
- component.getEndpointClass()
- );
+ connectors.put(connectorComponentName, connector);
- connector.setSettings(settings.getJsonObject());
-
- return connector;
- }
-
- protected Attributes buildConnectorSettings(String connectorComponentName,
- ComponentConfiguration componentConfiguration,
- Class<? extends Endpoint> endpointClass) {
-
- Attributes settings = new Attributes();
-
- for (Map.Entry<String, ParameterConfiguration> configEntry : componentConfiguration.getParameterConfigurationMap().entrySet()) {
- try {
- Field field = endpointClass.getDeclaredField(configEntry.getKey());
- if (field.isAnnotationPresent(UriParam.class)) {
- Attribute setting = buildConnectorSetting(field, connectorComponentName);
- settings.add(setting);
- LOG.fine("Adding connector setting: " + setting);
- }
- } catch (NoSuchFieldException ex) {
- // Ignoring setting if there is no annotated field on endpoint class
- // TODO: Inheritance of endpoint classes? Do we care?
+ } else {
+ LOG.warning(
+ "Component should implement " +
+ UriEndpointComponent.class.getName() + ": " + entry.getKey()
+ );
}
}
-
- return settings;
}
-
- protected Attribute buildConnectorSetting(Field field, String connectorComponentName) {
- UriParam uriParam = field.getAnnotation(UriParam.class);
-
- String attributeName = uriParam.name().length() != 0 ? uriParam.name() : field.getName();
-
- Attribute attribute = new Attribute(attributeName, Json.createObject());
- attribute.setMetadata(new Metadata(Json.createObject()));
-
- if (String.class.isAssignableFrom(field.getType())) {
- attribute.setType(AttributeType.STRING);
- } else if (Integer.class.isAssignableFrom(field.getType())) {
- attribute.setType(AttributeType.INTEGER);
- } else if (Double.class.isAssignableFrom(field.getType())) {
- attribute.setType(AttributeType.FLOAT);
- } else if (Boolean.class.isAssignableFrom(field.getType())) {
- attribute.setType(AttributeType.BOOLEAN);
- } else {
- throw new RuntimeException(
- "Unsupported endpoint attribute type of connector'" + connectorComponentName + "': " + field.getType()
- );
- }
-
- if (uriParam.label().length() > 0) {
- attribute.getMetadata().addElement(
- new MetadataElement("label", Json.createObject())
- .setType(AttributeType.STRING.getName())
- .setValue(Json.create(uriParam.label()))
- );
- }
-
- if (uriParam.description().length() > 0) {
- attribute.getMetadata().addElement(
- new MetadataElement("description", Json.createObject())
- .setType(AttributeType.STRING.getName())
- .setValue(Json.create(uriParam.description()))
- );
- }
-
- if (uriParam.defaultValue().length() > 0) {
- attribute.getMetadata().addElement(
- new MetadataElement("defaultValue", Json.createObject())
- .setType(AttributeType.STRING.getName())
- .setValue(Json.create(uriParam.defaultValue()))
- );
- }
-
- if (uriParam.defaultValueNote().length() > 0) {
- attribute.getMetadata().addElement(
- new MetadataElement("defaultValueNote", Json.createObject())
- .setType(AttributeType.STRING.getName())
- .setValue(Json.create(uriParam.defaultValueNote()))
- );
- }
-
- if (field.isAnnotationPresent(NotNull.class)) {
- attribute.getMetadata().addElement(
- new MetadataElement("required", Json.createObject())
- .setType(AttributeType.BOOLEAN.getName())
- .setValue(Json.create(true))
- );
- }
-
- return attribute;
- }
-
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentStatus.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentStatus.java
new file mode 100644
index 000000000..1db2fc451
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentStatus.java
@@ -0,0 +1,27 @@
+/*
+ * 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.agent;
+
+public enum AgentStatus {
+ UNAVAILABLE,
+ AVAILABLE,
+ INVALID_CREDENTIALS,
+ INVALID_SETTINGS
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java
index cee84bf3f..a1f216053 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/Attributes.java
@@ -19,19 +19,38 @@
*/
package org.openremote.manager.shared.attribute;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonUnwrapped;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import elemental.json.JsonObject;
+import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
+@JsonSerialize(using = AttributesSerializer.class)
+@JsonDeserialize(using = AttributesDeserializer.class)
public class Attributes {
-
final protected JsonObject jsonObject;
public Attributes() {
this(elemental.json.Json.createObject());
}
+ @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public Attributes(JsonObject jsonObject) {
this.jsonObject = jsonObject;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/AttributesDeserializer.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/AttributesDeserializer.java
new file mode 100644
index 000000000..10a26cb53
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/AttributesDeserializer.java
@@ -0,0 +1,47 @@
+/*
+ * 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.attribute;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import elemental.json.Json;
+
+import java.io.IOException;
+
+public class AttributesDeserializer extends StdDeserializer<Attributes> {
+ public AttributesDeserializer() {
+ this(null);
+ }
+
+ public AttributesDeserializer(Class<Attributes> t) {
+ super(t);
+ }
+
+ @Override
+ public Attributes deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
+ return new Attributes(Json.parse(p.getText()));
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/attribute/AttributesSerializer.java b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/AttributesSerializer.java
new file mode 100644
index 000000000..5b6e4d980
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/attribute/AttributesSerializer.java
@@ -0,0 +1,43 @@
+/*
+ * 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.attribute;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+import java.io.IOException;
+
+public class AttributesSerializer extends StdSerializer<Attributes> {
+ public AttributesSerializer() {
+ this(null);
+ }
+
+ public AttributesSerializer(Class<Attributes> t) {
+ super(t);
+ }
+
+ @Override
+ public void serialize(Attributes value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
+ jgen.writeObject(value.getJsonObject());
+ //jgen.writeRaw(value.toString());
+ }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
index b87ac8a36..6d69b85ad 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
@@ -1,161 +1,58 @@
-/*
- * 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.connector;
-
-import elemental.json.JsonObject;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.attribute.Attribute;
-import org.openremote.manager.shared.attribute.Attributes;
-
-import java.util.logging.Logger;
-
-/**
- * Interface for agent connectors that is used to connect and communicate with agents
- * in an agnostic way. (That is, a Camel component with the required endpoints.)
- */
-public class Connector {
-
- private static final Logger LOG = Logger.getLogger(Connector.class.getName());
-
- // Camel components which are OR connectors must have this in component.properties
- public static final String PROPERTY_TYPE = "openremote-connector-type";
- public static final String PROPERTY_SUPPORTS_DISCOVERY = "openremote-connector-supports-discovery";
- public static final String PROPERTY_SUPPORTS_INVENTORY = "openremote-connector-supports-inventory";
-
- protected String id;
- protected String name;
- protected String type;
- protected String syntax;
- protected boolean supportsDiscovery;
- protected boolean supportsInventory;
- protected JsonObject settings;
-
- public Connector() {
- }
-
- public Connector(String id) {
- this.id = id;
- }
-
- public Connector(String id, String name, String type) {
- this(id);
- this.name = name;
- this.type = type;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getSyntax() {
- return syntax;
- }
-
- public void setSyntax(String syntax) {
- this.syntax = syntax;
- }
-
- public boolean isSupportsDiscovery() {
- return supportsDiscovery;
- }
-
- public void setSupportsDiscovery(boolean supportsDiscovery) {
- this.supportsDiscovery = supportsDiscovery;
- }
-
- public boolean isSupportsInventory() {
- return supportsInventory;
- }
-
- public void setSupportsInventory(boolean supportsInventory) {
- this.supportsInventory = supportsInventory;
- }
-
- public JsonObject getSettings() {
- return settings;
- }
-
- public void setSettings(JsonObject settings) {
- this.settings = settings;
- }
-
- /**
- * Copy all settings which have a value into the {@link Agent}, keeping the value
- * of each attribute but not the attribute metadata.
- */
- public void writeSettings(Agent agent) {
- if (getSettings() == null) {
- agent.setConnectorSettings(null);
- return;
- }
- Attributes settings = new Attributes(getSettings());
- Attributes agentConnectorSettings = new Attributes();
- for (Attribute attribute : settings.get()) {
- if (attribute.getValue() == null)
- continue;
- Attribute agentConnectorAttribute = new Attribute(attribute.getName(), attribute.getType());
- agentConnectorAttribute.setValue(attribute.getValue());
- agentConnectorSettings.add(agentConnectorAttribute);
- }
- agent.setConnectorSettings(agentConnectorSettings.getJsonObject());
- }
-
- /**
- * Read the value for each settings attribute from the {@link Agent}, skipping any
- * unknown attribute or attribute that doesn't have the right type. The
- * {@link Agent#connectorSettings} can be "cleaned up" so they match a {@link Connector}
- * by calling {@link #readSettings(Agent)} followed by {@link #writeSettings(Agent)}.
- */
- public void readSettings(Agent agent) {
- if (agent.getConnectorSettings() == null)
- return;
-
- Attributes settings = new Attributes(getSettings());
- Attributes agentConnectorSettings = new Attributes(agent.getConnectorSettings());
- for (Attribute agentConnectorAttribute : agentConnectorSettings.get()) {
- Attribute settingsAttribute = settings.get(agentConnectorAttribute.getName());
- if (settingsAttribute != null
- && settingsAttribute.getType().equals(agentConnectorAttribute.getType())) {
- settingsAttribute.setValue(agentConnectorAttribute.getValue());
- }
- }
- }
-
-}
+/*
+ * 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.connector;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import org.openremote.manager.shared.attribute.Attributes;
+
+public interface Connector {
+ /**
+ * Get the unique type descriptor for this connector component
+ */
+ @JsonInclude
+ String getType();
+
+ /**
+ * Get the friendly display name for this connector component
+ */
+ @JsonInclude
+ String getDisplayName();
+
+ /**
+ * Indicates whether or not this connector component supports
+ * discovery of Agents (connector instances).
+ */
+ @JsonInclude
+ boolean supportsAgentDiscovery();
+
+ /**
+ * Create a new set of attributes defining the configurable settings for
+ * agent discovery on this connector.
+ */
+ @JsonInclude
+ Attributes getAgentDiscoverySettings();
+
+ /**
+ * Create a new set of attributes defining the configurable settings for
+ * an agent that uses this connector.
+ */
+ @JsonInclude
+ Attributes getAgentSettings();
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java
new file mode 100644
index 000000000..b30b04ecd
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java
@@ -0,0 +1,142 @@
+/*
+ * 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.connector;
+
+import org.openremote.manager.shared.attribute.Attributes;
+import org.openremote.manager.shared.device.InventoryCapabilities;
+import org.openremote.manager.shared.agent.AgentStatus;
+import org.openremote.manager.shared.device.Device;
+
+public interface ConnectorComponent extends Connector {
+ public static final String HEADER_DISCOVERY_START = ConnectorComponent.class.getCanonicalName() + ".HEADER_DISCOVERY_START";
+ public static final String HEADER_DISCOVERY_STOP = ConnectorComponent.class.getCanonicalName() + ".HEADER_DISCOVERY_STOP";
+ public static final String HEADER_INVENTORY_ACTION = ConnectorComponent.class.getCanonicalName() + ".HEADER_INVENTORY_ACTION";
+ public static final String HEADER_DEVICE_ACTION = ConnectorComponent.class.getCanonicalName() + ".HEADER_DEVICE_ACTION";
+ public static final String ACTION_CREATE = "CREATE";
+ public static final String ACTION_READ = "READ";
+ public static final String ACTION_UPDATE = "UPDATE";
+ public static final String ACTION_DELETE = "DELETE";
+ public static final String ACTION_SUBSCRIBE = "SUBSCRIBE";
+ public static final String ACTION_UNSUBSCRIBE = "UNSUBSCRIBE";
+ public static final String ACTION_WRITE = "WRITE";
+
+ /**
+ * Optional endpoint URI for performing agent discovery. If implemented
+ * when agent discovery is required then a route will be created requiring
+ * a consumer from this endpoint which should generate messages for any
+ * agents that the connector discovers using the discovery settings provided.
+ *
+ * {@link Attributes} produced should be valid agent settings. A message should
+ * contain either a single {@link Attributes} object (one message per discovered
+ * agent) or an array of {@link Attributes} objects (multiple agents per message).
+ * Discovery should run as long as this route is running.
+ */
+ String getAgentDiscoveryUri(Attributes discoverySettings);
+
+ /**
+ * Get device inventory capabilities of the supplied agent.
+ */
+ InventoryCapabilities getCapabilities(Attributes agentSettings);
+
+ /**
+ * Indicates whether or not this connector component supports monitoring of devices.
+ * If device monitoring is supported then {@link #getDeviceMonitorUri(Attributes)} must
+ * return the Endpoint URI for the device monitor.
+ */
+ boolean supportsDeviceMonitoring(Attributes agentSettings);
+
+ /**
+ * Optional endpoint URI for consuming changes in the connector's status;
+ * messages should be output with the body set to an appropriate {@link AgentStatus}
+ * value.
+ *
+ * If not supported then just return null.
+ */
+ String getAgentStatusUri(Attributes agentSettings);
+
+ /**
+ * Mandatory endpoint URI for performing device CRUD. The capabilities supported by a particular
+ * agent/connector are determined by the response from {@link #getCapabilities(Attributes)}.
+ *
+ * Support for reading devices from the inventory is mandatory, all other capabilities are
+ * optional and are agent/connector dependent.
+ *
+ * The endpoint should support InOut (Request Reply) producers. The action to perform is set
+ * by the {@link #HEADER_INVENTORY_ACTION} message header.
+ *
+ * {@Link #ACTION_CREATE}, {@Link #ACTION_UPDATE}, {@Link #ACTION_DELETE} operations
+ * should consume a {@link Device}[]. In the case of {@link #ACTION_DELETE} then only the
+ * device URI(s) should be required. The reply message body should contain an integer indicating
+ * the status of the request (conforming to the HTTP Status code specification).
+ *
+ * {@link #ACTION_READ} operations should consume a {@link Device}[] where only the device
+ * URI(s) should be required, if no devices are supplied then all devices should be returned.
+ * The reply message body should contain a {@link Device}[] of the requested devices.
+ *
+ */
+ String getDeviceInventoryUri(Attributes agentSettings);
+
+ /**
+ * Optional endpoint URI for performing device discovery. If implemented
+ * when device discovery is required then a route will be created requiring
+ * a consumer from this endpoint which should generate messages for any
+ * devices that the connector discovers from the specified agent.
+ *
+ * {@link Attributes} produced should be valid devices (URI and Type). A message should
+ * contain either a single {@link Attributes} object (one message per discovered device)
+ * or an array of {@link Attributes} objects (multiple devices per message).
+ *
+ * Discovery should run as long as this route is running.
+ *
+ * If not supported then just return null.
+ */
+ String getDeviceDiscoveryUri(Attributes agentSettings);
+
+ /**
+ * Mandatory endpoint URI for: -
+ * Reading from device resources
+ * Writing to device resources
+ * Subscribing/Un-subscribing to device changes
+ *
+ * A single endpoint is used for all devices that belong to the specified
+ * agent. This endpoint is expected to support the InOut MEP with the
+ * {@link #HEADER_DEVICE_ACTION} message header indicating the action to
+ * perform/data to return on messages to be consumed by this endpoint.
+ *
+ * {@link #ACTION_SUBSCRIBE}, {@link #ACTION_UNSUBSCRIBE} operations should consume a
+ * {@link Device}[] where only the device URI(s) should be required. The reply message body
+ * should contain an integer indicating the status of the request (conforming to the HTTP
+ * Status code specification). Agents/Connectors that support device subscriptions must return
+ * a valid endpoint URI from {@link #getDeviceMonitorUri(Attributes)}.
+ */
+ String getDevicesUri(Attributes agentSettings);
+
+ /**
+ * Optional endpoint URI for consuming device changes from the specified agent;
+ * subscribing to device changes is done separately using the devices Endpoint URI.
+ *
+ * A subscribed device should be monitored by the connector for any resource value
+ * changes; these changes should then be output in a message body as {@link Device}[]
+ * containing the modified device(s) and resource(s).
+ *
+ * If not supported (i.e. devices require polling) then just return null.
+ */
+ String getDeviceMonitorUri(Attributes agentSettings);
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorImpl.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorImpl.java
new file mode 100644
index 000000000..e942a92a8
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorImpl.java
@@ -0,0 +1,131 @@
+/*
+ * 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.connector;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.gwt.json.client.JSONObject;
+import elemental.json.JsonObject;
+import org.openremote.manager.shared.agent.Agent;
+import org.openremote.manager.shared.attribute.Attribute;
+import org.openremote.manager.shared.attribute.Attributes;
+
+public class ConnectorImpl implements Connector {
+ protected String type;
+ protected String displayName;
+ protected boolean agentDiscovery;
+ protected Attributes agentSettings;
+ protected Attributes discoverySettings;
+
+ public ConnectorImpl() {
+ }
+
+ public ConnectorImpl(String type, String displayName, boolean agentDiscovery, Attributes agentSettings, Attributes discoverySettings) {
+ this.type = type;
+ this.displayName = displayName;
+ this.agentDiscovery = agentDiscovery;
+ this.agentSettings = agentSettings;
+ this.discoverySettings = discoverySettings;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ @Override
+ public boolean supportsAgentDiscovery() {
+ return agentDiscovery;
+ }
+
+ @Override
+ public Attributes getAgentDiscoverySettings() {
+ return discoverySettings;
+ }
+
+ @Override
+ public Attributes getAgentSettings() {
+ return agentSettings;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public void setAgentDiscovery(boolean agentDiscovery) {
+ this.agentDiscovery = agentDiscovery;
+ }
+
+ public void setAgentSettings(Attributes agentSettings) {
+ this.agentSettings = agentSettings;
+ }
+
+ public void setDiscoverySettings(Attributes discoverySettings) {
+ this.discoverySettings = discoverySettings;
+ }
+
+ /**
+ * Copy all settings which have a value into the {@link Agent}, keeping the value
+ * of each attribute but not the attribute metadata.
+ */
+ public void writeSettings(Agent agent) {
+ if (getAgentSettings() == null) {
+ agent.setConnectorSettings(null);
+ return;
+ }
+ Attributes settings = getAgentSettings();
+ Attributes agentConnectorSettings = new Attributes();
+ for (Attribute attribute : settings.get()) {
+ if (attribute.getValue() == null)
+ continue;
+ Attribute agentConnectorAttribute = new Attribute(attribute.getName(), attribute.getType());
+ agentConnectorAttribute.setValue(attribute.getValue());
+ agentConnectorSettings.add(agentConnectorAttribute);
+ }
+ agent.setConnectorSettings(agentConnectorSettings.getJsonObject());
+ }
+
+ /**
+ * Read the value for each settings attribute from the {@link Agent}, skipping any
+ * unknown attribute or attribute that doesn't have the right type. The
+ * {@link Agent#connectorSettings} can be "cleaned up" so they match a {@link Connector}
+ * by calling {@link #readSettings(Agent)} followed by {@link #writeSettings(Agent)}.
+ */
+ public void readSettings(Agent agent) {
+ if (agent.getConnectorSettings() == null)
+ return;
+
+ Attributes settings = getAgentSettings();
+ Attributes agentConnectorSettings = new Attributes(agent.getConnectorSettings());
+ for (Attribute agentConnectorAttribute : agentConnectorSettings.get()) {
+ Attribute settingsAttribute = settings.get(agentConnectorAttribute.getName());
+ if (settingsAttribute != null
+ && settingsAttribute.getType().equals(agentConnectorAttribute.getType())) {
+ settingsAttribute.setValue(agentConnectorAttribute.getValue());
+ }
+ }
+ }
+}
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
new file mode 100644
index 000000000..1de1a5157
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java
@@ -0,0 +1,130 @@
+/*
+ * 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.connector;
+
+import elemental.json.Json;
+import elemental.json.JsonValue;
+import org.openremote.manager.shared.agent.Agent;
+import org.openremote.manager.shared.attribute.*;
+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() {}
+
+ public static Attribute buildConnectorSetting(String attributeName, AttributeType type, String displayName, String description, boolean required) {
+ return buildConnectorSetting(attributeName, type, displayName, description, required, null, null);
+ }
+
+ 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) {
+ attribute.getMetadata().addElement(
+ new MetadataElement("label", Json.createObject())
+ .setType(AttributeType.STRING.getName())
+ .setValue(Json.create(displayName))
+ );
+ }
+
+ if (description != null && description.length() > 0) {
+ attribute.getMetadata().addElement(
+ new MetadataElement("description", Json.createObject())
+ .setType(AttributeType.STRING.getName())
+ .setValue(Json.create(description))
+ );
+ }
+
+ if (defaultValue != null && defaultValue.length() > 0) {
+ attribute.getMetadata().addElement(
+ new MetadataElement("defaultValue", Json.createObject())
+ .setType(type.getName())
+ .setValue(Json.create(defaultValue))
+ );
+ }
+
+ if (defaultValueNote != null && defaultValueNote.length() > 0) {
+ attribute.getMetadata().addElement(
+ new MetadataElement("defaultValueNote", Json.createObject())
+ .setType(AttributeType.STRING.getName())
+ .setValue(Json.create(defaultValueNote))
+ );
+ }
+
+ if (required) {
+ attribute.getMetadata().addElement(
+ new MetadataElement("required", Json.createObject())
+ .setType(AttributeType.BOOLEAN.getName())
+ .setValue(Json.create(true))
+ );
+ }
+
+ return attribute;
+ }
+
+// /**
+// * Will synchronise the stored agent settings with the supplied connector. Existing agent settings
+// * that match a connector setting will be preserved.
+// */
+// public static void synchroniseAgentSettings(Agent agent, Connector connector) {
+// Attributes connectorSettings = connector.getAgentSettings();
+//
+// if (connectorSettings == null) {
+// agent.setConnectorSettings(null);
+// return;
+// }
+//
+// Attributes agentSettings = new Attributes(agent.getConnectorSettings());
+// Attributes newSettings = new Attributes();
+//
+// for (Attribute attribute : connectorSettings.get()) {
+// Attribute existingAttribute = agentSettings.get(attribute.getName());
+//
+// if (existingAttribute != null && existingAttribute.getType().equals(attribute.getType())) {
+// newSettings.add(existingAttribute);
+// } else {
+// Attribute newAttribute = createSettingAttribute(attribute);
+// if (newAttribute != null) {
+// newSettings.add(newAttribute);
+// }
+// }
+// }
+//
+// agent.setConnectorSettings(newSettings.getJsonObject());
+// }
+//
+// protected static Attribute createSettingAttribute(Attribute connectorAttribute) {
+// Metadata metadata = connectorAttribute.getMetadata();
+// if (!metadata.hasElement("required")) {
+// return null;
+// }
+//
+// JsonValue value = Json.createNull();
+//
+// if (metadata.hasElement("defaultValue")) {
+// value = metadata.getElement("defaultValue").getValue();
+// }
+//
+// return new Attribute(connectorAttribute.getName(), connectorAttribute.getType(), value);
+// }
+}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorInventory.java b/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceInventory.java
similarity index 81%
rename from manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorInventory.java
rename to manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceInventory.java
index c7caa91b0..ed42425d7 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorInventory.java
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceInventory.java
@@ -17,9 +17,9 @@
* 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.connector;
+package org.openremote.manager.shared.device;
-public class ConnectorInventory {
+public class DeviceInventory {
public enum Action {
ADD,
@@ -27,5 +27,5 @@ public class ConnectorInventory {
UPDATE
}
- public static final String HEADER_DEVICE_ACTION = ConnectorInventory.class.getCanonicalName() + ".DEVICE_ACTION";
+ public static final String HEADER_DEVICE_ACTION = DeviceInventory.class.getCanonicalName() + ".DEVICE_ACTION";
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/device/InventoryCapabilities.java b/manager/shared/src/main/java/org/openremote/manager/shared/device/InventoryCapabilities.java
new file mode 100644
index 000000000..18ee17923
--- /dev/null
+++ b/manager/shared/src/main/java/org/openremote/manager/shared/device/InventoryCapabilities.java
@@ -0,0 +1,49 @@
+/*
+ * 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.device;
+
+/**
+ * Describes the capabilities that an agent connectors's inventory
+ * offers; inventory read is mandatory. This is how device provisioning
+ * should be achieved.
+ */
+public class InventoryCapabilities {
+ protected boolean inventoryCreate;
+ protected boolean inventoryUpdate;
+ protected boolean inventoryDelete;
+
+ public InventoryCapabilities(boolean inventoryCreate, boolean inventoryUpdate, boolean inventoryDelete) {
+ this.inventoryCreate = inventoryCreate;
+ this.inventoryUpdate = inventoryUpdate;
+ this.inventoryDelete = inventoryDelete;
+ }
+
+ public boolean isInventoryCreate() {
+ return inventoryCreate;
+ }
+
+ public boolean isInventoryUpdate() {
+ return inventoryUpdate;
+ }
+
+ public boolean isInventoryDelete() {
+ return inventoryDelete;
+ }
+}
diff --git a/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java b/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java
index fca2ef7a4..1584c48c9 100644
--- a/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java
+++ b/test/src/test/groovy/org/openremote/test/controller2/Controller2Service.java
@@ -12,10 +12,10 @@ import org.openremote.manager.shared.device.Device;
import java.util.ArrayList;
import java.util.List;
-import static org.openremote.manager.shared.connector.ConnectorInventory.Action.ADD;
-import static org.openremote.manager.shared.connector.ConnectorInventory.Action.REMOVE;
-import static org.openremote.manager.shared.connector.ConnectorInventory.Action.UPDATE;
-import static org.openremote.manager.shared.connector.ConnectorInventory.HEADER_DEVICE_ACTION;
+import static org.openremote.manager.shared.device.DeviceInventory.Action.ADD;
+import static org.openremote.manager.shared.device.DeviceInventory.Action.REMOVE;
+import static org.openremote.manager.shared.device.DeviceInventory.Action.UPDATE;
+import static org.openremote.manager.shared.device.DeviceInventory.HEADER_DEVICE_ACTION;
// TODO This is an example service for testing, replaced later with production code
public class Controller2Service implements ContainerService {