Commit 1f25944b by Tuomas Riihimäki

Merge branch 'feature/rest-exceptions' into 'master'

rest exceptions, etc.

See merge request !249
2 parents d6be3845 54671cde
......@@ -10,13 +10,13 @@
<properties>
<moya.version>1.0</moya.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.7</java-version>
<java-version>1.8</java-version>
<!-- plugin versions -->
<ejb-plugin-version>2.3</ejb-plugin-version>
<war-plugin-version>2.4</war-plugin-version>
<ear-plugin-version>2.9</ear-plugin-version>
<compiler-plugin-version>3.1</compiler-plugin-version>
<compiler-plugin-version>3.2</compiler-plugin-version>
<!-- dependency versions -->
<javaee-api-version>7.0</javaee-api-version>
<!-- EJB spec version -->
......@@ -40,10 +40,9 @@
<version>${compiler-plugin-version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>${java-version}</source>
<target>${java-version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
......
......@@ -12,7 +12,7 @@
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingIncludes>WEB-INF/lib/moya-restpojo*,WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,WEB-INF/lib/*-1.0.8.jar,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*</packagingIncludes>
<packagingIncludes>WEB-INF/lib/moya-restpojo*,WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,WEB-INF/lib/*-1.0.8.jar,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*,swagger/**</packagingIncludes>
</configuration>
</plugin>
</plugins>
......
......@@ -84,9 +84,14 @@ public class MapAdminView {
@ApiResponse(code = 200, message = "Return backround map as JPEG")
public Response getMapBg(@PathParam("mapId") Integer mapid)
{
try {
EventMap map = placebean.findMap(mapid);
ByteArrayInputStream istream = new ByteArrayInputStream(map.getMapData());
return Response.ok().entity(istream).type("image/jpeg").build();
} catch(Exception e) {
logger.error("GET /placeadmin/background/{mapId} threw an exception", e);
throw e;
}
}
@GET
......@@ -94,28 +99,43 @@ public class MapAdminView {
@ApiOperation(value = "Get All maps", response = MapRoot.class)
@ApiResponse(code = 200, message = "Return all maps")
public MapRoot getAllMaps() {
try {
MapRoot ret = PojoUtils.parseMaps(eventbean.getCurrentEvent().getEventMaps());
logger.info("getallmaps called! {}", ret);
return ret;
} catch(Exception e) {
logger.error("GET /placeadmin/maps threw an exception", e);
throw e;
}
}
@GET
@Path("/places/{mapId}")
@ApiOperation(value = "Get places by mapId", response = PlaceRoot.class)
public PlaceRoot getPlaces(@PathParam("mapId") Integer mapid) {
try {
EventMap map = placebean.findMap(mapid);
PlaceRoot ret = PojoUtils.initPlaceRoot(map);
logger.info("returning map {} entity {}", mapid, ret);
return ret;
} catch(Exception e) {
logger.error("PUT /placeadmin/places/{mapId} threw an exception", e);
throw e;
}
}
@DELETE
@Path("/place/{id}")
@ApiOperation("Delete a place")
public Response deletePlace(@PathParam("id") Integer id) {
try {
Place place = eventmapbean.findPlace(id);
eventmapbean.deletePlace(place);
return Response.ok().build();
} catch(Exception e) {
logger.error("DELETE /placeadmin/place/{id} threw an exception", e);
throw e;
}
}
@GET
......@@ -123,16 +143,22 @@ public class MapAdminView {
@ApiOperation(value = "Always returns 406 - Not acceptable")
@ApiResponse(code = 406, message = "Nope. Not acceptable.")
public Response getPlaceError() {
try {
ResponseBuilder ret = Response.ok();
ret = ret.status(Status.NOT_ACCEPTABLE);
ret.entity("Method not allowed!\nGET is not supported for /place/. See api for correct use!");
return ret.build();
} catch(Exception e) {
logger.error("GET /placeadmin/place/ threw an exception", e);
throw e;
}
}
@POST
@Path("/place/")
@ApiOperation(value = "Create a place", response = PlacePojo.class)
public Response createPlace(PlacePojo create) {
try {
logger.info("Finding map with id {}", create.getMapId());
EventMap map = eventmapbean.find(create.getMapId());
if (map == null) {
......@@ -147,12 +173,17 @@ public class MapAdminView {
logger.info("Creating new place {}", place.getName());
eventmapbean.createPlace(place);
return Response.ok().entity(PojoUtils.initPlacePojo(place)).build();
} catch(Exception e) {
logger.error("POST /placeadmin/place/ threw an exception", e);
throw e;
}
}
@PUT
@Path("/place/{id}")
@ApiOperation(value = "Set a place", response = PlacePojo.class)
public Response updatePlace(@PathParam("id") Integer id, PlacePojo update) {
try {
if (update == null || id == null) {
return Response.serverError().entity("'id' field is required!").build();
}
......@@ -166,12 +197,17 @@ public class MapAdminView {
place = eventmapbean.updatePlace(place);
return Response.ok(PojoUtils.initPlacePojo(place)).build();
} catch (Exception e) {
logger.error("PUT /placeadmin/place/{id} threw an exception", e);
throw e;
}
}
@PUT
@Path("/place/{placeId}/release")
@ApiOperation("Release a class")
public Response releasePlace(@PathParam("placeId") Integer placeId) {
try {
Place place = eventmapbean.findPlace(placeId);
if (place == null) {
return Response.serverError().entity("Place not found!").build();
......@@ -180,24 +216,32 @@ public class MapAdminView {
placebean.unbuyPlace(place);
return Response.ok().build();
} catch (Exception e) {
logger.error("PUT /placeadmin/place/{placeId}/release threw an exception", e);
throw e;
}
}
@PUT
@Path("/place/{placeId}/reserve/{eventuserId}")
@ApiOperation("Reserve a place")
public Response reserve(@PathParam("placeId") Integer placeId, @PathParam("eventuserId") Integer eventuserId) {
try {
Place place = eventmapbean.findPlace(placeId);
EventUser eventuser = eventuserbean.findByEventUserId(eventuserId);
if (placebean.reservePlace(place, eventuser))
{
if (placebean.reservePlace(place, eventuser)) {
try {
placebean.reserveSelectedPlaces(eventuser);
return Response.ok().build();
} catch (BortalCatchableException e) {
logger.warn("Wtf! Bortalerror");
logger.warn("Wtf! Bortalerror", e);
}
}
return Response.serverError().build();
} catch(Exception e) {
logger.error("PUT /placeadmin/place/{placeId}/reserve/{eventuserId} threw an exception", e);
throw e;
}
}
private void setUpdatablePlaceValues(Place place, PlacePojo update) {
......
......@@ -517,3 +517,8 @@ cardTextData.deleteQ=Delete text data from card template?
cardObjectData.delete=Delete
cardTextData.delete=Delete
placegroup.noPlacegroups=Sinulla t\u00E4ytyy olla paikkoja ett\u00E4 voit n\u00E4hd\u00E4 lippusi
bortalApplication.VIP=VIP list
bortalApplication.vip.VIEW=View VIP list
bortalApplication.vip.USAGE=Use VIP list
bortalApplication.vip.EDIT=Edit VIP list
bortalApplication.event.VIEW_STATISTICS=View event statistics
......@@ -1734,3 +1734,8 @@ cardTextData.deleteQ=Delete text data from card template?
cardObjectData.delete=Delete
cardTextData.delete=Delete
placegroup.noPlacegroups=You must have placegroups that you can have places
bortalApplication.VIP=VIP list
bortalApplication.vip.VIEW=View VIP list
bortalApplication.vip.USAGE=Use VIP list
bortalApplication.vip.EDIT=Edit VIP list
bortalApplication.event.VIEW_STATISTICS=View event statistics
......@@ -1717,3 +1717,9 @@ cardTextData.deleteQ=Poistetaanko tekstidata korttipohjalta?
cardObjectData.delete=Poista
cardTextData.delete=Poista
placegroup.noPlacegroups=Sinulla t\u00E4ytyy olla paikkoja ett\u00E4 voit n\u00E4hd\u00E4 lippusi
bortalApplication.VIP=VIP-lista
bortalApplication.vip.VIEW=Näytä VIP-lista
bortalApplication.vip.USAGE=Käytä VIP-listaa
bortalApplication.vip.EDIT=Muokkaa VIP-listaa
bortalApplication.event.VIEW_STATISTICS=Näytä tapahtuman tilastot
lecture.showParticipants=Näytä osallistujat
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!