001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: * faycal.sougrati@francetelecom.com
023: */
024:
025: package salomeTMF_plug.bugzilla;
026:
027: import java.net.InetAddress;
028: import java.net.URL;
029: import java.net.URLEncoder;
030: import java.sql.Date;
031: import java.sql.PreparedStatement;
032: import java.sql.ResultSet;
033: import java.sql.Time;
034: import java.text.DateFormat;
035: import java.util.Locale;
036: import java.util.Vector;
037:
038: import javax.swing.JOptionPane;
039:
040: import org.objectweb.salome_tmf.api.Util;
041: import org.objectweb.salome_tmf.api.sql.IDataBase;
042: import org.objectweb.salome_tmf.data.Attachment;
043: import org.objectweb.salome_tmf.data.Environment;
044: import org.objectweb.salome_tmf.data.Execution;
045: import org.objectweb.salome_tmf.data.ExecutionResult;
046: import org.objectweb.salome_tmf.data.Project;
047: import org.objectweb.salome_tmf.data.Test;
048: import org.objectweb.salome_tmf.data.UrlAttachment;
049: import org.objectweb.salome_tmf.data.User;
050: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
051: import org.objectweb.salome_tmf.ihm.main.plugins.PluginsTools;
052: import org.objectweb.salome_tmf.plugins.core.BugTracker;
053:
054: import salomeTMF_plug.bugzilla.languages.Language;
055:
056: public class BugZillaTracker_2_20 extends BugZillaTracker {
057:
058: int product_id = -1;
059: int defComponetID = -1;
060: final static String ATTACH_DESC = "[BUGZILLA_2_20_ATTACH]";
061:
062: BugZillaTracker_2_20(IDataBase _iDB, String _bugzilla_host) {
063: super (_iDB, _bugzilla_host);
064: BUGZILLA_STMT_FILE = "/salomeTMF_plug/bugzilla/resources/sql/Bugzilla_Stmts_2_20.properties";
065: BUGZILLA_SUB_MENU = "Bugzilla-2.20";
066: }
067:
068: String getBugTrackerAttachDesc() {
069: return ATTACH_DESC;
070: }
071:
072: void init(User pUser, Project pProject) throws Exception {
073: currentUser = pUser;
074: currentProject = pProject;
075:
076: sql_prop = Util.getPropertiesFile(getClass().getResource(
077: BUGZILLA_STMT_FILE));
078: //Set bug user
079: String userEmail = pUser.getEmailFromModel();
080: ResultSet stmtRes = null;
081: PreparedStatement prep = iDB.prepareStatement(sql_prop
082: .getProperty("SelectUsrID"));
083: prep.setString(1, userEmail);
084: stmtRes = prep.executeQuery();
085: if (stmtRes.next()) {
086: Util.log("[BugzillaPlugin] Bugzilla connexion with user : "
087: + userEmail);
088: isCurrentUserExists = true;
089: bugUsrID = stmtRes.getInt("userid");
090: updateCookies(bugUsrID);
091: } else {
092: Util
093: .log("[BugzillaPlugin] Current user in Salomé doesn't exist in bugzilla DB : "
094: + userEmail);
095: isCurrentUserExists = false;
096: }
097: product_id = getProductID(currentProject.getNameFromModel());
098: }
099:
100: void addProject(Project project) throws Exception {
101: if (product_id > 0) {
102: return;
103: }
104:
105: if (!isCurrentUserExists) {
106: JOptionPane
107: .showMessageDialog(
108: SalomeTMFContext.getInstance()
109: .getSalomeFrame(),
110: Language
111: .getInstance()
112: .getText(
113: "creation_projet_avant_creation_utilisateur"),
114: Language.getInstance().getText(
115: "Information..."),
116: JOptionPane.INFORMATION_MESSAGE);
117: } else {
118: PreparedStatement prep = iDB.prepareStatement(sql_prop
119: .getProperty("SelectProductId"));
120: prep.setString(1, currentProject.getNameFromModel());
121: ResultSet stmtRes = prep.executeQuery();
122: if (stmtRes.next()) {
123: JOptionPane.showMessageDialog(SalomeTMFContext
124: .getInstance().getSalomeFrame(), Language
125: .getInstance().getText("Le_projet_\"")
126: + currentProject.getNameFromModel()
127: + Language.getInstance().getText(
128: "\"_existe_déjà _dans_Bugzilla"),
129: Language.getInstance()
130: .getText("Information..."),
131: JOptionPane.INFORMATION_MESSAGE);
132: } else {
133: // Adding Salomé TMF project to Bugzilla DB
134: int nbTrans = -1;
135: try {
136: nbTrans = SQLUtils.beginTrans();
137: prep = iDB.prepareStatement(sql_prop
138: .getProperty("AddNewProduct"));
139: prep
140: .setString(1, currentProject
141: .getNameFromModel());
142: prep.setString(2, currentProject
143: .getDescriptionFromModel());
144: prep.setString(3, "---");
145: prep.executeUpdate();
146:
147: product_id = getProductID(currentProject
148: .getNameFromModel());
149:
150: SQLUtils.commitTrans(nbTrans);
151: } catch (Exception e) {
152: e.printStackTrace();
153: SQLUtils.rollBackTrans(nbTrans);
154: throw e;
155: }
156:
157: try {
158: nbTrans = SQLUtils.beginTrans();
159: prep = iDB.prepareStatement(sql_prop
160: .getProperty("AddVersion"));
161: prep.setString(1, "Salome_Project");
162: prep.setInt(2, product_id);
163: prep.executeUpdate();
164: SQLUtils.commitTrans(nbTrans);
165: } catch (Exception e) {
166: e.printStackTrace();
167: SQLUtils.rollBackTrans(nbTrans);
168: throw e;
169: }
170:
171: try {
172: nbTrans = SQLUtils.beginTrans();
173: prep = iDB.prepareStatement(sql_prop
174: .getProperty("AddMilestones"));
175: prep.setInt(1, product_id);
176: prep.setString(2, "---");
177: prep.executeUpdate();
178: SQLUtils.commitTrans(nbTrans);
179: } catch (Exception e) {
180: e.printStackTrace();
181: SQLUtils.rollBackTrans(nbTrans);
182: throw e;
183: }
184:
185: // Adding default environment
186: nbTrans = -1;
187: try {
188: nbTrans = SQLUtils.beginTrans();
189: prep = iDB.prepareStatement(sql_prop
190: .getProperty("AddNewComponent"));
191: prep.setInt(1, product_id);
192: prep.setString(2, "___NO_ENV___");
193: prep.setString(3, "[SALOME_DEFAULT_ENVIRONMENT]");
194: prep.setInt(4, bugUsrID);
195: prep.setInt(5, 0);
196: prep.setInt(5, bugUsrID);
197: prep.executeUpdate();
198:
199: defComponetID = getComponetID("___NO_ENV___",
200: product_id);
201:
202: SQLUtils.commitTrans(nbTrans);
203: } catch (Exception e) {
204: e.printStackTrace();
205: SQLUtils.rollBackTrans(nbTrans);
206: throw e;
207: }
208:
209: afterAddProject(currentProject);
210:
211: }
212: }
213: }
214:
215: /*TODO*/
216: void addUser(User user) throws Exception {
217: if (isCurrentUserExists) {
218: JOptionPane.showMessageDialog(SalomeTMFContext
219: .getInstance().getSalomeFrame(), Language
220: .getInstance().getText("L'utilisateur_\"")
221: + currentUser.getLoginFromModel()
222: + Language.getInstance().getText(
223: "\"_existe_déjà _dans_Bugzilla"), Language
224: .getInstance().getText("Information..."),
225: JOptionPane.INFORMATION_MESSAGE);
226: } else {
227: int nbTrans = -1;
228:
229: try {
230: nbTrans = SQLUtils.beginTrans();
231: Util.log("[BugZillaTracker_2_20] add User "
232: + user.getEmailFromModel());
233: PreparedStatement prep = iDB.prepareStatement(sql_prop
234: .getProperty("AddNewBugUser"));
235: prep.setString(1, user.getEmailFromModel());
236: prep.setString(2, user.getFirstNameFromModel() + " "
237: + user.getLastNameFromModel());
238: prep.setString(3, "");
239: prep.executeUpdate();
240:
241: bugUsrID = getUserID(user.getEmailFromModel());
242: prep = iDB.prepareStatement(sql_prop
243: .getProperty("AddGroupMap"));
244: prep.setInt(1, bugUsrID);
245: prep.setInt(2, 8);
246: prep.setInt(3, 0);
247: prep.setInt(4, 2);
248: prep.executeUpdate();
249:
250: prep = iDB.prepareStatement(sql_prop
251: .getProperty("AddGroupMap"));
252: prep.setInt(1, bugUsrID);
253: prep.setInt(2, 9);
254: prep.setInt(3, 0);
255: prep.setInt(4, 2);
256: prep.executeUpdate();
257:
258: updateCookies(bugUsrID);
259: isCurrentUserExists = true;
260: JOptionPane
261: .showMessageDialog(
262: SalomeTMFContext.getInstance()
263: .getSalomeFrame(),
264: Language.getInstance().getText(
265: "utilisateur_added")
266: + "\n"
267: + Language
268: .getInstance()
269: .getText(
270: "vous_devez_quitter_Salomé_et_vous_reconnecter_pour\n")
271: + Language
272: .getInstance()
273: .getText(
274: "accéder_aux_fonctionnalités_concernées"),
275: Language.getInstance().getText(
276: "Information..."),
277: JOptionPane.INFORMATION_MESSAGE);
278:
279: SQLUtils.commitTrans(nbTrans);
280: } catch (Exception e) {
281: e.printStackTrace();
282: SQLUtils.rollBackTrans(nbTrans);
283: throw e;
284: }
285: }
286: }
287:
288: void addEnvironment(Environment environment) throws Exception {
289: if (product_id < 0) {
290: throw new Exception(
291: "[BugZillaTracker_2_20] Product not found");
292: }
293: int nbTrans = -1;
294: try {
295: nbTrans = SQLUtils.beginTrans();
296: PreparedStatement prep = iDB.prepareStatement(sql_prop
297: .getProperty("AddNewComponent"));
298: prep.setInt(1, product_id);
299: prep.setString(2, environment.getNameFromModel().trim());
300: prep.setString(3, environment.getDescriptionFromModel());
301: prep.setInt(4, bugUsrID);
302: prep.setInt(5, 0);
303: prep.setInt(5, bugUsrID);
304: prep.executeUpdate();
305: SQLUtils.commitTrans(nbTrans);
306: validateChange();
307: } catch (Exception e) {
308: e.printStackTrace();
309: SQLUtils.rollBackTrans(nbTrans);
310: throw e;
311: }
312: }
313:
314: void updateEnvironment(String old_component, String new_component,
315: String description) throws Exception {
316: if (product_id < 0) {
317: throw new Exception(
318: "[BugZillaTracker_2_20] Product not found");
319: }
320:
321: int nbTrans = -1;
322: try {
323: PreparedStatement prep;
324:
325: nbTrans = SQLUtils.beginTrans();
326: prep = iDB.prepareStatement(sql_prop
327: .getProperty("UpdateComponent"));
328: prep.setString(1, description);
329: prep.setString(2, new_component);
330: prep.setInt(3, product_id);
331: prep.setString(4, old_component);
332: prep.executeUpdate();
333: SQLUtils.commitTrans(nbTrans);
334: validateChange();
335:
336: } catch (Exception e) {
337: e.printStackTrace();
338: SQLUtils.rollBackTrans(nbTrans);
339: throw e;
340: }
341: }
342:
343: void deleteEnvironment(String environment) throws Exception {
344: if (product_id < 0) {
345: throw new Exception(
346: "[BugZillaTracker_2_20] Product not found");
347: }
348: int idComponent = getComponetID(environment.trim(), product_id);
349:
350: if (idComponent < 0) {
351: throw new Exception(
352: "[BugZillaTracker_2_20] Component not found");
353: }
354:
355: if (defComponetID < 0) {
356: defComponetID = getComponetID("___NO_ENV___", product_id);
357: }
358: if (defComponetID < 0) {
359: throw new Exception(
360: "[BugZillaTracker_2_20] Component not found");
361: }
362:
363: int nbTrans = -1;
364: try {
365:
366: PreparedStatement prep = iDB.prepareStatement(sql_prop
367: .getProperty("SelectBugOfComponent"));
368: prep.setInt(1, product_id);
369: prep.setInt(2, idComponent);
370: ResultSet stmtRes = prep.executeQuery();
371:
372: while (stmtRes.next()) {
373: nbTrans = SQLUtils.beginTrans();
374: prep = iDB.prepareStatement(sql_prop
375: .getProperty("UpdateComponentForBug"));
376: prep.setInt(1, defComponetID);
377: prep.setInt(2, idComponent);
378:
379: prep.executeUpdate();
380: SQLUtils.commitTrans(nbTrans);
381: }
382:
383: nbTrans = SQLUtils.beginTrans();
384: prep = iDB.prepareStatement(sql_prop
385: .getProperty("DeleteComponent"));
386: prep.setInt(1, idComponent);
387: prep.executeUpdate();
388:
389: SQLUtils.commitTrans(nbTrans);
390:
391: validateChange();
392: } catch (Exception e) {
393: e.printStackTrace();
394: SQLUtils.rollBackTrans(nbTrans);
395: throw e;
396: }
397: }
398:
399: Attachment addBug(String long_desc, String assigned_to,
400: String url_attach, String bug_severity, String short_desc,
401: String bug_OS, String bug_priority, String bug_platform,
402: Execution pExec, ExecutionResult pExecRes, Test ptest)
403: throws Exception {
404:
405: if (product_id == -1) {
406: JOptionPane.showMessageDialog(SalomeTMFContext
407: .getInstance().getSalomeFrame(), Language
408: .getInstance().getText("Must_create_project"),
409: "Error!", JOptionPane.ERROR_MESSAGE);
410: throw new Exception(
411: "[BugZillaTracker_2_20] Product not found");
412: }
413:
414: UrlAttachment bugURL = null;
415: Environment env = pExec.getEnvironmentFromModel();
416: if (env == null) {
417: throw new Exception(
418: "[BugZillaTracker] Can't add Bug to NULL Environment");
419: }
420: try {
421:
422: int envID = getComponetID(env.getNameFromModel().trim(),
423: product_id);
424: if (envID < 0) {
425: addEnvironment(env);
426: envID = getComponetID(env.getNameFromModel().trim(),
427: product_id);
428: }
429:
430: int assigned_to_ID = -1;
431: assigned_to_ID = bugUsrID;
432: try {
433: if (!(assigned_to == null) && !(assigned_to.equals(""))) {
434: ResultSet stmtRes;
435: PreparedStatement prep = iDB
436: .prepareStatement(sql_prop
437: .getProperty("SelectUsrID"));
438: prep.setString(1, assigned_to);
439: stmtRes = prep.executeQuery();
440: if (stmtRes.next()) {
441: assigned_to_ID = stmtRes.getInt("userid");
442: }
443: }
444: } catch (Exception e) {
445: }
446:
447: Date creation_ts = Util.getCurrentDate();
448: Locale locale = Locale.getDefault();
449: DateFormat dateFormat = DateFormat.getDateTimeInstance(
450: DateFormat.LONG, DateFormat.LONG, locale);
451: java.util.Date date = new java.util.Date();
452: String myDate = dateFormat.format(date);
453:
454: // Adding the bug
455: int nbTrans = -1;
456: try {
457: nbTrans = SQLUtils.beginTrans();
458: PreparedStatement prep = iDB.prepareStatement(sql_prop
459: .getProperty("AddBug"));
460: prep.setInt(1, assigned_to_ID);
461: prep.setString(2, url_attach);
462: prep.setString(3, bug_severity);
463: prep.setString(4, "NEW");
464: prep.setDate(5, creation_ts);
465: prep.setString(6, short_desc);
466: prep.setString(7, bug_OS);
467: prep.setString(8, bug_priority);
468: prep.setInt(9, product_id);
469: prep.setString(10, bug_platform);
470: prep.setInt(11, bugUsrID);
471: prep.setString(12, "Salome_Project");
472: prep.setInt(13, envID);
473: prep.setString(14, myDate);
474: prep.executeUpdate();
475: SQLUtils.commitTrans(nbTrans);
476: } catch (Exception e) {
477: e.printStackTrace();
478: SQLUtils.rollBackTrans(nbTrans);
479: throw e;
480: }
481:
482: // Shows the bug in Bugzilla
483: int bug_id = -1;
484: try {
485: PreparedStatement prep = iDB.prepareStatement(sql_prop
486: .getProperty("SelectBugID"));
487: prep.setString(1, short_desc);
488: prep.setInt(2, product_id);
489: prep.setInt(3, envID);
490: prep.setDate(4, creation_ts);
491: prep.setString(5, myDate);
492: ResultSet stmtRes = prep.executeQuery();
493: if (stmtRes.next()) {
494: bug_id = stmtRes.getInt("bug_id");
495: Util.log("[BugzillaPlugin]Add bug id = " + bug_id);
496: String url_res = bugzilla_host
497: + "/show_bug.cgi?id=" + bug_id;
498: bugURL = new UrlAttachment(url_res, ATTACH_DESC);
499: }
500: } catch (Exception E) {
501: E.printStackTrace();
502: }
503:
504: if (bug_id != -1) {
505: Util.log("[BugzillaPlugin] Bug_id : " + bug_id);
506: Util.log("[BugzillaPlugin] userID :"
507: + PluginsTools.getCurrentUser().getIdBdd());
508: Util.log("[BugzillaPlugin] creation time : "
509: + creation_ts);
510: Util.log("[BugzillaPlugin] description : " + long_desc);
511:
512: try {
513: nbTrans = SQLUtils.beginTrans();
514: PreparedStatement prep = iDB
515: .prepareStatement(sql_prop
516: .getProperty("AddDescToBUG"));
517: prep.setInt(1, bug_id);
518: prep.setInt(2, bugUsrID);
519: prep.setDate(3, creation_ts);
520: prep.setString(4, long_desc);
521: prep.executeUpdate();
522: SQLUtils.commitTrans(nbTrans);
523: } catch (Exception e) {
524: e.printStackTrace();
525: SQLUtils.rollBackTrans(nbTrans);
526: throw e;
527: }
528: }
529: validateChange();
530:
531: } catch (Exception e) {
532: e.printStackTrace();
533: throw e;
534: }
535:
536: return bugURL;
537: }
538:
539: String getBugID(Attachment pAttachment) {
540: String res = pAttachment.getNameFromModel();
541: int debut = res.lastIndexOf("id=");
542: if (debut > 0) {
543: try {
544: res = res.substring(debut + 3, res.length());
545: } catch (Exception e) {
546:
547: }
548:
549: }
550: return res;
551: }
552:
553: boolean isExistEnv(String projectName, String envName)
554: throws Exception {
555: if (getComponetID(envName, product_id) > 0) {
556: return true;
557: } else {
558: return false;
559: }
560: }
561:
562: void showEnvironmentBugs(Environment env) {
563:
564: String url_res = bugzilla_host
565: + "/buglist.cgi?query_format=advanced"
566: + "&short_desc_type=allwordssubstr&short_desc="
567: + "&product="
568: + URLEncoder.encode(currentProject.getNameFromModel())
569: + "&component="
570: + URLEncoder.encode(env.getNameFromModel())
571: +
572: //"&version=" +
573: "&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc="
574: + "&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED"
575: +
576:
577: "&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2="
578: + "&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Bug+Number&field0-0-0=noop&type0-0-0=noop&value0-0-0=";
579:
580: //String url_res = bugzilla_host + "/buglist.cgi?" +
581: //"short_desc_type=allwordssubstr&short_desc=" +
582: //&product=D%E9mo_04022006&component=eShopFree&long_desc_type=allwordssubstr&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&changedin=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&newqueryname=&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=
583: try {
584: //applet.getAppletContext().showDocument(new URL(url_res), getBugTrackerName());
585: SalomeTMFContext.getInstance().getBaseIHM().showDocument(
586: new URL(url_res), getBugTrackerName());
587: } catch (Exception e) {
588: e.printStackTrace();
589: }
590: }
591:
592: int getEnvironmentNbBugs(Environment env, int severity,
593: boolean onlyCorretedBugs) {
594: int res = 0;
595: String severity_str = "";
596: if (severity == BugTracker.CRITICAL) {
597: severity_str = BLOCKER_STR;
598: } else if (severity == BugTracker.MAJOR) {
599: severity_str = CRITICAL_STR;
600: }
601: if (product_id < 0) {
602: return 0;
603: }
604:
605: try {
606: ResultSet stmtRes;
607: int envID = getComponetID(env.getNameFromModel().trim(),
608: product_id);
609: if (envID < 0) {
610: return 0;
611: }
612: PreparedStatement prep;
613: if (onlyCorretedBugs) {
614: prep = iDB.prepareStatement(sql_prop
615: .getProperty("SelectCorretedBugsBySeverity"));
616: prep.setString(1, CORRECTED_STR);
617: prep.setString(2, severity_str);
618: prep.setInt(3, envID);
619: stmtRes = prep.executeQuery();
620: while (stmtRes.next()) {
621: res++;
622: }
623: } else {
624: prep = iDB.prepareStatement(sql_prop
625: .getProperty("SelectBugsBySeverity"));
626: prep.setString(1, severity_str);
627: prep.setInt(2, envID);
628: stmtRes = prep.executeQuery();
629: while (stmtRes.next()) {
630: res++;
631: }
632: }
633: } catch (Exception E) {
634: E.printStackTrace();
635: }
636:
637: return res;
638: }
639:
640: /***************************************************************************************************************************/
641:
642: Vector getBugOSList() {
643: Vector list = new Vector();
644:
645: try {
646: ResultSet stmtRes;
647: PreparedStatement prep = iDB.prepareStatement(sql_prop
648: .getProperty("SelectOS"));
649: stmtRes = prep.executeQuery();
650: while (stmtRes.next()) {
651: list.add(stmtRes.getString("value"));
652: }
653: } catch (Exception E) {
654: E.printStackTrace();
655: }
656:
657: return list;
658: }
659:
660: Vector getBugPriorityList() {
661: Vector list = new Vector();
662:
663: try {
664: ResultSet stmtRes;
665: PreparedStatement prep = iDB.prepareStatement(sql_prop
666: .getProperty("SelectBugPriority"));
667: stmtRes = prep.executeQuery();
668: while (stmtRes.next()) {
669: list.add(stmtRes.getString("value"));
670: }
671: } catch (Exception E) {
672: E.printStackTrace();
673: }
674:
675: return list;
676: }
677:
678: Vector getBugPlateformList() {
679: Vector list = new Vector();
680:
681: try {
682: ResultSet stmtRes;
683: PreparedStatement prep = iDB.prepareStatement(sql_prop
684: .getProperty("SelectBugsPlateform"));
685: stmtRes = prep.executeQuery();
686: while (stmtRes.next()) {
687: list.add(stmtRes.getString("value"));
688: }
689: } catch (Exception E) {
690: E.printStackTrace();
691: }
692:
693: return list;
694: }
695:
696: Vector getBugSeverityList() {
697: Vector list = new Vector();
698:
699: try {
700: ResultSet stmtRes;
701: PreparedStatement prep = iDB.prepareStatement(sql_prop
702: .getProperty("SelectBugSeverity"));
703: stmtRes = prep.executeQuery();
704: while (stmtRes.next()) {
705: list.add(stmtRes.getString("value"));
706: }
707: } catch (Exception E) {
708: E.printStackTrace();
709: }
710:
711: return list;
712: }
713:
714: /***********************************************************************************************/
715:
716: int getProductID(String name) throws Exception {
717: int pID = -1;
718: PreparedStatement prep = iDB.prepareStatement(sql_prop
719: .getProperty("SelectProductId"));
720: prep.setString(1, name);
721: ResultSet stmtRes = prep.executeQuery();
722: if (stmtRes.next()) {
723: pID = stmtRes.getInt("id");
724: }
725: return pID;
726: }
727:
728: int getUserID(String login) throws Exception {
729: int pID = -1;
730: PreparedStatement prep = iDB.prepareStatement(sql_prop
731: .getProperty("SelectBugUser"));
732: prep.setString(1, login);
733: ResultSet stmtRes = prep.executeQuery();
734: if (stmtRes.next()) {
735: pID = stmtRes.getInt("userid");
736: }
737: return pID;
738: }
739:
740: int getComponetID(String name, int idProduct) throws Exception {
741: int pID = -1;
742: PreparedStatement prep = iDB.prepareStatement(sql_prop
743: .getProperty("SelectComponentID"));
744: prep.setString(1, name);
745: prep.setInt(2, idProduct);
746: ResultSet stmtRes = prep.executeQuery();
747: if (stmtRes.next()) {
748: pID = stmtRes.getInt("id");
749: }
750: return pID;
751: }
752:
753: void updateCookies(int userID) throws Exception {
754: Date last_date = Util.getCurrentDate();
755: Time last_time = Util.getCurrentTime();
756: InetAddress this Ip = InetAddress.getLocalHost();
757: //System.out.println("IP:"+thisIp.getHostAddress());
758: PreparedStatement prep = iDB.prepareStatement(sql_prop
759: .getProperty("SelectCoookies"));
760: prep.setInt(1, userID);
761: prep.setString(2, this Ip.getHostAddress());
762: ResultSet stmtRes = prep.executeQuery();
763: if (stmtRes.next()) {
764: //Update
765: prep = iDB.prepareStatement(sql_prop
766: .getProperty("UpdateCoookies"));
767: prep.setString(1, last_date + " " + last_time);
768: prep.setInt(2, userID);
769: prep.setString(3, this Ip.getHostAddress());
770: prep.executeUpdate();
771: } else {
772: //create
773: prep = iDB.prepareStatement(sql_prop
774: .getProperty("AddCoookies"));
775: prep.setInt(1, userID);
776: prep.setString(2, this Ip.getHostAddress());
777: prep.setString(3, last_date + " " + last_time);
778: prep.executeUpdate();
779: }
780: }
781:
782: }
|