Commit fca5b3e2 by Tuomas Riihimäki

Move reader rest pojos from web to restpojo project

1 parent 0f4e7cd7
Showing with 153 additions and 86 deletions
......@@ -16,39 +16,27 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.reader.v1;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
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;
private EventUserRestPojo eventUser;
private PrintedCardRestPojo printedCard;
private Integer readerEventId;
private Date readerEventTime;
private Integer readerId;
private Integer printedCardId;
private String printedCardState;
public ReaderEventRestPojo() {
}
public ReaderEventRestPojo(ReaderEvent re) {
this.event = re;
if (re != null && re.getPrintedCard() != null) {
if (re.getPrintedCard().getUser() != null) {
eventUser = PojoUtils.initEventUserRestPojo(re.getPrintedCard().getUser());
}
} else if (re != null && re.getUser() != null) {
eventUser = PojoUtils.initEventUserRestPojo(re.getUser());
}
}
@XmlElement(name = "eventuser")
public EventUserRestPojo getEventuser() {
return eventUser;
......@@ -56,48 +44,27 @@ public class ReaderEventRestPojo {
@XmlElement(name = "readerEventId")
public Integer getEventId() {
return event.getId();
return readerEventId;
}
@XmlElement(name = "readerEventTime")
public Date getEventTime() {
return event.getUpdatetime();
public Date getReaderEventTime() {
return readerEventTime;
}
@XmlElement(name = "readerId")
public Integer getReaderId() {
return event.getReader().getId();
return readerId;
}
@XmlElement(name = "printedCardId")
public Integer getPrintedCardId()
{
Integer ret = null;
if (event != null && event.getPrintedCard() != null)
{
ret = event.getPrintedCard().getId();
}
return ret;
public Integer getPrintedCardId() {
return printedCardId;
}
@XmlElement(name = "printedCardState")
public CardState getPrintedCardState()
{
CardState ret = null;
if (event != null && event.getPrintedCard() != null) {
ret = event.getPrintedCard().getCardState();
}
return ret;
}
public static List<ReaderEventRestPojo> parse(List<ReaderEvent> readers) {
List<ReaderEventRestPojo> ret = new ArrayList<>();
for (ReaderEvent re : readers)
{
ret.add(new ReaderEventRestPojo(re));
}
return ret;
public String getPrintedCardState() {
return printedCardState;
}
public PrintedCardRestPojo getPrintedCard() {
......@@ -107,4 +74,37 @@ public class ReaderEventRestPojo {
public void setPrintedCard(PrintedCardRestPojo printedCard) {
this.printedCard = printedCard;
}
public EventUserRestPojo getEventUser() {
return eventUser;
}
public void setEventUser(EventUserRestPojo eventUser) {
this.eventUser = eventUser;
}
public Integer getReaderEventId() {
return readerEventId;
}
public void setReaderEventId(Integer readerEventId) {
this.readerEventId = readerEventId;
}
public void setReaderEventTime(Date readerEventTime) {
this.readerEventTime = readerEventTime;
}
public void setReaderId(Integer readerId) {
this.readerId = readerId;
}
public void setPrintedCardId(Integer printedCardId) {
this.printedCardId = printedCardId;
}
public void setPrintedCardState(String printedCardState) {
this.printedCardState = printedCardState;
}
}
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.reader.v1;
import java.util.List;
......
......@@ -16,53 +16,63 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
import java.util.ArrayList;
import java.util.List;
package fi.codecrew.moya.rest.pojo.reader.v1;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.Reader;
import fi.codecrew.moya.model.ReaderType;
public class ReaderRestPojo {
private Reader reader;
private Integer readerId;
private String identification;
private String description;
private String readerType;
public ReaderRestPojo() {
super();
}
@XmlElement(name = "readerId")
public Integer getId() {
return reader.getId();
return readerId;
}
@XmlElement(name = "identification")
public String getIdent() {
return reader.getIdentification();
public String getIdentification() {
return identification;
}
@XmlElement(name = "description")
public String getDescr() {
return reader.getDescription();
public String getdescription() {
return description;
}
@XmlElement(name = "readerType")
public ReaderType getType() {
return reader.getType();
public String getReaderType() {
return readerType;
}
public ReaderRestPojo() {
this.reader = null;
public void setReaderType(String readerType) {
this.readerType = readerType;
}
public ReaderRestPojo(Reader r) {
this.reader = r;
public Integer getReaderId() {
return readerId;
}
public static List<ReaderRestPojo> parse(List<Reader> readers) {
ArrayList<ReaderRestPojo> ret = new ArrayList<>();
for (Reader r : readers) {
ret.add(new ReaderRestPojo(r));
}
return ret;
public void setReaderId(Integer readerId) {
this.readerId = readerId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public void setIdentification(String identification) {
this.identification = identification;
}
}
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.reader.v1;
import java.util.List;
......
......@@ -7,10 +7,14 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Reader;
import fi.codecrew.moya.model.ReaderEvent;
import fi.codecrew.moya.rest.pojo.map.v1.MapPojo;
import fi.codecrew.moya.rest.pojo.map.v1.MapRoot;
import fi.codecrew.moya.rest.pojo.map.v1.PlacePojo;
import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot;
import fi.codecrew.moya.rest.pojo.reader.v1.ReaderEventRestPojo;
import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestPojo;
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;
......@@ -128,4 +132,60 @@ public class PojoUtils {
return new MapRoot(ret);
}
public static ReaderEventRestPojo initReaderEventRestPojo(ReaderEvent event) {
ReaderEventRestPojo ret = new ReaderEventRestPojo();
if (event != null && event.getPrintedCard() != null) {
if (event.getPrintedCard().getUser() != null) {
ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getPrintedCard().getUser()));
}
} else if (event != null && event.getUser() != null) {
ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getUser()));
}
ret.setReaderEventId(event.getId());
ret.setReaderEventTime(event.getUpdatetime());
ret.setReaderId(event.getReader().getId());
if (event != null && event.getPrintedCard() != null) {
ret.setPrintedCardId(event.getPrintedCard().getId());
}
if (event != null && event.getPrintedCard() != null) {
ret.setPrintedCardState(event.getPrintedCard().getCardState().name());
}
return ret;
}
public static List<ReaderEventRestPojo> parseReaderEvents(List<ReaderEvent> readers) {
List<ReaderEventRestPojo> ret = new ArrayList<>();
for (ReaderEvent re : readers) {
ret.add(initReaderEventRestPojo(re));
}
return ret;
}
public static ReaderRestPojo initReaderRestPojo(Reader reader)
{
ReaderRestPojo ret = new ReaderRestPojo();
ret.setReaderId(reader.getId());
ret.setIdentification(reader.getIdentification());
ret.setDescription(reader.getDescription());
String rt = null;
if (reader.getType() != null) {
rt = reader.getType().name();
}
ret.setReaderType(rt);
return ret;
}
public static List<ReaderRestPojo> parseReaders(List<Reader> readers) {
ArrayList<ReaderRestPojo> ret = new ArrayList<>();
for (Reader r : readers) {
ret.add(initReaderRestPojo(r));
}
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.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.reader.v1.ReaderEventRestPojo;
import fi.codecrew.moya.rest.pojo.reader.v1.ReaderEventRestRoot;
import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestPojo;
import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.UserPermissionRestPojo;
@RequestScoped
@Path("/reader")
......@@ -57,9 +57,8 @@ public class ReaderRestView {
@GET
@Path("/List")
public ReaderRestRoot getReaderList()
{
return new ReaderRestRoot(ReaderRestPojo.parse(readerbean.getReaders()));
public ReaderRestRoot getReaderList() {
return new ReaderRestRoot(PojoUtils.parseReaders(readerbean.getReaders()));
}
/**
......@@ -79,7 +78,7 @@ public class ReaderRestView {
events = readerbean.getReaderEvents(readerId, count);
}
return new ReaderEventRestRoot(ReaderEventRestPojo.parse(events));
return new ReaderEventRestRoot(PojoUtils.parseReaderEvents(events));
}
@GET
......@@ -94,7 +93,7 @@ public class ReaderRestView {
@Path("/LastEventusers")
public ReaderEventRestRoot getLastEventusers()
{
return new ReaderEventRestRoot(ReaderEventRestPojo.parse(readerbean.getLastReaderEvents()));
return new ReaderEventRestRoot(PojoUtils.parseReaderEvents(readerbean.getLastReaderEvents()));
}
// @GET
......@@ -147,6 +146,4 @@ public class ReaderRestView {
//
// }
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!