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 @@ ...@@ -4,7 +4,6 @@
<artifactId>moya-beans-client</artifactId> <artifactId>moya-beans-client</artifactId>
<build> <build>
<sourceDirectory>ejbModule</sourceDirectory> <sourceDirectory>ejbModule</sourceDirectory>
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<module>../moya-authmodule</module> <module>../moya-authmodule</module>
<module>../moya-authmodule-client</module> <module>../moya-authmodule-client</module>
<module>../moya-database</module> <module>../moya-database</module>
<module>../moya-restpojo</module>
<module>../moya-beans-client</module> <module>../moya-beans-client</module>
<module>../moya-beans</module> <module>../moya-beans</module>
<module>../moya-web</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 @@ ...@@ -16,16 +16,12 @@
* future versions of the Software. * 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 java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventMap;
@XmlRootElement @XmlRootElement
public class MapRoot { public class MapRoot {
...@@ -47,41 +43,4 @@ public class MapRoot { ...@@ -47,41 +43,4 @@ public class MapRoot {
this.maps = maps; 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 @@ ...@@ -16,9 +16,13 @@
* future versions of the Software. * 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 Integer id;
private String name; private String name;
...@@ -31,6 +35,12 @@ public class PlaceInputPojo { ...@@ -31,6 +35,12 @@ public class PlaceInputPojo {
private Integer productId; private Integer productId;
private Integer mapId; private Integer mapId;
private Boolean taken; private Boolean taken;
private String details;
private String code;
private Calendar releaseTime;
private String description;
private Integer reserverId;
private Integer eventuserId;
public String getName() { public String getName() {
return name; return name;
...@@ -88,6 +98,7 @@ public class PlaceInputPojo { ...@@ -88,6 +98,7 @@ public class PlaceInputPojo {
this.disabled = disabled; this.disabled = disabled;
} }
@XmlElement
public Integer getProductId() { public Integer getProductId() {
return productId; return productId;
} }
...@@ -120,4 +131,52 @@ public class PlaceInputPojo { ...@@ -120,4 +131,52 @@ public class PlaceInputPojo {
this.taken = taken; 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 @@ ...@@ -16,31 +16,22 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.map.v1;
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.EventMap;
import fi.codecrew.moya.rest.pojo.MapRoot.MapPojo;
@XmlRootElement @XmlRootElement
public class PlaceRoot { public class PlaceRoot {
public PlaceRoot() public PlaceRoot() {
{ super();
}
public PlaceRoot(EventMap map2) {
this.map = new MapPojo(map2);
setPlaces(PlaceOutPojo.parse(map2.getPlaces()));
} }
private MapPojo map; private MapPojo map;
private List<PlaceOutPojo> places; private List<PlacePojo> places;
public MapPojo getMap() { public MapPojo getMap() {
return map; return map;
...@@ -50,11 +41,11 @@ public class PlaceRoot { ...@@ -50,11 +41,11 @@ public class PlaceRoot {
this.map = map; this.map = map;
} }
public List<PlaceOutPojo> getPlaces() { public List<PlacePojo> getPlaces() {
return places; return places;
} }
public void setPlaces(List<PlaceOutPojo> places) { public void setPlaces(List<PlacePojo> places) {
this.places = places; this.places = places;
} }
......
...@@ -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.network.v1;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
......
...@@ -16,14 +16,10 @@ ...@@ -16,14 +16,10 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.Calendar;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.NetworkAssociation;
public class NetworkAssociationInfoPojo { public class NetworkAssociationInfoPojo {
private String createTime; private String createTime;
private String modifyTime; private String modifyTime;
...@@ -32,18 +28,7 @@ public class NetworkAssociationInfoPojo { ...@@ -32,18 +28,7 @@ public class NetworkAssociationInfoPojo {
private Integer placeId; private Integer placeId;
private Integer eventuserId; 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() { public NetworkAssociationInfoPojo() {
this.createTime = null; this.createTime = null;
......
...@@ -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.network.v1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -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.network.v1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -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.network.v1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -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.network.v1;
import javax.xml.bind.annotation.XmlElement; 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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
...@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
public class IntegerRoot { public class IntegerRoot {
private Integer value = -1; private Integer value = -1;
@XmlElement(name = "value") @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 java.util.List;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
...@@ -9,10 +8,6 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -9,10 +8,6 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.rest.pojo.ProductRestPojo;
@XmlRootElement @XmlRootElement
public class PlacemapMapRootPojo { public class PlacemapMapRootPojo {
...@@ -25,56 +20,50 @@ public class PlacemapMapRootPojo { ...@@ -25,56 +20,50 @@ public class PlacemapMapRootPojo {
public static class MapPojo { public static class MapPojo {
private EventMap map; private Integer id;
private String name;
private Integer width;
private Integer height;
public MapPojo() { public MapPojo() {
} }
public MapPojo(EventMap map2) {
this.map = map2;
}
@XmlElement(name = "name") @XmlElement(name = "name")
public String getName() { public String getName() {
return map.getName(); return name;
} }
@XmlElement(name = "id") @XmlElement(name = "id")
public Integer getId() { public Integer getId() {
return map.getId(); return id;
} }
@XmlElement(name = "width") @XmlElement(name = "width")
public Integer getWidth() { public Integer getWidth() {
return map.getWidth(); return width;
} }
@XmlElement(name = "height") @XmlElement(name = "height")
public Integer getHeight() { public Integer getHeight() {
return map.getHeight(); return height;
} }
} public void setId(Integer id) {
this.id = id;
public List<ProductRestPojo> getProducts() { }
return products;
}
public void setProducts(List<ProductRestPojo> products) { public void setName(String name) {
this.products = products; this.name = name;
} }
public void setMap(EventMap map2) { public void setWidth(Integer width) {
logger.info("Adding map {} to placemapMap", map2); this.width = width;
map = new MapPojo(map2); }
}
public void setRawProducts(List<Product> mapProducts) { public void setHeight(Integer height) {
products = new ArrayList<>(); this.height = height;
for (Product p : mapProducts) {
logger.warn("Adding product {}", p);
products.add(new ProductRestPojo(p));
} }
} }
public MapPojo getMap() { public MapPojo getMap() {
...@@ -85,4 +74,12 @@ public class PlacemapMapRootPojo { ...@@ -85,4 +74,12 @@ public class PlacemapMapRootPojo {
this.map = map; this.map = map;
} }
public List<ProductRestPojo> getProducts() {
return products;
}
public void setProducts(List<ProductRestPojo> products) {
this.products = products;
}
} }
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.placemap.v1;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.Product;
public class ProductRestPojo { public class ProductRestPojo {
private Product prod; private Integer id;
private String name;
private String price;
private String description;
public ProductRestPojo() { public ProductRestPojo() {
super();
}
public ProductRestPojo(Product p) {
this.prod = p;
} }
@XmlElement(name = "id") @XmlElement(name = "id")
public Integer getId() { public Integer getId() {
return prod.getId(); return id;
} }
@XmlElement(name = "name") @XmlElement(name = "name")
public String getName() { public String getName() {
return prod.getName(); return name;
} }
@XmlElement(name = "price") @XmlElement(name = "price")
public String getPrice() { public String getPrice() {
return prod.getPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); return price;
} }
@XmlElement(name = "description") @XmlElement(name = "description")
public String getDescription() { 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 java.util.List;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
@XmlRootElement @XmlRootElement
public class SimplePlacelistRoot { public class SimplePlacelistRoot {
...@@ -21,16 +17,6 @@ public class SimplePlacelistRoot { ...@@ -21,16 +17,6 @@ public class SimplePlacelistRoot {
this.places = places; 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 @@ ...@@ -16,36 +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.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.model.ReaderEvent; 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 = new EventUserRestPojo(re.getPrintedCard().getUser());
}
} else if(re != null && re.getUser() != null) {
eventUser = new EventUserRestPojo(re.getUser());
}
}
@XmlElement(name = "eventuser") @XmlElement(name = "eventuser")
public EventUserRestPojo getEventuser() { public EventUserRestPojo getEventuser() {
return eventUser; return eventUser;
...@@ -53,48 +44,27 @@ public class ReaderEventRestPojo { ...@@ -53,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() {
...@@ -104,4 +74,37 @@ public class ReaderEventRestPojo { ...@@ -104,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;
......
...@@ -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);
}
} }
...@@ -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 javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<configuration> <configuration>
<warSourceDirectory>WebContent</warSourceDirectory> <warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml> <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> </configuration>
</plugin> </plugin>
</plugins> </plugins>
...@@ -34,13 +34,18 @@ ...@@ -34,13 +34,18 @@
<artifactId>primefaces</artifactId> <artifactId>primefaces</artifactId>
<version>5.1</version> <version>5.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.primefaces.extensions</groupId> <groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId> <artifactId>all-themes</artifactId>
<version>1.0.8</version> <version>1.0.8</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-restpojo</artifactId>
<version>${moya.version}</version>
</dependency>
</dependencies> </dependencies>
<parent> <parent>
<groupId>fi.codecrew.moya</groupId> <groupId>fi.codecrew.moya</groupId>
......
...@@ -49,10 +49,9 @@ import fi.codecrew.moya.model.EventMap; ...@@ -49,10 +49,9 @@ 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.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.rest.pojo.MapRoot; import fi.codecrew.moya.rest.pojo.map.v1.MapRoot;
import fi.codecrew.moya.rest.pojo.PlaceInputPojo; import fi.codecrew.moya.rest.pojo.map.v1.PlacePojo;
import fi.codecrew.moya.rest.pojo.PlaceOutPojo; import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot;
import fi.codecrew.moya.rest.pojo.PlaceRoot;
@RequestScoped @RequestScoped
@Path("/placeadmin") @Path("/placeadmin")
...@@ -87,7 +86,7 @@ public class MapAdminView { ...@@ -87,7 +86,7 @@ public class MapAdminView {
@GET @GET
@Path("/maps") @Path("/maps")
public MapRoot getAllMaps() { public MapRoot getAllMaps() {
MapRoot ret = MapRoot.parseMaps(eventbean.getCurrentEvent().getEventMaps()); MapRoot ret = PojoUtils.parseMaps(eventbean.getCurrentEvent().getEventMaps());
logger.info("getallmaps called! {}", ret); logger.info("getallmaps called! {}", ret);
return ret; return ret;
} }
...@@ -96,7 +95,7 @@ public class MapAdminView { ...@@ -96,7 +95,7 @@ public class MapAdminView {
@Path("/places/{mapId}") @Path("/places/{mapId}")
public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) { public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) {
EventMap map = placebean.findMap(mapid); EventMap map = placebean.findMap(mapid);
PlaceRoot ret = new PlaceRoot(map); PlaceRoot ret = PojoUtils.initPlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret); logger.info("returning map {} entity {}", mapid, ret);
return ret; return ret;
} }
...@@ -120,7 +119,7 @@ public class MapAdminView { ...@@ -120,7 +119,7 @@ public class MapAdminView {
@POST @POST
@Path("/place/") @Path("/place/")
public Response createPlace(PlaceInputPojo create) { public Response createPlace(PlacePojo create) {
logger.info("Finding map with id {}", create.getMapId()); logger.info("Finding map with id {}", create.getMapId());
EventMap map = eventmapbean.find(create.getMapId()); EventMap map = eventmapbean.find(create.getMapId());
if (map == null) { if (map == null) {
...@@ -129,17 +128,17 @@ public class MapAdminView { ...@@ -129,17 +128,17 @@ public class MapAdminView {
} }
Place place = new Place(); Place place = new Place();
place.setMap(map); place.setMap(map);
setPlaceValues(place, create); setUpdatablePlaceValues(place, create);
if (create.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(create.getProductId()))) if (create.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(create.getProductId())))
return Response.serverError().entity("Product id unknown!").build(); return Response.serverError().entity("Product id unknown!").build();
logger.info("Creating new place {}", place.getName()); logger.info("Creating new place {}", place.getName());
eventmapbean.createPlace(place); eventmapbean.createPlace(place);
return Response.ok().entity(new PlaceOutPojo(place)).build(); return Response.ok().entity(PojoUtils.initPlacePojo(place)).build();
} }
@PUT @PUT
@Path("/place/{id}") @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) { if (update == null || id == null) {
return Response.serverError().entity("'id' field is required!").build(); return Response.serverError().entity("'id' field is required!").build();
} }
...@@ -147,12 +146,12 @@ public class MapAdminView { ...@@ -147,12 +146,12 @@ public class MapAdminView {
if (place == null) { if (place == null) {
return Response.serverError().entity("place not found with id: " + id).build(); 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()))) if (update.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(update.getProductId())))
return Response.serverError().entity("Product id unknown!").build(); return Response.serverError().entity("Product id unknown!").build();
place = eventmapbean.updatePlace(place); place = eventmapbean.updatePlace(place);
return Response.ok(new PlaceOutPojo(place)).build(); return Response.ok(PojoUtils.initPlacePojo(place)).build();
} }
@PUT @PUT
...@@ -185,7 +184,7 @@ public class MapAdminView { ...@@ -185,7 +184,7 @@ public class MapAdminView {
return Response.serverError().build(); return Response.serverError().build();
} }
private void setPlaceValues(Place place, PlaceInputPojo update) { private void setUpdatablePlaceValues(Place place, PlacePojo update) {
if (update.getName() != null) if (update.getName() != null)
place.setName(update.getName()); place.setName(update.getName());
......
...@@ -33,189 +33,206 @@ import javax.ws.rs.core.MediaType; ...@@ -33,189 +33,206 @@ import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.NetworkAssociationBeanLocal; import fi.codecrew.moya.beans.NetworkAssociationBeanLocal;
import fi.codecrew.moya.enums.NetworkAssociationStatus; import fi.codecrew.moya.enums.NetworkAssociationStatus;
import fi.codecrew.moya.model.NetworkAssociation; import fi.codecrew.moya.model.NetworkAssociation;
import fi.codecrew.moya.rest.pojo.NetworkAssociationActionPojo; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationActionPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoPojo; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoResponseRoot; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfolistResponseRoot; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfolistResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationResponseRoot; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationResponseRoot;
@RequestScoped @RequestScoped
@Path("/networkassociation") @Path("/networkassociation")
public class NetworkAssociationRestView { public class NetworkAssociationRestView {
@EJB @EJB
private NetworkAssociationBeanLocal networkAssociationBean; private NetworkAssociationBeanLocal networkAssociationBean;
@POST @POST
@Path("/auth") @Path("/auth")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot auth( public NetworkAssociationResponseRoot auth(
@FormParam("username") String username, @FormParam("username") String username,
@FormParam("password") String password, @FormParam("password") String password,
@FormParam("ip") String ip, @FormParam("ip") String ip,
@FormParam("mac") String mac, @FormParam("mac") String mac,
@FormParam("code") String code, @FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired @FormParam("coderequired") Boolean codeRequired
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
NetworkAssociation na = networkAssociationBean.tryAssociate( NetworkAssociation na = networkAssociationBean.tryAssociate(
username, password, ip, mac, code, codeRequired); 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())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) { if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
} else { } else {
resp.getResult().setMessage("UNKNOWN_ERROR"); resp.getResult().setMessage("UNKNOWN_ERROR");
} }
} }
return resp; return resp;
} }
@POST @POST
@Path("/codeauth") @Path("/codeauth")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot codeAuth( public NetworkAssociationResponseRoot codeAuth(
@FormParam("usercode") String usercode, @FormParam("usercode") String usercode,
@FormParam("ip") String ip, @FormParam("ip") String ip,
@FormParam("mac") String mac, @FormParam("mac") String mac,
@FormParam("code") String code, @FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired @FormParam("coderequired") Boolean codeRequired
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
NetworkAssociation na = networkAssociationBean.tryAssociate( NetworkAssociation na = networkAssociationBean.tryAssociate(
usercode, ip, mac, code, codeRequired); 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())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) { if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
} else { } else {
resp.getResult().setMessage("UNKNOWN_ERROR"); resp.getResult().setMessage("UNKNOWN_ERROR");
} }
} }
return resp; return resp;
} }
@GET @GET
@Path("/get_association_infos") @Path("/get_association_infos")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfolistResponseRoot getAssociationInfos() { public NetworkAssociationInfolistResponseRoot getAssociationInfos() {
NetworkAssociationInfolistResponseRoot nairr = new NetworkAssociationInfolistResponseRoot(); NetworkAssociationInfolistResponseRoot nairr = new NetworkAssociationInfolistResponseRoot();
for(NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) { for (NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) {
nairr.getAssociations().add(new NetworkAssociationInfoPojo(na)); nairr.getAssociations().add(initNetworkAssociationInfoPojo(na));
} }
return nairr; return nairr;
} }
@GET @GET
@Path("/get_association_info_by_ip/{ipAddress}") @Path("/get_association_info_by_ip/{ipAddress}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfoResponseRoot getAssociationInfos( public NetworkAssociationInfoResponseRoot getAssociationInfos(
@PathParam("ipAddress") String ipAddress @PathParam("ipAddress") String ipAddress
) { ) {
NetworkAssociation na = networkAssociationBean.getActiveAssociationByIP(ipAddress); NetworkAssociation na = networkAssociationBean.getActiveAssociationByIP(ipAddress);
NetworkAssociationInfoResponseRoot nairr; NetworkAssociationInfoResponseRoot nairr;
if(na != null) { if (na != null) {
nairr = new NetworkAssociationInfoResponseRoot( nairr = new NetworkAssociationInfoResponseRoot(
new NetworkAssociationInfoPojo(na) initNetworkAssociationInfoPojo(na)
); );
} else { } else {
nairr = new NetworkAssociationInfoResponseRoot(); nairr = new NetworkAssociationInfoResponseRoot();
} }
return nairr; return nairr;
} }
@GET @GET
@Path("/get_all/{activate}") @Path("/get_all/{activate}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAll( public NetworkAssociationResponseRoot getAll(
@PathParam("activate") Boolean activate @PathParam("activate") Boolean activate
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
if(activate == null) if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE"); throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociations(activate); List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociations(activate);
for(NetworkAssociation na : activeAssociations) { for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} }
return resp; return resp;
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
return resp; return resp;
} }
} }
@GET @GET
@Path("/get_all/{horizon}/{activate}") @Path("/get_all/{horizon}/{activate}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAllByHorizon( public NetworkAssociationResponseRoot getAllByHorizon(
@PathParam("activate") Boolean activate, @PathParam("activate") Boolean activate,
@PathParam("horizon") String horizon @PathParam("horizon") String horizon
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
if(activate == null) if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE"); throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociationsByHorizon(activate, horizon); List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociationsByHorizon(activate, horizon);
for(NetworkAssociation na : activeAssociations) { for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} }
return resp; return resp;
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
return resp; return resp;
} }
} }
@POST @POST
@Path("/get_status_by_ip_mac") @Path("/get_status_by_ip_mac")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getChanges( public NetworkAssociationResponseRoot getChanges(
@FormParam("ip") String ip, @FormParam("ip") String ip,
@FormParam("mac") String mac @FormParam("mac") String mac
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
for(NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) { for (NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) {
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) { if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); 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())); 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())); resp.getRemovals().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} }
} }
return resp; return resp;
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
return resp; 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; ...@@ -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.reader.v1.ReaderEventRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderEventRestPojo; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderEventRestRoot;
import fi.codecrew.moya.rest.pojo.ReaderEventRestRoot; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestPojo;
import fi.codecrew.moya.rest.pojo.ReaderRestPojo; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestRoot;
import fi.codecrew.moya.rest.pojo.ReaderRestRoot; import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.UserPermissionRestPojo; 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
...@@ -132,13 +131,14 @@ public class ReaderRestView { ...@@ -132,13 +131,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}")
......
...@@ -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();
} }
......
...@@ -28,10 +28,11 @@ import fi.codecrew.moya.model.EventMap; ...@@ -28,10 +28,11 @@ 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.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.rest.pojo.placemap.IntegerRoot; import fi.codecrew.moya.rest.PojoUtils;
import fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo; import fi.codecrew.moya.rest.pojo.placemap.v1.IntegerRoot;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo; import fi.codecrew.moya.rest.pojo.placemap.v1.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot; 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.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.user.UserView; import fi.codecrew.moya.web.cdiview.user.UserView;
...@@ -76,8 +77,8 @@ public class PlacemapRestViewV1 { ...@@ -76,8 +77,8 @@ public class PlacemapRestViewV1 {
public PlacemapMapRootPojo getMap(@PathParam("id") Integer id) { public PlacemapMapRootPojo getMap(@PathParam("id") Integer id) {
PlacemapMapRootPojo ret = new PlacemapMapRootPojo(); PlacemapMapRootPojo ret = new PlacemapMapRootPojo();
EventMap map = placebean.findMap(id); EventMap map = placebean.findMap(id);
ret.setMap(map); ret.setMap(PojoUtils.initPlacemapMapPojo(map));
ret.setRawProducts(placebean.getMapProducts(map)); ret.setProducts(PojoUtils.parseProducts(placebean.getMapProducts(map)));
return ret; return ret;
} }
...@@ -103,7 +104,7 @@ public class PlacemapRestViewV1 { ...@@ -103,7 +104,7 @@ public class PlacemapRestViewV1 {
if (userView != null) { if (userView != null) {
user = userView.getSelectedUser(); user = userView.getSelectedUser();
} }
return SimplePlacelistRoot.wrap(map.getPlaces(), user); return PojoUtils.parseSimplePlaces(map.getPlaces(), user);
} }
@GET @GET
...@@ -112,7 +113,7 @@ public class PlacemapRestViewV1 { ...@@ -112,7 +113,7 @@ public class PlacemapRestViewV1 {
{ {
List<Place> thisplace = new ArrayList<Place>(); List<Place> thisplace = new ArrayList<Place>();
thisplace.add(placebean.find(placeId)); thisplace.add(placebean.find(placeId));
return SimplePlacelistRoot.wrap(thisplace, permbean.getCurrentUser()); return PojoUtils.parseSimplePlaces(thisplace, permbean.getCurrentUser());
} }
@GET @GET
...@@ -168,7 +169,7 @@ public class PlacemapRestViewV1 { ...@@ -168,7 +169,7 @@ public class PlacemapRestViewV1 {
p = placebean.find(placeId); p = placebean.find(placeId);
List<Place> thisplace = new ArrayList<Place>(); List<Place> thisplace = new ArrayList<Place>();
thisplace.add(p); thisplace.add(p);
resp = Response.ok(SimplePlacelistRoot.wrap(thisplace, user)); resp = Response.ok(PojoUtils.parseSimplePlaces(thisplace, user));
} else { } else {
resp = Response.status(Response.Status.FORBIDDEN); 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!