Search in sources :

Example 1 with StockService

use of org.api.mkm.services.StockService 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 2 with StockService

use of org.api.mkm.services.StockService in project MtgDesktopCompanion by nicho92.

the class MkmOnlineExport method importStock.

@Override
public List<MagicCardStock> importStock(File f) throws IOException {
    if (!getString("STOCK_USE").equals("true"))
        return importFromDeck(importDeck(f));
    StockService serv = new StockService();
    List<Article> list = serv.getStock();
    List<MagicCardStock> stock = new ArrayList<>();
    for (Article a : list) {
        MagicCardStock mcs = new MagicCardStock();
        mcs.setUpdate(true);
        mcs.setIdstock(-1);
        mcs.setComment(a.getComments());
        mcs.setLanguage(a.getLanguage().getLanguageName());
        mcs.setQte(a.getCount());
        mcs.setFoil(a.isFoil());
        mcs.setSigned(a.isSigned());
        mcs.setAltered(a.isAltered());
        mcs.setPrice(a.getPrice());
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", a.getProduct().getEnName(), null, true).get(0);
        MagicCardMarketPricer2.selectEditionCard(mc, a.getProduct().getExpansionName());
        mcs.setMagicCard(mc);
        mcs.setCondition(convert(a.getCondition()));
        stock.add(mcs);
    }
    return stock;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Article(org.api.mkm.modele.Article) ArrayList(java.util.ArrayList) StockService(org.api.mkm.services.StockService) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

ArrayList (java.util.ArrayList)2 Article (org.api.mkm.modele.Article)2 StockService (org.api.mkm.services.StockService)2 MagicCardStock (org.magic.api.beans.MagicCardStock)2 EnumMap (java.util.EnumMap)1 Product (org.api.mkm.modele.Product)1 PRODUCT_ATTS (org.api.mkm.modele.Product.PRODUCT_ATTS)1 ProductServices (org.api.mkm.services.ProductServices)1 MagicCard (org.magic.api.beans.MagicCard)1 MagicDeck (org.magic.api.beans.MagicDeck)1