Search in sources :

Example 1 with MkmBoolean

use of org.api.mkm.modele.MkmBoolean in project MtgDesktopCompanion by nicho92.

the class MkmOnlineExport method export.

@Override
public void export(MagicDeck deck, File dest) throws IOException {
    WantsService wlService = new WantsService();
    List<WantItem> wants = new ArrayList<>();
    int c = 0;
    for (MagicCard mc : deck.getMap().keySet()) {
        Product p;
        p = MagicCardMarketPricer2.getProductFromCard(mc, pService.findProduct(mc.getName(), atts));
        if (p != null) {
            WantItem w = new WantItem();
            w.setProduct(p);
            w.setCount(deck.getMap().get(mc));
            w.setFoil(new MkmBoolean(false));
            w.setMinCondition(getString("QUALITY"));
            w.setAltered(new MkmBoolean(false));
            w.setType("product");
            w.setSigned(new MkmBoolean(false));
            for (String s : getString("LANGUAGES").split(",")) w.getIdLanguage().add(Integer.parseInt(s));
            wants.add(w);
        } else {
            logger.debug("could not export " + mc);
        }
        setChanged();
        notifyObservers(c++);
    }
    int max = Integer.parseInt(getString("MAX_WANTLIST_SIZE"));
    if (wants.size() <= max) {
        Wantslist l = wlService.createWantList(deck.getName());
        logger.debug("Create " + l + " list with " + wants.size() + " items");
        wlService.addItem(l, wants);
    } else {
        List<List<WantItem>> decoupes = ListUtils.partition(wants, max);
        for (int i = 0; i < decoupes.size(); i++) {
            Wantslist wl = wlService.createWantList(deck.getName() + "-" + (i + 1));
            logger.debug("Create " + wl + " list with " + decoupes.get(i).size() + " items");
            wlService.addItem(wl, decoupes.get(i));
        }
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList) WantsService(org.api.mkm.services.WantsService) Product(org.api.mkm.modele.Product) ArrayList(java.util.ArrayList) List(java.util.List) Wantslist(org.api.mkm.modele.Wantslist) MkmBoolean(org.api.mkm.modele.MkmBoolean) WantItem(org.api.mkm.modele.WantItem)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 MkmBoolean (org.api.mkm.modele.MkmBoolean)1 Product (org.api.mkm.modele.Product)1 WantItem (org.api.mkm.modele.WantItem)1 Wantslist (org.api.mkm.modele.Wantslist)1 WantsService (org.api.mkm.services.WantsService)1 MagicCard (org.magic.api.beans.MagicCard)1