use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class HsqlDAO method listCards.
@Override
public List<MagicCard> listCards() throws SQLException {
logger.trace("list all cards");
String sql = "select mcard from cards";
try (PreparedStatement pst = con.prepareStatement(sql)) {
try (ResultSet rs = pst.executeQuery()) {
List<MagicCard> ret = new ArrayList<>();
while (rs.next()) {
try {
ret.add((MagicCard) rs.getObject(cardField));
} catch (Exception e) {
throw new SQLException("ERROR", e);
}
}
return ret;
}
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class MongoDbDAO method listStocks.
@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
ArrayList<MagicCardStock> ret = new ArrayList<>();
BasicDBObject filter = new BasicDBObject(dbCardIDField, IDGenerator.generate(mc));
filter.put("stockItem.magicCollection.name", col.getName());
logger.debug(filter);
db.getCollection(colStocks, BasicDBObject.class).find(filter).forEach((Consumer<BasicDBObject>) result -> ret.add(deserialize(result.get(dbStockField).toString(), MagicCardStock.class)));
return ret;
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method listCardsFromCollection.
@Override
public List<MagicCard> listCardsFromCollection(MagicCollection collection, MagicEdition me) throws SQLException {
logger.debug("getCardsFromCollection " + collection + " " + me);
String sql = "select * from cards where collection= ?";
if (me != null)
sql = "select * from cards where collection= ? and edition = ?";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, collection.getName());
if (me != null)
pst.setString(2, me.getId());
try (ResultSet rs = pst.executeQuery()) {
List<MagicCard> ret = new ArrayList<>();
while (rs.next()) {
ret.add((MagicCard) rs.getObject(cardFieldName));
}
return ret;
}
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class PostgresqlDAO method listCardsFromCollection.
@Override
public List<MagicCard> listCardsFromCollection(MagicCollection collection, MagicEdition me) throws SQLException {
logger.debug("getCardsFromCollection " + collection + " " + me);
String sql = "select * from cards where collection= ?";
if (me != null)
sql = "select * from cards where collection= ? and edition = ?";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, collection.getName());
if (me != null)
pst.setString(2, me.getId());
try (ResultSet rs = pst.executeQuery()) {
List<MagicCard> ret = new ArrayList<>();
while (rs.next()) {
ret.add(readObject(MagicCard.class, rs.getBinaryStream(mcardField)));
}
return ret;
}
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class MTGSalvationDeckSniffer method getDeck.
@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
String url = info.getUrl() + "#Details:deck-export";
logger.debug("sniff url : " + url);
MagicDeck deck = new MagicDeck();
deck.setName(info.getName());
deck.setDateCreation(new Date());
Document d = Jsoup.connect(url).userAgent(getString("USER_AGENT")).get();
deck.setDescription(info.getUrl().toString() + "\n" + d.select("section.guide div").text());
for (Element a : d.select("span.deck-type")) deck.getTags().add(a.text());
String plainDeck = d.select("section.deck-export-section pre").get(1).text();
boolean sideboard = false;
List<String> elements = new ArrayList<>(Arrays.asList(plainDeck.split("\n")));
elements.remove(0);
for (String s : elements) {
if (s.toLowerCase().startsWith("sideboard")) {
sideboard = true;
} else if (s.length() > 1) {
try {
int qte = Integer.parseInt(s.substring(0, s.indexOf(' ')));
String cardName = s.substring(s.indexOf(' '), s.length()).trim();
MagicEdition ed = null;
if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
ed = new MagicEdition();
ed.setId(MTGControler.getInstance().get("default-land-deck"));
}
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
if (!sideboard) {
deck.getMap().put(mc, qte);
} else {
deck.getMapSideBoard().put(mc, qte);
}
} catch (Exception e) {
logger.error(e);
}
}
}
return deck;
}
Aggregations