public void persistIncidents() { JSONArray jsonIncidents = new JSONArray(); for (Incident incident : incidents) { jsonIncidents.add(incident.jsonify()); } json.put("incidents", jsonIncidents); }
private void restoreIncidents() { JSONArray jsonIncidents = (JSONArray) json.get("incidents"); for (Object incidentObject : jsonIncidents) { JSONObject jsonIncident = (JSONObject) incidentObject; String locationID = jsonIncident.get("location").toString(); Location location = null; if (!locationID.isEmpty()) { location = getLocation(Integer.parseInt(locationID)); } String dispatcherID = jsonIncident.get("dispatcher").toString(); Dispatcher dispatcher = null; if (!dispatcherID.isEmpty()) { dispatcher = getDispatcher(Integer.parseInt(dispatcherID)); } String reporterID = jsonIncident.get("reporter").toString(); Reporter reporter = null; if (!reporterID.isEmpty()) { reporter = getReporter(Integer.parseInt(reporterID)); } String typeID = jsonIncident.get("type").toString(); IncidentType type = null; if (!typeID.isEmpty()) { type = getIncidentType(Integer.parseInt(typeID)); } incidents.add(Incident.createFromJSON(jsonIncident, type, location, reporter, dispatcher)); } }
public void fill(Incident i) { title = i.getTitle(); description = i.getDescription(); Date d = i.getDate(); String parts[] = FORMATTER.format(d).split(" "); date = parts[0]; hour = parts[1]; minute = parts[2]; ampm = parts[3].toLowerCase(); locationName = i.getLocationName(); latitude = String.valueOf(i.getLatitude()); longitude = String.valueOf(i.getLongitude()); }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); Incident incident = new Incident(); incident.setIncidentLogNumber(request.getParameter("editfpsnumber")); incident.setReferenceNumber(request.getParameter("editSAPSnumber")); Tools t = new Tools(); String month = Integer.toString(t.getMonthNumber(request.getParameter("edit_incident_month").toString())); String date = request.getParameter("editdetailyear") + "-" + month + "-" + request.getParameter("edit_incident_day"); incident.setDateOfIncident(date); String time = request.getParameter("edit_incident_hour") + ":" + request.getParameter("edit_incident_minute") + ":00"; incident.setTimeOfIncident(time); incident.setNumberOfBodies(Integer.parseInt(request.getParameter("editnumberofbodies"))); incident.setPlaceBodyFound(request.getParameter("editplacefound")); incident.setCircumstanceOfDeath(request.getParameter("editcircumstancesofdeath")); incident.setSpecialCircumstances(request.getParameter("specialcircumstance")); HttpSession sess = request.getSession(); incident.setBodyCount(Integer.parseInt(sess.getAttribute("bodies_recieved").toString())); incident.setStatus(true); DbDetail dbdetail = t.getDbdetail(); IncidentDb incidentdb = new IncidentDb(incident, dbdetail); String persal = request.getSession().getAttribute("personnelnumber").toString(); incidentdb.init(); out.println(incidentdb.edit()); t.makeAuditTrail( "Incident has been edited", "Incident details of incident " + request.getParameter("editfpsnumber") + " has been edited", persal, "Edit Incident Details Tab"); response.sendRedirect("Home.jsp"); }
/** See if incidents are "well-behaved" objects. */ public void testObjectMethods() { Incident a = new Incident(); rest(); Incident b = new Incident(); assertEquals(a, a); assertTrue(!a.equals(b)); assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); int ignore = a.hashCode(); b.setActivityID("test"); assertTrue(!b.equals(a)); assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); ignore = b.hashCode(); }
/** Make sure incidents get timestamped. */ public void testTimestamping() { Incident i = new Incident(); rest(); assertTrue(new Date().compareTo(i.getTime()) > 0); }