Search in sources :

Example 1 with Wantslist

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

the class MkmOnlineExport method importDeck.

@Override
public MagicDeck importDeck(File f) throws IOException {
    WantsService service = new WantsService();
    MagicDeck d = new MagicDeck();
    d.setName(f.getName());
    Wantslist list = null;
    for (Wantslist l : service.getWantList()) if (l.getName().equalsIgnoreCase(d.getName()))
        list = l;
    if (list == null)
        throw new NullPointerException(getName() + " can't import deck for " + f.getName());
    service.loadItems(list);
    for (WantItem w : list.getItem()) {
        try {
            Product p = w.getProduct();
            if (p.getEnName().contains("(Version "))
                p.setEnName(p.getEnName().substring(0, p.getEnName().indexOf("(Version")));
            d.getMap().put(MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", p.getEnName().trim(), null, true).get(0), w.getCount());
        } catch (Exception e) {
            logger.error("could not import " + w);
        }
    }
    return d;
}
Also used : WantsService(org.api.mkm.services.WantsService) Product(org.api.mkm.modele.Product) Wantslist(org.api.mkm.modele.Wantslist) WantItem(org.api.mkm.modele.WantItem) IOException(java.io.IOException) MkmException(org.api.mkm.exceptions.MkmException) MagicDeck(org.magic.api.beans.MagicDeck)

Example 2 with Wantslist

use of org.api.mkm.modele.Wantslist 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

Product (org.api.mkm.modele.Product)2 WantItem (org.api.mkm.modele.WantItem)2 Wantslist (org.api.mkm.modele.Wantslist)2 WantsService (org.api.mkm.services.WantsService)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MkmException (org.api.mkm.exceptions.MkmException)1 MkmBoolean (org.api.mkm.modele.MkmBoolean)1 MagicCard (org.magic.api.beans.MagicCard)1 MagicDeck (org.magic.api.beans.MagicDeck)1