| 1 | package scriptbuilder.structures; |
|---|
| 2 | |
|---|
| 3 | import java.util.ArrayList; |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Aggregation of several information fields relevant to each timeslice. |
|---|
| 7 | * |
|---|
| 8 | * @author Bryan McGuffin |
|---|
| 9 | */ |
|---|
| 10 | public class CadData implements I_XML_Writable |
|---|
| 11 | { |
|---|
| 12 | |
|---|
| 13 | public CadData() |
|---|
| 14 | { |
|---|
| 15 | locInfo = new ArrayList<Location_Info>(); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * Constructor to add type and location, where TruncLoc is the first 5 letters of the fullloc. |
|---|
| 20 | * @param Header_Type |
|---|
| 21 | * @param Header_FullLoc |
|---|
| 22 | */ |
|---|
| 23 | public CadData(String Header_Type, String Header_FullLoc) |
|---|
| 24 | { |
|---|
| 25 | this.Header_Type = Header_Type; |
|---|
| 26 | this.Header_FullLoc = Header_FullLoc; |
|---|
| 27 | // if(Header_FullLoc.length()>10) |
|---|
| 28 | // { |
|---|
| 29 | // this.Header_TruncLoc = Header_FullLoc.substring(0,9); |
|---|
| 30 | // } |
|---|
| 31 | this.Header_TruncLoc = Header_FullLoc; |
|---|
| 32 | locInfo = new ArrayList<Location_Info>(); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public TimeSlice tSlice; |
|---|
| 36 | |
|---|
| 37 | public String Header_Type = ""; |
|---|
| 38 | |
|---|
| 39 | public String Header_Beat = ""; |
|---|
| 40 | |
|---|
| 41 | public String Header_TruncLoc = ""; |
|---|
| 42 | |
|---|
| 43 | public String Header_FullLoc = ""; |
|---|
| 44 | |
|---|
| 45 | public String Master_Inc_Num = ""; |
|---|
| 46 | |
|---|
| 47 | public String P = ""; |
|---|
| 48 | |
|---|
| 49 | public String Info_Type = ""; |
|---|
| 50 | |
|---|
| 51 | public String Info_Type_Code = ""; |
|---|
| 52 | |
|---|
| 53 | public String Agy = ""; |
|---|
| 54 | |
|---|
| 55 | public String General_Title = ""; |
|---|
| 56 | |
|---|
| 57 | public String General_Text = ""; |
|---|
| 58 | |
|---|
| 59 | public String Location_Beat = ""; |
|---|
| 60 | |
|---|
| 61 | public String Location_Address = ""; |
|---|
| 62 | |
|---|
| 63 | public String Location_Loc = ""; |
|---|
| 64 | |
|---|
| 65 | public String Location_City = ""; |
|---|
| 66 | |
|---|
| 67 | public String Location_Area = ""; |
|---|
| 68 | |
|---|
| 69 | public String Location_Fire = ""; |
|---|
| 70 | |
|---|
| 71 | public String Location_Law = ""; |
|---|
| 72 | |
|---|
| 73 | public String Location_Ems = ""; |
|---|
| 74 | |
|---|
| 75 | public ArrayList<Location_Info> locInfo; |
|---|
| 76 | |
|---|
| 77 | @Override |
|---|
| 78 | public String toXML() |
|---|
| 79 | { |
|---|
| 80 | String output = ""; |
|---|
| 81 | |
|---|
| 82 | if (!Master_Inc_Num.equals("")) |
|---|
| 83 | { |
|---|
| 84 | output += XMLBuilder.simpleTag(Master_Inc_Num, ELEMENT.MASTER_INC_NUM); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | if (!P.equals("")) |
|---|
| 88 | { |
|---|
| 89 | output += XMLBuilder.simpleTag(P, ELEMENT.P); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | if (hasAdditionalInfo()) |
|---|
| 93 | { |
|---|
| 94 | output += XMLBuilder.openTag(ELEMENT.ADDITIONAL_INFO.tag); |
|---|
| 95 | output += XMLBuilder.simpleTag(Info_Type_Code, ELEMENT.TYPE_CODE); |
|---|
| 96 | output += XMLBuilder.simpleTag(Info_Type, ELEMENT.TYPE); |
|---|
| 97 | output += XMLBuilder.closeTag(ELEMENT.ADDITIONAL_INFO.tag); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | if (hasLocation()) |
|---|
| 101 | { |
|---|
| 102 | output += XMLBuilder.openTag(ELEMENT.LOCATION.tag); |
|---|
| 103 | if (!Location_Beat.equals("")) |
|---|
| 104 | { |
|---|
| 105 | output += XMLBuilder.simpleTag(Location_Beat, ELEMENT.BEAT); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if (!Location_Address.equals("")) |
|---|
| 109 | { |
|---|
| 110 | output += XMLBuilder.simpleTag(Location_Address, ELEMENT.ADDRESS); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | if (!Location_Loc.equals("")) |
|---|
| 114 | { |
|---|
| 115 | output += XMLBuilder.simpleTag(Location_Loc, ELEMENT.LOC); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | if (!Location_City.equals("")) |
|---|
| 119 | { |
|---|
| 120 | output += XMLBuilder.simpleTag(Location_City, ELEMENT.CITY); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | if (!Location_Area.equals("")) |
|---|
| 124 | { |
|---|
| 125 | output += XMLBuilder.simpleTag(Location_Area, ELEMENT.AREA); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | if (!Location_Fire.equals("")) |
|---|
| 129 | { |
|---|
| 130 | output += XMLBuilder.simpleTag(Location_Fire, ELEMENT.FIRE); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | if (!Location_Law.equals("")) |
|---|
| 134 | { |
|---|
| 135 | output += XMLBuilder.simpleTag(Location_Law, ELEMENT.LAW); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | if (!Location_Ems.equals("")) |
|---|
| 139 | { |
|---|
| 140 | output += XMLBuilder.simpleTag(Location_Ems, ELEMENT.EMS); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | output += XMLBuilder.closeTag(ELEMENT.LOCATION.tag); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | if (!Agy.equals("")) |
|---|
| 147 | { |
|---|
| 148 | output += XMLBuilder.openTag(ELEMENT.GENERAL.tag); |
|---|
| 149 | output += XMLBuilder.simpleTag(Agy, ELEMENT.AGY); |
|---|
| 150 | output += XMLBuilder.closeTag(ELEMENT.GENERAL.tag); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | if (hasHeaderInfo()) //checking to see if header info is always necessary |
|---|
| 154 | { |
|---|
| 155 | //todo: make this logic trigger only once per incident |
|---|
| 156 | output += XMLBuilder.openTag(ELEMENT.HEADER_INFO.tag); |
|---|
| 157 | |
|---|
| 158 | output += XMLBuilder.simpleTag(Header_Type, ELEMENT.Type); |
|---|
| 159 | |
|---|
| 160 | output += XMLBuilder.simpleTag(Header_Beat, ELEMENT.Beat); |
|---|
| 161 | |
|---|
| 162 | output += XMLBuilder.simpleTag(Header_TruncLoc, ELEMENT.TruncLoc); |
|---|
| 163 | |
|---|
| 164 | output += XMLBuilder.simpleTag(Header_FullLoc, ELEMENT.FullLoc); |
|---|
| 165 | |
|---|
| 166 | output += XMLBuilder.closeTag(ELEMENT.HEADER_INFO.tag); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | if (locInfo.size() > 0) |
|---|
| 170 | { |
|---|
| 171 | for (Location_Info li : locInfo) |
|---|
| 172 | { |
|---|
| 173 | output += li.toXML(); |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | return output; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | public boolean hasHeaderInfo() |
|---|
| 181 | { |
|---|
| 182 | return !Header_Type.equals("") || !Header_Beat.equals("") |
|---|
| 183 | || !Header_FullLoc.equals("") || !Header_TruncLoc.equals(""); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | public boolean hasLocation() |
|---|
| 187 | { |
|---|
| 188 | return !Location_Address.equals("") || !Location_Area.equals("") |
|---|
| 189 | || !Location_Beat.equals("") || !Location_City.equals("") |
|---|
| 190 | || !Location_Ems.equals("") || !Location_Fire.equals("") |
|---|
| 191 | || !Location_Law.equals("") || !Location_Loc.equals(""); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | public boolean hasGeneralInfo() |
|---|
| 195 | { |
|---|
| 196 | return !General_Text.equals("") || !General_Title.equals(""); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | public boolean hasAdditionalInfo() |
|---|
| 200 | { |
|---|
| 201 | return !Info_Type.equals("") || !Info_Type_Code.equals(""); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | public boolean hasCadData() |
|---|
| 205 | { |
|---|
| 206 | return hasHeaderInfo() || hasLocation() || hasAdditionalInfo() |
|---|
| 207 | || !Master_Inc_Num.equals("") || !P.equals("") || !Agy.equals("") |
|---|
| 208 | || locInfo.size() > 0; |
|---|
| 209 | } |
|---|
| 210 | } |
|---|