package se252.jan15.calvinandhobbes.project0; import javax.ws.rs.DefaultValue; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; /** * Echo web service exposed at "echo" path relative to base URI * * @author Yogesh Simmhan * @version 1.0 * @see <a href="http://www.serc.iisc.ernet.in/~simmhan/SE252/">IISc SERC 'SE252:Intro to Cloud Computing' Course Webpage</a> * * (c) Yogesh Simmhan, 2015 * This work is licensed under a Attribution 4.0 International (CC BY 4.0). * http://creativecommons.org/licenses/by/4.0/ */ public class IIScCampusMapPOSTService { /** * Method handling HTTP GET requests. The request expects a "msg" input parameter with value of type string. * The returned object will be sent to the client as JSON media type. * * @return JSON form of EchoMessage will be returned as response. */ @Path("modifyData") public static class ModifyDataPost { @POST @Produces(MediaType.TEXT_PLAIN) public Response IIScCampusMapPost( @FormParam("drop") String category, @FormParam("dropSub") String name, @FormParam("uname") String newName, @FormParam("desc") String description, @FormParam("latitude") float lat, @FormParam("longitude") float lon, @FormParam("address") String address, @FormParam("operation") String operation, @DefaultValue("off") @FormParam("isEvent") String isEvent, @FormParam("eventStart") String eventStart, @FormParam("eventEnd") String eventEnd, @FormParam("eventTitle") String eventTitle, @FormParam("eventDesc") String eventDesc) { boolean status = false; EventInfo event = null; if(isEvent.equals("on")) { operation = operation.toLowerCase(); event = new EventInfo(); event.setCategory(category); event.setName(newName); event.setLatitude(lat); event.setLongitude(lon); event.setAddress(address); event.setDescription(description); event.setEventTitle(eventTitle); event.setEventDesc(eventDesc); event.setEventStart(eventStart); event.setEventEnd(eventEnd); if(operation.equals("update")) { status = DBConn.insertEvent(event); if(status) System.out.println("Inserted an event"); else System.out.println("Event not inserted"); } else System.out.println("Wrong request for an event" + operation); } else { operation = operation.toLowerCase(); LayerInfo layer = new LayerInfo(); layer.setCategory(category); layer.setName(newName); layer.setLatitude(lat); layer.setLongitude(lon); layer.setAddress(address); layer.setDescription(description); if(operation.equals("insert")) { status = DBConn.insertLayer(layer); if(status) System.out.println("Inserted"); else System.out.println("Not inserted"); } else if(operation.equals("update")) { status = DBConn.updateLayer(layer, name); if(status) System.out.println("Updated"); else System.out.println("Not updated"); } else if(operation.equals("delete")) { status = DBConn.deleteLayer(layer); if(status) System.out.println("Deleted"); else System.out.println("Not deleted"); } else System.out.println("Wrong request " + operation); } if(status) return Response.status(200).entity("true").header("Access-Control-Allow-Origin", "*").build(); else return Response.status(200).entity("false").header("Access-Control-Allow-Origin", "*").build(); } } }