@Path("deletecourses") @DELETE public String deleteCourses(String jsondata) { System.out.println("data received from front end" + jsondata); Object jsonObject = JSON.parse(jsondata); BasicDBObject basicdbobject = (BasicDBObject) jsonObject; CoursesDAO coursesdao = new CoursesDAO(); boolean status = coursesdao.deleteCourseFromDatabase(basicdbobject); JSONObject statusObject = new JSONObject(); try { if (status) { statusObject.put("status", "success"); } else { statusObject.put("status", "fail"); } } catch (JSONException e) { System.out.println("exception in message" + e.getMessage()); } return statusObject.toString(); }
@Path("insertcourses") @PUT @Produces(MediaType.APPLICATION_JSON) public String createCourses(String jsonData) { System.out.println("data received from front end" + jsonData); Object jsonObject = JSON.parse(jsonData); BasicDBObject basicdbobject = (BasicDBObject) jsonObject; CoursesDAO coursesdao = new CoursesDAO(); JSONObject jsonobject = new JSONObject(); try { if (coursesdao.insertCourseInfo(basicdbobject)) { jsonobject.put("status", "success"); } else { jsonobject.put("status", "fail"); } } catch (JSONException e) { System.out.println("Exception in json conversion" + e.getMessage()); } return jsonobject.toString(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("/courses") public String retrieveCourses() { CoursesDAO courseDAO = new CoursesDAO(); DBCursor dbcoursecursor = courseDAO.retrieveAllCourses(); return dbcoursecursor.toArray().toString(); }