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
Expose services only on localhost interface when in dev mode, must override when testing with LAN clients
Christian Bauer1577f541ab1f
diff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.javaindex 8bcdb232c..8d19172a7 100644--- a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java@@ -1,32 +1,8 @@package org.openremote.agent.protocol.knx;-import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;-import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;-import static org.openremote.model.util.TextUtil.REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO;-import static org.openremote.model.util.TextUtil.isNullOrEmpty;--import java.io.ByteArrayInputStream;-import java.io.ByteArrayOutputStream;-import java.io.IOException;-import java.util.Arrays;-import java.util.HashMap;-import java.util.List;-import java.util.Map;-import java.util.Optional;-import java.util.function.Consumer;-import java.util.logging.Logger;-import java.util.zip.ZipEntry;-import java.util.zip.ZipInputStream;--import javax.xml.transform.Transformer;-import javax.xml.transform.TransformerFactory;-import javax.xml.transform.stream.StreamResult;-import javax.xml.transform.stream.StreamSource;-import org.openremote.agent.protocol.AbstractProtocol;-import org.openremote.model.asset.agent.ConnectionStatus;import org.openremote.agent.protocol.ProtocolLinkedAttributeImport;-import org.openremote.container.util.Util;+import org.openremote.container.util.CodecUtil;import org.openremote.model.AbstractValueHolder;import org.openremote.model.ValidationFailure;import org.openremote.model.asset.Asset;@@ -34,20 +10,13 @@ import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetMeta;import org.openremote.model.asset.AssetType;import org.openremote.model.asset.agent.AgentLink;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.attribute.AttributeState;-import org.openremote.model.attribute.AttributeType;-import org.openremote.model.attribute.AttributeValidationResult;-import org.openremote.model.attribute.MetaItem;-import org.openremote.model.attribute.MetaItemDescriptor;-import org.openremote.model.attribute.MetaItemDescriptorImpl;+import org.openremote.model.asset.agent.ConnectionStatus;+import org.openremote.model.attribute.*;import org.openremote.model.file.FileInfo;import org.openremote.model.util.Pair;import org.openremote.model.value.Value;import org.openremote.model.value.ValueType;import org.openremote.model.value.Values;-import tuwien.auto.calimero.GroupAddress;import tuwien.auto.calimero.KNXException;import tuwien.auto.calimero.KNXFormatException;@@ -59,6 +28,24 @@ import tuwien.auto.calimero.xml.KNXMLException;import tuwien.auto.calimero.xml.XmlInputFactory;import tuwien.auto.calimero.xml.XmlReader;+import javax.xml.transform.Transformer;+import javax.xml.transform.TransformerFactory;+import javax.xml.transform.stream.StreamResult;+import javax.xml.transform.stream.StreamSource;+import java.io.ByteArrayInputStream;+import java.io.ByteArrayOutputStream;+import java.io.IOException;+import java.util.*;+import java.util.function.Consumer;+import java.util.logging.Logger;+import java.util.zip.ZipEntry;+import java.util.zip.ZipInputStream;++import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;+import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;+import static org.openremote.model.util.TextUtil.REGEXP_PATTERN_INTEGER_POSITIVE_NON_ZERO;+import static org.openremote.model.util.TextUtil.isNullOrEmpty;+/*** This protocol is used to connect to a KNX bus via an IP interface.*/@@ -444,7 +431,7 @@ public class KNXProtocol extends AbstractProtocol implements ProtocolLinkedAttritry {boolean fileFound = false;- byte[] data = Util.decodeBase64(fileInfo.getContents());+ byte[] data = CodecUtil.decodeBase64(fileInfo.getContents());zin = new ZipInputStream(new ByteArrayInputStream(data));ZipEntry zipEntry = zin.getNextEntry();while (zipEntry != null) {diff --git a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.javaindex eea44b0c4..586af0471 100644--- a/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/velbus/AbstractVelbusProtocol.java@@ -23,7 +23,7 @@ import org.openremote.agent.protocol.*;import org.openremote.agent.protocol.velbus.device.DevicePropertyValue;import org.openremote.agent.protocol.velbus.device.FeatureProcessor;import org.openremote.agent.protocol.velbus.device.VelbusDeviceType;-import org.openremote.container.util.Util;+import org.openremote.container.util.CodecUtil;import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetAttribute;import org.openremote.model.asset.AssetMeta;@@ -263,7 +263,7 @@ public abstract class AbstractVelbusProtocol extends AbstractProtocol implementspublic Asset[] discoverLinkedAssetAttributes(AssetAttribute protocolConfiguration, FileInfo fileInfo) throws IllegalStateException {Document xmlDoc;try {- String xmlStr = fileInfo.isBinary() ? new String(Util.decodeBase64(fileInfo.getContents()), "UTF8") : fileInfo.getContents();+ String xmlStr = fileInfo.isBinary() ? new String(CodecUtil.decodeBase64(fileInfo.getContents()), "UTF8") : fileInfo.getContents();LOG.info("Parsing VELBUS project file: " + fileInfo.getName());xmlDoc = DocumentBuilderFactorydiff --git a/client/build.gradle b/client/build.gradleindex 80e9fd79c..ed7b28241 100644--- a/client/build.gradle+++ b/client/build.gradle@@ -145,7 +145,9 @@ task gwtSuperDev(dependsOn: classes, type: JavaExec) {"-noprecompile","-generateJsInteropExports","-style", "PRETTY",- "-bindAddress", "0.0.0.0" // Careful! The code server listens on all interfaces!,+ // Change this to 0.0.0.0 to bind on all interfaces, enabling+ // access of the code server from other devices in your LAN+ "-bindAddress", "127.0.0.1"]// Make this magic directory easily cleanable by placing it into the build folderdiff --git a/container/src/main/java/org/openremote/container/util/CodecUtil.java b/container/src/main/java/org/openremote/container/util/CodecUtil.javanew file mode 100644index 000000000..2886af5f8--- /dev/null+++ b/container/src/main/java/org/openremote/container/util/CodecUtil.java@@ -0,0 +1,47 @@+/*+ * Copyright 2018, 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 org.apache.commons.codec.binary.Base64;++public class CodecUtil {++ protected CodecUtil() {}++ public static byte[] decodeBase64(String base64String) {+ if (base64String == null) {+ return null;+ }++ if (base64String.length() == 0) {+ return new byte[0];+ }++ // Could be data URL encoded so look for comma in first 50 chars+ int searchLength = Math.min(50, base64String.length());+ String str = base64String.substring(0, searchLength-1);+ int commaIndex = str.indexOf(',');+ if (commaIndex >=0) {+ base64String = base64String.substring(commaIndex+1);+ }++ return Base64.decodeBase64(base64String);+ }+}diff --git a/manager/src/main/java/org/openremote/manager/util/JsonUtil.java b/container/src/main/java/org/openremote/container/util/JsonUtil.javasimilarity index 77%rename from manager/src/main/java/org/openremote/manager/util/JsonUtil.javarename to container/src/main/java/org/openremote/container/util/JsonUtil.javaindex f7934797c..671c46b83 100644--- a/manager/src/main/java/org/openremote/manager/util/JsonUtil.java+++ b/container/src/main/java/org/openremote/container/util/JsonUtil.java@@ -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.util;+package org.openremote.container.util;import com.fasterxml.jackson.databind.ObjectMapper;@@ -27,11 +27,6 @@ public class JsonUtil {protected JsonUtil() {}- /**- * For some reason the GWT compiler no longer likes this being in the {@link org.openremote.model.util.JsonUtil}- * class; no idea why as it used to compile fine with this in there???- */- // TODO: Figure out why this won't compile when located in the model JsonUtil class and then remove this class@SuppressWarnings("unchecked")public static <T> T convert(ObjectMapper objectMapper, Class<T> targetType, Object object) {Map<String, Object> props = objectMapper.convertValue(object, Map.class);diff --git a/container/src/main/java/org/openremote/container/util/LogUtil.java b/container/src/main/java/org/openremote/container/util/LogUtil.javaindex 1358789f3..b8555b21f 100644--- a/container/src/main/java/org/openremote/container/util/LogUtil.java+++ b/container/src/main/java/org/openremote/container/util/LogUtil.java@@ -31,6 +31,9 @@ public class LogUtil {public static final String LOGGING_CONFIG_FILE = "LOGGING_CONFIG_FILE";+ protected LogUtil() {+ }+/*** If system property <code>java.util.logging.config.file</code> has not been set, try to load the* logging configuration specified in environment variable <code>LOGGING_CONFIG_FILE</code> as a file.diff --git a/container/src/main/java/org/openremote/container/util/MapAccess.java b/container/src/main/java/org/openremote/container/util/MapAccess.javaindex a58f700c7..b9eb7c847 100644--- a/container/src/main/java/org/openremote/container/util/MapAccess.java+++ b/container/src/main/java/org/openremote/container/util/MapAccess.java@@ -27,6 +27,9 @@ import java.util.Map;*/public class MapAccess {+ protected MapAccess() {+ }+static public String getString(Map<String, String> map, String key, String defaultValue) {return map.containsKey(key) ? map.get(key) : defaultValue;}diff --git a/container/src/main/java/org/openremote/container/util/Util.java b/container/src/main/java/org/openremote/container/util/Util.javaindex 0a7bbec35..0495770d1 100644--- a/container/src/main/java/org/openremote/container/util/Util.java+++ b/container/src/main/java/org/openremote/container/util/Util.java@@ -1,7 +1,5 @@package org.openremote.container.util;-import org.apache.commons.codec.binary.Base64;-import java.lang.reflect.Array;import java.text.ParseException;import java.text.SimpleDateFormat;@@ -141,23 +139,4 @@ public class Util {return (String.format("%.1f", d) + suffix);}- public static byte[] decodeBase64(String base64String) {- if (base64String == null) {- return null;- }-- if (base64String.length() == 0) {- return new byte[0];- }-- // Could be data URL encoded so look for comma in first 50 chars- int searchLength = Math.min(50, base64String.length());- String str = base64String.substring(0, searchLength-1);- int commaIndex = str.indexOf(',');- if (commaIndex >=0) {- base64String = base64String.substring(commaIndex+1);- }-- return Base64.decodeBase64(base64String);- }}diff --git a/container/src/main/java/org/openremote/container/web/WebService.java b/container/src/main/java/org/openremote/container/web/WebService.javaindex cb0798830..c4844f170 100644--- a/container/src/main/java/org/openremote/container/web/WebService.java+++ b/container/src/main/java/org/openremote/container/web/WebService.java@@ -58,8 +58,11 @@ public abstract class WebService implements ContainerService {private static final Logger LOG = Logger.getLogger(WebService.class.getName());+ // Change this to 0.0.0.0 to bind on all interfaces, enabling+ // access of the manager service from other devices in your LANpublic static final String WEBSERVER_LISTEN_HOST = "WEBSERVER_LISTEN_HOST";- public static final String WEBSERVER_LISTEN_HOST_DEFAULT = "0.0.0.0";+ public static final String WEBSERVER_LISTEN_HOST_DEFAULT = "127.0.0.1";+public static final String WEBSERVER_LISTEN_PORT = "WEBSERVER_LISTEN_PORT";public static final int WEBSERVER_LISTEN_PORT_DEFAULT = 8080;public static final String WEBSERVER_DUMP_REQUESTS = "WEBSERVER_DUMP_REQUESTS";diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesClock.java b/manager/src/main/java/org/openremote/manager/rules/RulesClock.javaindex 6a4b037fd..f57188c59 100644--- a/manager/src/main/java/org/openremote/manager/rules/RulesClock.java+++ b/manager/src/main/java/org/openremote/manager/rules/RulesClock.java@@ -23,9 +23,12 @@ import org.openremote.container.timer.TimerService;import org.openremote.model.rules.TemporaryFact;import org.openremote.model.util.TimeUtil;+import java.time.DayOfWeek;import java.time.Instant;import java.time.LocalDateTime;import java.time.ZoneId;+import java.time.temporal.ChronoUnit;+import java.time.temporal.TemporalUnit;import java.util.function.Predicate;/**@@ -58,6 +61,18 @@ public class RulesClock {return fact -> timeWindowStart <= fact.getTimestamp();}+ public DayOfWeek getDayOfWeek() {+ return getTime().getDayOfWeek();+ }++ public LocalDateTime getYesterday() {+ return getTime().minus(1, ChronoUnit.DAYS);+ }++ public LocalDateTime getTomorrow() {+ return getTime().plus(1, ChronoUnit.DAYS);+ }+@Overridepublic String toString() {return getClass().getSimpleName() + "{" +diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex f15327cb6..5598da56a 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -48,7 +48,7 @@ import java.util.ArrayList;import java.util.List;import java.util.logging.Logger;-import static org.openremote.manager.util.JsonUtil.convert;+import static org.openremote.container.util.JsonUtil.convert;import static org.openremote.model.Constants.*;public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider implements ManagerIdentityProvider {diff --git a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.javaindex 6be630bb5..4b6e7842a 100644--- a/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java+++ b/manager/src/main/java/org/openremote/manager/setup/AbstractManagerSetup.java@@ -362,13 +362,13 @@ public abstract class AbstractManagerSetup implements Setup {List<AssetAttribute> attributes = new ArrayList<>();for (DayOfWeek dayOfWeek : DayOfWeek.values()) {// "MONDAY" => "Monday"- String dayName = dayOfWeek.name().substring(0, 1) + dayOfWeek.name().substring(1).toLowerCase(Locale.ROOT);+ String dayOfWeekLabel = dayOfWeek.name().substring(0, 1) + dayOfWeek.name().substring(1).toLowerCase(Locale.ROOT);// "0 0 7 ? *" => "0 0 7 ? * MON *"String timePattern = startTime + " " + dayOfWeek.name().substring(0, 3).toUpperCase(Locale.ROOT) + " *";attributes.add(- initTimerConfiguration(new AssetAttribute(attributeName + dayName), timePattern,+ initTimerConfiguration(new AssetAttribute(attributeName + dayOfWeek.name()), timePattern,new AttributeState(apartment.getId(), attributeName, Values.create("REQUEST_START")))- .addMeta(new MetaItem(LABEL, Values.create(attributeLabel + " trigger " + dayName)))+ .addMeta(new MetaItem(LABEL, Values.create(attributeLabel + " trigger " + dayOfWeekLabel))));}return attributes.toArray(new AssetAttribute[attributes.size()]);@@ -452,24 +452,24 @@ public abstract class AbstractManagerSetup implements Setup {);for (DayOfWeek dayOfWeek : DayOfWeek.values()) {// "MONDAY" => "Monday"- String dayName = dayOfWeek.name().substring(0, 1) + dayOfWeek.name().substring(1).toLowerCase(Locale.ROOT);+ String dayOfWeekLabel = dayOfWeek.name().substring(0, 1) + dayOfWeek.name().substring(1).toLowerCase(Locale.ROOT);apartment.addAttributes(new AssetAttribute(scene.attributeName + "Time" + dayOfWeek.name(), AttributeType.STRING).setMeta(- new MetaItem(LABEL, Values.create(scene.attributeLabel + " time " + dayName)),+ new MetaItem(LABEL, Values.create(scene.attributeLabel + " time " + dayOfWeekLabel)),new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)),new MetaItem(RULE_STATE, Values.create(true)),new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayName).toArrayValue())+ new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayOfWeek.name()).toArrayValue())),new AssetAttribute(scene.attributeName + "Enabled" + dayOfWeek.name(), AttributeType.BOOLEAN).setMeta(- new MetaItem(LABEL, Values.create(scene.attributeLabel + " enabled " + dayName)),+ new MetaItem(LABEL, Values.create(scene.attributeLabel + " enabled " + dayOfWeekLabel)),new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)),new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)),new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),- new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayName).toArrayValue())+ new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), scene.attributeName + dayOfWeek.name()).toArrayValue())));}diff --git a/profile/deploy.yml b/profile/deploy.ymlindex c2905f5ff..d8a05b511 100644--- a/profile/deploy.yml+++ b/profile/deploy.yml@@ -185,9 +185,9 @@ services:# the rules engine.# SCHEDULED_TASKS_THREADS_MAX: 4- # When asset attributes are enabled for rule events, each value update will be an event fact- # in a rules. You can set the global default expiration time span, after which rule event- # facts are retracted automatically. Default is 1 hour.+ # When asset attributes are enabled for rule events, each value update will be a temporary+ # fact in rules. You can set the global default expiration time span used when no other+ # attribute-level configuration exists. Default is 1 hour.# RULE_EVENT_EXPIRES: '1h'# The identity provider implementation to use for managing user identities, roles, and