<%-- Copyright (c) 2013, Andy Janata All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> <%-- Interface to view and search all existing cards and card sets. @author Andy Janata (ajanata@socialgamer.net) --%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.HashSet" %> <%@ page import="java.util.List" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.Set" %> <%@ page import="net.socialgamer.cah.HibernateUtil" %> <%@ page import="net.socialgamer.cah.db.BlackCard" %> <%@ page import="net.socialgamer.cah.db.CardSet" %> <%@ page import="net.socialgamer.cah.db.WhiteCard" %> <%@ page import="org.hibernate.Session" %> <%@ page import="org.json.simple.JSONValue" %> <% Session hibernateSession = HibernateUtil.instance.sessionFactory.openSession(); // cheap way to make sure we can close the hibernate session at the end of the page try { // load from db @SuppressWarnings("unchecked") List cardSets = hibernateSession .createQuery("from CardSet where active = true order by weight, id") .setReadOnly(true) .list(); // all of the data to send to the client Map data = new HashMap(); // mapping of what card sets each card is in Map> whiteCardSets = new HashMap>(); Map> blackCardSets = new HashMap>(); // all of the cards that are actually in a card set Set whiteCards = new HashSet(); Set blackCards = new HashSet(); Map cardSetsData = new HashMap(); data.put("cardSets", cardSetsData); for (CardSet cardSet: cardSets) { Map cardSetData = new HashMap(); cardSetData.put("name", cardSet.getName()); cardSetData.put("id", cardSet.getId()); cardSetData.put("description", cardSet.getDescription()); List whiteCardIds = new ArrayList(cardSet.getWhiteCards().size()); for (WhiteCard whiteCard: cardSet.getWhiteCards()) { whiteCardIds.add(whiteCard.getId()); whiteCards.add(whiteCard); if (!whiteCardSets.containsKey(whiteCard.getId())) { whiteCardSets.put(whiteCard.getId(), new ArrayList()); } whiteCardSets.get(whiteCard.getId()).add(cardSet.getId()); } cardSetData.put("whiteCards", whiteCardIds); List blackCardIds = new ArrayList(cardSet.getBlackCards().size()); for (BlackCard blackCard: cardSet.getBlackCards()) { blackCardIds.add(blackCard.getId()); blackCards.add(blackCard); if (!blackCardSets.containsKey(blackCard.getId())) { blackCardSets.put(blackCard.getId(), new ArrayList()); } blackCardSets.get(blackCard.getId()).add(cardSet.getId()); } cardSetData.put("blackCards", blackCardIds); cardSetsData.put(cardSet.getWeight(), cardSetData); } Map blackCardsData = new HashMap(); data.put("blackCards", blackCardsData); for (BlackCard blackCard: blackCards) { Map blackCardData = new HashMap(); blackCardData.put("text", blackCard.getText()); blackCardData.put("watermark", blackCard.getWatermark()); blackCardData.put("draw", blackCard.getDraw()); blackCardData.put("pick", blackCard.getPick()); blackCardData.put("card_sets", blackCardSets.get(blackCard.getId())); blackCardsData.put(blackCard.getId(), blackCardData); } Map whiteCardsData = new HashMap(); data.put("whiteCards", whiteCardsData); for (WhiteCard whiteCard: whiteCards) { Map whiteCardData = new HashMap(); whiteCardData.put("text", whiteCard.getText()); whiteCardData.put("watermark", whiteCard.getWatermark()); whiteCardData.put("card_sets", whiteCardSets.get(whiteCard.getId())); whiteCardsData.put(whiteCard.getId(), whiteCardData); } %> Pretend You're Xyzzy: View Cards
Show only cards from card sets (hold ctrl or cmd to select multiple):
Type Text Source Draw Pick
<% } finally { hibernateSession.close(); } %>