Search in sources :

Example 1 with MagicCardAlert

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<>();
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MagicCardAlert(org.magic.api.beans.MagicCardAlert) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with MagicCardAlert

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<>();
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MagicCardAlert(org.magic.api.beans.MagicCardAlert) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 3 with MagicCardAlert

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<>();
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MagicCardAlert(org.magic.api.beans.MagicCardAlert) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 4 with MagicCardAlert

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");
}
Also used : MTGPricesProvider(org.magic.api.interfaces.MTGPricesProvider) TimerTask(java.util.TimerTask) MagicPrice(org.magic.api.beans.MagicPrice) ArrayList(java.util.ArrayList) MagicCardAlert(org.magic.api.beans.MagicCardAlert)

Example 5 with MagicCardAlert

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();
}
Also used : SQLException(java.sql.SQLException) MagicCardAlert(org.magic.api.beans.MagicCardAlert)

Aggregations

MagicCardAlert (org.magic.api.beans.MagicCardAlert)8 SQLException (java.sql.SQLException)4 IOException (java.io.IOException)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)2 Dimension (java.awt.Dimension)1 Rectangle (java.awt.Rectangle)1 File (java.io.File)1 TimerTask (java.util.TimerTask)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 MagicCard (org.magic.api.beans.MagicCard)1 MagicCardStock (org.magic.api.beans.MagicCardStock)1 MagicPrice (org.magic.api.beans.MagicPrice)1 MTGPricesProvider (org.magic.api.interfaces.MTGPricesProvider)1 HistoryPricesPanel (org.magic.gui.components.charts.HistoryPricesPanel)1 CardAlertTableModel (org.magic.gui.models.CardAlertTableModel)1