mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Migrating from from wiringpi to pigpio. This increases the sample rate by a factor of 3 and will allow creation of a board that can monitor over 30 breakers with a single raspberry pi.
This is based on pi4j 2.0 which is in a beta status. I have fixed a few bugs in a local version of pi4j 2.0 to get it to work but I haven't submitted those changes to pi4j yet. This change requires a migration to Java 11 and will *NOT* be backwards compatible. Upgrading to this hub software will require that java 11 and pigpio be installed on the hub. This can be done from an ssh session with the following commands: apt-get update apt-get install openjdk-11-jre-headless apt-get install pigpio Alternatively, you can download a new sd image, reflash your sd card, and re-adopt your hub.
This commit is contained in:
parent
079206fcd7
commit
c8319d6369
|
@ -1,15 +1,15 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-config-currentmonitor</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<name>lantern-config-currentmonitor</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>currentmonitor</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -25,12 +25,12 @@
|
|||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao-mongo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -56,8 +56,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-currentmonitor</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.7</version>
|
||||
<version>1.1.0</version>
|
||||
<name>lantern-currentmonitor</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>currentmonitor</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -24,8 +24,13 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
<artifactId>pi4j-gpio-extension</artifactId>
|
||||
<version>1.3</version>
|
||||
<artifactId>pi4j-core</artifactId>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
<artifactId>pi4j-plugin-pigpio</artifactId>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.hypfvieh</groupId>
|
||||
|
@ -35,12 +40,12 @@
|
|||
<dependency>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-datamodel-currentmonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${cm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-http</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
|
@ -71,8 +76,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package com.lanternsoftware.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.currentmonitor.adc.MCP3008Pin;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.pi4j.io.gpio.GpioPinAnalogInput;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BreakerSamples {
|
||||
private final Breaker breaker;
|
||||
private final GpioPinAnalogInput voltagePin;
|
||||
private final GpioPinAnalogInput currentPin;
|
||||
private final MCP3008Pin voltagePin;
|
||||
private final MCP3008Pin currentPin;
|
||||
private final List<PowerSample> samples;
|
||||
private int cycleCnt;
|
||||
private int sampleCnt;
|
||||
|
||||
public BreakerSamples(Breaker _breaker, GpioPinAnalogInput _voltagePin, GpioPinAnalogInput _currentPin, List<PowerSample> _samples) {
|
||||
public BreakerSamples(Breaker _breaker, MCP3008Pin _voltagePin, MCP3008Pin _currentPin, List<PowerSample> _samples) {
|
||||
breaker = _breaker;
|
||||
voltagePin = _voltagePin;
|
||||
currentPin = _currentPin;
|
||||
|
@ -23,11 +24,11 @@ public class BreakerSamples {
|
|||
return breaker;
|
||||
}
|
||||
|
||||
public GpioPinAnalogInput getVoltagePin() {
|
||||
public MCP3008Pin getVoltagePin() {
|
||||
return voltagePin;
|
||||
}
|
||||
|
||||
public GpioPinAnalogInput getCurrentPin() {
|
||||
public MCP3008Pin getCurrentPin() {
|
||||
return currentPin;
|
||||
}
|
||||
|
||||
|
@ -35,8 +36,20 @@ public class BreakerSamples {
|
|||
return samples;
|
||||
}
|
||||
|
||||
public PowerSample getSample(int _sample) {
|
||||
return samples.get(_sample);
|
||||
public void incrementCycleCnt() {
|
||||
cycleCnt++;
|
||||
}
|
||||
|
||||
public PowerSample incrementSample() {
|
||||
return samples.get(sampleCnt++);
|
||||
}
|
||||
|
||||
public int getCycleCnt() {
|
||||
return cycleCnt;
|
||||
}
|
||||
|
||||
public void setCycleCnt(int _cycleCnt) {
|
||||
cycleCnt = _cycleCnt;
|
||||
}
|
||||
|
||||
public int getSampleCnt() {
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
package com.lanternsoftware.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.currentmonitor.adc.MCP3008;
|
||||
import com.lanternsoftware.currentmonitor.adc.MCP3008Pin;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerHub;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPolarity;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPower;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.concurrency.ConcurrencyUtils;
|
||||
import com.pi4j.gpio.extension.base.AdcGpioProvider;
|
||||
import com.pi4j.gpio.extension.mcp.MCP3008GpioProvider;
|
||||
import com.pi4j.gpio.extension.mcp.MCP3008Pin;
|
||||
import com.pi4j.io.gpio.GpioController;
|
||||
import com.pi4j.io.gpio.GpioFactory;
|
||||
import com.pi4j.io.gpio.GpioPinAnalogInput;
|
||||
import com.pi4j.io.spi.SpiChannel;
|
||||
import com.pi4j.io.spi.SpiDevice;
|
||||
import com.pi4j.Pi4J;
|
||||
import com.pi4j.context.Context;
|
||||
import com.pi4j.io.spi.Spi;
|
||||
import com.pi4j.io.spi.SpiMode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
@ -30,22 +27,15 @@ import java.util.concurrent.Executors;
|
|||
public class CurrentMonitor {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CurrentMonitor.class);
|
||||
private static final int BATCH_CNT = 4;
|
||||
private GpioController gpio;
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
private final Map<Integer, AdcGpioProvider> chips = new HashMap<>();
|
||||
private final Map<Integer, GpioPinAnalogInput> pins = new HashMap<>();
|
||||
private Context pi4j;
|
||||
private final Map<Integer, MCP3008> chips = new HashMap<>();
|
||||
private Sampler sampler;
|
||||
private PowerListener listener;
|
||||
private boolean debug = false;
|
||||
|
||||
public void start() {
|
||||
try {
|
||||
gpio = GpioFactory.getInstance();
|
||||
LOG.info("Current Monitor Started");
|
||||
}
|
||||
catch (Throwable t) {
|
||||
LOG.info("Failed to get gpio factory", t);
|
||||
}
|
||||
pi4j = Pi4J.newAutoContext();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
@ -53,9 +43,12 @@ public class CurrentMonitor {
|
|||
ConcurrencyUtils.sleep(1000);
|
||||
executor.shutdown();
|
||||
ConcurrencyUtils.sleep(1000);
|
||||
for (MCP3008 mcp : chips.values()) {
|
||||
mcp.shutdown(pi4j);
|
||||
}
|
||||
ConcurrencyUtils.sleep(1000);
|
||||
pi4j.shutdown();
|
||||
chips.clear();
|
||||
pins.clear();
|
||||
gpio.shutdown();
|
||||
LOG.info("Power Monitor Service Stopped");
|
||||
}
|
||||
|
||||
|
@ -64,10 +57,9 @@ public class CurrentMonitor {
|
|||
}
|
||||
|
||||
public CalibrationResult calibrateVoltage(double _curCalibration) {
|
||||
GpioPinAnalogInput voltagePin = getPin(0, 0);
|
||||
if (voltagePin == null)
|
||||
return null;
|
||||
int maxSamples = 120000;
|
||||
LOG.info("Calibrating Voltage");
|
||||
MCP3008Pin voltagePin = new MCP3008Pin(getChip(0), 0);
|
||||
int maxSamples = 240000;
|
||||
CalibrationSample[] samples = new CalibrationSample[maxSamples];
|
||||
int offset = 0;
|
||||
for (;offset < maxSamples; offset++) {
|
||||
|
@ -77,7 +69,7 @@ public class CurrentMonitor {
|
|||
long intervalEnd = System.nanoTime() + 2000000000L; //Scan voltage for 2 seconds
|
||||
while (offset < maxSamples) {
|
||||
samples[offset].time = System.nanoTime();
|
||||
samples[offset].voltage = voltagePin.getValue();
|
||||
samples[offset].voltage = voltagePin.read();
|
||||
offset++;
|
||||
if (samples[offset-1].time > intervalEnd)
|
||||
break;
|
||||
|
@ -128,10 +120,12 @@ public class CurrentMonitor {
|
|||
stopMonitoring();
|
||||
listener = _listener;
|
||||
List<Breaker> validBreakers = CollectionUtils.filter(_breakers, _b -> _b.getPort() > 0 && _b.getPort() < 16);
|
||||
if (CollectionUtils.isEmpty(validBreakers))
|
||||
if (CollectionUtils.isEmpty(validBreakers)) {
|
||||
LOG.error("No breakers found for hub number {}", _hub.getHub());
|
||||
return;
|
||||
}
|
||||
LOG.info("Monitoring {} breakers for hub {}", CollectionUtils.size(validBreakers), _hub.getHub());
|
||||
sampler = new Sampler(_hub, validBreakers, _intervalMs, 2);
|
||||
sampler = new Sampler(_hub, validBreakers, _intervalMs, 5);
|
||||
LOG.info("Starting to monitor ports {}", CollectionUtils.transformToCommaSeparated(validBreakers, _b -> String.valueOf(_b.getPort())));
|
||||
executor.submit(sampler);
|
||||
}
|
||||
|
@ -140,34 +134,17 @@ public class CurrentMonitor {
|
|||
}
|
||||
}
|
||||
|
||||
private GpioPinAnalogInput getPin(int _chip, int _pin) {
|
||||
GpioPinAnalogInput pin;
|
||||
synchronized (pins) {
|
||||
AdcGpioProvider chip = chips.get(_chip);
|
||||
private synchronized MCP3008 getChip(int _chip) {
|
||||
MCP3008 chip = chips.get(_chip);
|
||||
if (chip == null) {
|
||||
SpiChannel channel = SpiChannel.getByNumber(_chip);
|
||||
if (channel == null)
|
||||
return null;
|
||||
try {
|
||||
chip = new MCP3008GpioProvider(channel, 1250000, SpiDevice.DEFAULT_SPI_MODE, false);
|
||||
String id = "SPI" + _chip;
|
||||
LOG.info("Creating chip {}", id);
|
||||
Spi spi = pi4j.create(Spi.newConfigBuilder(pi4j).mode(SpiMode.MODE_0).id(id).name("MCP3008_" + _chip).address(_chip).baud(810000).build());
|
||||
LOG.info("is open {}", spi.isOpen());
|
||||
chip = new MCP3008(spi);
|
||||
chips.put(_chip, chip);
|
||||
} catch (IOException _e) {
|
||||
LOG.error("Failed to connect to chip {}", _chip, _e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
int pinKey = pinKey(_chip, _pin);
|
||||
pin = pins.get(pinKey);
|
||||
if (pin == null) {
|
||||
pin = gpio.provisionAnalogInputPin(chip, MCP3008Pin.ALL[_pin], String.valueOf(pinKey));
|
||||
pins.put(pinKey, pin);
|
||||
}
|
||||
}
|
||||
return pin;
|
||||
}
|
||||
|
||||
private Integer pinKey(int _chip, int _pin) {
|
||||
return (_chip*8)+_pin;
|
||||
return chip;
|
||||
}
|
||||
|
||||
public void submit(Runnable _runnable) {
|
||||
|
@ -190,14 +167,14 @@ public class CurrentMonitor {
|
|||
|
||||
public Sampler(BreakerHub _hub, List<Breaker> _breakers, int _intervalMs, int _concurrentBreakerCnt) {
|
||||
hub = _hub;
|
||||
GpioPinAnalogInput voltagePin = getPin(0, 0);
|
||||
MCP3008Pin voltagePin = new MCP3008Pin(getChip(0), 0);
|
||||
breakers = CollectionUtils.transform(_breakers, _b->{
|
||||
LOG.info("Getting Chip {}, Pin {} for port {}", _b.getChip(), _b.getPin(), _b.getPort());
|
||||
GpioPinAnalogInput currentPin = getPin(_b.getChip(), _b.getPin());
|
||||
MCP3008Pin currentPin = new MCP3008Pin(getChip(_b.getChip()), _b.getPin());
|
||||
List<BreakerSamples> batches = new ArrayList<>(BATCH_CNT);
|
||||
for (int i=0; i<BATCH_CNT; i++) {
|
||||
List<PowerSample> samples = new ArrayList<>(30000/_breakers.size());
|
||||
for (int j=0; j<30000/_breakers.size(); j++) {
|
||||
for (int j=0; j<60000/_breakers.size(); j++) {
|
||||
samples.add(new PowerSample());
|
||||
}
|
||||
batches.add(new BreakerSamples(_b, voltagePin, currentPin, samples));
|
||||
|
@ -213,6 +190,7 @@ public class CurrentMonitor {
|
|||
long start = System.nanoTime();
|
||||
long interval = 0;
|
||||
int cycle;
|
||||
int curBreaker;
|
||||
BreakerSamples[] cycleBreakers = new BreakerSamples[concurrentBreakerCnt];
|
||||
try {
|
||||
while (true) {
|
||||
|
@ -227,22 +205,18 @@ public class CurrentMonitor {
|
|||
long intervalEnd = intervalStart + intervalNs;
|
||||
cycle = 0;
|
||||
final int batch = (int) (interval % BATCH_CNT);
|
||||
int curBreaker;
|
||||
for (curBreaker = 0; curBreaker < breakers.size(); curBreaker++) {
|
||||
breakers.get(curBreaker).get(batch).setSampleCnt(0);
|
||||
}
|
||||
while (System.nanoTime() < intervalEnd) {
|
||||
for (curBreaker = 0; curBreaker < concurrentBreakerCnt; curBreaker++) {
|
||||
cycleBreakers[curBreaker] = breakers.get(((cycle * concurrentBreakerCnt) + curBreaker) % breakers.size()).get(batch);
|
||||
cycleBreakers[curBreaker].incrementCycleCnt();
|
||||
}
|
||||
cycle++;
|
||||
long cycleEnd = intervalStart + (cycle * (intervalNs / hub.getFrequency()));
|
||||
while (System.nanoTime() < cycleEnd) {
|
||||
for (curBreaker = 0; curBreaker < concurrentBreakerCnt; curBreaker++) {
|
||||
PowerSample sample = cycleBreakers[curBreaker].getSample(cycleBreakers[curBreaker].getSampleCnt());
|
||||
sample.voltage = cycleBreakers[curBreaker].getVoltagePin().getValue();
|
||||
sample.current = cycleBreakers[curBreaker].getCurrentPin().getValue();
|
||||
cycleBreakers[curBreaker].setSampleCnt(cycleBreakers[curBreaker].getSampleCnt()+1);
|
||||
PowerSample sample = cycleBreakers[curBreaker].incrementSample();
|
||||
sample.voltage = cycleBreakers[curBreaker].getVoltagePin().read();
|
||||
sample.current = cycleBreakers[curBreaker].getCurrentPin().read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,10 +258,11 @@ public class CurrentMonitor {
|
|||
if (debug) {
|
||||
synchronized (CurrentMonitor.this) {
|
||||
LOG.info("===========================Start Port {}", samples.getBreaker().getPort());
|
||||
LOG.info("Cycles: {}", samples.getCycleCnt());
|
||||
LOG.info("Samples: {}", samples.getSampleCnt());
|
||||
LOG.info("vMin: {}, vMax: {}, vOffset: {}", String.format("%.3f", CollectionUtils.getSmallest(validSamples, Comparator.comparing(_v -> _v.voltage)).voltage), String.format("%.3f", CollectionUtils.getLargest(validSamples, Comparator.comparing(_v -> _v.voltage)).voltage), String.format("%.3f", vOffset));
|
||||
LOG.info("iMin: {}, iMax: {}, iOffset: {}", String.format("%.3f", CollectionUtils.getSmallest(validSamples, Comparator.comparing(_v -> _v.current)).current), String.format("%.3f", CollectionUtils.getLargest(validSamples, Comparator.comparing(_v -> _v.current)).current), String.format("%.3f", iOffset));
|
||||
double iRms = samples.getBreaker().getFinalCalibrationFactor() * Math.sqrt(CollectionUtils.mean(CollectionUtils.transform(validSamples, _p -> _p.current * _p.current)));
|
||||
double iRms = hub.getPortCalibrationFactor() * samples.getBreaker().getFinalCalibrationFactor() * Math.sqrt(CollectionUtils.mean(CollectionUtils.transform(validSamples, _p -> _p.current * _p.current)));
|
||||
LOG.info("vRms: {}", String.format("%.3f", vRms));
|
||||
LOG.info("iRms: {}", String.format("%.3f", iRms));
|
||||
double apparentPower = vRms * iRms;
|
||||
|
@ -298,6 +273,8 @@ public class CurrentMonitor {
|
|||
LOG.info("===========================End Port {}", samples.getBreaker().getPort());
|
||||
}
|
||||
}
|
||||
samples.setSampleCnt(0);
|
||||
samples.setCycleCnt(0);
|
||||
listener.onPowerEvent(new BreakerPower(samples.getBreaker().getPanel(), samples.getBreaker().getSpace(), readTime, realPower, vRms));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -35,12 +35,9 @@ import org.apache.http.entity.ContentType;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Console;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
@ -210,8 +207,8 @@ public class MonitorApp {
|
|||
version = getVersionNumber();
|
||||
config = DaoSerializer.parse(ResourceLoader.loadFileAsString(WORKING_DIR + "config.json"), MonitorConfig.class);
|
||||
if (config == null) {
|
||||
LOG.error("Failed to load config file from {}", WORKING_DIR + "config.json");
|
||||
return;
|
||||
config = new MonitorConfig();
|
||||
ResourceLoader.writeFile(WORKING_DIR + "config.json", DaoSerializer.toJson(config));
|
||||
}
|
||||
pool = new HttpPool(10, 10, config.getSocketTimeout(), config.getConnectTimeout(), config.getSocketTimeout());
|
||||
if (NullUtils.isNotEmpty(config.getHost()))
|
||||
|
@ -219,8 +216,6 @@ public class MonitorApp {
|
|||
monitor.setDebug(config.isDebug());
|
||||
monitor.start();
|
||||
LEDFlasher.setLEDOn(false);
|
||||
bluetoothConfig = new BluetoothConfig("Lantern Hub", bluetoothListener);
|
||||
bluetoothConfig.start();
|
||||
if (NullUtils.isNotEmpty(config.getAuthCode()))
|
||||
authCode = config.getAuthCode();
|
||||
else if (NullUtils.isNotEmpty(host) && NullUtils.isNotEmpty(config.getUsername()) && NullUtils.isNotEmpty(config.getPassword())) {
|
||||
|
@ -231,7 +226,8 @@ public class MonitorApp {
|
|||
if (NullUtils.isNotEmpty(config.getMqttBrokerUrl()))
|
||||
mqttPoster = new MqttPoster(config);
|
||||
if (NullUtils.isNotEmpty(host) && NullUtils.isNotEmpty(authCode)) {
|
||||
while (true) {
|
||||
int configAttempts = 0;
|
||||
while (configAttempts < 5) {
|
||||
HttpGet get = new HttpGet(host + "config");
|
||||
get.addHeader("auth_code", authCode);
|
||||
breakerConfig = DaoSerializer.parse(pool.executeToString(get), BreakerConfig.class);
|
||||
|
@ -239,8 +235,11 @@ public class MonitorApp {
|
|||
break;
|
||||
LOG.error("Failed to load breaker config. Retrying in 5 seconds...");
|
||||
ConcurrencyUtils.sleep(5000);
|
||||
configAttempts++;
|
||||
}
|
||||
}
|
||||
bluetoothConfig = new BluetoothConfig("Lantern Hub", bluetoothListener);
|
||||
bluetoothConfig.start();
|
||||
if ((mqttPoster != null) && (breakerConfig == null)) {
|
||||
LOG.info("Hub not configured by a Lantern Power Monitor server, defaulting to MQTT mode only");
|
||||
BreakerHub hub = new BreakerHub();
|
||||
|
@ -266,6 +265,7 @@ public class MonitorApp {
|
|||
BreakerHub hub = breakerConfig.getHub(config.getHub());
|
||||
if (hub != null) {
|
||||
if (config.isNeedsCalibration()) {
|
||||
try {
|
||||
CalibrationResult cal = monitor.calibrateVoltage(hub.getVoltageCalibrationFactor());
|
||||
if (cal != null) {
|
||||
hub.setVoltageCalibrationFactor(cal.getVoltageCalibrationFactor());
|
||||
|
@ -275,6 +275,10 @@ public class MonitorApp {
|
|||
post(DaoSerializer.toZipBson(breakerConfig), "config");
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
LOG.error("Exception trying to read from voltage pin", t);
|
||||
}
|
||||
}
|
||||
List<Breaker> breakers = breakerConfig.getBreakersForHub(config.getHub());
|
||||
monitor.monitorPower(hub, breakers, 1000, logger);
|
||||
}
|
||||
|
@ -288,18 +292,10 @@ public class MonitorApp {
|
|||
monitor.stop();
|
||||
pool.shutdown();
|
||||
}, "Monitor Shutdown"));
|
||||
Console c = System.console();
|
||||
BufferedReader reader = (c == null)?new BufferedReader(new InputStreamReader(System.in)):null;
|
||||
while (running.get()) {
|
||||
try {
|
||||
String command = c != null ? c.readLine() : reader.readLine();
|
||||
if (NullUtils.isEqual("exit", command))
|
||||
break;
|
||||
}
|
||||
catch (Exception _e) {
|
||||
LOG.error("Exception while reading from console input", _e);
|
||||
break;
|
||||
}
|
||||
monitor.wait();
|
||||
} catch (InterruptedException _e) {
|
||||
LOG.error("Interrupted, shutting down", _e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,7 +356,7 @@ public class MonitorApp {
|
|||
byte[] payload = DaoSerializer.toZipBson(minutePost);
|
||||
if (!post(payload, "power/hub")) {
|
||||
LOG.info("Failed Posting HubPowerMinute, writing cache");
|
||||
ResourceLoader.writeFile(WORKING_DIR + "cache/" + UUID.randomUUID().toString() + ".min", payload);
|
||||
ResourceLoader.writeFile(WORKING_DIR + "cache/" + UUID.randomUUID() + ".min", payload);
|
||||
}
|
||||
}
|
||||
if (post != null) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.lanternsoftware.currentmonitor;
|
|||
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -12,11 +13,11 @@ public class MonitorConfig {
|
|||
private String authCode;
|
||||
private String username;
|
||||
private String password;
|
||||
private int hub;
|
||||
private int hub = -1;
|
||||
private boolean debug;
|
||||
private int connectTimeout;
|
||||
private int socketTimeout;
|
||||
private boolean needsCalibration;
|
||||
private boolean needsCalibration = true;
|
||||
private String mqttBrokerUrl;
|
||||
private String mqttUserName;
|
||||
private String mqttPassword;
|
||||
|
@ -34,7 +35,7 @@ public class MonitorConfig {
|
|||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
return NullUtils.isEmpty(host) ? "https://lanternpowermonitor.com/" : host;
|
||||
}
|
||||
|
||||
public void setHost(String _host) {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.lanternsoftware.currentmonitor.adc;
|
||||
|
||||
import com.pi4j.context.Context;
|
||||
import com.pi4j.io.spi.Spi;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MCP3008 {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MCP3008.class);
|
||||
private static final byte[][] pins = new byte[8][];
|
||||
|
||||
private final Spi spi;
|
||||
private final byte[] resp = new byte[3];
|
||||
|
||||
static {
|
||||
for (int p = 0; p < 8; p++) {
|
||||
pins[p] = new byte[]{1,(byte)(p + 8 << 4),0};
|
||||
}
|
||||
}
|
||||
|
||||
public MCP3008(Spi _spi) {
|
||||
spi = _spi;
|
||||
}
|
||||
|
||||
public void shutdown(Context _pi4j) {
|
||||
spi.close();
|
||||
spi.shutdown(_pi4j);
|
||||
}
|
||||
|
||||
public int readPin(int _pin) {
|
||||
if (spi.transfer(pins[_pin], resp) > 2) {
|
||||
return ((resp[1] & 0x03) << 8) + (resp[2] & 0xFF);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.lanternsoftware.currentmonitor.adc;
|
||||
|
||||
public class MCP3008Pin {
|
||||
private final MCP3008 chip;
|
||||
private final int pin;
|
||||
|
||||
public MCP3008Pin(MCP3008 _chip, int _pin) {
|
||||
chip = _chip;
|
||||
pin = _pin;
|
||||
}
|
||||
|
||||
public int read() {
|
||||
return chip.readPin(pin);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
</appender>
|
||||
|
||||
<logger name="com.lanternsoftware" level="INFO"/>
|
||||
<logger name="com.pi4j" level="INFO"/>
|
||||
|
||||
<root level="OFF">
|
||||
<appender-ref ref="FILE"/>
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-dataaccess-currentmonitor</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<name>lantern-dataaccess-currentmonitor</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>currentmonitor</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-datamodel-currentmonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${cm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-datamodel-rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${rules.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao-mongo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mindrot</groupId>
|
||||
|
@ -56,8 +56,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -54,6 +54,7 @@ public interface CurrentMonitorDao {
|
|||
String getAuthCodeForEmail(String _email, TimeZone _tz);
|
||||
Account authCodeToAccount(String _authCode);
|
||||
AuthCode decryptAuthCode(String _authCode);
|
||||
String exchangeAuthCode(String _authCode, int _acctId);
|
||||
|
||||
Account putAccount(Account _account);
|
||||
Account getAccount(int _accountId);
|
||||
|
|
|
@ -90,6 +90,9 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
updateEnergySummaries(minute);
|
||||
}
|
||||
proxy.delete(DirtyMinute.class, new DaoQuery());
|
||||
if (!proxy.exists(Sequence.class, null)) {
|
||||
proxy.save(new Sequence());
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
@ -303,7 +306,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
TimeZone tz = getTimeZoneForAccount(_accountId);
|
||||
Date month = DateUtils.getStartOfMonth(range.getStart(), tz);
|
||||
Date end = DateUtils.getEndOfMonth(range.getEnd(), tz);
|
||||
while (month.before(end)) {
|
||||
while ((month != null) && month.before(end)) {
|
||||
statuses.computeIfAbsent(month, _m->new ArchiveStatus(_accountId, _m, 0));
|
||||
month = DateUtils.addMonths(month, 1, tz);
|
||||
}
|
||||
|
@ -326,6 +329,8 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
TimeZone tz = getTimeZoneForAccount(_minute.getAccountId());
|
||||
BreakerConfig config = getConfig(_minute.getAccountId());
|
||||
BreakerGroup group = CollectionUtils.getFirst(config.getBreakerGroups());
|
||||
if (group == null)
|
||||
return;
|
||||
Date day = DateUtils.getMidnightBefore(_minute.getMinuteAsDate(), tz);
|
||||
DebugTimer t2 = new DebugTimer("Updating energy", logger);
|
||||
EnergySummary energy = getEnergySummary(_minute.getAccountId(), group.getId(), EnergyViewMode.DAY, day);
|
||||
|
@ -412,13 +417,13 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
putEnergySummary(summary);
|
||||
}
|
||||
|
||||
private void updateChargeSummary(BreakerConfig _config, EnergySummary _energySummary, TimeZone _tz) {
|
||||
public void updateChargeSummary(BreakerConfig _config, EnergySummary _energySummary, TimeZone _tz) {
|
||||
Date lookback = null;
|
||||
for (BillingPlan p : CollectionUtils.makeNotNull(_config.getBillingPlans())) {
|
||||
Date cycleStart = p.getBillingCycleStart(_energySummary.getStart(), _tz);
|
||||
if (cycleStart.after(_energySummary.getStart()))
|
||||
cycleStart = DateUtils.addMonths(cycleStart, -1, _tz);
|
||||
if ((lookback == null) || cycleStart.before(lookback))
|
||||
if ((lookback == null) || ((cycleStart != null) && cycleStart.before(lookback)))
|
||||
lookback = cycleStart;
|
||||
}
|
||||
if (lookback != null) {
|
||||
|
@ -462,7 +467,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
Date yearMonthStart = yearStart;
|
||||
Set<String> monthSummaryIds = new HashSet<>();
|
||||
Date loopEnd = DateUtils.addDays(yearEnd, 1, _tz);
|
||||
while (yearMonthStart.before(loopEnd)) {
|
||||
while ((yearMonthStart != null) && yearMonthStart.before(loopEnd)) {
|
||||
Date billingStart = plan.getBillingCycleStart(yearMonthStart, _tz);
|
||||
if (DateUtils.isBetween(billingStart, yearStart, yearEnd))
|
||||
monthSummaryIds.add(ChargeSummary.toId(rootGroup.getAccountId(), plan.getPlanId(), rootGroup.getId(), EnergyViewMode.MONTH, billingStart));
|
||||
|
@ -691,6 +696,11 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
return (account == null)?null:toAuthCode(account.getId(), account.getAuxiliaryAccountIds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String exchangeAuthCode(String _authCode, int _acctId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toAuthCode(int _acctId, List<Integer> _auxAcctIds) {
|
||||
if (_acctId < 1)
|
||||
return null;
|
||||
|
@ -777,6 +787,8 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
|||
if (entity == null)
|
||||
return false;
|
||||
Account acct = getAccountByUsername(aes.decryptFromBase64ToString(_key));
|
||||
if (acct == null)
|
||||
return false;
|
||||
acct.setPassword(_password);
|
||||
putAccount(acct);
|
||||
proxy.delete("password_reset", new DaoQuery("_id", _key));
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-datamodel-currentmonitor</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<name>lantern-datamodel-currentmonitor</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>currentmonitor</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -41,8 +41,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BreakerHub implements IIdentical<BreakerHub> {
|
|||
}
|
||||
|
||||
public double getPortCalibrationFactor() {
|
||||
return portCalibrationFactor == 0.0?1.25:portCalibrationFactor;
|
||||
return portCalibrationFactor == 0.0?1.20:portCalibrationFactor;
|
||||
}
|
||||
|
||||
public void setPortCalibrationFactor(double _portCalibrationFactor) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
@DBSerializable
|
||||
public class EmailCredentials {
|
||||
private EmailProvider provider;
|
||||
private String apiKey;
|
||||
private String apiSecret;
|
||||
private String emailFrom;
|
||||
private String serverUrlBase;
|
||||
|
||||
public EmailProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public void setProvider(EmailProvider _provider) {
|
||||
provider = _provider;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String _apiKey) {
|
||||
apiKey = _apiKey;
|
||||
}
|
||||
|
||||
public String getApiSecret() {
|
||||
return apiSecret;
|
||||
}
|
||||
|
||||
public void setApiSecret(String _apiSecret) {
|
||||
apiSecret = _apiSecret;
|
||||
}
|
||||
|
||||
public String getEmailFrom() {
|
||||
return emailFrom;
|
||||
}
|
||||
|
||||
public void setEmailFrom(String _emailFrom) {
|
||||
emailFrom = _emailFrom;
|
||||
}
|
||||
|
||||
public String getServerUrlBase() {
|
||||
return serverUrlBase;
|
||||
}
|
||||
|
||||
public void setServerUrlBase(String _serverUrlBase) {
|
||||
serverUrlBase = _serverUrlBase;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
public enum EmailProvider {
|
||||
SENDGRID,
|
||||
MAILJET
|
||||
}
|
|
@ -21,7 +21,7 @@ public enum HubConfigCharacteristic {
|
|||
Shutdown(13, CharacteristicFlag.WRITE),
|
||||
Version(14, CharacteristicFlag.READ),
|
||||
Update(15, CharacteristicFlag.WRITE),
|
||||
ReloadConfig(15, CharacteristicFlag.WRITE);
|
||||
ReloadConfig(16, CharacteristicFlag.WRITE);
|
||||
|
||||
public final int idx;
|
||||
public final UUID uuid;
|
||||
|
|
|
@ -36,6 +36,10 @@ public class NetworkStatus {
|
|||
pingSuccessful = _pingSuccessful;
|
||||
}
|
||||
|
||||
public boolean isNetworkConnected() {
|
||||
return isWifiConnected() || isEthernetConnected();
|
||||
}
|
||||
|
||||
public boolean isWifiConnected() {
|
||||
return CollectionUtils.isNotEmpty(wifiIPs);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EmailCredentials;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EmailProvider;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class EmailCredentialsSerializer extends AbstractDaoSerializer<EmailCredentials>
|
||||
{
|
||||
@Override
|
||||
public Class<EmailCredentials> getSupportedClass()
|
||||
{
|
||||
return EmailCredentials.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(EmailCredentials _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("provider", DaoSerializer.toEnumName(_o.getProvider()));
|
||||
d.put("api_key", _o.getApiKey());
|
||||
d.put("api_secret", _o.getApiSecret());
|
||||
d.put("email_from", _o.getEmailFrom());
|
||||
d.put("server_url_base", _o.getServerUrlBase());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmailCredentials fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
EmailCredentials o = new EmailCredentials();
|
||||
o.setProvider(DaoSerializer.getEnum(_d, "provider", EmailProvider.class));
|
||||
o.setApiKey(DaoSerializer.getString(_d, "api_key"));
|
||||
o.setApiSecret(DaoSerializer.getString(_d, "api_secret"));
|
||||
o.setEmailFrom(DaoSerializer.getString(_d, "email_from"));
|
||||
o.setServerUrlBase(DaoSerializer.getString(_d, "server_url_base"));
|
||||
return o;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ com.lanternsoftware.datamodel.currentmonitor.dao.BreakerPowerSerializer
|
|||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.ChargeSummarySerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.ChargeTotalSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EmailCredentialsSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergyBlockSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergySummarySerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergyTotalSerializer
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-service-currentmonitor</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<name>lantern-service-currentmonitor</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>currentmonitor</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -33,18 +32,18 @@
|
|||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-servlet</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-http</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-service-rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${rules.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
|
@ -67,9 +66,9 @@
|
|||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sendgrid</groupId>
|
||||
<artifactId>sendgrid-java</artifactId>
|
||||
<version>4.7.2</version>
|
||||
<groupId>com.mailjet</groupId>
|
||||
<artifactId>mailjet-client</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -95,8 +94,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.lanternsoftware.currentmonitor.email;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EmailCredentials;
|
||||
|
||||
public interface IEmailProvider {
|
||||
int sendTextEmail(EmailCredentials _credentials, String _to, String _subject, String _message);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.lanternsoftware.currentmonitor.email;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EmailCredentials;
|
||||
import com.mailjet.client.ClientOptions;
|
||||
import com.mailjet.client.MailjetClient;
|
||||
import com.mailjet.client.MailjetRequest;
|
||||
import com.mailjet.client.MailjetResponse;
|
||||
import com.mailjet.client.resource.Emailv31;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MailJetProvider implements IEmailProvider {
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(MailJetProvider.class);
|
||||
|
||||
@Override
|
||||
public int sendTextEmail(EmailCredentials _credentials, String _to, String _subject, String _message) {
|
||||
MailjetClient client;
|
||||
MailjetRequest request;
|
||||
MailjetResponse response;
|
||||
client = new MailjetClient(_credentials.getApiKey(), _credentials.getApiSecret(), new ClientOptions("v3.1"));
|
||||
request = new MailjetRequest(Emailv31.resource).property(Emailv31.MESSAGES, new JSONArray().put(new JSONObject()
|
||||
.put(Emailv31.Message.FROM, new JSONObject().put("Email", _credentials.getEmailFrom()).put("Name", "Lantern Power Monitor"))
|
||||
.put(Emailv31.Message.TO, new JSONArray().put(new JSONObject().put("Email", _to)))
|
||||
.put(Emailv31.Message.SUBJECT, _subject)
|
||||
.put(Emailv31.Message.TEXTPART, _message)));
|
||||
try {
|
||||
response = client.post(request);
|
||||
return response.getStatus();
|
||||
} catch (Exception _e) {
|
||||
LOG.error("Failed to send email", _e);
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.lanternsoftware.currentmonitor.email;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EmailCredentials;
|
||||
|
||||
public class SendGridProvider implements IEmailProvider {
|
||||
@Override
|
||||
public int sendTextEmail(EmailCredentials _credentials, String _to, String _subject, String _message) {
|
||||
/* Email to = new Email(email);
|
||||
Content content = new Content("text/plain", "Reset your password using this link:\nhttps://lanternpowermonitor.com/currentmonitor/resetPassword/" + key);
|
||||
Mail mail = new Mail(from, subject, to, content);
|
||||
SendGrid sg = new SendGrid(api_key);
|
||||
Request request = new Request();
|
||||
try {
|
||||
request.setMethod(Method.POST);
|
||||
request.setEndpoint("mail/send");
|
||||
request.setBody(mail.build());
|
||||
Response response = sg.api(request);
|
||||
LOG.info("Password reset email status: {}\nfrom: {}\nto: {}\nkey: {}\nhost: {}", response.getStatusCode(), from.getEmail(), to.getEmail(), api_key, sg.getHost());
|
||||
zipBsonResponse(_resp, new DaoEntity("success", response.getStatusCode() == 200));
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Failed to send password reset email", ex);
|
||||
_resp.setStatus(500);
|
||||
}*/
|
||||
return 500;
|
||||
}
|
||||
}
|
|
@ -1,22 +1,19 @@
|
|||
package com.lanternsoftware.currentmonitor.servlet;
|
||||
|
||||
import com.lanternsoftware.currentmonitor.context.Globals;
|
||||
import com.lanternsoftware.currentmonitor.email.IEmailProvider;
|
||||
import com.lanternsoftware.currentmonitor.email.MailJetProvider;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.Account;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.EmailCredentials;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.external.LanternFiles;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.ResourceLoader;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.email.EmailValidator;
|
||||
import com.lanternsoftware.util.external.LanternFiles;
|
||||
import com.lanternsoftware.util.servlet.FreemarkerConfigUtil;
|
||||
import com.lanternsoftware.util.servlet.FreemarkerServlet;
|
||||
import com.sendgrid.Method;
|
||||
import com.sendgrid.Request;
|
||||
import com.sendgrid.Response;
|
||||
import com.sendgrid.SendGrid;
|
||||
import com.sendgrid.helpers.mail.Mail;
|
||||
import com.sendgrid.helpers.mail.objects.Content;
|
||||
import com.sendgrid.helpers.mail.objects.Email;
|
||||
import freemarker.template.Configuration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -25,13 +22,13 @@ import javax.servlet.annotation.WebServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/resetPassword/*")
|
||||
public class ResetPasswordServlet extends FreemarkerServlet {
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(ResetPasswordServlet.class);
|
||||
protected static final Configuration CONFIG = FreemarkerConfigUtil.createConfig(ResetPasswordServlet.class, "/templates", 100);
|
||||
protected static final String api_key = ResourceLoader.loadFileAsString(LanternFiles.CONFIG_PATH + "sendgrid.txt");
|
||||
protected static final EmailCredentials credentials = DaoSerializer.parse(ResourceLoader.loadFileAsString(LanternFiles.CONFIG_PATH + "email.json"), EmailCredentials.class);
|
||||
protected static final IEmailProvider provider = new MailJetProvider();
|
||||
|
||||
@Override
|
||||
protected Configuration getFreemarkerConfig() {
|
||||
|
@ -63,25 +60,11 @@ public class ResetPasswordServlet extends FreemarkerServlet {
|
|||
} else {
|
||||
DaoEntity payload = getRequestZipBson(_req);
|
||||
String email = DaoSerializer.getString(payload, "email");
|
||||
if (EmailValidator.getInstance().isValid(email)) {
|
||||
Account account = Globals.dao.getAccountByUsername(email);
|
||||
if ((account != null) && EmailValidator.getInstance().isValid(email)) {
|
||||
String key = Globals.dao.addPasswordResetKey(email);
|
||||
Email from = new Email("mark.milligan@lanternsoftware.com");
|
||||
String subject = "Password Reset - Lantern Power Monitor";
|
||||
Email to = new Email(email);
|
||||
Content content = new Content("text/plain", "Reset your password using this link:\nhttps://lanternpowermonitor.com/currentmonitor/resetPassword/" + key);
|
||||
Mail mail = new Mail(from, subject, to, content);
|
||||
SendGrid sg = new SendGrid(api_key);
|
||||
Request request = new Request();
|
||||
try {
|
||||
request.setMethod(Method.POST);
|
||||
request.setEndpoint("mail/send");
|
||||
request.setBody(mail.build());
|
||||
Response response = sg.api(request);
|
||||
zipBsonResponse(_resp, new DaoEntity("success", response.getStatusCode() == 200));
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Failed to send password reset email", ex);
|
||||
_resp.setStatus(500);
|
||||
}
|
||||
int status = provider.sendTextEmail(credentials, email, "Password Reset - Lantern Power Monitor", "Reset your password using this link:\n" + credentials.getServerUrlBase() + "resetPassword/" + key);
|
||||
zipBsonResponse(_resp, new DaoEntity("success", status == 200));
|
||||
}
|
||||
else
|
||||
_resp.setStatus(400);
|
||||
|
|
|
@ -6,10 +6,10 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
|
|||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.lanternsoftware.currentmonitor.context.Globals;
|
||||
import com.lanternsoftware.util.external.LanternFiles;
|
||||
import com.lanternsoftware.util.ResourceLoader;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.external.LanternFiles;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>currentmonitor</artifactId>
|
||||
<name>currentmonitor</name>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware</groupId>
|
||||
<artifactId>LanternPowerMonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>lantern-config-currentmonitor</module>
|
||||
|
|
9
pom.xml
9
pom.xml
|
@ -7,8 +7,13 @@
|
|||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<cm.version>1.1.0</cm.version>
|
||||
<util.version>1.0.0</util.version>
|
||||
<rules.version>1.0.0</rules.version>
|
||||
<zw.version>1.0.0</zw.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-dataaccess-rules</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-dataaccess-rules</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-datamodel-rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${rules.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao-mongo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -46,8 +46,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-datamodel-rules</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-datamodel-rules</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -41,8 +41,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-service-rules</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-service-rules</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -37,17 +37,17 @@
|
|||
<dependency>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-dataaccess-rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${rules.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-dataaccess-currentmonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${cm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-servlet</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
|
@ -84,8 +84,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>rules-reactor</artifactId>
|
||||
<name>rules-reactor</name>
|
||||
<artifactId>rules</artifactId>
|
||||
<name>rules</name>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware</groupId>
|
||||
<artifactId>LanternPowerMonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>lantern-dataaccess-rules</module>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-common</artifactId>
|
||||
<name>lantern-util-common</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
@ -43,8 +47,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao-ephemeral</artifactId>
|
||||
<name>lantern-util-dao-ephemeral</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
|
@ -38,8 +42,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
package com.lanternsoftware.util.dao.ephemeral;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.IFilter;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.ResourceLoader;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoProxy;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoQuery;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoSort;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.IFilter;
|
||||
import com.lanternsoftware.util.ITransformer;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.ResourceLoader;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EphemeralProxy extends AbstractDaoProxy {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EphemeralProxy.class);
|
||||
|
@ -42,11 +39,13 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
try {
|
||||
File file = new File(_path);
|
||||
if (file.isDirectory()) {
|
||||
for (File child : file.listFiles()) {
|
||||
File[] files = file.listFiles();
|
||||
if (files != null) {
|
||||
for (File child : files) {
|
||||
if (child.getName().endsWith(".json")) {
|
||||
Class<?> clazz = null;
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(child.getName().substring(0, child.getName().length()-5));
|
||||
clazz = Class.forName(child.getName().substring(0, child.getName().length() - 5));
|
||||
} catch (ClassNotFoundException _e) {
|
||||
continue;
|
||||
}
|
||||
|
@ -55,6 +54,7 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception _e) {
|
||||
LOG.error("Failed to load directory: " + _path);
|
||||
}
|
||||
|
@ -108,18 +108,14 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
@Override
|
||||
public synchronized void update(Class<?> _class, DaoQuery _query, DaoEntity _changes) {
|
||||
for (DaoEntity entity : queryForEntities(DaoSerializer.getTableName(_class, getType()), _query)) {
|
||||
for (Entry<String, Object> change : _changes.entrySet()) {
|
||||
entity.put(change.getKey(), change.getValue());
|
||||
}
|
||||
entity.putAll(_changes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized <T> T updateOne(Class<T> _class, DaoQuery _query, DaoEntity _changes) {
|
||||
DaoEntity entity = CollectionUtils.getFirst(queryForEntities(DaoSerializer.getTableName(_class, getType()), _query));
|
||||
for (Entry<String, Object> change : _changes.entrySet()) {
|
||||
entity.put(change.getKey(), change.getValue());
|
||||
}
|
||||
entity.putAll(_changes);
|
||||
return DaoSerializer.fromDaoEntity(entity, _class);
|
||||
}
|
||||
|
||||
|
@ -152,18 +148,12 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
}
|
||||
} else if (value instanceof Integer) {
|
||||
if (((Integer) value) == 0) {
|
||||
value = new Long(getNextSequence()).intValue();
|
||||
|
||||
value = Long.valueOf(getNextSequence()).intValue();
|
||||
}
|
||||
}
|
||||
_entity.put(key, value);
|
||||
}
|
||||
pk = CollectionUtils.commaSeparated(CollectionUtils.transform(CollectionUtils.getAll(_entity, _primaryKeys), new ITransformer<Object, String>() {
|
||||
@Override
|
||||
public String transform(Object _o) {
|
||||
return DaoSerializer.toString(_o);
|
||||
}
|
||||
}));
|
||||
pk = CollectionUtils.commaSeparated(CollectionUtils.transform(CollectionUtils.getAll(_entity, _primaryKeys), DaoSerializer::toString));
|
||||
}
|
||||
else
|
||||
pk = DaoSerializer.getString(_entity, "_id");
|
||||
|
@ -187,12 +177,7 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
IFilter<DaoEntity> filter = new QueryFilter(_query);
|
||||
Map<String, DaoEntity> table = tables.get(_tableName);
|
||||
if (table != null) {
|
||||
Iterator<DaoEntity> iter = table.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
DaoEntity entity = iter.next();
|
||||
if (filter.isFiltered(entity))
|
||||
iter.remove();
|
||||
}
|
||||
table.values().removeIf(filter::isFiltered);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -241,16 +226,16 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
if ((comp != null) && !DaoSerializer.getString(_daoEntity, qual.getKey()).toLowerCase().contains(((String) comp).toLowerCase()))
|
||||
return false;
|
||||
comp = child.get("$equalssIgnoreCase");
|
||||
if ((comp != null) && !DaoSerializer.getString(_daoEntity, qual.getKey()).toLowerCase().equals(((String) comp).toLowerCase()))
|
||||
if ((comp != null) && !DaoSerializer.getString(_daoEntity, qual.getKey()).equalsIgnoreCase(((String) comp)))
|
||||
return false;
|
||||
comp = child.get("$startsWithIgnoreCase");
|
||||
if ((comp != null) && !DaoSerializer.getString(_daoEntity, qual.getKey()).toLowerCase().startsWith(((String) comp).toLowerCase()))
|
||||
return false;
|
||||
comp = child.get("$in");
|
||||
if ((comp != null) && !in(_daoEntity.get(qual.getKey()), (Collection) comp))
|
||||
if ((comp != null) && !in(_daoEntity.get(qual.getKey()), (Collection<?>) comp))
|
||||
return false;
|
||||
comp = child.get("$nin");
|
||||
if ((comp != null) && in(_daoEntity.get(qual.getKey()), (Collection) comp))
|
||||
if ((comp != null) && in(_daoEntity.get(qual.getKey()), (Collection<?>) comp))
|
||||
return false;
|
||||
}
|
||||
else if ((qual.getValue() instanceof String) && NullUtils.isEqual(qual.getValue(), "$null")) {
|
||||
|
@ -268,10 +253,10 @@ public class EphemeralProxy extends AbstractDaoProxy {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean in(Object field, Collection qual) {
|
||||
private boolean in(Object field, Collection<?> qual) {
|
||||
for (Object qualObject : qual) {
|
||||
if (field instanceof Collection) {
|
||||
for (Object fieldObject : (Collection) field) {
|
||||
for (Object fieldObject : (Collection<?>) field) {
|
||||
if (NullUtils.isEqual(fieldObject, qualObject))
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao-mongo</artifactId>
|
||||
<name>lantern-util-dao-mongo</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
|
@ -43,8 +47,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<name>lantern-util-dao</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
|
@ -38,8 +42,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.lanternsoftware.util.dao;
|
||||
|
||||
import java.util.Arrays;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -11,10 +13,6 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.ITransformer;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
|
||||
public abstract class AbstractDaoProxy implements IDaoProxy {
|
||||
private ExecutorService executor;
|
||||
private int maxThreads = 50;
|
||||
|
@ -57,37 +55,37 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query));
|
||||
return submit(new QueryExecution<>(this, _class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query, DaoSort _sort) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query, _sort));
|
||||
return submit(new QueryExecution<>(this, _class, _query, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query, _fields));
|
||||
return submit(new QueryExecution<>(this, _class, _query, _fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<List<T>> queryAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort) {
|
||||
return submit(new QueryExecution<T>(this, _class, _query, _fields, _sort));
|
||||
return submit(new QueryExecution<>(this, _class, _query, _fields, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V> Future<List<V>> queryWithFinalizer(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort, QueryFinalizer<T, V> _finalizer) {
|
||||
return submit(new QueryFinalizerExecution<T, V>(this, _class, _query, _fields, _sort, _finalizer));
|
||||
return submit(new QueryFinalizerExecution<>(this, _class, _query, _fields, _sort, _finalizer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DaoPage<T> queryPage(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort, int _offset, int _count) {
|
||||
return new DaoPage<T>(query(_class, _query, _fields, _sort, _offset, _count), count(_class, _query));
|
||||
return new DaoPage<>(query(_class, _query, _fields, _sort, _offset, _count), count(_class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoPage<DaoEntity> queryForEntitiesPage(String _tableName, DaoQuery _query, Collection<String> _fields, DaoSort _sort, int _offset, int _count) {
|
||||
return new DaoPage<DaoEntity>(queryForEntities(_tableName, _query, _fields, _sort, _offset, _count), count(_tableName, _query));
|
||||
return new DaoPage<>(queryForEntities(_tableName, _query, _fields, _sort, _offset, _count), count(_tableName, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,22 +110,22 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query, DaoSort _sort) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query, _sort));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query, _fields));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query, _fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> queryOneAsync(Class<T> _class, DaoQuery _query, Collection<String> _fields, DaoSort _sort) {
|
||||
return submit(new QueryOneExecution<T>(this, _class, _query, _fields, _sort));
|
||||
return submit(new QueryOneExecution<>(this, _class, _query, _fields, _sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,7 +155,7 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
|
||||
@Override
|
||||
public <T> DaoPage<T> queryImportantPage(Class<T> _class, DaoQuery _query, DaoSort _sort, int _offset, int _count) {
|
||||
return new DaoPage<T>(queryImportant(_class, _query, _sort, _offset, _count), count(_class, _query));
|
||||
return new DaoPage<>(queryImportant(_class, _query, _sort, _offset, _count), count(_class, _query));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -247,22 +245,12 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
|
||||
@Override
|
||||
public List<String> queryForField(Class<?> _class, DaoQuery _query, final String _field, DaoSort _sort) {
|
||||
return CollectionUtils.transform(queryForEntities(DaoSerializer.getTableName(_class, getType()), _query, Arrays.asList(_field), _sort), new ITransformer<DaoEntity, String>() {
|
||||
@Override
|
||||
public String transform(DaoEntity _daoEntity) {
|
||||
return DaoSerializer.getString(_daoEntity, _field);
|
||||
}
|
||||
});
|
||||
return CollectionUtils.transform(queryForEntities(DaoSerializer.getTableName(_class, getType()), _query, List.of(_field), _sort), _daoEntity -> DaoSerializer.getString(_daoEntity, _field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryForField(String _tableName, DaoQuery _query, final String _field) {
|
||||
return CollectionUtils.transform(queryForEntities(_tableName, _query, Arrays.asList(_field)), new ITransformer<DaoEntity, String>() {
|
||||
@Override
|
||||
public String transform(DaoEntity _daoEntity) {
|
||||
return DaoSerializer.getString(_daoEntity, _field);
|
||||
}
|
||||
});
|
||||
return CollectionUtils.transform(queryForEntities(_tableName, _query, List.of(_field)), _daoEntity -> DaoSerializer.getString(_daoEntity, _field));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -272,7 +260,7 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
|
||||
@Override
|
||||
public <T> Map<String, T> save(Collection<T> _objects) {
|
||||
Map<String, T> ids = new HashMap<String, T>();
|
||||
Map<String, T> ids = new HashMap<>();
|
||||
for (T o : _objects) {
|
||||
String id = save(o);
|
||||
if (NullUtils.isNotEmpty(id))
|
||||
|
@ -284,6 +272,8 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
@Override
|
||||
public Map<String, DaoEntity> save(Class<?> _class, Collection<DaoEntity> _entities) {
|
||||
Map<String, DaoEntity> ids = new HashMap<>();
|
||||
if (_entities == null)
|
||||
return ids;
|
||||
for (DaoEntity e : _entities) {
|
||||
ids.put(saveEntity(_class, e), e);
|
||||
}
|
||||
|
@ -328,12 +318,7 @@ public abstract class AbstractDaoProxy implements IDaoProxy {
|
|||
}
|
||||
|
||||
protected <T> List<T> toObjects(List<DaoEntity> _entities, final Class<T> _class) {
|
||||
return CollectionUtils.transform(_entities, new ITransformer<DaoEntity, T>() {
|
||||
@Override
|
||||
public T transform(DaoEntity _daoEntity) {
|
||||
return DaoSerializer.fromDaoEntity(_daoEntity, _class, getType());
|
||||
}
|
||||
});
|
||||
return CollectionUtils.transform(_entities, _daoEntity -> DaoSerializer.fromDaoEntity(_daoEntity, _class, getType()));
|
||||
}
|
||||
protected DaoQuery prepareQuery(DaoQuery _query) {
|
||||
if (queryPreparer == null)
|
||||
|
|
|
@ -49,7 +49,7 @@ public class JdbcProxy extends AbstractJdbcProxy {
|
|||
else
|
||||
driver = "oracle.jdbc.driver.OracleDriver";
|
||||
try {
|
||||
DriverManager.registerDriver(Class.forName(driver).asSubclass(Driver.class).newInstance());
|
||||
DriverManager.registerDriver(Class.forName(driver).asSubclass(Driver.class).getDeclaredConstructor().newInstance());
|
||||
JdbcProxy proxy = new JdbcProxy(DriverManager.getConnection(_connectionString, _username, _password));
|
||||
proxy.databaseType = _type;
|
||||
return proxy;
|
||||
|
|
|
@ -2,12 +2,17 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-excel</artifactId>
|
||||
<name>lantern-util-excel</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
|
@ -38,8 +43,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-http</artifactId>
|
||||
<name>lantern-util-http</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
|
@ -48,8 +52,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-servlet</artifactId>
|
||||
<name>lantern-util-servlet</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
|
@ -44,8 +48,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
11
util/pom.xml
11
util/pom.xml
|
@ -1,18 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<name>util</name>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware</groupId>
|
||||
<artifactId>LanternPowerMonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>lantern-util-common</module>
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>lantern-datamodel-zwave</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-datamodel-zwave</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -41,8 +41,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.thermometer</groupId>
|
||||
<artifactId>lantern-service-thermometer</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-service-thermometer</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-servlet</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
|
@ -69,8 +69,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>lantern-service-zwave</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-service-zwave</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>lantern-datamodel-zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${zw.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.currentmonitor</groupId>
|
||||
<artifactId>lantern-datamodel-currentmonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${cm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
|
@ -31,22 +31,22 @@
|
|||
<dependency>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>lantern-zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${zw.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.rules</groupId>
|
||||
<artifactId>lantern-datamodel-rules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${rules.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao-mongo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-http</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
|
@ -83,8 +83,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>lantern-uirt</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-uirt</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
|
@ -46,8 +46,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>lantern-zwave</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-zwave</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>zwave</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>${util.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -57,8 +57,8 @@
|
|||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -19,7 +19,7 @@ public abstract class MessageEngine {
|
|||
for (Message m : ServiceLoader.load(Message.class)) {
|
||||
messages.put(m.getKey(), m);
|
||||
}
|
||||
for (IMessageSubscriber s : ServiceLoader.load(IMessageSubscriber.class)) {
|
||||
for (IMessageSubscriber<?> s : ServiceLoader.load(IMessageSubscriber.class)) {
|
||||
subscribe(s);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public abstract class MessageEngine {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
Message ret = message.getClass().newInstance();
|
||||
Message ret = message.getClass().getDeclaredConstructor().newInstance();
|
||||
ret.fromPayload(_data);
|
||||
return ret;
|
||||
} catch (Exception _e) {
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
<groupId>com.lanternsoftware.zwave</groupId>
|
||||
<artifactId>zwave-reactor</artifactId>
|
||||
<name>zwave-reactor</name>
|
||||
<artifactId>zwave</artifactId>
|
||||
<name>zwave</name>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>com.lanternsoftware</groupId>
|
||||
<artifactId>LanternPowerMonitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>lantern-datamodel-zwave</module>
|
||||
|
|
Loading…
Reference in New Issue
Block a user