Skip to content

armgit / core

Public Imported from GitHub
0

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

Cleaned up Event classes and improved asset update processing

Christian Bauer0039b4e90b52
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
index cd195af2a..2dcece9ba 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/AbstractProtocol.java
@@ -23,11 +23,11 @@ import org.apache.camel.Predicate;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.openremote.container.message.MessageBrokerSetupService;
+import org.openremote.model.AttributeEvent;
import org.openremote.model.asset.ThingAttribute;
import org.openremote.container.Container;
import org.openremote.container.message.MessageBrokerContext;
import org.openremote.model.AttributeRef;
-import org.openremote.model.AttributeState;
import java.util.Collection;
import java.util.HashMap;
@@ -39,12 +39,12 @@ public abstract class AbstractProtocol implements Protocol {
private static final Logger LOG = Logger.getLogger(AbstractProtocol.class.getName());
- static Predicate isAttributeStateIn(Collection<AttributeRef> attributeRefs) {
+ static Predicate isAttributeStateForAny(Collection<AttributeRef> attributeRefs) {
return exchange -> {
- if (!(exchange.getIn().getBody() instanceof AttributeState))
+ if (!(exchange.getIn().getBody() instanceof AttributeEvent))
return false;
- AttributeState attributeState = exchange.getIn().getBody(AttributeState.class);
- return attributeRefs.contains(attributeState.getAttributeRef());
+ AttributeEvent event = exchange.getIn().getBody(AttributeEvent.class);
+ return attributeRefs.contains(event.getAttributeRef());
};
}
@@ -71,8 +71,8 @@ public abstract class AbstractProtocol implements Protocol {
.process(exchange -> {
synchronized (linkedAttributes) {
// TODO This could be optimized, we must avoid inspecting all messages (maybe tag with protocol name in header?)
- if (isAttributeStateIn(linkedAttributes.keySet()).matches(exchange)) {
- sendToActuator(exchange.getIn().getBody(AttributeState.class));
+ if (isAttributeStateForAny(linkedAttributes.keySet()).matches(exchange)) {
+ sendToActuator(exchange.getIn().getBody(AttributeEvent.class));
}
}
});
@@ -128,9 +128,8 @@ public abstract class AbstractProtocol implements Protocol {
}
}
- protected void onSensorUpdate(AttributeState attributeState) {
- // TODO: Agent should be able to create AttributeUpdateEvent with desired timestamp
- producerTemplate.sendBody(SENSOR_TOPIC, attributeState);
+ protected void onSensorUpdate(AttributeEvent event) {
+ producerTemplate.sendBody(SENSOR_TOPIC, event);
}
@Override
@@ -139,7 +138,7 @@ public abstract class AbstractProtocol implements Protocol {
'}';
}
- abstract protected void sendToActuator(AttributeState attributeState);
+ abstract protected void sendToActuator(AttributeEvent event);
abstract protected void onAttributeAdded(ThingAttribute attribute);
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java
index f79de5148..a3d866a97 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/Protocol.java
@@ -20,7 +20,7 @@
package org.openremote.agent3.protocol;
import org.openremote.container.ContainerService;
-import org.openremote.model.AttributeState;
+import org.openremote.model.AttributeEvent;
import org.openremote.model.Constants;
import org.openremote.model.asset.ThingAttribute;
@@ -32,8 +32,8 @@ import java.util.Collection;
* OpenRemote protocols are in {@link Constants#PROTOCOL_NAMESPACE}, third-party protocols
* should use their own URN namespace identifier.
* <p>
- * The protocol implementation can receive {@link AttributeState} messages on the
- * {@link #ACTUATOR_TOPIC}. It can produce {@link AttributeState} messages on the
+ * The protocol implementation can receive {@link AttributeEvent} messages on the
+ * {@link #ACTUATOR_TOPIC}. It can produce {@link AttributeEvent} messages on the
* {@link #SENSOR_TOPIC}.
* <p>
* The linked attributes of a protocol provide the model for the protocol to perform these operations. How
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java b/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java
index 9a8d2cca4..78bcb859b 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/simulator/SimulatorProtocol.java
@@ -24,6 +24,7 @@ import org.openremote.agent3.protocol.AbstractProtocol;
import org.openremote.agent3.protocol.simulator.element.*;
import org.openremote.model.AttributeRef;
import org.openremote.model.AttributeState;
+import org.openremote.model.AttributeEvent;
import org.openremote.model.MetaItem;
import org.openremote.model.asset.ThingAttribute;
@@ -70,8 +71,8 @@ public class SimulatorProtocol extends AbstractProtocol {
}
@Override
- protected void sendToActuator(AttributeState attributeState) {
- putState(attributeState, false);
+ protected void sendToActuator(AttributeEvent event) {
+ putState(event.getAttributeState(), false);
}
public void putState(String entityId, String attributeName, JsonValue value) {
@@ -98,7 +99,7 @@ public class SimulatorProtocol extends AbstractProtocol {
if (isSensorUpdate) {
LOG.info("Propagating state change as sensor update: " + element);
- onSensorUpdate(attributeState);
+ onSensorUpdate(new AttributeEvent(attributeState));
}
}
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/util/StringArrayConverter.java b/container/src/main/java/org/openremote/container/persistence/StringArrayConverter.java
similarity index 84%
rename from manager/shared/src/main/java/org/openremote/manager/shared/util/StringArrayConverter.java
rename to container/src/main/java/org/openremote/container/persistence/StringArrayConverter.java
index 4b2796779..a973e6194 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/util/StringArrayConverter.java
+++ b/container/src/main/java/org/openremote/container/persistence/StringArrayConverter.java
@@ -17,7 +17,9 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.util;
+package org.openremote.container.persistence;
+
+import org.openremote.container.util.TextUtil;
import javax.persistence.AttributeConverter;
@@ -25,11 +27,11 @@ public class StringArrayConverter implements AttributeConverter<String[], String
@Override
public String convertToDatabaseColumn(String[] attribute) {
- return Util.toCommaSeparated(attribute);
+ return TextUtil.toCommaSeparated(attribute);
}
@Override
public String[] convertToEntityAttribute(String data) {
- return Util.fromCommaSeparated(data);
+ return TextUtil.fromCommaSeparated(data);
}
}
\ No newline at end of file
diff --git a/container/src/main/java/org/openremote/container/util/TextUtil.java b/container/src/main/java/org/openremote/container/util/TextUtil.java
index ae555c73c..d0fe2d86e 100644
--- a/container/src/main/java/org/openremote/container/util/TextUtil.java
+++ b/container/src/main/java/org/openremote/container/util/TextUtil.java
@@ -57,4 +57,37 @@ public class TextUtil {
return -1;
}
+ public static String toCommaSeparated(String... strings) {
+ if (strings == null || strings.length == 0)
+ return null;
+ StringBuilder sb = new StringBuilder();
+ for (String s : strings) {
+ sb.append(s).append(",");
+ }
+ if (sb.length() > 0) {
+ sb.deleteCharAt(sb.length()-1);
+ }
+ return sb.toString();
+ }
+
+ public static String[] fromCommaSeparated(String commaWords) {
+ if (commaWords == null)
+ return new String[0];
+ return commaWords.split(",");
+ }
+
+ /**
+ * Get an enum value from a string without throwing exception.
+ * Enum should be in uppercase to use this method.
+ */
+ public static <T extends Enum<T>> T getEnumFromString(Class<T> c, String string) {
+ if (c != null && string != null) {
+ try {
+ return Enum.valueOf(c, string.trim().toUpperCase());
+ } catch (IllegalArgumentException ex) {
+ }
+ }
+ return null;
+ }
+
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
index cb7c0b1ad..3cb7612f3 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerActivityMapper.java
@@ -37,8 +37,8 @@ import org.openremote.manager.client.assets.asset.AssetPlace;
import org.openremote.manager.client.assets.AssetsDashboardActivity;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
import org.openremote.manager.client.event.bus.EventBus;
-import org.openremote.manager.client.flows.FlowsActivity;
-import org.openremote.manager.client.flows.FlowsPlace;
+import org.openremote.manager.client.apps.AppsActivity;
+import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.i18n.ManagerMessages;
import org.openremote.manager.client.map.MapActivity;
import org.openremote.manager.client.map.MapPlace;
@@ -54,7 +54,7 @@ import org.openremote.manager.client.rules.tenant.RulesTenantPlace;
import org.openremote.manager.client.service.SecurityService;
import org.openremote.manager.client.user.UserAccountActivity;
import org.openremote.manager.client.user.UserAccountPlace;
-import org.openremote.manager.shared.event.ui.ShowFailureEvent;
+import org.openremote.manager.client.event.ShowFailureEvent;
import java.util.logging.Logger;
@@ -71,7 +71,7 @@ public class ManagerActivityMapper implements AppActivityMapper {
protected final Provider<RulesGlobalActivity> rulesGlobalActivityProvider;
protected final Provider<RulesTenantActivity> rulesTenantActivityProvider;
protected final Provider<RulesAssetActivity> rulesAssetActivityProvider;
- protected final Provider<FlowsActivity> flowsActivityProvider;
+ protected final Provider<AppsActivity> appsActivityProvider;
protected final Provider<AdminOverviewActivity> adminOverviewActivityProvider;
protected final Provider<AdminTenantsActivity> adminTenantsActivityProvider;
protected final Provider<AdminTenantActivity> adminTenantActivityProvider;
@@ -89,7 +89,7 @@ public class ManagerActivityMapper implements AppActivityMapper {
Provider<RulesGlobalActivity> rulesGlobalActivityProvider,
Provider<RulesTenantActivity> rulesTenantActivityProvider,
Provider<RulesAssetActivity> rulesAssetActivityProvider,
- Provider<FlowsActivity> flowsActivityProvider,
+ Provider<AppsActivity> appsActivityProvider,
Provider<AdminOverviewActivity> adminOverviewActivityProvider,
Provider<AdminTenantsActivity> adminTenantsActivityProvider,
Provider<AdminTenantActivity> adminTenantActivityProvider,
@@ -105,7 +105,7 @@ public class ManagerActivityMapper implements AppActivityMapper {
this.rulesGlobalActivityProvider = rulesGlobalActivityProvider;
this.rulesTenantActivityProvider = rulesTenantActivityProvider;
this.rulesAssetActivityProvider = rulesAssetActivityProvider;
- this.flowsActivityProvider = flowsActivityProvider;
+ this.appsActivityProvider = appsActivityProvider;
this.adminOverviewActivityProvider = adminOverviewActivityProvider;
this.adminTenantsActivityProvider = adminTenantsActivityProvider;
this.adminTenantActivityProvider = adminTenantActivityProvider;
@@ -134,8 +134,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
if (place instanceof RulesAssetPlace) {
return rulesAssetActivityProvider.get().init(securityService, (RulesAssetPlace) place);
}
- if (place instanceof FlowsPlace) {
- return flowsActivityProvider.get().init(securityService, (FlowsPlace) place);
+ if (place instanceof AppsPlace) {
+ return appsActivityProvider.get().init(securityService, (AppsPlace) place);
}
if (place instanceof AdminOverviewPlace) {
return adminOverviewActivityProvider.get().init(securityService, (AdminOverviewPlace) place);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerGinjector.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerGinjector.java
index 99f105314..3f88a053e 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerGinjector.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerGinjector.java
@@ -25,7 +25,7 @@ import org.openremote.manager.client.admin.AdminModule;
import org.openremote.manager.client.app.AppController;
import org.openremote.manager.client.app.AppModule;
import org.openremote.manager.client.assets.AssetsModule;
-import org.openremote.manager.client.flows.FlowsModule;
+import org.openremote.manager.client.apps.AppsModule;
import org.openremote.manager.client.map.MapModule;
import org.openremote.manager.client.mvp.MVPModule;
import org.openremote.manager.client.rules.RulesModule;
@@ -40,7 +40,7 @@ import org.openremote.manager.client.user.UserModule;
MapModule.class,
AssetsModule.class,
RulesModule.class,
- FlowsModule.class,
+ AppsModule.class,
AdminModule.class,
UserModule.class
})
diff --git a/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java b/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
index e28851641..9cf7edea7 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/ManagerHistoryMapper.java
@@ -28,7 +28,7 @@ import org.openremote.manager.client.admin.users.AdminUserPlace;
import org.openremote.manager.client.admin.users.AdminUsersPlace;
import org.openremote.manager.client.assets.AssetsDashboardPlace;
import org.openremote.manager.client.assets.asset.AssetPlace;
-import org.openremote.manager.client.flows.FlowsPlace;
+import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.map.MapPlace;
import org.openremote.manager.client.rules.RulesGlobalPlace;
import org.openremote.manager.client.rules.asset.RulesAssetPlace;
@@ -43,7 +43,7 @@ import org.openremote.manager.client.user.UserAccountPlace;
RulesGlobalPlace.Tokenizer.class,
RulesTenantPlace.Tokenizer.class,
RulesAssetPlace.Tokenizer.class,
- FlowsPlace.Tokenizer.class,
+ AppsPlace.Tokenizer.class,
AdminOverviewPlace.Tokenizer.class,
AdminTenantsPlace.Tokenizer.class,
AdminTenantPlace.Tokenizer.class,
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java
index 5cdc626ef..50439bcea 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/tenant/AdminTenantActivity.java
@@ -29,7 +29,7 @@ import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.event.bus.EventRegistration;
import org.openremote.manager.client.mvp.AppActivity;
import org.openremote.model.Consumer;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
+import org.openremote.manager.client.event.ShowInfoEvent;
import org.openremote.manager.shared.security.Tenant;
import org.openremote.manager.shared.security.TenantResource;
import org.openremote.manager.shared.validation.ConstraintViolation;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java
index d30aecbd1..0c586d3cb 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/admin/users/AdminUserActivity.java
@@ -28,7 +28,7 @@ import org.openremote.manager.client.event.bus.EventRegistration;
import org.openremote.manager.client.mvp.AppActivity;
import org.openremote.model.Consumer;
import org.openremote.model.Runnable;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
+import org.openremote.manager.client.event.ShowInfoEvent;
import org.openremote.manager.shared.security.Credential;
import org.openremote.manager.shared.security.Role;
import org.openremote.manager.shared.security.User;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/AppControllerImpl.java b/manager/client/src/main/java/org/openremote/manager/client/app/AppControllerImpl.java
index 6623939bd..81403a9c4 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/AppControllerImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/AppControllerImpl.java
@@ -28,8 +28,8 @@ import com.google.inject.Provider;
import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.toast.Toast;
import org.openremote.manager.client.toast.Toasts;
-import org.openremote.manager.shared.event.ui.ShowFailureEvent;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
+import org.openremote.manager.client.event.ShowFailureEvent;
+import org.openremote.manager.client.event.ShowInfoEvent;
import javax.inject.Inject;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java
index 75a9c9e39..24a4fc2cd 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderPresenter.java
@@ -30,7 +30,7 @@ import org.openremote.manager.client.event.GoToPlaceEvent;
import org.openremote.manager.client.event.UserChangeEvent;
import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.client.flows.FlowsPlace;
+import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.map.MapPlace;
import org.openremote.manager.client.rules.RulesGlobalPlace;
import org.openremote.manager.client.rules.asset.RulesAssetPlace;
@@ -118,9 +118,8 @@ public class HeaderPresenter implements HeaderView.Presenter {
}
@Override
- public void navigateFlows() {
- placeController.goTo(new FlowsPlace());
-
+ public void navigateApps() {
+ placeController.goTo(new AppsPlace());
}
@Override
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderView.java b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderView.java
index b7d73f3e8..ea3e2b9b8 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderView.java
@@ -35,7 +35,7 @@ public interface HeaderView extends IsWidget {
void navigateRules();
- void navigateFlows();
+ void navigateApps();
void navigateAdmin();
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.java
index d853ba102..1213a5d3b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.java
@@ -30,7 +30,7 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.inject.Inject;
import org.openremote.manager.client.assets.AssetsPlace;
import org.openremote.manager.client.admin.AdminPlace;
-import org.openremote.manager.client.flows.FlowsPlace;
+import org.openremote.manager.client.apps.AppsPlace;
import org.openremote.manager.client.map.MapPlace;
import org.openremote.manager.client.rules.RulesPlace;
import org.openremote.manager.client.user.UserAccountPlace;
@@ -57,7 +57,7 @@ public class HeaderViewImpl extends Composite implements HeaderView {
PushButton rulesButton;
@UiField
- PushButton flowsButton;
+ PushButton appsButton;
@UiField
PushButton adminButton;
@@ -77,7 +77,7 @@ public class HeaderViewImpl extends Composite implements HeaderView {
mapButton.setEnabled(presenter.isUserInRole("read:map"));
assetsButton.setEnabled(presenter.isUserInRole("read:assets"));
rulesButton.setEnabled(presenter.isUserInRole("read:rules"));
- flowsButton.setEnabled(presenter.isUserInRole("read:flows"));
+ appsButton.setEnabled(presenter.isUserInRole("read:admin"));
adminButton.setEnabled(presenter.isUserInRole("read:admin"));
}
@@ -86,7 +86,7 @@ public class HeaderViewImpl extends Composite implements HeaderView {
mapButton.removeStyleName("active");
assetsButton.removeStyleName("active");
rulesButton.removeStyleName("active");
- flowsButton.removeStyleName("active");
+ appsButton.removeStyleName("active");
adminButton.removeStyleName("active");
userButton.removeStyleName("active");
@@ -99,8 +99,8 @@ public class HeaderViewImpl extends Composite implements HeaderView {
if (place instanceof RulesPlace) {
rulesButton.addStyleName("active");
}
- if (place instanceof FlowsPlace) {
- flowsButton.addStyleName("active");
+ if (place instanceof AppsPlace) {
+ appsButton.addStyleName("active");
}
if (place instanceof AdminPlace) {
adminButton.addStyleName("active");
@@ -136,9 +136,9 @@ public class HeaderViewImpl extends Composite implements HeaderView {
presenter.navigateRules();
}
- @UiHandler("flowsButton")
- void flowsClicked(ClickEvent e) {
- presenter.navigateFlows();
+ @UiHandler("appsButton")
+ void appsClicked(ClickEvent e) {
+ presenter.navigateApps();
}
@UiHandler("userButton")
diff --git a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml
index a6371c87b..3e0aabf01 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/app/HeaderViewImpl.ui.xml
@@ -53,10 +53,10 @@
icon="chain"
text="{managerMessages.rules}"/>
- <w:PushButton ui:field="flowsButton"
+ <w:PushButton ui:field="appsButton"
addStyleNames="{widgetStyle.NavItem}"
icon="connectdevelop"
- text="{managerMessages.flows}"/>
+ text="{managerMessages.apps}"/>
<g:HTMLPanel styleName="flex"/>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/apps/AppsActivity.java b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsActivity.java
new file mode 100644
index 000000000..3428f878e
--- /dev/null
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsActivity.java
@@ -0,0 +1,69 @@
+/*
+ * 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.apps;
+
+import com.google.gwt.user.client.ui.AcceptsOneWidget;
+import org.openremote.manager.client.Environment;
+import org.openremote.manager.client.event.bus.EventBus;
+import org.openremote.manager.client.event.bus.EventRegistration;
+import org.openremote.manager.client.mvp.AppActivity;
+
+import javax.inject.Inject;
+import java.util.Collection;
+
+public class AppsActivity
+ extends AppActivity<AppsPlace>
+ implements AppsView.Presenter {
+
+ final AppsView view;
+ final Environment environment;
+
+ @Inject
+ public AppsActivity(Environment environment, AppsView view) {
+ this.environment = environment;
+ this.view = view;
+ }
+
+ @Override
+ protected AppActivity<AppsPlace> init(AppsPlace place) {
+ return this;
+ }
+
+ @Override
+ public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
+ container.setWidget(view.asWidget());
+ view.setPresenter(this);
+
+ // TODO Load console apps from server
+ // view.setApps(...);
+ }
+
+ @Override
+ public void onStop() {
+ view.setPresenter(null);
+ super.onStop();
+ }
+
+ @Override
+ public void onAppSelected(String name) {
+ // TODO Calculate URL of console app and open
+ // view.openAppUrl(...);
+ }
+}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsModule.java b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsModule.java
similarity index 79%
rename from manager/client/src/main/java/org/openremote/manager/client/flows/FlowsModule.java
rename to manager/client/src/main/java/org/openremote/manager/client/apps/AppsModule.java
index d721000a9..7b12dd3b0 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsModule.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsModule.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.
@@ -17,17 +17,17 @@
* 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.flows;
+package org.openremote.manager.client.apps;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Singleton;
-public class FlowsModule extends AbstractGinModule {
+public class AppsModule extends AbstractGinModule {
@Override
protected void configure() {
- bind(FlowsView.class).to(FlowsViewImpl.class).in(Singleton.class);
- bind(FlowsActivity.class);
+ bind(AppsView.class).to(AppsViewImpl.class).in(Singleton.class);
+ bind(AppsActivity.class);
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsPlace.java b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsPlace.java
similarity index 74%
rename from manager/client/src/main/java/org/openremote/manager/client/flows/FlowsPlace.java
rename to manager/client/src/main/java/org/openremote/manager/client/apps/AppsPlace.java
index 9d667afe7..17c6bd475 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsPlace.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsPlace.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.
@@ -17,24 +17,24 @@
* 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.flows;
+package org.openremote.manager.client.apps;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
-public class FlowsPlace extends Place {
+public class AppsPlace extends Place {
- @Prefix("flows")
- public static class Tokenizer implements PlaceTokenizer<FlowsPlace> {
+ @Prefix("apps")
+ public static class Tokenizer implements PlaceTokenizer<AppsPlace> {
@Override
- public FlowsPlace getPlace(String token) {
- return new FlowsPlace();
+ public AppsPlace getPlace(String token) {
+ return new AppsPlace();
}
@Override
- public String getToken(FlowsPlace place) {
+ public String getToken(AppsPlace place) {
return "";
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsView.java b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsView.java
similarity index 72%
rename from manager/client/src/main/java/org/openremote/manager/client/flows/FlowsView.java
rename to manager/client/src/main/java/org/openremote/manager/client/apps/AppsView.java
index 0fdd4b6c3..e77b65014 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsView.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.
@@ -17,22 +17,20 @@
* 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.flows;
+package org.openremote.manager.client.apps;
import com.google.gwt.user.client.ui.IsWidget;
-import org.openremote.model.asset.AssetInfo;
-public interface FlowsView extends IsWidget {
+public interface AppsView extends IsWidget {
interface Presenter {
- String getFlowsHistoryToken();
-
- void onAgentSelected(AssetInfo assetInfo);
+ void onAppSelected(String app);
}
void setPresenter(Presenter presenter);
- void setAgents(AssetInfo[] agents);
+ void setApps(String[] apps);
+
+ void openAppUrl(String appUrl);
- void setFrameSourceUrl(String frameSourceUrl);
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsViewImpl.java b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.java
similarity index 73%
rename from manager/client/src/main/java/org/openremote/manager/client/flows/FlowsViewImpl.java
rename to manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.java
index 192a18af3..cfc1948a1 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsViewImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.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.
@@ -17,7 +17,7 @@
* 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.flows;
+package org.openremote.manager.client.apps;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.IFrameElement;
@@ -36,11 +36,11 @@ import org.openremote.model.asset.AssetInfo;
import javax.inject.Inject;
import java.util.logging.Logger;
-public class FlowsViewImpl extends Composite implements FlowsView {
+public class AppsViewImpl extends Composite implements AppsView {
- private static final Logger LOG = Logger.getLogger(FlowsViewImpl.class.getName());
+ private static final Logger LOG = Logger.getLogger(AppsViewImpl.class.getName());
- interface UI extends UiBinder<HTMLPanel, FlowsViewImpl> {
+ interface UI extends UiBinder<HTMLPanel, AppsViewImpl> {
}
interface Style extends CssResource {
@@ -57,7 +57,7 @@ public class FlowsViewImpl extends Composite implements FlowsView {
Style style;
@UiField
- HTMLPanel agentListPanel;
+ HTMLPanel appsListPanel;
@UiField
IFrameElement frame;
@@ -68,7 +68,7 @@ public class FlowsViewImpl extends Composite implements FlowsView {
Presenter presenter;
@Inject
- public FlowsViewImpl() {
+ public AppsViewImpl() {
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
}
@@ -77,39 +77,38 @@ public class FlowsViewImpl extends Composite implements FlowsView {
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
if (presenter == null) {
- agentListPanel.clear();
+ appsListPanel.clear();
frame.setSrc("blank:");
placeholder.setVisible(true);
}
}
@Override
- public void setAgents(AssetInfo[] agents) {
- agentListPanel.clear();
+ public void setApps(String[] apps) {
+ appsListPanel.clear();
- if (agents == null || agents.length == 0) {
+ if (apps == null || apps.length == 0) {
Label noAgentsLabel = new Label(managerMessages.noAgentsFound());
noAgentsLabel.addStyleName(widgetStyle.SecondaryNavItem());
- agentListPanel.add(noAgentsLabel);
+ appsListPanel.add(noAgentsLabel);
return;
}
- for (AssetInfo agent : agents) {
+ for (String app : apps) {
Hyperlink agentLabel = new Hyperlink();
agentLabel.setIcon("cubes");
agentLabel.addStyleName(style.navItem());
agentLabel.addStyleName(widgetStyle.SecondaryNavItem());
- agentLabel.setText(agent.getName());
- agentLabel.setTargetHistoryToken(presenter.getFlowsHistoryToken());
- agentLabel.addClickHandler(event -> presenter.onAgentSelected(agent));
- agentListPanel.add(agentLabel);
+ agentLabel.setText(app);
+ agentLabel.addClickHandler(event -> presenter.onAppSelected(app));
+ appsListPanel.add(agentLabel);
}
}
@Override
- public void setFrameSourceUrl(String frameSourceUrl) {
+ public void openAppUrl(String appUrl) {
placeholder.setVisible(false);
- frame.setSrc(frameSourceUrl);
+ frame.setSrc(appUrl);
Timeout.debounce("setiframefocus", () -> {
frame.focus();
}, 500);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml
similarity index 78%
rename from manager/client/src/main/java/org/openremote/manager/client/flows/FlowsViewImpl.ui.xml
rename to manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml
index c20891df6..166c28239 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/apps/AppsViewImpl.ui.xml
@@ -5,7 +5,7 @@
<ui:with field="managerMessages" type="org.openremote.manager.client.i18n.ManagerMessages"/>
<ui:with field="widgetStyle" type="org.openremote.manager.client.style.WidgetStyle"/>
- <ui:style type="org.openremote.manager.client.flows.FlowsViewImpl.Style">
+ <ui:style type="org.openremote.manager.client.apps.AppsViewImpl.Style">
.navItem {
margin: 0 1em;
}
@@ -14,17 +14,18 @@
<g:HTMLPanel styleName="flex layout horizontal">
<g:HTMLPanel styleName="layout vertical {widgetStyle.SecondaryNav}"
- ui:field="agentListPanel">
+ ui:field="appsListPanel">
</g:HTMLPanel>
<g:HTMLPanel styleName="{widgetStyle.MainContent}"
ui:field="placeholder" >
- <g:Label text="Please select a controller with an app console on the left-hand side."/>
+ <g:Label text="Please select a Console on the left-hand side."/>
</g:HTMLPanel>
<iframe ui:field="frame"
class="flex"
style="width:100%; height:100%;border:0;"/>
+
</g:HTMLPanel>
</ui:UiBinder>
\ No newline at end of file
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
deleted file mode 100644
index 942ff5173..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/agent/AgentAttributesEditor.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.client.assets.agent;
-
-import com.google.gwt.text.shared.AbstractRenderer;
-import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.event.ServerSendEvent;
-import org.openremote.manager.client.widget.*;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.agent.RefreshInventoryEvent;
-import org.openremote.manager.shared.connector.Connector;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
-import org.openremote.model.Attribute;
-import org.openremote.model.Attributes;
-import org.openremote.model.asset.Asset;
-
-import java.util.List;
-
-import static org.openremote.manager.shared.connector.Connector.ASSET_ATTRIBUTE_CONNECTOR;
-
-public class AgentAttributesEditor extends AttributesEditor<AttributesEditor.Style> {
-
- final protected Agent agent;
- final protected Asset agentAsset;
-
- final protected FormGroup connectorListBoxGroup = new FormGroup();
- final protected FormValueListBox<Connector> connectorListBox;
-
- final protected FormGroup actionsGroup = new FormGroup();
- final protected FormButton refreshInventoryButton = new FormButton();
-
- // This is a dummy we use when the Agent's assigned connector is not installed
- protected final String notFoundConnectorType = "NOT_FOUND_CONNECTOR";
- protected final Connector notFoundConnector = new Connector(notFoundConnectorType);
-
- protected List<Connector> availableConnectors;
-
- public AgentAttributesEditor(Environment environment,
- Container<AttributesEditor.Style> container,
- Attributes attributes,
- boolean isCreateAsset,
- Asset agentAsset) {
- super(environment, container, attributes);
- this.agentAsset = agentAsset;
- this.agent = new Agent(attributes, isCreateAsset);
-
- connectorListBox = createConnectorListBox();
- FormLabel connectorListBoxLabel = new FormLabel();
- connectorListBoxLabel.setText(environment.getMessages().connector());
- FormField connectorListBoxField = new FormField();
- connectorListBoxField.add(connectorListBox);
- connectorListBoxGroup.addFormLabel(connectorListBoxLabel);
- connectorListBoxGroup.addFormField(connectorListBoxField);
-
- FormLabel actionsLabel = new FormLabel();
- actionsLabel.setText(environment.getMessages().actions());
- FormField actionsField = new FormField();
- actionsGroup.addFormLabel(actionsLabel);
- actionsGroup.addFormField(actionsField);
-
- refreshInventoryButton.setText(environment.getMessages().refreshInventory());
- refreshInventoryButton.setDanger(true);
- refreshInventoryButton.addClickHandler(event -> {
- doRefreshInventory();
- });
- refreshInventoryButton.setEnabled(false);
- actionsField.add(refreshInventoryButton);
-
- container.getFormView().setFormBusy(true);
-/*
- loadConnectors(connectors -> {
- availableConnectors = Arrays.asList(connectors);
-
- connectorListBox.setValue(null);
- connectorListBox.setAcceptableValues(availableConnectors);
-
- Connector connector = getConnector();
- if (connector != null) {
- connectorListBox.setValue(connector);
- refreshInventoryButton.setEnabled(
- connector.isSupportsInventoryRefresh() && agentAsset.getId() != null
- );
- agent.writeConnectorSettings(connector);
- } else if (agent.getConnectorType() != null) {
- notFoundConnector.setName(
- agent.getConnectorType() +
- " (" + environment.getMessages().connectorNotInstalled() + ")"
- );
- connectorListBox.setValue(notFoundConnector);
- }
-
- container.getFormView().setFormBusy(false);
- //clearBuild();
- });
-*/
- }
-
- @Override
- protected FormGroup createAttributeGroup(Attribute attribute) {
- if (attribute.getName().equals(ASSET_ATTRIBUTE_CONNECTOR))
- return null;
- return super.createAttributeGroup(attribute);
- }
-
- @Override
- protected FormLabel createAttributeLabel(Attribute attribute) {
- FormLabel formLabel = super.createAttributeLabel(attribute);
- if (attribute.getName().equals("enabled")) {
- formLabel.setText(environment.getMessages().enabled());
- }
- return formLabel;
- }
-
- /* TODO
- @Override
- protected String getDescription(Attribute attribute) {
- String description = super.getDescription(attribute);
- if (attribute.getName().equals("enabled")) {
- description = environment.getMessages().enableAgentDescription();
- }
- return description;
- }
- */
-
- @Override
- public void build() {
- container.getPanel().add(connectorListBoxGroup);
- container.getPanel().add(actionsGroup);
- super.build();
- }
-
- @Override
- public void setOpaque(boolean opaque) {
- super.setOpaque(opaque);
- connectorListBoxGroup.setOpaque(opaque);
- actionsGroup.setOpaque(opaque);
- }
-
- protected FormValueListBox<Connector> createConnectorListBox() {
- FormValueListBox<Connector> listBox = new FormValueListBox<>(
- new AbstractRenderer<Connector>() {
- @Override
- public String render(Connector connector) {
- if (connector == null)
- return environment.getMessages().noConnectorAssigned();
- return connector.getName();
- }
- }
- );
- listBox.addValueChangeHandler(event -> {
- Connector connector = event.getValue();
- onConnectorSelected(connector);
- });
- return listBox;
- }
-
- protected void onConnectorSelected(Connector connector) {
- if (connector != null) {
- agent.setConnectorType(connector.getType());
- Connector c = getConnector();
- agent.writeConnectorSettings(c);
- refreshInventoryButton.setEnabled(
- c.isSupportsInventoryRefresh() && agentAsset.getId() != null
- );
- } else {
- Connector oldConnector = getConnector();
- agent.removeConnectorSettings(oldConnector);
- agent.removeConnectorType();
- refreshInventoryButton.setEnabled(false);
- }
- // clearBuild();
- }
-
- protected Connector getConnector() {
- Connector assignedConnector = null;
- for (Connector connector : availableConnectors) {
- if (connector.getType().equals(agent.getConnectorType())) {
- assignedConnector = connector;
- break;
- }
- }
- return assignedConnector;
- }
-
- protected void doRefreshInventory() {
- if (agentAsset.getId() == null)
- return;
- container.showConfirmation(
- environment.getMessages().confirmation(),
- environment.getMessages().confirmationInventoryRefresh(agentAsset.getName()),
- () -> {
- environment.getEventBus().dispatch(new ServerSendEvent(
- new RefreshInventoryEvent(agentAsset.getId())
- ));
- environment.getEventBus().dispatch(
- new ShowInfoEvent(environment.getMessages().inventoryRefreshed(agentAsset.getName()))
- );
- }
- );
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
index 3a6415cc7..b954da7ce 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetActivity.java
@@ -30,7 +30,7 @@ import org.openremote.manager.client.event.bus.EventRegistration;
import org.openremote.manager.client.interop.elemental.JsonObjectMapper;
import org.openremote.manager.client.widget.AttributesEditor;
import org.openremote.manager.shared.asset.AssetResource;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
+import org.openremote.manager.client.event.ShowInfoEvent;
import org.openremote.manager.shared.map.MapResource;
import org.openremote.model.Attributes;
import org.openremote.model.asset.Asset;
@@ -355,17 +355,7 @@ public class AssetActivity
protected void writeAttributesEditorToView() {
switch(asset.getWellKnownType()) {
- /* TODO
- case DEVICE:
- if (parentAsset != null) {
- attributesEditor = new DeviceAttributesEditor(
- environment,
- view.getDeviceAttributesEditorContainer(),
- new Attributes(asset.getAttributes()),
- parentAsset.getId()
- );
- }
- break;
+ /* TODO Implement asset type-specific editors
case AGENT:
attributesEditor = new AgentAttributesEditor(
environment,
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
index c60013f55..70454119e 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetView.java
@@ -21,11 +21,10 @@ package org.openremote.manager.client.assets.asset;
import elemental.json.JsonObject;
import org.openremote.manager.client.assets.browser.AssetBrowsingView;
-import org.openremote.manager.client.assets.device.DeviceAttributesEditor;
import org.openremote.manager.client.widget.AttributesEditor;
import org.openremote.manager.client.widget.FormView;
-import org.openremote.model.asset.AssetType;
import org.openremote.manager.shared.map.GeoJSON;
+import org.openremote.model.asset.AssetType;
import java.util.Date;
@@ -101,8 +100,6 @@ public interface AssetView extends AssetBrowsingView<AssetView.Presenter>, FormV
AttributesEditor.Container<AttributesEditor.Style> getAttributesEditorContainer();
- AttributesEditor.Container<DeviceAttributesEditor.Style> getDeviceAttributesEditorContainer();
-
void setAttributesEditor(AttributesEditor attributesEditor);
void enableCreate(boolean enable);
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 ab25c04ee..14d796133 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
@@ -32,13 +32,12 @@ import com.google.inject.Provider;
import elemental.json.JsonObject;
import org.openremote.manager.client.app.dialog.ConfirmationDialog;
import org.openremote.manager.client.assets.browser.AssetBrowser;
-import org.openremote.manager.client.assets.device.DeviceAttributesEditor;
import org.openremote.manager.client.i18n.ManagerMessages;
import org.openremote.manager.client.widget.*;
import org.openremote.manager.client.widget.PushButton;
+import org.openremote.manager.shared.map.GeoJSON;
import org.openremote.model.Runnable;
import org.openremote.model.asset.AssetType;
-import org.openremote.manager.shared.map.GeoJSON;
import javax.inject.Inject;
import java.math.BigDecimal;
@@ -77,32 +76,12 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
String booleanEditor();
}
- interface DeviceAttributesEditorStyle extends CssResource, DeviceAttributesEditor.Style {
-
- String integerEditor();
-
- String decimalEditor();
-
- String stringEditor();
-
- String booleanEditor();
-
- String readWriteInput();
-
- String readButton();
-
- String writeButton();
- }
-
@UiField
Style style;
@UiField
AttributesEditorStyle attributesEditorStyle;
- @UiField
- DeviceAttributesEditorStyle deviceAttributesEditorStyle;
-
@UiField
FlexSplitPanel splitPanel;
@@ -456,41 +435,6 @@ public class AssetViewImpl extends FormViewImpl implements AssetView {
};
}
- @Override
- public AttributesEditor.Container<DeviceAttributesEditor.Style> getDeviceAttributesEditorContainer() {
- return new AttributesEditor.Container<DeviceAttributesEditor.Style>() {
- @Override
- public FormView getFormView() {
- return AssetViewImpl.this;
- }
-
- @Override
- public DeviceAttributesEditor.Style getStyle() {
- return deviceAttributesEditorStyle;
- }
-
- @Override
- public InsertPanel getPanel() {
- return attributesEditorContainer;
- }
-
- @Override
- public void showConfirmation(String title, String text, Runnable onConfirm) {
- AssetViewImpl.this.showConfirmation(title, text, onConfirm);
- }
-
- @Override
- public void showConfirmation(String title, String text, Runnable onConfirm, Runnable onCancel) {
- AssetViewImpl.this.showConfirmation(title, text, onConfirm, onCancel);
- }
-
- @Override
- public ManagerMessages getMessages(){
- return managerMessages;
- }
- };
- }
-
@Override
public void setAttributesEditor(AttributesEditor editor) {
this.attributesEditor = editor;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
index 41a56e66e..ba81a1e9f 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/asset/AssetViewImpl.ui.xml
@@ -43,34 +43,6 @@
}
</ui:style>
- <ui:style field="deviceAttributesEditorStyle"
- type="org.openremote.manager.client.assets.asset.AssetViewImpl.DeviceAttributesEditorStyle">
- .stringEditor {
- width: 44%;
- }
-
- .integerEditor {
- width: 5em;
- }
-
- .decimalEditor {
- width: 5em;
- }
-
- .booleanEditor {
- }
-
- .readWriteInput {
- width: 5em;
- }
-
- .readButton {
- }
-
- .writeButton {
- }
- </ui:style>
-
<w:FlexSplitPanel ui:field="splitPanel"
handleStyle="{widgetStyle.SplitPanelHandle}"
firstPanelWidth="250"
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java
index be37f9205..786c77340 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetBrowserPresenter.java
@@ -23,12 +23,10 @@ import com.google.gwt.view.client.HasData;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.admin.TenantArrayMapper;
import org.openremote.manager.client.assets.AssetInfoArrayMapper;
-import org.openremote.manager.client.event.CancelRepeatingServerSendEvent;
-import org.openremote.manager.client.event.RepeatingServerSendEvent;
import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.event.bus.EventListener;
import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.shared.asset.*;
+import org.openremote.manager.shared.asset.AssetResource;
import org.openremote.manager.shared.security.Tenant;
import org.openremote.manager.shared.security.TenantResource;
import org.openremote.model.Constants;
@@ -73,24 +71,6 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
this.assetResource = assetResource;
this.assetInfoArrayMapper = assetInfoArrayMapper;
- environment.getEventBus().register(AssetModifiedEvent.class, event -> {
- LOG.fine("Asset modified event received: " + event);
- if (event.getCause() == AssetModifiedEvent.Cause.CHILDREN_MODIFIED) {
-
- boolean forceRootRefresh = event.getAssetInfo().getParentId() == null;
-
- // If we are in the master realm, we never refresh the root of
- // the asset tree, these are "immutable" tenants
- // TODO: Notifications when tenants are modified?
- String currentRealm = environment.getSecurityService().getAuthenticatedRealm();
- if (currentRealm.equals(Constants.MASTER_REALM)) {
- forceRootRefresh = false;
- }
-
- view.refreshAssets(forceRootRefresh);
- }
- });
-
view.setPresenter(this);
}
@@ -101,21 +81,12 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
@Override
public void onViewAttached() {
- LOG.fine("Asset browser attached, subscribing to asset changes on the server");
- environment.getEventBus().dispatch(new RepeatingServerSendEvent(
- new SubscribeAssetModified(),
- AssetBrowserPresenter.class.getSimpleName(),
- 30000
- ));
+ // TODO LOG.fine("Asset browser attached, subscribing to asset changes on the server");
}
@Override
public void onViewDetached() {
- LOG.fine("Asset browser detached, unsubscribing from asset changes on the server");
- environment.getEventBus().dispatch(new CancelRepeatingServerSendEvent(
- new UnsubscribeAssetModified(),
- AssetBrowserPresenter.class.getSimpleName()
- ));
+ // TODO LOG.fine("Asset browser detached, unsubscribing from asset changes on the server");
}
@Override
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelectedEvent.java b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelectedEvent.java
index cd49b7831..d413923c3 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelectedEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/browser/AssetSelectedEvent.java
@@ -1,8 +1,10 @@
package org.openremote.manager.client.assets.browser;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
import org.openremote.model.asset.AssetInfo;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
+@JsonIgnoreType
public class AssetSelectedEvent extends Event {
final protected AssetInfo assetInfo;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
deleted file mode 100644
index b27b117bb..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/device/DeviceAttributesEditor.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.client.assets.device;
-
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.Label;
-import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.event.CancelRepeatingServerSendEvent;
-import org.openremote.manager.client.event.RepeatingServerSendEvent;
-import org.openremote.manager.client.event.ServerSendEvent;
-import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.client.widget.*;
-import org.openremote.manager.shared.agent.*;
-import org.openremote.manager.shared.device.DeviceAttributes;
-import org.openremote.manager.shared.device.DeviceResource;
-import org.openremote.model.Attribute;
-import org.openremote.model.Attributes;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-public class DeviceAttributesEditor extends AttributesEditor<DeviceAttributesEditor.Style> {
-
- private static final Logger LOG = Logger.getLogger(DeviceAttributesEditor.class.getName());
-
- public interface Style extends AttributesEditor.Style {
-
- String readWriteInput();
-
- String readButton();
-
- String writeButton();
- }
-
- final String agentAssetId;
- final protected FormGroup deviceActionsGroup = new FormGroup();
- final protected FormCheckBox enableLiveUpdatesCheckBox = new FormCheckBox();
- final protected DeviceAttributes deviceAttributes;
- final protected Map<String, FormInputText> deviceResourceInputs = new HashMap<>();
-
- protected EventRegistration<DeviceResourceValueEvent> deviceResourceValueRegistration;
-
- public DeviceAttributesEditor(Environment environment, Container<DeviceAttributesEditor.Style> container, Attributes attributes, String agentAssetId) {
- super(environment, container, attributes);
-
- this.agentAssetId = agentAssetId;
- this.deviceAttributes = new DeviceAttributes(attributes.getJsonObject());
-
- FormLabel enableLiveUpdates = new FormLabel();
- enableLiveUpdates.addStyleName("larger");
- enableLiveUpdates.setText(environment.getMessages().enableLiveUpdates());
- FormField deviceActionsFormField = new FormField();
- deviceActionsFormField.add(enableLiveUpdatesCheckBox);
- deviceActionsGroup.addFormLabel(enableLiveUpdates);
- deviceActionsGroup.addFormField(deviceActionsFormField);
-
- enableLiveUpdatesCheckBox.addValueChangeHandler(event -> {
- enableLiveUpdates(event.getValue());
- });
-
- deviceResourceValueRegistration = environment.getEventBus().register(
- DeviceResourceValueEvent.class, event -> {
- if (deviceAttributes.getKey().equals(event.getDeviceKey()) &&
- deviceResourceInputs.containsKey(event.getDeviceResourceKey())) {
- deviceResourceInputs.get(event.getDeviceResourceKey())
- .setText(event.getValue());
- }
- }
- );
- }
-
- @Override
- public void close() {
- super.close();
- enableLiveUpdates(false);
- if (deviceResourceValueRegistration != null) {
- environment.getEventBus().remove(deviceResourceValueRegistration);
- }
- }
-
- @Override
- public void build() {
- container.getPanel().add(deviceActionsGroup);
- super.build();
- }
-
- @Override
- public void setOpaque(boolean opaque) {
- super.setOpaque(opaque);
- deviceActionsGroup.setOpaque(opaque);
- }
-
- @Override
- protected FormLabel createAttributeLabel(Attribute attribute) {
- FormLabel formLabel = super.createAttributeLabel(attribute);
-
- if (DeviceResource.isDeviceResource(attribute)) {
- DeviceResource deviceResource = new DeviceResource(attribute);
- // TODO Anything
- } else if (attribute.getName().equals("key")) {
- formLabel.setText(environment.getMessages().deviceKey());
- }
-
- return formLabel;
- }
-
- @Override
- protected FormGroup createAttributeGroup(Attribute attribute) {
- FormGroup formGroup = super.createAttributeGroup(attribute);
- if (DeviceResource.isDeviceResource(attribute)) {
- formGroup.addInfolabel(
- new Label(environment.getMessages().resourceKey())
- );
-
- DeviceResource deviceResource = new DeviceResource(attribute);
-
-
- // TODO These actions don't do anything
- FlowPanel actionPanel = new FlowPanel();
- actionPanel.setStyleName("flex layout horizontal center");
-
- FormButton readButton = new FormButton();
- readButton.addClickHandler(event -> {
- environment.getEventBus().dispatch(new ServerSendEvent(
- new DeviceResourceRead(
- agentAssetId,
- deviceAttributes.getKey(),
- deviceResource.getValueAsString()
- )
- ));
- });
- readButton.setPrimary(true);
- readButton.addStyleName(container.getStyle().readButton());
- readButton.setText(environment.getMessages().read());
-
- FormInputText readWriteInput = new FormInputText();
- deviceResourceInputs.put(deviceResource.getValueAsString(), readWriteInput);
- readWriteInput.addStyleName(container.getStyle().readWriteInput());
-
- FormButton writeButton = new FormButton();
- writeButton.addClickHandler(event -> {
- environment.getEventBus().dispatch(new ServerSendEvent(
- new DeviceResourceWrite(
- agentAssetId,
- deviceAttributes.getKey(),
- deviceResource.getValueAsString(),
- readWriteInput.getText()
- )
- ));
- });
- writeButton.setDanger(true);
- writeButton.addStyleName(container.getStyle().writeButton());
- writeButton.setText(environment.getMessages().write());
-
- actionPanel.add(readButton);
- actionPanel.add(readWriteInput);
- actionPanel.add(writeButton);
- switch (deviceResource.getAccess()) {
- case R:
- readWriteInput.setReadOnly(true);
- readButton.setEnabled(true);
- writeButton.setEnabled(false);
- break;
- case W:
- readWriteInput.setReadOnly(false);
- readButton.setEnabled(false);
- writeButton.setEnabled(true);
- break;
- default:
- readWriteInput.setReadOnly(false);
- readButton.setEnabled(true);
- writeButton.setEnabled(true);
- }
- formGroup.getFormField().add(actionPanel);
- }
- return formGroup;
- }
-
- @Override
- protected boolean isDefaultReadOnly(Attribute attribute) {
- return DeviceAttributes.isReadOnly(attribute) || super.isDefaultReadOnly(attribute);
- }
-
-/*
- @Override
- protected FormInputText createStringEditor(Style style, Attribute attribute, boolean readOnly) {
- return super.createStringEditor(style, attribute, readOnly || DeviceResource.isDeviceResource(attribute));
- }
-
- @Override
- protected FormInputNumber createIntegerEditor(Style style, Attribute attribute, boolean readOnly) {
- return super.createIntegerEditor(style, attribute, readOnly || DeviceResource.isDeviceResource(attribute));
- }
-
- @Override
- protected FormInputText createDecimalEditor(Style style, Attribute attribute, boolean readOnly) {
- return super.createDecimalEditor(style, attribute, readOnly || DeviceResource.isDeviceResource(attribute));
- }
-
- @Override
- protected FormCheckBox createBooleanEditor(Style style, Attribute attribute, boolean readOnly) {
- return super.createBooleanEditor(style, attribute, readOnly || DeviceResource.isDeviceResource(attribute));
- }
-*/
-
- protected void enableLiveUpdates(boolean enable) {
- if (enable) {
- environment.getEventBus().dispatch(new RepeatingServerSendEvent(
- new SubscribeDeviceResourceUpdates(agentAssetId, deviceAttributes.getKey()),
- "deviceAttributes-liveUpdate",
- 30000
- ));
- } else {
- environment.getEventBus().dispatch(new CancelRepeatingServerSendEvent(
- new UnsubscribeDeviceResourceUpdates(agentAssetId, deviceAttributes.getKey()),
- "deviceAttributes-liveUpdate"
- ));
- }
-
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/EventMapper.java b/manager/client/src/main/java/org/openremote/manager/client/event/EventMapper.java
index e400451ca..1ce892ca9 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/EventMapper.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/EventMapper.java
@@ -22,7 +22,7 @@ package org.openremote.manager.client.event;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.manager.client.interop.jackson.DefaultJsonMixin;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
@JsonMixIns({@JsonMixIns.JsonMixIn(target = Event.class, mixIn = DefaultJsonMixin.class)})
public interface EventMapper extends ObjectMapper<Event> {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/GoToPlaceEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/GoToPlaceEvent.java
index 021ec9341..1439c2141 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/GoToPlaceEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/GoToPlaceEvent.java
@@ -21,7 +21,7 @@ package org.openremote.manager.client.event;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.google.gwt.place.shared.Place;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
@JsonIgnoreType
public class GoToPlaceEvent extends Event {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/MessageReceivedEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/MessageReceivedEvent.java
deleted file mode 100644
index e40b6f861..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/event/MessageReceivedEvent.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.client.event;
-
-import jsinterop.annotations.JsIgnore;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
-import org.openremote.manager.shared.event.Message;
-
-@JsType
-public class MessageReceivedEvent extends Event {
-
- public Message message;
-
- @JsIgnore
- public MessageReceivedEvent() {
- }
-
- @JsIgnore
- public MessageReceivedEvent(Message message) {
- this.message = message;
- }
-
- public Message getMessage() {
- return message;
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/ui/ShowFailureEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/ShowFailureEvent.java
similarity index 86%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/ui/ShowFailureEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/ShowFailureEvent.java
index 91a7ac427..f9a0a7ba4 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/ui/ShowFailureEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/ShowFailureEvent.java
@@ -17,13 +17,12 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.ui;
+package org.openremote.manager.client.event;
-import jsinterop.annotations.JsIgnore;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class ShowFailureEvent extends Event {
public static final int DURABLE = 9999999; // 7 days...
@@ -31,16 +30,13 @@ public class ShowFailureEvent extends Event {
public String text;
public int durationMillis;
- @JsIgnore
public ShowFailureEvent() {
}
- @JsIgnore
public ShowFailureEvent(String text) {
this(text, DURABLE);
}
- @JsIgnore
public ShowFailureEvent(String text, int durationMillis) {
this.text = text;
this.durationMillis = durationMillis;
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/ui/ShowInfoEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/ShowInfoEvent.java
similarity index 83%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/ui/ShowInfoEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/ShowInfoEvent.java
index f926521ed..1aaea88ef 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/ui/ShowInfoEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/ShowInfoEvent.java
@@ -17,22 +17,19 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.ui;
+package org.openremote.manager.client.event;
-import jsinterop.annotations.JsIgnore;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class ShowInfoEvent extends Event {
public String text;
- @JsIgnore
public ShowInfoEvent() {
}
- @JsIgnore
public ShowInfoEvent(String text) {
this.text = text;
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/UserChangeEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/UserChangeEvent.java
index d4578cdcc..136699d8c 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/UserChangeEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/UserChangeEvent.java
@@ -19,8 +19,10 @@
*/
package org.openremote.manager.client.event;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
+@JsonIgnoreType
public class UserChangeEvent extends Event {
final private String username;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/WillGoToPlaceEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/WillGoToPlaceEvent.java
index a0c5e87d8..8eb438bcd 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/WillGoToPlaceEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/WillGoToPlaceEvent.java
@@ -21,7 +21,7 @@ package org.openremote.manager.client.event;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.google.gwt.place.shared.Place;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
@JsonIgnoreType
public abstract class WillGoToPlaceEvent extends Event {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventBus.java b/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventBus.java
index 7d5ddea71..a11cffb54 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventBus.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventBus.java
@@ -19,7 +19,7 @@
*/
package org.openremote.manager.client.event.bus;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
import java.util.*;
import java.util.logging.Level;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventListener.java b/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventListener.java
index 09a43cba6..ea2a7be33 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventListener.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventListener.java
@@ -20,7 +20,7 @@
package org.openremote.manager.client.event.bus;
import jsinterop.annotations.JsFunction;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
@JsFunction
public interface EventListener<E extends Event> {
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventRegistration.java b/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventRegistration.java
index 984284402..e0c6dc64c 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventRegistration.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/bus/EventRegistration.java
@@ -19,7 +19,7 @@
*/
package org.openremote.manager.client.event.bus;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
public class EventRegistration<E extends Event> {
@@ -54,7 +54,7 @@ public class EventRegistration<E extends Event> {
}
public String getEventType() {
- return Event.getType(getEventClass());
+ return Event.getEventType(getEventClass());
}
public EventListener<E> getListener() {
@@ -62,6 +62,6 @@ public class EventRegistration<E extends Event> {
}
public boolean isMatching(Event event) {
- return getEventClass() == null || getEventType().equals(event.getType());
+ return getEventClass() == null || getEventType().equals(event.getEventType());
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/CancelRepeatingServerSendEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/CancelRepeatingServerSendEvent.java
similarity index 88%
rename from manager/client/src/main/java/org/openremote/manager/client/event/CancelRepeatingServerSendEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/CancelRepeatingServerSendEvent.java
index 21f26b575..734cbb3ad 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/CancelRepeatingServerSendEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/CancelRepeatingServerSendEvent.java
@@ -17,12 +17,10 @@
* 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.event;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
-@JsType
public class CancelRepeatingServerSendEvent extends ServerSendEvent {
final public String key;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/RepeatingServerSendEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/RepeatingServerSendEvent.java
similarity index 90%
rename from manager/client/src/main/java/org/openremote/manager/client/event/RepeatingServerSendEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/RepeatingServerSendEvent.java
index 2d6981b03..ed4b8bf0c 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/RepeatingServerSendEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/RepeatingServerSendEvent.java
@@ -17,12 +17,10 @@
* 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.event;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
-@JsType
public class RepeatingServerSendEvent extends ServerSendEvent {
final public String key;
diff --git a/manager/client/src/main/java/org/openremote/manager/client/event/ServerSendEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/ServerSendEvent.java
similarity index 86%
rename from manager/client/src/main/java/org/openremote/manager/client/event/ServerSendEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/ServerSendEvent.java
index 3055860dc..9e33ac4a2 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/event/ServerSendEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/ServerSendEvent.java
@@ -17,12 +17,12 @@
* 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.event;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class ServerSendEvent extends Event {
final public Event event;
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionCloseEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionCloseEvent.java
similarity index 84%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionCloseEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/SessionCloseEvent.java
index 0425978a7..16063b8af 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionCloseEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionCloseEvent.java
@@ -17,11 +17,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.session;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class SessionCloseEvent extends Event {
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionClosedCleanEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionClosedCleanEvent.java
similarity index 84%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionClosedCleanEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/SessionClosedCleanEvent.java
index 2bedf3b8a..6f0ffd235 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionClosedCleanEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionClosedCleanEvent.java
@@ -17,11 +17,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.session;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class SessionClosedCleanEvent extends Event {
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionClosedErrorEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionClosedErrorEvent.java
similarity index 88%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionClosedErrorEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/SessionClosedErrorEvent.java
index 9b7c96e4f..f397ec288 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionClosedErrorEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionClosedErrorEvent.java
@@ -17,15 +17,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.session;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class SessionClosedErrorEvent extends Event {
- @JsType
public static class Error {
public final int code;
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionConnectEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionConnectEvent.java
similarity index 84%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionConnectEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/SessionConnectEvent.java
index f9adcad50..d828aeabb 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionConnectEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionConnectEvent.java
@@ -17,11 +17,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.session;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class SessionConnectEvent extends Event {
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionOpenedEvent.java b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionOpenedEvent.java
similarity index 84%
rename from manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionOpenedEvent.java
rename to manager/client/src/main/java/org/openremote/manager/client/event/session/SessionOpenedEvent.java
index a2eeb6501..ae7b03901 100644
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/session/SessionOpenedEvent.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/event/session/SessionOpenedEvent.java
@@ -17,11 +17,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.openremote.manager.shared.event.session;
+package org.openremote.manager.client.event.session;
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.event.Event;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import org.openremote.model.Event;
-@JsType
+@JsonIgnoreType
public class SessionOpenedEvent extends Event {
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsActivity.java b/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsActivity.java
deleted file mode 100644
index d353ec2d6..000000000
--- a/manager/client/src/main/java/org/openremote/manager/client/flows/FlowsActivity.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.client.flows;
-
-import com.google.gwt.place.shared.PlaceHistoryMapper;
-import com.google.gwt.user.client.ui.AcceptsOneWidget;
-import org.openremote.manager.client.Environment;
-import org.openremote.manager.client.assets.AssetInfoArrayMapper;
-import org.openremote.manager.client.assets.AssetMapper;
-import org.openremote.manager.client.event.bus.EventBus;
-import org.openremote.manager.client.event.bus.EventRegistration;
-import org.openremote.manager.client.mvp.AppActivity;
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.model.Constants;
-import org.openremote.model.asset.AssetInfo;
-import org.openremote.manager.shared.asset.AssetResource;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
-import org.openremote.model.Attributes;
-
-import javax.inject.Inject;
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import static org.openremote.manager.client.http.RequestExceptionHandler.handleRequestException;
-
-public class FlowsActivity
- extends AppActivity<FlowsPlace>
- implements FlowsView.Presenter {
-
- private static final Logger LOG = Logger.getLogger(FlowsActivity.class.getName());
-
- final FlowsView view;
- final Environment environment;
- final PlaceHistoryMapper historyMapper;
- final AssetResource assetResource;
- final AssetInfoArrayMapper assetInfoArrayMapper;
- final AssetMapper assetMapper;
-
- @Inject
- public FlowsActivity(FlowsView view,
- Environment environment,
- PlaceHistoryMapper historyMapper,
- AssetResource assetResource,
- AssetInfoArrayMapper assetInfoArrayMapper,
- AssetMapper assetMapper) {
- this.view = view;
- this.environment = environment;
- this.historyMapper = historyMapper;
- this.assetResource = assetResource;
- this.assetInfoArrayMapper = assetInfoArrayMapper;
- this.assetMapper = assetMapper;
- }
-
- @Override
- protected AppActivity<FlowsPlace> init(FlowsPlace place) {
- return this;
- }
-
- @Override
- public void start(AcceptsOneWidget container, EventBus eventBus, Collection<EventRegistration> registrations) {
- container.setWidget(view.asWidget());
- view.setPresenter(this);
-/* TODO
- environment.getRequestService().execute(
- assetInfoArrayMapper,
- requestParams -> {
- // TODO We should query only agents with controller2 connectors
- assetResource.getByType(requestParams, AssetType.AGENT.getValue());
- },
- 200,
- view::setAgents,
- ex -> handleRequestException(ex, environment)
- );
- */
- }
-
- @Override
- public void onStop() {
- view.setPresenter(null);
- super.onStop();
- }
-
- @Override
- public String getFlowsHistoryToken() {
- return historyMapper.getToken(new FlowsPlace());
- }
-
- @Override
- public void onAgentSelected(AssetInfo assetInfo) {
- environment.getRequestService().execute(
- assetMapper,
- requestParams -> {
- assetResource.get(requestParams, assetInfo.getId());
- },
- 200,
- agentAsset -> {
- Attributes attributes = new Attributes(agentAsset.getAttributes());
- Agent agent = new Agent(attributes);
- if ((Constants.NAMESPACE + ":connector:controller2").equals(agent.getConnectorType())) {
- StringBuilder sb = new StringBuilder();
- sb.append("http://");
- sb.append(attributes.get("host").getValueAsString());
- sb.append(":");
- sb.append(attributes.get("port").getValueAsString());
- // TODO hardcoded dimensions
- sb.append("/webconsole/?consoleWidth=320&consoleHeight=568&showConsoleFrame=false&showWelcome=false&showToolbar=false&backgroundColor=444444");
- sb.append("&controllerURL=");
- sb.append("http://");
- sb.append(attributes.get("host").getValueAsString());
- sb.append(":");
- sb.append(attributes.get("port").getValueAsString());
- sb.append("/controller");
- sb.append("&panelName=iPhone5"); // TODO hardcoded panel name
- view.setFrameSourceUrl(sb.toString());
- } else {
- // TODO: Remove when we only have controller2 agents
- environment.getEventBus().dispatch(new ShowInfoEvent(
- "The selected agent is not an OpenRemote 2.x controller, no console available."
- ));
- }
- },
- ex -> handleRequestException(ex, environment)
- );
- }
-}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java b/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java
index c0159dc04..d53a53601 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/http/RequestExceptionHandler.java
@@ -23,7 +23,7 @@ import org.openremote.manager.client.Environment;
import org.openremote.manager.client.event.bus.EventBus;
import org.openremote.manager.client.i18n.ManagerMessages;
import org.openremote.model.Consumer;
-import org.openremote.manager.shared.event.ui.ShowFailureEvent;
+import org.openremote.manager.client.event.ShowFailureEvent;
import org.openremote.manager.shared.http.*;
import org.openremote.manager.shared.validation.ConstraintViolation;
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 67a1f3322..ef8a6c133 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
@@ -35,7 +35,7 @@ public interface ManagerMessages extends Messages {
String rules();
- String flows();
+ String apps();
String admin();
diff --git a/manager/client/src/main/java/org/openremote/manager/client/mvp/AppPlaceController.java b/manager/client/src/main/java/org/openremote/manager/client/mvp/AppPlaceController.java
index cd31b102c..5f2ed6d60 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/mvp/AppPlaceController.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/mvp/AppPlaceController.java
@@ -75,7 +75,9 @@ public class AppPlaceController extends PlaceController {
@Override
public String toString() {
- return "WillGoToPlaceEvent";
+ return "WillGoToPlaceEvent{" +
+ "place=" + event.getNewPlace()+
+ '}';
}
});
});
diff --git a/manager/client/src/main/java/org/openremote/manager/client/service/EventServiceImpl.java b/manager/client/src/main/java/org/openremote/manager/client/service/EventServiceImpl.java
index 78bf12740..4c36aba2a 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/service/EventServiceImpl.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/service/EventServiceImpl.java
@@ -25,12 +25,10 @@ import elemental.html.Location;
import elemental.html.WebSocket;
import org.openremote.manager.client.event.*;
import org.openremote.manager.client.event.bus.EventBus;
+import org.openremote.manager.client.event.session.*;
import org.openremote.manager.client.util.Timeout;
-import org.openremote.manager.shared.event.Event;
-import org.openremote.manager.shared.event.Message;
-import org.openremote.manager.shared.event.session.*;
-import org.openremote.manager.shared.event.ui.ShowFailureEvent;
import org.openremote.model.Constants;
+import org.openremote.model.Event;
import java.util.ArrayList;
import java.util.HashMap;
@@ -169,7 +167,7 @@ public class EventServiceImpl implements EventService {
}
securityService.updateToken(
- Constants.ACCESS_TOKEN_LIFESPAN_SECONDS/2,
+ Constants.ACCESS_TOKEN_LIFESPAN_SECONDS / 2,
refreshed -> {
// If it wasn't refreshed, it was still valid, in both cases we can continue
LOG.fine("Connecting to event websocket: " + serviceUrl);
@@ -230,17 +228,12 @@ public class EventServiceImpl implements EventService {
protected void onDataReceived(String data) {
Event event = eventMapper.read(data);
- if (event.getType().equals(Event.getType(Message.class))) {
- Message message = (Message) event;
- eventBus.dispatch(new MessageReceivedEvent(message));
- } else {
- eventBus.dispatch(event);
- }
+ eventBus.dispatch(event);
}
protected void reconnect() {
LOG.fine("Session reconnection attempt '" + serviceUrl + "' with delay milliseconds: " + DELAY_MILLIS);
SessionConnectEvent event = new SessionConnectEvent();
- Timeout.debounce(event.getType(), () -> eventBus.dispatch(event), DELAY_MILLIS);
+ Timeout.debounce(event.getEventType(), () -> eventBus.dispatch(event), DELAY_MILLIS);
}
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/user/UserControlsPresenter.java b/manager/client/src/main/java/org/openremote/manager/client/user/UserControlsPresenter.java
index 6d81e6944..dd8f34e77 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/user/UserControlsPresenter.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/user/UserControlsPresenter.java
@@ -23,7 +23,7 @@ import com.google.inject.Inject;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.ManagerHistoryMapper;
import org.openremote.manager.client.event.UserChangeEvent;
-import org.openremote.manager.shared.event.ui.ShowFailureEvent;
+import org.openremote.manager.client.event.ShowFailureEvent;
import java.util.logging.Logger;
diff --git a/model/src/main/java/org/openremote/model/asset/AssetStateChange.java b/manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.java
similarity index 62%
rename from model/src/main/java/org/openremote/model/asset/AssetStateChange.java
rename to manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.java
index c24a0248c..4b96deffa 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetStateChange.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/util/CollectionsUtil.java
@@ -17,22 +17,19 @@
* 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.asset;
+package org.openremote.manager.client.util;
-import org.openremote.model.Attribute;
-import org.openremote.model.AttributeState;
-import org.openremote.model.AttributeStateChange;
+import java.util.*;
-public class AssetStateChange<A extends Asset> extends AttributeStateChange {
+public class CollectionsUtil {
- final protected A asset;
-
- public AssetStateChange(A asset, Attribute attribute, AttributeState originalState) {
- super(attribute, originalState);
- this.asset = asset;
+ public static <K, V> void sortMap(LinkedHashMap<K, V> map, Comparator<? super V> c) {
+ List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet());
+ Collections.sort(entries, (lhs, rhs) -> c.compare(lhs.getValue(), rhs.getValue()));
+ map.clear();
+ for(Map.Entry<K, V> e : entries) {
+ map.put(e.getKey(), e.getValue());
+ }
}
- public A getAsset() {
- return asset;
- }
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
index 8fe88299d..8ab20af0b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/AttributesEditor.java
@@ -30,10 +30,11 @@ import elemental.json.JsonType;
import elemental.json.JsonValue;
import org.openremote.manager.client.Environment;
import org.openremote.manager.client.i18n.ManagerMessages;
+import org.openremote.manager.client.util.CollectionsUtil;
import org.openremote.manager.client.util.JsUtil;
import org.openremote.manager.client.util.TextUtil;
-import org.openremote.manager.shared.event.ui.ShowFailureEvent;
-import org.openremote.manager.shared.event.ui.ShowInfoEvent;
+import org.openremote.manager.client.event.ShowFailureEvent;
+import org.openremote.manager.client.event.ShowInfoEvent;
import org.openremote.model.*;
import org.openremote.model.Runnable;
import org.openremote.model.asset.AssetMeta;
@@ -42,7 +43,6 @@ import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.logging.Logger;
-import static org.openremote.manager.shared.util.Util.sortMap;
public class AttributesEditor<S extends AttributesEditor.Style> {
@@ -106,7 +106,7 @@ public class AttributesEditor<S extends AttributesEditor.Style> {
}
// Sort form groups by label text ascending
- sortMap(attributeGroups, Comparator.comparing(a -> a.getFormLabel().getText()));
+ CollectionsUtil.sortMap(attributeGroups, Comparator.comparing(a -> a.getFormLabel().getText()));
for (FormGroup attributeGroup : attributeGroups.values()) {
container.getPanel().add(attributeGroup);
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 b427a1544..d6aefa254 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
@@ -1,7 +1,7 @@
map = Map
assets = Assets
rules = Rules
-flows = Apps
+apps = Apps
admin = System
logout = Logout
fullscreen=Fullscreen
diff --git a/manager/server/src/main/java/org/openremote/manager/server/Main.java b/manager/server/src/main/java/org/openremote/manager/server/Main.java
index 525602d21..d6b2c2978 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/Main.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/Main.java
@@ -26,8 +26,8 @@ import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.message.MessageBrokerSetupService;
import org.openremote.container.persistence.PersistenceService;
import org.openremote.manager.server.agent.AgentService;
-import org.openremote.manager.server.asset.AssetStorageService;
import org.openremote.manager.server.asset.AssetProcessingService;
+import org.openremote.manager.server.asset.AssetStorageService;
import org.openremote.manager.server.datapoint.AssetDatapointService;
import org.openremote.manager.server.event.EventService;
import org.openremote.manager.server.i18n.I18NService;
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java
deleted file mode 100644
index fcbd704bb..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorResourceImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.server.agent;
-
-import org.openremote.container.web.WebResource;
-import org.openremote.manager.shared.connector.Connector;
-import org.openremote.manager.shared.connector.ConnectorComponent;
-import org.openremote.manager.shared.connector.ConnectorResource;
-import org.openremote.manager.shared.http.RequestParams;
-
-import javax.ws.rs.BeanParam;
-import java.util.Collection;
-
-public class ConnectorResourceImpl extends WebResource implements ConnectorResource {
-
- protected final ConnectorService connectorService;
-
- public ConnectorResourceImpl(ConnectorService connectorService) {
- this.connectorService = connectorService;
- }
-
- @Override
- public Connector[] getConnectors(@BeanParam RequestParams requestParams) {
- Collection<ConnectorComponent> connectorComponents = connectorService.getConnectorComponents().values();
- return connectorComponents
- .stream()
- .map(c -> new Connector(
- c.getDisplayName(),
- c.getType(),
- c.getProducerCapabilities().contains(ConnectorComponent.Capability.discovery),
- c.getConnectorSettings()
- ))
- .toArray(Connector[]::new);
- }
-
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java
deleted file mode 100644
index 52c0e4893..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ConnectorService.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.server.agent;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
-import org.apache.camel.util.CamelContextHelper;
-import org.openremote.container.Container;
-import org.openremote.container.ContainerService;
-import org.openremote.container.message.MessageBrokerSetupService;
-import org.openremote.container.web.WebService;
-import org.openremote.manager.shared.connector.ConnectorComponent;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Logger;
-
-public class ConnectorService implements ContainerService {
-
- private static final Logger LOG = Logger.getLogger(ConnectorService.class.getName());
-
- final protected Map<String, ConnectorComponent> connectors = new LinkedHashMap<>();
-
- @Override
- public void init(Container container) throws Exception {
- findConnectors(
- container.getService(MessageBrokerSetupService.class).getContext()
- );
-
- container.getService(WebService.class).getApiSingletons().add(
- new ConnectorResourceImpl(this)
- );
- }
-
- @Override
- public void start(Container container) throws Exception {
-
- }
-
- @Override
- public void stop(Container container) throws Exception {
-
- }
-
- public Map<String, ConnectorComponent> getConnectorComponents() {
- return connectors;
- }
-
- public ConnectorComponent getConnectorComponentByType(String connectorType) {
- for (ConnectorComponent connector : connectors.values()) {
- if (connector.getType().equals(connectorType))
- return connector;
- }
- return null;
- }
-
- protected void findConnectors(CamelContext context) throws Exception {
- for (Map.Entry<String, Properties> entry : CamelContextHelper.findComponents(context).entrySet()) {
-
- String connectorComponentName = entry.getKey();
- Component component = context.getComponent(connectorComponentName);
-
- if (component instanceof ConnectorComponent) {
- ConnectorComponent connector = (ConnectorComponent)component;
-
- for (ConnectorComponent existingConnector : connectors.values()) {
- if (existingConnector.getType().equals(connector.getType())) {
- throw new IllegalStateException(
- "Duplicate connector types are not allowed: " + connector.getType()
- );
- }
- }
-
- LOG.info(
- "Configured connector component '" + connectorComponentName + "' of type: " + connector.getType()
- );
-
- connectors.put(connectorComponentName, connector);
- }
- }
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- '}';
- }
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/DeviceResourceSubscription.java b/manager/server/src/main/java/org/openremote/manager/server/agent/DeviceResourceSubscription.java
deleted file mode 100644
index 167d0a099..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/DeviceResourceSubscription.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.server.agent;
-
-import org.openremote.manager.shared.agent.DeviceResourceValueEvent;
-import org.openremote.manager.shared.agent.UnsubscribeDeviceResourceUpdates;
-
-import java.util.Objects;
-
-public class DeviceResourceSubscription {
-
- final protected String agentId;
- final protected String deviceKey;
- final protected long timestamp;
-
- public DeviceResourceSubscription(String agentId, String deviceKey, long timestamp) {
- Objects.requireNonNull(agentId, "Agent asset identifier must be provided when creating a subscription");
- Objects.requireNonNull(deviceKey, "Device key must be provided when creating a subscription");
- this.agentId = agentId;
- this.deviceKey = deviceKey;
- this.timestamp = timestamp;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- public long getTimestamp() {
- return timestamp;
- }
-
- public boolean matches(DeviceResourceValueEvent event) {
- return event.getAgentId().equals(agentId) && event.getDeviceKey().equals(deviceKey);
- }
-
- public boolean matches(UnsubscribeDeviceResourceUpdates event) {
- return event.getAgentId().equals(agentId) && event.getDeviceKey().equals(deviceKey);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DeviceResourceSubscription that = (DeviceResourceSubscription) o;
-
- if (!agentId.equals(that.agentId)) return false;
- return deviceKey.equals(that.deviceKey);
-
- }
-
- @Override
- public int hashCode() {
- int result = agentId.hashCode();
- result = 31 * result + deviceKey.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "agentId='" + agentId + '\'' +
- ", deviceKey='" + deviceKey + '\'' +
- ", timestamp=" + timestamp +
- '}';
- }
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/DeviceResourceSubscriptions.java b/manager/server/src/main/java/org/openremote/manager/server/agent/DeviceResourceSubscriptions.java
deleted file mode 100644
index 4926dc853..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/DeviceResourceSubscriptions.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.server.agent;
-
-import org.openremote.manager.server.event.EventService;
-import org.openremote.manager.shared.agent.DeviceResourceValueEvent;
-import org.openremote.manager.shared.agent.SubscribeDeviceResourceUpdates;
-import org.openremote.manager.shared.agent.UnsubscribeDeviceResourceUpdates;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Logger;
-
-// TODO this is quite a hack to get some publish/subscribe system going, it will have to be replaced
-public class DeviceResourceSubscriptions {
-
- private static final Logger LOG = Logger.getLogger(DeviceResourceSubscriptions.class.getName());
-
- public static final int DEVICE_RESOURCE_SUBSCRIPTION_LIFETIME_SECONDS = 60;
-
- final protected EventService eventService;
- final protected Map<String, Set<DeviceResourceSubscription>> subscriptions = new ConcurrentHashMap<>();
- final protected ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
-
- public DeviceResourceSubscriptions(EventService eventService) {
- this.eventService = eventService;
-
- scheduler.scheduleAtFixedRate(() -> {
- synchronized (subscriptions) {
- subscriptions.forEach((sessionKey, subscriptions) -> {
- Iterator<DeviceResourceSubscription> it = subscriptions.iterator();
- while (it.hasNext()) {
- DeviceResourceSubscription subscription = it.next();
- if (subscription.timestamp + (DEVICE_RESOURCE_SUBSCRIPTION_LIFETIME_SECONDS * 1000) < System.currentTimeMillis()) {
- LOG.fine("Removing from session '" + sessionKey + "' due to timeout: " + subscription);
- it.remove();
- }
- }
- if (subscriptions.size() ==0) {
- this.subscriptions.remove(sessionKey);
- }
- });
-
- }
- }, DEVICE_RESOURCE_SUBSCRIPTION_LIFETIME_SECONDS, DEVICE_RESOURCE_SUBSCRIPTION_LIFETIME_SECONDS, TimeUnit.SECONDS);
- }
-
- public void addSubscription(String sessionKey, SubscribeDeviceResourceUpdates event) {
- DeviceResourceSubscription subscription = new DeviceResourceSubscription(
- event.getAgentId(),
- event.getDeviceKey(),
- System.currentTimeMillis()
- );
- synchronized (subscriptions) {
- Set<DeviceResourceSubscription> subscriptions = this.subscriptions.get(sessionKey);
- if (subscriptions == null) {
- subscriptions = new HashSet<>();
- }
- LOG.fine("Event session '" + sessionKey + "' adding/updating: " + subscription);
- subscriptions.add(subscription);
- this.subscriptions.put(sessionKey, subscriptions);
- }
- }
-
- public void removeSubscription(String sessionKey, UnsubscribeDeviceResourceUpdates event) {
- synchronized (subscriptions) {
- Set<DeviceResourceSubscription> subscriptions = this.subscriptions.get(sessionKey);
- if (subscriptions == null)
- return;
- Iterator<DeviceResourceSubscription> it = subscriptions.iterator();
- while (it.hasNext()) {
- DeviceResourceSubscription subscription = it.next();
- if (subscription.matches(event)) {
- LOG.fine("Event session '" + sessionKey + "' removing: " + subscription);
- it.remove();
- }
- }
- }
- }
-
- public void dispatch(DeviceResourceValueEvent updatedEvent) {
- synchronized (subscriptions) {
- for (Map.Entry<String, Set<DeviceResourceSubscription>> entry : subscriptions.entrySet()) {
- String sessionKey = entry.getKey();
- for (DeviceResourceSubscription subscription : entry.getValue()) {
- if (subscription.matches(updatedEvent)) {
- LOG.fine("For session '" + sessionKey + "' matching subscription of : " + updatedEvent);
- eventService.sendEvent(sessionKey, updatedEvent);
- }
- }
- }
- }
- }
-
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/ThingAttributes.java b/manager/server/src/main/java/org/openremote/manager/server/agent/ThingAttributes.java
index dae2f7942..cb90c0117 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/agent/ThingAttributes.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/ThingAttributes.java
@@ -19,10 +19,10 @@
*/
package org.openremote.manager.server.agent;
-import org.openremote.model.Function;
import org.openremote.model.Attribute;
import org.openremote.model.AttributeRef;
import org.openremote.model.Attributes;
+import org.openremote.model.Function;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.ProtocolConfiguration;
import org.openremote.model.asset.ThingAttribute;
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetListenerSubscriptions.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetListenerSubscriptions.java
deleted file mode 100644
index 4e7fbae88..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetListenerSubscriptions.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.server.asset;
-
-import org.openremote.container.persistence.PersistenceEvent;
-import org.openremote.manager.server.event.EventService;
-import org.openremote.manager.shared.asset.*;
-import org.openremote.model.asset.Asset;
-import org.openremote.model.asset.AssetInfo;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.*;
-import java.util.logging.Logger;
-
-// TODO this is quite a hack to get some publish/subscribe system going, it will have to be replaced
-// TODO More fine grained selection assets to subscribe to - currently all
-public abstract class AssetListenerSubscriptions {
-
- private static final Logger LOG = Logger.getLogger(AssetListenerSubscriptions.class.getName());
-
- final protected int ASSET_LISTENERS_MAX_LIFETIME_SECONDS = 60;
-
- final protected EventService eventService;
- final protected Map<String, Long> subscriptions = new ConcurrentHashMap<>();
- final protected ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(
- 1,
- r -> {
- Thread t = Executors.defaultThreadFactory().newThread(r);
- t.setDaemon(true);
- return t;
- }
- );
-
- public AssetListenerSubscriptions(EventService eventService) {
- this.eventService = eventService;
-
- // Max life time of listeners is 60 seconds
- scheduler.scheduleAtFixedRate(() -> {
- subscriptions.forEach((sessionKey, timeStamp) -> {
- if (timeStamp + (ASSET_LISTENERS_MAX_LIFETIME_SECONDS * 1000) < System.currentTimeMillis()) {
- LOG.fine("Removing asset listener session due to timeout: " + sessionKey);
- subscriptions.remove(sessionKey);
- }
- });
- }, ASSET_LISTENERS_MAX_LIFETIME_SECONDS, ASSET_LISTENERS_MAX_LIFETIME_SECONDS, TimeUnit.SECONDS);
-
- }
-
- public void addSubscription(String sessionKey, SubscribeAssetModified event) {
- Long timestamp = System.currentTimeMillis();
- LOG.fine("Subscribing/updating subscription to asset change events for session: " + sessionKey);
- subscriptions.put(sessionKey, timestamp);
- }
-
- public void removeSubscription(String sessionKey, UnsubscribeAssetModified event) {
- LOG.fine("Unsubscribing from asset change events for session: " + sessionKey);
- subscriptions.remove(sessionKey);
- }
-
- public void dispatch(PersistenceEvent persistenceEvent) {
- //noinspection unchecked
- for (AssetModifiedEvent assetModifiedEvent : createAssetModifiedEvents(persistenceEvent)) {
- for (String sessionKey : subscriptions.keySet()) {
- eventService.sendEvent(sessionKey, assetModifiedEvent);
- }
- }
- }
-
- private AssetModifiedEvent[] createAssetModifiedEvents(PersistenceEvent<Asset> persistenceEvent) {
- List<AssetModifiedEvent> events = new ArrayList<>();
-
- Asset asset = persistenceEvent.getEntity();
- // Assets are a composite structure and we want to be able to fire events that say
- // "a child was removed/inserted for this or that parent". To do this we need to
- // compare old and new entity state, figuring out which parent was modified. There
- // is also the special case of assets without parent: In that case we fire a "children
- // modified" for a special "empty" asset, which clients should consider to be the root
- // item of the whole tree. It has no name, no id, no parent, etc.
- List<String> modifiedParentIds = new ArrayList<>();
-
- AssetModifiedEvent.Cause cause = null;
-
- switch (persistenceEvent.getCause()) {
- case INSERT:
- cause = AssetModifiedEvent.Cause.CREATE;
- if (asset.getParentId() != null) {
- modifiedParentIds.add(asset.getParentId());
- } else {
- // The "root without id" asset was modified
- events.add(new AssetModifiedEvent(new AssetInfo(), AssetModifiedEvent.Cause.CHILDREN_MODIFIED));
- }
- break;
- case UPDATE:
- cause = AssetModifiedEvent.Cause.UPDATE;
-
- // Find out if the asset has a new parent
- String previousParentId = persistenceEvent.getPreviousState("parentId");
- String currentParentId = persistenceEvent.getCurrentState("parentId");
- if (previousParentId == null && currentParentId == null) {
- // The "root without id" asset was modified
- events.add(new AssetModifiedEvent(new AssetInfo(), AssetModifiedEvent.Cause.CHILDREN_MODIFIED));
- } else {
- if (previousParentId == null) {
- // The "root without id" asset was modified
- events.add(new AssetModifiedEvent(new AssetInfo(), AssetModifiedEvent.Cause.CHILDREN_MODIFIED));
- modifiedParentIds.add(currentParentId);
- } else if (currentParentId == null) {
- // The "root without id" asset was modified
- events.add(new AssetModifiedEvent(new AssetInfo(), AssetModifiedEvent.Cause.CHILDREN_MODIFIED));
- modifiedParentIds.add(previousParentId);
- }
- }
-
- // Only send "children modified" of the parent if the name of the asset changed
- String previousName = persistenceEvent.getPreviousState("name");
- String currentName = persistenceEvent.getCurrentState("name");
- boolean isEqualName = Objects.equals(previousName, currentName);
- if (!isEqualName) {
- modifiedParentIds.add(asset.getParentId());
- }
-
- break;
- case DELETE:
- cause = AssetModifiedEvent.Cause.DELETE;
- if (asset.getParentId() != null) {
- modifiedParentIds.add(asset.getParentId());
- } else {
- // The "root without id" asset was modified
- events.add(new AssetModifiedEvent(new AssetInfo(), AssetModifiedEvent.Cause.CHILDREN_MODIFIED));
- }
- break;
- }
-
- events.add(new AssetModifiedEvent(asset, cause));
-
- for (String modifiedParentId : modifiedParentIds) {
- Asset parent = getAsset(modifiedParentId);
- if (parent != null) {
- events.add(new AssetModifiedEvent(parent, AssetModifiedEvent.Cause.CHILDREN_MODIFIED));
- }
- }
-
- return events.toArray(new AssetModifiedEvent[events.size()]);
- }
-
- abstract protected Asset getAsset(String assetId);
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
index 67a546129..1926c899d 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java
@@ -19,7 +19,6 @@
*/
package org.openremote.manager.server.asset;
-import elemental.json.Json;
import org.apache.camel.builder.RouteBuilder;
import org.openremote.agent3.protocol.Protocol;
import org.openremote.container.Container;
@@ -28,10 +27,10 @@ import org.openremote.container.message.MessageBrokerSetupService;
import org.openremote.manager.server.agent.ThingAttributes;
import org.openremote.manager.server.datapoint.AssetDatapointService;
import org.openremote.manager.server.rules.AssetRulesService;
-import org.openremote.manager.shared.event.asset.AttributeStateUpdateEvent;
-import org.openremote.model.*;
-import org.openremote.model.asset.AssetMeta;
-import org.openremote.model.asset.AssetStateChange;
+import org.openremote.model.Attribute;
+import org.openremote.model.AttributeEvent;
+import org.openremote.model.AttributeState;
+import org.openremote.model.Consumer;
import org.openremote.model.asset.ThingAttribute;
import java.util.ArrayList;
@@ -48,10 +47,8 @@ import static org.openremote.model.asset.AssetType.THING;
* <li>
* Listens to {@link AttributeState} messages on {@link Protocol#SENSOR_TOPIC} and processes them
* with consumers: {@link AssetRulesService}, {@link AssetStorageService}, {@link AssetDatapointService}
- * TODO Make consumers Camel endpoints?
* </li>
* </ul>
- * TODO Move AssetListenerSubscriptions from AssetStorageService, when we figured out client messaging pub/sub
*/
public class AssetProcessingService extends RouteBuilder implements ContainerService {
@@ -60,8 +57,8 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
protected AssetRulesService assetRulesService;
protected AssetStorageService assetStorageService;
protected AssetDatapointService assetDatapointService;
- final protected List<Consumer<AssetStateChange<ServerAsset>>> attributeStateChangeConsumers = new ArrayList<>();
+ final protected List<Consumer<AssetUpdate>> processors = new ArrayList<>();
@Override
public void init(Container container) throws Exception {
@@ -69,9 +66,9 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
assetStorageService = container.getService(AssetStorageService.class);
assetDatapointService = container.getService(AssetDatapointService.class);
- attributeStateChangeConsumers.add(assetRulesService);
- attributeStateChangeConsumers.add(assetStorageService);
- attributeStateChangeConsumers.add(assetDatapointService);
+ processors.add(assetRulesService);
+ processors.add(assetStorageService);
+ processors.add(assetDatapointService);
container.getService(MessageBrokerSetupService.class).getContext().addRoutes(this);
}
@@ -91,115 +88,104 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
// Sensor updates are processed first by rules, then stored in the asset and datapoint databases
from(SENSOR_TOPIC)
- .filter(body().isInstanceOf(AttributeState.class))
+ .filter(body().isInstanceOf(AttributeEvent.class))
.process(exchange -> {
- AttributeState attributeState =
- exchange.getIn().getBody(AttributeState.class);
+ AttributeEvent attributeEvent = exchange.getIn().getBody(AttributeEvent.class);
- // TODO: Agent should be able to create AttributeStateUpdateEvent with desired timestamp
- AttributeStateUpdateEvent attributeStateUpdateEvent = new AttributeStateUpdateEvent(attributeState);
-
- // From sensor topic means this is a thing asset so we can get the thing
- ServerAsset thing = assetStorageService.find(attributeState.getAttributeRef().getEntityId());
-
- // If it's not a thing, that's wrong
+ // From sensor topic means this must update a thing asset
+ ServerAsset thing = assetStorageService.find(attributeEvent.getEntityId());
if (thing.getWellKnownType() != THING) {
- LOG.fine("Ignoring update of " + attributeState + ", not a thing: " + thing);
+ LOG.fine("Ignoring " + attributeEvent + ", not a thing: " + thing);
return;
}
- // Get the attribute and check it is actually linked to an agent
- // TODO: Do we really need to perform this verification it's the protocol that brought us here anyway?
+ // Get the attribute and check it is actually linked to an agent (although the
+ // event comes from a Protocol, we can not assume that the attribute is still linked,
+ // consider a protocol that receives a batch of messages because a gateway was offline
+ // for a day)
ThingAttributes thingAttributes = new ThingAttributes(thing);
ThingAttribute thingAttribute = thingAttributes.getLinkedAttribute(
- assetStorageService.getAgentLinkResolver(), attributeState.getAttributeRef().getAttributeName()
+ assetStorageService.getAgentLinkResolver(), attributeEvent.getAttributeName()
);
- if (thingAttribute == null) {
- LOG.fine("Ignoring update of " + attributeState + ", linked attribute not found in: " + thing);
- return;
- }
- processAttributeStateUpdate(attributeStateUpdateEvent, true);
+ processAssetUpdate(thing, thingAttribute, attributeEvent, true);
});
}
- // TODO: This should be used by client, rules and protocols as the single point of asset attribute state update
- // TODO: How to handle read only attribute updates (if from the protocol then it should be allowed)
- void processAttributeStateUpdate(AttributeStateUpdateEvent attributeStateUpdateEvent, boolean ignoreReadOnlyFlag) {
- AttributeState attributeState = attributeStateUpdateEvent.getAttributeState();
- ServerAsset asset = assetStorageService.find(attributeState.getAttributeRef().getEntityId());
- Attributes attributes = new Attributes(asset.getAttributes());
- String attributeName = attributeState.getAttributeRef().getAttributeName();
- Attribute attribute = attributes.get(attributeName);
+ public void processAssetUpdate(ServerAsset asset,
+ Attribute attribute,
+ AttributeEvent attributeEvent) {
+ processAssetUpdate(asset, attribute, attributeEvent, false);
+ }
+
+ protected void processAssetUpdate(ServerAsset asset,
+ Attribute attribute,
+ AttributeEvent attributeEvent,
+ boolean ignoreReadOnly) {
- // Check the asset has this attribute
+ // Check the asset has this attribute (might also not be present if a Thing's attribute is unlinked)
if (attribute == null) {
- LOG.fine("Ignoring update of " + attributeState + " as asset doesn't have an attribute by this name");
+ LOG.fine("Ignoring " + attributeEvent + ", attribute not available: " + asset);
return;
}
// Check attribute isn't readonly
- if (!ignoreReadOnlyFlag && attribute.firstMetaItem(AssetMeta.READ_ONLY) != null) {
- LOG.fine("Ignoring update of " + attributeState + " as asset attribute is readonly");
- return;
- }
-
- // Hold on to original attributeState so we can use it during processing
- AttributeState originalState = new AttributeState(
- new AttributeRef(asset.getId(), attribute.getName()), attribute.getValue()
- );
-
- // Set new value on attribute, thus validating the value type against the attribute type
- try {
- attribute.setValue(attributeState.getValue());
- } catch (IllegalArgumentException ex) {
- LOG.log(Level.FINE, "Ignoring update of " + attributeState + ", attribute constraint violations in: " + asset, ex);
+ if (!ignoreReadOnly && attribute.isReadOnly()) {
+ LOG.fine("Ignoring " + attributeEvent + ", attribute is read-only in: " + asset);
return;
}
// Ensure timestamp of event is not in the future as that would essentially block access to
// the attribute until after that time (maybe that is desirable behaviour)
// Allow a leniency of 1s
- if (attributeStateUpdateEvent.getTimestamp() - System.currentTimeMillis() > 1000) {
+ if (attributeEvent.getTimestamp() - System.currentTimeMillis() > 1000) {
// TODO: Decide how to handle update events in the future - ignore or change timestamp
- LOG.fine("Ignoring update of " + attributeState + ", update event timestamp is in the future");
+ LOG.fine("Ignoring " + attributeEvent + ", event-time is in the future in:" + asset);
return;
}
- // Check the last update timestamp meta on the attribute and store update timestamp
- Meta meta = attribute.getMeta();
- MetaItem lastUpdateMeta = meta.first(AssetMeta.VALUE_TIMESTAMP);
- if (lastUpdateMeta != null) {
- // Can't use int as timestamp will overflow
- Double lastUpdate = lastUpdateMeta.getValueAsDecimal();
- if (lastUpdate != null) {
- // Check last update is before this update
- if (attributeStateUpdateEvent.getTimestamp() - lastUpdate < 1000) {
- LOG.fine("Ignoring update of " + attributeState + ", update event timestamp is before the attributes last update timestamp");
- return;
- }
- }
- lastUpdateMeta.setValue(Json.create(attributeStateUpdateEvent.getTimestamp()));
+ // Hold on to existing attribute state so we can use it during processing
+ AttributeEvent lastStateEvent = attribute.getStateEvent(asset.getId());
+
+ // Check the last update timestamp of the attribute, ignoring any event that is older than last udpate
+ // TODO: This means we drop out-of-sequence events, we might need better at-least-once handling
+ if (lastStateEvent.getTimestamp() >= 0 && attributeEvent.getTimestamp() - lastStateEvent.getTimestamp() < 1000) {
+ LOG.fine("Ignoring " + attributeEvent + ", event-time is older than attribute's last value in: " + asset);
+ return;
}
- attribute.setMeta(meta);
- // Create and process the attributeState change
- AssetStateChange<ServerAsset> stateChange = new AssetStateChange<>(asset, attribute, originalState);
+ // Set new value and event timestamp on attribute, thus validating any attribute constraints
+ try {
+ attribute.applyStateEvent(attributeEvent);
+ } catch (IllegalArgumentException ex) {
+ LOG.log(Level.FINE, "Ignoring " + attributeEvent + ", attribute constraint violation in: " + asset, ex);
+ return;
+ }
- for (Consumer<AssetStateChange<ServerAsset>> consumer : attributeStateChangeConsumers) {
+ processAssetUpdate(
+ new AssetUpdate(asset, attribute, attributeEvent, lastStateEvent)
+ );
+ }
+
+ protected void processAssetUpdate(AssetUpdate assetUpdate) {
+
+ // Create and process the attributeState change
+ for (Consumer<AssetUpdate> processor : processors) {
try {
- LOG.fine("Consumer " + consumer + " should process: " + stateChange);
- consumer.accept(stateChange);
- LOG.fine("Consumer " + consumer + " completed processing: " + stateChange);
+ LOG.fine("Processor " + processor + " accepts: " + assetUpdate);
+ processor.accept(assetUpdate);
} catch (Throwable t) {
- // All exceptions during processing should end up here
- // TODO Better error handling, not sure we need rewind?
- throw new RuntimeException("Consumer " + consumer + " processing error: " + stateChange, t);
+ assetUpdate.setStatus(AssetUpdate.Status.ERROR);
+ assetUpdate.setError(t);
}
- if (stateChange.getProcessingStatus() == AttributeStateChange.Status.HANDLED) {
- LOG.fine("Consumer " + consumer + " finally handled: " + stateChange);
- break;
+ switch (assetUpdate.getStatus()) {
+ case HANDLED:
+ LOG.fine("Processor " + processor + " finally handled: " + assetUpdate);
+ break;
+ case ERROR:
+ // TODO Better error handling, not sure we need rewind?
+ throw new RuntimeException("Processor " + processor + " error: " + assetUpdate, assetUpdate.getError());
}
}
}
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.java
index 90e6211c7..2aa18494b 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
@@ -20,20 +20,16 @@
package org.openremote.manager.server.asset;
import elemental.json.JsonValue;
-import org.apache.camel.builder.RouteBuilder;
import org.hibernate.Session;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
-import org.openremote.container.message.MessageBrokerSetupService;
-import org.openremote.container.persistence.PersistenceEvent;
import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.web.WebService;
import org.openremote.manager.server.agent.AgentAttributes;
-import org.openremote.manager.server.event.EventService;
import org.openremote.manager.server.security.ManagerIdentityService;
-import org.openremote.manager.shared.asset.SubscribeAssetModified;
-import org.openremote.manager.shared.asset.UnsubscribeAssetModified;
-import org.openremote.model.*;
+import org.openremote.model.AttributeRef;
+import org.openremote.model.Consumer;
+import org.openremote.model.Function;
import org.openremote.model.asset.*;
import org.postgresql.util.PGobject;
@@ -46,21 +42,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
-import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
-import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;
-import static org.openremote.manager.server.event.EventPredicates.isEventType;
import static org.openremote.model.asset.AssetType.AGENT;
-public class AssetStorageService
- extends RouteBuilder
- implements ContainerService, Consumer<AssetStateChange<ServerAsset>> {
+public class AssetStorageService implements ContainerService, Consumer<AssetUpdate> {
private static final Logger LOG = Logger.getLogger(AssetStorageService.class.getName());
- protected EventService eventService;
protected PersistenceService persistenceService;
protected ManagerIdentityService managerIdentityService;
- protected AssetListenerSubscriptions assetListenerSubscriptions;
+
final protected Function<AttributeRef, ProtocolConfiguration> agentLinkResolver = agentLink -> {
// Resolve the agent and the protocol configuration
// TODO This is very inefficient and requires Hibernate second-level caching
@@ -74,20 +64,9 @@ public class AssetStorageService
@Override
public void init(Container container) throws Exception {
- eventService = container.getService(EventService.class);
persistenceService = container.getService(PersistenceService.class);
managerIdentityService = container.getService(ManagerIdentityService.class);
- // TODO None of this is secure or considers the realm of an asset or the logged-in user's realm
- assetListenerSubscriptions = new AssetListenerSubscriptions(eventService) {
- @Override
- protected Asset getAsset(String assetId) {
- return AssetStorageService.this.find(assetId);
- }
- };
-
- container.getService(MessageBrokerSetupService.class).getContext().addRoutes(this);
-
container.getService(WebService.class).getApiSingletons().add(
new AssetResourceImpl(this)
);
@@ -102,37 +81,6 @@ public class AssetStorageService
}
- @Override
- public void configure() throws Exception {
- // TODO None of this is secure or considers the realm of an asset or the logged-in user's realm
- from(EventService.INCOMING_EVENT_QUEUE)
- .filter(isEventType(SubscribeAssetModified.class))
- .process(exchange -> {
- String sessionKey = EventService.getSessionKey(exchange);
- assetListenerSubscriptions.addSubscription(
- sessionKey,
- exchange.getIn().getBody(SubscribeAssetModified.class)
- );
- });
-
- from(EventService.INCOMING_EVENT_QUEUE)
- .filter(isEventType(UnsubscribeAssetModified.class))
- .process(exchange -> {
- String sessionKey = EventService.getSessionKey(exchange);
- assetListenerSubscriptions.removeSubscription(
- sessionKey,
- exchange.getIn().getBody(UnsubscribeAssetModified.class)
- );
- });
-
- from(PERSISTENCE_TOPIC)
- .filter(isPersistenceEventForEntityType(Asset.class))
- .process(exchange -> {
- PersistenceEvent persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class);
- assetListenerSubscriptions.dispatch(persistenceEvent);
- });
- }
-
public Function<AttributeRef, ProtocolConfiguration> getAgentLinkResolver() {
return agentLinkResolver;
}
@@ -363,8 +311,16 @@ public class AssetStorageService
}
@Override
- public void accept(AssetStateChange<ServerAsset> stateChange) {
- if (!storeAttribute(stateChange.getAssetId(), stateChange.getAttribute())) {
+ public void accept(AssetUpdate assetUpdate) {
+ String assetId = assetUpdate.getAsset().getId();
+ String attributeName = assetUpdate.getAttribute().getName();
+ JsonValue value = assetUpdate.getAttribute().getValue();
+ // Some sanity checking, of course the timestamp should never be -1 if we store updated attribute state
+ long timestamp = assetUpdate.getAttribute().getValueTimestamp();
+ String valueTimestamp = Long.toString(
+ timestamp >= 0 ? timestamp : System.currentTimeMillis()
+ );
+ if (!storeAttributeValue(assetId, attributeName, value, valueTimestamp)) {
throw new RuntimeException("Database update failed, no rows updated");
};
}
@@ -397,34 +353,41 @@ public class AssetStorageService
return asset;
}
- protected boolean storeAttribute(String assetId, Attribute attribute) {
+ protected boolean storeAttributeValue(String assetId, String attributeName, JsonValue value, String timestamp) {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.unwrap(Session.class).doReturningWork(connection -> {
- // TODO: Need to push entire attribute update not just value
- String attributeName = attribute.getName();
- JsonValue value = attribute.getValue();
-
String update =
"UPDATE ASSET" +
- " SET ATTRIBUTES = jsonb_set(ATTRIBUTES, ?, ?, TRUE)" +
+ " SET ATTRIBUTES = jsonb_set(jsonb_set(ATTRIBUTES, ?, ?, TRUE), ?, ?, TRUE)" +
" WHERE ID = ? AND ATTRIBUTES -> ? IS NOT NULL";
try (PreparedStatement statement = connection.prepareStatement(update)) {
- Array attributePath = connection.createArrayOf(
+ // Bind the value
+ Array attributeValuePath = connection.createArrayOf(
"text",
new String[]{attributeName, "value"}
);
- statement.setArray(1, attributePath);
-
+ statement.setArray(1, attributeValuePath);
PGobject pgJsonValue = new PGobject();
pgJsonValue.setType("jsonb");
pgJsonValue.setValue(value.toJson());
statement.setObject(2, pgJsonValue);
- statement.setString(3, assetId);
-
- statement.setString(4, attributeName);
+ // Bind the value timestamp
+ Array attributeValueTimestampPath = connection.createArrayOf(
+ "text",
+ new String[]{attributeName, "valueTimestamp"}
+ );
+ statement.setArray(3, attributeValueTimestampPath);
+ PGobject pgJsonValueTimestamp = new PGobject();
+ pgJsonValueTimestamp.setType("jsonb");
+ pgJsonValueTimestamp.setValue(timestamp);
+ statement.setObject(4, pgJsonValueTimestamp);
+
+ // Bind asset ID and attribute name
+ statement.setString(5, assetId);
+ statement.setString(6, attributeName);
int updatedRows = statement.executeUpdate();
LOG.fine("Stored asset '" + assetId + "' attribute '" + attributeName + "' value, affected rows: " + updatedRows);
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetUpdate.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetUpdate.java
new file mode 100644
index 000000000..1c2e947e6
--- /dev/null
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetUpdate.java
@@ -0,0 +1,104 @@
+/*
+ * 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.asset;
+
+import org.openremote.model.Attribute;
+import org.openremote.model.AttributeEvent;
+
+/**
+ * An asset attribute value change that can be handled by a sequence of processors.
+ */
+public class AssetUpdate {
+
+ /**
+ * Processors of updates can change the status to direct further processing.
+ */
+ public enum Status {
+ /**
+ * Processor is happy for update to continue through the system.
+ */
+ CONTINUE,
+
+ /**
+ * Processor has finally handled the update, cancel further processing.
+ */
+ HANDLED,
+
+ /**
+ * Processor encountered an error trying to process the update, cancel further processing and escalate.
+ */
+ ERROR
+ }
+
+ final protected ServerAsset asset;
+ final protected Attribute attribute;
+ final protected AttributeEvent newState;
+ final protected AttributeEvent oldState;
+
+ protected Status status = Status.CONTINUE;
+ protected Throwable error;
+
+ public AssetUpdate(ServerAsset asset, Attribute attribute, AttributeEvent newState, AttributeEvent oldState) {
+ this.asset = asset;
+ this.attribute = attribute;
+ this.newState = newState;
+ this.oldState = oldState;
+ }
+
+ public ServerAsset getAsset() {
+ return asset;
+ }
+
+ public Attribute getAttribute() {
+ return attribute;
+ }
+
+ public AttributeEvent getNewState() {
+ return newState;
+ }
+
+ public AttributeEvent getOldState() {
+ return oldState;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public void setStatus(Status status) {
+ this.status = status;
+ }
+
+ public Throwable getError() {
+ return error;
+ }
+
+ public void setError(Throwable error) {
+ this.error = error;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "newState=" + newState +
+ ", status=" + status +
+ '}';
+ }
+}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
index e4a4e08fa..4a98b5deb 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
@@ -3,9 +3,9 @@ package org.openremote.manager.server.datapoint;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.container.persistence.PersistenceService;
+import org.openremote.manager.server.asset.AssetUpdate;
import org.openremote.manager.server.asset.ServerAsset;
import org.openremote.model.Consumer;
-import org.openremote.model.asset.AssetStateChange;
import org.openremote.model.datapoint.AssetDatapoint;
import java.util.logging.Logger;
@@ -13,8 +13,7 @@ import java.util.logging.Logger;
/**
* Store and retrieve datapoints.
*/
-public class AssetDatapointService
- implements ContainerService, Consumer<AssetStateChange<ServerAsset>> {
+public class AssetDatapointService implements ContainerService, Consumer<AssetUpdate> {
private static final Logger LOG = Logger.getLogger(AssetDatapointService.class.getName());
@@ -34,8 +33,8 @@ public class AssetDatapointService
}
@Override
- public void accept(AssetStateChange<ServerAsset> stateChange) {
- AssetDatapoint assetDatapoint = new AssetDatapoint(stateChange.getNewState(), stateChange.getTimestamp());
+ public void accept(AssetUpdate assetUpdate) {
+ AssetDatapoint assetDatapoint = new AssetDatapoint(assetUpdate.getNewState());
// TODO Persist datapoint
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/event/EventPredicates.java b/manager/server/src/main/java/org/openremote/manager/server/event/EventPredicates.java
deleted file mode 100644
index e6267dd61..000000000
--- a/manager/server/src/main/java/org/openremote/manager/server/event/EventPredicates.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.server.event;
-
-import org.apache.camel.Predicate;
-import org.openremote.manager.shared.event.Event;
-
-public class EventPredicates {
-
- public static <T extends Event> Predicate isEventType(Class<T> eventType) {
- return exchange -> exchange.getIn().getBody() != null
- && eventType.isAssignableFrom(exchange.getIn().getBody().getClass());
- }
-
-}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java b/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java
index 53e819309..021bb7ee2 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/event/EventService.java
@@ -23,11 +23,10 @@ import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
-import org.openremote.container.message.MessageBrokerContext;
import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.message.MessageBrokerSetupService;
import org.openremote.container.web.socket.WebsocketConstants;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
import java.util.logging.Logger;
diff --git a/manager/server/src/main/java/org/openremote/manager/server/event/EventTypeConverters.java b/manager/server/src/main/java/org/openremote/manager/server/event/EventTypeConverters.java
index 223efeda5..74b3b50bb 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/event/EventTypeConverters.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/event/EventTypeConverters.java
@@ -39,12 +39,11 @@
package org.openremote.manager.server.event;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.apache.camel.TypeConverters;
import org.openremote.container.Container;
-import org.openremote.manager.shared.event.Event;
+import org.openremote.model.Event;
import java.util.logging.Logger;
@@ -55,16 +54,12 @@ public class EventTypeConverters implements TypeConverters {
@Converter
public String writeEvent(Event event, Exchange exchange) throws Exception {
LOG.fine("Writing event JSON: " + event);
- return getObjectMapper(exchange).writeValueAsString(event);
+ return Container.JSON.writeValueAsString(event);
}
@Converter
public Event readEvent(String string, Exchange exchange) throws Exception {
LOG.fine("Reading event JSON: " + string);
- return getObjectMapper(exchange).readValue(string, Event.class);
+ return Container.JSON.readValue(string, Event.class);
}
-
- protected static ObjectMapper getObjectMapper(Exchange exchange) {
- Container container = (Container) exchange.getContext().getRegistry().lookupByName(Container.class.getName());
- return container.JSON;
- }}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/AssetRulesService.java b/manager/server/src/main/java/org/openremote/manager/server/rules/AssetRulesService.java
index 3964ef6b5..919e9eef2 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/rules/AssetRulesService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/AssetRulesService.java
@@ -40,11 +40,10 @@ import org.kie.internal.builder.DecisionTableInputType;
import org.kie.internal.builder.KnowledgeBuilderFactory;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
-import org.openremote.manager.server.asset.ServerAsset;
+import org.openremote.manager.server.asset.AssetUpdate;
+import org.openremote.model.AttributeEvent;
import org.openremote.model.AttributeRef;
-import org.openremote.model.AttributeStateChange;
import org.openremote.model.Consumer;
-import org.openremote.model.asset.AssetStateChange;
import java.util.Collection;
import java.util.HashMap;
@@ -52,8 +51,7 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-public class AssetRulesService implements ContainerService,
- Consumer<AssetStateChange<ServerAsset>> {
+public class AssetRulesService implements ContainerService, Consumer<AssetUpdate> {
private static final Logger LOG = Logger.getLogger(AssetRulesService.class.getName());
@@ -151,48 +149,49 @@ public class AssetRulesService implements ContainerService,
}
@Override
- public void accept(AssetStateChange<ServerAsset> stateChange) {
+ public void accept(AssetUpdate assetUpdate) {
if (kb == null) {
if (deployFailed) {
- stateChange.setProcessingStatus(AttributeStateChange.Status.ERROR);
+ throw new IllegalStateException("Knowledge base deployment failed, can't process updates");
} else {
- LOG.fine("No knowledge base configured, skipping processing of: " + stateChange);
- stateChange.setProcessingStatus(AttributeStateChange.Status.CONTINUE);
+ LOG.fine("No knowledge base configured");
+ return;
}
- return;
}
long newFactCount;
+ // TODO: Put the AssetUpdate into a facade so rules can set its status
+
+ AttributeEvent attributeEvent = assetUpdate.getNewState();
+
// If this fact is not in working memory (considering its equals() method)...
- if (!knowledgeSession.getObjects().contains(stateChange)) {
+ if (!knowledgeSession.getObjects().contains(attributeEvent)) {
// ... update or new insert?
boolean isUpdate = true;
- AttributeRef attributeRef = stateChange.getOriginalState().getAttributeRef();
-
// If there already is a fact in working memory for this attribute
- if (attributeFacts.keySet().contains(attributeRef)) {
+ if (attributeFacts.keySet().contains(attributeEvent.getAttributeRef())) {
try {
// ... retract it from working memory ...
- knowledgeSession.delete(attributeFacts.get(attributeRef));
+ knowledgeSession.delete(attributeFacts.get(attributeEvent.getAttributeRef()));
} finally {
// ... and make sure we don't keep a reference to a fact
- attributeFacts.remove(attributeRef);
+ attributeFacts.remove(attributeEvent.getAttributeRef());
}
} else {
isUpdate = false;
}
// Put the fact into working memory and remember the handle
- FactHandle handle = knowledgeSession.insert(stateChange);
- attributeFacts.put(attributeRef, handle);
+ FactHandle handle = knowledgeSession.insert(attributeEvent);
+ attributeFacts.put(attributeEvent.getAttributeRef(), handle);
if (isUpdate) {
- LOG.finest("Inserted: " + stateChange);
+ LOG.finest("Inserted: " + attributeEvent);
} else {
- LOG.finest("Updated: " + stateChange);
+ LOG.finest("Updated: " + attributeEvent);
}
// TODO: Prevent run away fact creation (not sure how we can do this reliably as facts can be generated in rule RHS)
@@ -203,7 +202,7 @@ public class AssetRulesService implements ContainerService,
newFactCount = knowledgeSession.getFactCount();
LOG.finest("New fact count: " + newFactCount);
if (newFactCount != currentFactCount) {
- LOG.finest("Fact count changed from " + currentFactCount + " to " + newFactCount + " on: " + stateChange);
+ LOG.finest("Fact count changed from " + currentFactCount + " to " + newFactCount + " on: " + attributeEvent);
}
currentFactCount = newFactCount;
}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/Agent.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/Agent.java
deleted file mode 100644
index 6f84f9d03..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/Agent.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import elemental.json.Json;
-import org.openremote.manager.shared.connector.Connector;
-import org.openremote.model.Attribute;
-import org.openremote.model.AttributeType;
-import org.openremote.model.Attributes;
-import org.openremote.model.asset.Asset;
-
-import java.util.logging.Logger;
-
-import static org.openremote.manager.shared.connector.Connector.ASSET_ATTRIBUTE_CONNECTOR;
-
-/**
- * Runtime instance of an agent {@link Asset}.
- * <p>
- * This is a message routing table that can be dynamically built from {@link Connector} settings.
- * This information is combined with calls to a {@link org.openremote.manager.shared.connector.ConnectorComponent}
- * when routes and endpoint URIs are established.
- * <p>
- * You can communicate with an agent through events:
- * <ul>
- * <li>{@link RefreshInventoryEvent}</li>
- * <li>{@link SubscribeDeviceResourceUpdates}</li>
- * <li>{@link UnsubscribeDeviceResourceUpdates}</li>
- * <li>{@link DeviceResourceWrite}</li>
- * <li>{@link DeviceResourceRead}</li>
- * <li>{@link DeviceResourceValueEvent}</li>
- * </ul>
- */
-public class Agent {
-
- private static final Logger LOG = Logger.getLogger(Agent.class.getName());
-
-
- final protected Attributes attributes;
-
- public Agent(Attributes attributes) {
- this(attributes, false);
- }
-
- public Agent(Attributes attributes, boolean initialize) {
- this.attributes = attributes;
- if (initialize)
- initialize();
- }
-
- public Attributes getAttributes() {
- return attributes;
- }
-
- public void initialize() {
- setEnabled(false);
- }
-
- public boolean isEnabled() {
- return attributes.hasAttribute("enabled") && attributes.get("enabled").isValueTrue();
- }
-
- public Agent setEnabled(boolean enabled) {
- if (attributes.hasAttribute("enabled")) {
- attributes.get("enabled").setValueAsBoolean(enabled);
- } else {
- attributes.put(new Attribute("enabled", AttributeType.BOOLEAN, Json.create(enabled)));
- }
- return this;
- }
-
- public Attribute getOrCreateConnectorTypeAttribute() {
- if (attributes.hasAttribute(ASSET_ATTRIBUTE_CONNECTOR)) {
- return attributes.get(ASSET_ATTRIBUTE_CONNECTOR);
- } else {
- Attribute attribute = new Attribute(ASSET_ATTRIBUTE_CONNECTOR, AttributeType.STRING);
- attributes.put(attribute);
- return attribute;
- }
- }
-
- public String getConnectorType() {
- return getOrCreateConnectorTypeAttribute().getValueAsString();
- }
-
- public Agent setConnectorType(String connectorType) {
- getOrCreateConnectorTypeAttribute().setValueAsString(connectorType);
- return this;
- }
-
- public Agent removeConnectorType() {
- attributes.remove(ASSET_ATTRIBUTE_CONNECTOR);
- return this;
- }
-
- public Agent removeConnectorSettings(Connector connector) {
- if (connector == null)
- return this;
- for (Attribute setting : connector.getSettings().get()) {
- attributes.remove(setting.getName());
- }
- return this;
- }
-
- public Agent writeConnectorSettings(Connector connector) {
- if (connector == null)
- return this;
- for (Attribute setting : connector.getSettings().get()) {
- Attribute attribute = attributes.get(setting.getName());
- // If the connector setting still has the same type as the agent's attribute, only update metadata
- if (attribute != null && attribute.getType().equals(setting.getType())) {
- attribute.setMeta(setting.getMeta().copy());
- } else {
- // The agent does not have the connector setting or it's now a different type, replace/create attribute
- attribute = new Attribute(setting.getName(), setting.getType());
- attribute.setMeta(setting.getMeta().copy());
- attributes.put(attribute);
- }
- }
- return this;
- }
-
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceRead.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceRead.java
deleted file mode 100644
index 680e68705..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceRead.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.manager.shared.event.Event;
-
-/**
- * Read a device resource value asynchronously, a {@link DeviceResourceValueEvent} will
- * be send by the service.
- */
-public class DeviceResourceRead extends Event {
-
- protected String agentId;
- protected String deviceKey;
- protected String deviceResourceKey;
-
- public DeviceResourceRead() {
- }
-
- public DeviceResourceRead(String agentId, String deviceKey, String deviceResourceKey) {
- this.agentId = agentId;
- this.deviceKey = deviceKey;
- this.deviceResourceKey = deviceResourceKey;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- public String getDeviceResourceKey() {
- return deviceResourceKey;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "agentId='" + agentId + '\'' +
- ", deviceKey='" + deviceKey + '\'' +
- ", deviceResourceKey='" + deviceResourceKey + '\'' +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceValueEvent.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceValueEvent.java
deleted file mode 100644
index 27cb4149f..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceValueEvent.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.manager.shared.event.Event;
-
-public class DeviceResourceValueEvent extends Event {
-
- protected String agentId;
- protected String deviceKey;
- protected String deviceResourceKey;
- protected String value;
-
- public DeviceResourceValueEvent() {
- }
-
- public DeviceResourceValueEvent(String agentId, String deviceKey, String deviceResourceKey, String value) {
- this.agentId = agentId;
- this.deviceKey = deviceKey;
- this.deviceResourceKey = deviceResourceKey;
- this.value = value;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- public String getDeviceResourceKey() {
- return deviceResourceKey;
- }
-
- public String getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "agentId='" + agentId + '\'' +
- ", deviceKey='" + deviceKey + '\'' +
- ", deviceResourceKey='" + deviceResourceKey + '\'' +
- ", value='" + value + '\'' +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceWrite.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceWrite.java
deleted file mode 100644
index 1f580b9fb..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/DeviceResourceWrite.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.manager.shared.event.Event;
-
-/**
- * Write a device resource value, this is a fire-and-forget operation.
- */
-public class DeviceResourceWrite extends Event {
-
- protected String agentId;
- protected String deviceKey;
- protected String deviceResourceKey;
- protected String value;
-
- public DeviceResourceWrite() {
- }
-
- public DeviceResourceWrite(String agentId, String deviceKey, String deviceResourceKey, String value) {
- this.agentId = agentId;
- this.deviceKey = deviceKey;
- this.deviceResourceKey = deviceResourceKey;
- this.value = value;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- public String getDeviceResourceKey() {
- return deviceResourceKey;
- }
-
- public String getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "agentId='" + agentId + '\'' +
- ", deviceKey='" + deviceKey + '\'' +
- ", deviceResourceKey='" + deviceResourceKey + '\'' +
- ", value='" + value + '\'' +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/InventoryModifiedEvent.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/InventoryModifiedEvent.java
deleted file mode 100644
index 1e732452d..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/InventoryModifiedEvent.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.model.asset.Asset;
-import org.openremote.manager.shared.event.Event;
-
-public class InventoryModifiedEvent extends Event {
-
- public enum Cause {
- PUT,
- DELETE,
- }
-
- final protected Asset deviceAsset;
- final protected Cause cause;
-
- public InventoryModifiedEvent(Asset deviceAsset, Cause cause) {
- this.deviceAsset = deviceAsset;
- this.cause = cause;
- }
-
- public Asset getDeviceAsset() {
- return deviceAsset;
- }
-
- public Cause getCause() {
- return cause;
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/RefreshInventoryEvent.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/RefreshInventoryEvent.java
deleted file mode 100644
index 792bc4e9d..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/RefreshInventoryEvent.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.manager.shared.event.Event;
-import org.openremote.model.asset.AssetType;
-
-/**
- * Tell an agent to delete and re-discover all it's child assets (which are
- * {@link AssetType#DEVICE}). You will
- * receive {@link org.openremote.manager.shared.asset.AssetModifiedEvent}s for
- * any detected changes.
- */
-public class RefreshInventoryEvent extends Event {
-
- protected String agentId;
-
- public RefreshInventoryEvent() {
- }
-
- public RefreshInventoryEvent(String agentId) {
- this.agentId = agentId;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- @Override
- public String toString() {
- return "RefreshInventoryEvent{" +
- "agentId='" + agentId + '\'' +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/SubscribeDeviceResourceUpdates.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/SubscribeDeviceResourceUpdates.java
deleted file mode 100644
index 9681d9c1b..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/SubscribeDeviceResourceUpdates.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.manager.shared.event.Event;
-
-/**
- * Tell an agent that you are interested in any state changes to readable device
- * resources of a given device. This registration must be repeated or the service
- * will expire the subscription after 60 seconds. While active, any value changes
- * detected on a device resource will be available through
- * {@link DeviceResourceValueEvent}s.
- */
-public class SubscribeDeviceResourceUpdates extends Event {
-
- protected String agentId;
- protected String deviceKey;
-
- public SubscribeDeviceResourceUpdates() {
- }
-
- public SubscribeDeviceResourceUpdates(String agentId, String deviceKey) {
- this.agentId = agentId;
- this.deviceKey = deviceKey;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() +"{" +
- "agentId='" + agentId + '\'' +
- ", deviceKey='" + deviceKey + '\'' +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/agent/UnsubscribeDeviceResourceUpdates.java b/manager/shared/src/main/java/org/openremote/manager/shared/agent/UnsubscribeDeviceResourceUpdates.java
deleted file mode 100644
index 0562c6cd8..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/agent/UnsubscribeDeviceResourceUpdates.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.agent;
-
-import org.openremote.manager.shared.event.Event;
-
-/**
- * Tell an agent that you are no longer interested in receiving
- * {@link DeviceResourceValueEvent}s for a given device.
- */
-public class UnsubscribeDeviceResourceUpdates extends Event {
-
- protected String agentId;
- protected String deviceKey;
-
- public UnsubscribeDeviceResourceUpdates() {
- }
-
- public UnsubscribeDeviceResourceUpdates(String agentId, String deviceKey) {
- this.agentId = agentId;
- this.deviceKey = deviceKey;
- }
-
- public String getAgentId() {
- return agentId;
- }
-
- public String getDeviceKey() {
- return deviceKey;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() +"{" +
- "assetId='" + agentId + '\'' +
- ", deviceKey='" + deviceKey + '\'' +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetModifiedEvent.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetModifiedEvent.java
deleted file mode 100644
index 83c5b1dc0..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/AssetModifiedEvent.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.asset;
-
-import org.openremote.manager.shared.event.Event;
-import org.openremote.model.asset.Asset;
-import org.openremote.model.asset.AssetInfo;
-
-public class AssetModifiedEvent extends Event {
-
- public enum Cause {
- CREATE,
- UPDATE,
- DELETE,
- CHILDREN_MODIFIED
- }
-
- protected AssetInfo assetInfo;
- protected Cause cause;
-
- public AssetModifiedEvent() {
- }
-
- public AssetModifiedEvent(Asset asset, Cause cause) {
- this(new AssetInfo(asset), cause);
- }
-
- public AssetModifiedEvent(AssetInfo assetInfo, Cause cause) {
- this.assetInfo = assetInfo;
- this.cause = cause;
- }
-
- public AssetInfo getAssetInfo() {
- return assetInfo;
- }
-
- public Cause getCause() {
- return cause;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "assetInfo='" + assetInfo+ '\'' +
- ", cause=" + cause +
- "}";
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/SubscribeAssetModified.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/SubscribeAssetModified.java
deleted file mode 100644
index 436b65932..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/SubscribeAssetModified.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.asset;
-
-import org.openremote.manager.shared.event.Event;
-
-public class SubscribeAssetModified extends Event {
-
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/asset/UnsubscribeAssetModified.java b/manager/shared/src/main/java/org/openremote/manager/shared/asset/UnsubscribeAssetModified.java
deleted file mode 100644
index 1c8e857b1..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/asset/UnsubscribeAssetModified.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.asset;
-
-import org.openremote.manager.shared.event.Event;
-
-public class UnsubscribeAssetModified extends Event {
-
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ChildAssetSupport.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ChildAssetSupport.java
deleted file mode 100644
index 6eccbd239..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ChildAssetSupport.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.connector;
-
-/**
- * Describes the capabilities that an agent connectors's inventory
- * offers; inventory read is mandatory. This is how device provisioning
- * should be achieved.
- */
-public class ChildAssetSupport {
- protected boolean create;
- protected boolean read;
- protected boolean update;
- protected boolean delete;
-
- public ChildAssetSupport(boolean create, boolean read, boolean update, boolean delete) {
- this.create = create;
- this.read = read;
- this.update = update;
- this.delete = delete;
- }
-
- public boolean isCreate() {
- return create;
- }
-
- public boolean isRead() {
- return read;
- }
-
- public boolean isUpdate() {
- return update;
- }
-
- public boolean isDelete() {
- return delete;
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
deleted file mode 100644
index e32f1e1c8..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/Connector.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.openremote.manager.shared.connector;
-
-import org.openremote.model.Attributes;
-
-public class Connector {
-
- public static final String ASSET_ATTRIBUTE_CONNECTOR = "connector";
-
- protected String name;
- protected String type;
- protected boolean supportsInventoryRefresh;
- protected Attributes settings;
-
- public Connector() {
- }
-
- public Connector(String type) {
- this.type = type;
- }
-
- public Connector(String name, String type, boolean supportsInventoryRefresh, Attributes settings) {
- this.name = name;
- this.type = type;
- this.supportsInventoryRefresh = supportsInventoryRefresh;
- this.settings = settings;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public boolean isSupportsInventoryRefresh() {
- return supportsInventoryRefresh;
- }
-
- public void setSupportsInventoryRefresh(boolean supportsInventoryRefresh) {
- this.supportsInventoryRefresh = supportsInventoryRefresh;
- }
-
- public Attributes getSettings() {
- return settings;
- }
-
- public void setSettings(Attributes settings) {
- this.settings = settings;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "name='" + name + '\'' +
- ", type='" + type + '\'' +
- ", settings=" + settings +
- '}';
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java
deleted file mode 100644
index 2d071d9c4..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponent.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.connector;
-
-import org.openremote.manager.shared.agent.Agent;
-import org.openremote.manager.shared.agent.InventoryModifiedEvent;
-import org.openremote.model.Attributes;
-
-import java.util.Collection;
-
-/**
- * Connectors to external systems are implemented as Apache Camel components.
- */
-public interface ConnectorComponent {
-
- String HEADER_DEVICE_KEY = ConnectorComponent.class.getCanonicalName() + ".HEADER_DEVICE_KEY";
- String HEADER_DEVICE_RESOURCE_KEY = ConnectorComponent.class.getCanonicalName() + ".HEADER_DEVICE_RESOURCE_KEY";
-
- enum Capability {
- /**
- * A producer that reacts to empty "trigger discovery" messages and notifies
- * any {@link #inventory} consumers when discovery of devices or device resources
- * resulted in any inventory changes.
- */
- discovery,
-
- /**
- * A producer that reacts to inventory update messages ("assign device", etc.), or
- * a consumer that starts {@link InventoryModifiedEvent} exchanges when device or device
- * resource inventory of this connector has been modified.
- */
- inventory,
-
- /**
- * A producer that can read a device resource value. Device and resource key will
- * be set as headers ({@link #HEADER_DEVICE_KEY}, {@link #HEADER_DEVICE_RESOURCE_KEY}),
- * the value must be returned as the body of the IN message.
- */
- read,
-
- /**
- * A producer that can write a device resource value. Device and resource key will
- * be set as headers ({@link #HEADER_DEVICE_KEY}, {@link #HEADER_DEVICE_RESOURCE_KEY}),
- * the value will be set as the body of the IN message.
- */
- write,
-
- /**
- * A consumer that starts exchanges when a device resource value is modified. The device
- * and resource key must be available as headers ({@link #HEADER_DEVICE_KEY},
- * {@link #HEADER_DEVICE_RESOURCE_KEY}), the resource value as body of the IN message.
- */
- listen
- }
-
- /**
- * Get the unique type descriptor for this connector component
- */
- String getType();
-
- /**
- * Get the friendly display name for this connector component
- */
- String getDisplayName();
-
- /**
- * Get the settings for configuring an {@link Agent} of this component.
- */
- Attributes getConnectorSettings();
-
- /**
- * Consumers supported by this connector.
- */
- Collection<Capability> getConsumerCapabilities();
-
- /**
- * Producers supported by this connector.
- */
- Collection<Capability> getProducerCapabilities();
-
- /**
- * Build a Camel consumer endpoint URI for the given capability and agent configuration. An
- * endpoint URI must be returned if the capability was announced in {@link #getConsumerCapabilities()}.
- * The <code>deviceKey</code> parameter is only available for consumer capability {@link Capability#listen}.
- */
- String buildConsumerEndpoint(Capability capability, String agentAssetId, Agent agent, String deviceKey);
-
- /**
- * Build a Camel producer endpoint URI for the given capability and agent configuration. An
- * endpoint URI must be returned if the capability was announced in {@link #getProducerCapabilities()}.
- */
- String buildProducerEndpoint(Capability capability, String agentAssetId, Agent agent);
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponentNG.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponentNG.java
deleted file mode 100644
index de1a39cb1..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorComponentNG.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.connector;
-
-import org.openremote.model.asset.Asset;
-import org.openremote.model.Attributes;
-
-/**
- * TODO This is a more sophisticated API, we should implement what we can in the Next Generation
- *
- * Connectors to external systems are implemented as Apache Camel components.
- */
-public interface ConnectorComponentNG extends ConnectorComponent {
-
- public static final String HEADER_DISCOVERY_START = ConnectorComponentNG.class.getCanonicalName() + ".HEADER_DISCOVERY_START";
- public static final String HEADER_DISCOVERY_STOP = ConnectorComponentNG.class.getCanonicalName() + ".HEADER_DISCOVERY_STOP";
- public static final String HEADER_INVENTORY_ACTION = ConnectorComponentNG.class.getCanonicalName() + ".HEADER_INVENTORY_ACTION";
- public static final String HEADER_DEVICE_ACTION = ConnectorComponentNG.class.getCanonicalName() + ".HEADER_DEVICE_ACTION";
- public static final String ACTION_CREATE = "CREATE";
- public static final String ACTION_READ = "READ";
- public static final String ACTION_UPDATE = "UPDATE";
- public static final String ACTION_DELETE = "DELETE";
- public static final String ACTION_SUBSCRIBE = "SUBSCRIBE";
- public static final String ACTION_UNSUBSCRIBE = "UNSUBSCRIBE";
- public static final String ACTION_WRITE = "WRITE";
-
- /**
- * Get CRUD support for child assets of the supplied parent asset. A null
- * response indicates that this asset doesn't support child assets (this can
- * also be indicated with the appropriate values in the returned {@link ChildAssetSupport}.
- *
- * If parentAsset is null then response indicates child CRUD support at the
- * root (in connector terms this usually means agent asset CRUD).
- */
- ChildAssetSupport getChildSupport(Asset parentAsset);
-
- /**
- * Indicates whether or not this connector component supports child discovery
- * of the supplied parent asset.
- *
- * If parentAsset is null then response indicates whether child discovery is
- * supported at the root (in connector terms this usually means is agent asset
- * discovery supported).
- */
- boolean supportsChildDiscovery(Asset parentAsset);
-
- /**
- * Get the settings mask for discovering child assets of the supplied
- * parent asset. This is used by clients for user entry of discovery settings.
- *
- * If parentAsset is null then child discovery is being requested at the root
- * (in connector terms this usually means discovering agent assets).
- */
- Attributes getChildDiscoverySettings(Asset parentAsset);
-
- /**
- * Endpoint URI for performing child asset discovery. If implemented
- * when child discovery is required then a route will be created requiring
- * a consumer from this endpoint which should generate messages for any
- * child assets that the connector discovers based on the supplied parent asset
- * and discovery settings.
- *
- * Messages output by the consumer should contain either a single {@link Asset} object or
- * an array of {@link Asset} objects. The outputted assets should have IDs and be linked
- * to their parent(s) thus allowing child discovery to return a hierarchy of assets.
- *
- * Discovery should run as long as this route is running.
- */
- String getChildDiscoveryUri(Asset parentAsset, Attributes discoverySettings);
-
- /**
- * Indicates whether or not this connector component supports monitoring of the supplied
- * asset.
- *
- * If asset monitoring is supported then {@link #getAssetMonitorUri(Asset)} must
- * return the Endpoint URI for the asset monitor.
- */
- boolean supportsMonitoring(Asset asset);
-
- /**
- * Endpoint URI for performing asset CRUD. The capabilities supported by a particular
- * connector for this asset are determined by the response from {@link #getChildSupport(Asset)}.
- *
- * Support for reading devices from the inventory is mandatory, all other capabilities are
- * optional and are agent/connector dependent.
- *
- * The endpoint should support InOut (Request Reply) producers. The action to perform is set
- * by the {@link #HEADER_INVENTORY_ACTION} message header.
- *
- * {@Link #ACTION_CREATE}, {@Link #ACTION_UPDATE}, {@Link #ACTION_DELETE} operations
- * should consume a {@link Asset}[]. In the case of {@link #ACTION_DELETE} then only the
- * asset ID should be required. The reply message body should contain an integer indicating
- * the status of the request (conforming to the HTTP Status code specification).
- *
- * {@link #ACTION_READ} operations should consume a {@link Asset}[] where only the ID should
- * be required, if no assets are supplied then all child assets should be returned.
- * The reply message body should contain a {@link Asset}[] of the requested devices.
- *
- */
- String getChildInventoryUri(Asset asset);
-
- /**
- * Endpoint URI for: -
- * Reading/Writing from/to assets
- * Subscribing/Un-subscribing to asset changes
- *
- * This endpoint is expected to support the InOut MEP with the
- * {@link #HEADER_DEVICE_ACTION} message header indicating the action to
- * perform/data to return on messages to be consumed by this endpoint.
- *
- * {@link #ACTION_SUBSCRIBE}, {@link #ACTION_UNSUBSCRIBE} operations should consume a
- * {@link Asset}[] where only the ID(s) should be required. The reply message body
- * should contain an integer indicating the status of the request (conforming to the HTTP
- * Status code specification). Connectors that support asset subscriptions must return
- * a valid endpoint URI from {@link #getAssetMonitorUri(Asset)}.
- *
- * Assets of a connector can share an endpoint which is indicated by returning the same
- * endpoint URI.
- */
- String getAssetUri(Asset asset);
-
- /**
- * Endpoint URI for consuming asset changes as reported by the connector.
- *
- * A subscribed asset should be monitored by the connector for any resource value
- * changes; these changes should then be output in a message body as {@link Asset}[]
- * containing the modified attributes.
- *
- * If not supported then just return null.
- */
- String getAssetMonitorUri(Asset asset);
-
- /**
- * Generate the asset represented by the supplied asset settings, the connector is responsible
- * for setting the asset ID and asset type as well as any attributes and metadata that are required.
- */
- Asset createAsset(Asset parent, Attributes assetSettings);
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.java
deleted file mode 100644
index 9e161dd42..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorResource.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.connector;
-
-import jsinterop.annotations.JsType;
-import org.openremote.manager.shared.http.RequestParams;
-import org.openremote.manager.shared.http.SuccessStatusCode;
-
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-
-@Path("connector")
-@JsType(isNative = true)
-public interface ConnectorResource {
-
- @GET
- @Produces(APPLICATION_JSON)
- @SuccessStatusCode(200)
- // TODO Implement admin roles on server
- //@RolesAllowed({"read:admin"})
- Connector[] getConnectors(@BeanParam RequestParams requestParams);
-
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java b/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java
deleted file mode 100644
index ab0f4f65a..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/connector/ConnectorUtil.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.connector;
-
-
-import org.openremote.model.Attribute;
-import org.openremote.model.AttributeType;
-
-public class ConnectorUtil {
- protected ConnectorUtil() {}
-
- public static Attribute buildConnectorSetting(String attributeName, AttributeType type, String displayName, String description, boolean required) {
- return buildConnectorSetting(attributeName, type, displayName, description, required, null, null);
- }
-
- public static Attribute buildConnectorSetting(String attributeName, AttributeType type, String displayName, String description, boolean required, String defaultValue, String defaultValueNote) {
- Attribute attribute = new Attribute(attributeName, type);
- /*
- attribute.setMetadata(new Metadata(Json.createObject()));
-
- if (displayName != null && displayName.length() > 0) {
- attribute.getMetadata().putElement(
- new MetadataElement("label", Json.createObject())
- .setType(AttributeType.STRING.getValue())
- .setValue(Json.create(displayName))
- );
- }
-
- if (description != null && description.length() > 0) {
- attribute.getMetadata().putElement(
- new MetadataElement("description", Json.createObject())
- .setType(AttributeType.STRING.getValue())
- .setValue(Json.create(description))
- );
- }
-
- if (defaultValue != null && defaultValue.length() > 0) {
- attribute.getMetadata().putElement(
- new MetadataElement("defaultValue", Json.createObject())
- .setType(type.getValue())
- .setValue(Json.create(defaultValue))
- );
- }
-
- if (defaultValueNote != null && defaultValueNote.length() > 0) {
- attribute.getMetadata().putElement(
- new MetadataElement("defaultValueNote", Json.createObject())
- .setType(AttributeType.STRING.getValue())
- .setValue(Json.create(defaultValueNote))
- );
- }
-
- if (required) {
- attribute.getMetadata().putElement(
- new MetadataElement("required", Json.createObject())
- .setType(AttributeType.BOOLEAN.getValue())
- .setValue(Json.create(true))
- );
- }
- */
-
- return attribute;
- }
-
-// /**
-// * Will synchronise the stored agent settings with the supplied connector. Existing agent settings
-// * that match a connector setting will be preserved.
-// */
-// public static void synchroniseAgentSettings(Agent agent, Connector connector) {
-// Attributes connectorSettings = connector.getAgentSettings();
-//
-// if (connectorSettings == null) {
-// agent.setConnectorSettings(null);
-// return;
-// }
-//
-// Attributes agentSettings = new Attributes(agent.getConnectorSettings());
-// Attributes newSettings = new Attributes();
-//
-// for (Attribute attribute : connectorSettings.get()) {
-// Attribute existingAttribute = agentSettings.get(attribute.getName());
-//
-// if (existingAttribute != null && existingAttribute.getType().equals(attribute.getType())) {
-// newSettings.add(existingAttribute);
-// } else {
-// Attribute newAttribute = createSettingAttribute(attribute);
-// if (newAttribute != null) {
-// newSettings.add(newAttribute);
-// }
-// }
-// }
-//
-// agent.setConnectorSettings(newSettings.getJsonObject());
-// }
-//
-// protected static Attribute createSettingAttribute(Attribute connectorAttribute) {
-// Metadata metadata = connectorAttribute.getMetadata();
-// if (!metadata.hasElement("required")) {
-// return null;
-// }
-//
-// JsonValue value = Json.createNull();
-//
-// if (metadata.hasElement("defaultValue")) {
-// value = metadata.getElement("defaultValue").getValue();
-// }
-//
-// return new Attribute(connectorAttribute.getName(), connectorAttribute.getType(), value);
-// }
-
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceAttributes.java b/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceAttributes.java
deleted file mode 100644
index 8326614ad..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/device/DeviceAttributes.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.device;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreType;
-import elemental.json.Json;
-import elemental.json.JsonObject;
-import org.openremote.model.Attribute;
-import org.openremote.model.AttributeType;
-import org.openremote.model.Attributes;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Device asset attribute handling for representing devices that come from agents.
- * <p>
- * A device asset requires a key (typically unique within the scope of the
- * {@link org.openremote.manager.shared.connector.ConnectorComponent}) and
- * zero or many device resources (which also have a key, typically unique
- * within the scope of the device). Both keys are used when an agent builds
- * messaging routes which integrate the connector component. Semantics and scope
- * of the keys are defined by each connector component and can be internal to
- * the connector component.
- * <p>
- * The resources define the functionality of the device and provide access
- * for each item of functionality.
- * <p>
- * TODO: The capabilities allow a device to expose defined device and device resource
- * metadata. A capability such as <em>LightControl</em> would be 'well-known'
- * by software that wants to control lighting. Capabilities provide contextual
- * information for UI and mapping purposes.
- * <p>
- * TODO: Implement resource refs
- */
-@JsonIgnoreType // TODO This must be enabled (and fixed before it's usable) if any of serialized classes uses this type
-public class DeviceAttributes extends Attributes {
-
- protected static final String KEY = "key";
-
- public static boolean isReadOnly(Attribute attribute) {
- return attribute.getName().equals(KEY);
- }
-
- public DeviceAttributes() {
- super();
- }
-
- public DeviceAttributes(JsonObject jsonObject) {
- super(jsonObject);
- }
-
- public String getKey() {
- return hasAttribute(KEY) ? get(KEY).getValueAsString() : null;
- }
-
- public void setKey(String key) {
- put(new Attribute(KEY, AttributeType.STRING, Json.create(key)));
- }
-
- public DeviceResource[] getDeviceResources() {
- Attribute[] attributes = super.get();
- List<DeviceResource> list = new ArrayList<>();
- for (Attribute attribute : attributes) {
- if (DeviceResource.isDeviceResource(attribute)) {
- list.add(new DeviceResource(attribute));
- }
- }
- return list.toArray(new DeviceResource[list.size()]);
- }
-
- public DeviceResource getDeviceResource(String name) {
- Attribute attribute = super.get(name);
- if (attribute == null || !DeviceResource.isDeviceResource(attribute))
- return null;
- return new DeviceResource(attribute);
- }
-
-
- /* TODO Implement capabilities, distinguish from device resources with attribute metadata
- public CapabilityRef[] getCapabilities() {
- if (!hasAttribute(RESOURCES))
- return null;
-
- JsonArray capabilitiesArr = get(CAPABILITIES).getValueAsArray();
- CapabilityRef[] capabilities = new CapabilityRef[capabilitiesArr.length()];
-
- for (int i = 0; i < capabilitiesArr.length(); i++) {
- JsonObject capabilityObj = capabilitiesArr.getObject(i);
- capabilities[i] = new CapabilityRef(capabilityObj);
- }
-
- return capabilities;
- }
-
- public void setCapabilities(CapabilityRef... capabilities) {
- if (capabilities == null || capabilities.length == 0) {
- remove(CAPABILITIES);
- return;
- }
-
- JsonArray capabilitiesArr = Json.createArray();
-
- for (int i = 0; i < capabilities.length; i++) {
- capabilitiesArr.set(i, Json.parse(capabilities[i].toString()));
- }
-
- put(new Attribute(CAPABILITIES, AttributeType.OBJECT_ARRAY, capabilitiesArr));
- }
- */
-}
\ No newline at end of file
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/Event.java b/manager/shared/src/main/java/org/openremote/manager/shared/event/Event.java
deleted file mode 100644
index 54197e0db..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/Event.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.event;
-
-import com.fasterxml.jackson.annotation.*;
-import org.openremote.manager.shared.agent.*;
-import org.openremote.manager.shared.asset.AssetModifiedEvent;
-import org.openremote.manager.shared.asset.SubscribeAssetModified;
-import org.openremote.manager.shared.asset.UnsubscribeAssetModified;
-import org.openremote.manager.shared.event.asset.AttributeStateUpdateEvent;
-import org.openremote.manager.shared.util.Util;
-
-@JsonSubTypes({
- // Events used on client and server (serialized on client/server bus)
- @JsonSubTypes.Type(value = Message.class, name = "MESSAGE"),
- @JsonSubTypes.Type(value = SubscribeAssetModified.class, name = "SUBSCRIBE_ASSET_CHANGES"),
- @JsonSubTypes.Type(value = UnsubscribeAssetModified.class, name = "UNSUBSCRIBE_ASSET_CHANGES"),
- @JsonSubTypes.Type(value = AssetModifiedEvent.class, name = "ASSET_MODIFIED"),
- @JsonSubTypes.Type(value = AttributeStateUpdateEvent.class, name = "ATTRIBUTE_STATE_UPDATE"),
- @JsonSubTypes.Type(value = RefreshInventoryEvent.class, name = "REFRESH_INVENTORY"),
- @JsonSubTypes.Type(value = SubscribeDeviceResourceUpdates.class, name = "SUBSCRIBE_DEVICE_RESOURCE_UPDATES"),
- @JsonSubTypes.Type(value = UnsubscribeDeviceResourceUpdates.class, name = "UNSUBSCRIBE_DEVICE_RESOURCE_UPDATES"),
- @JsonSubTypes.Type(value = DeviceResourceValueEvent.class, name = "DEVICE_RESOURCE_UPDATED"),
- @JsonSubTypes.Type(value = DeviceResourceRead.class, name = "DEVICE_RESOURCE_READ"),
- @JsonSubTypes.Type(value = DeviceResourceWrite.class, name = "DEVICE_RESOURCE_WRITE"),
- /*
- @JsonSubTypes.Type(value = FlowDeployEvent.class, name = "FLOW_DEPLOY"),
- @JsonSubTypes.Type(value = FlowDeploymentFailureEvent.class, name = "FLOW_DEPLOYMENT_FAILURE"),
- @JsonSubTypes.Type(value = FlowRuntimeFailureEvent.class, name = "FLOW_RUNTIME_FAILURE"),
- @JsonSubTypes.Type(value = FlowRequestStatusEvent.class, name = "FLOW_REQUEST_STATUS"),
- @JsonSubTypes.Type(value = FlowStatusEvent.class, name = "FLOW_STATUS"),
- @JsonSubTypes.Type(value = FlowStopEvent.class, name = "FLOW_STOP"),
- @JsonSubTypes.Type(value = InventoryDevicesUpdatedEvent.class, name = "INVENTORY_DEVICES_UPDATED"),
- // Events used only on client (serialized on console/native shell bus)
- @JsonSubTypes.Type(value = ConsoleEditModeEvent.class, name = "CONSOLE_EDIT_MODE"),
- @JsonSubTypes.Type(value = ConsoleLoopDetectedEvent.class, name = "CONSOLE_LOOP_DETECTED"),
- @JsonSubTypes.Type(value = ConsoleRefreshedEvent.class, name = "CONSOLE_REFRESHED"),
- @JsonSubTypes.Type(value = ConsoleRefreshEvent.class, name = "CONSOLE_REFRESH"),
- @JsonSubTypes.Type(value = ConsoleWidgetModifiedEvent.class, name = "CONSOLE_WIDGET_MODIFIED"),
- @JsonSubTypes.Type(value = ConsoleZoomEvent.class, name = "CONSOLE_ZOOM"),
- @JsonSubTypes.Type(value = MessageReceivedEvent.class, name = "MESSAGE_RECEIVED"),
- @JsonSubTypes.Type(value = MessageSendEvent.class, name = "MESSAGE_SEND"),
- @JsonSubTypes.Type(value = NodeCreateEvent.class, name = "NODE_CREATE"),
- @JsonSubTypes.Type(value = NodeSelectedEvent.class, name = "NODE_SELECTED"),
- @JsonSubTypes.Type(value = ShellCloseEvent.class, name = "SHELL_CLOSE"),
- @JsonSubTypes.Type(value = ShellOpenEvent.class, name = "SHELL_OPEN"),
- @JsonSubTypes.Type(value = ShellReadyEvent.class, name = "SHELL_READY"),
- @JsonSubTypes.Type(value = ShowFailureEvent.class, name = "SHOW_FAILURE"),
- @JsonSubTypes.Type(value = ShowInfoEvent.class, name = "SHOW_INFO"),
- @JsonSubTypes.Type(value = SubflowNodeCreateEvent.class, name = "SUBFLOW_NODE_CREATE")
- */
-})
-@JsonTypeInfo(
- use = JsonTypeInfo.Id.NAME,
- include = JsonTypeInfo.As.PROPERTY,
- property = "event"
-)
-@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
-// TODO The GWT jackson integration sometimes tries to pick up ALL subclasses when serialization generators are produced, use @JsonIgnoreType on them
-public abstract class Event {
- @JsonProperty
- protected long timestamp;
-
- protected Event(long timestamp) {
- this.timestamp = timestamp;
- }
-
- protected Event() {
- timestamp = System.currentTimeMillis();
- }
-
- // This is compatible with the Polymer event naming, so events can be used in JS/Polymer components
- public static String getType(String simpleClassName) {
- String type = Util.toLowerCaseDash(simpleClassName);
- if (type.length() > 6 && type.substring(type.length() - 6).equals("-event"))
- type = type.substring(0, type.length() - 6);
- return type;
- }
-
- public static String getType(Class<? extends Event> actionClass) {
- return getType(actionClass.getSimpleName());
- }
-
- public String getType() {
- return getType(getClass());
- }
-
- @JsonIgnore
- public long getTimestamp() {
- return timestamp;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/Message.java b/manager/shared/src/main/java/org/openremote/manager/shared/event/Message.java
deleted file mode 100644
index bc53703c8..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/Message.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.event;
-
-import java.util.Map;
-
-public class Message extends Event {
-
- public Map<String, Object> headers;
- public String body;
-
- public Message() {
- }
-
- public Message(Map<String, Object> headers, String body) {
- this.headers = headers;
- this.body = body;
- }
-
- public Message(String body) {
- this.body = body;
- }
-
- public Map<String, Object> getHeaders() {
- return headers;
- }
-
- public void setHeaders(Map<String, Object> headers) {
- this.headers = headers;
- }
-
- public boolean hasHeaders() {
- return getHeaders() != null;
- }
-
- public String getBody() {
- return body;
- }
-
- public void setBody(String body) {
- this.body = body;
- }
-
- @Override
- public String toString() {
- return "Message{" +
- "headers=" + headers +
- ", body='" + body + '\'' +
- '}';
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/event/asset/AttributeStateUpdateEvent.java b/manager/shared/src/main/java/org/openremote/manager/shared/event/asset/AttributeStateUpdateEvent.java
deleted file mode 100644
index 6386ce7cf..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/event/asset/AttributeStateUpdateEvent.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.shared.event.asset;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreType;
-import org.openremote.manager.shared.event.Event;
-import org.openremote.model.AttributeState;
-
-@JsonIgnoreType
-public class AttributeStateUpdateEvent extends Event {
- protected AttributeState attributeState;
-
- public AttributeStateUpdateEvent(AttributeState attributeState) {
- this.attributeState = attributeState;
- }
-
- public AttributeStateUpdateEvent(AttributeState attributeState, long timestamp) {
- super(timestamp);
- this.attributeState = attributeState;
- }
-
- public AttributeState getAttributeState() {
- return attributeState;
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/gateway/Gateway.java b/manager/shared/src/main/java/org/openremote/manager/shared/gateway/Gateway.java
deleted file mode 100644
index 6d0862913..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/gateway/Gateway.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.openremote.manager.shared.gateway;
-
-public class Gateway {
- protected String name;
- protected String description;
- protected String type;
- protected String endpointUri;
- protected boolean isAvailable;
- protected boolean isEnabled;
- protected boolean isRunning;
- protected String authToken;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getEndpointUri() {
- return endpointUri;
- }
-
- public void setEndpointUri(String endpointUri) {
- this.endpointUri = endpointUri;
- }
-
- public boolean isAvailable() {
- return isAvailable;
- }
-
- public void setAvailable(boolean available) {
- isAvailable = available;
- }
-
- public boolean isEnabled() {
- return isEnabled;
- }
-
- public void setEnabled(boolean enabled) {
- isEnabled = enabled;
- }
-
- public boolean isRunning() {
- return isRunning;
- }
-
- public void setRunning(boolean running) {
- isRunning = running;
- }
-
- public String getAuthToken() {
- return authToken;
- }
-
- public void setAuthToken(String authToken) {
- this.authToken = authToken;
- }
-}
diff --git a/manager/shared/src/main/java/org/openremote/manager/shared/util/Util.java b/manager/shared/src/main/java/org/openremote/manager/shared/util/Util.java
deleted file mode 100644
index 22eb0bb08..000000000
--- a/manager/shared/src/main/java/org/openremote/manager/shared/util/Util.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2016, OpenRemote Inc.
- *
- * See the CONTRIBUTORS.txt file in the distribution for a
- * full listing of individual contributors.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.openremote.manager.shared.util;
-
-import java.util.*;
-
-public class Util {
-
- public static String toLowerCaseDash(String camelCase) {
- // Transforms 'EXFooBar123' into 'ex-foo-bar-123 and "attributeX" into "attribute-x" without regex (GWT!)
- if (camelCase == null)
- return null;
- if (camelCase.length() == 0)
- return camelCase;
- StringBuilder sb = new StringBuilder();
- char[] chars = camelCase.toCharArray();
- boolean inNonLowerCase = false;
- for (int i = 0; i < chars.length; i++) {
- char c = chars[i];
- if (!Character.isLowerCase(c)) {
- if (!inNonLowerCase) {
- if (i > 0)
- sb.append("-");
- } else if (i < chars.length -1 && Character.isLowerCase(chars[i+1])) {
- sb.append("-");
- }
- inNonLowerCase = true;
- } else {
- inNonLowerCase = false;
- }
- sb.append(c);
- }
- String name = sb.toString();
- name = name.toLowerCase(Locale.ROOT);
- return name;
- }
-
- /**
- * Get an enum value from a string without throwing exception.
- * Enum should be in uppercase to use this method.
- *
- * @param c
- * @param string
- * @return
- */
- public static <T extends Enum<T>> T getEnumFromString(Class<T> c, String string) {
- if (c != null && string != null) {
- try {
- return Enum.valueOf(c, string.trim().toUpperCase());
- } catch (IllegalArgumentException ex) {
- }
- }
- return null;
- }
-
- public static String toCommaSeparated(String... strings) {
- if (strings == null || strings.length == 0)
- return null;
- StringBuilder sb = new StringBuilder();
- for (String s : strings) {
- sb.append(s).append(",");
- }
- if (sb.length() > 0) {
- sb.deleteCharAt(sb.length()-1);
- }
- return sb.toString();
- }
-
- public static String[] fromCommaSeparated(String commaWords) {
- if (commaWords == null)
- return new String[0];
- return commaWords.split(",");
- }
-
- public static <K, V> void sortMap(LinkedHashMap<K, V> map, Comparator<? super V> c) {
- List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet());
- Collections.sort(entries, (lhs, rhs) -> c.compare(lhs.getValue(), rhs.getValue()));
- map.clear();
- for(Map.Entry<K, V> e : entries) {
- map.put(e.getKey(), e.getValue());
- }
- }
-
-}
diff --git a/manager/test/src/main/groovy/org/openremote/test/EventBusWebsocketEndpoint.groovy b/manager/test/src/main/groovy/org/openremote/test/EventBusWebsocketEndpoint.groovy
index 3edcc8b9c..8bdfe68ef 100644
--- a/manager/test/src/main/groovy/org/openremote/test/EventBusWebsocketEndpoint.groovy
+++ b/manager/test/src/main/groovy/org/openremote/test/EventBusWebsocketEndpoint.groovy
@@ -20,11 +20,10 @@
package org.openremote.test
import com.fasterxml.jackson.databind.ObjectMapper
-import org.openremote.manager.client.event.MessageReceivedEvent
-import org.openremote.manager.client.event.ServerSendEvent
+
+import org.openremote.manager.client.event.session.ServerSendEvent
import org.openremote.manager.client.event.bus.EventBus
-import org.openremote.manager.shared.event.Event
-import org.openremote.manager.shared.event.Message
+import org.openremote.model.Event
import javax.websocket.CloseReason
import javax.websocket.Endpoint
@@ -59,12 +58,7 @@ class EventBusWebsocketEndpoint extends Endpoint {
@Override
void onMessage(String data) {
Event event = eventMapper.readValue(data, Event.class);
- if (event.getType().equals(Event.getType(Message.class))) {
- Message message = (Message) event;
- eventBus.dispatch(new MessageReceivedEvent(message));
- } else {
- eventBus.dispatch(event);
- }
+ eventBus.dispatch(event);
}
}
}
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.groovy
index 14bb1d3a6..dfc473d58 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
@@ -21,9 +21,9 @@ import org.openremote.manager.client.service.EventService
import org.openremote.manager.client.service.RequestServiceImpl
import org.openremote.manager.client.service.SecurityService
import org.openremote.manager.client.style.WidgetStyle
-import org.openremote.manager.shared.event.Event
-import org.openremote.manager.shared.event.ui.ShowFailureEvent
-import org.openremote.manager.shared.event.ui.ShowInfoEvent
+import org.openremote.model.Event
+import org.openremote.manager.client.event.ShowFailureEvent
+import org.openremote.manager.client.event.ShowInfoEvent
import org.openremote.manager.shared.http.EntityReader
import org.openremote.manager.shared.security.Tenant
import org.openremote.manager.shared.security.TenantResource
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.groovy
index 26f6ef367..0f13968ea 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
@@ -19,8 +19,8 @@ import org.openremote.manager.client.service.EventService
import org.openremote.manager.client.service.RequestServiceImpl
import org.openremote.manager.client.service.SecurityService
import org.openremote.manager.client.style.WidgetStyle
-import org.openremote.manager.shared.event.Event
-import org.openremote.manager.shared.event.ui.ShowInfoEvent
+import org.openremote.model.Event
+import org.openremote.manager.client.event.ShowInfoEvent
import org.openremote.manager.shared.http.EntityReader
import org.openremote.manager.shared.security.*
import org.openremote.manager.shared.validation.ConstraintViolationReport
diff --git a/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy
index 506ce83f1..99a3555f8 100644
--- a/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/agent/AgentDeploymentTest.groovy
@@ -6,10 +6,9 @@ import elemental.json.JsonType
import org.openremote.agent3.protocol.simulator.SimulatorProtocol
import org.openremote.container.message.MessageBrokerService
import org.openremote.manager.server.asset.AssetStorageService
-import org.openremote.manager.server.setup.builtin.ManagerDemoSetup
import org.openremote.manager.server.setup.SetupService
-import org.openremote.model.AttributeRef
-import org.openremote.model.AttributeState
+import org.openremote.manager.server.setup.builtin.ManagerDemoSetup
+import org.openremote.model.AttributeEvent
import org.openremote.model.Attributes
import org.openremote.model.units.ColorRGB
import org.openremote.test.ManagerContainerTrait
@@ -68,8 +67,8 @@ class AgentDeploymentTest extends Specification implements ManagerContainerTrait
4c. Should "forceUpdate" be the default behavior?
*/
- def light1DimmerChange = new AttributeState(
- new AttributeRef(managerDemoSetup.thingId, "light1Dimmer"), Json.create(66)
+ def light1DimmerChange = new AttributeEvent(
+ managerDemoSetup.thingId, "light1Dimmer", Json.create(66)
)
container.getService(MessageBrokerService.class).getProducerTemplate().sendBody(
ACTUATOR_TOPIC, light1DimmerChange
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy
index c7e47a121..033315d7d 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy
@@ -8,8 +8,7 @@ import org.openremote.container.message.MessageBrokerService
import org.openremote.manager.server.asset.AssetStorageService
import org.openremote.manager.server.setup.SetupService
import org.openremote.manager.server.setup.builtin.ManagerDemoSetup
-import org.openremote.model.AttributeRef
-import org.openremote.model.AttributeState
+import org.openremote.model.AttributeEvent
import org.openremote.model.Attributes
import org.openremote.model.units.ColorRGB
import org.openremote.test.ManagerContainerTrait
@@ -68,8 +67,8 @@ class RulesDeploymentTest extends Specification implements ManagerContainerTrait
4c. Should "forceUpdate" be the default behavior?
*/
- def light1DimmerChange = new AttributeState(
- new AttributeRef(managerDemoSetup.thingId, "light1Dimmer"), Json.create(66)
+ def light1DimmerChange = new AttributeEvent(
+ managerDemoSetup.thingId, "light1Dimmer", Json.create(66)
)
container.getService(MessageBrokerService.class).getProducerTemplate().sendBody(
ACTUATOR_TOPIC, light1DimmerChange
diff --git a/model/src/main/java/org/openremote/model/AbstractValueHolder.java b/model/src/main/java/org/openremote/model/AbstractValueHolder.java
index 028067638..0fce828dd 100644
--- a/model/src/main/java/org/openremote/model/AbstractValueHolder.java
+++ b/model/src/main/java/org/openremote/model/AbstractValueHolder.java
@@ -27,6 +27,8 @@ import elemental.json.*;
* {@link JsonValue}.
*/
public abstract class AbstractValueHolder<T extends AbstractValueHolder> {
+
+ protected static final String VALUE_FIELD_NAME = "value";
final protected JsonObject jsonObject;
@@ -35,7 +37,7 @@ public abstract class AbstractValueHolder<T extends AbstractValueHolder> {
}
public boolean hasValue() {
- return jsonObject.hasKey("value") && jsonObject.get("value").getType() != JsonType.NULL;
+ return jsonObject.hasKey(VALUE_FIELD_NAME) && jsonObject.get(VALUE_FIELD_NAME).getType() != JsonType.NULL;
}
public String getValueAsString() {
@@ -53,15 +55,15 @@ public abstract class AbstractValueHolder<T extends AbstractValueHolder> {
public Boolean getValueAsBoolean() {
// TODO This is also broken somehow...
// return hasValue() ? getValue_TODO_BUG_IN_JAVASCRIPT().asBoolean() : null;
- return hasValue() ? jsonObject.getBoolean("value") : null;
+ return hasValue() ? jsonObject.getBoolean(VALUE_FIELD_NAME) : null;
}
public JsonObject getValueAsObject() {
- return hasValue() ? jsonObject.getObject("value") : null;
+ return hasValue() ? jsonObject.getObject(VALUE_FIELD_NAME) : null;
}
public JsonArray getValueAsArray() {
- return hasValue() ? jsonObject.getArray("value") : null;
+ return hasValue() ? jsonObject.getArray(VALUE_FIELD_NAME) : null;
}
public boolean isValueTrue() {
@@ -73,7 +75,7 @@ public abstract class AbstractValueHolder<T extends AbstractValueHolder> {
}
public void clearValue() {
- jsonObject.remove("value");
+ jsonObject.remove(VALUE_FIELD_NAME);
}
public T setValueAsString(String value) {
@@ -106,7 +108,7 @@ public abstract class AbstractValueHolder<T extends AbstractValueHolder> {
* TODO https://github.com/gwtproject/gwt/issues/9484
*/
public JsonValue getValue() {
- return hasValue() ? jsonObject.get("value") : Json.createNull();
+ return hasValue() ? jsonObject.get(VALUE_FIELD_NAME) : Json.createNull();
}
/**
@@ -128,7 +130,7 @@ public abstract class AbstractValueHolder<T extends AbstractValueHolder> {
throw new IllegalArgumentException("Invalid value of type " + typeString + ": " + valueString);
}
- jsonObject.put("value", value);
+ jsonObject.put(VALUE_FIELD_NAME, value);
return (T) this;
}
diff --git a/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.java b/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.java
new file mode 100644
index 000000000..d0a9717be
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.java
@@ -0,0 +1,92 @@
+/*
+ * 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.model;
+
+import elemental.json.*;
+
+/**
+ * Base class for all model classes which have to internally store data in a
+ * {@link JsonObject} that has a <code>value</code> field that accepts any
+ * {@link JsonValue} and a <code>valueTimestamp</code> Unix timestamp field of
+ * the most recent value change.
+ */
+public abstract class AbstractValueTimestampHolder<T extends AbstractValueTimestampHolder> extends AbstractValueHolder<T> {
+
+ protected static final String VALUE_TIMESTAMP_FIELD_NAME = "valueTimestamp";
+
+ public AbstractValueTimestampHolder(JsonObject jsonObject) {
+ super(jsonObject);
+ }
+
+ public boolean hasValueTimestamp() {
+ return jsonObject.hasKey(VALUE_TIMESTAMP_FIELD_NAME) && jsonObject.get(VALUE_TIMESTAMP_FIELD_NAME).getType() != JsonType.NULL;
+ }
+
+ /**
+ * @return <code>-1</code> if there is no timestamp.
+ */
+ public long getValueTimestamp() {
+ return hasValueTimestamp() ? new Double(jsonObject.get(VALUE_TIMESTAMP_FIELD_NAME).asNumber()).longValue() : -1;
+ }
+
+ /**
+ * Sets the value timestamp to current system time.
+ */
+ public T setValueTimestamp() {
+ return setValueTimestamp(System.currentTimeMillis());
+ }
+
+ /**
+ * Sets the value timestamp to given time.
+ */
+ @SuppressWarnings("unchecked")
+ public T setValueTimestamp(long timestamp) {
+ jsonObject.put(VALUE_TIMESTAMP_FIELD_NAME, Json.create(timestamp));
+ return (T) this;
+ }
+
+ /**
+ * Removes the value and sets the timestamp to current system time.
+ */
+ @Override
+ public void clearValue() {
+ super.clearValue();
+ setValueTimestamp();
+ }
+
+ /**
+ * Sets the value and the timestamp to given time.
+ */
+ public T setValue(JsonValue value, long timestamp) throws IllegalArgumentException {
+ T result = setValue(value);
+ setValueTimestamp(timestamp);
+ return result;
+ }
+
+ /**
+ * Sets the value and the timestamp to current system time.
+ */
+ @Override
+ public T setValue(JsonValue value) throws IllegalArgumentException {
+ T result = super.setValue(value);
+ setValueTimestamp();
+ return result;
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/Attribute.java b/model/src/main/java/org/openremote/model/Attribute.java
index b806c2a55..503178e6f 100644
--- a/model/src/main/java/org/openremote/model/Attribute.java
+++ b/model/src/main/java/org/openremote/model/Attribute.java
@@ -19,17 +19,22 @@
*/
package org.openremote.model;
-import elemental.json.*;
+import elemental.json.Json;
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
import org.openremote.model.asset.AssetMeta;
import java.util.NoSuchElementException;
+import static org.openremote.model.asset.AssetMeta.PROTECTED;
+import static org.openremote.model.asset.AssetMeta.READ_ONLY;
+
/**
* Convenience overlay API for {@link JsonObject}.
* <p>
* Modifies the given or an empty object.
*/
-public class Attribute extends AbstractValueHolder<Attribute> {
+public class Attribute extends AbstractValueTimestampHolder<Attribute> {
protected String name;
@@ -107,18 +112,10 @@ public class Attribute extends AbstractValueHolder<Attribute> {
return this;
}
- public boolean hasMetaItem(AssetMeta assetMeta) {
- return hasMetaItem(assetMeta.getName());
- }
-
public boolean hasMetaItem(String name) {
return hasMeta() && getMeta().contains(name);
}
- public MetaItem firstMetaItem(AssetMeta assetMeta) {
- return firstMetaItem(assetMeta.getName());
- }
-
public MetaItem firstMetaItem(String name) {
return hasMetaItem(name) ? getMeta().first(name) : null;
}
@@ -136,4 +133,54 @@ public class Attribute extends AbstractValueHolder<Attribute> {
public boolean isValid() {
return getName() != null && getName().length() > 0 && getType() != null;
}
+
+ public AttributeRef getAttributeRef(String entityId) {
+ return new AttributeRef(entityId, getName());
+ }
+
+ /**
+ * @return The current value and its timestamp represented as an attribute event.
+ */
+ public AttributeEvent getStateEvent(String assetId) {
+ return new AttributeEvent(
+ getAttributeRef(assetId),
+ getValue(),
+ getValueTimestamp()
+ );
+ }
+
+ /**
+ * Set the attributes' value and updates the value timestamp to event time.
+ *
+ * @throws IllegalArgumentException If a constraint is violated.
+ */
+ public Attribute applyStateEvent(AttributeEvent attributeEvent) throws IllegalArgumentException {
+ if (!attributeEvent.getAttributeState().getAttributeRef().getAttributeName().equals(getName())) {
+ throw new IllegalArgumentException("Attribute name mismatch, expected: " + getName());
+ }
+ return setValue(attributeEvent.getAttributeState().getValue(), attributeEvent.getTimestamp());
+ }
+
+ /* ############################################################################### */
+
+ // The following methods are only applicable to attributes of assets, but they are very convenient here...
+
+ public boolean hasMetaItem(AssetMeta assetMeta) {
+ return hasMetaItem(assetMeta.getName());
+ }
+
+ public MetaItem firstMetaItem(AssetMeta assetMeta) {
+ return firstMetaItem(assetMeta.getName());
+ }
+
+ public boolean isProtected() {
+ return hasMetaItem(PROTECTED) && firstMetaItem(PROTECTED).isValueTrue();
+ }
+
+ public boolean isReadOnly() {
+ return hasMetaItem(READ_ONLY) && firstMetaItem(READ_ONLY).isValueTrue();
+ }
+
+ /* ############################################################################### */
+
}
diff --git a/model/src/main/java/org/openremote/model/AttributeEvent.java b/model/src/main/java/org/openremote/model/AttributeEvent.java
new file mode 100644
index 000000000..f3caec542
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/AttributeEvent.java
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import elemental.json.JsonValue;
+
+/**
+ * A timestamped {@link AttributeState}. Two attribute events
+ * are equal if their timestamps and attribute states are equal.
+ */
+@JsonIgnoreType
+public class AttributeEvent extends Event {
+
+ final protected AttributeState attributeState;
+
+ public AttributeEvent(AttributeState attributeState) {
+ this.attributeState = attributeState;
+ }
+
+ public AttributeEvent(String entityId, String attributeName, JsonValue value) {
+ this(new AttributeState(new AttributeRef(entityId, attributeName), value));
+ }
+
+ public AttributeEvent(AttributeRef attributeRef, JsonValue value) {
+ this(new AttributeState(attributeRef, value));
+ }
+
+ public AttributeEvent(AttributeRef attributeRef, JsonValue value, long timestamp) {
+ this(new AttributeState(attributeRef, value), timestamp);
+ }
+
+ public AttributeEvent(AttributeState attributeState, long timestamp) {
+ super(timestamp);
+ this.attributeState = attributeState;
+ }
+
+ public AttributeState getAttributeState() {
+ return attributeState;
+ }
+
+ public AttributeRef getAttributeRef() {
+ return getAttributeState().getAttributeRef();
+ }
+
+ public String getEntityId() {
+ return getAttributeRef().getEntityId();
+ }
+
+ public String getAttributeName() {
+ return getAttributeRef().getAttributeName();
+ }
+
+ public JsonValue getValue() {
+ return getAttributeState().getValue();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AttributeEvent that = (AttributeEvent) o;
+
+ return this.timestamp == that.timestamp &&
+ attributeState.equals(that.attributeState);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = new Long(timestamp).intValue();
+ result = 31 * result + attributeState.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "timestamp=" + timestamp +
+ ", attributeState=" + attributeState +
+ "}";
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/AttributeState.java b/model/src/main/java/org/openremote/model/AttributeState.java
index 1c4134cdb..078f35a2d 100644
--- a/model/src/main/java/org/openremote/model/AttributeState.java
+++ b/model/src/main/java/org/openremote/model/AttributeState.java
@@ -23,7 +23,8 @@ import elemental.json.Json;
import elemental.json.JsonValue;
/**
- * The desired or current or past state of an {@link AttributeRef}.
+ * The desired or current or past state of an {@link AttributeRef}. Two attribute
+ * states are equal if their attribute references and values are equal.
*/
public class AttributeState {
@@ -50,7 +51,8 @@ public class AttributeState {
AttributeState that = (AttributeState) o;
- return getAttributeRef().equals(that.getAttributeRef()) && getValue().equals(that.getValue());
+ return getAttributeRef().equals(that.getAttributeRef()) &&
+ getValue().jsEquals(that.getValue()); // Note the jsEquals() operation!
}
@Override
diff --git a/model/src/main/java/org/openremote/model/AttributeStateChange.java b/model/src/main/java/org/openremote/model/AttributeStateChange.java
deleted file mode 100644
index 2216abaa9..000000000
--- a/model/src/main/java/org/openremote/model/AttributeStateChange.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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;
-
-import org.openremote.model.asset.AssetMeta;
-
-// TODO: I'm not sure we need two attribute state objects in here as they should always refer to same entity and attribute
-// TODO: This should be an event and inherit a timestamp from Event class and should also use AttributeUpdateEvent (module dependency issue prevents this)
-public class AttributeStateChange {
-
- /**
- * Consumers of state changes can change the status to direct further processing.
- */
- public enum Status {
- /**
- * Consumer is happy for attribute state to continue through the system.
- */
- CONTINUE,
-
- /**
- * Consumer has finally handled the change, cancel further processing.
- */
- HANDLED,
-
- /**
- * Consumer encountered an error trying to process the change
- */
- ERROR
- }
-
- final protected Attribute attribute;
- final protected AttributeState originalState;
- final protected AttributeState newState;
- protected Status processingStatus = Status.CONTINUE;
- protected long timestamp;
-
- public AttributeStateChange(Attribute attribute, AttributeState originalState) {
- this(attribute, originalState, System.currentTimeMillis());
- }
-
- public AttributeStateChange(Attribute attribute, AttributeState originalState, long timestamp) {
- this.timestamp = timestamp;
- this.attribute = attribute;
- this.newState = new AttributeState(originalState.getAttributeRef(), attribute.getValue());
- this.originalState = originalState;
- }
-
- public long getTimestamp() {
- return timestamp;
- }
-
- // TODO: Once we have attribute update event just use its' timestamp
- public long getValueTimestamp() {
- return (long)attribute.firstMetaItemOrThrow(AssetMeta.VALUE_TIMESTAMP.getName()).getValueAsDecimal().doubleValue();
- }
-
- public Attribute getAttribute() {
- return attribute;
- }
-
- public AttributeState getNewState() {
- return newState;
- }
-
- public String getAssetId() {
- return originalState.attributeRef.getEntityId();
- }
-
- public String getAttributeName() {
- return attribute.getName();
- }
-
- public AttributeState getOriginalState() {
- return originalState;
- }
-
- public Status getProcessingStatus() {
- return processingStatus;
- }
-
- public void setProcessingStatus(Status processingStatus) {
- this.processingStatus = processingStatus;
- }
-
- /**
- * Two attribute state changes are considered equal if they reference
- * the same attribute and if the original and desired new states are the equal.
- */
- @Override
- public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
-
- if (o.getClass() != this.getClass()) {
- return false;
- }
- AttributeStateChange that = (AttributeStateChange) o;
- return this.getOriginalState().equals(that.getOriginalState()) &&
- this.getNewState().equals(that.getNewState());
- }
-
- @Override
- public int hashCode() {
- int result = getNewState().hashCode();
- result = 31 * result + getOriginalState().hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "originalState=" + originalState +
- ", newState=" + newState +
- ", processingStatus=" + processingStatus +
- '}';
- }
-}
diff --git a/model/src/main/java/org/openremote/model/Event.java b/model/src/main/java/org/openremote/model/Event.java
new file mode 100644
index 000000000..9c36c589f
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/Event.java
@@ -0,0 +1,117 @@
+/*
+ * 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.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import java.util.Locale;
+
+/*
+@JsonSubTypes({
+ // Events used on client and server (serialized on client/server bus)
+ @JsonSubTypes.Type(value = AttributeStateUpdateEvent.class, name = "ATTRIBUTE_STATE_UPDATE")
+})
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = "event"
+)
+@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
+*/
+// TODO Any subclass that is not @JsonIgnoreType will be made serializable (and must be compilable in GWT!)
+// TODO This needs more work when we know how to do client/server pub/sub message bus
+/**
+ * A timestamped event.
+ */
+public abstract class Event {
+
+ protected long timestamp;
+
+ protected Event(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ protected Event() {
+ timestamp = System.currentTimeMillis();
+ }
+
+ /**
+ * Transforms <code>EXFooBar123</code> into <code>ex-foo-bar-123</code> and
+ * <code>attributeX</code> into <code>attribute-x</code> without regex (GWT!)
+ */
+ public static String toLowerCaseDash(String camelCase) {
+ if (camelCase == null)
+ return null;
+ if (camelCase.length() == 0)
+ return camelCase;
+ StringBuilder sb = new StringBuilder();
+ char[] chars = camelCase.toCharArray();
+ boolean inNonLowerCase = false;
+ for (int i = 0; i < chars.length; i++) {
+ char c = chars[i];
+ if (!Character.isLowerCase(c)) {
+ if (!inNonLowerCase) {
+ if (i > 0)
+ sb.append("-");
+ } else if (i < chars.length - 1 && Character.isLowerCase(chars[i + 1])) {
+ sb.append("-");
+ }
+ inNonLowerCase = true;
+ } else {
+ inNonLowerCase = false;
+ }
+ sb.append(c);
+ }
+ String name = sb.toString();
+ name = name.toLowerCase(Locale.ROOT);
+ return name;
+ }
+
+ public static String getEventType(String simpleClassName) {
+ String type = toLowerCaseDash(simpleClassName);
+ if (type.length() > 6 && type.substring(type.length() - 6).equals("-event"))
+ type = type.substring(0, type.length() - 6);
+ return type;
+ }
+
+ public static String getEventType(Class<? extends Event> actionClass) {
+ return getEventType(actionClass.getSimpleName());
+ }
+
+ /**
+ * A type name that is compile with Polymer event naming, for example the subclass
+ * <code>FooBarEvent</code> will be <code>foo-bar</code>.
+ */
+ public String getEventType() {
+ return getEventType(getClass());
+ }
+
+ @JsonIgnore
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "timestamp=" + timestamp +
+ '}';
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
index 542b3e2f7..8af754631 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
@@ -108,9 +108,7 @@ public enum AssetMeta {
/**
* Should attribute values be stored in time series database
*/
- STORE_DATA_POINTS(ASSET_META_NAMESPACE + ":storeDataPoints", new Access(true, false, true), JsonType.BOOLEAN),
-
- VALUE_TIMESTAMP(ASSET_META_NAMESPACE + ":valueTimestamp", new Access(true, false, false), JsonType.NUMBER);
+ STORE_DATA_POINTS(ASSET_META_NAMESPACE + ":storeDataPoints", new Access(true, false, true), JsonType.BOOLEAN);
final protected String name;
final protected Access access;
diff --git a/model/src/main/java/org/openremote/model/asset/ProtectedAssetInfo.java b/model/src/main/java/org/openremote/model/asset/ProtectedAssetInfo.java
index e2f85b304..6e61f9ac7 100644
--- a/model/src/main/java/org/openremote/model/asset/ProtectedAssetInfo.java
+++ b/model/src/main/java/org/openremote/model/asset/ProtectedAssetInfo.java
@@ -47,10 +47,10 @@ public class ProtectedAssetInfo extends AssetInfo {
Attributes attributes = new Attributes(unfilteredAttributes);
for (Attribute attribute : attributes.get()) {
- // An attribute must have the PROTECTED flag to be included
- MetaItem protectedItem = attribute.firstMetaItem(PROTECTED);
- if (protectedItem == null || !protectedItem.getValueAsBoolean())
+ // An attribute must be protected to be included
+ if (!attribute.isProtected()) {
continue;
+ }
Attribute protectedAttribute = new Attribute(attribute.getName(), attribute.getJsonObject());
filteredAttributes.put(protectedAttribute);
diff --git a/model/src/main/java/org/openremote/model/datapoint/AssetDatapoint.java b/model/src/main/java/org/openremote/model/datapoint/AssetDatapoint.java
index 16090d7af..487cce4cb 100644
--- a/model/src/main/java/org/openremote/model/datapoint/AssetDatapoint.java
+++ b/model/src/main/java/org/openremote/model/datapoint/AssetDatapoint.java
@@ -1,8 +1,28 @@
+/*
+ * 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.model.datapoint;
import elemental.json.JsonValue;
import org.openremote.model.AttributeRef;
import org.openremote.model.AttributeState;
+import org.openremote.model.AttributeEvent;
import javax.persistence.Entity;
import javax.persistence.Table;
@@ -18,24 +38,27 @@ public class AssetDatapoint extends Datapoint {
super(attributeState);
}
- public AssetDatapoint(AttributeRef attributeRef, JsonValue value) {
- super(attributeRef, value);
- }
-
- public AssetDatapoint(String entityId, String attributeName, JsonValue value) {
- super(entityId, attributeName, value);
+ public AssetDatapoint(AttributeEvent stateEvent) {
+ super(stateEvent);
}
public AssetDatapoint(AttributeState attributeState, long timestamp) {
super(attributeState, timestamp);
}
+ public AssetDatapoint(AttributeRef attributeRef, JsonValue value) {
+ super(attributeRef, value);
+ }
+
public AssetDatapoint(AttributeRef attributeRef, JsonValue value, long timestamp) {
super(attributeRef, value, timestamp);
}
+ public AssetDatapoint(String entityId, String attributeName, JsonValue value) {
+ super(entityId, attributeName, value);
+ }
+
public AssetDatapoint(String entityId, String attributeName, JsonValue value, long timestamp) {
super(entityId, attributeName, value, timestamp);
}
-
}
diff --git a/model/src/main/java/org/openremote/model/datapoint/Datapoint.java b/model/src/main/java/org/openremote/model/datapoint/Datapoint.java
index 0d619b7f6..bfe63acc9 100644
--- a/model/src/main/java/org/openremote/model/datapoint/Datapoint.java
+++ b/model/src/main/java/org/openremote/model/datapoint/Datapoint.java
@@ -19,10 +19,10 @@
*/
package org.openremote.model.datapoint;
-import elemental.json.Json;
import elemental.json.JsonValue;
import org.openremote.model.AttributeRef;
import org.openremote.model.AttributeState;
+import org.openremote.model.AttributeEvent;
import javax.persistence.Column;
import javax.persistence.Id;
@@ -63,6 +63,10 @@ public abstract class Datapoint implements Serializable {
this(attributeState.getAttributeRef(), attributeState.getValue());
}
+ public Datapoint(AttributeEvent stateEvent) {
+ this(stateEvent.getAttributeState(), stateEvent.getTimestamp());
+ }
+
public Datapoint(AttributeState attributeState, long timestamp) {
this(attributeState.getAttributeRef(), attributeState.getValue(), timestamp);
}