Commit c7abafdc by Tuukka Kivilahti

Merge branch 'restproject' into 'master'

Rest pojo project

Irrotetaan REST-pojot omaksi projektikseen WEB-projektista jolloin voidaan sisällyttää helposti myös restiä kutsuvaan projektiin (esim DRD)

See merge request !191
2 parents f9fbb97a e71dfcdd
Showing with 894 additions and 668 deletions
......@@ -4,7 +4,6 @@
<artifactId>moya-beans-client</artifactId>
<build>
<sourceDirectory>ejbModule</sourceDirectory>
</build>
<dependencies>
<dependency>
......
......@@ -10,6 +10,7 @@
<module>../moya-authmodule</module>
<module>../moya-authmodule-client</module>
<module>../moya-database</module>
<module>../moya-restpojo</module>
<module>../moya-beans-client</module>
<module>../moya-beans</module>
<module>../moya-web</module>
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>moya-restpojo</artifactId>
<parent>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-parent</artifactId>
<version>1.0</version>
<relativePath>../moya-parent/pom.xml</relativePath>
</parent>
<!--
<dependencies>
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-database</artifactId>
<version>${moya.version}</version>
</dependency>
</dependencies>
-->
</project>
\ No newline at end of file
package fi.codecrew.moya.rest.pojo.map.v1;
import javax.xml.bind.annotation.XmlElement;
public class MapPojo {
private String name;
private Integer id;
private Boolean active;
public MapPojo() {
super();
}
@XmlElement(name = "name")
public String getName() {
return name;
}
@XmlElement(name = "id")
public Integer getId() {
return id;
}
@XmlElement(name = "active")
public boolean isActive() {
return active;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public void setName(String name) {
this.name = name;
}
public void setId(Integer id) {
this.id = id;
}
}
......@@ -16,16 +16,12 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.map.v1;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventMap;
@XmlRootElement
public class MapRoot {
......@@ -47,41 +43,4 @@ public class MapRoot {
this.maps = maps;
}
public static class MapPojo {
private EventMap map;
public MapPojo() {
super();
}
public MapPojo(EventMap m) {
this();
this.map = m;
}
@XmlElement(name = "name")
public String getName() {
return map.getName();
}
@XmlElement(name = "id")
public Integer getId() {
return map.getId();
}
@XmlElement(name = "active")
public boolean isActive() {
return map.isActive();
}
}
public static MapRoot parseMaps(List<EventMap> eventMaps) {
List<MapPojo> ret = new ArrayList<>();
for (EventMap m : eventMaps) {
ret.add(new MapPojo(m));
}
return new MapRoot(ret);
}
}
......@@ -16,9 +16,13 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.map.v1;
public class PlaceInputPojo {
import java.util.Calendar;
import javax.xml.bind.annotation.XmlElement;
public class PlacePojo {
private Integer id;
private String name;
......@@ -31,6 +35,12 @@ public class PlaceInputPojo {
private Integer productId;
private Integer mapId;
private Boolean taken;
private String details;
private String code;
private Calendar releaseTime;
private String description;
private Integer reserverId;
private Integer eventuserId;
public String getName() {
return name;
......@@ -88,6 +98,7 @@ public class PlaceInputPojo {
this.disabled = disabled;
}
@XmlElement
public Integer getProductId() {
return productId;
}
......@@ -120,4 +131,52 @@ public class PlaceInputPojo {
this.taken = taken;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Calendar getReleaseTime() {
return releaseTime;
}
public void setReleaseTime(Calendar releaseTime) {
this.releaseTime = releaseTime;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getReserverId() {
return reserverId;
}
public void setReserverId(Integer reserverId) {
this.reserverId = reserverId;
}
public Integer getEventuserId() {
return eventuserId;
}
public void setEventuserId(Integer eventuserId) {
this.eventuserId = eventuserId;
}
}
......@@ -16,31 +16,22 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.map.v1;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.rest.pojo.MapRoot.MapPojo;
@XmlRootElement
public class PlaceRoot {
public PlaceRoot()
{
}
public PlaceRoot(EventMap map2) {
this.map = new MapPojo(map2);
setPlaces(PlaceOutPojo.parse(map2.getPlaces()));
public PlaceRoot() {
super();
}
private MapPojo map;
private List<PlaceOutPojo> places;
private List<PlacePojo> places;
public MapPojo getMap() {
return map;
......@@ -50,11 +41,11 @@ public class PlaceRoot {
this.map = map;
}
public List<PlaceOutPojo> getPlaces() {
public List<PlacePojo> getPlaces() {
return places;
}
public void setPlaces(List<PlaceOutPojo> places) {
public void setPlaces(List<PlacePojo> places) {
this.places = places;
}
......
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.network.v1;
import javax.xml.bind.annotation.XmlElement;
......
......@@ -16,14 +16,10 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
import java.util.Calendar;
package fi.codecrew.moya.rest.pojo.network.v1;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.NetworkAssociation;
public class NetworkAssociationInfoPojo {
private String createTime;
private String modifyTime;
......@@ -32,18 +28,7 @@ public class NetworkAssociationInfoPojo {
private Integer placeId;
private Integer eventuserId;
public NetworkAssociationInfoPojo(NetworkAssociation na) {
this.createTime = na.getCreateTime().getTime().toString();
this.modifyTime = na.getModifyTime().getTime().toString();
this.ipAddress = na.getIP();
this.macAddress = na.getMAC();
if(na.getPlace() != null)
this.placeId = na.getPlace().getId();
else
this.placeId = null;
this.eventuserId = na.getEventUser().getId();
}
public NetworkAssociationInfoPojo() {
this.createTime = null;
......
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.ArrayList;
import java.util.List;
......
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.ArrayList;
import java.util.List;
......
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.ArrayList;
import java.util.List;
......
......@@ -16,7 +16,7 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.network.v1;
import javax.xml.bind.annotation.XmlElement;
......
package fi.codecrew.moya.rest.pojo.placemap;
package fi.codecrew.moya.rest.pojo.placemap.v1;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
......@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class IntegerRoot {
private Integer value = -1;
@XmlElement(name = "value")
......
package fi.codecrew.moya.rest.pojo.placemap;
package fi.codecrew.moya.rest.pojo.placemap.v1;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
......@@ -9,10 +8,6 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.rest.pojo.ProductRestPojo;
@XmlRootElement
public class PlacemapMapRootPojo {
......@@ -25,56 +20,50 @@ public class PlacemapMapRootPojo {
public static class MapPojo {
private EventMap map;
private Integer id;
private String name;
private Integer width;
private Integer height;
public MapPojo() {
}
public MapPojo(EventMap map2) {
this.map = map2;
}
@XmlElement(name = "name")
public String getName() {
return map.getName();
return name;
}
@XmlElement(name = "id")
public Integer getId() {
return map.getId();
return id;
}
@XmlElement(name = "width")
public Integer getWidth() {
return map.getWidth();
return width;
}
@XmlElement(name = "height")
public Integer getHeight() {
return map.getHeight();
return height;
}
}
public List<ProductRestPojo> getProducts() {
return products;
}
public void setId(Integer id) {
this.id = id;
}
public void setProducts(List<ProductRestPojo> products) {
this.products = products;
}
public void setName(String name) {
this.name = name;
}
public void setMap(EventMap map2) {
logger.info("Adding map {} to placemapMap", map2);
map = new MapPojo(map2);
}
public void setWidth(Integer width) {
this.width = width;
}
public void setRawProducts(List<Product> mapProducts) {
products = new ArrayList<>();
for (Product p : mapProducts) {
logger.warn("Adding product {}", p);
products.add(new ProductRestPojo(p));
public void setHeight(Integer height) {
this.height = height;
}
}
public MapPojo getMap() {
......@@ -85,4 +74,12 @@ public class PlacemapMapRootPojo {
this.map = map;
}
public List<ProductRestPojo> getProducts() {
return products;
}
public void setProducts(List<ProductRestPojo> products) {
this.products = products;
}
}
package fi.codecrew.moya.rest.pojo;
import java.math.BigDecimal;
package fi.codecrew.moya.rest.pojo.placemap.v1;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.Product;
public class ProductRestPojo {
private Product prod;
private Integer id;
private String name;
private String price;
private String description;
public ProductRestPojo() {
}
public ProductRestPojo(Product p) {
this.prod = p;
super();
}
@XmlElement(name = "id")
public Integer getId() {
return prod.getId();
return id;
}
@XmlElement(name = "name")
public String getName() {
return prod.getName();
return name;
}
@XmlElement(name = "price")
public String getPrice() {
return prod.getPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString();
return price;
}
@XmlElement(name = "description")
public String getDescription() {
return prod.getDescription();
return description;
}
public void setId(Integer id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(String price) {
this.price = price;
}
public void setDescription(String description) {
this.description = description;
}
}
package fi.codecrew.moya.rest.pojo.placemap.v1;
import javax.xml.bind.annotation.XmlElement;
public class SimplePlacePojo {
private Integer id;
private String name;
private String state;
private Integer x;
private Integer y;
private Integer width;
private Integer height;
public SimplePlacePojo() {
super();
}
@XmlElement(name = "id")
public Integer getId() {
return id;
}
@XmlElement(name = "name")
public String getName() {
return name;
}
@XmlElement(name = "state")
public String getState() {
return state;
}
@XmlElement(name = "x")
public Integer getX() {
return x;
}
@XmlElement(name = "y")
public Integer getY() {
return y;
}
@XmlElement(name = "w")
public Integer getWidth() {
return width;
}
@XmlElement(name = "h")
public Integer getHeight() {
return height;
}
public void setId(Integer id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setState(String state) {
this.state = state;
}
public void setX(Integer x) {
this.x = x;
}
public void setY(Integer y) {
this.y = y;
}
public void setWidth(Integer width) {
this.width = width;
}
public void setHeight(Integer height) {
this.height = height;
}
}
package fi.codecrew.moya.rest.pojo.placemap;
package fi.codecrew.moya.rest.pojo.placemap.v1;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
@XmlRootElement
public class SimplePlacelistRoot {
......@@ -21,16 +17,6 @@ public class SimplePlacelistRoot {
this.places = places;
}
public static SimplePlacelistRoot wrap(List<Place> places, EventUser user)
{
SimplePlacelistRoot ret = new SimplePlacelistRoot();
ArrayList<SimplePlacePojo> placeList = new ArrayList<SimplePlacePojo>();
ret.setPlaces(placeList);
for (Place p : places) {
placeList.add(new SimplePlacePojo(p, user));
}
return ret;
}
}
......@@ -16,36 +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.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 = new EventUserRestPojo(re.getPrintedCard().getUser());
}
} else if(re != null && re.getUser() != null) {
eventUser = new EventUserRestPojo(re.getUser());
}
}
@XmlElement(name = "eventuser")
public EventUserRestPojo getEventuser() {
return eventUser;
......@@ -53,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() {
......@@ -104,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;
......
......@@ -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));
}
CardRoot root = new CardRoot();
root.setCards(ret);
return root;
public void setEventuserId(Integer eventuserId) {
this.eventuserId = eventuserId;
}
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);
}
}
......@@ -16,7 +16,7 @@
* 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;
......
......@@ -12,7 +12,7 @@
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingIncludes>WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,WEB-INF/lib/*-1.0.8.jar,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*</packagingIncludes>
<packagingIncludes>WEB-INF/lib/moya-restpojo*,WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,WEB-INF/lib/*-1.0.8.jar,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*</packagingIncludes>
</configuration>
</plugin>
</plugins>
......@@ -34,13 +34,18 @@
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.8</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-restpojo</artifactId>
<version>${moya.version}</version>
</dependency>
</dependencies>
<parent>
<groupId>fi.codecrew.moya</groupId>
......
......@@ -49,10 +49,9 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.rest.pojo.MapRoot;
import fi.codecrew.moya.rest.pojo.PlaceInputPojo;
import fi.codecrew.moya.rest.pojo.PlaceOutPojo;
import fi.codecrew.moya.rest.pojo.PlaceRoot;
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;
@RequestScoped
@Path("/placeadmin")
......@@ -87,7 +86,7 @@ public class MapAdminView {
@GET
@Path("/maps")
public MapRoot getAllMaps() {
MapRoot ret = MapRoot.parseMaps(eventbean.getCurrentEvent().getEventMaps());
MapRoot ret = PojoUtils.parseMaps(eventbean.getCurrentEvent().getEventMaps());
logger.info("getallmaps called! {}", ret);
return ret;
}
......@@ -96,7 +95,7 @@ public class MapAdminView {
@Path("/places/{mapId}")
public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) {
EventMap map = placebean.findMap(mapid);
PlaceRoot ret = new PlaceRoot(map);
PlaceRoot ret = PojoUtils.initPlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret);
return ret;
}
......@@ -120,7 +119,7 @@ public class MapAdminView {
@POST
@Path("/place/")
public Response createPlace(PlaceInputPojo create) {
public Response createPlace(PlacePojo create) {
logger.info("Finding map with id {}", create.getMapId());
EventMap map = eventmapbean.find(create.getMapId());
if (map == null) {
......@@ -129,17 +128,17 @@ public class MapAdminView {
}
Place place = new Place();
place.setMap(map);
setPlaceValues(place, create);
setUpdatablePlaceValues(place, create);
if (create.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(create.getProductId())))
return Response.serverError().entity("Product id unknown!").build();
logger.info("Creating new place {}", place.getName());
eventmapbean.createPlace(place);
return Response.ok().entity(new PlaceOutPojo(place)).build();
return Response.ok().entity(PojoUtils.initPlacePojo(place)).build();
}
@PUT
@Path("/place/{id}")
public Response updatePlace(@PathParam("id") Integer id, PlaceInputPojo update) {
public Response updatePlace(@PathParam("id") Integer id, PlacePojo update) {
if (update == null || id == null) {
return Response.serverError().entity("'id' field is required!").build();
}
......@@ -147,12 +146,12 @@ public class MapAdminView {
if (place == null) {
return Response.serverError().entity("place not found with id: " + id).build();
}
setPlaceValues(place, update);
setUpdatablePlaceValues(place, update);
if (update.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(update.getProductId())))
return Response.serverError().entity("Product id unknown!").build();
place = eventmapbean.updatePlace(place);
return Response.ok(new PlaceOutPojo(place)).build();
return Response.ok(PojoUtils.initPlacePojo(place)).build();
}
@PUT
......@@ -185,7 +184,7 @@ public class MapAdminView {
return Response.serverError().build();
}
private void setPlaceValues(Place place, PlaceInputPojo update) {
private void setUpdatablePlaceValues(Place place, PlacePojo update) {
if (update.getName() != null)
place.setName(update.getName());
......
......@@ -33,189 +33,206 @@ import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.NetworkAssociationBeanLocal;
import fi.codecrew.moya.enums.NetworkAssociationStatus;
import fi.codecrew.moya.model.NetworkAssociation;
import fi.codecrew.moya.rest.pojo.NetworkAssociationActionPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfolistResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationResponseRoot;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationActionPojo;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoPojo;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoResponseRoot;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfolistResponseRoot;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationResponseRoot;
@RequestScoped
@Path("/networkassociation")
public class NetworkAssociationRestView {
@EJB
private NetworkAssociationBeanLocal networkAssociationBean;
@POST
@Path("/auth")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot auth(
@FormParam("username") String username,
@FormParam("password") String password,
@FormParam("ip") String ip,
@FormParam("mac") String mac,
@FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired
) {
@FormParam("username") String username,
@FormParam("password") String password,
@FormParam("ip") String ip,
@FormParam("mac") String mac,
@FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
NetworkAssociation na = networkAssociationBean.tryAssociate(
username, password, ip, mac, code, codeRequired);
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) {
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage());
} else {
resp.getResult().setMessage("UNKNOWN_ERROR");
}
}
return resp;
}
@POST
@Path("/codeauth")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot codeAuth(
@FormParam("usercode") String usercode,
@FormParam("ip") String ip,
@FormParam("mac") String mac,
@FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired
) {
@FormParam("usercode") String usercode,
@FormParam("ip") String ip,
@FormParam("mac") String mac,
@FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
NetworkAssociation na = networkAssociationBean.tryAssociate(
usercode, ip, mac, code, codeRequired);
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) {
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage());
} else {
resp.getResult().setMessage("UNKNOWN_ERROR");
}
}
return resp;
}
@GET
@Path("/get_association_infos")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfolistResponseRoot getAssociationInfos() {
NetworkAssociationInfolistResponseRoot nairr = new NetworkAssociationInfolistResponseRoot();
for(NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) {
nairr.getAssociations().add(new NetworkAssociationInfoPojo(na));
for (NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) {
nairr.getAssociations().add(initNetworkAssociationInfoPojo(na));
}
return nairr;
}
@GET
@Path("/get_association_info_by_ip/{ipAddress}")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfoResponseRoot getAssociationInfos(
@PathParam("ipAddress") String ipAddress
) {
@PathParam("ipAddress") String ipAddress
) {
NetworkAssociation na = networkAssociationBean.getActiveAssociationByIP(ipAddress);
NetworkAssociationInfoResponseRoot nairr;
if(na != null) {
if (na != null) {
nairr = new NetworkAssociationInfoResponseRoot(
new NetworkAssociationInfoPojo(na)
);
initNetworkAssociationInfoPojo(na)
);
} else {
nairr = new NetworkAssociationInfoResponseRoot();
}
return nairr;
}
@GET
@Path("/get_all/{activate}")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAll(
@PathParam("activate") Boolean activate
) {
@PathParam("activate") Boolean activate
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
if(activate == null)
if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociations(activate);
for(NetworkAssociation na : activeAssociations) {
for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
}
return resp;
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage());
return resp;
}
}
@GET
@Path("/get_all/{horizon}/{activate}")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAllByHorizon(
@PathParam("activate") Boolean activate,
@PathParam("horizon") String horizon
) {
@PathParam("activate") Boolean activate,
@PathParam("horizon") String horizon
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
if(activate == null)
if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociationsByHorizon(activate, horizon);
for(NetworkAssociation na : activeAssociations) {
for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
}
return resp;
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage());
return resp;
}
}
@POST
@Path("/get_status_by_ip_mac")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getChanges(
@FormParam("ip") String ip,
@FormParam("mac") String mac
) {
@FormParam("ip") String ip,
@FormParam("mac") String mac
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
for(NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) {
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) {
for (NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) {
if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} else if(na.getStatus().equals(NetworkAssociationStatus.PENDING)) {
} else if (na.getStatus().equals(NetworkAssociationStatus.PENDING)) {
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} else if(na.getStatus().equals(NetworkAssociationStatus.EXPIRED)) {
} else if (na.getStatus().equals(NetworkAssociationStatus.EXPIRED)) {
resp.getRemovals().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
}
}
return resp;
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage());
return resp;
}
}
private NetworkAssociationInfoPojo initNetworkAssociationInfoPojo(NetworkAssociation na)
{
NetworkAssociationInfoPojo ret = new NetworkAssociationInfoPojo();
ret.setCreateTime(na.getCreateTime().getTime().toString());
ret.setModifyTime(na.getModifyTime().getTime().toString());
ret.setIpAddress(na.getIP());
ret.setMacAddress(na.getMAC());
Integer placeid = null;
if (na.getPlace() != null)
placeid = na.getPlace().getId();
ret.setPlaceId(placeid);
ret.setEventuserId(na.getEventUser().getId());
return ret;
}
}
package fi.codecrew.moya.rest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
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.Product;
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.placemap.v1.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.v1.ProductRestPojo;
import fi.codecrew.moya.rest.pojo.placemap.v1.SimplePlacePojo;
import fi.codecrew.moya.rest.pojo.placemap.v1.SimplePlacelistRoot;
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;
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;
}
public static PlacePojo initPlacePojo(Place place) {
PlacePojo ret = new PlacePojo();
if (place.getProduct() != null)
ret.setProductId(place.getProduct().getId());
if (place.getPlaceReserver() != null && place.getPlaceReserver().getPlaceGroup() != null && place.getPlaceReserver().getPlaceGroup().getCreator() != null)
ret.setReserverId(place.getPlaceReserver().getPlaceGroup().getCreator().getId());
ret.setId(place.getId());
ret.setDescription(place.getDescription());
ret.setName(place.getName());
ret.setMapX(place.getMapX());
ret.setMapY(place.getMapY());
ret.setDetails(place.getDetails());
ret.setCode(place.getCode());
ret.setHeight(place.getHeight());
ret.setWidth(place.getWidth());
ret.setTaken(place.isTaken());
ret.setBuyable(place.isBuyable());
ret.setReleaseTime(place.getReleaseTime());
ret.setDisabled(place.isDisabled());
if (place.getMap() != null) {
ret.setMapId(place.getMap().getId());
}
if (place.getPlaceReserver() != null && place.getPlaceReserver().getUser() != null) {
ret.setEventuserId(place.getPlaceReserver().getUser().getId());
}
return ret;
}
public static PlaceRoot initPlaceRoot(EventMap map) {
PlaceRoot ret = new PlaceRoot();
ret.setMap(initMapPojo(map));
ret.setPlaces(parsePlaces(map.getPlaces()));
return ret;
}
private static List<PlacePojo> parsePlaces(List<Place> places) {
ArrayList<PlacePojo> ret = new ArrayList<PlacePojo>();
for (Place place : places) {
ret.add(initPlacePojo(place));
}
return ret;
}
private static MapPojo initMapPojo(EventMap map) {
MapPojo ret = new MapPojo();
ret.setId(map.getId());
ret.setName(map.getName());
ret.setActive(map.isActive());
return ret;
}
public static MapRoot parseMaps(List<EventMap> eventMaps) {
List<MapPojo> ret = new ArrayList<>();
for (EventMap m : eventMaps) {
ret.add(initMapPojo(m));
}
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;
}
public static List<ProductRestPojo> parseProducts(List<Product> prods) {
ArrayList<ProductRestPojo> ret = new ArrayList<ProductRestPojo>();
for (Product p : prods) {
ret.add(initProductRestPojo(p));
}
return ret;
}
public static ProductRestPojo initProductRestPojo(Product product)
{
ProductRestPojo ret = new ProductRestPojo();
ret.setId(product.getId());
ret.setName(product.getName());
ret.setDescription(product.getDescription());
ret.setPrice(product.getPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
return ret;
}
public static SimplePlacelistRoot parseSimplePlaces(List<Place> places, EventUser user)
{
SimplePlacelistRoot ret = new SimplePlacelistRoot();
ArrayList<SimplePlacePojo> placeList = new ArrayList<SimplePlacePojo>();
ret.setPlaces(placeList);
for (Place p : places) {
placeList.add(initSimplePlacePojo(p, user));
}
return ret;
}
private static SimplePlacePojo initSimplePlacePojo(Place p, EventUser user) {
SimplePlacePojo ret = new SimplePlacePojo();
ret.setId(p.getId());
ret.setName(p.getName());
String state = null;
switch (p.getState(user))
{
case DISABLED:
state = "D";
break;
case FREE:
state = "F";
break;
case LOCKED:
state = "L";
break;
case MY_PLACE:
state = "P";
break;
case RESERVED:
state = "R";
break;
case TEMP_RESERVED_FORME:
state = "T";
break;
default:
break;
}
ret.setState(state);
ret.setX(p.getMapX());
ret.setY(p.getMapY());
ret.setWidth(p.getWidth());
ret.setHeight(p.getHeight());
return ret;
}
public static PlacemapMapRootPojo.MapPojo initPlacemapMapPojo(EventMap map) {
PlacemapMapRootPojo.MapPojo ret = new PlacemapMapRootPojo.MapPojo();
ret.setId(map.getId());
ret.setName(map.getName());
ret.setWidth(map.getWidth());
ret.setHeight(map.getHeight());
return ret;
}
}
......@@ -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.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
......@@ -132,13 +131,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}")
......
......@@ -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();
}
......
......@@ -28,10 +28,11 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.rest.pojo.placemap.IntegerRoot;
import fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot;
import fi.codecrew.moya.rest.PojoUtils;
import fi.codecrew.moya.rest.pojo.placemap.v1.IntegerRoot;
import fi.codecrew.moya.rest.pojo.placemap.v1.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.v1.SimplePlacePojo;
import fi.codecrew.moya.rest.pojo.placemap.v1.SimplePlacelistRoot;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.user.UserView;
......@@ -76,8 +77,8 @@ public class PlacemapRestViewV1 {
public PlacemapMapRootPojo getMap(@PathParam("id") Integer id) {
PlacemapMapRootPojo ret = new PlacemapMapRootPojo();
EventMap map = placebean.findMap(id);
ret.setMap(map);
ret.setRawProducts(placebean.getMapProducts(map));
ret.setMap(PojoUtils.initPlacemapMapPojo(map));
ret.setProducts(PojoUtils.parseProducts(placebean.getMapProducts(map)));
return ret;
}
......@@ -103,7 +104,7 @@ public class PlacemapRestViewV1 {
if (userView != null) {
user = userView.getSelectedUser();
}
return SimplePlacelistRoot.wrap(map.getPlaces(), user);
return PojoUtils.parseSimplePlaces(map.getPlaces(), user);
}
@GET
......@@ -112,7 +113,7 @@ public class PlacemapRestViewV1 {
{
List<Place> thisplace = new ArrayList<Place>();
thisplace.add(placebean.find(placeId));
return SimplePlacelistRoot.wrap(thisplace, permbean.getCurrentUser());
return PojoUtils.parseSimplePlaces(thisplace, permbean.getCurrentUser());
}
@GET
......@@ -168,7 +169,7 @@ public class PlacemapRestViewV1 {
p = placebean.find(placeId);
List<Place> thisplace = new ArrayList<Place>();
thisplace.add(p);
resp = Response.ok(SimplePlacelistRoot.wrap(thisplace, user));
resp = Response.ok(PojoUtils.parseSimplePlaces(thisplace, user));
} else {
resp = Response.status(Response.Status.FORBIDDEN);
}
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.Place;
public class PlaceOutPojo {
private Place place;
public PlaceOutPojo() {
}
public PlaceOutPojo(Place p) {
this.place = p;
}
public static List<PlaceOutPojo> parse(List<Place> places) {
List<PlaceOutPojo> ret = new ArrayList<>();
for (Place p : places)
{
ret.add(new PlaceOutPojo(p));
}
return ret;
}
@XmlElement
public Integer getProductId()
{
Integer ret = null;
if (place.getProduct() != null)
ret = place.getProduct().getId();
return ret;
}
@XmlElement
public Integer getId() {
return place.getId();
}
@XmlElement
public String getDescription() {
return place.getDescription();
}
@XmlElement
public String getName() {
return place.getName();
}
@XmlElement
public Integer getMapX() {
return place.getMapX();
}
@XmlElement
public Integer getMapY() {
return place.getMapY();
}
@XmlElement
public String getDetails() {
return place.getDetails();
}
@XmlElement
public String getCode() {
return place.getCode();
}
@XmlElement
public Integer getHeight() {
return place.getHeight();
}
@XmlElement
public Integer getWidth() {
return place.getWidth();
}
@XmlElement
public boolean isTaken() {
return place.isTaken();
}
@XmlElement
public boolean isBuyable() {
return place.isBuyable();
}
@XmlElement
public Calendar getReleaseTime() {
return place.getReleaseTime();
}
@XmlElement
public boolean isDisabled() {
return place.isDisabled();
}
@XmlElement
public Integer getReserverId()
{
Integer ret = null;
if (place.getPlaceReserver() != null && place.getPlaceReserver().getPlaceGroup() != null && place.getPlaceReserver().getPlaceGroup().getCreator() != null)
ret = place.getPlaceReserver().getPlaceGroup().getCreator().getId();
return ret;
}
@XmlElement
public Integer getMapId() {
Integer ret = null;
if (place.getMap() != null) {
ret = place.getMap().getId();
}
return ret;
}
@XmlElement
public Integer getEventuserId()
{
Integer ret = null;
if (place.getPlaceReserver() != null && place.getPlaceReserver().getUser() != null)
ret = place.getPlaceReserver().getUser().getId();
return ret;
}
}
package fi.codecrew.moya.rest.pojo.placemap;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
public class SimplePlacePojo {
private Place place;
private EventUser user;
public SimplePlacePojo(Place place, EventUser user) {
super();
this.place = place;
this.user = user;
}
public SimplePlacePojo() {
super();
}
@XmlElement(name = "id")
public Integer getId() {
return place.getId();
}
@XmlElement(name = "name")
public String getName() {
return place.getName();
}
@XmlElement(name = "state")
public String getState() {
String ret = null;
switch (place.getState(user))
{
case DISABLED:
ret = "D";
break;
case FREE:
ret = "F";
break;
case LOCKED:
ret = "L";
break;
case MY_PLACE:
ret = "P";
break;
case RESERVED:
ret = "R";
break;
case TEMP_RESERVED_FORME:
ret = "T";
break;
default:
break;
}
return ret;
}
@XmlElement(name = "x")
public Integer getX() {
return place.getMapX();
}
@XmlElement(name = "y")
public Integer getY() {
return place.getMapY();
}
@XmlElement(name = "w")
public Integer getWidth() {
return place.getWidth();
}
@XmlElement(name = "h")
public Integer getHeight() {
return place.getHeight();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!