Commit 6ac4daa7 by Tuomas Riihimäki

Added place management rest stuff

1 parent 5533d232
......@@ -3,18 +3,19 @@ package fi.codecrew.moya.beans;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.EJBAccessException;
import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.facade.EventFacade;
import fi.codecrew.moya.facade.EventMapFacade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.EventMapBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
/**
* Session Bean implementation class EventMapBean
......@@ -31,6 +32,9 @@ public class EventMapBean implements EventMapBeanLocal {
@EJB
private EventFacade eventfacade;
@EJB
private PlaceFacade placefacade;
private static final Logger logger = LoggerFactory.getLogger(EventMapBean.class);
@Override
......@@ -78,4 +82,25 @@ public class EventMapBean implements EventMapBeanLocal {
return leMap;
}
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
public void deletePlace(Place place) {
place = placefacade.reload(place);
LanEvent currentEvent = eventbean.getCurrentEvent();
if (!currentEvent.equals(place.getMap().getEvent())) {
throw new EJBAccessException("Deleting placce for wrong event!");
}
}
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
public Place findPlace(Integer id) {
Place place = placefacade.find(id);
LanEvent currentEvent = eventbean.getCurrentEvent();
if (!currentEvent.equals(place.getMap().getEvent())) {
throw new EJBAccessException("Fetcing place for wrong event!");
}
return place;
}
}
......@@ -91,7 +91,7 @@ public class ProductBean implements ProductBeanLocal {
private EventBeanLocal eventbean;
@EJB
private BillLineFacade billLineFacade;
@EJB
private ProductPBean productPBean;
......@@ -100,7 +100,7 @@ public class ProductBean implements ProductBeanLocal {
@EJB
private PlaceBean placebean;
@EJB
private DiscountBean discountBean;
......@@ -174,7 +174,6 @@ public class ProductBean implements ProductBeanLocal {
ret.put(prod.getId(), lim);
// logger.info("Added product limit {} to {}", lim, prod);
}
System.out.println(ret);
return ret;
}
......
......@@ -3,6 +3,7 @@ package fi.codecrew.moya.beans;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.Place;
@Local
public interface EventMapBeanLocal {
......@@ -17,4 +18,10 @@ public interface EventMapBeanLocal {
EventMap clearPlaces(EventMap map);
void deletePlace(Place place);
Place findPlace(Integer id);
Place updatePlace(Place place);
}
......@@ -5,6 +5,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="java-output-path" value="/MoyaEventMgmtWeb/build/classes"/>
<property name="context-root" value="moya-mgmt-web"/>
<property name="component.inclusion.patterns" value="WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*"/>
<property name="component.inclusion.patterns" value="WEB-INF/lib/prettyfaces-core*,WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*"/>
</wb-module>
</project-modules>
......@@ -36,7 +36,7 @@ public class AccountEventRestView {
private ProductBeanLocal productBean;
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
@Path("/boughtTimecount/{productId}")
public ArrayList<HcSeriesRoot> boughtTimecount(@PathParam("productId") Integer productId) {
......
package fi.codecrew.moya.rest;
import java.io.ByteArrayInputStream;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.EventMapBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.PlaceMapBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.model.EventMap;
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;
@RequestScoped
@Path("/placeadmin")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
public class MapAdminView {
@EJB
private EventMapBeanLocal eventmapbean;
@EJB
private PlaceMapBeanLocal placemapbean;
@EJB
private PlaceGroupBeanLocal pgbean;
@EJB
private EventBeanLocal eventbean;
@EJB
private ProductBeanLocal productbean;
private static final Logger logger = LoggerFactory.getLogger(MapAdminView.class);
@GET
@Path("/background/{mapId}")
public Response getMapBg(@PathParam("mapId") Integer mapid)
{
EventMap map = placemapbean.findMap(mapid);
ByteArrayInputStream istream = new ByteArrayInputStream(map.getMapData());
return Response.ok().entity(istream).type("image/jpeg").build();
}
@GET
@Path("/maps")
public MapRoot getAllMaps() {
MapRoot ret = MapRoot.parseMaps(eventbean.getCurrentEvent().getEventMaps());
logger.info("getallmaps called! {}", ret);
return ret;
}
@GET
@Path("/places/{mapId}")
public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) {
EventMap map = placemapbean.findMap(mapid);
PlaceRoot ret = new PlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret);
return ret;
}
@DELETE
@Path("/place/{id}")
public Response deletePlace(@PathParam("id") Integer id) {
Place place = eventmapbean.findPlace(id);
eventmapbean.deletePlace(place);
return Response.ok().build();
}
@POST
@Path("/place/")
public Response createPlace(PlaceInputPojo create) {
EventMap map = eventmapbean.find(create.getMapId());
if (map == null) {
return Response.serverError().entity("Error with mapId").build();
}
Place place = new Place();
place.setMap(map);
setPlaceValues(place, create);
if (create.getProductId() != null && (place.getProduct() == null || !place.getProduct().getId().equals(create.getProductId())))
return Response.serverError().entity("Product id unknown!").build();
return Response.ok().entity(new PlaceOutPojo(place)).build();
}
@PUT
@Path("/place/{id}")
public Response updatePlace(@PathParam("id") Integer id, PlaceInputPojo update) {
if (update == null || id == null) {
return Response.serverError().entity("'id' field is required!").build();
}
Place place = eventmapbean.findPlace(id);
if (place == null) {
return Response.serverError().entity("place not found with id: " + id).build();
}
setPlaceValues(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();
}
private void setPlaceValues(Place place, PlaceInputPojo update) {
if (update.getName() != null)
place.setName(update.getName());
if (update.getMapX() != null)
place.setMapX(update.getMapX());
if (update.getMapY() != null)
place.setMapY(update.getMapY());
if (update.getWidth() != null)
place.setWidth(update.getWidth());
if (update.getHeight() != null)
place.setHeight(update.getHeight());
if (update.getBuyable() != null)
place.setBuyable(update.getBuyable());
if (update.getDisabled() != null)
place.setDisabled(update.getDisabled());
if (update.getProductId() != null) {
Product product = productbean.findById(update.getProductId());
if (product != null) {
place.setProduct(product);
}
}
}
}
......@@ -22,7 +22,7 @@ import fi.codecrew.moya.model.PlaceGroup;
@RequestScoped
@Path("/map")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
public class MapRestView {
@EJB
......@@ -32,7 +32,6 @@ public class MapRestView {
@GET
@Path("/dateJson")
@Produces("text/javascript")
public String getAllCards() {
EventMap map = placemapbean.getActiveMap();
......
......@@ -26,7 +26,7 @@ import fi.codecrew.moya.rest.pojo.PrintedCardRestPojo;
@RequestScoped
@Path("/card")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
public class PrinterRestView {
@EJB
......
......@@ -26,7 +26,7 @@ import fi.codecrew.moya.rest.pojo.UserPermissionRestPojo;
@RequestScoped
@Path("/reader")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
public class ReaderRestView {
@EJB
......@@ -55,6 +55,7 @@ public class ReaderRestView {
//
// }
// TBD: WTF! - Tarttis varmaan käydä ajatuksella läpi.. - Tuomari 2014-02-28
@GET
@Path("/EventRole/{reader}/{tagId}/{roleid}")
public Response eventRole(@PathParam("reader") String reader, @PathParam("tagId") String tag, @PathParam("roleid") Integer roleId) {
......
package fi.codecrew.moya.rest;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.rest.pojo.SimpleEventuserRoot;
import fi.codecrew.moya.util.UserSearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
@RequestScoped
@Path("/user")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
public class UserRestView {
@EJB
private UserBeanLocal userbean;
@GET
@Path("/eventusers")
public SimpleEventuserRoot getEventUsers() {
UserSearchQuery q = new UserSearchQuery();
q.setPagesize(0);
SearchResult<EventUser> users = userbean.getThisEventsUsers(q);
return SimpleEventuserRoot.parse(users.getResults());
}
}
package fi.codecrew.moya.rest.pojo;
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 {
private List<MapPojo> maps;
public MapRoot() {
}
public MapRoot(List<MapPojo> ret) {
this.setMaps(ret);
}
public List<MapPojo> getMaps() {
return maps;
}
public void setMaps(List<MapPojo> 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();
}
}
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);
}
}
package fi.codecrew.moya.rest.pojo;
public class PlaceInputPojo {
private String name;
private Integer mapX;
private Integer mapY;
private Integer width;
private Integer height;
private Boolean buyable;
private Boolean disabled;
private Integer productId;
private Integer mapId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getMapX() {
return mapX;
}
public void setMapX(Integer mapX) {
this.mapX = mapX;
}
public Integer getMapY() {
return mapY;
}
public void setMapY(Integer mapY) {
this.mapY = mapY;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
public Boolean getBuyable() {
return buyable;
}
public void setBuyable(Boolean buyable) {
this.buyable = buyable;
}
public Boolean getDisabled() {
return disabled;
}
public void setDisabled(Boolean disabled) {
this.disabled = disabled;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getMapId() {
return mapId;
}
public void setMapId(Integer mapId) {
this.mapId = mapId;
}
}
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 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;
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()));
}
private MapPojo map;
private List<PlaceOutPojo> places;
public MapPojo getMap() {
return map;
}
public void setMap(MapPojo map) {
this.map = map;
}
public List<PlaceOutPojo> getPlaces() {
return places;
}
public void setPlaces(List<PlaceOutPojo> places) {
this.places = places;
}
}
package fi.codecrew.moya.rest.pojo;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import fi.codecrew.moya.model.EventUser;
@XmlRootElement()
public class SimpleEventuserRoot {
private List<EventUserRestPojo> eventusers;
public SimpleEventuserRoot() {
}
public SimpleEventuserRoot(ArrayList<EventUserRestPojo> list) {
this.eventusers = list;
}
public List<EventUserRestPojo> getEventusers() {
return eventusers;
}
public void setEventusers(List<EventUserRestPojo> eventusers) {
this.eventusers = eventusers;
}
public static SimpleEventuserRoot parse(List<EventUser> users) {
ArrayList<EventUserRestPojo> list = new ArrayList<>();
for (EventUser u : users)
{
list.add(new EventUserRestPojo(u));
}
return new SimpleEventuserRoot(list);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!