Commit 0f4e7cd7 by Tuomas Riihimäki

Move place rest pojos from web project to restpojo class

1 parent ea6e614f
package fi.codecrew.moya.rest.pojo.map.v1;
import javax.xml.bind.annotation.XmlElement;
public class MapPojo {
private String name;
private Integer id;
private Boolean active;
public MapPojo() {
super();
}
@XmlElement(name = "name")
public String getName() {
return name;
}
@XmlElement(name = "id")
public Integer getId() {
return id;
}
@XmlElement(name = "active")
public boolean isActive() {
return active;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public void setName(String name) {
this.name = name;
}
public void setId(Integer id) {
this.id = id;
}
}
......@@ -16,16 +16,12 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.map.v1;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventMap;
@XmlRootElement
public class MapRoot {
......@@ -47,41 +43,4 @@ public class MapRoot {
this.maps = maps;
}
public static class MapPojo {
private EventMap map;
public MapPojo() {
super();
}
public MapPojo(EventMap m) {
this();
this.map = m;
}
@XmlElement(name = "name")
public String getName() {
return map.getName();
}
@XmlElement(name = "id")
public Integer getId() {
return map.getId();
}
@XmlElement(name = "active")
public boolean isActive() {
return map.isActive();
}
}
public static MapRoot parseMaps(List<EventMap> eventMaps) {
List<MapPojo> ret = new ArrayList<>();
for (EventMap m : eventMaps) {
ret.add(new MapPojo(m));
}
return new MapRoot(ret);
}
}
......@@ -16,9 +16,13 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.map.v1;
public class PlaceInputPojo {
import java.util.Calendar;
import javax.xml.bind.annotation.XmlElement;
public class PlacePojo {
private Integer id;
private String name;
......@@ -31,6 +35,12 @@ public class PlaceInputPojo {
private Integer productId;
private Integer mapId;
private Boolean taken;
private String details;
private String code;
private Calendar releaseTime;
private String description;
private Integer reserverId;
private Integer eventuserId;
public String getName() {
return name;
......@@ -88,6 +98,7 @@ public class PlaceInputPojo {
this.disabled = disabled;
}
@XmlElement
public Integer getProductId() {
return productId;
}
......@@ -120,4 +131,52 @@ public class PlaceInputPojo {
this.taken = taken;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Calendar getReleaseTime() {
return releaseTime;
}
public void setReleaseTime(Calendar releaseTime) {
this.releaseTime = releaseTime;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getReserverId() {
return reserverId;
}
public void setReserverId(Integer reserverId) {
this.reserverId = reserverId;
}
public Integer getEventuserId() {
return eventuserId;
}
public void setEventuserId(Integer eventuserId) {
this.eventuserId = eventuserId;
}
}
......@@ -16,31 +16,22 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
package fi.codecrew.moya.rest.pojo.map.v1;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.rest.pojo.MapRoot.MapPojo;
@XmlRootElement
public class PlaceRoot {
public PlaceRoot()
{
}
public PlaceRoot(EventMap map2) {
this.map = new MapPojo(map2);
setPlaces(PlaceOutPojo.parse(map2.getPlaces()));
public PlaceRoot() {
super();
}
private MapPojo map;
private List<PlaceOutPojo> places;
private List<PlacePojo> places;
public MapPojo getMap() {
return map;
......@@ -50,11 +41,11 @@ public class PlaceRoot {
this.map = map;
}
public List<PlaceOutPojo> getPlaces() {
public List<PlacePojo> getPlaces() {
return places;
}
public void setPlaces(List<PlaceOutPojo> places) {
public void setPlaces(List<PlacePojo> places) {
this.places = places;
}
......
......@@ -49,10 +49,9 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.rest.pojo.MapRoot;
import fi.codecrew.moya.rest.pojo.PlaceInputPojo;
import fi.codecrew.moya.rest.pojo.PlaceOutPojo;
import fi.codecrew.moya.rest.pojo.PlaceRoot;
import fi.codecrew.moya.rest.pojo.map.v1.MapRoot;
import fi.codecrew.moya.rest.pojo.map.v1.PlacePojo;
import fi.codecrew.moya.rest.pojo.map.v1.PlaceRoot;
@RequestScoped
@Path("/placeadmin")
......@@ -87,7 +86,7 @@ public class MapAdminView {
@GET
@Path("/maps")
public MapRoot getAllMaps() {
MapRoot ret = MapRoot.parseMaps(eventbean.getCurrentEvent().getEventMaps());
MapRoot ret = PojoUtils.parseMaps(eventbean.getCurrentEvent().getEventMaps());
logger.info("getallmaps called! {}", ret);
return ret;
}
......@@ -96,7 +95,7 @@ public class MapAdminView {
@Path("/places/{mapId}")
public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) {
EventMap map = placebean.findMap(mapid);
PlaceRoot ret = new PlaceRoot(map);
PlaceRoot ret = PojoUtils.initPlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret);
return ret;
}
......@@ -120,7 +119,7 @@ public class MapAdminView {
@POST
@Path("/place/")
public Response createPlace(PlaceInputPojo create) {
public Response createPlace(PlacePojo create) {
logger.info("Finding map with id {}", create.getMapId());
EventMap map = eventmapbean.find(create.getMapId());
if (map == null) {
......@@ -129,17 +128,17 @@ public class MapAdminView {
}
Place place = new Place();
place.setMap(map);
setPlaceValues(place, create);
setUpdatablePlaceValues(place, create);
if (create.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(create.getProductId())))
return Response.serverError().entity("Product id unknown!").build();
logger.info("Creating new place {}", place.getName());
eventmapbean.createPlace(place);
return Response.ok().entity(new PlaceOutPojo(place)).build();
return Response.ok().entity(PojoUtils.initPlacePojo(place)).build();
}
@PUT
@Path("/place/{id}")
public Response updatePlace(@PathParam("id") Integer id, PlaceInputPojo update) {
public Response updatePlace(@PathParam("id") Integer id, PlacePojo update) {
if (update == null || id == null) {
return Response.serverError().entity("'id' field is required!").build();
}
......@@ -147,12 +146,12 @@ public class MapAdminView {
if (place == null) {
return Response.serverError().entity("place not found with id: " + id).build();
}
setPlaceValues(place, update);
setUpdatablePlaceValues(place, update);
if (update.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(update.getProductId())))
return Response.serverError().entity("Product id unknown!").build();
place = eventmapbean.updatePlace(place);
return Response.ok(new PlaceOutPojo(place)).build();
return Response.ok(PojoUtils.initPlacePojo(place)).build();
}
@PUT
......@@ -185,7 +184,7 @@ public class MapAdminView {
return Response.serverError().build();
}
private void setPlaceValues(Place place, PlaceInputPojo update) {
private void setUpdatablePlaceValues(Place place, PlacePojo update) {
if (update.getName() != null)
place.setName(update.getName());
......
......@@ -3,8 +3,14 @@ package fi.codecrew.moya.rest;
import java.util.ArrayList;
import java.util.List;
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.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.userinfo.v1.CardRoot;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
......@@ -60,4 +66,66 @@ public class PojoUtils {
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);
}
}
/*
* 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;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!