mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Allow exporting all data in bson, json, or csv formats.
This commit is contained in:
@@ -607,29 +607,43 @@ public class CollectionUtils {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <T, V extends Comparable<V>> Map<V, T> transformToSortedMap(Collection<T> _coll, ITransformer<? super T, V> _transformer) {
|
||||
return transformToMap(_coll, _transformer, new TreeMap<>());
|
||||
}
|
||||
|
||||
public static <T, V> Map<V, T> transformToMap(Collection<T> _coll, ITransformer<? super T, V> _transformer) {
|
||||
Map<V, T> mapValues = new HashMap<>();
|
||||
return transformToMap(_coll, _transformer, new HashMap<>());
|
||||
}
|
||||
|
||||
public static <T, V> Map<V, T> transformToMap(Collection<T> _coll, ITransformer<? super T, V> _transformer, Map<V, T> _map) {
|
||||
if ((_coll == null) || (_transformer == null))
|
||||
return mapValues;
|
||||
return _map;
|
||||
for (T t : _coll) {
|
||||
V v = _transformer.transform(t);
|
||||
if (v != null)
|
||||
mapValues.put(v, t);
|
||||
_map.put(v, t);
|
||||
}
|
||||
return mapValues;
|
||||
return _map;
|
||||
}
|
||||
|
||||
public static <T, V extends Comparable<V>, U> Map<V, U> transformToSortedMap(Collection<T> _coll, ITransformer<? super T, V> _keyTrans, ITransformer<? super T, U> _valTrans) {
|
||||
return transformToMap(_coll, _keyTrans, _valTrans, new TreeMap<>());
|
||||
}
|
||||
|
||||
public static <T, V, U> Map<V, U> transformToMap(Collection<T> _coll, ITransformer<? super T, V> _keyTrans, ITransformer<? super T, U> _valTrans) {
|
||||
Map<V, U> mapValues = new HashMap<>();
|
||||
return transformToMap(_coll, _keyTrans, _valTrans, new HashMap<>());
|
||||
}
|
||||
|
||||
public static <T, V, U> Map<V, U> transformToMap(Collection<T> _coll, ITransformer<? super T, V> _keyTrans, ITransformer<? super T, U> _valTrans, Map<V, U> _map) {
|
||||
if ((_coll == null) || (_keyTrans == null) || (_valTrans == null))
|
||||
return mapValues;
|
||||
return _map;
|
||||
for (T t : _coll) {
|
||||
V v = _keyTrans.transform(t);
|
||||
U u = _valTrans.transform(t);
|
||||
if ((v != null) && (u != null))
|
||||
mapValues.put(v, u);
|
||||
_map.put(v, u);
|
||||
}
|
||||
return mapValues;
|
||||
return _map;
|
||||
}
|
||||
|
||||
public static <T, V> Map<V, List<T>> transformToMultiMap(Collection<T> _coll, ITransformer<? super T, V> _transformer) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lanternsoftware.util;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DateRange {
|
||||
private Date start;
|
||||
private Date end;
|
||||
|
||||
public DateRange() {
|
||||
}
|
||||
|
||||
public DateRange(Date _start, Date _end) {
|
||||
start = _start;
|
||||
end = _end;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Date _start) {
|
||||
start = _start;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Date _end) {
|
||||
end = _end;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.lanternsoftware.util;
|
||||
|
||||
public abstract class LanternFiles {
|
||||
public static final String SOURCE_PATH = "C:\\lantern\\LanternPowerMonitor\\";
|
||||
public static final String OPS_PATH = "/opt/tomcat/";
|
||||
// public static final String OPS_PATH = "D:\\zwave\\prodremote\\";
|
||||
// public static final String OPS_PATH = "D:\\zwave\\localhost\\";
|
||||
public static final String BACKUP_SOURCE = "D:\\zwave\\prodremote\\";
|
||||
public static final String BACKUP_DEST = "D:\\zwave\\localhost\\";
|
||||
}
|
||||
@@ -116,6 +116,8 @@ public abstract class ResourceLoader {
|
||||
public static void writeFile(String _sFile, byte[] _btData) {
|
||||
FileOutputStream os = null;
|
||||
try {
|
||||
int idx = _sFile.lastIndexOf(File.separator);
|
||||
new File((idx > 0)?_sFile.substring(0, idx):_sFile).mkdirs();
|
||||
os = new FileOutputStream(_sFile, false);
|
||||
os.write(_btData);
|
||||
os.flush();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.lanternsoftware.util;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@@ -19,7 +20,7 @@ public abstract class ZipUtils {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
GZIPOutputStream stream = null;
|
||||
try {
|
||||
stream = new GZIPOutputStream(out);
|
||||
stream = new GZIPOutputStream(out){{def.setLevel(Deflater.BEST_SPEED);}};
|
||||
stream.write(_btData);
|
||||
IOUtils.closeQuietly(stream);
|
||||
return out.toByteArray();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.lanternsoftware.util.cryptography;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.LongBuffer;
|
||||
@@ -17,7 +16,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.lanternsoftware.util.LanternFiles;
|
||||
import com.lanternsoftware.util.external.LanternFiles;
|
||||
import com.lanternsoftware.util.ResourceLoader;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.slf4j.Logger;
|
||||
@@ -79,7 +78,7 @@ public class AESTool {
|
||||
}
|
||||
|
||||
public static AESTool authTool() {
|
||||
return new AESTool(ResourceLoader.loadFile(LanternFiles.OPS_PATH + "authKey.dat"));
|
||||
return new AESTool(ResourceLoader.loadFile(LanternFiles.CONFIG_PATH + "authKey.dat"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/DevFiles.java
vendored
Normal file
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/DevFiles.java
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.lanternsoftware.util.external;
|
||||
|
||||
public class DevFiles {
|
||||
public static void init() {
|
||||
LanternFiles.SOURCE_CODE_PATH = "C:\\lantern\\LanternPowerMonitor\\";
|
||||
LanternFiles.CONFIG_PATH = "D:\\zwave\\localhost\\";
|
||||
LanternFiles.BACKUP_DEST_PATH = "D:\\zwave\\localhost\\";
|
||||
LanternFiles.runOpsTasks = false;
|
||||
}
|
||||
}
|
||||
12
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/LanternFiles.java
vendored
Normal file
12
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/LanternFiles.java
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.lanternsoftware.util.external;
|
||||
|
||||
public abstract class LanternFiles {
|
||||
public static String SOURCE_CODE_PATH;
|
||||
public static String CONFIG_PATH;
|
||||
public static String BACKUP_DEST_PATH;
|
||||
public static boolean runOpsTasks;
|
||||
|
||||
static {
|
||||
ProdConsoleFiles.init();
|
||||
}
|
||||
}
|
||||
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/ProdConsoleFiles.java
vendored
Normal file
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/ProdConsoleFiles.java
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.lanternsoftware.util.external;
|
||||
|
||||
public class ProdConsoleFiles {
|
||||
public static void init() {
|
||||
LanternFiles.SOURCE_CODE_PATH = "C:\\lantern\\LanternPowerMonitor\\";
|
||||
LanternFiles.CONFIG_PATH = "/opt/tomcat/";
|
||||
LanternFiles.BACKUP_DEST_PATH = "/home/backup/";
|
||||
LanternFiles.runOpsTasks = false;
|
||||
}
|
||||
}
|
||||
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/ProdFiles.java
vendored
Normal file
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/ProdFiles.java
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.lanternsoftware.util.external;
|
||||
|
||||
public class ProdFiles {
|
||||
public static void init() {
|
||||
LanternFiles.SOURCE_CODE_PATH = "C:\\lantern\\LanternPowerMonitor\\";
|
||||
LanternFiles.CONFIG_PATH = "/opt/tomcat/";
|
||||
LanternFiles.BACKUP_DEST_PATH = "/home/backup/";
|
||||
LanternFiles.runOpsTasks = true;
|
||||
}
|
||||
}
|
||||
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/ProdSupportFiles.java
vendored
Normal file
10
util/lantern-util-common/src/main/java/com/lanternsoftware/util/external/ProdSupportFiles.java
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.lanternsoftware.util.external;
|
||||
|
||||
public class ProdSupportFiles {
|
||||
public static void init() {
|
||||
LanternFiles.SOURCE_CODE_PATH = "C:\\lantern\\LanternPowerMonitor\\";
|
||||
LanternFiles.CONFIG_PATH = "D:\\zwave\\prodremote\\";
|
||||
LanternFiles.BACKUP_DEST_PATH = "D:\\zwave\\localhost\\";
|
||||
LanternFiles.runOpsTasks = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user