KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > bugzilla > Issue


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.bugs.bugzilla;
21
22 import java.io.*;
23 import java.net.URL JavaDoc;
24 import java.util.*;
25 import java.util.Date JavaDoc;
26
27 import javax.xml.parsers.SAXParserFactory JavaDoc;
28 import javax.xml.parsers.SAXParser JavaDoc;
29 import javax.xml.parsers.ParserConfigurationException JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32
33 /** Represents on issue in issuezilla.
34  * Created by {@link Issuezilla#getBug}
35  *
36  *
37  * tor@netbeans.org:
38  * This class is virtually identical to
39  * nbbuild/antsrc/org/netbeans/nbbuild/Issue.java
40  * At first, I inclouded its class file directly as part of
41  * the build. However, treating Issuezilla as a black box
42  * didn't work well because when connections fail (and are
43  * retried), or even during a query, there is no feedback - and
44  * since issuezilla is so slow, it's hard to know in the GUI
45  * that things are working. Therefore, I've modified the java
46  * file to give us a little bit more feedback.
47  * In CVS I stored the original file as the first revision,
48  * so you can easily diff to see what has changed - and generate
49  * a patch which you can then apply to an updated version
50  * of nbbuild/antsrc/ to keep the two in sync.
51  *
52  * serff@netbeans.org:
53  * This class is almost exactally the same as issuezilla.Issue, but modified to
54  * work with bugzilla. I didn't want to call this class Bug because of the
55  * higher level Bug class. If you can think of a better name, please let me know
56  *
57  * @todo think of a better name.
58  *
59  * @author Ivan Bradac, refactored by Jaroslav Tulach
60  */

61 public final class Issue extends Object JavaDoc implements Comparable JavaDoc {
62     //static final String ENHANCEMENT = "ENHANCEMENT";
63
static final String JavaDoc ISSUE_TYPE = "bug_severity";
64     static final String JavaDoc SHORT_DESC = "short_desc";
65     static final String JavaDoc LONG_DESC = "long_desc";
66     static final String JavaDoc COMMENT = "comment";
67     static final String JavaDoc ISSUE_ID = "bug_id";
68     static final String JavaDoc ISSUE_STATUS = "bug_status";
69     static final String JavaDoc RESOLUTION = "resolution";
70     static final String JavaDoc COMPONENT = "product";
71     static final String JavaDoc REPORTER = "reporter";
72     static final String JavaDoc VERSION = "version";
73     static final String JavaDoc SUBCOMPONENT = "component";
74     static final String JavaDoc REP_PLATFORM = "rep_platform";
75     static final String JavaDoc OP_SYS = "op_sys";
76     static final String JavaDoc PRIORITY = "priority";
77     static final String JavaDoc ASSIGNED_TO = "assigned_to";
78 // static final String CC = "cc";
79
// static final String DEPENDS_ON = "dependson";
80
// static final String BLOCKS = "blocks";
81
static final String JavaDoc CREATED = "creation_ts";
82 // static final String VOTES = "votes";
83
// static final String KEYWORDS = "keywords";
84

85     /** The target milestone attribute name. */
86     static final String JavaDoc TARGET_MILESTONE = "target_milestone";
87
88     /** Name of the attribute containing the long_desc as a list */
89     static final String JavaDoc LONG_DESC_LIST = "long_desc_list";
90
91     private HashMap attributes = new HashMap (49);
92
93
94     /**
95      * Gets the id as an Integer.
96      *
97      * @return the issue_id as
98      */

99     public int getId() {
100         Object JavaDoc id = getAttribute(ISSUE_ID);
101         try {
102             return Integer.parseInt ((String JavaDoc) id);
103         } catch (Exception JavaDoc ex) {
104             return -1;
105         }
106     }
107
108     /** Who is assigned to this bug.
109      * @return name of person assigned to this bug
110      */

111     public String JavaDoc getAssignedTo () {
112         return string (ASSIGNED_TO);
113     }
114
115     /** Who reported the bug.
116      * @return name of the reporter
117      */

118     public String JavaDoc getReportedBy () {
119         return string (REPORTER);
120     }
121     
122     /** Everyone who is interested in the issue.
123      * @return array of names or empty array if nobody is
124      */

125     public String JavaDoc[] getObservedBy () {
126 // java.util.List l = (java.util.List)getAttribute (CC);
127
// if (l != null) {
128
// return (String[])l.toArray (new String[0]);
129
// } else {
130
return new String JavaDoc[0];
131 // }
132
}
133
134     /** Status of the bug, verified, etc.
135      * @return textual name of the status.
136      */

137     public String JavaDoc getStatus () {
138         return string (ISSUE_STATUS);
139     }
140
141     /** Resolution: Fixed, etc...
142      * @return textual name of resolution.
143      */

144     public String JavaDoc getResolution () {
145         return string (RESOLUTION);
146     }
147
148     /** Type of the issue: Bug, Enhancement, Task, etc...
149      * @return textual name of issue type
150      */

151     public String JavaDoc getType () {
152         return string (ISSUE_TYPE);
153     }
154
155     /** Priority of the issue.
156      * @return integer describing priority, -1 if unknown
157      */

158     public int getPriority () {
159         String JavaDoc s = string (PRIORITY);
160         if (s.length () == 2 && s.charAt (0) == 'P') {
161             return s.charAt (1) - '0';
162         } else {
163             return -1;
164         }
165     }
166     
167     /** A time when this issue has been created.
168      * @return the date or begining of epoch if wrongly defined
169      */

170     public Date JavaDoc getCreated () {
171         Date JavaDoc d = (Date JavaDoc)getAttribute (CREATED);
172         return d == null ? new Date JavaDoc (0) : d;
173     }
174     
175     /** The summary or short description of the bug.
176      * @return string
177      */

178     public String JavaDoc getSummary () {
179         return string (SHORT_DESC);
180     }
181
182     /** Getter of descriptions.
183      * @return array of descriptions
184      */

185     public Description[] getDescriptions () {
186         Object JavaDoc obj = getAttribute(LONG_DESC_LIST);
187         if (obj == null) {
188             return new Description[0];
189         }
190
191         return (Description[])((List)obj).toArray (new Description[0]);
192     }
193     
194     /** A list of bugs that depends on this one.
195      * @return array of integer numbers of those bugs or empty array
196      */

197 // public int[] getDependsOn () {
198
// return ints (DEPENDS_ON);
199
// }
200

201     /** A list of bugs that this issue blocks.
202      * @return array of integer numbers of those bugs or empty array
203      */

204 // public int[] getBlocks () {
205
// return ints (BLOCKS);
206
// }
207

208     /** Name of the milestone this issue should be resolved in.
209      * @return string name
210      */

211     public String JavaDoc getTargetMilestone () {
212         return string (TARGET_MILESTONE);
213     }
214     
215     /** Name of the component this issue belongs to.
216      * @return string name
217      */

218     public String JavaDoc getComponent () {
219         return string (COMPONENT);
220     }
221     
222     /** Name of subcomponent this issue belongs to.
223      * @return string name
224      */

225     public String JavaDoc getSubcomponent () {
226         return string (SUBCOMPONENT);
227     }
228     
229     /** Number of votes for given component.
230      * @return integer representing number of votes or 0 is no votes present
231      */

232 // public int getVotes () {
233
// try {
234
// String s = string (VOTES);
235
// return Integer.parseInt (s);
236
// } catch (Exception ex) {
237
// return 0;
238
// }
239
// }
240

241     /** All keywords of the issue.
242      * @return Keywords deliminated by comma or empty string
243      */

244 // public String getKeywords () {
245
// try {
246
// return string (KEYWORDS);
247
// } catch (Exception ex) {
248
// return "";
249
// }
250
// }
251

252     /** Check if the this issue has the specified keyword
253      * @return <code>true</code> if specified keyword is set in this issue,
254      * otherwise <code>false</code>.
255      */

256 // public boolean containsKeyword (String keyword) {
257
// StringTokenizer tokenizer = new StringTokenizer(getKeywords());
258
// while (tokenizer.hasMoreTokens()) {
259
// String current = tokenizer.nextToken();
260
// if (current.equals(keyword))
261
// return true;
262
// }
263
// return false;
264
// }
265

266     /** Is this bug actually an enhancement?
267      * @return <CODE>true</CODE> if this is enhancement, <CODE>false</CODE> otherwise
268      *
269     public boolean isEnhancement() {
270         if (attributes == null) {
271             return false;
272         }
273         String s = (String) getAttribute(ISSUE_TYPE);
274         return (s == null) ? false : s.equals(ENHANCEMENT);
275     }
276      */

277
278     /** Getter to return string for given attribute.
279      */

280     private String JavaDoc string (String JavaDoc name) {
281         Object JavaDoc o = getAttribute (name);
282         return o instanceof String JavaDoc ? (String JavaDoc)o : "";
283     }
284     
285     /** Getter for array of integers.
286      */

287     private int[] ints (String JavaDoc name) {
288         List l = (List)getAttribute (name);
289         if (l == null) {
290             return new int[0];
291         }
292         
293         int[] arr = new int[l.size ()];
294         for (int i = 0; i < arr.length; i++) {
295             arr[i] = Integer.parseInt ((String JavaDoc)l.get (i));
296         }
297         return arr;
298     }
299
300     /** Package private getter, it is expected to add getter for useful
301      * issues.
302      */

303     Object JavaDoc getAttribute(String JavaDoc name) {
304         if (name.equals(LONG_DESC)) {
305             return formatLongDescriptions();
306         } else {
307             return attributes.get(name);
308         }
309     }
310
311
312     /** Setter of values, package private. */
313     void setAttribute(String JavaDoc name, Object JavaDoc value) {
314         attributes.put(name, value);
315     }
316
317     /**
318      * Gets the name/value pairs of the bug attributes as a Map.
319      *
320      * @return the name/value pairs of the attributes
321      */

322     private Map attributes() {
323         return attributes;
324     }
325
326     /** Converts the object to textual representation.
327      * @return a text description of the issue
328      */

329     public String JavaDoc toString() {
330         StringBuffer JavaDoc buffer;
331         if (attributes == null) {
332             return "Empty BugBase";
333         }
334         Iterator it = attributes.entrySet().iterator();
335         buffer = new StringBuffer JavaDoc();
336         buffer.append(this.getClass().getName()
337                       + " containing these name/value attribute pairs:\n");
338         while (it.hasNext()) {
339             Map.Entry entry = (Map.Entry) it.next();
340             buffer.append("NAME : " + entry.getKey() + "\n");
341             buffer.append("VALUE : " + entry.getValue() + "\n");
342         }
343         return buffer.toString();
344     }
345
346     /** Compares issues by their ID
347      */

348     public int compareTo (Object JavaDoc o) {
349         Issue i = (Issue)o;
350         return getId () - i.getId ();
351     }
352
353     /**
354      * Formats the list of long_desc's into one String
355      *
356      * @return the long descriptions in one String
357      */

358     private String JavaDoc formatLongDescriptions() {
359         if (attributes.get (Issue.LONG_DESC) == null) {
360             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("");
361             Object JavaDoc obj = getAttribute(LONG_DESC_LIST);
362             List descriptions;
363             if (obj == null) {
364                 return null;
365             }
366             descriptions = (List) obj;
367             Iterator it = descriptions.iterator();
368             while (it.hasNext()) {
369                 Description ld = (Description) it.next();
370                 buffer.append(ld.toString());
371             }
372             attributes.put (LONG_DESC, buffer.toString());
373         }
374         return attributes.get (LONG_DESC).toString();
375     }
376     
377
378
379     /**
380      * Long description of Issues.
381      */

382     public final static class Description {
383         static final String JavaDoc WHO = "who";
384         static final String JavaDoc ISSUE_WHEN = "bug_when";
385         static final String JavaDoc BODY = "thetext";
386         static final String JavaDoc THETEXT = "thetext";
387
388         /** Holds value of property who. */
389         private String JavaDoc who;
390
391         /** Holds value of property issue_when. */
392         private Date JavaDoc when;
393
394         /** Holds value of property thetext. */
395         private String JavaDoc body;
396
397         /** Name of the author of the issue.
398          * @return Value of property who.
399          */

400         public String JavaDoc getWho() {
401             return who;
402         }
403
404         /** Setter for property who.
405          * @param who New value of property who.
406          */

407         void setWho(String JavaDoc who) {
408             this.who = who;
409         }
410
411         /** When this comment has been added.
412          * @return Value of property issue_when.
413          */

414         public java.util.Date JavaDoc getWhen() {
415             return when;
416         }
417
418         /** Setter for property issue_when.
419          * @param issue_when New value of property issue_when.
420          */

421         void setIssueWhen(Date JavaDoc when) {
422             this.when = when;
423         }
424
425         /** The actual text of the issue.
426          * @return Value of property thetext.
427          */

428         public String JavaDoc getBody() {
429             return body;
430         }
431
432         /** Textual description.
433          * @return string representation of the description.
434          */

435         public String JavaDoc toString() {
436             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
437             buffer.append(getWho());
438             buffer.append(", ");
439             buffer.append(getWhen());
440             buffer.append(" : \n");
441             buffer.append(getBody());
442             buffer.append("\n\n");
443             return buffer.toString();
444         }
445
446
447
448
449
450
451
452
453
454
455
456         /** Setter for property thetext.
457          * @param thetext New value of property thetext.
458          */

459         void setBody(String JavaDoc body) {
460             this.body = body;
461         }
462
463         void setAtribute(String JavaDoc name, String JavaDoc value) {
464             if (name.equalsIgnoreCase(WHO)) {
465                 setWho(value);
466             } else if (name.equalsIgnoreCase(BODY)
467                     || name.equalsIgnoreCase(THETEXT)) {
468                 setBody(value);
469             }
470         }
471
472         private String JavaDoc getAttribute(String JavaDoc name) {
473             if (name.equalsIgnoreCase(WHO)) {
474                 return who;
475             } else if (name.equalsIgnoreCase(BODY)
476                     || name.equalsIgnoreCase(THETEXT)) {
477                 return body;
478             } else {
479                 return null;
480             }
481         }
482
483     }
484     
485 }
486
Popular Tags