Commit 220fddf4 by Tuukka Kivilahti

Merge branch 'restDeleteFix' into 'master'

Fix rest place removing

Add missing remove function, and more informative responses to http.

See merge request !327
2 parents a6ed14c6 06960395
...@@ -53,9 +53,10 @@ public class EventMapBean implements EventMapBeanLocal { ...@@ -53,9 +53,10 @@ public class EventMapBean implements EventMapBeanLocal {
@EJB @EJB
private PlaceFacade placefacade; private PlaceFacade placefacade;
private static final Logger logger = LoggerFactory.getLogger(EventMapBean.class); @EJB
private PermissionBeanLocal permbean;
private static final Logger logger = LoggerFactory.getLogger(EventMapBean.class);
@Override @Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS) @RolesAllowed(MapPermission.S_MANAGE_MAPS)
...@@ -110,6 +111,7 @@ public class EventMapBean implements EventMapBeanLocal { ...@@ -110,6 +111,7 @@ public class EventMapBean implements EventMapBeanLocal {
if (!currentEvent.equals(place.getMap().getEvent())) { if (!currentEvent.equals(place.getMap().getEvent())) {
throw new EJBAccessException("Deleting placce for wrong event!"); throw new EJBAccessException("Deleting placce for wrong event!");
} }
placefacade.remove(place);
} }
@Override @Override
...@@ -119,7 +121,8 @@ public class EventMapBean implements EventMapBeanLocal { ...@@ -119,7 +121,8 @@ public class EventMapBean implements EventMapBeanLocal {
Place place = placefacade.find(id); Place place = placefacade.find(id);
LanEvent currentEvent = eventbean.getCurrentEvent(); LanEvent currentEvent = eventbean.getCurrentEvent();
if (!currentEvent.equals(place.getMap().getEvent())) { if (!currentEvent.equals(place.getMap().getEvent())) {
throw new EJBAccessException("Fetcing place for wrong event!"); logger.warn("Tried to fetch place from wrong event!: user {}, place: {}, event {}", permbean.getCurrentUser(), place, currentEvent);
place = null;
} }
return place; return place;
} }
......
...@@ -82,13 +82,12 @@ public class MapAdminView { ...@@ -82,13 +82,12 @@ public class MapAdminView {
@GET @GET
@Path("/background/{mapId}") @Path("/background/{mapId}")
@ApiResponse(code = 200, message = "Return backround map as JPEG") @ApiResponse(code = 200, message = "Return backround map as JPEG")
public Response getMapBg(@PathParam("mapId") Integer mapid) public Response getMapBg(@PathParam("mapId") Integer mapid) {
{
try { try {
EventMap map = placebean.findMap(mapid); EventMap map = placebean.findMap(mapid);
ByteArrayInputStream istream = new ByteArrayInputStream(map.getMapData()); ByteArrayInputStream istream = new ByteArrayInputStream(map.getMapData());
return Response.ok().entity(istream).type("image/jpeg").build(); return Response.ok().entity(istream).type("image/jpeg").build();
} catch(Exception e) { } catch (Exception e) {
logger.error("GET /placeadmin/background/{mapId} threw an exception", e); logger.error("GET /placeadmin/background/{mapId} threw an exception", e);
throw e; throw e;
} }
...@@ -103,7 +102,7 @@ public class MapAdminView { ...@@ -103,7 +102,7 @@ public class MapAdminView {
MapRoot ret = PojoUtils.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;
} catch(Exception e) { } catch (Exception e) {
logger.error("GET /placeadmin/maps threw an exception", e); logger.error("GET /placeadmin/maps threw an exception", e);
throw e; throw e;
} }
...@@ -118,7 +117,7 @@ public class MapAdminView { ...@@ -118,7 +117,7 @@ public class MapAdminView {
PlaceRoot ret = PojoUtils.initPlaceRoot(map); PlaceRoot ret = PojoUtils.initPlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret); logger.info("returning map {} entity {}", mapid, ret);
return ret; return ret;
} catch(Exception e) { } catch (Exception e) {
logger.error("PUT /placeadmin/places/{mapId} threw an exception", e); logger.error("PUT /placeadmin/places/{mapId} threw an exception", e);
throw e; throw e;
} }
...@@ -130,11 +129,14 @@ public class MapAdminView { ...@@ -130,11 +129,14 @@ public class MapAdminView {
public Response deletePlace(@PathParam("id") Integer id) { public Response deletePlace(@PathParam("id") Integer id) {
try { try {
Place place = eventmapbean.findPlace(id); Place place = eventmapbean.findPlace(id);
if (place == null) {
return Response.status(Status.NOT_FOUND).entity("Place not found for id " + id).build();
}
eventmapbean.deletePlace(place); eventmapbean.deletePlace(place);
return Response.ok().build(); return Response.ok().build();
} catch(Exception e) { } catch (Exception e) {
logger.error("DELETE /placeadmin/place/{id} threw an exception", e); logger.error("DELETE /placeadmin/place/{id} threw an exception", e);
throw e; return Response.serverError().entity("Got exception when removing place: " + e.getMessage()).build();
} }
} }
...@@ -148,7 +150,7 @@ public class MapAdminView { ...@@ -148,7 +150,7 @@ public class MapAdminView {
ret = ret.status(Status.NOT_ACCEPTABLE); ret = ret.status(Status.NOT_ACCEPTABLE);
ret.entity("Method not allowed!\nGET is not supported for /place/. See api for correct use!"); ret.entity("Method not allowed!\nGET is not supported for /place/. See api for correct use!");
return ret.build(); return ret.build();
} catch(Exception e) { } catch (Exception e) {
logger.error("GET /placeadmin/place/ threw an exception", e); logger.error("GET /placeadmin/place/ threw an exception", e);
throw e; throw e;
} }
...@@ -173,7 +175,7 @@ public class MapAdminView { ...@@ -173,7 +175,7 @@ public class MapAdminView {
logger.info("Creating new place {}", place.getName()); logger.info("Creating new place {}", place.getName());
eventmapbean.createPlace(place); eventmapbean.createPlace(place);
return Response.ok().entity(PojoUtils.initPlacePojo(place)).build(); return Response.ok().entity(PojoUtils.initPlacePojo(place)).build();
} catch(Exception e) { } catch (Exception e) {
logger.error("POST /placeadmin/place/ threw an exception", e); logger.error("POST /placeadmin/place/ threw an exception", e);
throw e; throw e;
} }
...@@ -238,7 +240,7 @@ public class MapAdminView { ...@@ -238,7 +240,7 @@ public class MapAdminView {
} }
} }
return Response.serverError().build(); return Response.serverError().build();
} catch(Exception e) { } catch (Exception e) {
logger.error("PUT /placeadmin/place/{placeId}/reserve/{eventuserId} threw an exception", e); logger.error("PUT /placeadmin/place/{placeId}/reserve/{eventuserId} threw an exception", e);
throw e; throw e;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!