mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Forgot that I still had everything hard-coded to central time. Changed it to be configurable per account.
This commit is contained in:
@@ -33,13 +33,14 @@ public interface CurrentMonitorDao {
|
||||
void updateSummaries(BreakerGroup _rootGroup, Set<Date> _daysToSummarize, TimeZone _tz);
|
||||
|
||||
String authenticateAccount(String _username, String _password);
|
||||
String getAuthCodeForEmail(String _email);
|
||||
String getAuthCodeForEmail(String _email, TimeZone _tz);
|
||||
Account authCodeToAccount(String _authCode);
|
||||
AuthCode decryptAuthCode(String _authCode);
|
||||
|
||||
Account putAccount(Account _account);
|
||||
Account getAccount(int _accountId);
|
||||
Account getAccountByUsername(String _username);
|
||||
TimeZone getTimeZoneForAccount(int _accountId);
|
||||
|
||||
MongoProxy getProxy();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
@@ -55,7 +54,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||
proxy.ensureIndex(BreakerPower.class, DaoSort.sort("account_id").then("key"));
|
||||
proxy.ensureIndex(HubPowerMinute.class, DaoSort.sort("account_id").then("minute"));
|
||||
proxy.ensureIndex(BreakerGroupEnergy.class, DaoSort.sort("account_id").then("group_id").then("view_mode"));
|
||||
proxy.ensureIndex(BreakerGroupSummary.class, DaoSort.sort("account_id").then("group_id").then("view_mode"));
|
||||
proxy.ensureIndex(BreakerGroupSummary.class, DaoSort.sort("account_id").then("group_id").then("view_mode").then("start"));
|
||||
proxy.ensureIndex(DirtyMinute.class, DaoSort.sort("posted"));
|
||||
for (DirtyMinute minute : proxy.queryAll(DirtyMinute.class)) {
|
||||
updateSummaries(minute);
|
||||
@@ -95,7 +94,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||
private void updateSummaries(DirtyMinute _minute) {
|
||||
DebugTimer timer = new DebugTimer("Updating summaries", logger);
|
||||
List<HubPowerMinute> minutes = proxy.query(HubPowerMinute.class, new DaoQuery("account_id", _minute.getAccountId()).and("minute", _minute.getMinute()));
|
||||
TimeZone tz = TimeZone.getTimeZone("America/Chicago");
|
||||
TimeZone tz = getTimeZoneForAccount(_minute.getAccountId());
|
||||
BreakerConfig config = getConfig(_minute.getAccountId());
|
||||
BreakerGroup group = CollectionUtils.getFirst(config.getBreakerGroups());
|
||||
Date day = DateUtils.getMidnightBefore(_minute.getMinuteAsDate(), tz);
|
||||
@@ -103,7 +102,7 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||
if (summary == null)
|
||||
summary = new BreakerGroupEnergy(group, minutes, EnergyBlockViewMode.DAY, day, tz);
|
||||
else
|
||||
summary.addEnergy(group, minutes, tz);
|
||||
summary.addEnergy(group, minutes);
|
||||
putBreakerGroupEnergy(summary);
|
||||
updateSummaries(group, CollectionUtils.asHashSet(day), tz);
|
||||
timer.stop();
|
||||
@@ -216,12 +215,13 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthCodeForEmail(String _email) {
|
||||
public String getAuthCodeForEmail(String _email, TimeZone _tz) {
|
||||
_email = _email.toLowerCase().trim();
|
||||
Account account = getAccountByUsername(_email);
|
||||
if (account == null) {
|
||||
account = new Account();
|
||||
account.setUsername(_email);
|
||||
account.setTimezone(_tz.getID());
|
||||
putAccount(account);
|
||||
}
|
||||
return aes.encryptToBase64(DaoSerializer.toZipBson(new AuthCode(account.getId(), account.getAuxiliaryAccountIds())));
|
||||
@@ -259,6 +259,20 @@ public class MongoCurrentMonitorDao implements CurrentMonitorDao {
|
||||
return clearPassword(proxy.queryOne(Account.class, new DaoQuery("username", NullUtils.makeNotNull(_username).toLowerCase().trim())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone getTimeZoneForAccount(int _accountId) {
|
||||
String timezone = proxy.queryForOneField(Account.class, new DaoQuery("_id", String.valueOf(_accountId)), "timezone");
|
||||
TimeZone tz = null;
|
||||
try {
|
||||
if (NullUtils.isNotEmpty(timezone))
|
||||
tz = TimeZone.getTimeZone(timezone);
|
||||
}
|
||||
catch (Exception _e) {
|
||||
logger.error("TimeZone not configured correctly for account {}", _accountId);
|
||||
}
|
||||
return tz == null ? TimeZone.getTimeZone("America/Chicago") : tz;
|
||||
}
|
||||
|
||||
private Account clearPassword(Account _account) {
|
||||
if (_account == null)
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user