| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.services.util; |
| 20 |
|
|
| 21 |
|
import java.util.ArrayList; |
| 22 |
|
import java.util.Date; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
import java.util.Iterator; |
| 25 |
|
import java.util.List; |
| 26 |
|
import java.util.Map; |
| 27 |
|
|
| 28 |
|
import org.apache.log4j.Logger; |
| 29 |
|
import org.itracker.core.resources.ITrackerResources; |
| 30 |
|
import org.itracker.model.AbstractEntity; |
| 31 |
|
import org.itracker.model.Component; |
| 32 |
|
import org.itracker.model.Configuration; |
| 33 |
|
import org.itracker.model.CustomField; |
| 34 |
|
import org.itracker.model.Issue; |
| 35 |
|
import org.itracker.model.IssueAttachment; |
| 36 |
|
import org.itracker.model.IssueField; |
| 37 |
|
import org.itracker.model.IssueHistory; |
| 38 |
|
import org.itracker.model.Project; |
| 39 |
|
import org.itracker.model.Status; |
| 40 |
|
import org.itracker.model.SystemConfiguration; |
| 41 |
|
import org.itracker.model.User; |
| 42 |
|
import org.itracker.model.Version; |
| 43 |
|
import org.xml.sax.Attributes; |
| 44 |
|
import org.xml.sax.SAXException; |
| 45 |
|
import org.xml.sax.helpers.DefaultHandler; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
|
|
|
| 93.2% |
Uncovered Elements: 41 (606) |
Complexity: 155 |
Complexity Density: 0.45 |
|
| 52 |
|
public class ImportHandler extends DefaultHandler implements ImportExportTags { |
| 53 |
|
|
| 54 |
|
private final Logger logger; |
| 55 |
|
private List<AbstractEntity> items; |
| 56 |
|
private StringBuffer tagBuffer; |
| 57 |
|
private SAXException endException; |
| 58 |
|
|
| 59 |
|
private AbstractEntity parentModel; |
| 60 |
|
private AbstractEntity childModel; |
| 61 |
|
private List<Object> itemList; |
| 62 |
|
private String tempStorage; |
| 63 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 64 |
32
|
public ImportHandler() {... |
| 65 |
32
|
this.logger = Logger.getLogger(getClass()); |
| 66 |
32
|
this.items = new ArrayList<AbstractEntity>(); |
| 67 |
32
|
this.endException = null; |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 70 |
19
|
public AbstractEntity[] getModels() {... |
| 71 |
19
|
AbstractEntity[] modelsArray = items.toArray(new AbstractEntity[]{}); |
| 72 |
19
|
return modelsArray; |
| 73 |
|
} |
| 74 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
1
|
public void startDocument() {... |
| 76 |
1
|
logger.debug("Started import xml parsing."); |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 79 |
1
|
public void endDocument() {... |
| 80 |
1
|
logger.debug("Completed import xml parsing."); |
| 81 |
|
} |
| 82 |
|
|
|
|
|
| 98.3% |
Uncovered Elements: 3 (172) |
Complexity: 37 |
Complexity Density: 0.36 |
|
| 83 |
116
|
public void startElement(String uri, String name, String qName, Attributes atts) throws SAXException {... |
| 84 |
116
|
logger.debug("Parsing import tag " + qName); |
| 85 |
|
|
| 86 |
116
|
if(endException != null) { |
| 87 |
0
|
throw endException; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
116
|
tempStorage = ""; |
| 92 |
116
|
try { |
| 93 |
116
|
if(TAG_COMPONENT.equals(qName)) { |
| 94 |
2
|
String id = atts.getValue(ATTR_SYSTEMID); |
| 95 |
2
|
if(id == null) { |
| 96 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for component."); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
1
|
childModel = new Component((Project)parentModel, atts.getValue(ATTR_ID)); |
| 101 |
1
|
childModel.setId(new Integer(id)); |
| 102 |
114
|
} else if(TAG_COMPONENTS.equals(qName)) { |
| 103 |
1
|
itemList = new ArrayList<Object>(); |
| 104 |
113
|
} else if(TAG_CONFIGURATION.equals(qName)) { |
| 105 |
8
|
parentModel = new SystemConfiguration(); |
| 106 |
105
|
} else if(TAG_CUSTOM_FIELD.equals(qName)) { |
| 107 |
4
|
String id = atts.getValue(ATTR_SYSTEMID); |
| 108 |
4
|
if(id == null) { |
| 109 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for issue."); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
3
|
childModel = new CustomField(); |
| 113 |
3
|
childModel.setId(new Integer(id)); |
| 114 |
101
|
} else if(TAG_CUSTOM_FIELD_OPTION.equals(qName)) { |
| 115 |
2
|
tempStorage = ITrackerResources.unescapeUnicodeString(atts.getValue(ATTR_VALUE)); |
| 116 |
99
|
} else if(TAG_CUSTOM_FIELDS.equals(qName)) { |
| 117 |
3
|
itemList = new ArrayList<Object>(); |
| 118 |
96
|
} else if(TAG_HISTORY_ENTRY.equals(qName)) { |
| 119 |
3
|
String creatorId = atts.getValue(ATTR_CREATOR_ID); |
| 120 |
3
|
String date = atts.getValue(ATTR_DATE); |
| 121 |
3
|
String status = atts.getValue(ATTR_STATUS); |
| 122 |
3
|
if(creatorId == null) { |
| 123 |
1
|
throw new SAXException("Attribute creatorId was null for issue history."); |
| 124 |
2
|
} else if(date == null) { |
| 125 |
1
|
throw new SAXException("Attribute date was null for issue history."); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
1
|
childModel = new IssueHistory(); |
| 129 |
1
|
((IssueHistory) childModel).setUser((User) findModel(creatorId)); |
| 130 |
1
|
((IssueHistory) childModel).setStatus(status != null && ! status.equals("") ? Integer.parseInt(status) : IssueUtilities.HISTORY_STATUS_AVAILABLE); |
| 131 |
1
|
((IssueHistory) childModel).setCreateDate(getDateValue(date, qName)); |
| 132 |
1
|
tagBuffer = new StringBuffer(); |
| 133 |
93
|
} else if(TAG_ISSUE.equals(qName)) { |
| 134 |
9
|
String id = atts.getValue(ATTR_SYSTEMID); |
| 135 |
9
|
if(id == null) { |
| 136 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for issue."); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
8
|
parentModel = new Issue(); |
| 140 |
8
|
parentModel.setId(new Integer(id)); |
| 141 |
84
|
} else if(TAG_ISSUE_ATTACHMENT.equals(qName)) { |
| 142 |
2
|
childModel = new IssueAttachment(); |
| 143 |
82
|
} else if(TAG_ISSUE_ATTACHMENTS.equals(qName)) { |
| 144 |
2
|
itemList = new ArrayList<Object>(); |
| 145 |
80
|
} else if(TAG_ISSUE_COMPONENTS.equals(qName)) { |
| 146 |
1
|
itemList = new ArrayList<Object>(); |
| 147 |
79
|
} else if(TAG_ISSUE_FIELD.equals(qName)) { |
| 148 |
2
|
String id = atts.getValue(ATTR_ID); |
| 149 |
2
|
if(id == null) { |
| 150 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for issue field."); |
| 151 |
|
} |
| 152 |
1
|
childModel = new IssueField((Issue) parentModel, (CustomField) findModel(id)); |
| 153 |
77
|
} else if(TAG_ISSUE_FIELDS.equals(qName)) { |
| 154 |
1
|
itemList = new ArrayList<Object>(); |
| 155 |
76
|
} else if(TAG_ISSUE_HISTORY.equals(qName)) { |
| 156 |
1
|
itemList = new ArrayList<Object>(); |
| 157 |
75
|
} else if(TAG_ISSUE_VERSIONS.equals(qName)) { |
| 158 |
1
|
itemList = new ArrayList<Object>(); |
| 159 |
74
|
} else if(TAG_PROJECT.equals(qName)) { |
| 160 |
7
|
String id = atts.getValue(ATTR_SYSTEMID); |
| 161 |
7
|
if(id == null) { |
| 162 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for project."); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
6
|
parentModel = new Project(); |
| 166 |
6
|
parentModel.setId(new Integer(id)); |
| 167 |
67
|
} else if(TAG_PROJECT_FIELDS.equals(qName)) { |
| 168 |
1
|
itemList = new ArrayList<Object>(); |
| 169 |
66
|
} else if(TAG_PROJECT_OWNERS.equals(qName)) { |
| 170 |
1
|
itemList = new ArrayList<Object>(); |
| 171 |
65
|
} else if(TAG_RESOLUTION.equals(qName)) { |
| 172 |
1
|
String value = atts.getValue(ATTR_VALUE); |
| 173 |
1
|
String order = atts.getValue(ATTR_ORDER); |
| 174 |
|
|
| 175 |
1
|
childModel = new Configuration(SystemConfigurationUtilities.TYPE_RESOLUTION, value, Integer.parseInt(order)); |
| 176 |
1
|
tagBuffer = new StringBuffer(); |
| 177 |
64
|
} else if(TAG_SEVERITY.equals(qName)) { |
| 178 |
1
|
String value = atts.getValue(ATTR_VALUE); |
| 179 |
1
|
String order = atts.getValue(ATTR_ORDER); |
| 180 |
|
|
| 181 |
1
|
childModel = new Configuration(SystemConfigurationUtilities.TYPE_SEVERITY, value, Integer.parseInt(order)); |
| 182 |
1
|
tagBuffer = new StringBuffer(); |
| 183 |
63
|
} else if(TAG_STATUS.equals(qName)) { |
| 184 |
2
|
String value = atts.getValue(ATTR_VALUE); |
| 185 |
2
|
String order = atts.getValue(ATTR_ORDER); |
| 186 |
|
|
| 187 |
2
|
childModel = new Configuration(SystemConfigurationUtilities.TYPE_STATUS, value, Integer.parseInt(order)); |
| 188 |
1
|
tagBuffer = new StringBuffer(); |
| 189 |
61
|
} else if(TAG_USER.equals(qName)) { |
| 190 |
4
|
String id = atts.getValue(ATTR_SYSTEMID); |
| 191 |
4
|
if(id == null) { |
| 192 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for user."); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
3
|
parentModel = new User(); |
| 196 |
3
|
parentModel.setId(new Integer(id)); |
| 197 |
57
|
} else if(TAG_VERSION.equals(qName)) { |
| 198 |
3
|
String id = atts.getValue(ATTR_SYSTEMID); |
| 199 |
3
|
if(id == null) { |
| 200 |
1
|
throw new SAXException("Attribute " + ATTR_SYSTEMID + " was null for version."); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
2
|
childModel = new Version((Project)parentModel, atts.getValue(ATTR_ID)); |
| 205 |
2
|
childModel.setId(new Integer(id)); |
| 206 |
54
|
} else if(TAG_VERSIONS.equals(qName)) { |
| 207 |
2
|
itemList = new ArrayList<Object>(); |
| 208 |
|
} else { |
| 209 |
52
|
tagBuffer = new StringBuffer(); |
| 210 |
|
} |
| 211 |
|
} catch(NumberFormatException nfe) { |
| 212 |
1
|
throw new SAXException("Attribute in " + qName + " did not contain a numeric value."); |
| 213 |
|
} |
| 214 |
|
} |
| 215 |
|
|
|
|
|
| 94.4% |
Uncovered Elements: 19 (338) |
Complexity: 86 |
Complexity Density: 0.46 |
|
| 216 |
99
|
public void endElement(String uri, String name, String qName) throws SAXException {... |
| 217 |
99
|
logger.debug("Completing import tag " + qName); |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
99
|
try { |
| 223 |
99
|
if(TAG_ISSUE.equals(qName) || TAG_PROJECT.equals(qName) || TAG_USER.equals(qName) || TAG_CONFIGURATION.equals(qName)) { |
| 224 |
22
|
items.add((AbstractEntity)parentModel.clone()); |
| 225 |
22
|
parentModel = null; |
| 226 |
22
|
childModel = null; |
| 227 |
22
|
itemList = null; |
| 228 |
77
|
} else if(TAG_RESOLUTION.equals(qName) || TAG_SEVERITY.equals(qName) || TAG_STATUS.equals(qName)) { |
| 229 |
3
|
((Configuration) childModel).setName(getBuffer()); |
| 230 |
3
|
items.add((AbstractEntity)childModel.clone()); |
| 231 |
3
|
((SystemConfiguration) parentModel).addConfiguration((Configuration) childModel); |
| 232 |
3
|
childModel = null; |
| 233 |
74
|
} else if(TAG_COMPONENT.equals(qName) || TAG_VERSION.equals(qName) || TAG_CUSTOM_FIELD.equals(qName)) { |
| 234 |
|
|
| 235 |
|
|
| 236 |
5
|
items.add((AbstractEntity)childModel.clone()); |
| 237 |
5
|
itemList.add(childModel.clone()); |
| 238 |
5
|
childModel = null; |
| 239 |
69
|
} else if(TAG_HISTORY_ENTRY.equals(qName)) { |
| 240 |
1
|
((IssueHistory) childModel).setDescription(getBuffer()); |
| 241 |
1
|
itemList.add(childModel.clone()); |
| 242 |
1
|
childModel = null; |
| 243 |
68
|
} else if(TAG_ISSUE_ATTACHMENT.equals(qName)) { |
| 244 |
1
|
itemList.add(childModel.clone()); |
| 245 |
1
|
childModel = null; |
| 246 |
67
|
} else if(TAG_ISSUE_FIELD.equals(qName)) { |
| 247 |
1
|
itemList.add(childModel.clone()); |
| 248 |
1
|
childModel = null; |
| 249 |
66
|
} else if(TAG_COMPONENTS.equals(qName)) { |
| 250 |
1
|
List<Component> itemListArray = new ArrayList<Component>(); |
| 251 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 252 |
1
|
itemListArray.add((Component) itemList.get(i)); |
| 253 |
|
} |
| 254 |
1
|
((Project) parentModel).setComponents(itemListArray); |
| 255 |
65
|
} else if(TAG_COMPONENT_DESCRIPTION.equals(qName)) { |
| 256 |
1
|
((Component) childModel).setDescription(getBuffer()); |
| 257 |
64
|
} else if(TAG_COMPONENT_ID.equals(qName)) { |
| 258 |
1
|
if(itemList == null) { |
| 259 |
0
|
itemList = new ArrayList<Object>(); |
| 260 |
|
} |
| 261 |
1
|
itemList.add((Component) findModel(getBuffer())); |
| 262 |
63
|
} else if(TAG_COMPONENT_NAME.equals(qName)) { |
| 263 |
1
|
((Component) childModel).setName(getBuffer()); |
| 264 |
62
|
} else if(TAG_CONFIGURATION_VERSION.equals(qName)) { |
| 265 |
1
|
((SystemConfiguration) parentModel).setVersion(getBuffer()); |
| 266 |
61
|
} else if(TAG_CREATE_DATE.equals(qName)) { |
| 267 |
2
|
((Issue) parentModel).setCreateDate(getDateValue(getBuffer(), qName)); |
| 268 |
59
|
} else if(TAG_CREATOR.equals(qName)) { |
| 269 |
1
|
((Issue) parentModel).setCreator((User) findModel(getBuffer())); |
| 270 |
58
|
} else if(TAG_CUSTOM_FIELDS.equals(qName)) { |
| 271 |
2
|
List<CustomField> itemListArray = new ArrayList<CustomField>(); |
| 272 |
4
|
for(int i = 0; i < itemList.size(); i++) { |
| 273 |
2
|
itemListArray.add((CustomField) itemList.get(i)); |
| 274 |
|
} |
| 275 |
2
|
((SystemConfiguration) parentModel).setCustomFields(itemListArray); |
| 276 |
56
|
} else if(TAG_CUSTOM_FIELD_DATEFORMAT.equals(qName)) { |
| 277 |
1
|
((CustomField) childModel).setDateFormat(getBuffer()); |
| 278 |
55
|
} else if(TAG_CUSTOM_FIELD_LABEL.equals(qName)) { |
| 279 |
|
|
| 280 |
|
|
| 281 |
54
|
} else if(TAG_CUSTOM_FIELD_OPTION.equals(qName)) { |
| 282 |
2
|
((CustomField) childModel).addOption(tempStorage, getBuffer()); |
| 283 |
52
|
} else if(TAG_CUSTOM_FIELD_REQUIRED.equals(qName)) { |
| 284 |
1
|
((CustomField) childModel).setRequired(("true".equalsIgnoreCase(getBuffer()) ? true : false)); |
| 285 |
51
|
} else if(TAG_CUSTOM_FIELD_SORTOPTIONS.equals(qName)) { |
| 286 |
1
|
((CustomField) childModel).setSortOptionsByName(("true".equalsIgnoreCase(getBuffer()) ? true : false)); |
| 287 |
50
|
} else if(TAG_CUSTOM_FIELD_TYPE.equals(qName)) { |
| 288 |
2
|
((CustomField) childModel).setFieldType(CustomField.Type.valueOf(getBufferAsInt())); |
| 289 |
48
|
} else if(TAG_EMAIL.equals(qName)) { |
| 290 |
1
|
((User) parentModel).setEmail(getBuffer()); |
| 291 |
47
|
} else if(TAG_FIRST_NAME.equals(qName)) { |
| 292 |
1
|
((User) parentModel).setFirstName(getBuffer()); |
| 293 |
46
|
} else if(TAG_ISSUE_ATTACHMENTS.equals(qName)) { |
| 294 |
1
|
List<IssueAttachment> itemListArray = new ArrayList<IssueAttachment>(); |
| 295 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 296 |
1
|
itemListArray.add((IssueAttachment) itemList.get(i)); |
| 297 |
|
} |
| 298 |
1
|
((Issue) parentModel).setAttachments(itemListArray); |
| 299 |
45
|
} else if(TAG_ISSUE_ATTACHMENT_CREATOR.equals(qName)) { |
| 300 |
1
|
((IssueAttachment) childModel).setUser((User) findModel(getBuffer())); |
| 301 |
44
|
} else if(TAG_ISSUE_ATTACHMENT_DESCRIPTION.equals(qName)) { |
| 302 |
1
|
((IssueAttachment) childModel).setDescription(getBuffer()); |
| 303 |
43
|
} else if(TAG_ISSUE_ATTACHMENT_FILENAME.equals(qName)) { |
| 304 |
2
|
((IssueAttachment) childModel).setFileName(getBuffer()); |
| 305 |
41
|
} else if(TAG_ISSUE_ATTACHMENT_ORIGFILE.equals(qName)) { |
| 306 |
1
|
((IssueAttachment) childModel).setOriginalFileName(getBuffer()); |
| 307 |
40
|
} else if(TAG_ISSUE_ATTACHMENT_SIZE.equals(qName)) { |
| 308 |
2
|
((IssueAttachment) childModel).setSize(getBufferAsLong()); |
| 309 |
38
|
} else if(TAG_ISSUE_ATTACHMENT_TYPE.equals(qName)) { |
| 310 |
1
|
((IssueAttachment) childModel).setType(getBuffer()); |
| 311 |
37
|
} else if(TAG_ISSUE_COMPONENTS.equals(qName)) { |
| 312 |
1
|
List<Component> itemListArray = new ArrayList<Component>(); |
| 313 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 314 |
1
|
itemListArray.add((Component) itemList.get(i)); |
| 315 |
|
} |
| 316 |
1
|
((Issue) parentModel).setComponents(itemListArray); |
| 317 |
36
|
} else if(TAG_ISSUE_DESCRIPTION.equals(qName)) { |
| 318 |
1
|
((Issue) parentModel).setDescription(getBuffer()); |
| 319 |
35
|
} else if(TAG_ISSUE_FIELDS.equals(qName)) { |
| 320 |
1
|
List<IssueField> itemListArray = new ArrayList<IssueField>(); |
| 321 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 322 |
1
|
itemListArray.add(i,(IssueField) itemList.get(i)); |
| 323 |
|
} |
| 324 |
1
|
((Issue) parentModel).setFields(itemListArray); |
| 325 |
34
|
} else if(TAG_ISSUE_HISTORY.equals(qName)) { |
| 326 |
1
|
List<IssueHistory> itemListArray = new ArrayList<IssueHistory>(); |
| 327 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 328 |
1
|
itemListArray.add(i,(IssueHistory) itemList.get(i)); |
| 329 |
|
} |
| 330 |
1
|
((Issue) parentModel).setHistory(itemListArray); |
| 331 |
33
|
} else if(TAG_ISSUE_PROJECT.equals(qName)) { |
| 332 |
1
|
((Issue) parentModel).setProject((Project) findModel(getBuffer())); |
| 333 |
32
|
} else if(TAG_ISSUE_RESOLUTION.equals(qName)) { |
| 334 |
1
|
((Issue) parentModel).setResolution(getBuffer()); |
| 335 |
31
|
} else if(TAG_ISSUE_SEVERITY.equals(qName)) { |
| 336 |
1
|
((Issue) parentModel).setSeverity(getBufferAsInt()); |
| 337 |
30
|
} else if(TAG_ISSUE_STATUS.equals(qName)) { |
| 338 |
1
|
((Issue) parentModel).setStatus(getBufferAsInt()); |
| 339 |
29
|
} else if(TAG_ISSUE_VERSIONS.equals(qName)) { |
| 340 |
1
|
List<Version> itemListArray = new ArrayList<Version>(); |
| 341 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 342 |
1
|
itemListArray.add(i,(Version) itemList.get(i)); |
| 343 |
|
} |
| 344 |
1
|
((Issue) parentModel).setVersions(itemListArray); |
| 345 |
28
|
} else if(TAG_LAST_MODIFIED.equals(qName)) { |
| 346 |
1
|
((Issue) parentModel).setLastModifiedDate(getDateValue(getBuffer(), qName)); |
| 347 |
27
|
} else if(TAG_LAST_NAME.equals(qName)) { |
| 348 |
1
|
((User) parentModel).setLastName(getBuffer()); |
| 349 |
26
|
} else if(TAG_LOGIN.equals(qName)) { |
| 350 |
1
|
((User) parentModel).setLogin(getBuffer()); |
| 351 |
25
|
} else if(TAG_OWNER.equals(qName)) { |
| 352 |
1
|
((Issue) parentModel).setOwner((User) findModel(getBuffer())); |
| 353 |
24
|
} else if(TAG_PROJECT_NAME.equals(qName)) { |
| 354 |
1
|
((Project) parentModel).setName(getBuffer()); |
| 355 |
23
|
} else if(TAG_PROJECT_DESCRIPTION.equals(qName)) { |
| 356 |
1
|
((Project) parentModel).setDescription(getBuffer()); |
| 357 |
22
|
} else if(TAG_PROJECT_FIELDS.equals(qName)) { |
| 358 |
1
|
List<CustomField> itemListArray = new ArrayList<CustomField>(); |
| 359 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 360 |
1
|
itemListArray.add(i,(CustomField) itemList.get(i)); |
| 361 |
|
} |
| 362 |
1
|
((Project) parentModel).setCustomFields(itemListArray); |
| 363 |
21
|
} else if(TAG_PROJECT_FIELD_ID.equals(qName)) { |
| 364 |
1
|
itemList.add((CustomField) findModel(getBuffer())); |
| 365 |
20
|
} else if(TAG_PROJECT_OPTIONS.equals(qName)) { |
| 366 |
1
|
((Project) parentModel).setOptions(getBufferAsInt()); |
| 367 |
19
|
} else if(TAG_PROJECT_OWNERS.equals(qName)) { |
| 368 |
1
|
List<User> itemListArray = new ArrayList<User>(); |
| 369 |
2
|
for(int i = 0; i < itemList.size(); i++) { |
| 370 |
1
|
itemListArray.add(i,(User) itemList.get(i)); |
| 371 |
|
} |
| 372 |
1
|
((Project) parentModel).setOwners(itemListArray); |
| 373 |
18
|
} else if(TAG_PROJECT_OWNER_ID.equals(qName)) { |
| 374 |
1
|
itemList.add((User) findModel(getBuffer())); |
| 375 |
17
|
} else if(TAG_PROJECT_STATUS.equals(qName)) { |
| 376 |
|
|
| 377 |
1
|
((Project) parentModel).setStatus(Status.LOCKED); |
| 378 |
|
|
| 379 |
|
|
| 380 |
|
|
| 381 |
1
|
String currBuffer = getBuffer(); |
| 382 |
1
|
Map<Status, String> projectStatuses = ProjectUtilities.getStatusNames(EXPORT_LOCALE); |
| 383 |
5
|
for(Iterator<Status> iter = projectStatuses.keySet().iterator(); iter.hasNext(); ) { |
| 384 |
4
|
Status key = iter.next(); |
| 385 |
4
|
String keyValue = (String) projectStatuses.get(key); |
| 386 |
4
|
if(keyValue != null && keyValue.equalsIgnoreCase(currBuffer)) { |
| 387 |
0
|
((Project) parentModel).setStatus(key); |
| 388 |
0
|
break; |
| 389 |
|
} |
| 390 |
|
} |
| 391 |
16
|
} else if(TAG_SUPER_USER.equals(qName)) { |
| 392 |
1
|
((User) parentModel).setSuperUser(("true".equalsIgnoreCase(getBuffer()) ? true : false)); |
| 393 |
15
|
} else if(TAG_TARGET_VERSION_ID.equals(qName)) { |
| 394 |
1
|
((Issue) parentModel).setTargetVersion((Version) findModel(getBuffer())); |
| 395 |
14
|
} else if(TAG_USER_STATUS.equals(qName)) { |
| 396 |
|
|
| 397 |
1
|
((User) parentModel).setStatus(UserUtilities.STATUS_LOCKED); |
| 398 |
|
|
| 399 |
1
|
String currBuffer = getBuffer(); |
| 400 |
1
|
HashMap<String,String> userStatuses = UserUtilities.getStatusNames(EXPORT_LOCALE); |
| 401 |
4
|
for(Iterator<String> iter = userStatuses.keySet().iterator(); iter.hasNext(); ) { |
| 402 |
3
|
String key = (String) iter.next(); |
| 403 |
3
|
String keyValue = (String) userStatuses.get(key); |
| 404 |
3
|
if(keyValue != null && keyValue.equalsIgnoreCase(currBuffer)) { |
| 405 |
0
|
((User) parentModel).setStatus(Integer.parseInt(key)); |
| 406 |
0
|
break; |
| 407 |
|
} |
| 408 |
|
} |
| 409 |
13
|
} else if(TAG_VERSIONS.equals(qName)) { |
| 410 |
2
|
List<Version> itemListArray = new ArrayList<Version>(); |
| 411 |
5
|
for(int i = 0; i < itemList.size(); i++) { |
| 412 |
3
|
itemListArray.add(i,(Version) itemList.get(i)); |
| 413 |
|
} |
| 414 |
2
|
((Project) parentModel).setVersions(itemListArray); |
| 415 |
11
|
} else if(TAG_VERSION_DESCRIPTION.equals(qName)) { |
| 416 |
1
|
((Version) childModel).setDescription(getBuffer()); |
| 417 |
10
|
} else if(TAG_VERSION_ID.equals(qName)) { |
| 418 |
2
|
if(itemList == null) { |
| 419 |
0
|
itemList = new ArrayList<Object>(); |
| 420 |
|
} |
| 421 |
2
|
itemList.add((Version) findModel(getBuffer())); |
| 422 |
8
|
} else if(TAG_VERSION_NUMBER.equals(qName)) { |
| 423 |
1
|
((Version) childModel).setVersionInfo(getBuffer()); |
| 424 |
|
} |
| 425 |
|
} catch(RuntimeException e) { |
| 426 |
0
|
logger.debug("endElement: RuntimeException importing data.", e); |
| 427 |
0
|
endException = new SAXException("Error processing tag " + qName + ": " + e.getMessage()); |
| 428 |
0
|
throw endException; |
| 429 |
|
} catch (SAXException e) { |
| 430 |
3
|
logger.debug("endElement: SAXException importing data.", e); |
| 431 |
3
|
throw e; |
| 432 |
|
} catch (CloneNotSupportedException e) { |
| 433 |
0
|
logger.debug("endElement: CloneNotSupportedException importing data.", e); |
| 434 |
0
|
endException = new SAXException("Error processing tag " + qName + ": " + e.getMessage()); |
| 435 |
0
|
throw endException; |
| 436 |
|
} |
| 437 |
96
|
tagBuffer = null; |
| 438 |
|
} |
| 439 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 440 |
10
|
public void characters(char[] ch, int start, int length) {... |
| 441 |
10
|
logger.debug("Read " + ch.length + " Start: " + start + " Length: " + length); |
| 442 |
10
|
logger.debug("String: " + new String(ch, start, length)); |
| 443 |
10
|
if(tagBuffer != null) { |
| 444 |
10
|
tagBuffer.append(ITrackerResources.unescapeUnicodeString(new String(ch, start, length))); |
| 445 |
|
} |
| 446 |
|
} |
| 447 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 448 |
43
|
private String getBuffer() {... |
| 449 |
43
|
if(tagBuffer == null) { |
| 450 |
2
|
return ""; |
| 451 |
|
} else { |
| 452 |
41
|
return tagBuffer.toString(); |
| 453 |
|
} |
| 454 |
|
} |
| 455 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 456 |
5
|
private int getBufferAsInt() throws SAXException {... |
| 457 |
5
|
if(tagBuffer == null) { |
| 458 |
0
|
return -1; |
| 459 |
|
} else { |
| 460 |
5
|
try { |
| 461 |
5
|
return Integer.parseInt(tagBuffer.toString()); |
| 462 |
|
} catch(NumberFormatException nfe) { |
| 463 |
1
|
throw new SAXException("Could not convert string buffer to int value."); |
| 464 |
|
} |
| 465 |
|
} |
| 466 |
|
} |
| 467 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 468 |
2
|
private long getBufferAsLong() throws SAXException {... |
| 469 |
2
|
if(tagBuffer == null) { |
| 470 |
0
|
return -1; |
| 471 |
|
} else { |
| 472 |
2
|
try { |
| 473 |
2
|
return Long.parseLong(tagBuffer.toString()); |
| 474 |
|
} catch(NumberFormatException nfe) { |
| 475 |
1
|
throw new SAXException("Could not convert string buffer to long value."); |
| 476 |
|
} |
| 477 |
|
} |
| 478 |
|
} |
| 479 |
|
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 480 |
12
|
private AbstractEntity findModel(String itemTypeId) {... |
| 481 |
12
|
if(itemTypeId != null && ! itemTypeId.equals("")) { |
| 482 |
2
|
for(int i = 0; i < items.size(); i++) { |
| 483 |
2
|
AbstractEntity model = (AbstractEntity) items.get(i); |
| 484 |
2
|
if(getModelTypeIdString(model).equalsIgnoreCase(itemTypeId)) { |
| 485 |
2
|
return model; |
| 486 |
|
} |
| 487 |
|
} |
| 488 |
|
} |
| 489 |
10
|
logger.debug("Unable to find model id " + itemTypeId + " during import."); |
| 490 |
10
|
return null; |
| 491 |
|
} |
| 492 |
|
|
|
|
|
| 61.3% |
Uncovered Elements: 12 (31) |
Complexity: 9 |
Complexity Density: 0.53 |
|
| 493 |
2
|
private String getModelTypeIdString(AbstractEntity model) {... |
| 494 |
2
|
String idString = "UNKNOWN"; |
| 495 |
|
|
| 496 |
2
|
if(model != null && model.getId() != null) { |
| 497 |
2
|
String type = ""; |
| 498 |
2
|
if(model instanceof Component) { |
| 499 |
0
|
type = TAG_COMPONENT; |
| 500 |
2
|
} else if(model instanceof CustomField) { |
| 501 |
1
|
type = TAG_CUSTOM_FIELD; |
| 502 |
1
|
} else if(model instanceof Issue) { |
| 503 |
0
|
type = TAG_ISSUE; |
| 504 |
1
|
} else if(model instanceof Project) { |
| 505 |
0
|
type = TAG_PROJECT; |
| 506 |
1
|
} else if(model instanceof User) { |
| 507 |
1
|
type = TAG_USER; |
| 508 |
0
|
} else if(model instanceof Version) { |
| 509 |
0
|
type = TAG_VERSION; |
| 510 |
|
} |
| 511 |
|
|
| 512 |
2
|
idString = type + model.getId(); |
| 513 |
|
} |
| 514 |
|
|
| 515 |
2
|
return idString; |
| 516 |
|
} |
| 517 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 518 |
4
|
private Date getDateValue(String dateString, String qName) throws SAXException {... |
| 519 |
4
|
if(dateString == null || "".equals(dateString)) { |
| 520 |
2
|
return new Date(); |
| 521 |
|
} |
| 522 |
|
|
| 523 |
2
|
try { |
| 524 |
2
|
return DATE_FORMATTER.parse(dateString); |
| 525 |
|
} catch(Exception e) { |
| 526 |
1
|
throw new SAXException("Value in " + qName + " did not contain a valid date value."); |
| 527 |
|
} |
| 528 |
|
} |
| 529 |
|
} |