Search in sources :

Example 16 with MagicCollection

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

the class ExportsProviderTests method testExports.

public void testExports(MTGCardsExport p) {
    System.out.println("*****************************" + p.getName());
    System.out.println("EXT  " + p.getFileExtension());
    System.out.println("STAT " + p.getStatut());
    System.out.println("PROP " + p.getProperties());
    System.out.println("TYPE " + p.getType());
    System.out.println("ENAB " + p.isEnable());
    System.out.println("ICON " + p.getIcon());
    System.out.println("VERS " + p.getVersion());
    MagicDeck d = new MagicDeck();
    d.setDateCreation(new Date());
    d.setDescription("Test of " + p);
    d.setTags(Arrays.asList("test", p.getName(), "mtgdesktopcompanion"));
    d.setName("TEST " + p);
    d.getMap().put(mc, 40);
    d.getMapSideBoard().put(mc, 10);
    File destD = new File("target", d.getName() + " DECK " + p.getFileExtension());
    File destL = new File("target", d.getName() + " LIST " + p.getFileExtension());
    try {
        p.export(d, destD);
        System.out.println(p + " export Deck OK");
    } catch (Exception e) {
        System.out.println(p + " export Deck ERROR " + e);
    }
    try {
        p.export(d.getAsList(), destL);
        System.out.println(p + " export List OK");
    } catch (Exception e) {
        System.out.println(p + " export List ERROR " + e);
    }
    File destS = new File("target", d.getName() + " STOCK " + p.getFileExtension());
    List<MagicCardStock> stocks = new ArrayList<>();
    MagicCardStock s = new MagicCardStock();
    s.setMagicCard(mc);
    s.setAltered(false);
    s.setFoil(false);
    s.setSigned(false);
    s.setCondition(EnumCondition.LIGHTLY_PLAYED);
    s.setLanguage("English");
    s.setMagicCollection(new MagicCollection("TEST"));
    s.setQte(8);
    s.setPrice(9999.0);
    s.setComment("Test");
    stocks.add(s);
    try {
        p.exportStock(stocks, destS);
        System.out.println(p + " export Stock OK");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(p + " export Stock ERROR" + e);
    }
    MagicDeck d2;
    try {
        d2 = p.importDeck(destD);
        System.out.println(d2 + " " + " import deck OK");
    } catch (Exception e) {
        System.out.println(p + " import deck ERROR " + e);
    }
    try {
        System.out.println(p.importStock(destS));
        System.out.println(p + " " + " import stock OK");
    } catch (Exception e) {
        System.out.println(p + " " + " import stock ERROR " + e);
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) MkmException(org.api.mkm.exceptions.MkmException) MagicCollection(org.magic.api.beans.MagicCollection) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 17 with MagicCollection

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

the class DAOProviderTests method createCards.

@Before
public void createCards() {
    mc = new MagicCard();
    mc.setName("Black Lotus");
    mc.setLayout("normal");
    mc.setCost("{0}");
    mc.setCmc(0);
    mc.getTypes().add("Artifact");
    mc.setReserved(true);
    mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
    mc.setRarity("Rare");
    mc.setArtist("Christopher Rush");
    mc.setId("c944c7dc960c4832604973844edee2a1fdc82d98");
    mc.setMciNumber("232");
    MagicEdition ed = new MagicEdition();
    ed.setId("lea");
    ed.setSet("Limited Edition Alpha");
    ed.setBorder("Black");
    ed.setRarity("Rare");
    ed.setArtist("Christopher Rush");
    ed.setMultiverse_id("3");
    ed.setNumber("232");
    mc.getEditions().add(ed);
    col = new MagicCollection("TEST");
    MTGLogger.changeLevel(Level.ERROR);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition) MagicCollection(org.magic.api.beans.MagicCollection) Before(org.junit.Before)

Example 18 with MagicCollection

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

the class FileDAO method listCollectionFromCards.

@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
    String id = IDGenerator.generate(mc);
    File f = new File(directory, CARDSDIR);
    List<MagicCollection> ret = new ArrayList<>();
    Collection<File> res = FileUtils.listFiles(f, new NameFileFilter(id), TrueFileFilter.INSTANCE);
    for (File result : res) ret.add(new MagicCollection(result.getParentFile().getParentFile().getName()));
    return ret;
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) ArrayList(java.util.ArrayList) File(java.io.File) MagicCollection(org.magic.api.beans.MagicCollection)

Example 19 with MagicCollection

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

the class HsqlDAO method listStocks.

public List<MagicCardStock> listStocks() throws SQLException {
    try (PreparedStatement pst = con.prepareStatement("select * from stocks");
        ResultSet rs = pst.executeQuery()) {
        List<MagicCardStock> colls = new ArrayList<>();
        while (rs.next()) {
            MagicCardStock state = new MagicCardStock();
            state.setComment(rs.getString("comments"));
            state.setIdstock(rs.getInt("idstock"));
            state.setMagicCard((MagicCard) rs.getObject(cardField));
            state.setMagicCollection(new MagicCollection(rs.getString("collection")));
            state.setCondition(EnumCondition.valueOf(rs.getString("conditions")));
            state.setFoil(rs.getBoolean("foil"));
            state.setSigned(rs.getBoolean("signedcard"));
            state.setLanguage(rs.getString("langage"));
            state.setQte(rs.getInt("qte"));
            state.setPrice(rs.getDouble("price"));
            colls.add(state);
        }
        logger.debug("load " + colls.size() + " item(s) from stock");
        return colls;
    }
}
Also used : ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 20 with MagicCollection

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

the class MongoDbDAO method removeCollection.

@Override
public void removeCollection(MagicCollection c) throws SQLException {
    logger.debug("remove collection " + c);
    BasicDBObject query = new BasicDBObject();
    query.put(dbColIDField, c.getName());
    DeleteResult dr = db.getCollection(colCards).deleteMany(query);
    logger.trace(dr);
    MongoCollection<MagicCollection> collection = db.getCollection(colCollects, MagicCollection.class);
    collection.deleteOne(Filters.eq("name", c.getName()));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DeleteResult(com.mongodb.client.result.DeleteResult) MagicCollection(org.magic.api.beans.MagicCollection)

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