Commit e71dfcdd by Tuomas Riihimäki

Move placemap rest to restpojo package

1 parent fca5b3e2
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 void setId(Integer id) {
this.id = id;
}
public List<ProductRestPojo> getProducts() {
return products;
public void setName(String name) {
this.name = name;
}
public void setProducts(List<ProductRestPojo> products) {
this.products = products;
public void setWidth(Integer width) {
this.width = width;
}
public void setMap(EventMap map2) {
logger.info("Adding map {} to placemapMap", map2);
map = new MapPojo(map2);
public void setHeight(Integer height) {
this.height = height;
}
public void setRawProducts(List<Product> mapProducts) {
products = new ArrayList<>();
for (Product p : mapProducts) {
logger.warn("Adding product {}", p);
products.add(new ProductRestPojo(p));
}
}
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;
package fi.codecrew.moya.rest.pojo.placemap.v1;
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;
}
private Integer id;
private String name;
private String state;
private Integer x;
private Integer y;
private Integer width;
private Integer height;
public SimplePlacePojo() {
super();
......@@ -22,60 +18,66 @@ public class SimplePlacePojo {
@XmlElement(name = "id")
public Integer getId() {
return place.getId();
return id;
}
@XmlElement(name = "name")
public String getName() {
return place.getName();
return name;
}
@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;
return state;
}
@XmlElement(name = "x")
public Integer getX() {
return place.getMapX();
return x;
}
@XmlElement(name = "y")
public Integer getY() {
return place.getMapY();
return y;
}
@XmlElement(name = "w")
public Integer getWidth() {
return place.getWidth();
return width;
}
@XmlElement(name = "h")
public Integer getHeight() {
return place.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,12 +16,10 @@
* 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.rest.pojo.userinfo.v1.EventUserRestPojo;
public class UserPermissionRestPojo {
public UserPermissionRestPojo(EventUserRestPojo eventUserRestPojo, boolean granted)
......
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;
......@@ -188,4 +196,83 @@ public class PojoUtils {
}
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;
}
}
......@@ -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);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!