use of org.magic.api.beans.MagicCardAlert in project MtgDesktopCompanion by nicho92.
the class HsqlDAO method listAlerts.
@Override
public List<MagicCardAlert> listAlerts() {
try {
try (PreparedStatement pst = con.prepareStatement("select * from alerts");
ResultSet rs = pst.executeQuery()) {
list = new ArrayList<>();
while (rs.next()) {
MagicCardAlert alert = new MagicCardAlert();
alert.setCard((MagicCard) rs.getObject(cardField));
alert.setId(rs.getString("id"));
alert.setPrice(rs.getDouble("amount"));
list.add(alert);
}
return list;
}
} catch (Exception e) {
return new ArrayList<>();
}
}
use of org.magic.api.beans.MagicCardAlert in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method listAlerts.
@Override
public List<MagicCardAlert> listAlerts() {
if (!list.isEmpty())
return list;
try (PreparedStatement pst = con.prepareStatement("select * from alerts")) {
list = new ArrayList<>();
try (ResultSet rs = pst.executeQuery()) {
while (rs.next()) {
MagicCardAlert alert = new MagicCardAlert();
alert.setCard((MagicCard) rs.getObject(cardFieldName));
alert.setId(rs.getString("id"));
alert.setPrice(rs.getDouble("amount"));
list.add(alert);
}
return list;
}
} catch (Exception e) {
logger.error(e);
return new ArrayList<>();
}
}
use of org.magic.api.beans.MagicCardAlert in project MtgDesktopCompanion by nicho92.
the class PostgresqlDAO method listAlerts.
@Override
public List<MagicCardAlert> listAlerts() {
try (PreparedStatement pst = con.prepareStatement("select * from alerts");
ResultSet rs = pst.executeQuery()) {
if (!list.isEmpty())
return list;
while (rs.next()) {
MagicCardAlert alert = new MagicCardAlert();
alert.setCard(readObject(MagicCard.class, rs.getBinaryStream(mcardField)));
alert.setId(rs.getString("id"));
alert.setPrice(rs.getDouble("amount"));
list.add(alert);
}
return list;
} catch (Exception e) {
logger.error(e);
return new ArrayList<>();
}
}
use of org.magic.api.beans.MagicCardAlert in project MtgDesktopCompanion by nicho92.
the class PricesCheckerTimer method start.
public void start() {
running = true;
tache = new TimerTask() {
public void run() {
StringBuilder message = new StringBuilder();
boolean notify = false;
if (MTGControler.getInstance().getEnabledDAO().listAlerts() != null)
for (MagicCardAlert alert : MTGControler.getInstance().getEnabledDAO().listAlerts()) {
alert.getOffers().clear();
for (MTGPricesProvider prov : MTGControler.getInstance().getEnabledPricers()) {
List<MagicPrice> okz = new ArrayList<>();
try {
List<MagicPrice> list = prov.getPrice(alert.getCard().getEditions().get(0), alert.getCard());
for (MagicPrice p : list) {
if (p.getValue() <= alert.getPrice() && p.getValue() > Double.parseDouble(MTGControler.getInstance().get("min-price-alert"))) {
alert.getOffers().add(p);
okz.add(p);
logger.info("Found offer " + prov + ":" + alert.getCard() + " " + p.getValue() + p.getCurrency());
notify = true;
}
}
prov.alertDetected(okz);
alert.orderDesc();
} catch (Exception e) {
MTGLogger.printStackTrace(e);
logger.error(e);
}
}
message.append(alert.getCard()).append(" : ").append(alert.getOffers().size()).append(" offers").append("\n");
}
if (enableNotify && notify)
MTGControler.getInstance().notify("New offers", message.toString(), MessageType.INFO);
}
};
timer.scheduleAtFixedRate(tache, 0, Long.parseLong(getString("TIMEOUT_MINUTE")) * 60000);
logger.info("Server start with " + getString("TIMEOUT_MINUTE") + " min timeout");
}
use of org.magic.api.beans.MagicCardAlert in project MtgDesktopCompanion by nicho92.
the class AlarmGUI method addCard.
private void addCard(MagicCard mc) {
MagicCardAlert alert = new MagicCardAlert();
alert.setCard(mc);
alert.setPrice(0.0);
try {
MTGControler.getInstance().getEnabledDAO().saveAlert(alert);
} catch (SQLException e) {
logger.error(e);
}
model.fireTableDataChanged();
}
Aggregations