Search in sources :

Example 56 with MagicCard

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

the class MongoDbDAO method listCardsFromCollection.

@Override
public List<MagicCard> listCardsFromCollection(MagicCollection collection, MagicEdition me) throws SQLException {
    logger.debug("getCardsFromCollection " + collection + " " + me);
    BasicDBObject query = new BasicDBObject();
    List<MagicCard> ret = new ArrayList<>();
    List<BasicDBObject> obj = new ArrayList<>();
    obj.add(new BasicDBObject(dbColIDField, collection.getName()));
    if (me != null) {
        obj.add(new BasicDBObject(dbEditionField, me.getId().toUpperCase()));
        query.put("$and", obj);
    }
    db.getCollection(colCards, BasicDBObject.class).find(query).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get("card").toString(), MagicCard.class)));
    return ret;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Document(org.bson.Document) Arrays(java.util.Arrays) MagicCollection(org.magic.api.beans.MagicCollection) MongoCollection(com.mongodb.client.MongoCollection) MagicCardAlert(org.magic.api.beans.MagicCardAlert) Aggregates(com.mongodb.client.model.Aggregates) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) MongoDatabase(com.mongodb.client.MongoDatabase) MagicCardStock(org.magic.api.beans.MagicCardStock) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) STATUT(org.magic.api.interfaces.MTGCardsProvider.STATUT) Filters(com.mongodb.client.model.Filters) SQLException(java.sql.SQLException) MongoClientOptions(com.mongodb.MongoClientOptions) UpdateResult(com.mongodb.client.result.UpdateResult) Gson(com.google.gson.Gson) Map(java.util.Map) AbstractMagicDAO(org.magic.api.interfaces.abstracts.AbstractMagicDAO) CodecRegistries.fromRegistries(org.bson.codecs.configuration.CodecRegistries.fromRegistries) ServerAddress(com.mongodb.ServerAddress) PojoCodecProvider(org.bson.codecs.pojo.PojoCodecProvider) Accumulators(com.mongodb.client.model.Accumulators) MagicNews(org.magic.api.beans.MagicNews) CodecRegistries.fromProviders(org.bson.codecs.configuration.CodecRegistries.fromProviders) BasicDBObject(com.mongodb.BasicDBObject) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) MagicEdition(org.magic.api.beans.MagicEdition) TreeMap(java.util.TreeMap) IDGenerator(org.magic.tools.IDGenerator) MongoClient(com.mongodb.MongoClient) MagicCard(org.magic.api.beans.MagicCard) DeleteResult(com.mongodb.client.result.DeleteResult) BasicDBObject(com.mongodb.BasicDBObject) MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList)

Example 57 with MagicCard

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

the class MongoDbDAO method listCollectionFromCards.

@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
    List<MagicCollection> ret = new ArrayList<>();
    BasicDBObject query = new BasicDBObject();
    query.put(dbIDField, IDGenerator.generate(mc));
    db.getCollection(colCards, BasicDBObject.class).distinct(dbColIDField, query, String.class).forEach((Consumer<String>) result -> {
        try {
            logger.trace("found " + mc + " in " + result);
            ret.add(getCollection(result));
        } catch (SQLException e) {
            logger.error("Error", e);
        }
    });
    return ret;
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Document(org.bson.Document) Arrays(java.util.Arrays) MagicCollection(org.magic.api.beans.MagicCollection) MongoCollection(com.mongodb.client.MongoCollection) MagicCardAlert(org.magic.api.beans.MagicCardAlert) Aggregates(com.mongodb.client.model.Aggregates) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) MongoDatabase(com.mongodb.client.MongoDatabase) MagicCardStock(org.magic.api.beans.MagicCardStock) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson) STATUT(org.magic.api.interfaces.MTGCardsProvider.STATUT) Filters(com.mongodb.client.model.Filters) SQLException(java.sql.SQLException) MongoClientOptions(com.mongodb.MongoClientOptions) UpdateResult(com.mongodb.client.result.UpdateResult) Gson(com.google.gson.Gson) Map(java.util.Map) AbstractMagicDAO(org.magic.api.interfaces.abstracts.AbstractMagicDAO) CodecRegistries.fromRegistries(org.bson.codecs.configuration.CodecRegistries.fromRegistries) ServerAddress(com.mongodb.ServerAddress) PojoCodecProvider(org.bson.codecs.pojo.PojoCodecProvider) Accumulators(com.mongodb.client.model.Accumulators) MagicNews(org.magic.api.beans.MagicNews) CodecRegistries.fromProviders(org.bson.codecs.configuration.CodecRegistries.fromProviders) BasicDBObject(com.mongodb.BasicDBObject) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) MagicEdition(org.magic.api.beans.MagicEdition) TreeMap(java.util.TreeMap) IDGenerator(org.magic.tools.IDGenerator) MongoClient(com.mongodb.MongoClient) MagicCard(org.magic.api.beans.MagicCard) DeleteResult(com.mongodb.client.result.DeleteResult) BasicDBObject(com.mongodb.BasicDBObject) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) MagicCollection(org.magic.api.beans.MagicCollection)

Example 58 with MagicCard

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

the class MysqlDAO method listCards.

@Override
public List<MagicCard> listCards() throws SQLException {
    logger.debug("list all cards");
    String sql = "select mcard from cards";
    try (PreparedStatement pst = con.prepareStatement(sql);
        ResultSet rs = pst.executeQuery()) {
        List<MagicCard> listCards = new ArrayList<>();
        while (rs.next()) {
            listCards.add((MagicCard) rs.getObject(cardFieldName));
        }
        return listCards;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 59 with MagicCard

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

the class PostgresqlDAO method listCards.

@Override
public List<MagicCard> listCards() throws SQLException {
    logger.debug("list all cards");
    String sql = "select * from cards";
    try (PreparedStatement pst = con.prepareStatement(sql);
        ResultSet rs = pst.executeQuery()) {
        List<MagicCard> ret = new ArrayList<>();
        while (rs.next()) {
            ret.add(readObject(MagicCard.class, rs.getBinaryStream(mcardField)));
        }
        return ret;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 60 with MagicCard

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

the class LightDescribeCardPanel method initDataBindings.

protected BindingGroup initDataBindings() {
    BeanProperty<MagicCard, String> nameProperty = BeanProperty.create("name");
    BeanProperty<JTextField, String> textProperty = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ, card, nameProperty, txtName, textProperty);
    autoBinding.bind();
    BeanProperty<MagicCard, String> costProperty = BeanProperty.create("cost");
    BeanProperty<ManaPanel, String> textProperty1 = BeanProperty.create("manaCost");
    AutoBinding<MagicCard, String, ManaPanel, String> autoBinding1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, card, costProperty, manaPanel, textProperty1);
    autoBinding1.bind();
    BeanProperty<MagicCard, String> fullTypeProperty = BeanProperty.create("fullType");
    BeanProperty<JTextField, String> textProperty2 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ, card, fullTypeProperty, txtType, textProperty2);
    autoBinding2.bind();
    BeanProperty<MagicCard, Integer> loyaltyProperty = BeanProperty.create("loyalty");
    BeanProperty<JTextField, String> textProperty4 = BeanProperty.create("text");
    AutoBinding<MagicCard, Integer, JTextField, String> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ, card, loyaltyProperty, txtLoyalty, textProperty4);
    autoBinding4.bind();
    BeanProperty<MagicCard, String> textProperty8 = BeanProperty.create("text");
    BeanProperty<MagicTextPane, String> textProperty9 = BeanProperty.create("text");
    AutoBinding<MagicCard, String, MagicTextPane, String> autoBinding8 = Bindings.createAutoBinding(UpdateStrategy.READ, card, textProperty8, magicTextPane, textProperty9);
    autoBinding8.bind();
    BeanProperty<MagicCard, String> pProperty = BeanProperty.create("power");
    BeanProperty<JTextField, String> textPropertyP = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBindingP = Bindings.createAutoBinding(UpdateStrategy.READ, card, pProperty, txtPower, textPropertyP);
    autoBindingP.bind();
    BeanProperty<MagicCard, String> tProperty = BeanProperty.create("toughness");
    BeanProperty<JTextField, String> textPropertyT = BeanProperty.create("text");
    AutoBinding<MagicCard, String, JTextField, String> autoBindingT = Bindings.createAutoBinding(UpdateStrategy.READ, card, tProperty, txtT, textPropertyT);
    autoBindingT.bind();
    StringBuilder rules = new StringBuilder();
    for (MagicRuling rul : card.getRulings()) rules.append("-").append(rul.getText()).append("\n");
    rulesTextPane.setText(rules.toString());
    // 
    BindingGroup bindingGroup = new BindingGroup();
    // 
    bindingGroup.addBinding(autoBinding);
    bindingGroup.addBinding(autoBinding1);
    bindingGroup.addBinding(autoBinding2);
    bindingGroup.addBinding(autoBinding4);
    bindingGroup.addBinding(autoBinding8);
    bindingGroup.addBinding(autoBindingT);
    bindingGroup.addBinding(autoBindingP);
    magicTextPane.updateTextWithIcons();
    return bindingGroup;
}
Also used : JTextField(javax.swing.JTextField) ManaPanel(org.magic.gui.components.ManaPanel) MagicCard(org.magic.api.beans.MagicCard) BindingGroup(org.jdesktop.beansbinding.BindingGroup) MagicTextPane(org.magic.gui.components.MagicTextPane) MagicRuling(org.magic.api.beans.MagicRuling)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6