100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Finished implementing protocol connection status UI
Christian Bauer011c27ce4a69
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentStatus.java b/manager/client/src/main/java/org/openremote/manager/client/assets/AgentStatusEventMapper.javasimilarity index 57%rename from manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentStatus.javarename to manager/client/src/main/java/org/openremote/manager/client/assets/AgentStatusEventMapper.javaindex 1db2fc451..67f8c9b49 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentStatus.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/AgentStatusEventMapper.java@@ -1,27 +1,34 @@-/*- * 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-}+/*+ * 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.assets;++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.http.EntityReader;+import org.openremote.model.asset.agent.AgentStatusEvent;++import java.util.List;++@JsonMixIns({@JsonMixIns.JsonMixIn(target = AgentStatusEvent.class, mixIn = DefaultJsonMixin.class)})+public interface AgentStatusEventMapper+ extends ObjectMapper<List<AgentStatusEvent>>,+ EntityReader<List<AgentStatusEvent>> {+}diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.javaindex 3b4ba7af4..ac1bd709a 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.java@@ -70,17 +70,13 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {String booleanEditor();- String regularAttribute();-- String highlightAttribute();-- String highlightAttributeError();-String metaItemNameEditor();String metaItemValueEditor();String agentLinkEditor();++ String attributeView();}@UiFielddiff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xmlindex 47cac5e39..224e63083 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetEditImpl.ui.xml@@ -37,13 +37,7 @@.booleanEditor {}- .regularAttribute {- }-- .highlightAttribute {- }-- .highlightAttributeError {+ .attributeView {}.metaItemNameEditor {diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.javaindex 61d912d65..40d7329e6 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.java@@ -64,13 +64,9 @@ public class AssetLinkUsersImpl extends FormViewImpl implements AssetLinkUsers {String metaItemNameEditor();- String regularAttribute();-- String highlightAttribute();-- String highlightAttributeError();-String agentLinkEditor();++ String attributeView();}@UiFielddiff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.ui.xmlindex 5318b49b0..a3d5f481e 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.ui.xml+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetLinkUsersImpl.ui.xml@@ -27,15 +27,7 @@.booleanEditor {}- .regularAttribute {- border-left: 4px solid;- }-- .highlightAttribute {- border-left: 4px solid;- }-- .highlightAttributeError {+ .attributeView {border-left: 4px solid;}diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.javaindex d1cb8b0f5..a865b4d45 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewActivity.java@@ -22,6 +22,7 @@ package org.openremote.manager.client.assets.asset;import com.google.inject.Provider;import org.openremote.manager.client.Environment;import org.openremote.manager.client.app.dialog.JsonEditor;+import org.openremote.manager.client.assets.AgentStatusEventMapper;import org.openremote.manager.client.assets.AssetMapper;import org.openremote.manager.client.assets.attributes.AbstractAttributeViewExtension;import org.openremote.manager.client.assets.attributes.AttributeView;@@ -32,13 +33,17 @@ import org.openremote.manager.client.datapoint.NumberDatapointArrayMapper;import org.openremote.manager.client.interop.value.ObjectValueMapper;import org.openremote.manager.client.simulator.Simulator;import org.openremote.manager.client.widget.FormButton;+import org.openremote.manager.shared.agent.AgentResource;import org.openremote.manager.shared.asset.AssetResource;import org.openremote.manager.shared.datapoint.AssetDatapointResource;import org.openremote.manager.shared.map.MapResource;import org.openremote.manager.shared.security.Tenant;import org.openremote.model.Constants;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.AssetType;import org.openremote.model.asset.ReadAssetAttributesEvent;+import org.openremote.model.asset.agent.AgentLink;+import org.openremote.model.asset.agent.AgentStatusEvent;import org.openremote.model.asset.agent.ProtocolConfiguration;import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeExecuteStatus;@@ -65,6 +70,8 @@ public class AssetViewActivityprotected final static String READ_BUTTON_CLASS = "or-internal-read-button";final AssetResource assetResource;final AssetMapper assetMapper;+ final AgentResource agentResource;+ final AgentStatusEventMapper agentStatusEventMapper;final AssetDatapointResource assetDatapointResource;final NumberDatapointArrayMapper numberDatapointArrayMapper;final protected List<AttributeRef> activeSimulators = new ArrayList<>();@@ -78,15 +85,19 @@ public class AssetViewActivityAssetView view,AssetResource assetResource,AssetMapper assetMapper,+ AgentResource agentResource,+ AgentStatusEventMapper agentStatusEventMapper,AssetDatapointResource assetDatapointResource,NumberDatapointArrayMapper numberDatapointArrayMapper,MapResource mapResource,ObjectValueMapper objectValueMapper) {super(environment, currentTenant, assetBrowserPresenter, jsonEditorProvider, objectValueMapper, mapResource, false);+ this.agentStatusEventMapper = agentStatusEventMapper;this.presenter = this;this.view = view;this.assetResource = assetResource;this.assetMapper = assetMapper;+ this.agentResource = agentResource;this.assetDatapointResource = assetDatapointResource;this.numberDatapointArrayMapper = numberDatapointArrayMapper;}@@ -94,6 +105,9 @@ public class AssetViewActivity@Overridepublic void onStop() {subscribeLiveUpdates(false);+ if (asset.getWellKnownType() == AssetType.AGENT) {+ subscribeAgentStatus(false);+ }super.onStop();}@@ -108,15 +122,38 @@ public class AssetViewActivitysubscribeLiveUpdates(true);}+ // If this is an agent or an asset with attributes linked to an agent, start polling all agents status+ if (asset.getWellKnownType() == AssetType.AGENT+ || asset.getAttributesStream().anyMatch(attribute -> AgentLink.getAgentLink(attribute).isPresent())) {+ subscribeAgentStatus(true);+ }+registrations.add(environment.getEventBus().register(AttributeEvent.class,this::onAttributeEvent));-writeAssetToView();writeAttributesToView();loadParent();++ // Receive all agent status events for any agent+ // TODO Improve security? We should only be able to+ registrations.add(environment.getEventBus().register(+ AgentStatusEvent.class,+ this::onAgentStatusEvent+ ));++ if (asset.getWellKnownType() == AssetType.AGENT) {+ fetchAgentStatus(assetId);+ } else {+ asset.getAttributesStream()+ .map(AgentLink::getAgentLink)+ .filter(Optional::isPresent)+ .map(Optional::get)+ .map(AttributeRef::getEntityId)+ .forEach(this::fetchAgentStatus);+ }}@Override@@ -130,7 +167,7 @@ public class AssetViewActivityfor (AttributeView attributeView : attributeViews) {if (attributeView instanceof AttributeViewImpl) {- ((AttributeViewImpl)attributeView).getActionButtons().forEach(button -> {+ ((AttributeViewImpl) attributeView).getActionButtons().forEach(button -> {if (button.getStyleName().contains(READ_BUTTON_CLASS)) {(button).setEnabled(!enable);}@@ -159,6 +196,14 @@ public class AssetViewActivity}}+ protected void subscribeAgentStatus(boolean subscribe) {+ if (subscribe) {+ environment.getEventService().subscribe(AgentStatusEvent.class);+ } else {+ environment.getEventService().unsubscribe(AgentStatusEvent.class);+ }+ }+@Overridepublic void refresh() {for (AttributeView attributeView : attributeViews) {@@ -185,6 +230,43 @@ public class AssetViewActivity}}+ protected void onAgentStatusEvent(AgentStatusEvent event) {+ for (AttributeView attributeView : attributeViews) {+ AssetAttribute assetAttribute = attributeView.getAttribute();+ Optional<AttributeRef> assetAttributeRef = assetAttribute.getReference();++ if (asset.getWellKnownType() == AssetType.AGENT) {+ if (assetAttributeRef.map(ref -> ref.equals(event.getProtocolConfiguration())).orElse(false)) {+ attributeView.setStatus(event.getConnectionStatus());+ break;+ }+ } else {+ if (AgentLink.getAgentLink(assetAttribute)+ .filter(agentLink -> agentLink.equals(event.getProtocolConfiguration()))+ .map(agentLink -> {+ attributeView.setStatus(event.getConnectionStatus());+ return true;+ }).orElse(false))+ break;+ }++ }+ }++ protected void fetchAgentStatus(String agentId) {+ environment.getRequestService().execute(+ agentStatusEventMapper,+ requestParams -> agentResource.getAgentStatus(requestParams, agentId),+ 200,+ agentStatuses -> {+ for (AgentStatusEvent event : agentStatuses) {+ onAgentStatusEvent(event);+ }+ },+ ex -> handleRequestException(ex, environment.getEventBus(), environment.getMessages())+ );+ }+@Overridepublic void writeAssetToView() {super.writeAssetToView();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.javaindex ae89d74ad..10408446d 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@@ -69,17 +69,13 @@ public class AssetViewImpl extends Composite implements AssetView {String booleanEditor();- String regularAttribute();-- String highlightAttribute();-- String highlightAttributeError();-String metaItemValueEditor();String metaItemNameEditor();String agentLinkEditor();++ String attributeView();}@UiFielddiff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xmlindex ddd9dfff3..fd55d4801 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml@@ -28,16 +28,8 @@.booleanEditor {}- .regularAttribute {- border-left: 4px solid;- }-- .highlightAttribute {- border-left: 4px solid;- }-- .highlightAttributeError {- border-left: 4px solid;+ .attributeView {+ border-left: 8px solid;}.metaItemValueEditor {diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AbstractAttributeViewExtension.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AbstractAttributeViewExtension.javaindex 5224fc372..72e30c2d6 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AbstractAttributeViewExtension.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AbstractAttributeViewExtension.java@@ -23,6 +23,7 @@ import org.openremote.manager.client.Environment;import org.openremote.manager.client.widget.FormSection;import org.openremote.model.ValidationFailure;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.agent.ConnectionStatus;import java.util.function.Consumer;@@ -82,7 +83,7 @@ public abstract class AbstractAttributeViewExtension extends FormSection impleme}@Override- public void setHighlightError(boolean highlightError) {+ public void setStatus(ConnectionStatus connectionStatus) {// TODO Ability for extensions to display some error highlight/visual marker}diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeView.javaindex 392b6382e..9f16c3be9 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeView.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeView.java@@ -23,6 +23,7 @@ import com.google.gwt.user.client.ui.IsWidget;import org.openremote.model.ValidationFailure;import org.openremote.model.ValueHolder;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.agent.ConnectionStatus;import org.openremote.model.attribute.AttributeValidationResult;import org.openremote.model.value.Value;import org.openremote.model.value.ValueType;@@ -53,11 +54,7 @@ public interface AttributeView extends IsWidget {String booleanEditor();- String regularAttribute();-- String highlightAttribute();-- String highlightAttributeError();+ String attributeView();String metaItemNameEditor();@@ -115,7 +112,7 @@ public interface AttributeView extends IsWidget {void setEditMode(boolean editMode);/**- * Highlight the attribute as having an error.+ * Shows the current status, if any, to the user.*/- void setHighlightError(boolean highlightError);+ void setStatus(ConnectionStatus connectionStatus);}diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeViewImpl.javaindex a1dcc7de1..9aacfd57d 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeViewImpl.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributeViewImpl.java@@ -26,6 +26,7 @@ import elemental.client.Browser;import org.openremote.manager.client.Environment;import org.openremote.manager.client.widget.*;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.agent.ConnectionStatus;import org.openremote.model.attribute.AttributeType;import org.openremote.model.attribute.AttributeValidationResult;import org.openremote.model.value.Value;@@ -46,7 +47,7 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {protected AssetAttribute attribute;protected List<FormButton> attributeActions;protected List<AbstractAttributeViewExtension> attributeExtensions;- protected boolean highlightError;+ protected ConnectionStatus connectionStatus;protected boolean editMode;protected ValueEditorSupplier valueEditorSupplier;protected ValidationErrorConsumer validationErrorConsumer;@@ -59,6 +60,7 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {this.attribute = attribute;addStyleName("flex-none");+ addStyleName(style.attributeView());addStyleName(environment.getWidgetStyle().FormListItem());showDisabledExtensionToggle();@@ -170,8 +172,9 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {}@Override- public void setHighlightError(boolean highlightError) {- this.highlightError = highlightError;+ public void setStatus(ConnectionStatus connectionStatus) {+ this.connectionStatus = connectionStatus;+ refresh();}protected void notifyAttributeModified(Value newValue) {@@ -201,11 +204,10 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {}protected void refresh() {- removeStyleName(style.highlightAttribute());- removeStyleName(style.highlightAttributeError());- removeStyleName(environment.getWidgetStyle().HighlightBorder());- removeStyleName(style.regularAttribute());- removeStyleName(environment.getWidgetStyle().RegularBorder());+ removeStyleName(environment.getWidgetStyle().BorderDefault());+ removeStyleName(environment.getWidgetStyle().BorderGreen());+ removeStyleName(environment.getWidgetStyle().BorderYellow());+ removeStyleName(environment.getWidgetStyle().BorderRed());getFormLabel().setIcon(null);getFormLabel().setText(null);getInfoLabel().setText(null);@@ -215,15 +217,26 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {return;}- if (highlightError) {- addStyleName(style.highlightAttributeError());- addStyleName(environment.getWidgetStyle().HighlightBorder());- } else if (attribute.hasAgentLink() || attribute.isProtocolConfiguration()) {- addStyleName(style.highlightAttribute());- addStyleName(environment.getWidgetStyle().HighlightBorder());+ if (connectionStatus != null) {+ switch (connectionStatus) {+ case DISABLED:+ case CLOSED:+ addStyleName(environment.getWidgetStyle().BorderDefault());+ break;+ case CONNECTED:+ addStyleName(environment.getWidgetStyle().BorderGreen());+ break;+ case WAITING:+ case CONNECTING:+ case DISCONNECTING:+ addStyleName(environment.getWidgetStyle().BorderYellow());+ break;+ default:+ addStyleName(environment.getWidgetStyle().BorderRed());+ break;+ }} else {- addStyleName(style.regularAttribute());- addStyleName(environment.getWidgetStyle().RegularBorder());+ addStyleName(environment.getWidgetStyle().BorderDefault());}if (attribute.isExecutable()) {@@ -240,7 +253,11 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {if (attribute.isExecutable()) {infoText.append(environment.getMessages().executable());} else if (attribute.isProtocolConfiguration()) {- infoText.append(environment.getMessages().protocolConfiguration());+ if (editMode) {+ infoText.append(environment.getMessages().protocolConfiguration());+ } else {+ infoText.append(connectionStatus != null ? connectionStatus.toString() : environment.getMessages().waitingForStatus());+ }} else if (attribute.getType().isPresent()) {infoText.append(environment.getMessages().attributeType(attribute.getType().get().name()));}diff --git a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.javaindex 3c32c9e60..3e41ce723 100644--- a/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java+++ b/manager/client/src/main/java/org/openremote/manager/client/i18n/ManagerMessages.java@@ -444,4 +444,8 @@ public interface ManagerMessages extends Messages {String deleteConverterValue();String linkAssetUsers();++ String waitingForStatus();++ String noAttributesLinkedToSimulator();}diff --git a/manager/client/src/main/java/org/openremote/manager/client/simulator/Simulator.java b/manager/client/src/main/java/org/openremote/manager/client/simulator/Simulator.javaindex 4e1189023..4959766b8 100644--- a/manager/client/src/main/java/org/openremote/manager/client/simulator/Simulator.java+++ b/manager/client/src/main/java/org/openremote/manager/client/simulator/Simulator.java@@ -26,10 +26,7 @@ import org.openremote.manager.client.assets.attributes.AbstractAttributeViewExteimport org.openremote.manager.client.assets.attributes.AttributeView;import org.openremote.manager.client.assets.attributes.AttributeViewImpl;import org.openremote.manager.client.event.ShowSuccessEvent;-import org.openremote.manager.client.widget.FormButton;-import org.openremote.manager.client.widget.FormField;-import org.openremote.manager.client.widget.FormGroup;-import org.openremote.manager.client.widget.FormLabel;+import org.openremote.manager.client.widget.*;import org.openremote.model.ValidationFailure;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.attribute.AttributeRef;@@ -131,25 +128,29 @@ public class Simulator extends AbstractAttributeViewExtension {add(formGroup);}- FormGroup submitGroup = new FormGroup();- submitGroup.getElement().getStyle().setWidth(80, com.google.gwt.dom.client.Style.Unit.PCT);-- FormField submitField = new FormField();- submitGroup.setFormField(submitField);-- FormButton writeButton = new FormButton(environment.getMessages().writeSimulatorState());- writeButton.setPrimary(true);- writeButton.addClickHandler(event -> {- if (isValid()) {- environment.getEventService().dispatch(simulatorState);- environment.getEventBus().dispatch(- new ShowSuccessEvent(environment.getMessages().simulatorStateSubmitted())- );- }- });- submitField.add(writeButton);-- add(submitGroup);+ if (sortedElements.size() > 0) {+ FormGroup submitGroup = new FormGroup();+ submitGroup.getElement().getStyle().setWidth(80, com.google.gwt.dom.client.Style.Unit.PCT);++ FormField submitField = new FormField();+ submitGroup.setFormField(submitField);++ FormButton writeButton = new FormButton(environment.getMessages().writeSimulatorState());+ writeButton.setPrimary(true);+ writeButton.addClickHandler(event -> {+ if (isValid()) {+ environment.getEventService().dispatch(simulatorState);+ environment.getEventBus().dispatch(+ new ShowSuccessEvent(environment.getMessages().simulatorStateSubmitted())+ );+ }+ });+ submitField.add(writeButton);++ add(submitGroup);+ } else {+ add(new FormInlineLabel(environment.getMessages().noAttributesLinkedToSimulator()));+ }// "Blink" the editor so users know there might be a new valuefor (FormGroup formGroup : formGroups.values()) {diff --git a/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java b/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.javaindex 7a424e2ff..4e2c109b6 100644--- a/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java+++ b/manager/client/src/main/java/org/openremote/manager/client/style/WidgetStyle.java@@ -397,15 +397,23 @@ public class WidgetStyle {return "or-HighlightBackground";}- public String HighlightBorder() {- return "or-HighlightBorder";+ public String JsonEditor() {+ return "or-JsonEditor";}- public String RegularBorder() {- return "or-RegularBorder";+ public String BorderRed() {+ return "or-BorderRed";}- public String JsonEditor() {- return "or-JsonEditor";+ public String BorderGreen() {+ return "or-BorderGreen";+ }++ public String BorderYellow() {+ return "or-BorderYellow";+ }++ public String BorderDefault() {+ return "or-BorderDefault";}}diff --git a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.propertiesindex fd91262c6..0e670ff02 100644--- a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties+++ b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties@@ -369,4 +369,6 @@ converterType[DECREMENT]=DecrementconverterType[INCREMENT]=IncrementaddConverterValue=Add valuedeleteConverterValue=Delete value-linkAssetUsers=Link asset users\ No newline at end of file+linkAssetUsers=Link asset users+waitingForStatus=Waiting for connection status...+noAttributesLinkedToSimulator=No attributes are linked to this simulator protocol configuration.\ No newline at end of filediff --git a/manager/client/src/main/webapp/css/theme.html b/manager/client/src/main/webapp/css/theme.htmlindex 84753bde3..61b8384a1 100644--- a/manager/client/src/main/webapp/css/theme.html+++ b/manager/client/src/main/webapp/css/theme.html@@ -411,12 +411,20 @@border-color: transparent;}- .or-HighlightBorder {- border-color: var(--theme-lightgreen);+ .or-BorderRed {+ border-color: var(--theme-red);}- .or-RegularBorder {- border-color: var(--theme-mediumgrey);+ .or-BorderGreen {+ border-color: var(--theme-mediumgreen);+ }++ .or-BorderYellow {+ border-color: var(--theme-yellow);+ }++ .or-BorderDefault {+ border-color: var(--theme-lightergrey);}.or-DatapointBrowser {diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentConnector.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentConnector.javaindex a0c51fa8b..50708f7f5 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentConnector.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentConnector.java@@ -21,17 +21,22 @@ package org.openremote.manager.server.agent;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.agent.AgentStatusEvent;import org.openremote.model.asset.agent.ProtocolDescriptor;import org.openremote.model.attribute.AttributeRef;import org.openremote.model.attribute.AttributeValidationResult;import org.openremote.model.file.FileInfo;+import java.util.List;+/*** This is an interface for communicating with an agent. It* should be stateless and re-usable.*/public interface AgentConnector {+ List<AgentStatusEvent> getConnectionStatus(Asset agent);+ProtocolDescriptor[] getProtocolDescriptors(Asset agent);AttributeValidationResult validateProtocolConfiguration(AssetAttribute protocolConfiguration);@@ -56,4 +61,5 @@ public interface AgentConnector {* @throws IllegalStateException thrown by the protocol if an error occurs processing the supplied {@link FileInfo}*/Asset[] getDiscoveredLinkedAttributes(AttributeRef protocolConfigurationRef, FileInfo fileInfo) throws IllegalArgumentException, UnsupportedOperationException, IllegalStateException;+}diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.javaindex 93522a987..a40651e4f 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentResourceImpl.java@@ -20,7 +20,6 @@package org.openremote.manager.server.agent;import org.openremote.container.timer.TimerService;-import org.openremote.manager.server.asset.AssetResourceImpl;import org.openremote.manager.server.asset.AssetStorageService;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.security.ManagerIdentityService;@@ -31,6 +30,7 @@ import org.openremote.manager.shared.security.Tenant;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetType;+import org.openremote.model.asset.agent.AgentStatusEvent;import org.openremote.model.asset.agent.ProtocolDescriptor;import org.openremote.model.attribute.AttributeRef;import org.openremote.model.attribute.AttributeValidationResult;@@ -39,8 +39,10 @@ import org.openremote.model.util.Pair;import javax.ws.rs.*;import java.util.HashMap;+import java.util.List;import java.util.Map;import java.util.Optional;+import java.util.function.Function;import java.util.logging.Level;import java.util.logging.Logger;@@ -63,21 +65,18 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour@Overridepublic ProtocolDescriptor[] getSupportedProtocols(RequestParams requestParams, String agentId) {- Asset[] agentFinal = new Asset[1];-- return findAgent(agentId)- .flatMap(agent -> {- agentFinal[0] = agent;- return agentService.getAgentConnector(agent);- })- .map(agentConnector -> {- LOG.finer("Asking connector '" + agentConnector.getClass().getSimpleName() + "' for protocol descriptors");- return agentConnector.getProtocolDescriptors(agentFinal[0]);- })- .orElseThrow(() -> {- LOG.warning("Agent connector not found for agent ID: " + agentId);- return new IllegalStateException("Agent connector not found or returned invalid response");- });+ return withAgentConnector(agentId, agentConnector -> {+ LOG.finer("Asking connector '" + agentConnector.value.getClass().getSimpleName() + "' for protocol configurations");+ return agentConnector.value.getProtocolDescriptors(agentConnector.key);+ });+ }++ @Override+ public List<AgentStatusEvent> getAgentStatus(RequestParams requestParams, String agentId) {+ return withAgentConnector(agentId, agentConnector -> {+ LOG.finer("Asking connector '" + agentConnector.getClass().getSimpleName() + "' for connection status");+ return agentConnector.value.getConnectionStatus(agentConnector.key);+ });}@Override@@ -107,32 +106,27 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour@Overridepublic AttributeValidationResult validateProtocolConfiguration(RequestParams requestParams, String agentId, AssetAttribute protocolConfiguration) {- return findAgent(agentId)- .flatMap(agentService::getAgentConnector)- .map(agentConnector -> {- LOG.finer("Asking connector '" + agentConnector.getClass().getSimpleName() + "' to validate protocol configuration: " + protocolConfiguration);- return agentConnector.validateProtocolConfiguration(protocolConfiguration);- })- .orElseThrow(() -> {- LOG.warning("Agent connector not found for agent ID: " + agentId);- return new IllegalStateException("Agent connector not found or returned invalid response");- });+ return withAgentConnector(agentId, agentConnector -> agentConnector.value.validateProtocolConfiguration(protocolConfiguration));}@Overridepublic Asset[] searchForLinkedAttributes(RequestParams requestParams, String agentId, String protocolConfigurationName, String parentId, String realmId) {AttributeRef protocolConfigRef = new AttributeRef(agentId, protocolConfigurationName);- AgentConnector agentConnector = findAgent(agentId)- .flatMap(agentService::getAgentConnector)- .orElseThrow(() -> new NotFoundException("Agent connector not found for: " + agentId));Pair<Asset, String> parentAndRealmId = getParentAssetAndRealmId(parentId, realmId);- LOG.finer("Asking connector '" + agentConnector.getClass().getSimpleName() + "' to do linked attribute discovery for protocol configuration: " + protocolConfigRef);+ // TODO: Allow user to select which assets/attributes are actually added to the DB+ Asset[] assets = withAgentConnector(+ agentId,+ agentConnector -> {+ LOG.finer(+ "Asking connector '" + agentConnector.value.getClass().getSimpleName()+ + "' to do linked attribute discovery for protocol configuration: " + protocolConfigRef);+ return agentConnector.value.getDiscoveredLinkedAttributes(protocolConfigRef);+ }+ );try {- // TODO: Allow user to select which assets/attributes are actually added to the DB- Asset[] assets = agentConnector.getDiscoveredLinkedAttributes(protocolConfigRef);persistAssets(assets, parentAndRealmId.key, parentAndRealmId.value);return assets;} catch (IllegalArgumentException e) {@@ -147,9 +141,6 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour@Overridepublic Asset[] importLinkedAttributes(RequestParams requestParams, String agentId, String protocolConfigurationName, String parentId, String realmId, FileInfo fileInfo) {AttributeRef protocolConfigRef = new AttributeRef(agentId, protocolConfigurationName);- AgentConnector agentConnector = findAgent(agentId)- .flatMap(agentService::getAgentConnector)- .orElseThrow(() -> new NotFoundException("Agent connector not found for: " + agentId));if (fileInfo == null || fileInfo.getContents() == null) {throw new BadRequestException("A file must be provided for import");@@ -157,11 +148,19 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResourPair<Asset, String> parentAndRealmId = getParentAssetAndRealmId(parentId, realmId);- LOG.finer("Asking connector '" + agentConnector.getClass().getSimpleName() + "' to do linked attribute discovery using uploaded file for protocol configuration: " + protocolConfigRef);+ Asset[] assets = withAgentConnector(+ agentId,+ agentConnector -> {+ LOG.finer(+ "Asking connector '" + agentConnector.value.getClass().getSimpleName()+ + "' to do linked attribute discovery using uploaded file for protocol configuration: " + protocolConfigRef+ );+ return agentConnector.value.getDiscoveredLinkedAttributes(protocolConfigRef, fileInfo);+ }+ );try {// TODO: Allow user to select which assets/attributes are actually added to the DB- Asset[] assets = agentConnector.getDiscoveredLinkedAttributes(protocolConfigRef, fileInfo);persistAssets(assets, parentAndRealmId.key, parentAndRealmId.value);return assets;} catch (IllegalArgumentException e) {@@ -176,15 +175,18 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour}}- protected Optional<Asset> findAgent(String agentId) {- // Find the agent- LOG.finer("Find agent: " + agentId);- Asset agent = agentService.getAgents().get(agentId);- if (agent == null || agent.getWellKnownType() != AssetType.AGENT) {- LOG.warning("Failed to find agent with ID: " + agentId);- throw new IllegalArgumentException("Agent not found");- }- return Optional.of(agent);+ protected <T> T withAgentConnector(String agentId, Function<Pair<Asset, AgentConnector>, T> function) {+ return Optional.ofNullable(agentService.getAgents().get(agentId))+ .filter(asset -> asset.getWellKnownType() == AssetType.AGENT)+ .map(agent -> new Pair<>(agent, agentService.getAgentConnector(agent).orElseThrow(() -> {+ LOG.warning("Failed to find agent connector for: " + agent);+ return new IllegalStateException("Agent connector not found or returned invalid response");+ })))+ .map(function)+ .orElseThrow(() -> {+ LOG.warning("Failed to find agent with ID: " + agentId);+ return new IllegalArgumentException("Agent not found");+ });}/**@@ -225,7 +227,7 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResourreturn;}- for (int i=0; i< assets.length; i++) {+ for (int i = 0; i < assets.length; i++) {Asset asset = assets[i];asset.setId(null);asset.setParent(parentAsset);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.javaindex 4a3ffa215..9541d7230 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@@ -21,7 +21,9 @@ package org.openremote.manager.server.agent;import org.apache.camel.builder.RouteBuilder;import org.openremote.manager.server.event.ClientEventService;-import org.openremote.model.asset.agent.ConnectionStatus;+import org.openremote.manager.shared.security.ClientRole;+import org.openremote.model.Constants;+import org.openremote.model.asset.agent.*;import org.openremote.agent.protocol.Protocol;import org.openremote.agent.protocol.ProtocolAssetService;import org.openremote.container.Container;@@ -37,9 +39,6 @@ import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.model.AbstractValueTimestampHolder;import org.openremote.model.asset.*;-import org.openremote.model.asset.agent.Agent;-import org.openremote.model.asset.agent.AgentLink;-import org.openremote.model.asset.agent.ProtocolConfiguration;import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeRef;import org.openremote.model.util.Pair;@@ -76,7 +75,8 @@ public class AgentService extends RouteBuilder implements ContainerService, Consprivate static final Logger LOG = Logger.getLogger(AgentService.class.getName());- protected Container container;+ protected TimerService timerService;+ protected ManagerIdentityService identityService;protected AssetProcessingService assetProcessingService;protected AssetStorageService assetStorageService;protected MessageBrokerService messageBrokerService;@@ -89,13 +89,34 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons@Overridepublic void init(Container container) throws Exception {- this.container = container;+ timerService = container.getService(TimerService.class);+ identityService = container.getService(ManagerIdentityService.class);assetProcessingService = container.getService(AssetProcessingService.class);assetStorageService = container.getService(AssetStorageService.class);messageBrokerService = container.getService(MessageBrokerService.class);clientEventService = container.getService(ClientEventService.class);localAgentConnector = new LocalAgentConnector(this);+ clientEventService.addSubscriptionAuthorizer((auth, subscription) -> {+ if (!subscription.isEventType(AgentStatusEvent.class))+ return false;++ // Superuser can get all+ if (auth.isSuperUser())+ return true;++ // Restricted users get nothing+ if (identityService.getIdentityProvider().isRestrictedUser(auth.getUserId()))+ return false;++ // User must have role+ if (!auth.hasResourceRole(ClientRole.READ_ASSETS.getValue(), Constants.KEYCLOAK_CLIENT_ID)) {+ return false;+ }++ return true;+ });+container.getService(WebService.class).getApiSingletons().add(new AgentResourceImpl(container.getService(TimerService.class),@@ -426,7 +447,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Conssynchronized (protocolConfigurations) {// Create a consumer callback for deployment status updatesConsumer<ConnectionStatus> deploymentStatusConsumer = status ->- publishProtocolDeploymentStatus(protocolAttributeRef, status);+ publishProtocolConnectionStatus(protocolAttributeRef, status);// Store the infoprotocolConfigurations.put(@@ -435,7 +456,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons);// Set status to linking- publishProtocolDeploymentStatus(protocolAttributeRef, CONNECTING);+ publishProtocolConnectionStatus(protocolAttributeRef, CONNECTING);// Link the protocol configuration to the protocoltry {@@ -443,7 +464,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons} catch (Exception e) {LOG.log(Level.SEVERE, "Protocol threw an exception during protocol configuration linking", e);// Set status to error- publishProtocolDeploymentStatus(protocolAttributeRef, ERROR);+ publishProtocolConnectionStatus(protocolAttributeRef, ERROR);// Cannot continue to link attributes;return;}@@ -511,29 +532,27 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons}// Set status to disconnected- publishProtocolDeploymentStatus(protocolAttributeRef, DISCONNECTED);+ publishProtocolConnectionStatus(protocolAttributeRef, DISCONNECTED);protocolConfigurations.remove(protocolAttributeRef);}}- // TODO: Implement mechanism for publishing/subscribing to protocolconfiguration deployment status- protected void publishProtocolDeploymentStatus(AttributeRef protocolRef, ConnectionStatus connectionStatus) {- LOG.fine("Protocol status updated to '" + connectionStatus + "': " + protocolRef);+ protected void publishProtocolConnectionStatus(AttributeRef protocolRef, ConnectionStatus connectionStatus) {+ LOG.info("Agent protocol status updated to " + connectionStatus + ": " + protocolRef);synchronized (protocolConfigurations) {Pair<AssetAttribute, ConnectionStatus> protocolDeploymentInfo = protocolConfigurations.get(protocolRef);if (protocolDeploymentInfo != null) {protocolDeploymentInfo.value = connectionStatus;+ // Notify clientsclientEventService.publishEvent(- new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealmId(), asset.getId())+ new AgentStatusEvent(timerService.getCurrentTimeMillis(), protocolRef, connectionStatus));--}}}- public ConnectionStatus getProtocolDeploymentStatus(AttributeRef protocolRef) {+ public ConnectionStatus getProtocolConnectionStatus(AttributeRef protocolRef) {synchronized (protocolConfigurations) {return Optional.ofNullable(protocolConfigurations.get(protocolRef)).map(pair -> pair.value)@@ -565,7 +584,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons} catch (Exception ex) {LOG.log(Level.SEVERE, "Ignoring error on linking attributes to protocol: " + protocol.getProtocolName(), ex);// Update the status of this protocol configuration to error- publishProtocolDeploymentStatus(protocolConfiguration.getReferenceOrThrow(), ERROR);+ publishProtocolConnectionStatus(protocolConfiguration.getReferenceOrThrow(), ERROR);}}@@ -589,7 +608,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons} catch (Exception ex) {LOG.log(Level.SEVERE, "Ignoring error on unlinking attributes from protocol: " + protocol.getProtocolName(), ex);// Update the status of this protocol configuration to error- publishProtocolDeploymentStatus(protocolConfiguration.getReferenceOrThrow(), ERROR);+ publishProtocolConnectionStatus(protocolConfiguration.getReferenceOrThrow(), ERROR);}}diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/LocalAgentConnector.java b/manager/server/src/main/java/org/openremote/manager/server/agent/LocalAgentConnector.javaindex bc9d46e7b..a454ef0aa 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/LocalAgentConnector.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/LocalAgentConnector.java@@ -25,16 +25,17 @@ import org.openremote.agent.protocol.ProtocolLinkedAttributeImport;import org.openremote.model.ValidationFailure;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.agent.ProtocolConfiguration;-import org.openremote.model.asset.agent.ProtocolDescriptor;+import org.openremote.model.asset.agent.*;import org.openremote.model.attribute.AttributeRef;import org.openremote.model.attribute.AttributeValidationResult;import org.openremote.model.file.FileInfo;import org.openremote.model.util.Pair;import java.util.Collections;+import java.util.List;import java.util.Optional;import java.util.logging.Logger;+import java.util.stream.Collectors;public class LocalAgentConnector implements AgentConnector {@@ -45,6 +46,17 @@ public class LocalAgentConnector implements AgentConnector {this.agentService = agentService;}+ @Override+ public List<AgentStatusEvent> getConnectionStatus(Asset agent) {+ return agentService.getAgents().entrySet().stream()+ .filter(entry -> entry.getKey().equals(agent.getId()))+ .flatMap(entry -> Agent.getProtocolConfigurations(entry.getValue()).stream())+ .map(AssetAttribute::getReferenceOrThrow)+ .map(protocolConfigurationRef -> new Pair<>(protocolConfigurationRef, agentService.getProtocolConnectionStatus(protocolConfigurationRef)))+ .map(pair -> new AgentStatusEvent(agentService.timerService.getCurrentTimeMillis(), pair.key, pair.value))+ .collect(Collectors.toList());+ }+@Overridepublic ProtocolDescriptor[] getProtocolDescriptors(Asset agent) {return agentService.protocolsdiff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.javaindex 1a14d9907..fcc052c50 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java@@ -119,7 +119,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicreturn false;// User must have role- auth.hasResourceRole(ClientRole.READ_ASSETS.getValue(), Constants.KEYCLOAK_CLIENT_ID);+ if (!auth.hasResourceRole(ClientRole.READ_ASSETS.getValue(), Constants.KEYCLOAK_CLIENT_ID)) {+ return false;+ }// Ensure filter matches authenticated realmif (subscription.getFilter() instanceof AssetTreeModifiedEvent.TenantFilter) {@@ -257,6 +259,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic}public List<String> findNames(String... ids) {+ if (ids == null || ids.length == 0)+ return new ArrayList<>();+// TODO: Do this in a loop in reasonably sized batchesreturn persistenceService.doReturningTransaction(em -> {List<Object[]> result = em.createQuery("select a.id, a.name from Asset a where a.id in :ids")diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.javaindex 7c76d7617..317eb8828 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/agent/AgentResource.java@@ -24,12 +24,15 @@ import org.openremote.manager.shared.http.RequestParams;import org.openremote.manager.shared.http.SuccessStatusCode;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.agent.AgentStatusEvent;+import org.openremote.model.asset.agent.ConnectionStatus;import org.openremote.model.asset.agent.ProtocolDescriptor;import org.openremote.model.attribute.AttributeValidationResult;import org.openremote.model.file.FileInfo;import javax.annotation.security.RolesAllowed;import javax.ws.rs.*;+import java.util.List;import java.util.Map;import static javax.ws.rs.core.MediaType.APPLICATION_JSON;@@ -58,6 +61,19 @@ public interface AgentResource {@PathParam("agentId") String agentId);+ /**+ * Retrieve {@link org.openremote.model.asset.agent.ConnectionStatus} of all protocol configurations.+ */+ @GET+ @Path("status/{agentId}")+ @Produces(APPLICATION_JSON)+ @SuccessStatusCode(200)+ @RolesAllowed({"read:assets"})+ List<AgentStatusEvent> getAgentStatus(+ @BeanParam RequestParams requestParams,+ @PathParam("agentId") String agentId+ );+/*** Retrieve all the protocols for all the agents*/diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovyindex 128a0fee0..a52e515ad 100644--- a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy@@ -20,6 +20,7 @@package org.openremote.test.protocolimport org.openremote.agent.protocol.AbstractProtocol+import org.openremote.model.asset.agent.AgentStatusEventimport org.openremote.model.asset.agent.ConnectionStatusimport org.openremote.manager.server.agent.AgentServiceimport org.openremote.manager.server.asset.AssetProcessingService@@ -31,15 +32,26 @@ import org.openremote.model.asset.AssetMetaimport org.openremote.model.asset.AssetTypeimport org.openremote.model.asset.agent.ProtocolConfigurationimport org.openremote.model.attribute.*+import org.openremote.model.event.shared.SharedEventimport org.openremote.model.value.Values+import org.openremote.test.ClientEventService+import org.openremote.test.GwtClientTraitimport org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions+import static org.openremote.container.util.MapAccess.getString+import static org.openremote.manager.server.event.ClientEventService.WEBSOCKET_EVENTS+import static org.openremote.manager.server.setup.AbstractKeycloakSetup.SETUP_KEYCLOAK_ADMIN_PASSWORD+import static org.openremote.manager.server.setup.AbstractKeycloakSetup.SETUP_KEYCLOAK_ADMIN_PASSWORD_DEFAULT+import static org.openremote.model.Constants.KEYCLOAK_CLIENT_ID+import static org.openremote.model.Constants.MASTER_REALM+import static org.openremote.model.Constants.MASTER_REALM_ADMIN_USER+/*** This tests the basic protocol interface and abstract protocol implementation.*/-class BasicProtocolTest extends Specification implements ManagerContainerTrait {+class BasicProtocolTest extends Specification implements ManagerContainerTrait, GwtClientTrait {def "Check abstract protocol linking/un-linking"() {@@ -180,6 +192,24 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {mockAgent.setRealmId(Constants.MASTER_REALM)mockAgent = assetStorageService.merge(mockAgent)+ and: "a client websocket connection and attached event bus and service"+ def accessToken = {+ authenticate(+ container,+ MASTER_REALM,+ KEYCLOAK_CLIENT_ID,+ MASTER_REALM_ADMIN_USER,+ getString(container.getConfig(), SETUP_KEYCLOAK_ADMIN_PASSWORD, SETUP_KEYCLOAK_ADMIN_PASSWORD_DEFAULT)+ ).token+ }+ List<SharedEvent> collectedSharedEvents = []+ def eventBus = createEventBus(collectedSharedEvents)+ def clientEventService = new ClientEventService(eventBus, container.JSON)+ def websocketSession = connect(createWebsocketClient(), clientEventService.endpoint, serverUri(serverPort), WEBSOCKET_EVENTS, MASTER_REALM, accessToken.call())++ and: "a subscription is made to the flight priority filters"+ clientEventService.subscribe(AgentStatusEvent.class)+then: "the protocol configurations should be linked and their deployment status should be available in the agent service"conditions.eventually {assert protocolLinkedConfigurations.size() == 4@@ -191,10 +221,35 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {assert config2 != nullassert config3 != nullassert config4 != null- assert agentService.getProtocolDeploymentStatus(config1.getReferenceOrThrow()) == ConnectionStatus.CONNECTED- assert agentService.getProtocolDeploymentStatus(config2.getReferenceOrThrow()) == ConnectionStatus.ERROR- assert agentService.getProtocolDeploymentStatus(config3.getReferenceOrThrow()) == ConnectionStatus.ERROR- assert agentService.getProtocolDeploymentStatus(config4.getReferenceOrThrow()) == ConnectionStatus.DISABLED+ assert agentService.getProtocolConnectionStatus(config1.getReferenceOrThrow()) == ConnectionStatus.CONNECTED+ assert agentService.getProtocolConnectionStatus(config2.getReferenceOrThrow()) == ConnectionStatus.ERROR+ assert agentService.getProtocolConnectionStatus(config3.getReferenceOrThrow()) == ConnectionStatus.ERROR+ assert agentService.getProtocolConnectionStatus(config4.getReferenceOrThrow()) == ConnectionStatus.DISABLED+ assert collectedSharedEvents[0] instanceof AgentStatusEvent+ assert (collectedSharedEvents[0] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[0] as AgentStatusEvent).protocolConfigurationName == "mockConfig1"+ assert (collectedSharedEvents[0] as AgentStatusEvent).connectionStatus == ConnectionStatus.CONNECTING+ assert (collectedSharedEvents[1] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[1] as AgentStatusEvent).protocolConfigurationName == "mockConfig1"+ assert (collectedSharedEvents[1] as AgentStatusEvent).connectionStatus == ConnectionStatus.CONNECTED+ assert (collectedSharedEvents[2] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[2] as AgentStatusEvent).protocolConfigurationName == "mockConfig2"+ assert (collectedSharedEvents[2] as AgentStatusEvent).connectionStatus == ConnectionStatus.CONNECTING+ assert (collectedSharedEvents[3] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[3] as AgentStatusEvent).protocolConfigurationName == "mockConfig2"+ assert (collectedSharedEvents[3] as AgentStatusEvent).connectionStatus == ConnectionStatus.ERROR+ assert (collectedSharedEvents[4] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[4] as AgentStatusEvent).protocolConfigurationName == "mockConfig3"+ assert (collectedSharedEvents[4] as AgentStatusEvent).connectionStatus == ConnectionStatus.CONNECTING+ assert (collectedSharedEvents[5] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[5] as AgentStatusEvent).protocolConfigurationName == "mockConfig3"+ assert (collectedSharedEvents[5] as AgentStatusEvent).connectionStatus == ConnectionStatus.ERROR+ assert (collectedSharedEvents[6] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[6] as AgentStatusEvent).protocolConfigurationName == "mockConfig4"+ assert (collectedSharedEvents[6] as AgentStatusEvent).connectionStatus == ConnectionStatus.CONNECTING+ assert (collectedSharedEvents[7] as AgentStatusEvent).agentId == mockAgent.id+ assert (collectedSharedEvents[7] as AgentStatusEvent).protocolConfigurationName == "mockConfig4"+ assert (collectedSharedEvents[7] as AgentStatusEvent).connectionStatus == ConnectionStatus.DISABLED}when: "a mock thing asset is created that links to the mock protocol configurations"@@ -384,7 +439,10 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {assert mockThing.getAttribute("tempTarget1").get().getValueAsNumber().orElse(0d) == 30d}- cleanup: "the server should be stopped"+ cleanup: "the client should be stopped"+ clientEventService.close()++ and: "the server should be stopped"stopContainer(container)}}\ No newline at end of filediff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovyindex a493364c9..0e24c37a5 100644--- a/manager/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy@@ -72,7 +72,7 @@ class KNXImportTest extends Specification implements ManagerContainerTrait {then: "the protocol configurations should be linked and their deployment status should be available in the agent service"conditions.eventually {- assert agentService.getProtocolDeploymentStatus(knxAgent.getAttribute("knxConfigError1").get().getReferenceOrThrow()) == ConnectionStatus.ERROR+ assert agentService.getProtocolConnectionStatus(knxAgent.getAttribute("knxConfigError1").get().getReferenceOrThrow()) == ConnectionStatus.ERROR}when: "an authenticated admin user"diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovyindex a9f0df7bd..2aa0b0393 100644--- a/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy@@ -106,13 +106,13 @@ class KNXProtocolTest extends Specification implements ManagerContainerTrait {then: "the protocol configurations should be linked and their deployment status should be available in the agent service"conditions.eventually {- assert agentService.getProtocolDeploymentStatus(knxAgent.getAttribute("knxConfig").get().getReferenceOrThrow()) == ConnectionStatus.CONNECTED+ assert agentService.getProtocolConnectionStatus(knxAgent.getAttribute("knxConfig").get().getReferenceOrThrow()) == ConnectionStatus.CONNECTED}conditions.eventually {- assert agentService.getProtocolDeploymentStatus(knxAgent.getAttribute("knxConfigError1").get().getReferenceOrThrow()) == ConnectionStatus.ERROR+ assert agentService.getProtocolConnectionStatus(knxAgent.getAttribute("knxConfigError1").get().getReferenceOrThrow()) == ConnectionStatus.ERROR}conditions.eventually {- assert agentService.getProtocolDeploymentStatus(knxAgent.getAttribute("knxConfigError2").get().getReferenceOrThrow()) == ConnectionStatus.ERROR+ assert agentService.getProtocolConnectionStatus(knxAgent.getAttribute("knxConfigError2").get().getReferenceOrThrow()) == ConnectionStatus.ERROR}diff --git a/model/src/main/java/org/openremote/model/ValidationFailure.java b/model/src/main/java/org/openremote/model/ValidationFailure.javaindex e34b6bcf9..f48ad2010 100644--- a/model/src/main/java/org/openremote/model/ValidationFailure.java+++ b/model/src/main/java/org/openremote/model/ValidationFailure.java@@ -79,4 +79,12 @@ public class ValidationFailure {public Optional<String> getParameter() {return Optional.ofNullable(param);}++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "reason=" + reason ++ ", param='" + param + '\'' ++ '}';+ }}diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java b/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.javaindex 32a1d3844..1b56d15a2 100644--- a/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java@@ -19,7 +19,7 @@*/package org.openremote.model.asset.agent;-import org.openremote.model.event.shared.EventFilter;+import org.openremote.model.attribute.AttributeRef;import org.openremote.model.event.shared.SharedEvent;/**@@ -28,68 +28,31 @@ import org.openremote.model.event.shared.SharedEvent;*/public class AgentStatusEvent extends SharedEvent {- protected String realmId;- protected String assetId;- protected boolean newAssetChildren;+ protected AttributeRef protocolConfiguration;+ protected ConnectionStatus connectionStatus;protected AgentStatusEvent() {}- public AgentStatusEvent(long timestamp, String realmId, String assetId) {+ public AgentStatusEvent(long timestamp, AttributeRef protocolConfiguration, ConnectionStatus connectionStatus) {super(timestamp);- this.realmId = realmId;- this.assetId = assetId;+ this.protocolConfiguration = protocolConfiguration;+ this.connectionStatus = connectionStatus;}- public AgentStatusEvent(long timestamp, String realmId, String parentId, boolean newAssetChildren) {- this(timestamp, realmId, parentId);- this.newAssetChildren = newAssetChildren;+ public AttributeRef getProtocolConfiguration() {+ return protocolConfiguration;}- public AgentStatusEvent(long timestamp, String realmId, boolean newAssetChildren) {- this(timestamp, realmId, null);- this.newAssetChildren = newAssetChildren;- }-- /**- * @return The identifier of the realm/tenant for tenant and asset addition, removal, name change- * and relocation of in the tree events. For creation of child asset events, this is the identifier- * of the realm of a newly created root asset.- */- public String getRealmId() {- return realmId;- }-- /**- * @return The identifier of the asset for asset addition, removal, name change, and- * relocation in the tree events. For creation of child asset events, this is the- * identifier of the parent asset. Empty if a tenant was modified and/or no asset was affected.- */- public String getAssetId() {- return assetId;- }-- public boolean isTenantModified() {- return getRealmId() != null && getAssetId() == null;- }-- /**- * @return <code>true</code> if child assets were added to parent {@link #assetId} or {@link #realmId}.- */- public boolean isNewAssetChildren() {- return newAssetChildren;- }-- public void setNewAssetChildren(boolean newAssetChildren) {- this.newAssetChildren = newAssetChildren;+ public ConnectionStatus getConnectionStatus() {+ return connectionStatus;}@Overridepublic String toString() {return getClass().getSimpleName() + "{" +- "realmId='" + realmId + '\'' +- ", assetId='" + assetId + '\'' +- ", newAssetChildren=" + newAssetChildren ++ "protocolConfiguration=" + protocolConfiguration ++ ", connectionStatus=" + connectionStatus +'}';}}diff --git a/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java b/model/src/main/java/org/openremote/model/event/shared/SharedEvent.javaindex 2d1df2dfe..0da27ed45 100644--- a/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java+++ b/model/src/main/java/org/openremote/model/event/shared/SharedEvent.java@@ -41,7 +41,7 @@ import org.openremote.model.syslog.SyslogEvent;@JsonSubTypes.Type(value = ReadAssetAttributesEvent.class, name = "read-asset-attributes"),@JsonSubTypes.Type(value = AssetTreeModifiedEvent.class, name = "asset-tree-modified"),@JsonSubTypes.Type(value = SimulatorState.class, name = "simulator-state"),- @JsonSubTypes.Type(value = RequestSimulatorState.class, name = "request-simulator-state")+ @JsonSubTypes.Type(value = RequestSimulatorState.class, name = "request-simulator-state"),@JsonSubTypes.Type(value = AgentStatusEvent.class, name = "agent-status")})@JsonTypeInfo(