|
Lines 22-31
Link Here
|
| 22 |
import java.net.URL; |
22 |
import java.net.URL; |
| 23 |
import java.net.URLConnection; |
23 |
import java.net.URLConnection; |
| 24 |
import java.net.URLEncoder; |
24 |
import java.net.URLEncoder; |
| 25 |
import java.security.KeyManagementException; |
|
|
| 26 |
import java.security.NoSuchAlgorithmException; |
| 27 |
import java.util.ArrayList; |
25 |
import java.util.ArrayList; |
| 28 |
import java.util.HashMap; |
26 |
import java.util.HashMap; |
|
|
27 |
import java.util.LinkedHashMap; |
| 29 |
import java.util.List; |
28 |
import java.util.List; |
| 30 |
|
29 |
|
| 31 |
import javax.security.auth.login.LoginException; |
30 |
import javax.security.auth.login.LoginException; |
|
Lines 51-57
Link Here
|
| 51 |
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BugzillaServerVersion; |
50 |
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BugzillaServerVersion; |
| 52 |
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser; |
51 |
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser; |
| 53 |
import org.eclipse.mylar.internal.bugzilla.core.internal.BugReportElement; |
52 |
import org.eclipse.mylar.internal.bugzilla.core.internal.BugReportElement; |
| 54 |
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser; |
|
|
| 55 |
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile; |
53 |
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile; |
| 56 |
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration; |
54 |
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration; |
| 57 |
import org.eclipse.mylar.internal.bugzilla.core.internal.ServerConfigurationFactory; |
55 |
import org.eclipse.mylar.internal.bugzilla.core.internal.ServerConfigurationFactory; |
|
Lines 69-74
Link Here
|
| 69 |
*/ |
67 |
*/ |
| 70 |
public class BugzillaRepositoryUtil { |
68 |
public class BugzillaRepositoryUtil { |
| 71 |
|
69 |
|
|
|
70 |
private static final String BUG_STATUS_NEW = "NEW"; |
| 71 |
|
| 72 |
private static final String ATTACHMENT_DOWNLOAD_FAILED = "Attachment download FAILED."; |
72 |
private static final String ATTACHMENT_DOWNLOAD_FAILED = "Attachment download FAILED."; |
| 73 |
|
73 |
|
| 74 |
private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual"; |
74 |
private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual"; |
|
Lines 229-336
Link Here
|
| 229 |
|
229 |
|
| 230 |
} |
230 |
} |
| 231 |
|
231 |
|
| 232 |
/** |
232 |
// /** |
| 233 |
* Get the attribute values for a new bug |
233 |
// * Get the attribute values for a new bug |
| 234 |
* |
234 |
// * |
| 235 |
* @param nbm |
235 |
// * @param nbm |
| 236 |
* A reference to a NewBugModel to store all of the data |
236 |
// * A reference to a NewBugModel to store all of the data |
| 237 |
* @throws Exception |
237 |
// * @throws Exception |
| 238 |
*/ |
238 |
// */ |
| 239 |
public static void setupNewBugAttributes(String serverUrl, NewBugModel nbm, boolean getProd) throws Exception { |
239 |
// public static void setupNewBugAttributes(String serverUrl, NewBugModel |
| 240 |
BufferedReader in = null; |
240 |
// nbm, boolean getProd) throws Exception { |
| 241 |
try { |
241 |
// BufferedReader in = null; |
| 242 |
// create a new input stream for getting the bug |
242 |
// try { |
| 243 |
String prodname = URLEncoder.encode(nbm.getProduct(), BugzillaPlugin.ENCODING_UTF_8); |
243 |
// // create a new input stream for getting the bug |
| 244 |
|
244 |
// String prodname = URLEncoder.encode(nbm.getProduct(), |
| 245 |
TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository( |
245 |
// BugzillaPlugin.ENCODING_UTF_8); |
| 246 |
BugzillaPlugin.REPOSITORY_KIND, serverUrl); |
246 |
// |
| 247 |
|
247 |
// TaskRepository repository = |
| 248 |
if (repository == null) { |
248 |
// MylarTaskListPlugin.getRepositoryManager().getRepository( |
| 249 |
throw new LoginException("Repository configuration error."); |
249 |
// BugzillaPlugin.REPOSITORY_KIND, serverUrl); |
| 250 |
} |
250 |
// |
| 251 |
if (repository.getUserName() == null || repository.getUserName().trim().equals("") |
251 |
// if (repository == null) { |
| 252 |
|| repository.getPassword() == null) { |
252 |
// throw new LoginException("Repository configuration error."); |
| 253 |
throw new LoginException("Login credentials missing."); |
253 |
// } |
| 254 |
} |
254 |
// if (repository.getUserName() == null || |
| 255 |
|
255 |
// repository.getUserName().trim().equals("") |
| 256 |
String url = repository.getUrl() + "/enter_bug.cgi"; |
256 |
// || repository.getPassword() == null) { |
| 257 |
|
257 |
// throw new LoginException("Login credentials missing."); |
| 258 |
// use the proper url if we dont know the product yet |
258 |
// } |
| 259 |
if (!getProd) |
259 |
// |
| 260 |
url += "?product=" + prodname + "&"; |
260 |
// String url = repository.getUrl() + "/enter_bug.cgi"; |
| 261 |
else |
261 |
// |
| 262 |
url += "?"; |
262 |
// // use the proper url if we dont know the product yet |
| 263 |
|
263 |
// if (!getProd) |
| 264 |
url += POST_ARGS_LOGIN + URLEncoder.encode(repository.getUserName(), BugzillaPlugin.ENCODING_UTF_8) |
264 |
// url += "?product=" + prodname + "&"; |
| 265 |
+ POST_ARGS_PASSWORD + URLEncoder.encode(repository.getPassword(), BugzillaPlugin.ENCODING_UTF_8); |
265 |
// else |
| 266 |
|
266 |
// url += "?"; |
| 267 |
URL bugUrl = new URL(url); |
267 |
// |
| 268 |
URLConnection cntx = BugzillaPlugin.getDefault().getUrlConnection(bugUrl); |
268 |
// url += POST_ARGS_LOGIN + URLEncoder.encode(repository.getUserName(), |
| 269 |
if (cntx != null) { |
269 |
// BugzillaPlugin.ENCODING_UTF_8) |
| 270 |
InputStream input = cntx.getInputStream(); |
270 |
// + POST_ARGS_PASSWORD + URLEncoder.encode(repository.getPassword(), |
| 271 |
if (input != null) { |
271 |
// BugzillaPlugin.ENCODING_UTF_8); |
| 272 |
in = new BufferedReader(new InputStreamReader(input)); |
272 |
// |
| 273 |
|
273 |
// URL bugUrl = new URL(url); |
| 274 |
new NewBugParser(in).parseBugAttributes(nbm, getProd); |
274 |
// URLConnection cntx = |
| 275 |
} |
275 |
// BugzillaPlugin.getDefault().getUrlConnection(bugUrl); |
| 276 |
} |
276 |
// if (cntx != null) { |
| 277 |
|
277 |
// InputStream input = cntx.getInputStream(); |
| 278 |
} catch (Exception e) { |
278 |
// if (input != null) { |
| 279 |
|
279 |
// in = new BufferedReader(new InputStreamReader(input)); |
| 280 |
if (e instanceof KeyManagementException || e instanceof NoSuchAlgorithmException |
280 |
// |
| 281 |
|| e instanceof IOException) { |
281 |
// new NewBugParser(in).parseBugAttributes(nbm, getProd); |
| 282 |
if (MessageDialog.openQuestion(null, "Bugzilla Connect Error", |
282 |
// } |
| 283 |
"Unable to connect to Bugzilla server.\n" |
283 |
// } |
| 284 |
+ "Bug report will be created offline and saved for submission later.")) { |
284 |
// |
| 285 |
nbm.setConnected(false); |
285 |
// } catch (Exception e) { |
| 286 |
setupBugAttributes(serverUrl, nbm); |
286 |
// |
| 287 |
} else |
287 |
// if (e instanceof KeyManagementException || e instanceof |
| 288 |
throw new Exception("Bug report will not be created."); |
288 |
// NoSuchAlgorithmException |
| 289 |
} else |
289 |
// || e instanceof IOException) { |
| 290 |
throw e; |
290 |
// if (MessageDialog.openQuestion(null, "Bugzilla Connect Error", |
| 291 |
} finally { |
291 |
// "Unable to connect to Bugzilla server.\n" |
| 292 |
try { |
292 |
// + "Bug report will be created offline and saved for submission later.")) |
| 293 |
if (in != null) |
293 |
// { |
| 294 |
in.close(); |
294 |
// nbm.setConnected(false); |
| 295 |
} catch (IOException e) { |
295 |
// setupBugAttributes(serverUrl, nbm); |
| 296 |
BugzillaPlugin.log(new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.ERROR, |
296 |
// } else |
| 297 |
"Problem closing the stream", e)); |
297 |
// throw new Exception("Bug report will not be created."); |
| 298 |
} |
298 |
// } else |
| 299 |
} |
299 |
// throw e; |
| 300 |
} |
300 |
// } finally { |
|
|
301 |
// try { |
| 302 |
// if (in != null) |
| 303 |
// in.close(); |
| 304 |
// } catch (IOException e) { |
| 305 |
// BugzillaPlugin.log(new Status(IStatus.ERROR, |
| 306 |
// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR, |
| 307 |
// "Problem closing the stream", e)); |
| 308 |
// } |
| 309 |
// } |
| 310 |
// } |
| 301 |
|
311 |
|
| 302 |
/** |
312 |
/** |
| 303 |
* Adds bug attributes to new bug model and sets defaults |
313 |
* Adds bug attributes to new bug model and sets defaults |
| 304 |
*/ |
314 |
*/ |
| 305 |
public static void setupBugAttributes(String serverUrl, NewBugModel model) { |
315 |
public static void setupBugAttributes(String serverUrl, NewBugModel model) { |
| 306 |
|
316 |
|
| 307 |
HashMap<String, Attribute> attributes = new HashMap<String, Attribute>(); |
317 |
// // order is important |
| 308 |
|
318 |
// BugReportElement[] newBugElements = { BugReportElement.PRODUCT, |
| 309 |
Attribute a = new Attribute(BugReportElement.BUG_SEVERITY.toString()); |
319 |
// BugReportElement.BUG_STATUS, |
| 310 |
a.setParameterName(BugReportElement.BUG_SEVERITY.getKeyString()); |
320 |
// BugReportElement.VERSION, |
| 311 |
List<String> optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getSeverities(); |
321 |
// BugReportElement.COMPONENT, |
| 312 |
for (String option : optionValues) { |
322 |
// BugReportElement.TARGET_MILESTONE, |
| 313 |
a.addOptionValue(option, option); |
323 |
// BugReportElement.REP_PLATFORM, |
| 314 |
} |
324 |
// BugReportElement.OP_SYS, |
| 315 |
a.setValue(optionValues.get((optionValues.size() / 2))); |
325 |
// BugReportElement.PRIORITY, |
| 316 |
attributes.put(a.getName(), a); |
326 |
// BugReportElement.BUG_SEVERITY, |
|
|
327 |
// BugReportElement.ASSIGNED_TO, |
| 328 |
//// NOT USED BugReportElement.CC, |
| 329 |
// BugReportElement.BUG_FILE_LOC, |
| 330 |
// //NOT USED BugReportElement.SHORT_DESC, |
| 331 |
// //NOT USED BugReportElement.LONG_DESC |
| 332 |
// }; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
HashMap<String, Attribute> attributes = new LinkedHashMap<String, Attribute>(); |
| 317 |
|
338 |
|
| 318 |
a = new Attribute(BugReportElement.OP_SYS.toString()); |
339 |
Attribute a = new Attribute(BugReportElement.PRODUCT.toString()); |
| 319 |
a.setParameterName(BugReportElement.OP_SYS.getKeyString()); |
340 |
a.setParameterName(BugReportElement.PRODUCT.getKeyString()); |
| 320 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getOSs(); |
341 |
List<String> optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getProducts(); |
| 321 |
for (String option : optionValues) { |
342 |
for (String option : optionValues) { |
| 322 |
a.addOptionValue(option, option); |
343 |
a.addOptionValue(option, option); |
| 323 |
} |
344 |
} |
|
|
345 |
a.setValue(model.getProduct()); |
| 324 |
attributes.put(a.getName(), a); |
346 |
attributes.put(a.getName(), a); |
| 325 |
|
347 |
|
| 326 |
a = new Attribute(BugReportElement.REP_PLATFORM.toString()); |
348 |
|
| 327 |
a.setParameterName(BugReportElement.REP_PLATFORM.getKeyString()); |
349 |
a = new Attribute(BugReportElement.BUG_STATUS.toString()); |
| 328 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getPlatforms(); |
350 |
a.setParameterName(BugReportElement.BUG_STATUS.getKeyString()); |
|
|
351 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getStatusValues(); |
| 329 |
for (String option : optionValues) { |
352 |
for (String option : optionValues) { |
| 330 |
a.addOptionValue(option, option); |
353 |
a.addOptionValue(option, option); |
| 331 |
} |
354 |
} |
|
|
355 |
a.setValue(BUG_STATUS_NEW); |
| 332 |
attributes.put(a.getName(), a); |
356 |
attributes.put(a.getName(), a); |
| 333 |
|
357 |
|
| 334 |
a = new Attribute(BugReportElement.VERSION.toString()); |
358 |
a = new Attribute(BugReportElement.VERSION.toString()); |
| 335 |
a.setParameterName(BugReportElement.VERSION.getKeyString()); |
359 |
a.setParameterName(BugReportElement.VERSION.getKeyString()); |
| 336 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getVersions(model.getProduct()); |
360 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getVersions(model.getProduct()); |
|
Lines 339-345
Link Here
|
| 339 |
} |
363 |
} |
| 340 |
a.setValue(optionValues.get(optionValues.size() - 1)); |
364 |
a.setValue(optionValues.get(optionValues.size() - 1)); |
| 341 |
attributes.put(a.getName(), a); |
365 |
attributes.put(a.getName(), a); |
| 342 |
|
366 |
|
| 343 |
a = new Attribute(BugReportElement.COMPONENT.toString()); |
367 |
a = new Attribute(BugReportElement.COMPONENT.toString()); |
| 344 |
a.setParameterName(BugReportElement.COMPONENT.getKeyString()); |
368 |
a.setParameterName(BugReportElement.COMPONENT.getKeyString()); |
| 345 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getComponents(model.getProduct()); |
369 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getComponents(model.getProduct()); |
|
Lines 347-352
Link Here
|
| 347 |
a.addOptionValue(option, option); |
371 |
a.addOptionValue(option, option); |
| 348 |
} |
372 |
} |
| 349 |
attributes.put(a.getName(), a); |
373 |
attributes.put(a.getName(), a); |
|
|
374 |
|
| 375 |
a = new Attribute(BugReportElement.REP_PLATFORM.toString()); |
| 376 |
a.setParameterName(BugReportElement.REP_PLATFORM.getKeyString()); |
| 377 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getPlatforms(); |
| 378 |
for (String option : optionValues) { |
| 379 |
a.addOptionValue(option, option); |
| 380 |
} |
| 381 |
attributes.put(a.getName(), a); |
| 382 |
|
| 383 |
a = new Attribute(BugReportElement.OP_SYS.toString()); |
| 384 |
a.setParameterName(BugReportElement.OP_SYS.getKeyString()); |
| 385 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getOSs(); |
| 386 |
for (String option : optionValues) { |
| 387 |
a.addOptionValue(option, option); |
| 388 |
} |
| 389 |
attributes.put(a.getName(), a); |
| 350 |
|
390 |
|
| 351 |
a = new Attribute(BugReportElement.PRIORITY.toString()); |
391 |
a = new Attribute(BugReportElement.PRIORITY.toString()); |
| 352 |
a.setParameterName(BugReportElement.PRIORITY.getKeyString()); |
392 |
a.setParameterName(BugReportElement.PRIORITY.getKeyString()); |
|
Lines 357-378
Link Here
|
| 357 |
a.setValue(optionValues.get((optionValues.size() / 2))); |
397 |
a.setValue(optionValues.get((optionValues.size() / 2))); |
| 358 |
attributes.put(a.getName(), a); |
398 |
attributes.put(a.getName(), a); |
| 359 |
|
399 |
|
| 360 |
a = new Attribute(BugReportElement.PRODUCT.toString()); |
400 |
a = new Attribute(BugReportElement.BUG_SEVERITY.toString()); |
| 361 |
a.setParameterName(BugReportElement.PRODUCT.getKeyString()); |
401 |
a.setParameterName(BugReportElement.BUG_SEVERITY.getKeyString()); |
| 362 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getProducts(); |
402 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getSeverities(); |
| 363 |
for (String option : optionValues) { |
403 |
for (String option : optionValues) { |
| 364 |
a.addOptionValue(option, option); |
404 |
a.addOptionValue(option, option); |
| 365 |
} |
405 |
} |
|
|
406 |
a.setValue(optionValues.get((optionValues.size() / 2))); |
| 366 |
attributes.put(a.getName(), a); |
407 |
attributes.put(a.getName(), a); |
| 367 |
|
408 |
|
| 368 |
a = new Attribute(BugReportElement.BUG_STATUS.toString()); |
409 |
a = new Attribute(BugReportElement.TARGET_MILESTONE.toString()); |
| 369 |
a.setParameterName(BugReportElement.BUG_STATUS.getKeyString()); |
410 |
a.setParameterName(BugReportElement.TARGET_MILESTONE.getKeyString()); |
| 370 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getStatusValues(); |
411 |
optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(model.getProduct()); |
| 371 |
for (String option : optionValues) { |
412 |
for (String option : optionValues) { |
| 372 |
a.addOptionValue(option, option); |
413 |
a.addOptionValue(option, option); |
| 373 |
} |
414 |
} |
| 374 |
attributes.put(a.getName(), a); |
415 |
attributes.put(a.getName(), a); |
| 375 |
|
416 |
|
|
|
417 |
a = new Attribute(BugReportElement.ASSIGNED_TO.toString()); |
| 418 |
a.setParameterName(BugReportElement.ASSIGNED_TO.getKeyString()); |
| 419 |
a.setValue(""); |
| 420 |
attributes.put(a.getName(), a); |
| 421 |
|
| 422 |
a = new Attribute(BugReportElement.BUG_FILE_LOC.toString()); |
| 423 |
a.setParameterName(BugReportElement.BUG_FILE_LOC.getKeyString()); |
| 424 |
a.setValue("http://"); |
| 425 |
attributes.put(a.getName(), a); |
| 426 |
|
| 376 |
model.attributes = attributes; |
427 |
model.attributes = attributes; |
| 377 |
} |
428 |
} |
| 378 |
|
429 |
|