source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/data/Incident.java @ 310

Revision 310, 20.0 KB checked in by jdalbey, 7 years ago (diff)

Fix defect #102. Also add revision number to filenames of deploy jars.

Line 
1package tmcsim.client.cadclientgui.data;
2
3import java.util.LinkedList;
4import java.util.TreeMap;
5import java.util.Vector;
6
7import java.io.Serializable;
8
9import javax.swing.ImageIcon;
10import javax.swing.table.DefaultTableModel;
11
12import tmcsim.cadmodels.IncidentEditLog;
13import tmcsim.cadmodels.IncidentInquiryHeader;
14import tmcsim.client.cadclientgui.data.IncidentEvent.EVENT_STATUS;
15import tmcsim.client.cadclientgui.enums.CADScriptTags.CAD_DATA_TAGS;
16import tmcsim.client.cadclientgui.enums.IncidentEnums;
17import tmcsim.common.ParamicsLocation;
18
19/**
20 * This class holds for the data for an incident.
21 *
22 * @author Vincent
23 *
24 */
25public class Incident implements Serializable {
26   
27    public Integer logNum;
28    private String masterInc;
29   
30    /* The init variables are set only from the XML script (readXMLNode method)
31     * and are only used for resetCADDataSimulation purposes
32     */
33    private String init_oau = "";
34    private String init_logTime = "";
35    private String init_p = "";
36    private String init_userData = "";
37    private String init_attachments = "";
38    private String init_rp = "";
39    private String init_ali = "";
40    private String init_rpType = "";
41    private String init_media = "";
42   
43    private ImageIcon alert;
44    private String oau;
45    private String logTime;
46    private String p;
47    private LinkedList<String> assignedUnitNums;
48    private String userData;
49    private String attachments;
50    private String rp;
51    private String ali;
52    private String rpType;
53    private String media;
54    private DefaultTableModel commentsNotesTable;
55   
56    private long startTime;
57    private long secondsIncidentStarted = 0;
58    private boolean incidentOccured = false;
59    public TreeMap<String, ParamicsLocation> locationMap;
60    private Vector<IncidentEvent> eventList = null;
61    public String description;
62   
63    private IncidentLocation incidentLocation;
64    private IncidentCaller incidentCaller;
65    private IncidentProblem problem;
66    private IncidentGeneralInfo genInfo;
67    private IncidentResponse response;
68    private IncidentAdditionalInfo additionalInfo;
69    private IncidentActivities activities;
70    private IncidentCallBacks callBacks;
71    private IncidentEditLog editLog;
72    private IncidentInfo info;
73    private IncidentTimes times;
74    private IncidentTransportInfo transpInfo;
75    private IncidentVehicle incidentVehicle;
76    private IncidentEnums status;
77
78    private Vector<Object> toTableVector;
79
80    public IncidentInquiryHeader header = new IncidentInquiryHeader();
81
82
83    /*
84     * Constructor. Initializes all objects to avoid null pointers.
85     */
86    /*public Incident(int logNum) {
87        masterInc = "";
88        alert = new ImageIcon("images/IncidentPanelsImages/blank.png");
89        oau = "";
90        p = "";
91        description = "";
92        incidentLocation = new IncidentLocation();
93        incidentCaller = new IncidentCaller();
94        problem = new IncidentProblem();
95        genInfo = new IncidentGeneralInfo();
96        assignedUnitNums = new LinkedList<String>();
97        response = new IncidentResponse();
98        additionalInfo = new IncidentAdditionalInfo();
99        activities = new IncidentActivities();
100        callBacks = new IncidentCallBacks();
101        editLog = new IncidentEditLog();
102        info = new IncidentInfo();
103        times = new IncidentTimes();
104        transpInfo = new IncidentTransportInfo();
105        incidentVehicle = new IncidentVehicle();
106        userData = "";
107        attachments = "";
108        status = IncidentEnums.Pending;
109        assignedUnitNums = new LinkedList<String>();
110        rp = "";
111        ali = "";
112        rpType = "";
113        media = "";
114        eventList = new Vector<IncidentEvent>();
115
116        toTableVector = new Vector<Object>();
117
118        commentsNotesTable = new DefaultTableModel() {
119            public boolean isCellEditable(int row, int column) {
120                return false;// This causes all cells to be not editable
121            }
122        };
123        commentsNotesTable.setColumnIdentifiers(new String[] { "Date", "Time",
124                "Initial", "Block", "Comment" });
125
126        setLogNum(logNum);
127    }*/
128
129    public Incident(Integer log, String desc, long start) {
130        logNum = log;
131        description = desc;
132        startTime = start;
133        header      = new IncidentInquiryHeader();     
134        locationMap = new TreeMap<String, ParamicsLocation>();
135        eventList    = new Vector<IncidentEvent>();
136       
137        masterInc = "";
138        alert = new ImageIcon("images/IncidentPanelsImages/blank.png");
139        oau = "";
140        p = "";
141        incidentLocation = new IncidentLocation();
142        incidentCaller = new IncidentCaller();
143        problem = new IncidentProblem();
144        genInfo = new IncidentGeneralInfo();
145        assignedUnitNums = new LinkedList<String>();
146        response = new IncidentResponse();
147        additionalInfo = new IncidentAdditionalInfo();
148        activities = new IncidentActivities();
149        callBacks = new IncidentCallBacks();
150        editLog = new IncidentEditLog();
151        info = new IncidentInfo();
152        times = new IncidentTimes();
153        transpInfo = new IncidentTransportInfo();
154        userData = "";
155        attachments = "";
156        status = IncidentEnums.Pending;
157        assignedUnitNums = new LinkedList();
158        rp = "";
159        ali = "";
160        rpType = "";
161        media = "";
162        eventList = new Vector<IncidentEvent>();
163
164        toTableVector = new Vector<Object>();
165       
166        commentsNotesTable = new DefaultTableModel() {
167            public boolean isCellEditable(int row, int column) {
168                return false;// This causes all cells to be not editable
169            }
170        };
171        commentsNotesTable.setColumnIdentifiers(new String[] { "Date", "Time",
172                "Initial", "Block", "Comment" });
173    }
174
175    /*This method is to be called alongside resetSimulation for true reset.
176     * resetSimulation handles the variables from prior version, while this method resets all the variables
177     * specific to the CADData version. This method is called in the Coordinator following resetSimulation.
178     */
179    public void resetCADDataSimulation(){
180        oau = init_oau;
181        logTime = init_logTime;
182        p = init_p;
183        userData = init_userData;
184        attachments = init_attachments;
185        rp = init_rp;
186        ali = init_ali;
187        rpType = init_rpType;
188        media = init_media;
189        assignedUnitNums.clear();
190        while(commentsNotesTable.getRowCount() > 0){
191            commentsNotesTable.removeRow(0);
192        }
193       
194        incidentLocation.resetCADDataSimulation();
195        incidentCaller.resetCADDataSimulation();
196        problem.resetCADDataSimulation();
197        genInfo.resetCADDataSimulation();
198        response.resetCADDataSimulation();
199        additionalInfo.resetCADDataSimulation();
200        activities.resetCADDataSimulation();
201        callBacks.resetCADDataSimulation();
202        //editLog.resetCADDataSimulation();
203        info.resetCADDataSimulation();
204        //times.resetCADDataSimulation();
205        //transpInfo.resetCADDataSimulation();
206    }
207   
208    public boolean tick(long scriptSeconds) {
209
210        if (scriptSeconds >= startTime && !incidentOccured) {
211            incidentOccured = true;
212            secondsIncidentStarted = scriptSeconds;
213
214            return true;
215        } else
216            return false;
217    }
218
219    public Vector<IncidentEvent> getTriggeredEvents(long simTime) {
220
221        Vector<IncidentEvent> triggered = new Vector<IncidentEvent>();
222
223        if (incidentOccured) {
224            for (IncidentEvent evt : eventList) {
225                if (evt.triggerEvent(secondsIncidentStarted, simTime)) {
226                    triggered.add(evt);
227                }
228            }
229        }
230
231        return triggered;
232    }
233
234    public Vector<IncidentEvent> getCompletedEvents() {
235
236        Vector<IncidentEvent> completed = new Vector<IncidentEvent>();
237
238        for (IncidentEvent evt : eventList) {
239            if (evt.eventStatus == EVENT_STATUS.COMPLETED) {
240                completed.add(evt);
241            }
242        }
243
244        return completed;
245    }
246
247    public Integer getLogNumber() {
248        return logNum;
249    }
250
251    public void manualTrigger(long newtime) {
252        secondsIncidentStarted = newtime;
253        incidentOccured = true;
254    }
255
256    public long getSecondsToStart() {
257        return startTime;
258    }
259
260    public void setSecondsToStart(long newStartTime) {
261        startTime = newStartTime;
262    }
263
264    public Long getIncidentLength() {
265        if (eventList.size() == 0) return 0L;
266        return eventList.lastElement().secondsToOccurInIncident
267                - eventList.firstElement().secondsToOccurInIncident;
268    }
269
270    public boolean hasOccured() {
271        return incidentOccured;
272    }
273
274    public void resetSimulation() {
275        secondsIncidentStarted = 0;
276        incidentOccured = false;
277
278        for (IncidentEvent ie : eventList)
279            ie.resetSimulation();
280
281    }
282
283    public void addEvent(IncidentEvent newEvent) {
284        newEvent.eventInfo.setHeader(header);
285        eventList.add(newEvent);
286    }
287   
288    public String getMasterInc() {
289        return masterInc;
290    }
291
292    public void setMasterInc(String masterInc) {
293        this.masterInc = masterInc;
294    }
295
296    public int getLogNum() {
297        return logNum;
298    }
299
300    public void setLogNum(int logNum) {
301        this.logNum = logNum;
302    }
303
304    public String getOau() {
305        return oau;
306    }
307
308    public void setOau(String oau) {
309        this.oau = oau;
310    }
311
312    public long getTime() {
313        return startTime;
314    }
315
316    public void setTime(long time) {
317        this.startTime = time;
318    }
319
320    public String getLogTime() {
321        return logTime;
322    }
323
324    public void setLogTime(String logTime) {
325        this.logTime = logTime;
326    }
327   
328    public String getP() {
329        return p;
330    }
331
332    public void setP(String p) {
333        this.p = p;
334    }
335
336    public String getDescription() {
337        return description;
338    }
339
340    public void setDescription(String description) {
341        this.description = description;
342    }
343
344    public IncidentCaller getIncidentCaller() {
345        return incidentCaller;
346    }
347
348    public void setIncidentCaller(IncidentCaller incidentCaller) {
349        this.incidentCaller = incidentCaller;
350    }
351
352    public IncidentLocation getIncidentLocation() {
353        return incidentLocation;
354    }
355
356    public void setIncidentLocation(IncidentLocation incidentLocation) {
357        this.incidentLocation = incidentLocation;
358    }
359
360    public IncidentProblem getProblem() {
361        return problem;
362    }
363
364    public void setProblem(IncidentProblem problem) {
365        this.problem = problem;
366    }
367
368    public IncidentGeneralInfo getGenInfo() {
369        return genInfo;
370    }
371
372    public void setGenInfo(IncidentGeneralInfo genInfo) {
373        this.genInfo = genInfo;
374    }
375
376    public LinkedList<String> getAssignedUnitNums() {
377        return assignedUnitNums;
378    }
379
380    public void setPrimaryAssignedUnitNum(String assignedUnitNum) {
381        assignedUnitNums.remove(assignedUnitNum);
382        assignedUnitNums.addFirst(assignedUnitNum);
383    }
384
385    public void addAssignedUnitNum(String assignedUnitNum) {
386        assignedUnitNums.addLast(assignedUnitNum);
387    }
388   
389    public void removeAssignedUnitNum(String assignedUnitNum){
390        assignedUnitNums.remove(assignedUnitNum);
391        if(assignedUnitNums.size() == 0){
392            status = IncidentEnums.Closed;
393        }
394    }
395
396    public IncidentResponse getResponse() {
397        return response;
398    }
399
400    public void setResponse(IncidentResponse response) {
401        this.response = response;
402    }
403
404    public IncidentAdditionalInfo getAdditionalInfo() {
405        return additionalInfo;
406    }
407
408    public void setAdditionalInfo(IncidentAdditionalInfo additionalInfo) {
409        this.additionalInfo = additionalInfo;
410    }
411
412    public IncidentActivities getActivities() {
413        return activities;
414    }
415
416    public void setActivities(IncidentActivities activities) {
417        this.activities = activities;
418    }
419
420    public IncidentCallBacks getCallBacks() {
421        return callBacks;
422    }
423
424    public void setCallBacks(IncidentCallBacks callBacks) {
425        this.callBacks = callBacks;
426    }
427
428    public IncidentEditLog getEditLog() {
429        return editLog;
430    }
431
432    public void setEditLog(IncidentEditLog editLog) {
433        this.editLog = editLog;
434    }
435
436    public IncidentInfo getInfo() {
437        return info;
438    }
439
440    public void setInfo(IncidentInfo info) {
441        this.info = info;
442    }
443
444    public IncidentTimes getTimes() {
445        return times;
446    }
447
448    public void setTimes(IncidentTimes times) {
449        this.times = times;
450    }
451
452    public IncidentTransportInfo getTranspInfo() {
453        return transpInfo;
454    }
455
456    public void setTranspInfo(IncidentTransportInfo transpInfo) {
457        this.transpInfo = transpInfo;
458    }
459
460    public IncidentVehicle getIncidentVehicle() {
461        return incidentVehicle;
462    }
463
464    public void setIncidentVehicle(IncidentVehicle incidentVehicle) {
465        this.incidentVehicle = incidentVehicle;
466    }
467
468    public String getUserData() {
469        return userData;
470    }
471
472    public void setUserData(String userData) {
473        this.userData = userData;
474    }
475
476    public String getAttachments() {
477        return attachments;
478    }
479
480    public void setAttachments(String attachments) {
481        this.attachments = attachments;
482    }
483
484    public IncidentEnums getIncidentStatus() {
485        return status;
486    }
487
488    public void setIncidentStatus(IncidentEnums status) {
489        this.status = status;
490    }
491
492    public String getRp() {
493        return rp;
494    }
495
496    public void setRp(String rp) {
497        this.rp = rp;
498    }
499
500    public String getAli() {
501        return ali;
502    }
503
504    public void setAli(String ali) {
505        this.ali = ali;
506    }
507
508    public String getRpType() {
509        return rpType;
510    }
511
512    public void setRpType(String rpType) {
513        this.rpType = rpType;
514    }
515
516    public String getMedia() {
517        return media;
518    }
519
520    public void setMedia(String media) {
521        this.media = media;
522    }
523
524    public DefaultTableModel getCommentsNotesTable() {
525        return commentsNotesTable;
526    }
527
528    public void addToCommentsNotesTable(String[] fields) {
529        this.commentsNotesTable.insertRow(0, fields); // new notes go 1st
530    }
531
532    /*
533     * Stores the data needed to be displayed in the AssignedIncidents panel and
534     * sends it out as a toTableVector.
535     */
536    public Vector<Object> toVectorForAssignedIncidents() {
537        Vector<Object> vector = new Vector<Object>();
538
539        toTableVector.clear();
540        toTableVector.add(logNum);
541        toTableVector.add(masterInc);
542        toTableVector.add(alert);
543        if (assignedUnitNums.size() != 0) {
544            toTableVector.add(assignedUnitNums.getFirst());
545        } else {
546            toTableVector.add("");
547        }
548
549        String unitNums = "";
550        for (int i = 0; i < assignedUnitNums.size(); i++) {
551            unitNums = unitNums.concat((String) assignedUnitNums.get(i));
552            if (i == assignedUnitNums.size() - 1) {
553                break;
554            }
555            unitNums = unitNums.concat(", ");
556        }
557        toTableVector.add(unitNums);
558        toTableVector.add(additionalInfo.getType());
559        toTableVector.add(incidentLocation.getAddress());
560        toTableVector.add(incidentLocation.getLoc());
561        toTableVector.add(incidentLocation.getBeat());
562        toTableVector.add(incidentLocation.getArea());
563        toTableVector.add(oau);
564        toTableVector.add(startTime);
565        toTableVector.add(logTime);
566        toTableVector.add(additionalInfo.getTypeCode());
567        toTableVector.add(p);
568        toTableVector.add(genInfo.getAgy());
569        return toTableVector;
570    }
571
572    /*
573     * Stores the data needed to be displayed in the PendingIncidents panel and
574     * sends it out as a toTableVector.
575     */
576    public Vector<Object> toVectorForPendingIncidents() {
577        Vector<Object> vector = new Vector<Object>();
578        vector.add(logNum);
579        vector.add(masterInc);
580        vector.add(alert);
581        vector.add(p);
582        vector.add(additionalInfo.getType());
583        vector.add(incidentLocation.getAddress());
584        vector.add(incidentLocation.getLoc());
585        vector.add(incidentLocation.getCity());
586        vector.add(incidentLocation.getBeat());
587        vector.add(incidentLocation.getArea());
588        vector.add(oau);
589        vector.add(startTime);
590        vector.add(logTime);
591        vector.add(additionalInfo.getTypeCode());
592        vector.add(genInfo.getAgy());
593
594        return vector;
595    }
596
597    public Vector<Object> toVectorForIncidentEditor() {
598        toTableVector.clear();
599        toTableVector.add(logTime);
600        toTableVector.add(additionalInfo.getTypeCode());
601        toTableVector.add(incidentLocation.getAddress());
602        toTableVector.add(incidentLocation.getLoc());
603        toTableVector.add(incidentLocation.getCity());
604        toTableVector.add(masterInc);
605        toTableVector.add("GG");
606        toTableVector.add(incidentLocation.getArea());
607       
608        String unitNums = "";
609        for (int i = 0; i < assignedUnitNums.size(); i++) {
610            unitNums = unitNums.concat((String) assignedUnitNums.get(i));
611            if (i == assignedUnitNums.size() - 1) {
612                break;
613            }
614            unitNums = unitNums.concat(", ");
615        }
616       
617        toTableVector.add("F-File");
618        return toTableVector;
619    }
620
621    /*
622     * Called from the tmc.simulator.cadclient.ScriptHandler.java. Handles
623     * storing data based on script tag.
624     */
625    public void readXMLNode(String outer_tag_name, String inner_tag_name,
626            String value) {
627        if (outer_tag_name.equals(CAD_DATA_TAGS.LOCATION.tag)) {
628            incidentLocation.readXMLNode(inner_tag_name, value);
629        } else if (outer_tag_name.equals(CAD_DATA_TAGS.CALLER.tag)) {
630            incidentCaller.readXMLNode(inner_tag_name, value);
631        } else if (outer_tag_name.equals(CAD_DATA_TAGS.PROBLEM.tag)) {
632            problem.readXMLNode(inner_tag_name, value);
633        } else if (outer_tag_name.equals(CAD_DATA_TAGS.GENERAL.tag)) {
634            genInfo.readXMLNode(inner_tag_name, value);
635        } else if (outer_tag_name.equals(CAD_DATA_TAGS.RESPONSE.tag)) {
636            response.readXMLNode(inner_tag_name, value);
637        } else if (outer_tag_name.equals(CAD_DATA_TAGS.ADDITIONAL_INFO.tag)) {
638            additionalInfo.readXMLNode(inner_tag_name, value);
639        } else if (outer_tag_name.equals(CAD_DATA_TAGS.ACTIVITIES.tag)) {
640            activities.readXMLNode(inner_tag_name, value);
641        } else if (outer_tag_name.equals(CAD_DATA_TAGS.CALL_BACKS.tag)) {
642            callBacks.readXMLNode(inner_tag_name, value);
643        } else if (outer_tag_name.equals(CAD_DATA_TAGS.EDIT_LOG.tag)) {
644            editLog.readXMLNode(inner_tag_name, value);
645        } else if (outer_tag_name.equals(CAD_DATA_TAGS.INFO.tag)) {
646            info.readXMLNode(inner_tag_name, value);
647        } else if (outer_tag_name.equals(CAD_DATA_TAGS.TIMES.tag)) {
648            times.readXMLNode(inner_tag_name, value);
649        } else if (outer_tag_name.equals(CAD_DATA_TAGS.TRANSPORT_INFO.tag)) {
650            transpInfo.readXMLNode(inner_tag_name, value);
651        } else if (outer_tag_name.equals(CAD_DATA_TAGS.USER_DATA.tag)) {
652            init_userData = value;
653            setUserData(value);
654        } else if (outer_tag_name.equals(CAD_DATA_TAGS.ATTACHMENTS.tag)) {
655            init_attachments = value;
656            setAttachments(value);
657        } else if (outer_tag_name.equals(CAD_DATA_TAGS.RP.tag)) {
658            init_rp = value;
659            setRp(value);
660        } else if (outer_tag_name.equals(CAD_DATA_TAGS.ALI.tag)) {
661            init_ali = value;
662            setAli(value);
663        } else if (outer_tag_name.equals(CAD_DATA_TAGS.RP_TYPE.tag)) {
664            init_rpType = value;
665            setRpType(value);
666        } else if (outer_tag_name.equals(CAD_DATA_TAGS.MEDIA.tag)) {
667            init_media = value;
668            setMedia(value);
669        } else if (outer_tag_name.equals(CAD_DATA_TAGS.MASTER_INC_NUM.tag)) {
670            //masterInc should be unchanged,no init
671            setMasterInc(value);
672        } else if (outer_tag_name.equals(CAD_DATA_TAGS.P.tag)) {
673            init_p = value;
674            setP(value);
675        } 
676
677    }
678}
Note: See TracBrowser for help on using the repository browser.