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;
}
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));
}
}
}
Aggregations