mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Add a rules engine so I can be notified when I forget to close my garage door.
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class AuthCode {
|
||||
private int accountId;
|
||||
private List<Integer> auxiliaryAccountIds;
|
||||
|
||||
public AuthCode() {
|
||||
}
|
||||
|
||||
public AuthCode(int _accountId, List<Integer> _auxiliaryAccountIds) {
|
||||
accountId = _accountId;
|
||||
auxiliaryAccountIds = _auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public List<Integer> getAuxiliaryAccountIds() {
|
||||
return auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public void setAuxiliaryAccountIds(List<Integer> _auxiliaryAccountIds) {
|
||||
auxiliaryAccountIds = _auxiliaryAccountIds;
|
||||
}
|
||||
|
||||
public List<Integer> getAllAccountIds() {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
ids.add(accountId);
|
||||
if (auxiliaryAccountIds != null)
|
||||
ids.addAll(auxiliaryAccountIds);
|
||||
return ids;
|
||||
}
|
||||
|
||||
public boolean isAuthorized(int _accountId) {
|
||||
return accountId == _accountId || CollectionUtils.contains(auxiliaryAccountIds, _accountId);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.AuthCode;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
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.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AuthCodeSerializer extends AbstractDaoSerializer<AuthCode>
|
||||
{
|
||||
@Override
|
||||
public Class<AuthCode> getSupportedClass()
|
||||
{
|
||||
return AuthCode.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(AuthCode _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("account_id", _o.getAccountId());
|
||||
if (CollectionUtils.isNotEmpty(_o.getAuxiliaryAccountIds()))
|
||||
d.put("aux_account_ids", CollectionUtils.toByteArray(_o.getAuxiliaryAccountIds()));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthCode fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
AuthCode o = new AuthCode();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setAuxiliaryAccountIds(CollectionUtils.fromByteArrayOfIntegers(DaoSerializer.getByteArray(_d, "aux_account_ids")));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.AccountSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.AuthCodeSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerConfigSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerGroupEnergySerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.BreakerGroupSerializer
|
||||
|
||||
Reference in New Issue
Block a user