Commit 28bfd68e by Tuomas Riihimäki

Rest to jackson.

1 parent c9b01cc0
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
package fi.codecrew.moya.rest;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
......@@ -22,6 +20,7 @@ import fi.codecrew.moya.beans.CardTemplateBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.CardState;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.rest.pojo.CardRoot;
import fi.codecrew.moya.rest.pojo.PrintedCardRestPojo;
@RequestScoped
......@@ -98,16 +97,16 @@ public class PrinterRestView {
@GET
@Path("/ListUnprinted")
public List<PrintedCardRestPojo> getUserCard(@QueryParam("key") String key) throws Exception {
List<PrintedCardRestPojo> ret = PrintedCardRestPojo.parseCards(cardbean.getCardsByState(CardState.VALIDATED));
public CardRoot getUserCard(@QueryParam("key") String key) throws Exception {
CardRoot ret = PrintedCardRestPojo.parseCards(cardbean.getCardsByState(CardState.VALIDATED));
logger.info("Returning card pojos: {} for key {}", ret, key);
return ret;
}
@GET
@Path("/ListAll")
public List<PrintedCardRestPojo> getAllCards(@QueryParam("key") String key) throws Exception {
List<PrintedCardRestPojo> ret = PrintedCardRestPojo.parseCards(cardbean.getCardsByState());
public CardRoot getAllCards(@QueryParam("key") String key) throws Exception {
CardRoot ret = PrintedCardRestPojo.parseCards(cardbean.getCardsByState());
logger.info("Returning card pojos: {} for key {}", ret, key);
return ret;
}
......
package fi.codecrew.moya.rest.pojo;
import java.util.List;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class CardRoot {
@XmlElementWrapper(name = "cards")
private List<PrintedCardRestPojo> cards;
public List<PrintedCardRestPojo> getCards() {
return cards;
}
public void setCards(List<PrintedCardRestPojo> cards) {
this.cards = cards;
}
}
......@@ -4,12 +4,10 @@ import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import fi.codecrew.moya.model.PrintedCard;
@XmlRootElement(name = "cards")
public class PrintedCardRestPojo {
public PrintedCardRestPojo() {
......@@ -57,12 +55,14 @@ public class PrintedCardRestPojo {
return card.getCardState().toString();
}
public static List<PrintedCardRestPojo> parseCards(List<PrintedCard> cards)
public static CardRoot parseCards(List<PrintedCard> cards)
{
ArrayList<PrintedCardRestPojo> ret = new ArrayList<PrintedCardRestPojo>();
for (PrintedCard c : cards) {
ret.add(new PrintedCardRestPojo(c));
}
return ret;
CardRoot root = new CardRoot();
root.setCards(ret);
return root;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!