Search in sources :

Example 21 with MagicCardStock

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

the class WebsiteImportExport method importStock.

@Override
public List<MagicCardStock> importStock(File f) throws IOException {
    MagicDeck d = importDeck(f);
    List<MagicCardStock> ret = new ArrayList<>();
    for (MagicCard mc : d.getMap().keySet()) {
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setQte(d.getMap().get(mc));
        stock.setUpdate(true);
        stock.setIdstock(-1);
        ret.add(stock);
    }
    return ret;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 22 with MagicCardStock

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

the class XMageDeckExport method exportStock.

@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    d.setName(f.getName());
    for (MagicCardStock mcs : stock) {
        d.getMap().put(mcs.getMagicCard(), mcs.getQte());
    }
    export(d, f);
}
Also used : MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 23 with MagicCardStock

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

the class AbstractCardExport method importFromDeck.

protected List<MagicCardStock> importFromDeck(MagicDeck deck) {
    List<MagicCardStock> mcs = new ArrayList<>();
    for (MagicCard mc : deck.getMap().keySet()) {
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setQte(deck.getMap().get(mc));
        stock.setComment("import from " + deck.getName());
        stock.setIdstock(-1);
        stock.setUpdate(true);
        mcs.add(stock);
    }
    return mcs;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 24 with MagicCardStock

use of org.magic.api.beans.MagicCardStock 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 25 with MagicCardStock

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

the class FileDAO method deleteStock.

@Override
public void deleteStock(List<MagicCardStock> state) throws SQLException {
    for (MagicCardStock s : state) {
        File f = Paths.get(directory.getAbsolutePath(), STOCKDIR, s.getIdstock() + "-" + IDGenerator.generate(s.getMagicCard())).toFile();
        logger.debug("Delete " + f);
        FileUtils.deleteQuietly(f);
    }
}
Also used : File(java.io.File) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

MagicCardStock (org.magic.api.beans.MagicCardStock)38 ArrayList (java.util.ArrayList)17 MagicDeck (org.magic.api.beans.MagicDeck)14 PreparedStatement (java.sql.PreparedStatement)9 MagicCard (org.magic.api.beans.MagicCard)9 ResultSet (java.sql.ResultSet)6 MagicCollection (org.magic.api.beans.MagicCollection)6 File (java.io.File)5 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 Gson (com.google.gson.Gson)2 FileReader (java.io.FileReader)2 Article (org.api.mkm.modele.Article)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1