100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Work on Simulator UI and notifications
Christian Bauerb2c071a1d37f
diff --git a/console/android/src/main/java/org/openremote/android/ORFirebaseInstanceIDService.java b/console/android/src/main/java/org/openremote/android/ORFirebaseInstanceIDService.javaindex edf53e565..3ba7ea689 100644--- a/console/android/src/main/java/org/openremote/android/ORFirebaseInstanceIDService.java+++ b/console/android/src/main/java/org/openremote/android/ORFirebaseInstanceIDService.java@@ -23,6 +23,10 @@ import com.google.firebase.iid.FirebaseInstanceIdService;import org.openremote.android.service.TokenService;+/**+ * This runs only once when the application is started for the first time after install. To generate+ * new device tokens and send them to the server, uninstall the app first.+ */public class ORFirebaseInstanceIDService extends FirebaseInstanceIdService {private static final String TAG = "ORFirebaseIIDService";diff --git a/manager/client/src/main/java/org/openremote/manager/client/Environment.java b/manager/client/src/main/java/org/openremote/manager/client/Environment.javaindex 44ef25dc5..8fdb799cc 100644--- a/manager/client/src/main/java/org/openremote/manager/client/Environment.java+++ b/manager/client/src/main/java/org/openremote/manager/client/Environment.java@@ -21,12 +21,15 @@ package org.openremote.manager.client;import com.google.gwt.place.shared.PlaceController;import com.google.gwt.place.shared.PlaceHistoryMapper;-import org.openremote.model.event.bus.EventBus;import org.openremote.manager.client.i18n.ManagerMessages;import org.openremote.manager.client.service.EventService;import org.openremote.manager.client.service.RequestService;import org.openremote.manager.client.service.SecurityService;+import org.openremote.manager.client.simulator.Simulator;import org.openremote.manager.client.style.WidgetStyle;+import org.openremote.model.event.bus.EventBus;++import javax.inject.Provider;/*** Bundle all typically needed dependencies of activities/presenters, so@@ -34,7 +37,15 @@ import org.openremote.manager.client.style.WidgetStyle;*/public interface Environment {- static Environment create(SecurityService securityService,+ /**+ * Various managed components with dependent lifecycle.+ */+ interface Factory {+ Provider<Simulator> getSimulatorProvider();+ }++ static Environment create(Factory factory,+ SecurityService securityService,RequestService requestService,EventService eventService,PlaceController placeController,@@ -43,6 +54,12 @@ public interface Environment {ManagerMessages managerMessages,WidgetStyle widgetStyle) {return new Environment() {++ @Override+ public Factory getFactory() {+ return factory;+ }+@Overridepublic SecurityService getSecurityService() {return securityService;@@ -107,4 +124,6 @@ public interface Environment {WidgetStyle getWidgetStyle();+ Factory getFactory();+}diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerModule.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerModule.javaindex 959870124..9d46464a0 100644--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerModule.java+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerModule.java@@ -23,6 +23,7 @@ import com.google.gwt.inject.client.AbstractGinModule;import com.google.gwt.place.shared.PlaceController;import com.google.gwt.place.shared.PlaceHistoryHandler;import com.google.gwt.place.shared.PlaceHistoryMapper;+import com.google.inject.Provider;import com.google.inject.Provides;import com.google.inject.Singleton;import org.openremote.manager.client.event.*;@@ -33,11 +34,11 @@ import org.openremote.manager.client.map.MapAssetPlace;import org.openremote.manager.client.mvp.AppActivityManager;import org.openremote.manager.client.mvp.AppPlaceController;import org.openremote.manager.client.service.*;+import org.openremote.manager.client.simulator.Simulator;import org.openremote.manager.client.style.WidgetStyle;import org.openremote.manager.shared.security.Tenant;import org.openremote.manager.shared.security.TenantResource;import org.openremote.model.event.bus.EventBus;-import org.openremote.manager.client.service.EventService;public class ManagerModule extends AbstractGinModule {@@ -64,8 +65,15 @@ public class ManagerModule extends AbstractGinModule {PlaceHistoryMapper placeHistoryMapper,EventBus eventBus,ManagerMessages managerMessages,- WidgetStyle widgetStyle) {+ WidgetStyle widgetStyle,+ Provider<Simulator> simulatorProvider) {return Environment.create(+ new Environment.Factory() {+ @Override+ public Provider<Simulator> getSimulatorProvider() {+ return simulatorProvider;+ }+ },securityService,requestService,eventService,diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.javaindex 233056d96..b0afd1ff4 100644--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java@@ -20,15 +20,17 @@package org.openremote.manager.client.assets.attributes;import com.google.gwt.user.client.ui.IsWidget;-import com.google.gwt.user.client.ui.Widget;import elemental.client.Browser;import org.openremote.manager.client.Environment;import org.openremote.manager.client.datapoint.DatapointBrowser;+import org.openremote.manager.client.simulator.Simulator;import org.openremote.manager.client.util.CollectionsUtil;import org.openremote.manager.client.widget.*;+import org.openremote.model.Constants;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.ReadAssetAttributesEvent;+import org.openremote.model.asset.agent.ProtocolConfiguration;import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeExecuteStatus;import org.openremote.model.attribute.AttributeState;@@ -121,83 +123,93 @@ public abstract class AttributesBrowserprotected void addAttributeActions(AssetAttribute attribute,FormGroup formGroup,FormField formField,- FormGroupActions formGroupActions,- IsWidget editor) {-- // Allow read/write of attribute if we understand attribute type (have an editor)- if (editor != null) {-- if (attribute.isExecutable()) {- // A command is executed by writing a special value- FormButton startButton = new FormButton();- startButton.setEnabled(!attribute.isReadOnly());- startButton.setText(container.getMessages().start());- startButton.setPrimary(true);- startButton.setIcon("play-circle");- startButton.addClickHandler(clickEvent -> {- attribute.setValue(AttributeExecuteStatus.REQUEST_START.asValue());- writeAttributeValue(attribute);- });- formGroupActions.add(startButton);-- FormButton repeatButton = new FormButton();- repeatButton.setEnabled(!attribute.isReadOnly());- repeatButton.setText(container.getMessages().repeat());- repeatButton.setPrimary(true);- repeatButton.setIcon("repeat");- repeatButton.addClickHandler(clickEvent -> {- attribute.setValue(AttributeExecuteStatus.REQUEST_REPEATING.asValue());- writeAttributeValue(attribute);- });- formGroupActions.add(repeatButton);-- FormButton cancelButton = new FormButton();- cancelButton.setEnabled(!attribute.isReadOnly());- cancelButton.setText(container.getMessages().cancel());- cancelButton.setPrimary(true);- cancelButton.setIcon("stop-circle");- cancelButton.addClickHandler(clickEvent -> {- attribute.setValue(AttributeExecuteStatus.REQUEST_CANCEL.asValue());- writeAttributeValue(attribute);- });- formGroupActions.add(cancelButton);-- FormButton readStatusButton = new FormButton();- readStatusButton.setText(container.getMessages().getStatus());- readStatusButton.setIcon("cloud-download");- readStatusButton.addClickHandler(clickEvent -> readAttributeValue(attribute));- readButtons.add(readStatusButton);- formGroupActions.add(readStatusButton);-- } else {- // Default read/write actions- FormButton writeValueButton = new FormButton();- writeValueButton.setEnabled(!attribute.isReadOnly());- writeValueButton.setText(container.getMessages().write());- writeValueButton.setPrimary(true);- writeValueButton.setIcon("cloud-upload");- writeValueButton.addClickHandler(clickEvent -> writeAttributeValue(attribute));- formGroupActions.add(writeValueButton);-- FormButton readValueButton = new FormButton();- readValueButton.setText(container.getMessages().read());- readValueButton.setIcon("cloud-download");- readValueButton.addClickHandler(clickEvent -> readAttributeValue(attribute));- readButtons.add(readValueButton);- formGroupActions.add(readValueButton);- }+ FormGroupActions formGroupActions) {++ if (attribute.isExecutable()) {+ // A command is executed by writing a special value+ FormButton startButton = new FormButton();+ startButton.setEnabled(!attribute.isReadOnly());+ startButton.setText(container.getMessages().start());+ startButton.setPrimary(true);+ startButton.setIcon("play-circle");+ startButton.addClickHandler(clickEvent -> {+ attribute.setValue(AttributeExecuteStatus.REQUEST_START.asValue());+ writeAttributeValue(attribute);+ });+ formGroupActions.add(startButton);++ FormButton repeatButton = new FormButton();+ repeatButton.setEnabled(!attribute.isReadOnly());+ repeatButton.setText(container.getMessages().repeat());+ repeatButton.setPrimary(true);+ repeatButton.setIcon("repeat");+ repeatButton.addClickHandler(clickEvent -> {+ attribute.setValue(AttributeExecuteStatus.REQUEST_REPEATING.asValue());+ writeAttributeValue(attribute);+ });+ formGroupActions.add(repeatButton);++ FormButton cancelButton = new FormButton();+ cancelButton.setEnabled(!attribute.isReadOnly());+ cancelButton.setText(container.getMessages().cancel());+ cancelButton.setPrimary(true);+ cancelButton.setIcon("stop-circle");+ cancelButton.addClickHandler(clickEvent -> {+ attribute.setValue(AttributeExecuteStatus.REQUEST_CANCEL.asValue());+ writeAttributeValue(attribute);+ });+ formGroupActions.add(cancelButton);++ FormButton readStatusButton = new FormButton();+ readStatusButton.setText(container.getMessages().getStatus());+ readStatusButton.setIcon("cloud-download");+ readStatusButton.addClickHandler(clickEvent -> readAttributeValue(attribute));+ readButtons.add(readStatusButton);+ formGroupActions.add(readStatusButton);++ } else {+ // Default read/write actions+ FormButton writeValueButton = new FormButton();+ writeValueButton.setEnabled(!attribute.isReadOnly());+ writeValueButton.setText(container.getMessages().write());+ writeValueButton.setPrimary(true);+ writeValueButton.setIcon("cloud-upload");+ writeValueButton.addClickHandler(clickEvent -> writeAttributeValue(attribute));+ formGroupActions.add(writeValueButton);++ FormButton readValueButton = new FormButton();+ readValueButton.setText(container.getMessages().read());+ readValueButton.setIcon("cloud-download");+ readValueButton.addClickHandler(clickEvent -> readAttributeValue(attribute));+ readButtons.add(readValueButton);+ formGroupActions.add(readValueButton);}}@Overrideprotected void addAttributeExtensions(AssetAttribute attribute,FormGroup formGroup) {- Widget datapointBrowser = createDatapointBrowser(attribute);++ boolean haveExtensions = false;++ IsWidget datapointBrowser = createDatapointBrowser(attribute);if (datapointBrowser != null) {FormSectionLabel sectionLabel = new FormSectionLabel(environment.getMessages().historicalData());formGroup.addExtension(sectionLabel);formGroup.addExtension(datapointBrowser);- } else {+ haveExtensions = true;+ }++ IsWidget simulator = createSimulator(attribute);+ if (simulator != null) {+ FormSectionLabel sectionLabel = new FormSectionLabel(environment.getMessages().simulator());+ formGroup.addExtension(sectionLabel);+ formGroup.addExtension(simulator);+ haveExtensions = true;+ }+++ if (!haveExtensions) {formGroup.showDisabledExtensionToggle();}}@@ -268,12 +280,7 @@ public abstract class AttributesBrowserif (formField.getWidgetCount() > 0) {formField.getWidget(0).removeFromParent();}- final AttributeEditor editor = createEditor(attribute, formGroup);- if (editor == null) {- formField.add(createUnsupportedEditor(attribute));- return;- }-+ final IsWidget editor = createAttributeValueEditor(attribute, formGroup);formField.add(editor);// "Blink" the editor so users know there might be a new value@@ -308,6 +315,13 @@ public abstract class AttributesBrowserreturn null;}+ protected Simulator createSimulator(AssetAttribute attribute) {+ return environment.getSecurityService().isSuperUser() && ProtocolConfiguration.isProtocolConfiguration(attribute)+ ? ProtocolConfiguration.getProtocolName(attribute)+ .filter(name -> name.equals(Constants.PROTOCOL_NAMESPACE + ":simulator"))+ .map(name ->environment.getFactory().getSimulatorProvider().get()).orElse(null) : null;+ }+/* ####################################################################### */abstract protected void getNumberDatapoints(AssetAttribute assetAttribute,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.javaindex 9f0fbf97a..b8d12e36c 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@@ -38,6 +38,7 @@ import java.util.Optional;import java.util.function.Consumer;import java.util.function.Supplier;+import static org.openremote.manager.client.widget.ValueEditors.*;import static org.openremote.model.attribute.Attribute.ATTRIBUTE_NAME_VALIDATOR;import static org.openremote.model.attribute.Attribute.isAttributeNameEqualTo;@@ -61,7 +62,7 @@ public class AttributesEditorprotected FormLabel createAttributeLabel(AssetAttribute attribute) {FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 30));- formLabel.addStyleName("larger");+ formLabel.getElement().getStyle().setWidth(20, com.google.gwt.dom.client.Style.Unit.EM);return formLabel;}@@ -79,8 +80,7 @@ public class AttributesEditorprotected void addAttributeActions(AssetAttribute attribute,FormGroup formGroup,FormField formField,- FormGroupActions formGroupActions,- IsWidget editor) {+ FormGroupActions formGroupActions) {FormButton deleteButton = new FormButton();deleteButton.setText(container.getMessages().deleteAttribute());@@ -191,7 +191,7 @@ public class AttributesEditorFormGroup formGroup = new FormGroup();FormLabel label = new FormLabel(item.getName().orElse(null));- label.addStyleName("largest");+ label.getElement().getStyle().setWidth(40, com.google.gwt.dom.client.Style.Unit.EM);formGroup.addFormLabel(label);FormField formField = new FormField();@@ -265,82 +265,66 @@ public class AttributesEditoritemValueEditorGroup.addFormGroupActions(formGroupActions);}- protected IsWidget createEditor(MetaItem item, ValueType valueType, boolean forceEditable, FormGroup formGroup) {- IsWidget editor;-+ protected IsWidget createEditor(MetaItem item, ValueType valueType, boolean isNewMetaItem, FormGroup formGroup) {AttributesEditor.Style style = container.getStyle();// For some meta items we know if we can edit them or not... custom items are always editable- 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 -> {- // 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);- }+ boolean isEditable = item.getName().map(AssetMeta::isEditable).orElse(isNewMetaItem);++ Consumer<List<ValidationFailure>> validationResultConsumer =+ failures -> {+ // If we are not creating a new meta item, validate again in context of attribute+ if (!isNewMetaItem && failures.isEmpty()) {+ failures = attribute.getMetaItemValidationFailures(item);+ }+ if (!failures.isEmpty()) {+ formGroup.setError(true);+ for (ValidationFailure failure : failures) {+ showValidationError(item.getName().orElse(null), failure);}}- attributeGroups.get(attribute).setErrorInExtension(!success);- }- : null;+ // Validation failure of meta item marks the attribute form extension as error state+ if (!isNewMetaItem) {+ attributeGroups.get(attribute).setErrorInExtension(!failures.isEmpty());+ }+ };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))- : null;- editor = createStringEditorWidget(style, currentValue, Optional.empty(), updateConsumer);+ return createStringEditor(+ item, currentValue, null, false, style.stringEditor(), formGroup, false, validationResultConsumer+ );} else if (valueType.equals(ValueType.NUMBER)) {String currentValue = item.getValue().map(Object::toString).orElse(null);- Consumer<String> updateConsumer = isEditable- ? rawValue -> DOUBLE_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))- : null;- editor = createNumberEditorWidget(style, currentValue, Optional.empty(), updateConsumer);+ return createNumberEditor(+ item, currentValue, null, false, style.numberEditor(), formGroup, false, validationResultConsumer+ );} else if (valueType.equals(ValueType.BOOLEAN)) {Boolean currentValue = item.getValueAsBoolean().orElse(null);- Consumer<Boolean> updateConsumer = isEditable- ? rawValue -> BOOLEAN_UPDATER.accept(new ValueUpdate<>(item.getName().orElse(null), formGroup, item, resultConsumer, rawValue))- : null;- editor = createBooleanEditorWidget(style, currentValue, Optional.empty(), updateConsumer);+ return createBooleanEditor(+ item, currentValue, null, false, style.booleanEditor(), formGroup, false, validationResultConsumer+ );} 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;+ String label = environment.getMessages().jsonObject();+ String title = environment.getMessages().edit() + " " + environment.getMessages().jsonObject();Supplier<Value> resetSupplier = () -> item.getValue().orElse(null);- String title = updateConsumer != null- ? environment.getMessages().edit() + " " + environment.getMessages().jsonObject()- : environment.getMessages().jsonObject();- editor = createJsonEditorWidget(- style, environment.getMessages().jsonObject(), title, currentValue, updateConsumer, resetSupplier+ return createObjectEditor(+ attribute, currentValue, resetSupplier, false, label, title, container.getJsonEditor(), formGroup, false, validationResultConsumer);} 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;+ String label = environment.getMessages().jsonArray();+ String title = environment.getMessages().edit() + " " + environment.getMessages().jsonArray();Supplier<Value> resetSupplier = () -> item.getValue().orElse(null);- String title = updateConsumer != null- ? environment.getMessages().edit() + " " + environment.getMessages().jsonArray()- : environment.getMessages().jsonArray();- editor = createJsonEditorWidget(- style, environment.getMessages().jsonArray(), title, currentValue, updateConsumer, resetSupplier+ return createArrayEditor(+ attribute, currentValue, resetSupplier, false, label, title, container.getJsonEditor(), formGroup, false, validationResultConsumer);} else {- FormField unsupportedField = new FormField();- unsupportedField.add(new FormOutputText(+ return new FormOutputText(environment.getMessages().unsupportedMetaItemType(valueType.name())- ));- editor = unsupportedField;+ );}- return editor;}/**@@ -372,7 +356,8 @@ public class AttributesEditorformField.add(new FormOutputText(environment.getMessages().or()));- FormInputText itemNameInput = createFormInputText(container.getStyle().stringEditor());+ FormInputText itemNameInput = new FormInputText();+ itemNameInput.addStyleName(container.getStyle().stringEditor());itemNameInput.setPlaceholder(environment.getMessages().enterCustomAssetAttributeMetaName());itemNameInput.addValueChangeHandler(event -> item.setName(event.getValue()));formField.add(itemNameInput);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.javaindex d1b4b4aaf..2f51cb706 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@@ -19,7 +19,6 @@*/package org.openremote.manager.client.assets.attributes;-import com.google.gwt.i18n.client.DateTimeFormat;import com.google.gwt.user.client.ui.*;import org.openremote.manager.client.Environment;import org.openremote.manager.client.app.dialog.JsonEditor;@@ -30,7 +29,6 @@ import org.openremote.manager.client.i18n.ManagerMessages;import org.openremote.manager.client.util.CollectionsUtil;import org.openremote.manager.client.widget.*;import org.openremote.model.AbstractValueHolder;-import org.openremote.model.Constants;import org.openremote.model.ValidationFailure;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetMeta;@@ -44,6 +42,8 @@ import java.util.function.Consumer;import java.util.function.Supplier;import java.util.logging.Logger;+import static org.openremote.manager.client.widget.ValueEditors.*;+public abstract class AttributesView<C extends AttributesView.Container<S>,S extends AttributesView.Style@@ -74,116 +74,9 @@ public abstract class AttributesView<String highlightAttribute();}- public interface AttributeEditor extends IsWidget {- }-- public class ValueUpdate<T> {-- final String fieldLabel;- final FormGroup formGroup;- final AbstractValueHolder valueHolder;- final Consumer<Boolean> resultConsumer;- final T rawValue;-- public ValueUpdate(String fieldLabel, FormGroup formGroup, AbstractValueHolder valueHolder, Consumer<Boolean> resultConsumer, T rawValue) {- this.fieldLabel = fieldLabel;- this.formGroup = formGroup;- this.valueHolder = valueHolder;- this.resultConsumer = resultConsumer;- this.rawValue = rawValue;- }- }-- public abstract class ValueUpdater<T> implements Consumer<ValueUpdate<T>> {-- @Override- public void accept(ValueUpdate<T> valueUpdate) {- valueUpdate.formGroup.setError(false);- List<ValidationFailure> failures = new ArrayList<>();- try {- valueUpdate.valueHolder.setValue(- valueUpdate.rawValue != null ? createValue(valueUpdate.rawValue) : null- );- failures.addAll(valueUpdate.valueHolder.getValidationFailures());- } catch (IllegalArgumentException ex) {- failures.add(ex::getMessage);- }- if (!failures.isEmpty()) {- valueUpdate.formGroup.setError(true);- for (ValidationFailure failure : failures) {- showValidationError(valueUpdate.fieldLabel, failure);- }- }- if (valueUpdate.resultConsumer != null) {- valueUpdate.resultConsumer.accept(failures.isEmpty());- }- }-- abstract Value createValue(T rawValue) throws IllegalArgumentException;- }-- public enum ConversionValidationFailure implements ValidationFailure {- NOT_A_VALID_NUMBER- }-- public final ValueUpdater<String> STRING_UPDATER = new ValueUpdater<String>() {- @Override- Value createValue(String rawValue) throws IllegalArgumentException {- return Values.create(rawValue);- }- };-- public final ValueUpdater<String> DOUBLE_UPDATER = new ValueUpdater<String>() {- @Override- Value createValue(String rawValue) throws IllegalArgumentException {- try {- return Values.create(Double.valueOf(rawValue));- } catch (NumberFormatException ex) {- throw new IllegalArgumentException(ConversionValidationFailure.NOT_A_VALID_NUMBER.name());- }- }- };-- public final ValueUpdater<Boolean> BOOLEAN_UPDATER = new ValueUpdater<Boolean>() {- @Override- Value createValue(Boolean rawValue) throws IllegalArgumentException {- return Values.create(rawValue);- }- };-- 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);- static protected DateTimeFormat timeFormat = DateTimeFormat.getFormat(Constants.DEFAULT_TIME_FORMAT);-- public TimestampLabel(Long timestamp) {- addStyleName("flex layout vertical end or-FormInfoLabel");- if (timestamp != null) {- setTimestamp(timestamp);- }- }-- public void setTimestamp(long timestamp) {- clear();- if (timestamp > 0) {- add(new FormOutputText(dateFormat.format(new Date(timestamp))));- add(new FormOutputText(timeFormat.format(new Date(timestamp))));- }- }- }--final protected Environment environment;final protected C container;final protected List<AssetAttribute> attributes;- final protected Map<String, AttributeEditor> editors = new HashMap<>();final protected LinkedHashMap<AssetAttribute, FormGroup> attributeGroups = new LinkedHashMap<>();public AttributesView(Environment environment, C container, List<AssetAttribute> attributes) {@@ -200,7 +93,6 @@ public abstract class AttributesView<while (container.getPanel().getWidgetCount() > 0) {container.getPanel().remove(0);}- editors.clear();attributeGroups.clear();}@@ -257,8 +149,7 @@ public abstract class AttributesView<protected void addAttributeActions(AssetAttribute attribute,FormGroup formGroup,FormField formField,- FormGroupActions formGroupActions,- IsWidget editor) {+ FormGroupActions formGroupActions) {}protected void addAttributeExtensions(AssetAttribute attribute,@@ -333,22 +224,15 @@ public abstract class AttributesView<FormGroupActions formGroupActions = new FormGroupActions();FormField formField = new FormField();+ formField.add(createAttributeValueEditor(attribute, formGroup));- AttributeEditor attributeEditor = createEditor(attribute, formGroup);-- addAttributeActions(attribute, formGroup, formField, formGroupActions, attributeEditor);-- if (attributeEditor == null)- attributeEditor = createUnsupportedEditor(attribute);-- formField.add(attributeEditor);+ addAttributeActions(attribute, formGroup, formField, formGroupActions);formGroup.addFormField(formField);formGroup.addFormGroupActions(formGroupActions);addAttributeExtensions(attribute, formGroup);- editors.put(attribute.getName().orElse(null), attributeEditor);return formGroup;}@@ -368,7 +252,7 @@ public abstract class AttributesView<return attribute.getDescription();}- protected AttributeEditor createEditor(AssetAttribute attribute, FormGroup formGroup) {+ protected IsWidget createAttributeValueEditor(AssetAttribute attribute, FormGroup formGroup) {Optional<MetaItem> defaultValueItem = attribute.getMetaItem(AssetMeta.DEFAULT);S style = container.getStyle();@@ -376,287 +260,63 @@ public abstract class AttributesView<if (attributeType == null)return null;- AttributeEditor attributeEditor;+ boolean readOnly = isEditorReadOnly(attribute);+ boolean showTimestamp = isShowTimestamp(attribute);++ Consumer<List<ValidationFailure>> validationResultConsumer = failures -> {+ for (ValidationFailure failure : failures) {+ showValidationError(attribute.getLabelOrName().orElse(null), failure);+ }+ };++ IsWidget editor;if (attributeType == AttributeType.STRING || attributeType.getValueType() == ValueType.STRING) {- attributeEditor = createStringEditor(attribute, defaultValueItem, style, formGroup);+ String currentValue = attribute.getValue().map(Object::toString).orElse(null);+ String defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString).orElse(null);+ editor = createStringEditor(+ attribute, currentValue, defaultValue, readOnly, style.stringEditor(), formGroup, showTimestamp, validationResultConsumer+ );} else if (attributeType == AttributeType.NUMBER || attributeType.getValueType() == ValueType.NUMBER) {- attributeEditor = createNumberEditor(attribute, defaultValueItem, style, formGroup);+ String currentValue = attribute.getValue().map(Object::toString).orElse(null);+ String defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString).orElse(null);+ editor = createNumberEditor(+ attribute, currentValue, defaultValue, readOnly, style.numberEditor(), formGroup, showTimestamp, validationResultConsumer+ );} else if (attributeType == AttributeType.BOOLEAN || attributeType.getValueType() == ValueType.BOOLEAN) {- attributeEditor = createBooleanEditor(attribute, defaultValueItem, style, formGroup);- } else if (attributeType.getValueType() == ValueType.OBJECT) {- attributeEditor = createObjectEditor(attribute, style, formGroup);- } else if (attributeType.getValueType() == ValueType.ARRAY) {- attributeEditor = createArrayEditor(attribute, style, formGroup);+ Boolean currentValue = attribute.getValueAsBoolean().orElse(null);+ Boolean defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsBoolean).orElse(null);+ editor = createBooleanEditor(+ attribute, currentValue, defaultValue, readOnly, style.booleanEditor(), formGroup, showTimestamp, validationResultConsumer+ );+ } else if (attributeType == AttributeType.OBJECT || attributeType.getValueType() == ValueType.OBJECT) {+ ObjectValue currentValue = attribute.getValue().flatMap(Values::getObject).orElse(null);+ Supplier<Value> resetSupplier = () -> attribute.getValue().orElse(null);+ String label = environment.getMessages().jsonObject();+ String title = !readOnly+ ? environment.getMessages().edit() + " " + environment.getMessages().jsonObject()+ : environment.getMessages().jsonObject();++ editor = createObjectEditor(+ attribute, currentValue, resetSupplier, readOnly, label, title, container.getJsonEditor(), formGroup, showTimestamp, validationResultConsumer+ );+ } else if (attributeType == AttributeType.ARRAY || attributeType.getValueType() == ValueType.ARRAY) {+ ArrayValue currentValue = attribute.getValue().flatMap(Values::getArray).orElse(null);+ Supplier<Value> resetSupplier = () -> attribute.getValue().orElse(null);+ String label = environment.getMessages().jsonArray();+ String title = !readOnly+ ? environment.getMessages().edit() + " " + environment.getMessages().jsonArray()+ : environment.getMessages().jsonArray();+ editor = createArrayEditor(+ attribute, currentValue, resetSupplier, readOnly, label, title, container.getJsonEditor(), formGroup, showTimestamp, validationResultConsumer+ );} else {- return null;- }- return attributeEditor;- }-- protected AttributeEditor createUnsupportedEditor(AssetAttribute attribute) {- FormField unsupportedField = new FormField();- unsupportedField.add(new FormOutputText(- environment.getMessages().unsupportedAttributeType(- attribute.getType().map(AttributeType::name).orElse(null)- )- ));- return () -> unsupportedField;- }-- protected IsWidget createNoValueWidget() {- return new FormOutputText(- environment.getMessages().noValue()- );- }-- protected AttributeEditor createStringEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {- String currentValue = attribute.getValue().map(Object::toString).orElse(null);- Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);-- Consumer<String> updateConsumer = !isEditorReadOnly(attribute)- ? rawValue -> STRING_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))- : null;-- FlowPanel panel = new FlowPanel();- panel.setStyleName("flex layout horizontal center");- IsWidget widget = createStringEditorWidget(style, currentValue, defaultValue, updateConsumer);- FlowPanel widgetWrapper = new FlowPanel();- widgetWrapper.setStyleName("flex layout horizontal center");- widgetWrapper.add(widget);- panel.add(widgetWrapper);- if (isShowTimestamp(attribute)) {- TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());- panel.add(timestampLabel);- }-- return () -> panel;- }-- protected IsWidget createStringEditorWidget(S style,- String currentValue,- Optional<String> defaultValue,- Consumer<String> updateConsumer) {- FormInputText input = createFormInputText(style.stringEditor());-- if (currentValue != null) {- input.setValue(currentValue);- } else if (defaultValue.isPresent()) {- input.setValue(defaultValue.get());- } else if (updateConsumer == null) {- return createNoValueWidget();- }-- if (updateConsumer != null) {- input.addValueChangeHandler(- event -> updateConsumer.accept(- event.getValue() == null || event.getValue().length() == 0 ? null : event.getValue()+ editor = new FormOutputText(+ environment.getMessages().unsupportedAttributeType(+ attribute.getType().map(AttributeType::name).orElse(null)));- } else {- input.setReadOnly(true);- }- return input;- }-- protected AttributeEditor createNumberEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {- String currentValue = attribute.getValue().map(Object::toString).orElse(null);- Optional<String> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsString);-- Consumer<String> updateConsumer = !isEditorReadOnly(attribute)- ? rawValue -> DOUBLE_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))- : null;-- FlowPanel panel = new FlowPanel();- panel.setStyleName("flex layout horizontal center");- IsWidget widget = createNumberEditorWidget(style, currentValue, defaultValue, updateConsumer);- FlowPanel widgetWrapper = new FlowPanel();- widgetWrapper.setStyleName("flex layout horizontal center");- widgetWrapper.add(widget);- panel.add(widgetWrapper);- if (isShowTimestamp(attribute)) {- TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());- panel.add(timestampLabel);- }-- return () -> panel;- }-- protected IsWidget createNumberEditorWidget(S style,- String currentValue,- Optional<String> defaultValue,- Consumer<String> updateConsumer) {- FormInputText input = createFormInputText(style.numberEditor());-- if (currentValue != null) {- input.setValue(currentValue);- } else if (defaultValue.isPresent()) {- input.setValue(defaultValue.get());- } else if (updateConsumer == null) {- return createNoValueWidget();- }-- if (updateConsumer != null) {- input.addValueChangeHandler(event -> {- updateConsumer.accept(- event.getValue() == null || event.getValue().length() == 0 ? null : event.getValue()- );- });- } else {- input.setReadOnly(true);- }- return input;- }-- protected AttributeEditor createBooleanEditor(AssetAttribute attribute, Optional<MetaItem> defaultValueItem, S style, FormGroup formGroup) {- Boolean currentValue = attribute.getValueAsBoolean().orElse(null);- Optional<Boolean> defaultValue = defaultValueItem.flatMap(AbstractValueHolder::getValueAsBoolean);-- Consumer<Boolean> updateConsumer = !isEditorReadOnly(attribute)- ? rawValue -> BOOLEAN_UPDATER.accept(new ValueUpdate<>(attribute.getLabelOrName().orElse(null), formGroup, attribute, null, rawValue))- : null;-- FlowPanel panel = new FlowPanel();- panel.setStyleName("flex layout horizontal center");- IsWidget widget = createBooleanEditorWidget(style, currentValue, defaultValue, updateConsumer);- FlowPanel widgetWrapper = new FlowPanel();- widgetWrapper.setStyleName("flex layout horizontal center");- widgetWrapper.add(widget);- panel.add(widgetWrapper);- if (isShowTimestamp(attribute)) {- TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());- panel.add(timestampLabel);}-- return () -> panel;- }-- protected IsWidget createBooleanEditorWidget(S style,- Boolean currentValue,- Optional<Boolean> defaultValue,- Consumer<Boolean> updateConsumer) {- FormCheckBox input = createFormInputCheckBox(style.booleanEditor());-- Boolean value = null;- if (currentValue != null) {- value = currentValue;- } else if (defaultValue.isPresent()) {- value = defaultValue.get();- } else if (updateConsumer == null) {- return createNoValueWidget();- }-- input.setValue(value);-- if (updateConsumer != null) {- input.addValueChangeHandler(event -> updateConsumer.accept(input.getValue()));- } else {- input.setEnabled(false);- }- 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");- IsWidget widget = createJsonEditorWidget(- style, environment.getMessages().jsonArray(), title, currentValue.orElse(null), updateConsumer, resetSupplier- );- FlowPanel widgetWrapper = new FlowPanel();- widgetWrapper.setStyleName("flex layout horizontal center");- widgetWrapper.add(widget);- panel.add(widgetWrapper);- 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");- IsWidget widget = createJsonEditorWidget(- style, environment.getMessages().jsonObject(), title, currentValue.orElse(null), updateConsumer, resetSupplier- );- FlowPanel widgetWrapper = new FlowPanel();- widgetWrapper.setStyleName("flex layout horizontal center");- widgetWrapper.add(widget);- panel.add(widgetWrapper);- if (isShowTimestamp(attribute)) {- TimestampLabel timestampLabel = new TimestampLabel(attribute.getValueTimestamp());- panel.add(timestampLabel);- }-- return () -> panel;- }-- protected IsWidget createJsonEditorWidget(S style,- String label,- 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(label);- 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);- return input;- }-- protected FormInputNumber createFormInputNumber(String formFieldStyleName) {- FormInputNumber input = new FormInputNumber();- input.addStyleName(formFieldStyleName);- return input;- }-- protected FormCheckBox createFormInputCheckBox(String formFieldStyleName) {- FormCheckBox input = new FormCheckBox();- input.addStyleName(formFieldStyleName);- return input;+ return editor;}protected boolean isEditorReadOnly(AssetAttribute attribute) {@@ -677,10 +337,6 @@ public abstract class AttributesView<protected void removeAttribute(AssetAttribute attribute) {attributes.remove(attribute);- attribute- .getName()- .map(editors::remove);-int attributeGroupIndex = container.getPanel().getWidgetIndex(attributeGroups.get(attribute));container.getPanel().remove(attributeGroupIndex);attributeGroups.remove(attribute);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 9e0a93211..d3da22666 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@@ -221,8 +221,6 @@ public interface ManagerMessages extends Messages {String value();- String noValue();-String metaItems();String or();@@ -392,4 +390,6 @@ public interface ManagerMessages extends Messages {String settingsSaved();String noAttributes();++ String simulator();}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.javanew file mode 100644index 000000000..93299bf24--- /dev/null+++ b/manager/client/src/main/java/org/openremote/manager/client/simulator/Simulator.java@@ -0,0 +1,39 @@+/*+ * 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.simulator;++import com.google.gwt.user.client.ui.FlowPanel;+import com.google.gwt.user.client.ui.IsWidget;+import com.google.gwt.user.client.ui.Label;+import com.google.inject.Inject;+import org.openremote.manager.client.Environment;++public class Simulator extends FlowPanel implements IsWidget{++ final protected Environment environment;+ @Inject+ public Simulator(Environment environment) {+ this.environment = environment;+ setStyleName("layout vertical center or-Simulator");++ add(new Label("TODO Use ValueEditors and a new SimulatorResource on server to implement " + environment.getMessages().simulator()));+ }++}diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.javaindex 9ba013ca1..716f1bd78 100644--- a/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/FormGroup.java@@ -21,10 +21,7 @@ package org.openremote.manager.client.widget;import com.google.gwt.dom.client.Style;import com.google.gwt.uibinder.client.UiChild;-import com.google.gwt.user.client.ui.FlowPanel;-import com.google.gwt.user.client.ui.HasWidgets;-import com.google.gwt.user.client.ui.Label;-import com.google.gwt.user.client.ui.Widget;+import com.google.gwt.user.client.ui.*;import java.util.function.Consumer;import java.util.logging.Logger;@@ -119,7 +116,7 @@ public class FormGroup extends FlowPanel implements HasWidgets {}@UiChild(tagname = "expansion")- public void addExtension(Widget widget) {+ public void addExtension(IsWidget widget) {toggleExtensionButton.setVisible(true);toggleExtensionButton.setEnabled(true);extensionPanel.add(widget);diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java b/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.javaindex 49b6fe600..fe2c1d720 100644--- a/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/MapWidget.java@@ -91,6 +91,7 @@ public class MapWidget extends FlowPanel {ArrayValue offset = Values.createArray();offset.addAll(create(0), create(0.8));layout.put("text-offset", offset);+ layout.put("text-max-width", create(44));layout.put("icon-image", "marker_15");offset = Values.createArray();diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.java b/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.javanew file mode 100644index 000000000..f35a2d429--- /dev/null+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.java@@ -0,0 +1,368 @@+/*+ * 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.widget;++import com.google.gwt.i18n.client.DateTimeFormat;+import com.google.gwt.user.client.ui.FlowPanel;+import com.google.gwt.user.client.ui.IsWidget;+import org.openremote.manager.client.app.dialog.JsonEditor;+import org.openremote.model.AbstractValueHolder;+import org.openremote.model.AbstractValueTimestampHolder;+import org.openremote.model.Constants;+import org.openremote.model.ValidationFailure;+import org.openremote.model.value.ArrayValue;+import org.openremote.model.value.ObjectValue;+import org.openremote.model.value.Value;+import org.openremote.model.value.Values;++import java.util.ArrayList;+import java.util.Date;+import java.util.List;+import java.util.function.Consumer;+import java.util.function.Supplier;++/**+ * Collection of functions and types for {@link Value} editor UI.+ */+public final class ValueEditors {++ public enum ConversionValidationFailure implements ValidationFailure {+ NOT_A_VALID_NUMBER+ }++ /**+ * Maps a {@link FormGroup} which is typically one editor line to an {@link AbstractValueHolder} and+ * encapsulates the raw value that should be set on the value holder and the consumer of validation failure+ * results. If there are no validation failures, the update was successful.+ */+ private static class ValueUpdate<T> {+ final FormGroup formGroup;+ final AbstractValueHolder valueHolder;+ final Consumer<List<ValidationFailure>> resultConsumer;+ final T rawValue;++ public ValueUpdate(FormGroup formGroup, AbstractValueHolder valueHolder, Consumer<List<ValidationFailure>> resultConsumer, T rawValue) {+ this.formGroup = formGroup;+ this.valueHolder = valueHolder;+ this.resultConsumer = resultConsumer;+ this.rawValue = rawValue;+ }+ }++ /**+ * Performs the update and notifies the result consumer of any validation failures.+ */+ private static abstract class ValueUpdater<T> implements Consumer<ValueUpdate<T>> {++ @Override+ public void accept(ValueUpdate<T> valueUpdate) {+ valueUpdate.formGroup.setError(false);+ List<ValidationFailure> failures = new ArrayList<>();+ try {+ valueUpdate.valueHolder.setValue(+ valueUpdate.rawValue != null ? createValue(valueUpdate.rawValue) : null+ );+ failures.addAll(valueUpdate.valueHolder.getValidationFailures());+ } catch (IllegalArgumentException ex) {+ failures.add(ex::getMessage);+ }+ if (!failures.isEmpty()) {+ valueUpdate.formGroup.setError(true);+ }+ if (valueUpdate.resultConsumer != null) {+ valueUpdate.resultConsumer.accept(failures);+ }+ }++ abstract Value createValue(T rawValue) throws IllegalArgumentException;+ }++ private static ValueUpdater<String> STRING_UPDATER = new ValueUpdater<String>() {+ @Override+ Value createValue(String rawValue) throws IllegalArgumentException {+ return Values.create(rawValue);+ }+ };++ private static ValueUpdater<String> DOUBLE_UPDATER = new ValueUpdater<String>() {+ @Override+ Value createValue(String rawValue) throws IllegalArgumentException {+ try {+ return Values.create(Double.valueOf(rawValue));+ } catch (NumberFormatException ex) {+ throw new IllegalArgumentException(ConversionValidationFailure.NOT_A_VALID_NUMBER.name());+ }+ }+ };++ private static ValueUpdater<Boolean> BOOLEAN_UPDATER = new ValueUpdater<Boolean>() {+ @Override+ Value createValue(Boolean rawValue) throws IllegalArgumentException {+ return Values.create(rawValue);+ }+ };++ private static ValueUpdater<Value> VALUE_UPDATER = new ValueUpdater<Value>() {+ @Override+ Value createValue(Value rawValue) throws IllegalArgumentException {+ return rawValue;+ }+ };++ private static class TimestampLabel extends FlowPanel {++ static protected DateTimeFormat dateFormat = DateTimeFormat.getFormat(Constants.DEFAULT_DATE_FORMAT);+ static protected DateTimeFormat timeFormat = DateTimeFormat.getFormat(Constants.DEFAULT_TIME_FORMAT);++ public TimestampLabel(Long timestamp) {+ addStyleName("layout vertical end or-FormInfoLabel or-ValueTimestamp");+ if (timestamp != null) {+ setTimestamp(timestamp);+ }+ }++ public void setTimestamp(long timestamp) {+ clear();+ if (timestamp > 0) {+ add(new FormOutputText(dateFormat.format(new Date(timestamp))));+ add(new FormOutputText(timeFormat.format(new Date(timestamp))));+ }+ }+ }++ public static IsWidget createStringEditor(AbstractValueHolder valueHolder,+ String currentValue,+ String defaultValue,+ boolean readOnly,+ String styleName,+ FormGroup formGroup,+ boolean showTimestamp,+ Consumer<List<ValidationFailure>> validationResultConsumer) {+ Consumer<String> updateConsumer = !readOnly+ ? rawValue -> STRING_UPDATER.accept(new ValueUpdate<>(formGroup, valueHolder, validationResultConsumer, rawValue))+ : null;+ FlowPanel panel = new FlowPanel();+ panel.setStyleName("flex layout horizontal center or-StringValueEditor");+ IsWidget widget = ValueEditors.createStringEditorWidget(styleName, currentValue, defaultValue, updateConsumer);+ FlowPanel widgetWrapper = new FlowPanel();+ widgetWrapper.setStyleName("flex layout horizontal center");+ widgetWrapper.add(widget);+ panel.add(widgetWrapper);+ if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {+ AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;+ TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp());+ panel.add(timestampLabel);+ }+ return () -> panel;+ }+++ public static IsWidget createNumberEditor(AbstractValueHolder valueHolder,+ String currentValue,+ String defaultValue,+ boolean readOnly,+ String styleName,+ FormGroup formGroup,+ boolean showTimestamp,+ Consumer<List<ValidationFailure>> validationResultConsumer) {++ Consumer<String> updateConsumer = !readOnly+ ? rawValue -> DOUBLE_UPDATER.accept(new ValueUpdate<>(formGroup, valueHolder, validationResultConsumer, rawValue))+ : null;++ FlowPanel panel = new FlowPanel();+ panel.setStyleName("flex layout horizontal center or-NumberValueEditor");+ IsWidget widget = ValueEditors.createStringEditorWidget(styleName, currentValue, defaultValue, updateConsumer);+ FlowPanel widgetWrapper = new FlowPanel();+ widgetWrapper.setStyleName("flex layout horizontal center");+ widgetWrapper.add(widget);+ panel.add(widgetWrapper);+ if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {+ AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;+ TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp());+ panel.add(timestampLabel);+ }+ return () -> panel;+ }++ public static IsWidget createBooleanEditor(AbstractValueHolder valueHolder,+ Boolean currentValue,+ Boolean defaultValue,+ boolean readOnly,+ String styleName,+ FormGroup formGroup,+ boolean showTimestamp,+ Consumer<List<ValidationFailure>> validationResultConsumer) {+ Consumer<Boolean> updateConsumer = !readOnly+ ? rawValue -> BOOLEAN_UPDATER.accept(new ValueUpdate<>(formGroup, valueHolder, validationResultConsumer, rawValue))+ : null;++ FlowPanel panel = new FlowPanel();+ panel.setStyleName("flex layout horizontal center or-BooleanValueEditor");+ IsWidget widget = ValueEditors.createBooleanEditorWidget(styleName, currentValue, defaultValue, updateConsumer);+ FlowPanel widgetWrapper = new FlowPanel();+ widgetWrapper.setStyleName("flex layout horizontal center");+ widgetWrapper.add(widget);+ panel.add(widgetWrapper);+ if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {+ AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;+ TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp());+ panel.add(timestampLabel);+ }+ return () -> panel;+ }++ public static IsWidget createObjectEditor(AbstractValueHolder valueHolder,+ ObjectValue currentValue,+ Supplier<Value> resetSupplier,+ boolean readOnly,+ String label,+ String title,+ JsonEditor jsonEditor,+ FormGroup formGroup,+ boolean showTimestamp,+ Consumer<List<ValidationFailure>> validationResultConsumer) {+ Consumer<Value> updateConsumer = !readOnly+ ? rawValue -> VALUE_UPDATER.accept(new ValueUpdate<>(formGroup, valueHolder, validationResultConsumer, rawValue))+ : null;+ FlowPanel panel = new FlowPanel();+ panel.setStyleName("flex layout horizontal center or-ObjectValueEditor");+ IsWidget widget = createJsonEditorWidget(+ jsonEditor, label, title, currentValue, updateConsumer, resetSupplier+ );+ FlowPanel widgetWrapper = new FlowPanel();+ widgetWrapper.setStyleName("flex layout horizontal center");+ widgetWrapper.add(widget);+ panel.add(widgetWrapper);+ if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {+ AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;+ TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp());+ panel.add(timestampLabel);+ }+ return () -> panel;+ }++ public static IsWidget createArrayEditor(AbstractValueHolder valueHolder,+ ArrayValue currentValue,+ Supplier<Value> resetSupplier,+ boolean readOnly,+ String label,+ String title,+ JsonEditor jsonEditor,+ FormGroup formGroup,+ boolean showTimestamp,+ Consumer<List<ValidationFailure>> validationResultConsumer) {+ Consumer<Value> updateConsumer = !readOnly+ ? rawValue -> VALUE_UPDATER.accept(new ValueUpdate<>(formGroup, valueHolder, validationResultConsumer, rawValue))+ : null;++ FlowPanel panel = new FlowPanel();+ panel.setStyleName("flex layout horizontal center or-ArrayValueEditor");+ IsWidget widget = createJsonEditorWidget(+ jsonEditor, label, title, currentValue, updateConsumer, resetSupplier+ );+ FlowPanel widgetWrapper = new FlowPanel();+ widgetWrapper.setStyleName("flex layout horizontal center");+ widgetWrapper.add(widget);+ panel.add(widgetWrapper);+ if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {+ AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;+ TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp());+ panel.add(timestampLabel);+ }+ return () -> panel;+ }++ private static IsWidget createStringEditorWidget(String styleName,+ String currentValue,+ String defaultValue,+ Consumer<String> updateConsumer) {+ FormInputText input = new FormInputText();+ input.addStyleName(styleName);+ if (currentValue != null) {+ input.setValue(currentValue);+ } else if (defaultValue != null) {+ input.setValue(defaultValue);+ } else if (updateConsumer == null) {+ input.setValue("-");+ }+ if (updateConsumer != null) {+ input.addValueChangeHandler(+ event -> updateConsumer.accept(+ event.getValue() == null || event.getValue().length() == 0 ? null : event.getValue()+ )+ );+ } else {+ input.setReadOnly(true);+ }+ return input;+ }++ private static IsWidget createBooleanEditorWidget(String styleName,+ Boolean currentValue,+ Boolean defaultValue,+ Consumer<Boolean> updateConsumer) {+ FormCheckBox input = new FormCheckBox();+ input.addStyleName(styleName);++ Boolean value = null;+ if (currentValue != null) {+ value = currentValue;+ } else if (defaultValue != null) {+ value = defaultValue;+ } else if (updateConsumer == null) {+ return new FormOutputText("-");+ }++ input.setValue(value);++ if (updateConsumer != null) {+ input.addValueChangeHandler(event -> updateConsumer.accept(input.getValue()));+ } else {+ input.setEnabled(false);+ }+ return input;+ }++ private static IsWidget createJsonEditorWidget(JsonEditor jsonEditor,+ String label,+ String title,+ Value currentValue,+ Consumer<Value> updateConsumer,+ Supplier<Value> resetSupplier) {+ jsonEditor.setTitle(title);++ if (currentValue != null) {+ jsonEditor.setValue(currentValue);+ }++ FormButton button = new FormButton();+ button.setIcon("file-text-o");+ button.setText(label);+ button.addClickHandler(event -> jsonEditor.show());++ jsonEditor.setOnReset(() -> jsonEditor.setValue(resetSupplier.get()));++ if (updateConsumer != null) {+ jsonEditor.setOnApply(updateConsumer);+ }+ return button;+ }+}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 38f3f470f..54244e597 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@@ -176,6 +176,7 @@ attributeType[STRING]=TextattributeType[NUMBER]=NumberattributeType[BOOLEAN]=On/Off toggleattributeType[OBJECT]=JSON Object+attributeType[ARRAY]=JSON ArrayattributeType[PERCENTAGE]=PercentageattributeType[TIMESTAMP_MILLIS]=Timestamp milliseconds since epochattributeType[DATETIME]=Timestamp in ISO 8601@@ -252,6 +253,6 @@ hours=Hoursdays=DayseventsRemoved=All events removed.settingsSaved=Settings saved.-noValue=No value available.noAttributes=Asset has no attributes.+simulator=Simulatordiff --git a/manager/client/src/main/webapp/css/style.html b/manager/client/src/main/webapp/css/style.htmlindex b170e737e..53e9624f0 100644--- a/manager/client/src/main/webapp/css/style.html+++ b/manager/client/src/main/webapp/css/style.html@@ -337,10 +337,6 @@width: 15em;}- .or-FormLabel.largest {- width: 35em;- }-.or-FormField {min-width: 10em;}diff --git a/manager/client/src/main/webapp/css/theme.html b/manager/client/src/main/webapp/css/theme.htmlindex 6f0cdcfc6..79deacad2 100644--- a/manager/client/src/main/webapp/css/theme.html+++ b/manager/client/src/main/webapp/css/theme.html@@ -171,8 +171,8 @@}.or-FormControl.error {- background-color: var(--theme-red);- color: var(--theme-white);+ background-color: var(--theme-red) !important;+ color: var(--theme-white) !important;}.or-FormControl.primary {diff --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 6d72f9434..996465707 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@@ -237,6 +237,26 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicreturn persistenceService.doReturningTransaction(em -> findAllIdentifiersOnly(em, query));}+ public List<String> findNames(String... ids) {+ // TODO: Do this in a loop in reasonably sized batches+ return persistenceService.doReturningTransaction(em -> {+ List<Object[]> result = em.createQuery("select a.id, a.name from Asset a where a.id in :ids")+ .setParameter("ids", Arrays.asList(ids))+ .getResultList();+ List<String> names = new ArrayList<>();+ idLoop:+ for (String id : ids) {+ for (Object[] tuple: result) {+ if (tuple[0].equals(id)) {+ names.add((String) tuple[1]);+ break idLoop;+ }+ }+ }+ return names;+ });+ }+/*** @return The current stored asset state.* @throws IllegalArgumentException if the realm or parent is illegal, or other asset constraint is violated.diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/DeviceNotificationToken.java b/manager/server/src/main/java/org/openremote/manager/server/notification/DeviceNotificationToken.javaindex 0a3b499c3..6c1c5f934 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/DeviceNotificationToken.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/DeviceNotificationToken.java@@ -1,3 +1,22 @@+/*+ * 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.server.notification;import javax.persistence.Column;diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.javaindex 6472ff321..250b579b3 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMBaseMessage.java@@ -1,9 +1,27 @@+/*+ * 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.server.notification;-public class FCMBaseMessage {- private String to;+ protected String to;public FCMBaseMessage(String to) {this.to = to;diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.javaindex f5d7739ab..8158a94b1 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/FCMMessage.java@@ -1,43 +1,67 @@+/*+ * 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.server.notification;-public class FCMMessage extends FCMBaseMessage {- private Notification notification;- private boolean content_available;- private String priority;--- public FCMMessage(Notification notification, boolean content_available, String priority, String to) {- super(to);- this.notification = notification;- this.content_available = content_available;- this.priority = priority;- }+ protected Notification notification;+ protected boolean contentAvailable;+ protected String priority;- public Notification getNotification() {- return notification;- }+ public FCMMessage(Notification notification, boolean contentAvailable, String priority, String to) {+ super(to);+ this.notification = notification;+ this.contentAvailable = contentAvailable;+ this.priority = priority;+ }- public void setNotification(Notification notification) {- this.notification = notification;- }+ public Notification getNotification() {+ return notification;+ }- public boolean getContent_available() {- return content_available;- }+ public void setNotification(Notification notification) {+ this.notification = notification;+ }- public void setContent_available(boolean content_available) {- this.content_available = content_available;- }+ public boolean getContentAvailable() {+ return contentAvailable;+ }- public String getPriority() {- return priority;- }+ public void setContentAvailable(boolean contentAvailable) {+ this.contentAvailable = contentAvailable;+ }- public void setPriority(String priority) {- this.priority = priority;- }+ public String getPriority() {+ return priority;+ }+ public void setPriority(String priority) {+ this.priority = priority;+ }+ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "notification=" + notification ++ ", contentAvailable=" + contentAvailable ++ ", priority='" + priority + '\'' ++ '}';+ }}diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/Notification.java b/manager/server/src/main/java/org/openremote/manager/server/notification/Notification.javaindex 964cf120a..458be6e15 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/Notification.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/Notification.java@@ -1,34 +1,62 @@+/*+ * 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.server.notification;public class Notification {- String body;- boolean mutable_content;- String click_action = "openremoteNotification";-- public Notification(String body, boolean mutable_content) {- super();- this.body = body;- this.mutable_content = mutable_content;- }-- public String getBody() {- return body;- }-- public void setBody(String body) {- this.body = body;- }-- public boolean getMutable_content() {- return mutable_content;- }-- public void setMutable_content(boolean mutable_content) {- this.mutable_content = mutable_content;- }-- public String getClick_action() {- return click_action;- }+ protected String body;+ protected boolean mutableContent;+ protected String clickAction = "openremoteNotification";++ public Notification(String body, boolean mutableContent) {+ super();+ this.body = body;+ this.mutableContent = mutableContent;+ }++ public String getBody() {+ return body;+ }++ public void setBody(String body) {+ this.body = body;+ }++ public boolean getMutableContent() {+ return mutableContent;+ }++ public void setMutableContent(boolean mutableContent) {+ this.mutableContent = mutableContent;+ }++ public String getClickAction() {+ return clickAction;+ }++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{" ++ "body='" + body + '\'' ++ ", mutableContent=" + mutableContent ++ ", clickAction='" + clickAction + '\'' ++ '}';+ }}diff --git a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.javaindex 51497cc7a..ad843a8b4 100644--- a/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/notification/NotificationService.java@@ -1,5 +1,5 @@/*- * Copyright 2016, OpenRemote Inc.+ * Copyright 2017, OpenRemote Inc.** See the CONTRIBUTORS.txt file in the distribution for a* full listing of individual contributors.@@ -48,7 +48,7 @@ public class NotificationService implements ContainerService {public static final String NOTIFICATION_FIREBASE_URL_DEFAULT = "https://fcm.googleapis.com/fcm/send";protected PersistenceService persistenceService;- protected ResteasyWebTarget target;+ protected ResteasyWebTarget firebaseTarget;private String fcmKey;@Override@@ -65,7 +65,7 @@ public class NotificationService implements ContainerService {);ResteasyClient client = new ResteasyClientBuilder().build();- target = client.target(container.getConfig().getOrDefault(NOTIFICATION_FIREBASE_URL, NOTIFICATION_FIREBASE_URL_DEFAULT));+ firebaseTarget = client.target(container.getConfig().getOrDefault(NOTIFICATION_FIREBASE_URL, NOTIFICATION_FIREBASE_URL_DEFAULT));}@Override@@ -113,7 +113,7 @@ public class NotificationService implements ContainerService {List<DeviceNotificationToken> allTokenForUser = findAllTokenForUser(userId);for (DeviceNotificationToken notificationToken : allTokenForUser) {try {- Invocation.Builder builder = target.request().header("Authorization", "key=" + fcmKey);+ Invocation.Builder builder = firebaseTarget.request().header("Authorization", "key=" + fcmKey);Notification notification = new Notification("_", true);FCMBaseMessage message;@@ -183,7 +183,7 @@ public class NotificationService implements ContainerService {protected String buildFromString(UserQuery query) {StringBuilder sb = new StringBuilder();- sb.append("FROM DeviceNotificationToken dnt ");+ sb.append("FROM DeviceNotificationToken dnt ");if (query.tenantPredicate != null) {sb.append("join User u on u.id = dnt.id.userId");diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.javaindex ddbeb3f5b..f15f220d9 100644--- a/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.java+++ b/manager/shared/src/main/java/org/openremote/manager/shared/notification/NotificationResource.java@@ -36,6 +36,9 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;@JsType(isNative = true)public interface NotificationResource {+ /**+ * Store a device token for the authenticated user.+ */@PUT@Path("token")@SuccessStatusCode(204)diff --git a/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovyindex da79fd3ab..eef83de89 100644--- a/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy@@ -134,6 +134,7 @@ class AdminTenantsActivityTest extends Specification implements ManagerContainerand: "An activity management configuration"def environment = Environment.create(+ Mock(Environment.Factory),securityService,requestService,Mock(EventService),diff --git a/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovyindex 7830d6267..229dc6dbc 100644--- a/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy@@ -154,6 +154,7 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTrand: "An activity management configuration"def environment = Environment.create(+ Mock(Environment.Factory),securityService,requestService,Mock(EventService),diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovyindex b57d8729f..154acd0d8 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy@@ -103,6 +103,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContainedef placeController = createPlaceController(securityService, eventBus)def placeHistoryMapper = createPlaceHistoryMapper(ManagerHistoryMapper.getAnnotation(WithTokenizers.class))def environment = Environment.create(+ Mock(Environment.Factory),securityService,requestService,clientEventService,@@ -275,6 +276,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContainedef placeController = createPlaceController(securityService, eventBus)def placeHistoryMapper = createPlaceHistoryMapper(ManagerHistoryMapper.getAnnotation(WithTokenizers.class))def environment = Environment.create(+ Mock(Environment.Factory),securityService,requestService,clientEventService,@@ -453,6 +455,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContainedef placeController = createPlaceController(securityService, eventBus)def placeHistoryMapper = createPlaceHistoryMapper(ManagerHistoryMapper.getAnnotation(WithTokenizers.class))def environment = Environment.create(+ Mock(Environment.Factory),securityService,requestService,clientEventService,diff --git a/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy b/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovyindex f7650dd6f..ae940fe8e 100644--- a/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy@@ -96,10 +96,10 @@ class NotificationServiceTest extends Specification implements ManagerContainerTthen: "it should be one alert notification pending"alerts.size() == 1- when: "the alert Notification is acknowledge"+ when: "the alert Notification is acknowledged"notificationResource.removeAlertNotification(alerts.get(0).id)- then: "it should be no alert"+ then: "there should be no alert"notificationResource.getAlertNotification().size() == 0cleanup: "the server should be stopped"diff --git a/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java b/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.javaindex 2d13c8010..76d6306d0 100644--- a/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java+++ b/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java@@ -51,6 +51,7 @@ final public class ProtocolConfiguration {}isValidProtocolNameOrThrow(protocolName);attribute.setEnabled(true);+ attribute.setReadOnly(true);attribute.setTypeAndClearValue(AttributeType.STRING);attribute.setValue(Values.create(protocolName));attribute.getMeta().add(new MetaItem(PROTOCOL_CONFIGURATION, Values.create(true)));diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeType.java b/model/src/main/java/org/openremote/model/attribute/AttributeType.javaindex 5f112c660..03929d1a2 100644--- a/model/src/main/java/org/openremote/model/attribute/AttributeType.java+++ b/model/src/main/java/org/openremote/model/attribute/AttributeType.java@@ -51,6 +51,8 @@ public enum AttributeType {OBJECT("cubes", ValueType.OBJECT, value -> Optional.empty()),+ ARRAY("ellipsis-h", ValueType.ARRAY, value -> Optional.empty()),+/*** When {@link Ruleset#templateAssetId} references an asset, use the attribute to customize the* template when the ruleset is deployed. The attribute name is available in the template asdiff --git a/model/src/main/java/org/openremote/model/notification/ActionType.java b/model/src/main/java/org/openremote/model/notification/ActionType.javaindex 9203d567c..9fdcf7612 100644--- a/model/src/main/java/org/openremote/model/notification/ActionType.java+++ b/model/src/main/java/org/openremote/model/notification/ActionType.java@@ -1,5 +1,24 @@-package org.openremote.model.notification;+/*+ * 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.model.notification;public enum ActionType {ACTUATOR,diff --git a/model/src/main/java/org/openremote/model/notification/AlertAction.java b/model/src/main/java/org/openremote/model/notification/AlertAction.javaindex adbfcea60..a51acc842 100644--- a/model/src/main/java/org/openremote/model/notification/AlertAction.java+++ b/model/src/main/java/org/openremote/model/notification/AlertAction.java@@ -1,3 +1,22 @@+/*+ * 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.model.notification;import org.openremote.model.AbstractTypeHolder;diff --git a/model/src/main/java/org/openremote/model/notification/AlertNotification.java b/model/src/main/java/org/openremote/model/notification/AlertNotification.javaindex 35796a2fa..aeb857be4 100644--- a/model/src/main/java/org/openremote/model/notification/AlertNotification.java+++ b/model/src/main/java/org/openremote/model/notification/AlertNotification.java@@ -1,3 +1,22 @@+/*+ * 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.model.notification;import org.openremote.model.value.ArrayValue;@@ -93,7 +112,7 @@ public class AlertNotification {AlertAction action = new AlertAction();action.setActionType(ActionType.LINK);action.setTitle(title);- // TODO: this is currenly on notification, should be on action, but must update console to support that+ // TODO: this is currently on notification, should be on action, but must update console to support thatsetAppUrl(url);addAction(action);}diff --git a/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java b/model/src/main/java/org/openremote/model/notification/DeliveryStatus.javaindex 35bf32583..e2d760727 100644--- a/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java+++ b/model/src/main/java/org/openremote/model/notification/DeliveryStatus.java@@ -1,3 +1,22 @@+/*+ * 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.model.notification;public enum DeliveryStatus {