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 @@ ...@@ -16,39 +16,27 @@
* future versions of the Software. * 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.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlElement; 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.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo; import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
public class ReaderEventRestPojo { public class ReaderEventRestPojo {
private ReaderEvent event;
private EventUserRestPojo eventUser; private EventUserRestPojo eventUser;
private PrintedCardRestPojo printedCard; private PrintedCardRestPojo printedCard;
private Integer readerEventId;
private Date readerEventTime;
private Integer readerId;
private Integer printedCardId;
private String printedCardState;
public ReaderEventRestPojo() { 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") @XmlElement(name = "eventuser")
public EventUserRestPojo getEventuser() { public EventUserRestPojo getEventuser() {
return eventUser; return eventUser;
...@@ -56,48 +44,27 @@ public class ReaderEventRestPojo { ...@@ -56,48 +44,27 @@ public class ReaderEventRestPojo {
@XmlElement(name = "readerEventId") @XmlElement(name = "readerEventId")
public Integer getEventId() { public Integer getEventId() {
return event.getId(); return readerEventId;
} }
@XmlElement(name = "readerEventTime") @XmlElement(name = "readerEventTime")
public Date getEventTime() { public Date getReaderEventTime() {
return event.getUpdatetime(); return readerEventTime;
} }
@XmlElement(name = "readerId") @XmlElement(name = "readerId")
public Integer getReaderId() { public Integer getReaderId() {
return event.getReader().getId(); return readerId;
} }
@XmlElement(name = "printedCardId") @XmlElement(name = "printedCardId")
public Integer getPrintedCardId() public Integer getPrintedCardId() {
{ return printedCardId;
Integer ret = null;
if (event != null && event.getPrintedCard() != null)
{
ret = event.getPrintedCard().getId();
}
return ret;
} }
@XmlElement(name = "printedCardState") @XmlElement(name = "printedCardState")
public CardState getPrintedCardState() public String getPrintedCardState() {
{ return printedCardState;
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 PrintedCardRestPojo getPrintedCard() { public PrintedCardRestPojo getPrintedCard() {
...@@ -107,4 +74,37 @@ public class ReaderEventRestPojo { ...@@ -107,4 +74,37 @@ public class ReaderEventRestPojo {
public void setPrintedCard(PrintedCardRestPojo printedCard) { public void setPrintedCard(PrintedCardRestPojo printedCard) {
this.printedCard = 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 @@ ...@@ -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.reader.v1;
import java.util.List; import java.util.List;
......
...@@ -16,53 +16,63 @@ ...@@ -16,53 +16,63 @@
* future versions of the Software. * 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.List;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.Reader;
import fi.codecrew.moya.model.ReaderType;
public class ReaderRestPojo { public class ReaderRestPojo {
private Reader reader; private Integer readerId;
private String identification;
private String description;
private String readerType;
public ReaderRestPojo() {
super();
}
@XmlElement(name = "readerId") @XmlElement(name = "readerId")
public Integer getId() { public Integer getId() {
return reader.getId(); return readerId;
} }
@XmlElement(name = "identification") @XmlElement(name = "identification")
public String getIdent() { public String getIdentification() {
return reader.getIdentification(); return identification;
} }
@XmlElement(name = "description") @XmlElement(name = "description")
public String getDescr() { public String getdescription() {
return reader.getDescription(); return description;
} }
@XmlElement(name = "readerType") @XmlElement(name = "readerType")
public ReaderType getType() { public String getReaderType() {
return reader.getType(); return readerType;
} }
public ReaderRestPojo() { public void setReaderType(String readerType) {
this.reader = null; this.readerType = readerType;
} }
public ReaderRestPojo(Reader r) { public Integer getReaderId() {
this.reader = r; return readerId;
} }
public static List<ReaderRestPojo> parse(List<Reader> readers) { public void setReaderId(Integer readerId) {
ArrayList<ReaderRestPojo> ret = new ArrayList<>(); this.readerId = readerId;
for (Reader r : readers) {
ret.add(new ReaderRestPojo(r));
}
return ret;
} }
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 @@ ...@@ -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.reader.v1;
import java.util.List; import java.util.List;
......
...@@ -7,10 +7,14 @@ import fi.codecrew.moya.model.EventMap; ...@@ -7,10 +7,14 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard; 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.MapPojo;
import fi.codecrew.moya.rest.pojo.map.v1.MapRoot; 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.PlacePojo;
import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot; 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.CardRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo; 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.PrintedCardRestPojo;
...@@ -128,4 +132,60 @@ public class PojoUtils { ...@@ -128,4 +132,60 @@ public class PojoUtils {
return new MapRoot(ret); 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; ...@@ -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.ReaderEventRestPojo; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderEventRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderEventRestRoot; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderEventRestRoot;
import fi.codecrew.moya.rest.pojo.ReaderRestPojo; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderRestRoot; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestRoot;
import fi.codecrew.moya.rest.pojo.UserPermissionRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo; import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.UserPermissionRestPojo;
@RequestScoped @RequestScoped
@Path("/reader") @Path("/reader")
...@@ -57,9 +57,8 @@ public class ReaderRestView { ...@@ -57,9 +57,8 @@ public class ReaderRestView {
@GET @GET
@Path("/List") @Path("/List")
public ReaderRestRoot getReaderList() public ReaderRestRoot getReaderList() {
{ return new ReaderRestRoot(PojoUtils.parseReaders(readerbean.getReaders()));
return new ReaderRestRoot(ReaderRestPojo.parse(readerbean.getReaders()));
} }
/** /**
...@@ -79,7 +78,7 @@ public class ReaderRestView { ...@@ -79,7 +78,7 @@ public class ReaderRestView {
events = readerbean.getReaderEvents(readerId, count); events = readerbean.getReaderEvents(readerId, count);
} }
return new ReaderEventRestRoot(ReaderEventRestPojo.parse(events)); return new ReaderEventRestRoot(PojoUtils.parseReaderEvents(events));
} }
@GET @GET
...@@ -94,7 +93,7 @@ public class ReaderRestView { ...@@ -94,7 +93,7 @@ public class ReaderRestView {
@Path("/LastEventusers") @Path("/LastEventusers")
public ReaderEventRestRoot getLastEventusers() public ReaderEventRestRoot getLastEventusers()
{ {
return new ReaderEventRestRoot(ReaderEventRestPojo.parse(readerbean.getLastReaderEvents())); return new ReaderEventRestRoot(PojoUtils.parseReaderEvents(readerbean.getLastReaderEvents()));
} }
// @GET // @GET
...@@ -147,6 +146,4 @@ public class ReaderRestView { ...@@ -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!