Commit ea6e614f by Tuomas Riihimäki

Move User rest pojos from web project to restpojo-project

1 parent 044491ba
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.userinfo.v1;
import java.util.List;
......
......@@ -16,75 +16,83 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.userinfo.v1;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.EventUser;
public class EventUserRestPojo {
private EventUser user;
private String nick = "";
private String login = "";
private Integer eventuserId = 0;
private Integer userId = 0;
private String firstname = "";
private String lastname = "";
public EventUserRestPojo() {
}
public EventUserRestPojo(EventUser user) {
this.user = user;
}
@XmlElement(name = "nick")
public String getUsername()
{
if(user == null)
return "";
else
return user.getUser().getNick();
public String getNick() {
return nick;
}
@XmlElement(name = "login")
public String getLogin()
{
if(user == null)
return "";
else
return user.getUser().getLogin();
return login;
}
@XmlElement(name = "eventuserId")
public Integer getEventuserId()
{
if(user == null)
return 0;
else
return user.getId();
return eventuserId;
}
@XmlElement(name = "userId")
public Integer getuserId()
{
if(user == null)
return 0;
else
return user.getUser().getId();
return getUserId();
}
@XmlElement(name = "firstname")
public String getFirstname()
{
if(user == null)
return "";
else
return user.getUser().getFirstnames();
public String getFirstname() {
return firstname;
}
@XmlElement(name = "lastname")
public String getLastname()
{
if(user == null)
return "";
else
return user.getUser().getLastname();
public String getLastname() {
return lastname;
}
public void setNick(String nick) {
this.nick = nick;
}
public void setLogin(String login) {
this.login = login;
}
public void setEventuserId(Integer eventuserId) {
this.eventuserId = eventuserId;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}
......@@ -16,86 +16,91 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.userinfo.v1;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import fi.codecrew.moya.model.PrintedCard;
public class PrintedCardRestPojo {
public PrintedCardRestPojo() {
card = null;
}
private Integer eventuserId;
private Integer id;
private String template;
private String username;
private String wholeName;
private String state;
private Date printTime;
public PrintedCardRestPojo(PrintedCard card)
{
this.card = card;
public PrintedCardRestPojo() {
super();
}
@XmlElement(name = "eventuserId")
public Integer getEventuserId() {
return card.getUser().getId();
return eventuserId;
}
@XmlTransient
private final PrintedCard card;
@XmlElement(name = "cardId")
public Integer getId()
{
return card.getId();
public Integer getId() {
return id;
}
@XmlElement(name = "cardTemplate")
public String getTemplate()
{
String ret = null;
if (card.getTemplate() != null)
ret = card.getTemplate().getName();
return ret;
public String getTemplate() {
return template;
}
@XmlElement(name = "username")
public String getUsername()
{
return card.getUser().getNick();
return username;
}
@XmlElement(name = "wholeName")
public String getWholeName()
{
return card.getUser().getWholeName();
public String getWholeName() {
return wholeName;
}
@XmlElement(name = "state")
public String getState() {
return card.getCardState().toString();
return state;
}
@XmlElement(name = "printTime")
public Date getPrintTime()
{
Date ret = null;
if (card.getPrintTime() != null)
ret = card.getPrintTime().getTime();
return ret;
public Date getPrintTime() {
return printTime;
}
public static CardRoot parseCards(List<PrintedCard> cards)
{
ArrayList<PrintedCardRestPojo> ret = new ArrayList<PrintedCardRestPojo>();
for (PrintedCard c : cards) {
ret.add(new PrintedCardRestPojo(c));
public void setEventuserId(Integer eventuserId) {
this.eventuserId = eventuserId;
}
CardRoot root = new CardRoot();
root.setCards(ret);
return root;
public void setId(Integer id) {
this.id = id;
}
public void setTemplate(String template) {
this.template = template;
}
public void setUsername(String username) {
this.username = username;
}
public void setWholeName(String wholeName) {
this.wholeName = wholeName;
}
public void setState(String state) {
this.state = state;
}
public void setPrintTime(Date printTime) {
this.printTime = printTime;
}
}
......@@ -16,21 +16,25 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.userinfo.v1;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventUser;
@XmlRootElement()
public class SimpleEventuserRoot {
private List<EventUserRestPojo> eventusers;
public SimpleEventuserRoot() {
super();
}
public SimpleEventuserRoot(List<EventUserRestPojo> users)
{
this.eventusers = users;
}
public SimpleEventuserRoot(ArrayList<EventUserRestPojo> list) {
......@@ -44,14 +48,4 @@ public class SimpleEventuserRoot {
public void setEventusers(List<EventUserRestPojo> eventusers) {
this.eventusers = eventusers;
}
public static SimpleEventuserRoot parse(List<EventUser> users) {
ArrayList<EventUserRestPojo> list = new ArrayList<>();
for (EventUser u : users)
{
list.add(new EventUserRestPojo(u));
}
return new SimpleEventuserRoot(list);
}
}
package fi.codecrew.moya.rest;
import java.util.ArrayList;
import java.util.List;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.rest.pojo.userinfo.v1.CardRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.SimpleEventuserRoot;
public class PojoUtils {
public static EventUserRestPojo initEventUserRestPojo(EventUser user)
{
EventUserRestPojo ret = new EventUserRestPojo();
ret.setNick(user.getUser().getNick());
ret.setLogin(user.getUser().getLogin());
ret.setEventuserId(user.getId());
ret.setUserId(user.getUser().getId());
ret.setFirstname(user.getUser().getFirstnames());
ret.setLastname(user.getUser().getLastname());
return ret;
}
public static SimpleEventuserRoot parseEventusers(List<EventUser> users) {
ArrayList<EventUserRestPojo> list = new ArrayList<>();
for (EventUser u : users) {
list.add(initEventUserRestPojo(u));
}
return new SimpleEventuserRoot(list);
}
public static PrintedCardRestPojo initPrintedCardRestPojo(PrintedCard card)
{
PrintedCardRestPojo ret = new PrintedCardRestPojo();
ret.setEventuserId(card.getUser().getId());
ret.setId(card.getId());
if (card.getTemplate() != null)
ret.setTemplate(card.getTemplate().getName());
ret.setUsername(card.getUser().getNick());
ret.setWholeName(card.getUser().getWholeName());
ret.setState(card.getCardState().toString());
if (card.getPrintTime() != null)
ret.setPrintTime(card.getPrintTime().getTime());
return ret;
}
public static CardRoot parsePrintedCards(List<PrintedCard> cards)
{
ArrayList<PrintedCardRestPojo> ret = new ArrayList<PrintedCardRestPojo>();
for (PrintedCard c : cards) {
ret.add(initPrintedCardRestPojo(c));
}
CardRoot root = new CardRoot();
root.setCards(ret);
return root;
}
}
......@@ -38,8 +38,8 @@ 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;
import fi.codecrew.moya.rest.pojo.userinfo.v1.CardRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
@RequestScoped
@Path("/card")
......@@ -63,7 +63,7 @@ public class PrinterRestView {
try {
PrintedCard card = cardbean.setCardState(cardId, CardState.PRINTING_IN_PROGRESS);
if (card.getCardState().equals(CardState.PRINTING_IN_PROGRESS)) {
ret = Response.ok(new PrintedCardRestPojo(card));
ret = Response.ok(PojoUtils.initPrintedCardRestPojo(card));
}
} catch (Exception e) {
ret = null;
......@@ -79,7 +79,7 @@ public class PrinterRestView {
@GET
@Path("/Printed/{id}/")
public PrintedCardRestPojo setCardPrinted(@PathParam("id") int cardId, @QueryParam("key") String hash) throws Exception {
return new PrintedCardRestPojo(cardbean.setCardState(cardId, CardState.PRINTED));
return PojoUtils.initPrintedCardRestPojo(cardbean.setCardState(cardId, CardState.PRINTED));
// PrintedCard card = cardbean.findCard(cardId);
// card.setCardState(CardState.PRINTED);
// card.setPrintCount(card.getPrintCount() + 1);
......@@ -91,7 +91,7 @@ public class PrinterRestView {
@Path("/Get/{id}/")
public PrintedCardRestPojo getCard(@PathParam("id") int cardId, @QueryParam("key") String hash) throws Exception {
PrintedCard card = cardbean.findCard(cardId);
return new PrintedCardRestPojo(card);
return PojoUtils.initPrintedCardRestPojo(card);
}
@GET
......@@ -118,7 +118,7 @@ public class PrinterRestView {
@GET
@Path("/ListUnprinted")
public CardRoot getUserCard(@QueryParam("key") String key) throws Exception {
CardRoot ret = PrintedCardRestPojo.parseCards(cardbean.getCardsByState(CardState.VALIDATED));
CardRoot ret = PojoUtils.parsePrintedCards(cardbean.getCardsByState(CardState.VALIDATED));
logger.info("Returning card pojos: {} for key {}", ret, key);
return ret;
}
......@@ -126,7 +126,7 @@ public class PrinterRestView {
@GET
@Path("/ListAll")
public CardRoot getAllCards(@QueryParam("key") String key) throws Exception {
CardRoot ret = PrintedCardRestPojo.parseCards(cardbean.getCardsByState());
CardRoot ret = PojoUtils.parsePrintedCards(cardbean.getCardsByState());
logger.info("Returning card pojos: {} for key {}", ret, key);
return ret;
}
......
......@@ -36,12 +36,12 @@ import fi.codecrew.moya.beans.ReaderBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.ReaderEvent;
import fi.codecrew.moya.rest.pojo.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderEventRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderEventRestRoot;
import fi.codecrew.moya.rest.pojo.ReaderRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderRestRoot;
import fi.codecrew.moya.rest.pojo.UserPermissionRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
@RequestScoped
@Path("/reader")
......@@ -132,13 +132,14 @@ public class ReaderRestView {
} else {
builder = Response.status(Status.FORBIDDEN);
}
builder.entity(new UserPermissionRestPojo(new EventUserRestPojo(user), found));
builder.entity(new UserPermissionRestPojo(PojoUtils.initEventUserRestPojo(user), found));
}
}
return builder.build();
}
//
// @GET
// @Path("/EventCard/{reader}/{cardid}")
......@@ -146,4 +147,6 @@ public class ReaderRestView {
//
// }
}
......@@ -32,9 +32,9 @@ import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.CardTemplateBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.rest.pojo.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.PrintedCardRestPojo;
import fi.codecrew.moya.rest.pojo.SimpleEventuserRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.SimpleEventuserRoot;
import fi.codecrew.moya.util.UserSearchQuery;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
import fi.codecrew.moya.utilities.SearchResult;
......@@ -56,14 +56,14 @@ public class UserRestView {
public SimpleEventuserRoot getEventUsers() {
UserSearchQuery q = new UserSearchQuery(0, 0, null, null, QuerySortOrder.UNSORTED);
SearchResult<EventUser> users = userbean.getThisEventsUsers(q);
return SimpleEventuserRoot.parse(users.getResults());
return PojoUtils.parseEventusers(users.getResults());
}
@GET
@Path("/card/{eventuserId}")
public PrintedCardRestPojo getUsersCard(@PathParam("eventuserId") Integer eventuserid) {
EventUser user = userbean.findByEventUserId(eventuserid);
return new PrintedCardRestPojo(cardbean.checkPrintedCard(user));
return PojoUtils.initPrintedCardRestPojo(cardbean.checkPrintedCard(user));
}
......@@ -73,7 +73,7 @@ public class UserRestView {
EventUser user = userbean.getUserByAuthcode(code);
if(user != null)
return new EventUserRestPojo(user);
return PojoUtils.initEventUserRestPojo(user);
else
return new EventUserRestPojo();
}
......
......@@ -26,6 +26,9 @@ import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.enums.CardState;
import fi.codecrew.moya.model.ReaderEvent;
import fi.codecrew.moya.rest.PojoUtils;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
public class ReaderEventRestPojo {
private ReaderEvent event;
......@@ -39,10 +42,10 @@ public class ReaderEventRestPojo {
this.event = re;
if (re != null && re.getPrintedCard() != null) {
if (re.getPrintedCard().getUser() != null) {
eventUser = new EventUserRestPojo(re.getPrintedCard().getUser());
eventUser = PojoUtils.initEventUserRestPojo(re.getPrintedCard().getUser());
}
} else if(re != null && re.getUser() != null) {
eventUser = new EventUserRestPojo(re.getUser());
} else if (re != null && re.getUser() != null) {
eventUser = PojoUtils.initEventUserRestPojo(re.getUser());
}
}
......
......@@ -20,6 +20,8 @@ package fi.codecrew.moya.rest.pojo;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
public class UserPermissionRestPojo {
public UserPermissionRestPojo(EventUserRestPojo eventUserRestPojo, boolean granted)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!