Class: Projects::Parser::BugParser

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/projects/parser/BugParser.rb

Overview

  • Parse the JSON response into respective objects.

Instance Method Summary collapse

Instance Method Details

#getBug(response) ⇒ Object



48
49
50
51
52
# File 'lib/projects/parser/BugParser.rb', line 48

def getBug(response)
	bug_json = JSON.parse response
	bug_array = bug_json["bugs"]
	return jsonToBug(bug_array[0])
end

#getBugs(response) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/projects/parser/BugParser.rb', line 26

def getBugs(response)
	bugs_all_json = JSON.parse response
	bugs_all_array = bugs_all_json["bugs"]
	bugs_class_array = Array.new
	for i in 0...bugs_all_array.length
		bugs_class_array.push(jsonToBug(bugs_all_array[i]))
	end
	return bugs_class_array
end

#getCustomfields(response) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/projects/parser/BugParser.rb', line 324

def getCustomfields(response)

	jsonObject = JSON.parse response
	
	customFields = Array.new
	
	if jsonObject.has_key?("customfields")
	
		customfields = jsonObject["customfields"]
		
		for i in 0...customfields.length
		
			customFields.push(jsonToCustomfield(customfields[i]))
			
		end
		
	end
	
	return customFields

end

#getDefaultFields(response) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/projects/parser/BugParser.rb', line 204

def getDefaultFields(response)

	jsonObject = JSON.parse response
	
	defaultField = Defaultfield.new
	
	if jsonObject.has_key?("defaultfields")
	
		defaultFields = jsonObject["defaultfields"]
	
		if defaultFields.has_key?("severity_details")
	
			severitydetails = defaultFields["severity_details"]
			
			severityDetails = Array.new
		
			for i in 0...severitydetails.length
		
				severityDetails.push(jsonToHash(severity_details[i]))
			end
			
			defaultField.setSeverityDetails(severityDetails)
		end
		
		if defaultFields.has_key?("status_deatils")
		
			statusdeatils = defaultFields["status_deatils"]
			
			statusDeatils = Array.new
			
			for i in 0...statusdeatils.length
			
				statusDeatils.push(jsonToHash(statusdeatils[i]))
				
			end
			
			defaultField.setStatusDeatils(statusDeatils)
		end
		
		if defaultFields.has_key?("module_details")
		
			moduledetails = defaultFields["module_details"]
			
			moduleDetails = Array.new
			
			for i in 0...moduledetails.length
			
				moduleDetails.push(jsonToHash(moduledetails[i]))
				
			end
			
			defaultField.setModuleDetails(moduleDetails)
		end
		
		if defaultFields.has_key?("priority_details")
		
			prioritydetails = defaultFields["priority_details"]
			
			priorityDetails = Array.new
			
			for i in 0...prioritydetails.length
			
				priorityDetails.push(jsonToHash(prioritydetails[i]))
				
			end
			
			defaultField.setPriorityDetails(priorityDetails)
		end
		
		if defaultFields.has_key?("classification_details")
		
			classificationdetails = defaultFields["classification_details"]
			
			classificationDetails = Array.new
			
			for i in 0...classificationdetails.length
			
				classificationDetails.push(jsonToHash(classificationdetails[i]))
				
			end
			
			defaultField.setClassificationDetails(classificationDetails)
		end
		
	end
	
	return defaultField
end

#getResult(response) ⇒ Object

  • Parse the JSON response and get the success message.

Parameters

  • response
    • This JSON response contains the success message.

Returns

  • String object.



410
411
412
413
414
# File 'lib/projects/parser/BugParser.rb', line 410

def getResult(response)
	jsonObject = JSON.parse response
	result = jsonObject["response"]
	return result
end

#jsonToBug(jsonObject) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/projects/parser/BugParser.rb', line 65

def jsonToBug(jsonObject)
	bug = Bug.new
	
	if jsonObject.has_key?("id")
		bug.setId(jsonObject["id"])
	end
	if jsonObject.has_key?("key")
		bug.setKey(jsonObject["key"])
	end
	
	if jsonObject.has_key?("project")
		bug.setProjectId(jsonObject["project"]["id"])
	end
	
	if jsonObject.has_key?("flag")
		bug.setFlag(jsonObject["flag"])
	end
	if jsonObject.has_key?("title")
		bug.setTitle(jsonObject["title"])
	end
	if jsonObject.has_key?("description")
		bug.setDescription(jsonObject["description"])
	end
	if jsonObject.has_key?("reporter_id")
		bug.setReporterId(jsonObject["reporter_id"])
	end
	if jsonObject.has_key?("reported_person")
		bug.setReportedPerson(jsonObject["reported_person"])
	end
	if jsonObject.has_key?("created_time")
		bug.setCreatedTime(jsonObject["created_time"])
	end
	if jsonObject.has_key?("created_time_format")
		bug.setCreatedTimeFormat(jsonObject["created_time_format"])
	end
	if jsonObject.has_key?("created_time_long")
		bug.setCreatedTimeLong(jsonObject["created_time_long"])
	end
	if jsonObject.has_key?("assignee_id")
		bug.setAssigneeId(jsonObject["assignee_id"])
	end
	if jsonObject.has_key?("assignee_name")
		bug.setAssigneeName(jsonObject["assignee_name"])
	end
	if jsonObject.has_key?("closed")	
		bug.setClosed(jsonObject["closed"])
	end
	if jsonObject.has_key?("due_date")
		bug.setDueDate(jsonObject["due_date"])
	end
	if jsonObject.has_key?("due_date_format")
		bug.setDueDateFormat(jsonObject["due_date_format"])
	end
	if jsonObject.has_key?("due_date_long")
		bug.setDueDateLong(jsonObject["due_date_long"])
	end
	
	
	if jsonObject.has_key?("classification")
		classification = jsonObject["classification"]
		
		if classification.has_key?("id")
			bug.setClassificationId(classification["id"])
		end
		if classification.has_key?("type")
			bug.setClassificationType(classification["type"])
		end
	end
	
	if jsonObject.has_key?("severity")
		severity = jsonObject["severity"]
		
		if severity.has_key?("id")
			bug.setSeverityId(severity["id"])
		end
		if severity.has_key?("type")
			bug.setSeverityType(severity["type"])
		end
	end
	
	if jsonObject.has_key?("status")
		status = jsonObject["status"]
		
		if status.has_key?("id")
			bug.setStatusId(status["id"])
		end
		if status.has_key?("type")
			bug.setStatusType(status["type"])
		end
	end
	
	if jsonObject.has_key?("reproducible")
		reproducible = jsonObject["reproducible"]
		
		if reproducible.has_key?("id")
			bug.setReproducibleId(reproducible["id"])
		end
		if reproducible.has_key?("type")
			bug.setReproducibleType(reproducible["type"])
		end
	end
	
	if jsonObject.has_key?("module")
		mod = jsonObject["module"]
		
		if mod.has_key?("id")
			bug.setModuleId(mod["id"])
		end
		if mod.has_key?("name")
			bug.setModuleName(mod["name"])
		end
	end
	
	if jsonObject.has_key?("link")
		link = jsonObject["link"]
		
		if link.has_key?("self")
			bug.setURL(link["self"]["url"])
		end
		
		if link.has_key?("timesheet")
			bug.setTimesheetURL(link["timesheet"]["url"])
		end
	end
	
	return bug
end

#jsonToCustomfield(jsonObject) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/projects/parser/BugParser.rb', line 357

def jsonToCustomfield(jsonObject)

	customfield = Customfield.new
	
	if jsonObject.has_key?("label_name")
	
		customfield.setLabelName(jsonObject["label_name"])
	
	end
	
	if jsonObject.has_key?("column_name")
	
		customfield.setColumnName(jsonObject["column_name"])
	
	end
		
	if jsonObject.has_key?("default_Value")
	
		customfield.setDefaultValue(jsonObject["default_Value"])
	
	end
		
	if jsonObject.has_key?("picklist_values")
	
		picklistValues = Array.new
		
		picklistvalues = jsonObject["picklist_values"]
		
		for i in 0...picklistvalues.length
		
			picklistValues.push(picklistvalues[i])
	
		end	
				
		customfield.setPicklistValues(picklistValues)
	
	end	
	
	return customfield
	
end

#jsonToHash(jsonObject) ⇒ Object



305
306
307
308
309
310
# File 'lib/projects/parser/BugParser.rb', line 305

def jsonToHash(jsonObject)

	hash = JSON.parse(jsonObject)	
	
	return hash
end