use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MysqlDAO method getCollection.
@Override
public MagicCollection getCollection(String name) throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from collections where name= ?")) {
pst.setString(1, name);
try (ResultSet rs = pst.executeQuery()) {
if (rs.next()) {
MagicCollection mc = new MagicCollection();
mc.setName(rs.getString("name"));
return mc;
}
return null;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class PostgresqlDAO method listCollectionFromCards.
@Override
public List<MagicCollection> listCollectionFromCards(MagicCard mc) throws SQLException {
if (mc.getEditions().isEmpty())
throw new SQLException("No edition defined");
try (PreparedStatement pst = con.prepareStatement("SELECT collection FROM cards WHERE name=? and edition=?")) {
pst.setString(1, mc.getName());
pst.setString(2, mc.getEditions().get(0).getId());
try (ResultSet rs = pst.executeQuery()) {
List<MagicCollection> cols = new ArrayList<>();
while (rs.next()) {
MagicCollection col = new MagicCollection();
col.setName(rs.getString("collection"));
cols.add(col);
}
return cols;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class PostgresqlDAO method getCollection.
@Override
public MagicCollection getCollection(String name) throws SQLException {
try (PreparedStatement pst = con.prepareStatement("select * from collections where name= ?")) {
pst.setString(1, name);
try (ResultSet rs = pst.executeQuery()) {
if (rs.next()) {
MagicCollection mc = new MagicCollection();
mc.setName(rs.getString("name"));
return mc;
}
return null;
}
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class Search method run.
@Override
public void run(String[] args, IoSession session, MTGConsoleHandler mtgConsoleHandler) throws ParseException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
CommandLine cl = parser.parse(opts, args);
this.session = session;
if (cl.hasOption("c")) {
String att = cl.getOptionValue("c").split("=")[0];
String val = cl.getOptionValue("c").split("=")[1];
List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(att, val, null, false);
session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCards())));
}
if (cl.hasOption("s")) {
List<MagicEdition> list = MTGControler.getInstance().getEnabledProviders().loadEditions();
session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttSet())));
}
if (cl.hasOption("col")) {
List<MagicCollection> list;
try {
list = MTGControler.getInstance().getEnabledDAO().getCollections();
} catch (SQLException e) {
throw new IOException(e);
}
session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCols())));
}
if (cl.hasOption("?")) {
usage();
}
}
use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.
the class MagicWebSiteGenerator method generateCollectionsTemplate.
// lister les editions disponibles
private void generateCollectionsTemplate() throws IOException, TemplateException, SQLException {
Template generatedColTemplate = cfg.getTemplate("page-col.html");
for (MagicCollection col : cols) {
Map rootEd = new HashMap<>();
rootEd.put("cols", cols);
rootEd.put("colName", col.getName());
Set<MagicEdition> eds = new HashSet<>();
for (MagicCard mc : dao.listCardsFromCollection(col)) {
eds.add(mc.getEditions().get(0));
generateCardsTemplate(mc);
}
rootEd.put("editions", eds);
FileWriter out = new FileWriter(Paths.get(dest, "page-col-" + col.getName() + ".htm").toFile());
generatedColTemplate.process(rootEd, out);
generateEditionsTemplate(eds, col);
out.close();
}
}
Aggregations