Skip to content

armgit / core

Public Imported from GitHub
0

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

Added plain JSON attribute value editor

Christian Bauer49c646f68d16
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.java
index d7157acc7..3589d5ec2 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantImpl.java
@@ -25,10 +25,9 @@ import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.SimpleCheckBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.inject.Provider;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.app.dialog.Confirmation;
import org.openremote.manager.client.widget.FormCheckBox;
import org.openremote.manager.client.widget.FormGroup;
import org.openremote.manager.client.widget.FormViewImpl;
@@ -71,7 +70,7 @@ public class AdminTenantImpl extends FormViewImpl implements AdminTenant {
protected Presenter presenter;
@Inject
- public AdminTenantImpl(Provider<ConfirmationDialog> confirmationDialogProvider) {
+ public AdminTenantImpl(Provider<Confirmation> confirmationDialogProvider) {
super(confirmationDialogProvider);
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java
index 76dd35890..4a39d2d9a 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserImpl.java
@@ -27,7 +27,7 @@ import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.*;
import com.google.inject.Provider;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.app.dialog.Confirmation;
import org.openremote.manager.client.widget.FormCheckBox;
import org.openremote.manager.client.widget.FormGroup;
import org.openremote.manager.client.widget.FormViewImpl;
@@ -107,7 +107,7 @@ public class AdminUserImpl extends FormViewImpl implements AdminUser {
protected Presenter presenter;
@Inject
- public AdminUserImpl(Provider<ConfirmationDialog> confirmationDialogProvider) {
+ public AdminUserImpl(Provider<Confirmation> confirmationDialogProvider) {
super(confirmationDialogProvider);
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/AppModule.java b/manager/client/src/main/java/org/openremote/manager/client/app/AppModule.java
index 3fda73187..e3454e887 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/AppModule.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/AppModule.java
@@ -21,10 +21,7 @@ package org.openremote.manager.client.app;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Singleton;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
-import org.openremote.manager.client.app.dialog.ConfirmationDialogImpl;
-import org.openremote.manager.client.app.dialog.Dialog;
-import org.openremote.manager.client.app.dialog.DialogImpl;
+import org.openremote.manager.client.app.dialog.*;
public class AppModule extends AbstractGinModule {
@@ -35,6 +32,7 @@ public class AppModule extends AbstractGinModule {
bind(HeaderView.class).to(HeaderViewImpl.class).in(Singleton.class);
bind(FooterView.class).to(FooterViewImpl.class).in(Singleton.class);
bind(Dialog.class).to(DialogImpl.class);
- bind(ConfirmationDialog.class).to(ConfirmationDialogImpl.class);
+ bind(Confirmation.class).to(ConfirmationImpl.class);
+ bind(JsonEditor.class).to(JsonEditorImpl.class);
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.java b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/Confirmation.java
similarity index 96%
rename from manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.java
rename to manager/client/src/main/java/org/openremote/manager/client/app/dialog/Confirmation.java
index f95e89902..d5a5117c2 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialog.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/Confirmation.java
@@ -19,7 +19,7 @@
*/
package org.openremote.manager.client.app.dialog;
-public interface ConfirmationDialog {
+public interface Confirmation {
void setTitle(String title);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.java b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationImpl.java
similarity index 92%
rename from manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.java
rename to manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationImpl.java
index aea01ec98..f96e0eff9 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationDialogImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/ConfirmationImpl.java
@@ -26,7 +26,7 @@ import org.openremote.manager.client.widget.PushButton;
import javax.inject.Inject;
-public class ConfirmationDialogImpl implements ConfirmationDialog {
+public class ConfirmationImpl implements Confirmation {
final protected Dialog dialog;
@@ -34,9 +34,9 @@ public class ConfirmationDialogImpl implements ConfirmationDialog {
protected Runnable onCancel;
@Inject
- public ConfirmationDialogImpl(Dialog dialog,
- WidgetStyle widgetStyle,
- ManagerMessages managerMessages) {
+ public ConfirmationImpl(Dialog dialog,
+ WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
this.dialog = dialog;
dialog.setModal(true);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/JsonEditor.java b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/JsonEditor.java
new file mode 100644
index 000000000..0753bfb87
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/JsonEditor.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017, 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.app.dialog;
+
+import org.openremote.model.value.Value;
+
+import java.util.function.Consumer;
+
+public interface JsonEditor {
+
+ void setTitle(String title);
+
+ void setValue(Value value);
+
+ void setOnApply(Consumer<Value> onApply);
+
+ void setOnReset(Runnable onReset);
+
+ void setOnCancel(Runnable onCancel);
+
+ void show();
+
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/dialog/JsonEditorImpl.java b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/JsonEditorImpl.java
new file mode 100644
index 000000000..2dbec39a2
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/dialog/JsonEditorImpl.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2017, 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.app.dialog;
+
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.InlineLabel;
+import com.google.gwt.user.client.ui.TextArea;
+import org.openremote.manager.client.i18n.ManagerMessages;
+import org.openremote.manager.client.style.WidgetStyle;
+import org.openremote.manager.client.widget.IconLabel;
+import org.openremote.manager.client.widget.PushButton;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueException;
+import org.openremote.model.value.Values;
+import org.openremote.model.value.impl.ValueUtil;
+
+import javax.inject.Inject;
+import java.util.function.Consumer;
+
+public class JsonEditorImpl implements JsonEditor {
+
+ final protected Dialog dialog;
+ final protected WidgetStyle widgetStyle;
+ final protected ManagerMessages managerMessages;
+
+ TextArea editor;
+ FlowPanel errorPanel = new FlowPanel();
+ Consumer<Value> onApply;
+ Runnable onReset;
+ Runnable onCancel;
+
+ @Inject
+ public JsonEditorImpl(Dialog dialog,
+ WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
+ this.dialog = dialog;
+ this.widgetStyle = widgetStyle;
+ this.managerMessages = managerMessages;
+
+ dialog.setModal(true);
+ dialog.setAutoHideOnHistoryEvents(true);
+ dialog.addStyleName(widgetStyle.JsonEditor());
+
+ PushButton okButton = new PushButton();
+ okButton.setFocus(true);
+ okButton.setText(managerMessages.OK());
+ okButton.setIcon("check");
+ okButton.addStyleName(widgetStyle.FormControl());
+ okButton.addStyleName(widgetStyle.PushButton());
+ okButton.addStyleName(widgetStyle.FormButtonPrimary());
+ okButton.addClickHandler(event -> {
+ Value value = parseValue();
+ if (value != null) {
+ if (onApply != null)
+ onApply.accept(value);
+ dialog.hide();
+ }
+ });
+ dialog.getFooterPanel().add(okButton);
+
+ PushButton resetButton = new PushButton();
+ resetButton.setText(managerMessages.reset());
+ resetButton.setIcon("refresh");
+ resetButton.addStyleName(widgetStyle.FormControl());
+ resetButton.addStyleName(widgetStyle.PushButton());
+ resetButton.addStyleName(widgetStyle.FormButton());
+ resetButton.addClickHandler(event -> {
+ if (onReset != null)
+ onReset.run();
+ });
+ dialog.getFooterPanel().add(resetButton);
+
+ PushButton cancelButton = new PushButton();
+ cancelButton.setText(managerMessages.cancel());
+ cancelButton.setIcon("close");
+ cancelButton.addStyleName(widgetStyle.FormControl());
+ cancelButton.addStyleName(widgetStyle.PushButton());
+ cancelButton.addStyleName(widgetStyle.FormButton());
+ cancelButton.addClickHandler(event -> {
+ if (errorPanel.isVisible() && onReset != null) {
+ onReset.run();
+ }
+ dialog.hide();
+ if (onCancel != null)
+ onCancel.run();
+ });
+ dialog.getFooterPanel().add(cancelButton);
+
+ errorPanel.setStyleName("flex-none layout horizontal error");
+ errorPanel.addStyleName(widgetStyle.FormMessages());
+ errorPanel.setVisible(false);
+ dialog.getContentPanel().add(errorPanel);
+
+ editor = new TextArea();
+ editor.setHeight("30em");
+ dialog.getContentPanel().add(editor);
+ }
+
+ @Override
+ public void setTitle(String title) {
+ dialog.setHeaderLabel(title);
+ }
+
+ @Override
+ public void setValue(Value value) {
+ errorPanel.clear();
+ errorPanel.setVisible(false);
+ editor.setText(value != null ? ValueUtil.stringify(value, 4) : null);
+ }
+
+ @Override
+ public void setOnApply(Consumer<Value> onApply) {
+ this.onApply = onApply;
+ }
+
+ @Override
+ public void setOnReset(Runnable onReset) {
+ this.onReset = onReset;
+ }
+
+ @Override
+ public void setOnCancel(Runnable onCancel) {
+ this.onCancel = onCancel;
+ }
+
+ @Override
+ public void show() {
+ dialog.showCenter();
+ }
+
+ protected Value parseValue() {
+ errorPanel.clear();
+ Value value = null;
+ String error = null;
+ try {
+ value = Values.parse(editor.getText()).orElse(null);
+ if (value == null)
+ error = managerMessages.emptyJsonData();
+ } catch (ValueException ex) {
+ error = ex.getMessage();
+ }
+ if (error != null) {
+ IconLabel warningLabel = new IconLabel();
+ warningLabel.setIcon("warning");
+ warningLabel.addStyleName(widgetStyle.MessagesIcon());
+ errorPanel.add(warningLabel);
+ InlineLabel errorMessage = new InlineLabel(error);
+ errorPanel.add(errorMessage);
+ errorPanel.setVisible(true);
+ return null;
+ }
+ errorPanel.setVisible(false);
+ return value;
+ }
+}
\ No newline at end of file
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.java
index ccd40a03b..de5e5a2ed 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
@@ -29,7 +29,8 @@ import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.*;
import com.google.inject.Provider;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.app.dialog.Confirmation;
+import org.openremote.manager.client.app.dialog.JsonEditor;
import org.openremote.manager.client.assets.attributes.AttributesEditor;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetSelector;
@@ -151,14 +152,17 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
PushButton deleteButton;
final AssetBrowser assetBrowser;
+ final Provider<JsonEditor> jsonEditorProvider;
Presenter presenter;
AttributesEditor attributesEditor;
@Inject
public AssetEditImpl(AssetBrowser assetBrowser,
- Provider<ConfirmationDialog> confirmationDialogProvider,
+ Provider<Confirmation> confirmationDialogProvider,
+ Provider<JsonEditor> jsonEditorProvider,
ManagerMessages managerMessages) {
super(confirmationDialogProvider);
+ this.jsonEditorProvider = jsonEditorProvider;
this.assetBrowser = assetBrowser;
parentAssetSelector = new AssetSelector(
@@ -403,6 +407,11 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
return attributesEditorContainer;
}
+ @Override
+ public JsonEditor getJsonEditor() {
+ return jsonEditorProvider.get();
+ }
+
@Override
public ManagerMessages getMessages() {
return managerMessages;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.java
index 5b50ada96..0ccdebc23 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
@@ -31,7 +31,7 @@ import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.InsertPanel;
import com.google.inject.Provider;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.app.dialog.JsonEditor;
import org.openremote.manager.client.assets.attributes.AttributesBrowser;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.assets.browser.AssetSelector;
@@ -46,12 +46,9 @@ import org.openremote.model.value.ObjectValue;
import javax.inject.Inject;
import java.util.Date;
-import java.util.logging.Logger;
public class AssetViewImpl extends Composite implements AssetView {
- private static final Logger LOG = Logger.getLogger(AssetViewImpl.class.getName());
-
interface UI extends UiBinder<FlexSplitPanel, AssetViewImpl> {
}
@@ -137,15 +134,15 @@ public class AssetViewImpl extends Composite implements AssetView {
/* ############################################################################ */
final AssetBrowser assetBrowser;
- final Provider<ConfirmationDialog> confirmationDialogProvider;
+ final Provider<JsonEditor> jsonEditorProvider;
Presenter presenter;
AttributesBrowser attributesBrowser;
@Inject
public AssetViewImpl(AssetBrowser assetBrowser,
- Provider<ConfirmationDialog> confirmationDialogProvider) {
+ Provider<JsonEditor> jsonEditorProvider) {
this.assetBrowser = assetBrowser;
- this.confirmationDialogProvider = confirmationDialogProvider;
+ this.jsonEditorProvider = jsonEditorProvider;
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
@@ -296,6 +293,11 @@ public class AssetViewImpl extends Composite implements AssetView {
return attributesBrowserContainer;
}
+ @Override
+ public JsonEditor getJsonEditor() {
+ return jsonEditorProvider.get();
+ }
+
@Override
public ManagerMessages getMessages() {
return managerMessages;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
index 20c494e10..c3965b9d6 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
@@ -32,12 +32,12 @@ import org.openremote.model.attribute.Attribute;
import org.openremote.model.attribute.AttributeType;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.util.TextUtil;
-import org.openremote.model.value.ValueType;
-import org.openremote.model.value.Values;
+import org.openremote.model.value.*;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
+import java.util.function.Supplier;
import static org.openremote.model.attribute.Attribute.ATTRIBUTE_NAME_VALIDATOR;
@@ -325,20 +325,33 @@ public class AttributesEditor
boolean isEditable = item.getName().map(AssetMeta::isEditable).orElse(forceEditable);
// Validation failure of meta item marks the attribute form extension as error state
- Consumer<Boolean> resultConsumer = !forceEditable
- ? success -> attributeGroups.get(attribute).setErrorInExtension(!success)
+ Consumer<Boolean> resultConsumer = !forceEditable ?
+ success -> {
+ // Validate again in context of attribute
+ if (success) {
+ List<ValidationFailure> failures = attribute.getMetaItemValidationFailures(item);
+ if (!failures.isEmpty()) {
+ success = false;
+ formGroup.setError(true);
+ for (ValidationFailure failure : failures) {
+ showValidationError(item.getName().orElse(null), failure);
+ }
+ }
+ }
+ attributeGroups.get(attribute).setErrorInExtension(!success);
+ }
: null;
if (valueType.equals(ValueType.STRING)) {
String currentValue = item.getValue().map(Object::toString).orElse(null);
Consumer<String> updateConsumer = isEditable
- ? rawValue -> STRING_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null),formGroup, item, resultConsumer, rawValue))
+ ? rawValue -> STRING_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
: null;
editor = createStringEditorWidget(style, currentValue, Optional.empty(), updateConsumer);
} else if (valueType.equals(ValueType.NUMBER)) {
String currentValue = item.getValue().map(Object::toString).orElse(null);
Consumer<String> updateConsumer = isEditable
- ? rawValue -> TO_DOUBLE_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
+ ? rawValue -> DOUBLE_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
: null;
editor = createDecimalEditorWidget(style, currentValue, Optional.empty(), updateConsumer);
} else if (valueType.equals(ValueType.BOOLEAN)) {
@@ -347,6 +360,26 @@ public class AttributesEditor
? rawValue -> BOOLEAN_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
: null;
editor = createBooleanEditorWidget(style, currentValue, Optional.empty(), updateConsumer);
+ } else if (valueType.equals(ValueType.OBJECT)) {
+ ObjectValue currentValue = item.getValueAsObject().orElse(null);
+ Consumer<Value> updateConsumer = isEditable
+ ? rawValue -> VALUE_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
+ : null;
+ Supplier<Value> resetSupplier = () -> item.getValue().orElse(null);
+ String title = updateConsumer != null
+ ? environment.getMessages().edit() + " " + environment.getMessages().jsonObject()
+ : environment.getMessages().jsonObject();
+ editor = createJsonEditorWidget(style, title, currentValue, updateConsumer, resetSupplier);
+ } else if (valueType.equals(ValueType.ARRAY)) {
+ ArrayValue currentValue = item.getValueAsArray().orElse(null);
+ Consumer<Value> updateConsumer = isEditable
+ ? rawValue -> VALUE_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))
+ : null;
+ Supplier<Value> resetSupplier = () -> item.getValue().orElse(null);
+ String title = updateConsumer != null
+ ? environment.getMessages().edit() + " " + environment.getMessages().jsonArray()
+ : environment.getMessages().jsonArray();
+ editor = createJsonEditorWidget(style, title, currentValue, updateConsumer, resetSupplier);
} else {
FormField unsupportedField = new FormField();
unsupportedField.add(new FormOutputText(
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
index f4731bb3a..ef8939a1e 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
@@ -25,6 +25,7 @@ import com.google.gwt.user.client.ui.InsertPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.app.dialog.JsonEditor;
import org.openremote.manager.client.event.ShowFailureEvent;
import org.openremote.manager.client.event.ShowInfoEvent;
import org.openremote.manager.client.event.ShowSuccessEvent;
@@ -39,23 +40,27 @@ import org.openremote.model.asset.AssetMeta;
import org.openremote.model.attribute.AttributeType;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.util.TextUtil;
-import org.openremote.model.value.Value;
-import org.openremote.model.value.ValueType;
-import org.openremote.model.value.Values;
+import org.openremote.model.value.*;
import java.util.*;
import java.util.function.Consumer;
+import java.util.function.Supplier;
+import java.util.logging.Logger;
public abstract class AttributesView<
C extends AttributesView.Container<S>,
S extends AttributesView.Style
> {
+ private static final Logger LOG = Logger.getLogger(AttributesView.class.getName());
+
public interface Container<S extends AttributesView.Style> {
S getStyle();
InsertPanel getPanel();
+ JsonEditor getJsonEditor();
+
ManagerMessages getMessages();
}
@@ -109,9 +114,6 @@ public abstract class AttributesView<
for (ValidationFailure failure : failures) {
showValidationError(valueUpdate.fieldLabel, failure);
}
- if (valueUpdate.resultConsumer != null) {
- valueUpdate.resultConsumer.accept(false);
- }
}
if (valueUpdate.resultConsumer != null) {
valueUpdate.resultConsumer.accept(failures.isEmpty());
@@ -133,7 +135,7 @@ public abstract class AttributesView<
}
};
- public final ValueUpdater<String> TO_INTEGER_UPDATER = new ValueUpdater<String>() {
+ public final ValueUpdater<String> INTEGER_UPDATER = new ValueUpdater<String>() {
@Override
Value createValue(String rawValue) throws IllegalArgumentException {
try {
@@ -144,7 +146,7 @@ public abstract class AttributesView<
}
};
- public final ValueUpdater<String> TO_DOUBLE_UPDATER = new ValueUpdater<String>() {
+ public final ValueUpdater<String> DOUBLE_UPDATER = new ValueUpdater<String>() {
@Override
Value createValue(String rawValue) throws IllegalArgumentException {
try {
@@ -162,6 +164,13 @@ public abstract class AttributesView<
}
};
+ public final ValueUpdater<Value> VALUE_UPDATER = new ValueUpdater<Value>() {
+ @Override
+ Value createValue(Value rawValue) throws IllegalArgumentException {
+ return rawValue;
+ }
+ };
+
public static class TimestampLabel extends FlowPanel {
static protected DateTimeFormat dateFormat = DateTimeFormat.getFormat(Constants.DEFAULT_DATE_FORMAT);
@@ -240,6 +249,7 @@ public abstract class AttributesView<
List<ValidationFailure> failures = attribute.getValidationFailures();
if (!failures.isEmpty()) {
+ LOG.fine("Invalid " + attribute + ": " + failures);
attributeGroups.get(attribute).setError(true);
if (showValidationFailureMessage) {
for (ValidationFailure failure : failures) {
@@ -352,6 +362,8 @@ public abstract class AttributesView<
attributeEditor = createDecimalEditor(attribute, defaultValueItem, style, formGroup);
} else if (attributeType == AttributeType.BOOLEAN || attributeType.getValueType() == ValueType.BOOLEAN) {
attributeEditor = createBooleanEditor(attribute, defaultValueItem, style, formGroup);
+ } else if (attributeType.getValueType() == ValueType.ARRAY) {
+ attributeEditor = createArrayEditor(attribute, style, formGroup);
} else {
return null;
}
@@ -415,7 +427,7 @@ public abstract class AttributesView<
Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);
Consumer<String> updateConsumer = !isEditorReadOnly(attribute)
- ? rawValue -> TO_INTEGER_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ ? rawValue -> INTEGER_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
: null;
FlowPanel panel = new FlowPanel();
@@ -457,7 +469,7 @@ public abstract class AttributesView<
Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);
Consumer<String> updateConsumer = !isEditorReadOnly(attribute)
- ? rawValue -> TO_DOUBLE_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ ? rawValue -> DOUBLE_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
: null;
FlowPanel panel = new FlowPanel();
@@ -540,6 +552,87 @@ public abstract class AttributesView<
return input;
}
+ protected AttributeEditor createArrayEditor(AssetAttribute attribute, S style, FormGroup formGroup) {
+ Optional<ArrayValue> currentValue = attribute.getValue().flatMap(Values::getArray);
+
+ Consumer<Value> updateConsumer = !isEditorReadOnly(attribute)
+ ? rawValue -> VALUE_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ : null;
+
+ Supplier<Value> resetSupplier = () -> attribute.getValue().orElse(null);
+
+ String title = updateConsumer != null
+ ? environment.getMessages().edit() + " " + environment.getMessages().jsonArray()
+ : environment.getMessages().jsonArray();
+
+ FlowPanel panel = new FlowPanel();
+ panel.setStyleName("flex layout horizontal center");
+ FormButton editButton = createJsonEditorWidget(style, title, currentValue.orElse(null), updateConsumer, resetSupplier);
+ FlowPanel wrapper = new FlowPanel();
+ wrapper.setStyleName("flex layout horizontal center");
+ wrapper.add(editButton);
+ panel.add(wrapper);
+ if (isShowTimestamp(attribute)) {
+ TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());
+ panel.add(timestampLabel);
+ }
+
+ return () -> panel;
+ }
+
+ protected AttributeEditor createObjectEditor(AssetAttribute attribute, S style, FormGroup formGroup) {
+ Optional<ObjectValue> currentValue = attribute.getValue().flatMap(Values::getObject);
+
+ Consumer<Value> updateConsumer = !isEditorReadOnly(attribute)
+ ? rawValue -> VALUE_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))
+ : null;
+
+ Supplier<Value> resetSupplier = () -> attribute.getValue().orElse(null);
+
+ String title = updateConsumer != null
+ ? environment.getMessages().edit() + " " + environment.getMessages().jsonObject()
+ : environment.getMessages().jsonObject();
+
+ FlowPanel panel = new FlowPanel();
+ panel.setStyleName("flex layout horizontal center");
+ FormButton editButton = createJsonEditorWidget(style, title, currentValue.orElse(null), updateConsumer, resetSupplier);
+ FlowPanel wrapper = new FlowPanel();
+ wrapper.setStyleName("flex layout horizontal center");
+ wrapper.add(editButton);
+ panel.add(wrapper);
+ if (isShowTimestamp(attribute)) {
+ TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());
+ panel.add(timestampLabel);
+ }
+
+ return () -> panel;
+ }
+
+ protected FormButton createJsonEditorWidget(S style,
+ String title,
+ Value currentValue,
+ Consumer<Value> updateConsumer,
+ Supplier<Value> resetSupplier) {
+ JsonEditor jsonEditor = container.getJsonEditor();
+ jsonEditor.setTitle(title);
+
+ if (currentValue != null) {
+ jsonEditor.setValue(currentValue);
+ }
+
+ FormButton button = new FormButton();
+ button.setIcon("file-text-o");
+ button.setText(environment.getMessages().jsonArray());
+ button.addClickHandler(event -> jsonEditor.show());
+
+ jsonEditor.setOnReset(() -> jsonEditor.setValue(resetSupplier.get()));
+
+ if (updateConsumer != null) {
+ jsonEditor.setOnApply(updateConsumer);
+ }
+ return button;
+ }
+
protected FormInputText createFormInputText(String formFieldStyleName) {
FormInputText input = new FormInputText();
input.addStyleName(formFieldStyleName);
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.java
index 4b951fa05..8f385ba5f 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
@@ -349,8 +349,13 @@ public interface ManagerMessages extends Messages {
String noLogMessagesReceived();
- String editJsonObject();
+ String jsonObject();
- String editJsonArray();
+ String jsonArray();
+ String edit();
+
+ String emptyJsonData();
+
+ String reset();
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java
index bf973a216..ff68e8d1d 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/rules/RulesEditorImpl.java
@@ -33,7 +33,7 @@ import elemental.client.Browser;
import elemental.html.AnchorElement;
import elemental.html.Blob;
import elemental.html.FileReader;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.app.dialog.Confirmation;
import org.openremote.manager.client.assets.browser.AssetBrowser;
import org.openremote.manager.client.widget.*;
@@ -92,7 +92,7 @@ public class RulesEditorImpl
protected Presenter presenter;
@Inject
- public RulesEditorImpl(Provider<ConfirmationDialog> confirmationDialogProvider, AssetBrowser assetBrowser) {
+ public RulesEditorImpl(Provider<Confirmation> confirmationDialogProvider, AssetBrowser assetBrowser) {
super(confirmationDialogProvider);
this.assetBrowser = assetBrowser;
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.java
index aa1b4a1b7..3d33b2c05 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
@@ -404,4 +404,8 @@ public class WidgetStyle {
public String HighlightBackground() {
return "or-HighlightBackground";
}
+
+ public String JsonEditor() {
+ return "or-JsonEditor";
+ }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java
index 44a5371d0..db795f6ab 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormViewImpl.java
@@ -25,13 +25,13 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.inject.Provider;
-import org.openremote.manager.client.app.dialog.ConfirmationDialog;
+import org.openremote.manager.client.app.dialog.Confirmation;
import org.openremote.manager.client.i18n.ManagerMessages;
import org.openremote.manager.client.style.WidgetStyle;
public class FormViewImpl extends Composite implements FormView {
- protected final Provider<ConfirmationDialog> confirmationDialogProvider;
+ protected final Provider<Confirmation> confirmationDialogProvider;
@UiField
public WidgetStyle widgetStyle;
@@ -48,7 +48,7 @@ public class FormViewImpl extends Composite implements FormView {
@UiField
public FlowPanel formMessagesError;
- public FormViewImpl(Provider<ConfirmationDialog> confirmationDialogProvider) {
+ public FormViewImpl(Provider<Confirmation> confirmationDialogProvider) {
this.confirmationDialogProvider = confirmationDialogProvider;
}
@@ -96,11 +96,11 @@ public class FormViewImpl extends Composite implements FormView {
@Override
public void showConfirmation(String title, String text, Runnable onConfirm, Runnable onCancel) {
- ConfirmationDialog confirmationDialog = confirmationDialogProvider.get();
- confirmationDialog.setTitle(title);
- confirmationDialog.setText(text);
- confirmationDialog.setOnConfirm(onConfirm);
- confirmationDialog.setOnCancel(onCancel);
- confirmationDialog.show();
+ Confirmation confirmation = confirmationDialogProvider.get();
+ confirmation.setTitle(title);
+ confirmation.setText(text);
+ confirmation.setOnConfirm(onConfirm);
+ confirmation.setOnCancel(onCancel);
+ confirmation.show();
}
}
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.properties
index 74f1ebf1f..4c04508ac 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
@@ -229,7 +229,10 @@ pauseLog=Pause
continueLog=Continue
clearLog=Clear log
noLogMessagesReceived=No log messages received.
-editJsonObject=Edit JSON object
-editJsonArray=Edit JSON array
+jsonObject=JSON object
+jsonArray=JSON array
+edit=Edit
+emptyJsonData=Empty JSON data.
+reset=Reset
diff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.html
index 61ba4a3bd..f4a161e73 100644
--- a/manager/client/src/main/webapp/css/style.html
+++ b/manager/client/src/main/webapp/css/style.html
@@ -573,4 +573,9 @@
padding: 0.4em;
}
+ .or-JsonEditor {
+ width: 48em;
+ height: 30em;
+ }
+
</style>
\ No newline at end of file
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java
index 2d0d7a54c..4a6931b74 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
@@ -64,6 +64,7 @@ import static org.openremote.model.util.TextUtil.isValidURN;
public class AgentService extends RouteBuilder implements ContainerService, Consumer<AssetState>, ProtocolAssetService {
private static final Logger LOG = Logger.getLogger(AgentService.class.getName());
+
protected Container container;
protected AssetStorageService assetStorageService;
protected AssetDatapointService assetDatapointService;
@@ -150,14 +151,14 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
@Override
public void updateProtocolConfiguration(AssetAttribute protocolConfiguration) {
if (protocolConfiguration == null || !protocolConfiguration.getReference().isPresent()) {
- LOG.warning("Cannot update protocol configuration as it is not valid: " + protocolConfiguration);
+ LOG.warning("Cannot update invalid: " + protocolConfiguration);
return;
}
AttributeRef protocolRef = protocolConfiguration.getReference().get();
ServerAsset agent = assetStorageService.find(protocolRef.getEntityId(), true);
- if (agent == null || agent.getWellKnownType() != AssetType.AGENT || !agent.hasAttribute(protocolRef.getAttributeName())) {
- LOG.warning("Protocol configuration doesn't belong to a valid agent");
+ if (agent == null || agent.getWellKnownType() != AssetType.AGENT || !agent.hasAttribute(protocolRef.getAttributeName())) {
+ LOG.warning("Protocol configuration doesn't belong to a valid agent: " + protocolConfiguration);
return;
}
@@ -165,7 +166,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
@SuppressWarnings("ConstantConditions")
AssetAttribute oldProtocolConfiguration = agent.getAttribute(protocolRef.getAttributeName()).get();
if (oldProtocolConfiguration.getObjectValue().equals(protocolConfiguration.getObjectValue())) {
- LOG.fine("Protocol configuration hasn't changed so nothing to do here");
+ // Protocol configuration hasn't changed so nothing to do here
return;
}
@@ -264,7 +265,11 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
// Link any AGENT_LINK attributes to the referenced protocol
Map<AssetAttribute, List<AssetAttribute>> groupedAgentLinksAttributes =
- getGroupedAgentLinkAttributes(asset.getAttributesStream(), attribute -> true);
+ getGroupedAgentLinkAttributes(
+ asset.getAttributesStream(),
+ attribute -> true,
+ attribute -> LOG.warning("Linked protocol configuration not found: " + attribute)
+ );
groupedAgentLinksAttributes.forEach(this::linkAttributes);
break;
@@ -323,8 +328,11 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
)
);
- getGroupedAgentLinkAttributes(attributesToLink, attribute -> true)
- .forEach(this::linkAttributes);
+ getGroupedAgentLinkAttributes(
+ attributesToLink,
+ attribute -> true,
+ attribute -> LOG.warning("Linked protocol configuration not found: " + attribute)
+ ).forEach(this::linkAttributes);
break;
case DELETE: {
@@ -342,7 +350,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
}
protected void linkProtocolConfiguration(AssetAttribute protocolConfiguration) {
- LOG.finest("Linking all attributes that use protocol attribute: " + protocolConfiguration);
+ LOG.info("Linking all attributes that use protocol attribute: " + protocolConfiguration);
AttributeRef protocolAttributeRef = protocolConfiguration.getReferenceOrThrow();
Protocol protocol = getProtocol(protocolConfiguration);
@@ -396,12 +404,14 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
asset.getAttributesStream(),
assetAttribute -> getAgentLink(assetAttribute)
.map(attributeRef -> attributeRef.equals(protocolAttributeRef))
- .orElse(false)
+ .orElse(false),
+ attribute -> LOG.warning("Linked protocol configuration not found: " + attribute)
).forEach(this::linkAttributes)
);
}
protected void unlinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
+ LOG.info("Unlinking all attributes that use protocol attribute: " + protocolConfiguration);
AttributeRef protocolAttributeRef = protocolConfiguration.getReferenceOrThrow();
// Get all assets that have attributes that use this protocol configuration
@@ -470,7 +480,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
Protocol protocol = getProtocol(protocolConfiguration);
if (protocol == null) {
- LOG.severe("Cannot link protocol attributes as protocol is null");
+ LOG.severe("Cannot link protocol attributes as protocol is null: " + protocolConfiguration);
return;
}
@@ -488,7 +498,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
Protocol protocol = getProtocol(protocolConfiguration);
if (protocol == null) {
- LOG.severe("Cannot unlink protocol attributes as protocol is null");
+ LOG.severe("Cannot unlink protocol attributes as protocol is null: " + protocolConfiguration);
return;
}
@@ -563,6 +573,13 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
@SuppressWarnings("ConstantConditions")
protected Map<AssetAttribute, List<AssetAttribute>> getGroupedAgentLinkAttributes(Stream<AssetAttribute> attributes,
Predicate<AssetAttribute> filter) {
+
+ return getGroupedAgentLinkAttributes(attributes, filter, null);
+ }
+
+ protected Map<AssetAttribute, List<AssetAttribute>> getGroupedAgentLinkAttributes(Stream<AssetAttribute> attributes,
+ Predicate<AssetAttribute> filter,
+ Consumer<AssetAttribute> notFoundConsumer) {
Map<AssetAttribute, List<AssetAttribute>> result = new HashMap<>();
attributes
.filter(AgentLink::hasAgentLink)
@@ -570,7 +587,14 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons
.map(attribute -> new Pair<>(attribute, getAgentLink(attribute)))
.filter(pair -> pair.value.isPresent())
.map(pair -> new Pair<>(pair.key, getProtocolConfiguration(pair.value.get())))
- .filter(pair -> pair.value.isPresent())
+ .filter(pair -> {
+ if (pair.value.isPresent()) {
+ return true;
+ } else if (notFoundConsumer != null) {
+ notFoundConsumer.accept(pair.key);
+ }
+ return false;
+ })
.forEach(pair -> result.computeIfAbsent(pair.value.get(), newProtocolConfiguration -> new ArrayList<>())
.add(pair.key)
);
diff --git a/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java b/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java
index dd3f655f5..06a75dca9 100644
--- a/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java
+++ b/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java
@@ -24,16 +24,17 @@ import java.util.logging.Logger;
public enum SyslogCategory {
- ASSET_STORAGE(
- "Asset Storage",
+ ASSET(
+ "Asset Processing",
false,
+ "AssetProcessingService",
"AssetStorageService",
"AssetDatapointService"
),
- ASSET_PROCESSING(
- "Asset Processing",
+ AGENT(
+ "Agents",
false,
- "AssetProcessingService"
+ "AgentService"
),
RULES(
"Rules",