Commit ea6e614f by Tuomas Riihimäki

Move User rest pojos from web project to restpojo-project

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