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.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; package fi.codecrew.moya.rest.pojo.placemap.v1;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
public class SimplePlacePojo { public class SimplePlacePojo {
private Place place; private Integer id;
private EventUser user; private String name;
private String state;
public SimplePlacePojo(Place place, EventUser user) { private Integer x;
super(); private Integer y;
this.place = place; private Integer width;
this.user = user; private Integer height;
}
public SimplePlacePojo() { public SimplePlacePojo() {
super(); super();
...@@ -22,60 +18,66 @@ public class SimplePlacePojo { ...@@ -22,60 +18,66 @@ public class SimplePlacePojo {
@XmlElement(name = "id") @XmlElement(name = "id")
public Integer getId() { public Integer getId() {
return place.getId(); return id;
} }
@XmlElement(name = "name") @XmlElement(name = "name")
public String getName() { public String getName() {
return place.getName(); return name;
} }
@XmlElement(name = "state") @XmlElement(name = "state")
public String getState() { public String getState() {
String ret = null;
switch (place.getState(user)) return state;
{
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") @XmlElement(name = "x")
public Integer getX() { public Integer getX() {
return place.getMapX(); return x;
} }
@XmlElement(name = "y") @XmlElement(name = "y")
public Integer getY() { public Integer getY() {
return place.getMapY(); return y;
} }
@XmlElement(name = "w") @XmlElement(name = "w")
public Integer getWidth() { public Integer getWidth() {
return place.getWidth(); return width;
} }
@XmlElement(name = "h") @XmlElement(name = "h")
public Integer getHeight() { 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 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,12 +16,10 @@ ...@@ -16,12 +16,10 @@
* 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.rest.pojo.userinfo.v1.EventUserRestPojo;
public class UserPermissionRestPojo { public class UserPermissionRestPojo {
public UserPermissionRestPojo(EventUserRestPojo eventUserRestPojo, boolean granted) public UserPermissionRestPojo(EventUserRestPojo eventUserRestPojo, boolean granted)
......
package fi.codecrew.moya.rest; package fi.codecrew.moya.rest;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.EventMap; import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place; import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.Reader; import fi.codecrew.moya.model.Reader;
import fi.codecrew.moya.model.ReaderEvent; import fi.codecrew.moya.model.ReaderEvent;
import fi.codecrew.moya.rest.pojo.map.v1.MapPojo; import fi.codecrew.moya.rest.pojo.map.v1.MapPojo;
import fi.codecrew.moya.rest.pojo.map.v1.MapRoot; import fi.codecrew.moya.rest.pojo.map.v1.MapRoot;
import fi.codecrew.moya.rest.pojo.map.v1.PlacePojo; import fi.codecrew.moya.rest.pojo.map.v1.PlacePojo;
import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot; import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot;
import fi.codecrew.moya.rest.pojo.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.ReaderEventRestPojo;
import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestPojo; import fi.codecrew.moya.rest.pojo.reader.v1.ReaderRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.CardRoot; import fi.codecrew.moya.rest.pojo.userinfo.v1.CardRoot;
...@@ -188,4 +196,83 @@ public class PojoUtils { ...@@ -188,4 +196,83 @@ public class PojoUtils {
} }
return ret; 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; ...@@ -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);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!