Search in sources :

Example 1 with ArticleService

use of org.api.mkm.services.ArticleService 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)

Aggregations

IOException (java.io.IOException)1 EnumMap (java.util.EnumMap)1 MkmException (org.api.mkm.exceptions.MkmException)1 Article (org.api.mkm.modele.Article)1 ARTICLES_ATT (org.api.mkm.modele.Article.ARTICLES_ATT)1 Product (org.api.mkm.modele.Product)1 PRODUCT_ATTS (org.api.mkm.modele.Product.PRODUCT_ATTS)1 ArticleService (org.api.mkm.services.ArticleService)1 ProductServices (org.api.mkm.services.ProductServices)1 MagicPrice (org.magic.api.beans.MagicPrice)1