use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class PostgresqlDAO method getCollections.
@Override
public List<MagicCollection> getCollections() throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from collections");
ResultSet rs = pst.executeQuery()) {
List<MagicCollection> colls = new ArrayList<>();
while (rs.next()) {
MagicCollection mc = new MagicCollection();
mc.setName(rs.getString(1));
colls.add(mc);
}
return colls;
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class CollectionPanelGUI method initPopupCollection.
public void initPopupCollection() throws SQLException {
popupMenuEdition = new JPopupMenu();
popupMenuCards = new JPopupMenu();
JMenu menuItemAdd = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("ADD_MISSING_CARDS_IN"));
JMenu menuItemMove = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("MOVE_CARD_TO"));
for (MagicCollection mc : dao.getCollections()) {
JMenuItem adds = new JMenuItem(mc.getName());
JMenuItem movs = new JMenuItem(mc.getName());
movs.addActionListener(e -> {
DefaultMutableTreeNode nodeCol = ((DefaultMutableTreeNode) path.getPathComponent(1));
DefaultMutableTreeNode nodeCd = ((DefaultMutableTreeNode) path.getPathComponent(3));
MagicCard card = (MagicCard) nodeCd.getUserObject();
MagicCollection oldCol = (MagicCollection) nodeCol.getUserObject();
final String collec = ((JMenuItem) e.getSource()).getText();
MagicCollection nmagicCol = new MagicCollection();
nmagicCol.setName(collec);
try {
dao.removeCard(card, oldCol);
dao.saveCard(card, nmagicCol);
nodeCd.removeFromParent();
nodeCol.add(new DefaultMutableTreeNode(card));
tree.refresh();
} catch (SQLException e1) {
logger.error(e1);
}
});
adds.addActionListener(e -> {
final String destinationCollection = ((JMenuItem) e.getSource()).getText();
ThreadManager.getInstance().execute(() -> {
try {
DefaultMutableTreeNode node = ((DefaultMutableTreeNode) path.getPathComponent(2));
MagicEdition me = (MagicEdition) node.getUserObject();
MagicCollection col = new MagicCollection();
col.setName(destinationCollection);
List<MagicCard> sets = provider.searchCardByCriteria("set", me.getId(), null, false);
MagicCollection sourceCol = new MagicCollection();
sourceCol.setName(node.getPath()[1].toString());
List<MagicCard> list = dao.listCardsFromCollection(sourceCol, me);
sets.removeAll(list);
for (MagicCard m : sets) dao.saveCard(m, col);
tree.refresh();
} catch (Exception e1) {
MTGLogger.printStackTrace(e1);
}
}, "btnAdds addCardsCollection");
});
menuItemAdd.add(adds);
menuItemMove.add(movs);
}
JMenuItem menuItemOpen = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("OPEN"));
menuItemOpen.addActionListener(e -> {
MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
MagicEdition edition = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
try {
CardSearchPanel.getInstance().open(MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col, edition));
} catch (SQLException e1) {
logger.error(e1);
}
});
popupMenuEdition.add(menuItemOpen);
JMenuItem it = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("MASS_MOVEMENTS"));
it.addActionListener(e -> {
MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
MagicEdition edition = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
MassMoverDialog d = new MassMoverDialog(col, edition);
d.setVisible(true);
logger.debug("closing mass import with change =" + d.hasChange());
});
popupMenuEdition.add(it);
popupMenuEdition.add(menuItemAdd);
popupMenuCards.add(menuItemMove);
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MagicWebSiteGenerator method generate.
public void generate(List<MagicCollection> cols, List<MTGPricesProvider> providers) throws TemplateException, IOException, SQLException {
this.pricesProvider = providers;
this.cols = cols;
Template generatedTemplate = cfg.getTemplate("index.html");
try (Writer out = new FileWriter(Paths.get(dest, "index.htm").toFile())) {
Map<String, List<MagicCard>> root = new HashMap<>();
for (MagicCollection col : cols) root.put(col.getName(), dao.listCardsFromCollection(col));
generatedTemplate.process(root, out);
generateCollectionsTemplate();
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class JSONHttpServer method start.
@Override
public void start() throws IOException {
port(getInt("SERVER-PORT"));
exception(Exception.class, new ExceptionHandler<Exception>() {
@Override
public void handle(Exception exception, Request req, Response res) {
res.status(500);
res.body("{\"error\":\"" + exception + "\"}");
}
});
notFound((req, res) -> {
res.status(404);
return "{\"error\":\"not found\"}";
});
before("/*", (request, response) -> {
response.type(getString("MIME"));
logger.info("Received api call from " + request.ip());
});
get("/cards/search/:att/:val", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(request.params(":att"), request.params(":val"), null, false);
}, transformer);
post("/cards/move/:from/:to/:id", getString("MIME"), (request, response) -> {
MagicCollection from = new MagicCollection(request.params(":from"));
MagicCollection to = new MagicCollection(request.params(":to"));
MagicCard mc = MTGControler.getInstance().getEnabledProviders().getCardById(request.params(":id"));
MTGControler.getInstance().getEnabledDAO().removeCard(mc, from);
MTGControler.getInstance().getEnabledDAO().saveCard(mc, to);
return "OK";
}, transformer);
get("/cards/list/:col/:idEd", getString("MIME"), (request, response) -> {
MagicCollection col = new MagicCollection(request.params(":col"));
MagicEdition ed = new MagicEdition();
ed.setId(request.params(":idEd"));
ed.setSet(request.params(":idEd"));
return MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col, ed);
}, transformer);
get("/cards/:id", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().getCardById(request.params(":id"));
}, transformer);
get("/collections/list", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledDAO().getCollections();
}, transformer);
get("/collections/:name", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledDAO().getCollection(request.params(":name"));
}, transformer);
get("/editions/list", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().loadEditions();
}, transformer);
get("/editions/:idSet", getString("MIME"), (request, response) -> {
return MTGControler.getInstance().getEnabledProviders().getSetById(request.params(":idSet"));
}, transformer);
get("/editions/list/:colName", getString("MIME"), (request, response) -> {
List<MagicEdition> eds = new ArrayList<>();
List<String> list = MTGControler.getInstance().getEnabledDAO().getEditionsIDFromCollection(new MagicCollection(request.params(":colName")));
for (String s : list) eds.add(MTGControler.getInstance().getEnabledProviders().getSetById(s));
Collections.sort(eds);
return eds;
}, transformer);
get("/prices/:idSet/:name", getString("MIME"), (request, response) -> {
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", request.params(":name"), null, false).get(0);
MagicEdition ed = MTGControler.getInstance().getEnabledProviders().getSetById(request.params(":idSet"));
List<MagicPrice> pricesret = new ArrayList<>();
for (MTGPricesProvider prices : MTGControler.getInstance().getEnabledPricers()) pricesret.addAll(prices.getPrice(ed, mc));
return pricesret;
}, transformer);
if (getBoolean("ENABLE_GZIP")) {
after((request, response) -> {
response.header("Content-Encoding", "gzip");
});
}
Spark.init();
logger.info("Server start on port " + getString("SERVER-PORT"));
running = true;
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MagicEditionsTableModel method calculate.
public void calculate() throws SQLException {
MagicCollection mc = new MagicCollection(MTGControler.getInstance().get("default-library"));
Map<String, Integer> temp = MTGControler.getInstance().getEnabledDAO().getCardsCountGlobal(mc);
countDefaultLibrary = 0;
countTotal = 0;
for (MagicEdition me : list) {
mapCount.put(me, (temp.get(me.getId()) == null) ? 0 : temp.get(me.getId()));
countDefaultLibrary += mapCount.get(me);
}
for (MagicEdition me : list) countTotal += me.getCardCount();
}
Aggregations