Search in sources :

Example 1 with Product

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

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

the class MkmOnlineExport method exportStock.

@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
    if (!getString("STOCK_USE").equals("true")) {
        MagicDeck d = new MagicDeck();
        d.setName(f.getName());
        for (MagicCardStock mcs : stock) {
            d.getMap().put(mcs.getMagicCard(), mcs.getQte());
        }
        export(d, f);
    } else {
        StockService serv = new StockService();
        ProductServices prods = new ProductServices();
        EnumMap<PRODUCT_ATTS, String> enumAtts = new EnumMap<>(PRODUCT_ATTS.class);
        enumAtts.put(PRODUCT_ATTS.idGame, "1");
        enumAtts.put(PRODUCT_ATTS.exact, "true");
        List<Article> list = new ArrayList<>();
        for (MagicCardStock mcs : stock) {
            Product p = MagicCardMarketPricer2.getProductFromCard(mcs.getMagicCard(), prods.findProduct(mcs.getMagicCard().getName(), enumAtts));
            Article a = new Article();
            a.setAltered(mcs.isAltered());
            a.setSigned(mcs.isSigned());
            a.setCount(mcs.getQte());
            a.setFoil(mcs.isFoil());
            a.setPrice(mcs.getPrice());
            a.setCondition(convert(mcs.getCondition()));
            a.setLanguage(convertLang(mcs.getLanguage()));
            a.setProduct(p);
            a.setIdProduct(p.getIdProduct());
            list.add(a);
        }
        serv.addArticles(list);
    }
}
Also used : PRODUCT_ATTS(org.api.mkm.modele.Product.PRODUCT_ATTS) Article(org.api.mkm.modele.Article) ArrayList(java.util.ArrayList) Product(org.api.mkm.modele.Product) ProductServices(org.api.mkm.services.ProductServices) StockService(org.api.mkm.services.StockService) EnumMap(java.util.EnumMap) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 3 with Product

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

the class MagicCardMarketPricer2 method getPrice.

public List<MagicPrice> getPrice(MagicEdition me, MagicCard card) throws IOException {
    try {
        if (me == null)
            me = card.getEditions().get(0);
        lists = new ArrayList<>();
        logger.info(getName() + " looking for " + card + " " + me);
        if (me.getRarity() != null)
            if (!getBoolean("COMMONCHECK") && me.getRarity().equalsIgnoreCase("Common")) {
                MagicPrice mp = new MagicPrice();
                mp.setCurrency("EUR");
                mp.setValue(0.01);
                mp.setSite(getName());
                mp.setSeller("Not checked common");
                lists.add(mp);
                return lists;
            }
        ProductServices pService = new ProductServices();
        EnumMap<PRODUCT_ATTS, String> atts = new EnumMap<>(PRODUCT_ATTS.class);
        atts.put(PRODUCT_ATTS.idGame, "1");
        atts.put(PRODUCT_ATTS.exact, getString("IS_EXACT"));
        if (!getString("LANGUAGE_ID").equals(""))
            atts.put(PRODUCT_ATTS.idLanguage, getString("LANGUAGE_ID"));
        if (getString("USER_ARTICLE").equals("false")) {
            Product p = getProductFromCard(card, pService.findProduct(card.getName(), atts));
            if (p != null) {
                p = pService.getProductById(p.getIdProduct());
                MagicPrice mp = new MagicPrice();
                mp.setSeller(String.valueOf(p.getExpansionName()));
                mp.setValue(p.getPriceGuide().getLOW());
                mp.setQuality("");
                mp.setUrl("https://www.magiccardmarket.eu" + p.getWebsite());
                mp.setSite(getName());
                mp.setFoil(false);
                mp.setCurrency("EUR");
                mp.setLanguage(String.valueOf(p.getLocalization()));
                lists.add(mp);
            }
        } else {
            List<Product> list = pService.findProduct(card.getName(), atts);
            Product resultat = getProductFromCard(card, list);
            if (resultat == null) {
                logger.info(getName() + " found no item");
                return lists;
            }
            ArticleService aServ = new ArticleService();
            EnumMap<ARTICLES_ATT, String> aatts = new EnumMap<>(ARTICLES_ATT.class);
            aatts.put(ARTICLES_ATT.start, "0");
            aatts.put(ARTICLES_ATT.maxResults, getString("MAX"));
            if (!getString("LANGUAGE_ID").equals(""))
                aatts.put(ARTICLES_ATT.idLanguage, getString("LANGUAGE_ID"));
            if (!getString("MIN_CONDITION").equals(""))
                aatts.put(ARTICLES_ATT.minCondition, getString("MIN_CONDITION"));
            List<Article> articles = aServ.find(resultat, aatts);
            logger.debug(getName() + " found " + articles.size() + " items");
            for (Article a : articles) {
                MagicPrice mp = new MagicPrice();
                mp.setSeller(String.valueOf(a.getSeller()));
                mp.setCountry(String.valueOf(a.getSeller().getAddress().getCountry()));
                mp.setValue(a.getPrice());
                mp.setQuality(a.getCondition());
                mp.setUrl("https://www.magiccardmarket.eu" + resultat.getWebsite());
                mp.setSite("MagicCardMarket");
                mp.setFoil(a.isFoil());
                mp.setCurrency("EUR");
                mp.setLanguage(a.getLanguage().toString());
                mp.setShopItem(a);
                lists.add(mp);
            }
        }
    } catch (Exception e) {
        logger.error("Error retrieving prices for " + card, e);
        logger.error(e);
    }
    return lists;
}
Also used : ARTICLES_ATT(org.api.mkm.modele.Article.ARTICLES_ATT) MagicPrice(org.magic.api.beans.MagicPrice) Article(org.api.mkm.modele.Article) Product(org.api.mkm.modele.Product) ProductServices(org.api.mkm.services.ProductServices) IOException(java.io.IOException) MkmException(org.api.mkm.exceptions.MkmException) PRODUCT_ATTS(org.api.mkm.modele.Product.PRODUCT_ATTS) ArticleService(org.api.mkm.services.ArticleService) EnumMap(java.util.EnumMap)

Example 4 with Product

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

the class MagicCardMarketPricer2 method getProductFromCard.

public static Product getProductFromCard(MagicCard mc, List<Product> list) {
    String edName = mc.getEditions().get(0).getSet();
    Product resultat = null;
    for (Product p : list) {
        if (mc.getEditions().get(0).getMkm_name() != null)
            edName = mc.getEditions().get(0).getMkm_name();
        if (p.getCategoryName().equalsIgnoreCase("Magic Single") && edName.startsWith(p.getExpansionName())) {
            resultat = p;
            break;
        }
    }
    return resultat;
}
Also used : Product(org.api.mkm.modele.Product)

Example 5 with Product

use of org.api.mkm.modele.Product 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)5 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 MkmException (org.api.mkm.exceptions.MkmException)2 Article (org.api.mkm.modele.Article)2 PRODUCT_ATTS (org.api.mkm.modele.Product.PRODUCT_ATTS)2 WantItem (org.api.mkm.modele.WantItem)2 Wantslist (org.api.mkm.modele.Wantslist)2 ProductServices (org.api.mkm.services.ProductServices)2 WantsService (org.api.mkm.services.WantsService)2 MagicDeck (org.magic.api.beans.MagicDeck)2 List (java.util.List)1 ARTICLES_ATT (org.api.mkm.modele.Article.ARTICLES_ATT)1 MkmBoolean (org.api.mkm.modele.MkmBoolean)1 ArticleService (org.api.mkm.services.ArticleService)1 StockService (org.api.mkm.services.StockService)1 MagicCard (org.magic.api.beans.MagicCard)1 MagicCardStock (org.magic.api.beans.MagicCardStock)1 MagicPrice (org.magic.api.beans.MagicPrice)1