diff --git a/build.gradle b/build.gradle index b4ff480..65e3924 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ version = 3.1 buildscript { repositories { - mavenCentral() + jcenter() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE") @@ -21,7 +21,8 @@ subprojects { targetCompatibility = 1.8 repositories { - mavenCentral() + jcenter() + maven { url "http://dl.bintray.com/atennert/com" } flatDir { dirs 'libs' } diff --git a/controls/src/main/java/org/atennert/homectrl/controls/AbstractController.java b/controls/src/main/java/de/atennert/homectrl/controls/AbstractController.java similarity index 92% rename from controls/src/main/java/org/atennert/homectrl/controls/AbstractController.java rename to controls/src/main/java/de/atennert/homectrl/controls/AbstractController.java index 5346605..c60076d 100644 --- a/controls/src/main/java/org/atennert/homectrl/controls/AbstractController.java +++ b/controls/src/main/java/de/atennert/homectrl/controls/AbstractController.java @@ -14,9 +14,9 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.controls; +package de.atennert.homectrl.controls; -import org.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.event.EventBus; public abstract class AbstractController { diff --git a/controls/src/main/java/org/atennert/homectrl/controls/ActivatableHeatingController.java b/controls/src/main/java/de/atennert/homectrl/controls/ActivatableHeatingController.java similarity index 92% rename from controls/src/main/java/org/atennert/homectrl/controls/ActivatableHeatingController.java rename to controls/src/main/java/de/atennert/homectrl/controls/ActivatableHeatingController.java index 9428088..bfa6c99 100644 --- a/controls/src/main/java/org/atennert/homectrl/controls/ActivatableHeatingController.java +++ b/controls/src/main/java/de/atennert/homectrl/controls/ActivatableHeatingController.java @@ -14,14 +14,14 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.controls; - -import org.atennert.homectrl.controls.util.IInitializable; -import org.atennert.homectrl.event.EControlUpdate; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; -import org.atennert.homectrl.util.DeviceValue; +package de.atennert.homectrl.controls; + +import de.atennert.homectrl.controls.util.IInitializable; +import de.atennert.homectrl.event.EControlUpdate; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.util.DeviceValue; /** * Heating controller that uses an inside and an outside temperature sensor diff --git a/controls/src/main/java/org/atennert/homectrl/controls/SimpleHeatingController.java b/controls/src/main/java/de/atennert/homectrl/controls/SimpleHeatingController.java similarity index 91% rename from controls/src/main/java/org/atennert/homectrl/controls/SimpleHeatingController.java rename to controls/src/main/java/de/atennert/homectrl/controls/SimpleHeatingController.java index 755cc17..000432a 100644 --- a/controls/src/main/java/org/atennert/homectrl/controls/SimpleHeatingController.java +++ b/controls/src/main/java/de/atennert/homectrl/controls/SimpleHeatingController.java @@ -14,14 +14,14 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.controls; - -import org.atennert.homectrl.controls.util.IInitializable; -import org.atennert.homectrl.event.EControlUpdate; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; -import org.atennert.homectrl.util.DeviceValue; +package de.atennert.homectrl.controls; + +import de.atennert.homectrl.controls.util.IInitializable; +import de.atennert.homectrl.event.EControlUpdate; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.util.DeviceValue; /** * Simple heating controller that uses an inside and an outside temperature sensor diff --git a/controls/src/main/java/org/atennert/homectrl/controls/TwoModeHeatingController.java b/controls/src/main/java/de/atennert/homectrl/controls/TwoModeHeatingController.java similarity index 94% rename from controls/src/main/java/org/atennert/homectrl/controls/TwoModeHeatingController.java rename to controls/src/main/java/de/atennert/homectrl/controls/TwoModeHeatingController.java index e4878c1..0175a3e 100644 --- a/controls/src/main/java/org/atennert/homectrl/controls/TwoModeHeatingController.java +++ b/controls/src/main/java/de/atennert/homectrl/controls/TwoModeHeatingController.java @@ -14,14 +14,14 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.controls; - -import org.atennert.homectrl.controls.util.IInitializable; -import org.atennert.homectrl.event.EControlUpdate; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; -import org.atennert.homectrl.util.DeviceValue; +package de.atennert.homectrl.controls; + +import de.atennert.homectrl.controls.util.IInitializable; +import de.atennert.homectrl.event.EControlUpdate; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.util.DeviceValue; /** * Heating controller that uses an inside and an outside temperature sensor diff --git a/controls/src/main/java/org/atennert/homectrl/controls/util/ControlManager.java b/controls/src/main/java/de/atennert/homectrl/controls/util/ControlManager.java similarity index 85% rename from controls/src/main/java/org/atennert/homectrl/controls/util/ControlManager.java rename to controls/src/main/java/de/atennert/homectrl/controls/util/ControlManager.java index 781db0f..4ae5141 100644 --- a/controls/src/main/java/org/atennert/homectrl/controls/util/ControlManager.java +++ b/controls/src/main/java/de/atennert/homectrl/controls/util/ControlManager.java @@ -1,9 +1,9 @@ -package org.atennert.homectrl.controls.util; +package de.atennert.homectrl.controls.util; import java.util.Set; -import org.atennert.homectrl.controls.AbstractController; -import org.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.controls.AbstractController; +import de.atennert.homectrl.event.EventBus; import org.springframework.beans.factory.annotation.Autowired; public class ControlManager diff --git a/controls/src/main/java/org/atennert/homectrl/controls/util/IInitializable.java b/controls/src/main/java/de/atennert/homectrl/controls/util/IInitializable.java similarity index 88% rename from controls/src/main/java/org/atennert/homectrl/controls/util/IInitializable.java rename to controls/src/main/java/de/atennert/homectrl/controls/util/IInitializable.java index 89bcf32..fa6a3ae 100644 --- a/controls/src/main/java/org/atennert/homectrl/controls/util/IInitializable.java +++ b/controls/src/main/java/de/atennert/homectrl/controls/util/IInitializable.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.controls.util; +package de.atennert.homectrl.controls.util; /** * Since controllers are generated from a special device configuration diff --git a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/AbstractDataProcessor.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/AbstractDataProcessor.java similarity index 80% rename from dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/AbstractDataProcessor.java rename to dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/AbstractDataProcessor.java index 32d132a..87b5a9e 100644 --- a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/AbstractDataProcessor.java +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/AbstractDataProcessor.java @@ -1,7 +1,7 @@ -package org.atennert.homectrl.dataprocessing; +package de.atennert.homectrl.dataprocessing; -import org.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.event.EventBus; public abstract class AbstractDataProcessor { diff --git a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/HighIntegerProcessor.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/HighIntegerProcessor.java similarity index 91% rename from dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/HighIntegerProcessor.java rename to dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/HighIntegerProcessor.java index 3b785ad..7e1ed5f 100644 --- a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/HighIntegerProcessor.java +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/HighIntegerProcessor.java @@ -14,13 +14,13 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.dataprocessing; +package de.atennert.homectrl.dataprocessing; import java.util.HashMap; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; /** * Virtual sensor which returns the highest integer value from a set of sensors. diff --git a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/IntegerIsUnderLimitProcessor.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/IntegerIsUnderLimitProcessor.java similarity index 90% rename from dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/IntegerIsUnderLimitProcessor.java rename to dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/IntegerIsUnderLimitProcessor.java index 7ac46e6..8e7bb45 100644 --- a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/IntegerIsUnderLimitProcessor.java +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/IntegerIsUnderLimitProcessor.java @@ -14,13 +14,13 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.dataprocessing; +package de.atennert.homectrl.dataprocessing; import java.util.Map; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; /** * Virtual sensor which checks if a sensor value is larger than a given limit. diff --git a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/LogicalAndProcessor.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LogicalAndProcessor.java similarity index 90% rename from dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/LogicalAndProcessor.java rename to dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LogicalAndProcessor.java index 4d2df97..a9b0cde 100644 --- a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/LogicalAndProcessor.java +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LogicalAndProcessor.java @@ -14,14 +14,14 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.dataprocessing; +package de.atennert.homectrl.dataprocessing; import java.util.Collection; import java.util.HashMap; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; /** * Virtual sensor which computes the logical AND from a set of boolean diff --git a/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LogicalOrProcessor.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LogicalOrProcessor.java new file mode 100644 index 0000000..1961ab6 --- /dev/null +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LogicalOrProcessor.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright 2016 Andreas Tennert + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + *******************************************************************************/ +package de.atennert.homectrl.dataprocessing; + +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; + +import java.util.Map; + +/** + * This sensor is used to combine sensor values with an or combinator. + * It forwards true if at least one of the inputs is + * true, false otherwise. + */ +public class LogicalOrProcessor extends AbstractDataProcessor { + + private final Map sensors; + + public LogicalOrProcessor( + @ConfigurationField(fieldId = "id") int id, + @ConfigurationField(fieldId = "resources") Map sensors) + { + super(id, false); + + this.sensors = sensors; + } + + @Subscribe + public void update(EDeviceValueUpdate event) + { + if (sensors.containsKey(event.deviceId)) + { + sensors.put(event.deviceId, (Boolean)event.value); + + final boolean oldProcessorValue = processorValue; + processorValue = sensors.values().stream().anyMatch(status -> status); + + if (oldProcessorValue != processorValue) { + eventBus.post(processorId, new EDeviceValueUpdate(processorId, processorValue)); + } + } + } +} diff --git a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/LowPrioritizingDoubleProcessor.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LowPrioritizingDoubleProcessor.java similarity index 93% rename from dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/LowPrioritizingDoubleProcessor.java rename to dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LowPrioritizingDoubleProcessor.java index 19b7fd1..ee3d686 100644 --- a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/LowPrioritizingDoubleProcessor.java +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/LowPrioritizingDoubleProcessor.java @@ -14,13 +14,13 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.dataprocessing; +package de.atennert.homectrl.dataprocessing; import java.util.HashMap; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.util.ConfigurationField; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.util.ConfigurationField; /** * Virtual sensor for temperature calculation that listens to other temperature sensors diff --git a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/util/ProcessorManager.java b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/util/ProcessorManager.java similarity index 81% rename from dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/util/ProcessorManager.java rename to dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/util/ProcessorManager.java index 3b818bf..d74c02c 100644 --- a/dataprocessing/src/main/java/org/atennert/homectrl/dataprocessing/util/ProcessorManager.java +++ b/dataprocessing/src/main/java/de/atennert/homectrl/dataprocessing/util/ProcessorManager.java @@ -1,9 +1,9 @@ -package org.atennert.homectrl.dataprocessing.util; +package de.atennert.homectrl.dataprocessing.util; import java.util.Set; -import org.atennert.homectrl.dataprocessing.AbstractDataProcessor; -import org.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.dataprocessing.AbstractDataProcessor; +import de.atennert.homectrl.event.EventBus; import org.springframework.beans.factory.annotation.Autowired; public class ProcessorManager diff --git a/server/src/main/resources/example-configuration.json b/example-configuration.json similarity index 89% rename from server/src/main/resources/example-configuration.json rename to example-configuration.json index 40735e8..a289386 100644 --- a/server/src/main/resources/example-configuration.json +++ b/example-configuration.json @@ -142,7 +142,7 @@ { "type": "processor", "name": "estimatedOutsideTemperature", - "class": "org.atennert.homectrl.dataprocessing.LowPrioritizingDoubleProcessor", + "class": "de.atennert.homectrl.dataprocessing.LowPrioritizingDoubleProcessor", "id": 5, "value": 20, "data": "double", @@ -152,7 +152,7 @@ { "type": "processor", "name": "highestOutsideBrightness", - "class": "org.atennert.homectrl.dataprocessing.HighIntegerProcessor", + "class": "de.atennert.homectrl.dataprocessing.HighIntegerProcessor", "id": 8, "value": 600, "data": "integer", @@ -161,7 +161,7 @@ { "type": "processor", "name": "isItCloudyOrDark", - "class": "org.atennert.homectrl.dataprocessing.IntegerIsUnderLimitProcessor", + "class": "de.atennert.homectrl.dataprocessing.IntegerIsUnderLimitProcessor", "id": 9, "value": false, "data": "boolean", @@ -171,7 +171,7 @@ { "type": "processor", "name": "heatingActive", - "class": "org.atennert.homectrl.dataprocessing.LogicalAndProcessor", + "class": "de.atennert.homectrl.dataprocessing.LogicalAndProcessor", "id": 10, "value": false, "data": "boolean", @@ -180,7 +180,7 @@ { "type": "control", "name": "workRoomHeatingController", - "class": "org.atennert.homectrl.controls.ActivatableHeatingController", + "class": "de.atennert.homectrl.controls.ActivatableHeatingController", "actorId": 10001, "value": false, "outsideSensorId": 5, @@ -192,7 +192,7 @@ { "type": "control", "name": "livingRoomHeatingController", - "class": "org.atennert.homectrl.controls.ActivatableHeatingController", + "class": "de.atennert.homectrl.controls.ActivatableHeatingController", "actorId": 10002, "value": false, "outsideSensorId": 5, diff --git a/example-server.properties b/example-server.properties new file mode 100644 index 0000000..dd71d61 --- /dev/null +++ b/example-server.properties @@ -0,0 +1,10 @@ + +# communication address properties +homectrl.server.address.http=192.168.0.2:80 +homectrl.server.address.enocean=/dev/ttyUSB0 + +# database information +homectrl.server.logDb.driverClassName = org.sqlite.JDBC +homectrl.server.logDb.url = jdbc:sqlite:homectrlLog.sqlite +homectrl.server.logDb.username = "user" +homectrl.server.logDb.password = "pwd" diff --git a/homectrl-com-if/build.gradle b/homectrl-com-if/build.gradle index 8ac0411..170b938 100644 --- a/homectrl-com-if/build.gradle +++ b/homectrl-com-if/build.gradle @@ -7,4 +7,5 @@ version = "0.0.2" dependencies { compile project(':homectrl') + compile 'de.atennert:com:2+' } diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/AbstractHttpReceiver.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/AbstractHttpReceiver.java similarity index 96% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/AbstractHttpReceiver.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/AbstractHttpReceiver.java index 09e4899..8dda207 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/AbstractHttpReceiver.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/AbstractHttpReceiver.java @@ -14,9 +14,9 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; -import org.atennert.com.communication.AbstractReceiver; +import de.atennert.com.communication.AbstractReceiver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Required; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/Base64Coder.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/Base64Coder.java similarity index 99% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/Base64Coder.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/Base64Coder.java index 91b3e67..32318d7 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/Base64Coder.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/Base64Coder.java @@ -14,7 +14,7 @@ //Please contact the author if you need another license. //This module is provided "as is", without warranties of any kind. -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; /** * A Base64 encoder/decoder. diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/CodingHelper.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/CodingHelper.java similarity index 98% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/CodingHelper.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/CodingHelper.java index 94c43b6..9f81288 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/CodingHelper.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/CodingHelper.java @@ -11,7 +11,7 @@ * Boston, MA 02110-1301, USA. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; /** * This class contains hepler methods for encoding and decoding EnOcean data diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/CommunicationHandler.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/CommunicationHandler.java similarity index 57% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/CommunicationHandler.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/CommunicationHandler.java index 314ac10..08657d3 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/CommunicationHandler.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/CommunicationHandler.java @@ -14,24 +14,20 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Future; - -import org.atennert.com.communication.ICommunicatorAccess; -import org.atennert.com.communication.IDataAcceptance; -import org.atennert.com.util.DataContainer; -import org.atennert.com.util.MapDataContainer; -import org.atennert.homectrl.DataType; -import org.atennert.homectrl.event.EControlUpdate; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.EventBus; -import org.atennert.homectrl.event.Subscribe; -import org.atennert.homectrl.registration.DataDescription; -import org.atennert.homectrl.registration.IHostAddressBook; +package de.atennert.homectrl.communication; + +import de.atennert.com.communication.ICommunicatorAccess; +import de.atennert.com.communication.IDataAcceptance; +import de.atennert.com.util.DataContainer; +import de.atennert.com.util.MapDataContainer; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.DataType; +import de.atennert.homectrl.event.EControlUpdate; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.registration.DataDescription; +import de.atennert.homectrl.registration.IHostAddressBook; +import de.atennert.homectrl.util.EventObserver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,6 +35,10 @@ import rx.Single; import rx.SingleSubscriber; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + /** * This component is the binding between HomeCtrl and COM-framework. */ @@ -52,6 +52,8 @@ public class CommunicationHandler implements IDataAcceptance private EventBus eventBus; + private EventObserver observer = EventObserver.STUB; + @Autowired public void setCommunicator( ICommunicatorAccess communicator ) { @@ -70,16 +72,22 @@ public void setHostLibrary( IHostAddressBook hostAddressBook ) this.hostAddressBook = hostAddressBook; } + public void setObserver(final EventObserver observer) + { + this.observer = observer; + } + @Override - public void accept(String senderAddress, DataContainer data) { - evaluateData(senderAddress, data) - .subscribe(data.subscriber); + public void accept( String senderAddress, DataContainer data ) + { + evaluateData( senderAddress, data ) + .subscribe( data.subscriber ); } private Single evaluateData( String senderAddress, DataContainer data ) { - Map valueMap; - if( data instanceof MapDataContainer ) + final Map valueMap; + if (data instanceof MapDataContainer) { valueMap = ((MapDataContainer) data).getData(); } @@ -91,17 +99,19 @@ private Single evaluateData( String senderAddress, DataContainer Set deviceDescriptions = hostAddressBook.getHostDevices( senderAddress, valueMap.keySet() ); - for( DataDescription description : deviceDescriptions ) - { - // we know, that the value is a String since it comes from the - // interpreter - eventBus.post( - description.id, - new EDeviceValueUpdate( description.id, - DataType.getTypeValue( description.dataType, - (String) valueMap.get( description.referenceId ) ) ) ); - } - return Single.just(null); + deviceDescriptions.stream() + .peek( description -> observer.notify( description, valueMap.get( description.referenceId ) ) ) + .forEach( description -> + { + // we know, that the value is a String since it comes from the + // interpreter + eventBus.post( + description.id, + new EDeviceValueUpdate( description.id, + DataType.getTypeValue( description.dataType, + (String) valueMap.get( description.referenceId ) ) ) ); + } ); + return Single.just( null ); } @Subscribe @@ -110,26 +120,31 @@ public void control( EControlUpdate event ) log.info( "[control] " + event.actorId + " := " + event.value ); DataDescription entry = hostAddressBook.getHostInformation( event.actorId ); - if( entry == null ) + if (entry == null) { log.error( "[control] tried to control unregistered device: " + event.actorId ); } else { communicator.send( entry.hostName, new DataContainer( entry.referenceId, event.value, resultSubscriber ) ); + observer.notify( entry, event.value ); } } - private final SingleSubscriber resultSubscriber = new SingleSubscriber() { + private final SingleSubscriber resultSubscriber = new SingleSubscriber() + { @Override - public void onSuccess(DataContainer container) { - if (container != null) { - log.debug("[resultSubscriber.onSuccess] " + container.dataId + " := " + container.data); + public void onSuccess( DataContainer container ) + { + if (container != null) + { + log.debug( "[resultSubscriber.onSuccess] " + container.dataId + " := " + container.data ); } } @Override - public void onError(Throwable throwable) { + public void onError( Throwable throwable ) + { log.warn( "[resultSubscriber.onError] " + throwable.getMessage() ); } }; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/EnOceanReceiver.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/EnOceanReceiver.java similarity index 98% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/EnOceanReceiver.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/EnOceanReceiver.java index 4a48cb0..c73eff8 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/EnOceanReceiver.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/EnOceanReceiver.java @@ -14,12 +14,12 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; import gnu.io.*; -import org.atennert.com.communication.AbstractReceiver; -import org.atennert.com.util.MessageContainer; -import org.atennert.com.util.Session; +import de.atennert.com.communication.AbstractReceiver; +import de.atennert.com.util.MessageContainer; +import de.atennert.com.util.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Required; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpHelper.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpHelper.java similarity index 97% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpHelper.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpHelper.java index 088b10d..fb3f36f 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpHelper.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpHelper.java @@ -14,12 +14,12 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; import java.io.BufferedReader; import java.io.IOException; -import org.atennert.com.util.MessageContainer; +import de.atennert.com.util.MessageContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpReader.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpReader.java similarity index 96% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpReader.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpReader.java index 991b210..53419ea 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpReader.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpReader.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; import java.io.BufferedReader; import java.io.IOException; @@ -22,9 +22,9 @@ import java.io.OutputStream; import java.net.Socket; -import org.atennert.com.interpretation.InterpreterManager; -import org.atennert.com.util.MessageContainer; -import org.atennert.com.util.Session; +import de.atennert.com.interpretation.InterpreterManager; +import de.atennert.com.util.MessageContainer; +import de.atennert.com.util.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import rx.Scheduler; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpReceiver.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpReceiver.java similarity index 84% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpReceiver.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpReceiver.java index ed49e3f..47682bf 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpReceiver.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpReceiver.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; import java.net.Socket; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpSender.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpSender.java similarity index 96% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpSender.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpSender.java index 928650b..1a70999 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/HttpSender.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/HttpSender.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; import java.io.BufferedReader; import java.io.IOException; @@ -23,8 +23,8 @@ import java.net.Socket; import java.net.UnknownHostException; -import org.atennert.com.communication.ISender; -import org.atennert.com.util.MessageContainer; +import de.atennert.com.communication.ISender; +import de.atennert.com.util.MessageContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/SSEServer.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/SSEServer.java similarity index 92% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/communication/SSEServer.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/communication/SSEServer.java index ba179c6..9a6ea70 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/communication/SSEServer.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/communication/SSEServer.java @@ -14,12 +14,12 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.communication; +package de.atennert.homectrl.communication; import java.net.Socket; -import org.atennert.com.communication.ISender; -import org.atennert.com.util.MessageContainer; +import de.atennert.com.communication.ISender; +import de.atennert.com.util.MessageContainer; /** * Server class for Server-Sent Events. This class is a receiver as well as a diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/AtmelInterpreter.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/AtmelInterpreter.java similarity index 93% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/AtmelInterpreter.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/AtmelInterpreter.java index 681f097..21701a1 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/AtmelInterpreter.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/AtmelInterpreter.java @@ -14,9 +14,9 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.interpretation; +package de.atennert.homectrl.interpretation; -import org.atennert.com.util.DataContainer; +import de.atennert.com.util.DataContainer; /** * Interpreter for the ATMEL parameter protocol (home made protocol). diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/EnOceanInterpreter.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/EnOceanInterpreter.java similarity index 90% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/EnOceanInterpreter.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/EnOceanInterpreter.java index 9be1ece..4e9d6a3 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/EnOceanInterpreter.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/EnOceanInterpreter.java @@ -14,16 +14,16 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.interpretation; - -import org.atennert.com.communication.IDataAcceptance; -import org.atennert.com.interpretation.IInterpreter; -import org.atennert.com.util.DataContainer; -import org.atennert.com.util.MapDataContainer; -import org.atennert.com.util.MessageContainer; -import org.atennert.com.util.Session; -import org.atennert.homectrl.communication.Base64Coder; -import org.atennert.homectrl.communication.CodingHelper; +package de.atennert.homectrl.interpretation; + +import de.atennert.com.communication.IDataAcceptance; +import de.atennert.com.interpretation.IInterpreter; +import de.atennert.com.util.DataContainer; +import de.atennert.com.util.MapDataContainer; +import de.atennert.com.util.MessageContainer; +import de.atennert.com.util.Session; +import de.atennert.homectrl.communication.Base64Coder; +import de.atennert.homectrl.communication.CodingHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import rx.Scheduler; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/ParameterInterpreter.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/ParameterInterpreter.java similarity index 91% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/ParameterInterpreter.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/ParameterInterpreter.java index d7c4986..384adea 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/ParameterInterpreter.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/ParameterInterpreter.java @@ -14,18 +14,18 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.interpretation; +package de.atennert.homectrl.interpretation; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import org.atennert.com.communication.IDataAcceptance; -import org.atennert.com.interpretation.IInterpreter; -import org.atennert.com.util.DataContainer; -import org.atennert.com.util.MapDataContainer; -import org.atennert.com.util.MessageContainer; -import org.atennert.com.util.Session; +import de.atennert.com.communication.IDataAcceptance; +import de.atennert.com.interpretation.IInterpreter; +import de.atennert.com.util.DataContainer; +import de.atennert.com.util.MapDataContainer; +import de.atennert.com.util.MessageContainer; +import de.atennert.com.util.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import rx.Scheduler; @@ -83,6 +83,7 @@ public void interpret(MessageContainer messageContainer, final Session session, if (messageContainer.hasException() && !MessageContainer.Exception.EMPTY.equals( messageContainer.error )){ session.call(null); + return; } Map map = translateMessage( messageContainer.message ); @@ -107,7 +108,7 @@ public void onError(Throwable throwable) { }) ); } - private Map translateMessage( String message ) + protected Map translateMessage( String message ) { Map map = new HashMap<>(); if( message != null ) diff --git a/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/PasswordProtectedParameterInterpreter.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/PasswordProtectedParameterInterpreter.java new file mode 100644 index 0000000..92a88bc --- /dev/null +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/PasswordProtectedParameterInterpreter.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright 2016 Andreas Tennert + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + *******************************************************************************/ +package de.atennert.homectrl.interpretation; + +import de.atennert.com.communication.IDataAcceptance; +import de.atennert.com.util.DataContainer; +import de.atennert.com.util.MapDataContainer; +import de.atennert.com.util.MessageContainer; +import de.atennert.com.util.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import rx.Scheduler; +import rx.Single; +import rx.SingleSubscriber; + +import java.util.Map; + +/** + * This interpreter checks accounts fields in the data. If the account data is correct, then the data will + * be forwarded to the server. Otherwise it won't. This Interpreter uses the {@link ParameterInterpreter} + * to encode and decode the data. It removes the name and pw-fields from the data before forwarding it to + * the server. The fields must literally be named "name" and "pw". If the data includes a field with the + * key "id", then the content of this field will replace the sender address for the application. + */ +public class PasswordProtectedParameterInterpreter extends ParameterInterpreter { + + private static Logger log = LoggerFactory.getLogger( ParameterInterpreter.class ); + + /** Holds names and passwords */ + private final Map accountData; + + public PasswordProtectedParameterInterpreter(Map accountData) { + // TODO encrypt data + this.accountData = accountData; + } + + @Override + public void interpret(MessageContainer messageContainer, Session session, IDataAcceptance acceptance, Scheduler scheduler) { + log.trace( "interpreting: " + messageContainer.message ); + + if (messageContainer.hasException() && !MessageContainer.Exception.EMPTY.equals( messageContainer.error )){ + session.call(null); + return; + } + + Map map = translateMessage( messageContainer.message ); + + final String name = (String) map.remove("name"); + final String pw = (String) map.remove("pw"); + + if (!checkNameAndPw(name, pw)) + { + session.call(null); + return; + } + + final String sender = map.containsKey("id") + ? (String) map.remove("id") + : session.getSender(); + + acceptance.accept( sender, new MapDataContainer(map, + new SingleSubscriber() { + @Override + public void onSuccess(DataContainer dataContainer) { + Single.just(dataContainer) + .subscribeOn(session.scheduler) + .map(data -> encode(data)) + .subscribe(session); + } + + @Override + public void onError(Throwable throwable) { + log.error("[ParameterInterpreter.Subscriber.accept] ERROR"); + Single.just(null) + .subscribeOn(session.scheduler) + .subscribe(session); + } + }) ); + } + + /** + * @param name The account name + * @param pw The account password + * @return true if name and password are known, false otherwise + */ + private boolean checkNameAndPw(final String name, final String pw) { + return !(name == null || pw == null) + && accountData.get(name) != null + && accountData.get(name).equals(pw); + } +} diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/SSEInterpreter.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/SSEInterpreter.java similarity index 80% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/SSEInterpreter.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/SSEInterpreter.java index bad7347..fc2c0fe 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/interpretation/SSEInterpreter.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/interpretation/SSEInterpreter.java @@ -14,14 +14,13 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.interpretation; +package de.atennert.homectrl.interpretation; -import org.atennert.com.communication.IDataAcceptance; -import org.atennert.com.interpretation.IInterpreter; -import org.atennert.com.registration.INodeRegistration; -import org.atennert.com.util.DataContainer; -import org.atennert.com.util.MessageContainer; -import org.atennert.com.util.Session; +import de.atennert.com.communication.IDataAcceptance; +import de.atennert.com.interpretation.IInterpreter; +import de.atennert.com.util.DataContainer; +import de.atennert.com.util.MessageContainer; +import de.atennert.com.util.Session; import rx.Scheduler; /** diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/DataDescription.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/DataDescription.java similarity index 96% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/registration/DataDescription.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/registration/DataDescription.java index eb278f1..0772f0c 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/DataDescription.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/DataDescription.java @@ -14,9 +14,9 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.registration; +package de.atennert.homectrl.registration; -import org.atennert.homectrl.DataType; +import de.atennert.homectrl.DataType; /** * Object that describes a data field or device in the HomeCtrl system. diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/DeviceRegistration.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/DeviceRegistration.java similarity index 96% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/registration/DeviceRegistration.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/registration/DeviceRegistration.java index 959b25d..611701c 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/DeviceRegistration.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/DeviceRegistration.java @@ -14,15 +14,15 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.registration; +package de.atennert.homectrl.registration; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.atennert.com.registration.INodeRegistration; -import org.atennert.homectrl.util.IAddress; +import de.atennert.com.registration.INodeRegistration; +import de.atennert.homectrl.util.IAddress; import org.springframework.beans.factory.annotation.Required; public class DeviceRegistration implements INodeRegistration, IHostAddressBook diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/IHostAddressBook.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/IHostAddressBook.java similarity index 94% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/registration/IHostAddressBook.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/registration/IHostAddressBook.java index a884291..b41cf79 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/IHostAddressBook.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/IHostAddressBook.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.registration; +package de.atennert.homectrl.registration; import java.util.Set; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/NodeDescription.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/NodeDescription.java similarity index 95% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/registration/NodeDescription.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/registration/NodeDescription.java index 5b74327..f82a7e4 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/registration/NodeDescription.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/registration/NodeDescription.java @@ -1,9 +1,9 @@ -package org.atennert.homectrl.registration; +package de.atennert.homectrl.registration; import java.util.HashSet; import java.util.Set; -import org.atennert.homectrl.util.IAddress; +import de.atennert.homectrl.util.IAddress; public class NodeDescription { diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/AddressFactory.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/AddressFactory.java similarity index 95% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/util/AddressFactory.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/util/AddressFactory.java index 5141a58..08433ba 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/AddressFactory.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/AddressFactory.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; import java.util.Map; diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/EnOceanAddress.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EnOceanAddress.java similarity index 94% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/util/EnOceanAddress.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/util/EnOceanAddress.java index fb58a11..ecf2dc8 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/EnOceanAddress.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EnOceanAddress.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; public class EnOceanAddress implements IAddress { diff --git a/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EventDistributor.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EventDistributor.java new file mode 100644 index 0000000..1a17b7d --- /dev/null +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EventDistributor.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2016 Andreas Tennert + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + *******************************************************************************/ +package de.atennert.homectrl.util; + +import de.atennert.homectrl.communication.CommunicationHandler; +import de.atennert.homectrl.registration.DataDescription; + +import java.util.List; + +/** + * This class will get updates from the {@link CommunicationHandler} about + * incoming events and outgoing control actions. + */ +public class EventDistributor implements EventObserver +{ + private final List observers; + + public EventDistributor( final List observers ) {this.observers = observers;} + + @Override + public void notify( final DataDescription description, final Object value ) + { + observers.forEach( o -> o.notify( description, value ) ); + } +} diff --git a/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EventObserver.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EventObserver.java new file mode 100644 index 0000000..df2e20a --- /dev/null +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/EventObserver.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2016 Andreas Tennert + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + *******************************************************************************/ +package de.atennert.homectrl.util; + +import de.atennert.homectrl.registration.DataDescription; + +/** + * This interface is implemented by classes, which receive observed events from the + * {@link EventDistributor}. + */ +public interface EventObserver +{ + EventObserver STUB = ( description, value ) -> {}; + + void notify( DataDescription description, Object value ); +} diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/HttpAddress.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/HttpAddress.java similarity index 93% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/util/HttpAddress.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/util/HttpAddress.java index e8938aa..b7d2706 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/HttpAddress.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/HttpAddress.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; public class HttpAddress implements IAddress { diff --git a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/IAddress.java b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/IAddress.java similarity index 69% rename from homectrl-com-if/src/main/java/org/atennert/homectrl/util/IAddress.java rename to homectrl-com-if/src/main/java/de/atennert/homectrl/util/IAddress.java index e8de7cf..4d82844 100644 --- a/homectrl-com-if/src/main/java/org/atennert/homectrl/util/IAddress.java +++ b/homectrl-com-if/src/main/java/de/atennert/homectrl/util/IAddress.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; public interface IAddress { diff --git a/homectrl-com-if/src/test/java/org/atennert/homectrl/communication/CommunicationHandlerTest.java b/homectrl-com-if/src/test/java/de/atennert/homectrl/communication/CommunicationHandlerTest.java similarity index 85% rename from homectrl-com-if/src/test/java/org/atennert/homectrl/communication/CommunicationHandlerTest.java rename to homectrl-com-if/src/test/java/de/atennert/homectrl/communication/CommunicationHandlerTest.java index 52964bc..9ef9ceb 100644 --- a/homectrl-com-if/src/test/java/org/atennert/homectrl/communication/CommunicationHandlerTest.java +++ b/homectrl-com-if/src/test/java/de/atennert/homectrl/communication/CommunicationHandlerTest.java @@ -1,23 +1,23 @@ -package org.atennert.homectrl.communication; - -import org.atennert.com.communication.ICommunicatorAccess; -import org.atennert.com.util.DataContainer; -import org.atennert.homectrl.DataType; -import org.atennert.homectrl.event.EControlUpdate; -import org.atennert.homectrl.event.EventBus; -import org.atennert.homectrl.registration.DataDescription; -import org.atennert.homectrl.registration.IHostAddressBook; +package de.atennert.homectrl.communication; + +import de.atennert.com.communication.ICommunicatorAccess; +import de.atennert.com.util.DataContainer; +import de.atennert.homectrl.DataType; +import de.atennert.homectrl.event.EControlUpdate; +import de.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.registration.DataDescription; +import de.atennert.homectrl.registration.IHostAddressBook; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mock; import rx.SingleSubscriber; -import rx.Subscription; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.isNull; import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.initMocks; diff --git a/homectrl-com-if/src/test/java/org/atennert/homectrl/registration/DeviceRegistrationTest.java b/homectrl-com-if/src/test/java/de/atennert/homectrl/registration/DeviceRegistrationTest.java similarity index 97% rename from homectrl-com-if/src/test/java/org/atennert/homectrl/registration/DeviceRegistrationTest.java rename to homectrl-com-if/src/test/java/de/atennert/homectrl/registration/DeviceRegistrationTest.java index e44bfe2..c1d2d4b 100644 --- a/homectrl-com-if/src/test/java/org/atennert/homectrl/registration/DeviceRegistrationTest.java +++ b/homectrl-com-if/src/test/java/de/atennert/homectrl/registration/DeviceRegistrationTest.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.registration; +package de.atennert.homectrl.registration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/homectrl/build.gradle b/homectrl/build.gradle index dbfdc46..72780e9 100644 --- a/homectrl/build.gradle +++ b/homectrl/build.gradle @@ -6,13 +6,13 @@ archivesBaseName = "homectrl" version = "2.0.0" dependencies { - compile "org.springframework:spring-core:4.0.2.RELEASE" - compile "org.springframework:spring-expression:4.0.2.RELEASE" + compile "org.springframework:spring-core:4.3.3.RELEASE" + compile "org.springframework:spring-expression:4.3.3.RELEASE" compile "org.slf4j:slf4j-api:1.6.4" compile "org.slf4j:jcl-over-slf4j:1.6.4" compile "org.slf4j:slf4j-log4j12:1.6.4" compile "commons-daemon:commons-daemon:1.0.9" compile "javax.annotation:jsr250-api:1.0" - compile "org.springframework:spring-beans:4.0.2.RELEASE" + compile "org.springframework:spring-beans:4.3.3.RELEASE" compile "org.bidib.jbidib.org.qbang.rxtx:rxtxcomm:2.2" } diff --git a/homectrl/src/main/java/org/atennert/homectrl/DataType.java b/homectrl/src/main/java/de/atennert/homectrl/DataType.java similarity index 86% rename from homectrl/src/main/java/org/atennert/homectrl/DataType.java rename to homectrl/src/main/java/de/atennert/homectrl/DataType.java index 652dc0a..1549686 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/DataType.java +++ b/homectrl/src/main/java/de/atennert/homectrl/DataType.java @@ -1,5 +1,5 @@ -package org.atennert.homectrl; +package de.atennert.homectrl; public enum DataType @@ -20,7 +20,7 @@ public static Object getTypeValue(DataType type, String value) return value == null ? "" : value; case BOOL : - return new Boolean(Boolean.parseBoolean(value) || ( Integer.parseInt(getValidNumberString(value)) > 1 )); + return Boolean.parseBoolean( value ) || (Integer.parseInt( getValidNumberString( value ) ) > 1); default : return null; @@ -29,7 +29,7 @@ public static Object getTypeValue(DataType type, String value) private static String getValidNumberString(String value) { - return value == null || "".equals(value) ? "0" : value; + return value == null || value.isEmpty() ? "0" : value; } public static DataType getDataTypeFromString(String type){ diff --git a/homectrl/src/main/java/org/atennert/homectrl/event/EControlUpdate.java b/homectrl/src/main/java/de/atennert/homectrl/event/EControlUpdate.java similarity index 96% rename from homectrl/src/main/java/org/atennert/homectrl/event/EControlUpdate.java rename to homectrl/src/main/java/de/atennert/homectrl/event/EControlUpdate.java index 55dd62c..8ed9b92 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/event/EControlUpdate.java +++ b/homectrl/src/main/java/de/atennert/homectrl/event/EControlUpdate.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.event; +package de.atennert.homectrl.event; /** * Event object for control actions towards actors. diff --git a/homectrl/src/main/java/org/atennert/homectrl/event/EDeviceValueUpdate.java b/homectrl/src/main/java/de/atennert/homectrl/event/EDeviceValueUpdate.java similarity index 96% rename from homectrl/src/main/java/org/atennert/homectrl/event/EDeviceValueUpdate.java rename to homectrl/src/main/java/de/atennert/homectrl/event/EDeviceValueUpdate.java index 7ad486b..33ccb8e 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/event/EDeviceValueUpdate.java +++ b/homectrl/src/main/java/de/atennert/homectrl/event/EDeviceValueUpdate.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.event; +package de.atennert.homectrl.event; /** * Event object for updates of device values from actors and sensors. diff --git a/homectrl/src/main/java/org/atennert/homectrl/event/EventBus.java b/homectrl/src/main/java/de/atennert/homectrl/event/EventBus.java similarity index 99% rename from homectrl/src/main/java/org/atennert/homectrl/event/EventBus.java rename to homectrl/src/main/java/de/atennert/homectrl/event/EventBus.java index 811c8c5..1d2f04b 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/event/EventBus.java +++ b/homectrl/src/main/java/de/atennert/homectrl/event/EventBus.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.event; +package de.atennert.homectrl.event; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -29,7 +29,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.atennert.homectrl.util.Pair; +import de.atennert.homectrl.util.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/homectrl/src/main/java/org/atennert/homectrl/event/Subscribe.java b/homectrl/src/main/java/de/atennert/homectrl/event/Subscribe.java similarity index 97% rename from homectrl/src/main/java/org/atennert/homectrl/event/Subscribe.java rename to homectrl/src/main/java/de/atennert/homectrl/event/Subscribe.java index e8bee35..d07ccd2 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/event/Subscribe.java +++ b/homectrl/src/main/java/de/atennert/homectrl/event/Subscribe.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.event; +package de.atennert.homectrl.event; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/homectrl/src/main/java/org/atennert/homectrl/util/ConfigurationField.java b/homectrl/src/main/java/de/atennert/homectrl/util/ConfigurationField.java similarity index 94% rename from homectrl/src/main/java/org/atennert/homectrl/util/ConfigurationField.java rename to homectrl/src/main/java/de/atennert/homectrl/util/ConfigurationField.java index 442e818..7401d45 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/util/ConfigurationField.java +++ b/homectrl/src/main/java/de/atennert/homectrl/util/ConfigurationField.java @@ -1,4 +1,4 @@ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/homectrl/src/main/java/org/atennert/homectrl/util/DeviceValue.java b/homectrl/src/main/java/de/atennert/homectrl/util/DeviceValue.java similarity index 97% rename from homectrl/src/main/java/org/atennert/homectrl/util/DeviceValue.java rename to homectrl/src/main/java/de/atennert/homectrl/util/DeviceValue.java index 83b9acf..1bf3bff 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/util/DeviceValue.java +++ b/homectrl/src/main/java/de/atennert/homectrl/util/DeviceValue.java @@ -14,7 +14,7 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/homectrl/src/main/java/org/atennert/homectrl/util/Pair.java b/homectrl/src/main/java/de/atennert/homectrl/util/Pair.java similarity index 85% rename from homectrl/src/main/java/org/atennert/homectrl/util/Pair.java rename to homectrl/src/main/java/de/atennert/homectrl/util/Pair.java index b0003ff..75121b6 100644 --- a/homectrl/src/main/java/org/atennert/homectrl/util/Pair.java +++ b/homectrl/src/main/java/de/atennert/homectrl/util/Pair.java @@ -1,5 +1,5 @@ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; public class Pair { diff --git a/homectrl/src/test/java/org/atennert/homectrl/TestUtils.java b/homectrl/src/test/java/de/atennert/homectrl/TestUtils.java similarity index 97% rename from homectrl/src/test/java/org/atennert/homectrl/TestUtils.java rename to homectrl/src/test/java/de/atennert/homectrl/TestUtils.java index f63a5d3..a5c013c 100644 --- a/homectrl/src/test/java/org/atennert/homectrl/TestUtils.java +++ b/homectrl/src/test/java/de/atennert/homectrl/TestUtils.java @@ -1,5 +1,5 @@ -package org.atennert.homectrl; +package de.atennert.homectrl; import static org.junit.Assert.fail; diff --git a/homectrl/src/test/java/org/atennert/homectrl/event/EventBusTest.java b/homectrl/src/test/java/de/atennert/homectrl/event/EventBusTest.java similarity index 98% rename from homectrl/src/test/java/org/atennert/homectrl/event/EventBusTest.java rename to homectrl/src/test/java/de/atennert/homectrl/event/EventBusTest.java index e986bb4..74375f5 100644 --- a/homectrl/src/test/java/org/atennert/homectrl/event/EventBusTest.java +++ b/homectrl/src/test/java/de/atennert/homectrl/event/EventBusTest.java @@ -1,12 +1,12 @@ -package org.atennert.homectrl.event; +package de.atennert.homectrl.event; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import java.util.concurrent.ExecutorService; -import org.atennert.homectrl.TestUtils; +import de.atennert.homectrl.TestUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/server/readme.txt b/readme.md similarity index 51% rename from server/readme.txt rename to readme.md index ad79ad2..631f9f3 100644 --- a/server/readme.txt +++ b/readme.md @@ -1,21 +1,18 @@ -=================================== - HomeCtrl -=================================== -Contents: -- Introduction -- How to get the example working? -- Device configuration -- Event bus -- How to add control modules? -- How to add data processors? -- Communication protocols -- Copyright +# HomeCtrl +## Contents: -=================================== - Introduction -=================================== +* [Introduction](#intro) +* [How to get the example working?](#make-it-work) +* [Device configuration](#device-config) +* [Event bus](#event-bus) +* [How to add control modules?](#controls) +* [How to add data processors?](#processors) +* [Communication protocols](#protocols) +* [Copyright](#copyright) + +## Introduction HomeCtrl is an event based home or building automation system. The name is constructed from "home" and the label of the English keyboard control button "Ctrl". @@ -26,12 +23,13 @@ and user interfaces using different communication protocols with my COM library current available protocols are HTTP for reading and writing and EnOcean for reading. The HomeCtrl software consists of 6 projects: -- homectrl: the core application -- homectrl-com-if: all the stuff for interacting with the COM library the world beyond that -- sensors: software "sensors" for stuff, that is computed by the server -- dataprocessing: software modules for sensor data preprocessing -- controls: software modules for controlling devices -- server: the application project with all configurations + +* *homectrl*: the core application +* *homectrl-com-if*: all the stuff for interacting with the COM library the world beyond that +* *sensors*: software "sensors" for stuff, that is computed by the server +* *dataprocessing*: software modules for sensor data preprocessing +* *controls*: software modules for controlling devices +* *server*: the application project with all configurations Version 3 of HomeCtrl is the first, where the server can actually control the devices. In versions 2 and earlier, devices where directly controlled by the user and the server was only creating the @@ -41,55 +39,49 @@ behavior of the application is defined in a device configuration file, which is contains all devices, the processors and the controls with their individual settings. -=================================== - How to get the example working? -=================================== +## How to get the example working? + +1. Compile the server project as runnable jar file (simply build the Gradle file in the main directory). +2. Rename example-server.properties to server.properties. +3. Change the data in server.properties to what you like (or go with the default). +4. Rename example-configuration.json to configuration.json. +5. Change the configuration in configuration.json to what your system looks like. This one might be a bit tricky. In case of doubt, check the chapter about device configuration. +6. Start the application and lean back. -- rename example-addresses.properties to addresses.properties -- rename example-configuration.json to configuration.json -- adjust the addresses in both files -Compile the server project as runnable Jar, start the application and have fun :) +## Device configuration -=================================== - Device configuration -=================================== - TODO +**Light at the end of the tunnel ...** + +I know that this manual JSON writing is hideous. I'm planning on a visual tool to create and edit configuration files. It will mostly be colorful clicking and dragging and dropping. Even a simulation mode would be nice. + +Unfortunately, it will probably take a while to get to this point. + -=================================== - Event bus -=================================== +## Event bus TODO -=================================== - How to add control modules? -=================================== +## How to add control modules? TODO -=================================== - How to add data processors? -=================================== +## How to add data processors? TODO -=================================== - Communication protocols -=================================== +## Communication protocols TODO -=================================== - Copyright -=================================== +## Copyright The following copyright license is effective for all resources of the HomeCtrl software, unless there is a different copyright information in or for the resource. If a resource has it's own @@ -97,7 +89,7 @@ copyright information, then the resources license statement replaces the license for this particular resource. -Copyright 2015 Andreas Tennert +Copyright 2016 Andreas Tennert Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/sensors/src/main/java/org/atennert/homectrl/sensors/WeekendSensor.java b/sensors/src/main/java/de/atennert/homectrl/sensors/WeekendSensor.java similarity index 96% rename from sensors/src/main/java/org/atennert/homectrl/sensors/WeekendSensor.java rename to sensors/src/main/java/de/atennert/homectrl/sensors/WeekendSensor.java index 75641a9..b02464e 100644 --- a/sensors/src/main/java/org/atennert/homectrl/sensors/WeekendSensor.java +++ b/sensors/src/main/java/de/atennert/homectrl/sensors/WeekendSensor.java @@ -14,13 +14,13 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.sensors; +package de.atennert.homectrl.sensors; import java.util.Calendar; import java.util.GregorianCalendar; -import org.atennert.homectrl.event.EDeviceValueUpdate; -import org.atennert.homectrl.event.EventBus; +import de.atennert.homectrl.event.EDeviceValueUpdate; +import de.atennert.homectrl.event.EventBus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/server/build.gradle b/server/build.gradle index 72ec363..edc8b33 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -7,14 +7,14 @@ apply plugin: "spring-boot" archivesBaseName = "server" version = "0.0.1" -mainClassName = "org.atennert.homectrl.Main" +mainClassName = "de.atennert.homectrl.Main" jar { baseName = "HomeCtrl" version = "" manifest { - attributes 'Main-Class': 'org.atennert.homectrl.Main' + attributes 'Main-Class': 'de.atennert.homectrl.Main' } from { @@ -31,6 +31,8 @@ dependencies { compile project(':dataprocessing') compile project(':controls') compile project(':sensors') - compile "org.springframework:spring-context:4.0.2.RELEASE" + compile "org.springframework:spring-context:4.3.3.RELEASE" + compile "org.springframework:spring-jdbc:4.3.3.RELEASE" + compile "org.xerial:sqlite-jdbc:3.14+" compile "org.json:json:20140107" } diff --git a/server/src/main/java/org/atennert/homectrl/Main.java b/server/src/main/java/de/atennert/homectrl/Main.java similarity index 98% rename from server/src/main/java/org/atennert/homectrl/Main.java rename to server/src/main/java/de/atennert/homectrl/Main.java index 1e12059..9c56fe3 100644 --- a/server/src/main/java/org/atennert/homectrl/Main.java +++ b/server/src/main/java/de/atennert/homectrl/Main.java @@ -14,7 +14,7 @@ * limitations under the License. *******************************************************************************/ -package org.atennert.homectrl; +package de.atennert.homectrl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/server/src/main/java/org/atennert/homectrl/util/DeviceDescriptionFactory.java b/server/src/main/java/de/atennert/homectrl/util/DeviceDescriptionFactory.java similarity index 95% rename from server/src/main/java/org/atennert/homectrl/util/DeviceDescriptionFactory.java rename to server/src/main/java/de/atennert/homectrl/util/DeviceDescriptionFactory.java index a41ca87..0a2b10a 100644 --- a/server/src/main/java/org/atennert/homectrl/util/DeviceDescriptionFactory.java +++ b/server/src/main/java/de/atennert/homectrl/util/DeviceDescriptionFactory.java @@ -14,7 +14,19 @@ * the License. *******************************************************************************/ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; + +import de.atennert.homectrl.registration.NodeDescription; +import de.atennert.homectrl.DataType; +import de.atennert.homectrl.controls.AbstractController; +import de.atennert.homectrl.dataprocessing.AbstractDataProcessor; +import de.atennert.homectrl.registration.DataDescription; +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -23,23 +35,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.atennert.homectrl.DataType; -import org.atennert.homectrl.controls.AbstractController; -import org.atennert.homectrl.dataprocessing.AbstractDataProcessor; -import org.atennert.homectrl.registration.DataDescription; -import org.atennert.homectrl.registration.NodeDescription; -import org.json.JSONArray; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; +import java.util.*; public class DeviceDescriptionFactory { @@ -71,7 +67,7 @@ private final void loadConfiguration(String configuration) controls = new HashSet>(); defaultValues = new HashMap(); - Resource resource = new ClassPathResource(configuration); + Resource resource = new FileSystemResource(configuration); try { BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream())); diff --git a/server/src/main/java/org/atennert/homectrl/util/EventBusPostProcessor.java b/server/src/main/java/de/atennert/homectrl/util/EventBusPostProcessor.java similarity index 94% rename from server/src/main/java/org/atennert/homectrl/util/EventBusPostProcessor.java rename to server/src/main/java/de/atennert/homectrl/util/EventBusPostProcessor.java index 283ccc1..2ef6b2f 100644 --- a/server/src/main/java/org/atennert/homectrl/util/EventBusPostProcessor.java +++ b/server/src/main/java/de/atennert/homectrl/util/EventBusPostProcessor.java @@ -7,13 +7,13 @@ * Use it as you see fit, and entirely at your own risk. */ -package org.atennert.homectrl.util; +package de.atennert.homectrl.util; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import org.atennert.homectrl.event.EventBus; -import org.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.event.Subscribe; +import de.atennert.homectrl.event.EventBus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; diff --git a/server/src/main/java/de/atennert/homectrl/util/ServerIOLogger.java b/server/src/main/java/de/atennert/homectrl/util/ServerIOLogger.java new file mode 100644 index 0000000..83a5630 --- /dev/null +++ b/server/src/main/java/de/atennert/homectrl/util/ServerIOLogger.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright 2016 Andreas Tennert + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + *******************************************************************************/ +package de.atennert.homectrl.util; + +import de.atennert.homectrl.registration.DataDescription; +import org.springframework.beans.factory.annotation.Required; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * This class is used to log incoming and outgoing data to a database. + */ +public class ServerIOLogger implements EventObserver +{ + private static final String INSERT_HOST_STATEMENT = + "INSERT INTO hosts (host_name, device_ref) " + + "VALUES (?, ?)"; + + private static final String INSERT_EVENT_STATEMENT = + "INSERT INTO events (host, value) " + + "VALUES ( (SELECT host_id FROM hosts " + + "WHERE host_name = ? and device_ref = ?), ?)"; + + private JdbcTemplate sqliteAccess; + private Set dataDescriptions; + + @Required + public void setDataSource( DataSource dataSource ) + { + this.sqliteAccess = new JdbcTemplate( dataSource ); + } + + @Required + public void setDataDescriptions( Set dataDescriptions ) + { + this.dataDescriptions = dataDescriptions; + } + + public void init() + { + List hostData = dataDescriptions.stream() + .map( d -> new Object[]{d.hostName, d.referenceId} ) + .collect( Collectors.toList() ); + + sqliteAccess.batchUpdate( INSERT_HOST_STATEMENT, hostData ); + } + + @Override + public void notify( DataDescription description, Object value ) + { + sqliteAccess.update( INSERT_EVENT_STATEMENT, description.hostName, description.referenceId, value ); + } +} diff --git a/server/src/main/resources/example-addresses.properties b/server/src/main/resources/example-addresses.properties deleted file mode 100644 index 21cce27..0000000 --- a/server/src/main/resources/example-addresses.properties +++ /dev/null @@ -1,2 +0,0 @@ -address.homectrl.server.http=192.168.0.2:80 -address.homectrl.server.enocean=/dev/ttyUSB0 diff --git a/server/src/main/resources/homectrlLog-schema.sql b/server/src/main/resources/homectrlLog-schema.sql new file mode 100644 index 0000000..1616787 --- /dev/null +++ b/server/src/main/resources/homectrlLog-schema.sql @@ -0,0 +1,14 @@ + +CREATE TABLE IF NOT EXISTS hosts ( + host_id INTEGER PRIMARY KEY AUTOINCREMENT, + host_name TEXT NOT NULL, + device_ref TEXT NOT NULL, + UNIQUE (host_name, device_ref) ON CONFLICT IGNORE +); + +CREATE TABLE IF NOT EXISTS events ( + event_id INTEGER PRIMARY KEY AUTOINCREMENT, + host INTEGER NOT NULL REFERENCES hosts (host_id), + time DATETIME DEFAULT CURRENT_TIMESTAMP, + value TEXT NOT NULL +); diff --git a/server/src/main/resources/spring/app.xml b/server/src/main/resources/spring/app.xml index 42b4fc7..aeaa8b8 100644 --- a/server/src/main/resources/spring/app.xml +++ b/server/src/main/resources/spring/app.xml @@ -25,6 +25,7 @@ + diff --git a/server/src/main/resources/spring/com.xml b/server/src/main/resources/spring/com.xml index 4eb6d12..1a2a6ad 100644 --- a/server/src/main/resources/spring/com.xml +++ b/server/src/main/resources/spring/com.xml @@ -28,7 +28,15 @@ - + + + + + + + + + @@ -52,32 +60,33 @@ - - + + + - + - + - + - + - + - + @@ -91,20 +100,20 @@ - + - + - + - + - + diff --git a/server/src/main/resources/spring/database.xml b/server/src/main/resources/spring/database.xml new file mode 100644 index 0000000..693a80d --- /dev/null +++ b/server/src/main/resources/spring/database.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/src/main/resources/spring/devices.xml b/server/src/main/resources/spring/devices.xml index f8a6326..595beb4 100644 --- a/server/src/main/resources/spring/devices.xml +++ b/server/src/main/resources/spring/devices.xml @@ -31,14 +31,14 @@ - + - + @@ -46,13 +46,13 @@ - + - + diff --git a/server/src/main/resources/spring/eventBus.xml b/server/src/main/resources/spring/eventBus.xml index 9322fc3..af6f32c 100644 --- a/server/src/main/resources/spring/eventBus.xml +++ b/server/src/main/resources/spring/eventBus.xml @@ -30,8 +30,8 @@ - + - + \ No newline at end of file diff --git a/server/src/main/resources/spring/properties.xml b/server/src/main/resources/spring/properties.xml index 79dae6e..90ce851 100644 --- a/server/src/main/resources/spring/properties.xml +++ b/server/src/main/resources/spring/properties.xml @@ -26,14 +26,16 @@ default-destroy-method="dispose"> - - addresses.properties + + + + - + - +