Search in sources :

Example 11 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class MysqlDAO method getCollection.

@Override
public MagicCollection getCollection(String name) throws SQLException {
    try (PreparedStatement pst = con.prepareStatement("select * from collections where name= ?")) {
        pst.setString(1, name);
        try (ResultSet rs = pst.executeQuery()) {
            if (rs.next()) {
                MagicCollection mc = new MagicCollection();
                mc.setName(rs.getString("name"));
                return mc;
            }
            return null;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection)

Example 12 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class PostgresqlDAO method listCollectionFromCards.

@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
    if (mc.getEditions().isEmpty())
        throw new SQLException("No edition defined");
    try (PreparedStatement pst = con.prepareStatement("SELECT collection FROM cards WHERE name=? and edition=?")) {
        pst.setString(1, mc.getName());
        pst.setString(2, mc.getEditions().get(0).getId());
        try (ResultSet rs = pst.executeQuery()) {
            List<MagicCollection> cols = new ArrayList<>();
            while (rs.next()) {
                MagicCollection col = new MagicCollection();
                col.setName(rs.getString("collection"));
                cols.add(col);
            }
            return cols;
        }
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection)

Example 13 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class PostgresqlDAO method getCollection.

@Override
public MagicCollection getCollection(String name) throws SQLException {
    try (PreparedStatement pst = con.prepareStatement("select * from collections where name= ?")) {
        pst.setString(1, name);
        try (ResultSet rs = pst.executeQuery()) {
            if (rs.next()) {
                MagicCollection mc = new MagicCollection();
                mc.setName(rs.getString("name"));
                return mc;
            }
            return null;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection)

Example 14 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class Search method run.

@Override
public void run(String[] args, IoSession session, MTGConsoleHandler mtgConsoleHandler) throws ParseException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    CommandLine cl = parser.parse(opts, args);
    this.session = session;
    if (cl.hasOption("c")) {
        String att = cl.getOptionValue("c").split("=")[0];
        String val = cl.getOptionValue("c").split("=")[1];
        List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(att, val, null, false);
        session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCards())));
    }
    if (cl.hasOption("s")) {
        List<MagicEdition> list = MTGControler.getInstance().getEnabledProviders().loadEditions();
        session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttSet())));
    }
    if (cl.hasOption("col")) {
        List<MagicCollection> list;
        try {
            list = MTGControler.getInstance().getEnabledDAO().getCollections();
        } catch (SQLException e) {
            throw new IOException(e);
        }
        session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCols())));
    }
    if (cl.hasOption("?")) {
        usage();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) MagicCard(org.magic.api.beans.MagicCard) SQLException(java.sql.SQLException) MagicEdition(org.magic.api.beans.MagicEdition) IOException(java.io.IOException) MagicCollection(org.magic.api.beans.MagicCollection)

Example 15 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class MagicWebSiteGenerator method generateCollectionsTemplate.

// lister les editions disponibles
private void generateCollectionsTemplate() throws IOException, TemplateException, SQLException {
    Template generatedColTemplate = cfg.getTemplate("page-col.html");
    for (MagicCollection col : cols) {
        Map rootEd = new HashMap<>();
        rootEd.put("cols", cols);
        rootEd.put("colName", col.getName());
        Set<MagicEdition> eds = new HashSet<>();
        for (MagicCard mc : dao.listCardsFromCollection(col)) {
            eds.add(mc.getEditions().get(0));
            generateCardsTemplate(mc);
        }
        rootEd.put("editions", eds);
        FileWriter out = new FileWriter(Paths.get(dest, "page-col-" + col.getName() + ".htm").toFile());
        generatedColTemplate.process(rootEd, out);
        generateEditionsTemplate(eds, col);
        out.close();
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) MagicEdition(org.magic.api.beans.MagicEdition) HashMap(java.util.HashMap) Map(java.util.Map) MagicCollection(org.magic.api.beans.MagicCollection) Template(freemarker.template.Template) HashSet(java.util.HashSet)

Aggregations

MagicCollection (org.magic.api.beans.MagicCollection)32 ArrayList (java.util.ArrayList)20 MagicCard (org.magic.api.beans.MagicCard)15 SQLException (java.sql.SQLException)14 MagicEdition (org.magic.api.beans.MagicEdition)13 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)12 IOException (java.io.IOException)9 MagicCardStock (org.magic.api.beans.MagicCardStock)8 File (java.io.File)7 List (java.util.List)6 BorderLayout (java.awt.BorderLayout)4 Map (java.util.Map)4 JButton (javax.swing.JButton)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 BasicDBObject (com.mongodb.BasicDBObject)3 DeleteResult (com.mongodb.client.result.DeleteResult)3 Point (java.awt.Point)3