100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Fixed tests, new unique identifier generator, experimental UPnP protocol
Christian Bauer94574fd61768
diff --git a/agent/build.gradle b/agent/build.gradleindex c430bd6f1..1a2a39d4c 100644--- a/agent/build.gradle+++ b/agent/build.gradle@@ -13,5 +13,7 @@ dependencies {compile "com.github.calimero:calimero-core:$calimeroVersion"compile "com.github.calimero:calimero-tools:$calimeroVersion"++ compile "org.fourthline.cling:cling-core:$clingVersion"}\ No newline at end of filediff --git a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.javaindex 37d4b4f19..e4e0fb384 100644--- a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java+++ b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java@@ -20,6 +20,7 @@package org.openremote.agent.protocol;import org.openremote.container.ContainerService;+import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.attribute.AttributeEvent;@@ -34,6 +35,20 @@ public interface ProtocolAssetService extends ContainerService {*/void updateProtocolConfiguration(AssetAttribute protocolConfiguration);+ /**+ * Protocols may store assets in the context or update existing assets. A unique identifier+ * must be set by the protocol implementor, as well as a parent identifier. This operation+ * stores transient or detached state and returns the current state.+ */+ Asset mergeAsset(Asset asset);++ /**+ * Protocols may remove assets from the context store.+ *+ * @return <code>false</code> if the delete could not be performed (asset may have children?)+ */+ boolean deleteAsset(String assetId);+/*** Protocols can send arbitrary attribute change events for regular processing.*/diff --git a/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.javanew file mode 100644index 000000000..15fa760e7--- /dev/null+++ b/agent/src/main/java/org/openremote/agent/protocol/upnp/UpnpProtocol.java@@ -0,0 +1,183 @@+package org.openremote.agent.protocol.upnp;++import com.fasterxml.uuid.Generators;+import org.fourthline.cling.UpnpService;+import org.fourthline.cling.UpnpServiceImpl;+import org.fourthline.cling.model.message.header.STAllHeader;+import org.fourthline.cling.model.meta.Device;+import org.fourthline.cling.registry.DefaultRegistryListener;+import org.fourthline.cling.registry.Registry;+import org.fourthline.cling.registry.RegistryListener;+import org.openremote.agent.protocol.AbstractProtocol;+import org.openremote.model.asset.Asset;+import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.AssetType;+import org.openremote.model.attribute.AttributeEvent;+import org.openremote.model.attribute.AttributeRef;+import org.openremote.model.attribute.MetaItem;+import org.openremote.model.value.Values;++import java.util.Collection;+import java.util.Optional;+import java.util.logging.Logger;++import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;+import static org.openremote.model.asset.AssetMeta.LABEL;+import static org.openremote.model.attribute.AttributeType.STRING;++// TODO Experimental++public class UpnpProtocol extends AbstractProtocol {++ private static final Logger LOG = Logger.getLogger(UpnpProtocol.class.getName());++ public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":upnp";++ static protected UpnpService INSTANCE = null;+ final protected RegistryListener registryListener = new DefaultRegistryListener() {+ @Override+ public void deviceAdded(Registry registry, Device device) {+ LOG.fine("UPnP device discovered: " + device.getDisplayString());+ for (AttributeRef attributeRef : linkedProtocolConfigurations.keySet()) {+ storeAssets(attributeRef.getEntityId(), device);+ }+ }++ @Override+ public void deviceRemoved(Registry registry, Device device) {+ LOG.fine("UPnP device gone: " + device.getDisplayString());+ if (!assetService.deleteAsset(getAssetId(device))) {+ LOG.warning("UPnP device gone but can't delete discovered asset: " + device);+ }+ }++ };++ @Override+ public String getProtocolName() {+ return PROTOCOL_NAME;+ }++ @Override+ protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {+ protocolConfiguration.getAssetId().ifPresent(agentId -> {+ Collection<Device> devices = getService().getRegistry().getDevices();+ if (devices.size() > 0) {+ LOG.fine("Storing UPnP devices as child assets of agent: " + agentId);+ for (Device device : getService().getRegistry().getDevices()) {+ storeAssets(agentId, device);+ }+ }+ });+ }++ @Override+ protected void doUnlinkProtocolConfiguration(AssetAttribute protocolConfiguration) {+ if (linkedProtocolConfigurations.size() == 1) {+ closeService();+ }+ }++ @Override+ protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {+++ }++ @Override+ protected void doUnlinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {++ }++ @Override+ protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute protocolConfiguration) {++ }++ protected UpnpService getService() {+ if (INSTANCE == null) {+ INSTANCE = new UpnpServiceImpl(registryListener);+ INSTANCE.getControlPoint().search(new STAllHeader());+ }+ return INSTANCE;+ }++ protected void closeService() {+ if (INSTANCE != null) {+ INSTANCE.shutdown();+ INSTANCE = null;+ }+ }++ protected void storeAssets(String agentId, Device device) {+ Asset asset = createAsset(agentId, device);+ asset = assetService.mergeAsset(asset);+ }++ protected Asset createAsset(String parentId, Device device) {+ Asset asset = new Asset(+ device.getDisplayString(),+ AssetType.THING+ );+ asset.setParentId(parentId);+ asset.setId(getAssetId(device));++ Optional.ofNullable(device.getType().getDisplayString()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("type", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Device Type")))+ )+ );++ Optional.ofNullable(device.getDetails().getManufacturerDetails().getManufacturer()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("manufacturer", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Manufacturer")))+ )+ );++ Optional.ofNullable(device.getDetails().getFriendlyName()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("friendlyName", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Friendly Name")))+ )+ );++ Optional.ofNullable(device.getDetails().getModelDetails().getModelNumber()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("modelNumber", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Model Number")))+ )+ );++ Optional.ofNullable(device.getDetails().getModelDetails().getModelName()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("modelName", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Model Name")))+ )+ );++ Optional.ofNullable(device.getDetails().getModelDetails().getModelDescription()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("modelDescription", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Model Description")))+ )+ );++ Optional.ofNullable(device.getDetails().getSerialNumber()).ifPresent(v ->+ asset.addAttributes(+ new AssetAttribute("serialNumber", STRING, Values.create(v))+ .addMeta(new MetaItem(LABEL, Values.create("Serial Number")))+ )+ );++ return asset;+ }++ protected String getAssetId(Device device) {+ return Generators.nameBasedGenerator().generate(+ device.getIdentity().getUdn().getIdentifierString()+ ).toString();+ }++}diff --git a/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol b/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocolindex cfd06659c..f082e2647 100644--- a/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol+++ b/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol@@ -1,4 +1,5 @@org.openremote.agent.protocol.simulator.SimulatorProtocolorg.openremote.agent.protocol.macro.MacroProtocolorg.openremote.agent.protocol.timer.TimerProtocol-org.openremote.agent.protocol.knx.KNXProtocol\ No newline at end of file+org.openremote.agent.protocol.knx.KNXProtocol+org.openremote.agent.protocol.upnp.UpnpProtocol\ No newline at end of filediff --git a/container/build.gradle b/container/build.gradleindex f464ec630..70571f1cc 100644--- a/container/build.gradle+++ b/container/build.gradle@@ -47,6 +47,8 @@ dependencies {compile "org.apache.camel:camel-script:$camelVersion"compile "org.apache.camel:camel-groovy:$camelVersion"+ compile "com.fasterxml.uuid:java-uuid-generator:$uuidGeneratorVersion"+// Test environment dependenciescompile "org.glassfish.tyrus:tyrus-client:$tyrusVersion"compile "org.glassfish.tyrus:tyrus-container-grizzly-client:$tyrusVersion"diff --git a/container/src/main/java/org/openremote/container/persistence/UniqueIdentifierGenerator.java b/container/src/main/java/org/openremote/container/persistence/UniqueIdentifierGenerator.javaindex f3a2c5cf8..1e2b0831f 100644--- a/container/src/main/java/org/openremote/container/persistence/UniqueIdentifierGenerator.java+++ b/container/src/main/java/org/openremote/container/persistence/UniqueIdentifierGenerator.java@@ -19,10 +19,11 @@*/package org.openremote.container.persistence;+import com.fasterxml.uuid.Generators;+import com.fasterxml.uuid.impl.RandomBasedGenerator;import org.hibernate.HibernateException;import org.hibernate.engine.spi.SharedSessionContractImplementor;import org.hibernate.id.IdentifierGenerator;-import org.openremote.container.util.IdentifierUtil;import org.openremote.model.IdentifiableEntity;import java.io.Serializable;@@ -33,6 +34,8 @@ import java.io.Serializable;*/public class UniqueIdentifierGenerator implements IdentifierGenerator {+ final protected RandomBasedGenerator generator = Generators.randomBasedGenerator();+@Overridepublic Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {if (object instanceof IdentifiableEntity) {@@ -40,6 +43,6 @@ public class UniqueIdentifierGenerator implements IdentifierGenerator {if (identifiableEntity.getId() != null)return identifiableEntity.getId();}- return IdentifierUtil.generateGlobalUniqueId();+ return generator.generate().toString();}}diff --git a/container/src/main/java/org/openremote/container/util/IdentifierUtil.java b/container/src/main/java/org/openremote/container/util/IdentifierUtil.javadeleted file mode 100644index 02536c53d..000000000--- a/container/src/main/java/org/openremote/container/util/IdentifierUtil.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.container.util;--import java.net.NetworkInterface;-import java.nio.ByteBuffer;-import java.nio.LongBuffer;-import java.nio.charset.Charset;-import java.security.MessageDigest;-import java.util.Base64;-import java.util.Collections;-import java.util.Enumeration;-import java.util.UUID;--/**- * Utility functions for identifier value generation.- */-public class IdentifierUtil {-- /**- * A random 128 bit UUID in URL-safe 22 characters.- */- public static String generateGlobalUniqueId() {- String encoded = Base64.getUrlEncoder().encodeToString(IdentifierUtil.toByteArray(UUID.randomUUID()));- while (encoded.charAt(encoded.length() - 1) == '=')- encoded = encoded.substring(0, encoded.length() - 1);- return encoded;- }-- /**- * Generates a unique identifier that is the same every time this method is invoked on the same machine with- * the same argument. This is a 43 characters URL-safe string.- * <p>- * This method combines the first non-loopback network interface's MAC address with given salt, then produces a- * SHA-256 hash. In other words, every time you call this method with the same salt on the same- * machine, you get the same identifier. If you use the same salt on a different machine, a different identifier- * will be generated.- * </p>- *- * @param salt An arbitrary string, longer values improve uniqueness.- * @return A global unique identifier, stable for the current system and salt- */- public static String generateSystemUniqueId(String salt) {- return getEncodedHash(- IdentifierUtil.getFirstNetworkInterfaceHardwareAddress(),- salt.getBytes(Charset.forName("UTF-8"))- );- }-- /**- * Generates a URL-safe, 43 character unpadded Base64 encoded SHA-256 hash of the given bytes.- */- public static String getEncodedHash(byte[]... bytes) {- if (bytes == null)- throw new IllegalArgumentException("Can't encode/hash null bytes");- try {- MessageDigest digest = MessageDigest.getInstance("SHA-256");- digest.reset();- for (byte[] byteArray : bytes) {- digest.update(byteArray);- }- byte[] hash = digest.digest();- digest.reset();- String encoded = Base64.getUrlEncoder().encodeToString(hash);- while (encoded.charAt(encoded.length() - 1) == '=')- encoded = encoded.substring(0, encoded.length() - 1);- return encoded;- } catch (Exception ex) {- throw new RuntimeException(ex);- }- }-- /**- * Gets the first non-loopback, "up" network interface's MAC address or throws an exception.- */- public static byte[] getFirstNetworkInterfaceHardwareAddress() {- try {- Enumeration<NetworkInterface> interfaceEnumeration = NetworkInterface.getNetworkInterfaces();- for (NetworkInterface iface : Collections.list(interfaceEnumeration)) {- if (!iface.isLoopback() && iface.isUp() && iface.getHardwareAddress() != null) {- return iface.getHardwareAddress();- }- }- } catch (Exception ex) {- throw new RuntimeException("Could not discover first network interface hardware address", ex);- }- throw new RuntimeException("Could not discover first network interface hardware address");- }-- /**- * Returns the 16 bytes of the given UUID.- */- public static byte[] toByteArray(UUID uuid) {- byte[] byteArray = new byte[(Long.SIZE / Byte.SIZE) * 2];- ByteBuffer buffer = ByteBuffer.wrap(byteArray);- LongBuffer longBuffer = buffer.asLongBuffer();- longBuffer.put(new long[]{uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()});- return byteArray;- }--}diff --git a/gradle.properties b/gradle.propertiesindex 2e0bda1f0..46d1b399a 100644--- a/gradle.properties+++ b/gradle.properties@@ -29,4 +29,6 @@ tyrusVersion = 1.10sunriseSunsetCalculatorVersion = 1.2droolsVersion = 6.5.0.FinalquartzVersion= 2.2.3-calimeroVersion = 2.3\ No newline at end of file+calimeroVersion = 2.3+clingVersion = 2.1.1+uuidGeneratorVersion = 3.1.3\ No newline at end of filediff --git a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.propertiesindex 1c50b4a5e..38f3f470f 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@@ -175,6 +175,7 @@ attributeType=Unknown attribute typeattributeType[STRING]=TextattributeType[NUMBER]=NumberattributeType[BOOLEAN]=On/Off toggle+attributeType[OBJECT]=JSON ObjectattributeType[PERCENTAGE]=PercentageattributeType[TIMESTAMP_MILLIS]=Timestamp milliseconds since epochattributeType[DATETIME]=Timestamp in ISO 8601diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.javaindex ed399f9cb..c6585702e 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java@@ -186,6 +186,23 @@ public class AgentService extends RouteBuilder implements ContainerService, ConsassetStorageService.merge(agent);}+ @Override+ public Asset mergeAsset(Asset asset) {+ Objects.requireNonNull(asset.getId());+ Objects.requireNonNull(asset.getParentId());+ LOG.fine("Merging (and overriding existing older version of) with protocol-provided: " + asset);+ ServerAsset serverAsset = ServerAsset.map(asset, new ServerAsset());+ // Use the unique identifier provided by the protocol, it manages its own identifier space+ serverAsset.setId(asset.getId());+ return assetStorageService.merge(serverAsset, true);+ }++ @Override+ public boolean deleteAsset(String assetId) {+ LOG.fine("Deleting protocol-provided: " + assetId);+ return assetStorageService.delete(assetId);+ }+@Overridepublic void sendAttributeEvent(AttributeEvent attributeEvent) {assetProcessingService.sendAttributeEvent(attributeEvent);diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.javaindex b25872b57..6d72f9434 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@@ -242,11 +242,17 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic* @throws IllegalArgumentException if the realm or parent is illegal, or other asset constraint is violated.*/public ServerAsset merge(ServerAsset asset) {+ return merge(asset, false);+ }++ /**+ * @param overrideVersion If <code>true</code>, the merge will override the data in the database, independent of version.+ * @return The current stored asset state.+ * @throws IllegalArgumentException if the realm or parent is illegal, or other asset constraint is violated.+ */+ public ServerAsset merge(ServerAsset asset, boolean overrideVersion) {return persistenceService.doReturningTransaction(em -> {- // Validate realm- if (!managerIdentityService.isActiveTenant(asset.getRealmId())) {- throw new IllegalStateException("Realm not found/active: " + asset.getRealmId());- }+// Validate parentif (asset.getParentId() != null) {// If this is a not a root asset...@@ -257,6 +263,15 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic// ... the parent can not be a child of the assetif (parent.pathContains(asset.getId()))throw new IllegalStateException("Invalid parent");++ // ... and if we don't have a realm identifier, use the parent's+ if (asset.getRealmId() == null)+ asset.setRealmId(parent.getRealmId());+ }++ // Validate realm+ if (!managerIdentityService.isActiveTenant(asset.getRealmId())) {+ throw new IllegalStateException("Realm not found/active: " + asset.getRealmId());}// Validate attributes@@ -272,6 +287,17 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicthrow new IllegalStateException("Storing asset failed, invalid attributes: " + invalid);}++ // If this is real merge and desired, copy the persistent version number over the detached+ // version, so the detached state always wins and this update will go through and ignore+ // concurrent updates+ if (asset.getId() != null && overrideVersion) {+ ServerAsset existing = em.find(ServerAsset.class, asset.getId());+ if (existing != null) {+ asset.setVersion(existing.getVersion());+ }+ }+LOG.fine("Storing: " + asset);return em.merge(asset);});diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.javaindex eb796bd11..62440ba22 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java@@ -24,6 +24,7 @@ import org.openremote.agent.protocol.simulator.SimulatorProtocol;import org.openremote.agent.protocol.simulator.element.ColorSimulatorElement;import org.openremote.agent.protocol.simulator.element.NumberSimulatorElement;import org.openremote.agent.protocol.simulator.element.SwitchSimulatorElement;+import org.openremote.agent.protocol.upnp.UpnpProtocol;import org.openremote.container.Container;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.setup.AbstractManagerSetup;@@ -417,6 +418,14 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment2 = assetStorageService.merge(apartment2);apartment2Id = apartment2.getId();+ /* TODO Experimental+ ServerAsset apartment2UpnpAgent= new ServerAsset("UPnP Agent", AGENT, apartment2);+ apartment2UpnpAgent.setAttributes(+ initProtocolConfiguration(new AssetAttribute("upnpConfig1"), UpnpProtocol.PROTOCOL_NAME)+ );+ apartment2UpnpAgent = assetStorageService.merge(apartment2UpnpAgent);+ */+ServerAsset apartment2Livingroom = new ServerAsset("Living Room", ROOM, apartment2);apartment2Livingroom.setLocation(apartment2.getLocation());apartment2Livingroom.setAttributes(diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovyindex b9b14b71f..7c6c9ed26 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy@@ -1,15 +1,15 @@package org.openremote.test.assets-import org.openremote.model.value.Values-import org.openremote.container.util.IdentifierUtil+import com.fasterxml.uuid.Generatorsimport org.openremote.manager.server.setup.SetupServiceimport org.openremote.manager.server.setup.builtin.KeycloakDemoSetupimport org.openremote.manager.server.setup.builtin.ManagerDemoSetupimport org.openremote.manager.shared.asset.AssetResource-import org.openremote.model.attribute.AttributeTypeimport org.openremote.model.asset.Assetimport org.openremote.model.asset.AssetAttributeimport org.openremote.model.asset.AssetType+import org.openremote.model.attribute.AttributeType+import org.openremote.model.value.Valuesimport org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions@@ -45,7 +45,7 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTraitwhen: "an asset is created in the authenticated realm"def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)testAsset = assetResource.get(null, testAsset.getId())diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovyindex 348de9461..8f61ed8e4 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy@@ -1,6 +1,6 @@package org.openremote.test.assets-import org.openremote.container.util.IdentifierUtil+import com.fasterxml.uuid.Generatorsimport org.openremote.manager.server.setup.SetupServiceimport org.openremote.manager.server.setup.builtin.KeycloakDemoSetupimport org.openremote.manager.server.setup.builtin.ManagerDemoSetup@@ -107,7 +107,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiwhen: "an asset is created in the authenticated realm"def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)testAsset = assetResource.get(null, testAsset.getId())@@ -283,7 +283,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiwhen: "an asset is created in the authenticated realm"def testAsset = new Asset("Test Room", AssetType.ROOM) // Note: no realm means auth realm- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)testAsset = assetResource.get(null, testAsset.getId())@@ -428,7 +428,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiwhen: "an asset is created in a foreign realm"def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)then: "access should be forbidden"@@ -446,7 +446,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiwhen: "an asset is created in the authenticated realm"testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.customerATenant.id)- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)then: "access should be forbidden"@@ -606,7 +606,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiwhen: "an asset is created in a foreign realm"def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)then: "access should be forbidden"@@ -624,7 +624,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTraiwhen: "an asset is created in the authenticated realm"testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.customerATenant.id)- testAsset.setId(IdentifierUtil.generateGlobalUniqueId())+ testAsset.setId(Generators.randomBasedGenerator().generate().toString())assetResource.create(null, testAsset)then: "access should be forbidden"diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotificationWhenAlarmTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotificationWhenAlarmTest.groovyindex 65834f6ee..35b811eb5 100644--- a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotificationWhenAlarmTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentNotificationWhenAlarmTest.groovy@@ -75,7 +75,7 @@ class ApartmentNotificationWhenAlarmTest extends Specification implements Managdef notificationResource = getClientTarget(serverUri(serverPort), realm, accessToken).proxy(NotificationResource.class)when: "the notification tokens of some devices are stored"- notificationResource.storeDeviceToken(null, "device123", "token123")+ notificationResource.storeDeviceToken(null, "device123", "token123", "ANDROID")then: "the tokens should be in the database"notificationService.findDeviceToken("device123", keycloakDemoSetup.testuser3Id) == "token123"diff --git a/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy b/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovyindex dfc79f874..f7650dd6f 100644--- a/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/user/NotificationServiceTest.groovy@@ -54,8 +54,8 @@ class NotificationServiceTest extends Specification implements ManagerContainerTnotificationService.findAllUsersWithToken().isEmpty()when: "the notification tokens of some devices are stored"- notificationResource.storeDeviceToken(null, "device123", "token123")- notificationResource.storeDeviceToken(null, "device456", "token456")+ notificationResource.storeDeviceToken(null, "device123", "token123", "ANDROID")+ notificationResource.storeDeviceToken(null, "device456", "token456", "ANDROID")then: "the tokens should be in the database"notificationService.findDeviceToken("device123", keycloakDemoSetup.testuser3Id) == "token123"@@ -83,7 +83,7 @@ class NotificationServiceTest extends Specification implements ManagerContainerTnotificationService.findAllUsersWithToken(new UserQuery().asset(new UserQuery.AssetPredicate().id(managerDemoSetup.apartment3Id))).isEmpty()when: "the notification token of some device is updated"- notificationResource.storeDeviceToken(null, "device456", "token789")+ notificationResource.storeDeviceToken(null, "device456", "token789", "ANDROID")then: "the updated token should be in the database"notificationService.findDeviceToken("device456", keycloakDemoSetup.testuser3Id) == "token789"diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex 67faab8a2..0a7ef22fd 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -220,7 +220,7 @@ import static org.openremote.model.asset.AssetAttribute.*;public class Asset implements IdentifiableEntity {@Id- @Column(name = "ID", length = 27)+ @Column(name = "ID", length = 43) // TODO Is this ideal long-term for reads when keys must be distributed on cluster?@GeneratedValue(generator = PERSISTENCE_UNIQUE_ID_GENERATOR)protected String id;@@ -243,7 +243,7 @@ public class Asset implements IdentifiableEntity {@Column(name = "ASSET_TYPE", nullable = false, updatable = false)protected String type;- @Column(name = "PARENT_ID", length = 27)+ @Column(name = "PARENT_ID", length = 36)protected String parentId;@Transientdiff --git a/model/src/main/java/org/openremote/model/asset/UserAsset.java b/model/src/main/java/org/openremote/model/asset/UserAsset.javaindex d53e029c7..e83ddda3a 100644--- a/model/src/main/java/org/openremote/model/asset/UserAsset.java+++ b/model/src/main/java/org/openremote/model/asset/UserAsset.java@@ -52,7 +52,7 @@ public class UserAsset implements Serializable {protected String userId;@Id- @Column(name = "ASSET_ID", length = 27)+ @Column(name = "ASSET_ID", length = 36)protected String assetId;protected UserAsset() {diff --git a/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java b/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.javaindex 3f8432b6f..2d13c8010 100644--- a/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java+++ b/model/src/main/java/org/openremote/model/asset/agent/ProtocolConfiguration.java@@ -72,7 +72,12 @@ final public class ProtocolConfiguration {}public static boolean isProtocolConfiguration(AssetAttribute attribute) {- return getProtocolName(attribute).isPresent() && attribute.getMetaStream().anyMatch(isMetaNameEqualTo(PROTOCOL_CONFIGURATION));+ return getProtocolName(attribute).isPresent()+ && attribute.getMetaStream().anyMatch(isMetaNameEqualTo(PROTOCOL_CONFIGURATION))+ && attribute.getMetaStream().filter(isMetaNameEqualTo(PROTOCOL_CONFIGURATION))+ .findFirst()+ .map(metaItem -> metaItem.getValueAsBoolean().orElse(false))+ .orElse(false);}public static Optional<String> getProtocolName(AssetAttribute attribute) {diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeType.java b/model/src/main/java/org/openremote/model/attribute/AttributeType.javaindex caa3c515a..5f112c660 100644--- a/model/src/main/java/org/openremote/model/attribute/AttributeType.java+++ b/model/src/main/java/org/openremote/model/attribute/AttributeType.java@@ -49,6 +49,8 @@ public enum AttributeType {BOOLEAN("toggle-off", ValueType.BOOLEAN, value -> Optional.empty()),+ OBJECT("cubes", ValueType.OBJECT, value -> Optional.empty()),+/*** When {@link Ruleset#templateAssetId} references an asset, use the attribute to customize the* template when the ruleset is deployed. The attribute name is available in the template asdiff --git a/model/src/main/java/org/openremote/model/datapoint/Datapoint.java b/model/src/main/java/org/openremote/model/datapoint/Datapoint.javaindex c4ff915e0..f116b4228 100644--- a/model/src/main/java/org/openremote/model/datapoint/Datapoint.java+++ b/model/src/main/java/org/openremote/model/datapoint/Datapoint.java@@ -42,7 +42,7 @@ import static org.openremote.model.Constants.PERSISTENCE_JSON_VALUE_TYPE;public abstract class Datapoint implements Serializable {@Id- @Column(name = "ENTITY_ID", length = 27, nullable = false)+ @Column(name = "ENTITY_ID", length = 36, nullable = false)protected String entityId;@Iddiff --git a/model/src/main/java/org/openremote/model/value/impl/StringValueImpl.java b/model/src/main/java/org/openremote/model/value/impl/StringValueImpl.javaindex 6a3fbd132..8182c352f 100644--- a/model/src/main/java/org/openremote/model/value/impl/StringValueImpl.java+++ b/model/src/main/java/org/openremote/model/value/impl/StringValueImpl.java@@ -19,11 +19,14 @@ import org.openremote.model.value.StringValue;import org.openremote.model.value.ValueException;import org.openremote.model.value.ValueType;+import java.util.Objects;+public class StringValueImpl extends ValueImpl implements StringValue {private transient String string;public StringValueImpl(String string) {+ Objects.requireNonNull(string);this.string = string;}diff --git a/project.gradle b/project.gradleindex 89768b4d3..47d61878e 100644--- a/project.gradle+++ b/project.gradle@@ -10,6 +10,9 @@ repositories {maven {url "http://m2repo.openremote.com/content/groups/public/"}+ maven {+ url "http://4thline.org/m2"+ }}// Eclipse needs help