KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > issuezilla > 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.issuezilla;
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  *
53  * @author Ivan Bradac, refactored by Jaroslav Tulach
54  */

55 public final class Issue extends Object JavaDoc implements Comparable JavaDoc {
56     //static final String ENHANCEMENT = "ENHANCEMENT";
57
static final String JavaDoc ISSUE_TYPE = "issue_type";
58     static final String JavaDoc SHORT_DESC = "short_desc";
59     static final String JavaDoc LONG_DESC = "long_desc";
60     static final String JavaDoc COMMENT = "comment";
61     static final String JavaDoc ISSUE_ID = "issue_id";
62     static final String JavaDoc ISSUE_STATUS = "issue_status";
63     static final String JavaDoc RESOLUTION = "resolution";
64     static final String JavaDoc COMPONENT = "component";
65     static final String JavaDoc REPORTER = "reporter";
66     static final String JavaDoc VERSION = "version";
67     static final String JavaDoc SUBCOMPONENT = "subcomponent";
68     static final String JavaDoc REP_PLATFORM = "rep_platform";
69     static final String JavaDoc OP_SYS = "op_sys";
70     static final String JavaDoc PRIORITY = "priority";
71     static final String JavaDoc ASSIGNED_TO = "assigned_to";
72     static final String JavaDoc CC = "cc";
73     static final String JavaDoc DEPENDS_ON = "dependson";
74     static final String JavaDoc BLOCKS = "blocks";
75     static final String JavaDoc CREATED = "creation_ts";
76     static final String JavaDoc VOTES = "votes";
77     static final String JavaDoc KEYWORDS = "keywords";
78     
79     /** The target milestone attribute name. */
80     static final String JavaDoc TARGET_MILESTONE = "target_milestone";
81
82     /** Name of the attribute containing the long_desc as a list */
83     static final String JavaDoc LONG_DESC_LIST = "long_desc_list";
84
85     private HashMap attributes = new HashMap (49);
86
87
88     /**
89      * Gets the id as an Integer.
90      *
91      * @return the issue_id as
92      */

93     public int getId() {
94         Object JavaDoc id = getAttribute(ISSUE_ID);
95         try {
96             return Integer.parseInt ((String JavaDoc) id);
97         } catch (Exception JavaDoc ex) {
98             return -1;
99         }
100     }
101
102     /** Who is assigned to this bug.
103      * @return name of person assigned to this bug
104      */

105     public String JavaDoc getAssignedTo () {
106         return string (ASSIGNED_TO);
107     }
108
109     /** Who reported the bug.
110      * @return name of the reporter
111      */

112     public String JavaDoc getReportedBy () {
113         return string (REPORTER);
114     }
115     
116     /** Everyone who is interested in the issue.
117      * @return array of names or empty array if nobody is
118      */

119     public String JavaDoc[] getObservedBy () {
120         java.util.List JavaDoc l = (java.util.List JavaDoc)getAttribute (CC);
121         if (l != null) {
122             return (String JavaDoc[])l.toArray (new String JavaDoc[0]);
123         } else {
124             return new String JavaDoc[0];
125         }
126     }
127
128     /** Status of the bug, verified, etc.
129      * @return textual name of the status.
130      */

131     public String JavaDoc getStatus () {
132         return string (ISSUE_STATUS);
133     }
134
135     /** Resolution: Fixed, etc...
136      * @return textual name of resolution.
137      */

138     public String JavaDoc getResolution () {
139         return string (RESOLUTION);
140     }
141
142     /** Type of the issue: Bug, Enhancement, Task, etc...
143      * @return textual name of issue type
144      */

145     public String JavaDoc getType () {
146         return string (ISSUE_TYPE);
147     }
148
149     /** Priority of the issue.
150      * @return integer describing priority, -1 if unknown
151      */

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

164     public Date JavaDoc getCreated () {
165         Date JavaDoc d = (Date JavaDoc)getAttribute (CREATED);
166         return d == null ? new Date JavaDoc (0) : d;
167     }
168     
169     /** The summary or short description of the bug.
170      * @return string
171      */

172     public String JavaDoc getSummary () {
173         return string (SHORT_DESC);
174     }
175
176     /** Getter of descriptions.
177      * @return array of descriptions
178      */

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

191     public int[] getDependsOn () {
192         return ints (DEPENDS_ON);
193     }
194     
195     /** A list of bugs that this issue blocks.
196      * @return array of integer numbers of those bugs or empty array
197      */

198     public int[] getBlocks () {
199         return ints (BLOCKS);
200     }
201     
202     /** Name of the milestone this issue should be resolved in.
203      * @return string name
204      */

205     public String JavaDoc getTargetMilestone () {
206         return string (TARGET_MILESTONE);
207     }
208     
209     /** Name of the component this issue belongs to.
210      * @return string name
211      */

212     public String JavaDoc getComponent () {
213         return string (COMPONENT);
214     }
215     
216     /** Name of subcomponent this issue belongs to.
217      * @return string name
218      */

219     public String JavaDoc getSubcomponent () {
220         return string (SUBCOMPONENT);
221     }
222     
223     /** Number of votes for given component.
224      * @return integer representing number of votes or 0 is no votes present
225      */

226     public int getVotes () {
227         try {
228             String JavaDoc s = string (VOTES);
229             return Integer.parseInt (s);
230         } catch (Exception JavaDoc ex) {
231             return 0;
232         }
233     }
234
235     /** All keywords of the issue.
236      * @return Keywords deliminated by comma or empty string
237      */

238     public String JavaDoc getKeywords () {
239         try {
240             return string (KEYWORDS);
241         } catch (Exception JavaDoc ex) {
242             return "";
243         }
244     }
245     
246     /** Check if the this issue has the specified keyword
247      * @return <code>true</code> if specified keyword is set in this issue,
248      * otherwise <code>false</code>.
249      */

250     public boolean containsKeyword (String JavaDoc keyword) {
251         StringTokenizer tokenizer = new StringTokenizer(getKeywords());
252         while (tokenizer.hasMoreTokens()) {
253             String JavaDoc current = tokenizer.nextToken();
254             if (current.equals(keyword))
255                 return true;
256         }
257         return false;
258     }
259     
260     /** Is this bug actually an enhancement?
261      * @return <CODE>true</CODE> if this is enhancement, <CODE>false</CODE> otherwise
262      *
263     public boolean isEnhancement() {
264         if (attributes == null) {
265             return false;
266         }
267         String s = (String) getAttribute(ISSUE_TYPE);
268         return (s == null) ? false : s.equals(ENHANCEMENT);
269     }
270      */

271
272     /** Getter to return string for given attribute.
273      */

274     private String JavaDoc string (String JavaDoc name) {
275         Object JavaDoc o = getAttribute (name);
276         return o instanceof String JavaDoc ? (String JavaDoc)o : "";
277     }
278     
279     /** Getter for array of integers.
280      */

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

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

316     private Map attributes() {
317         return attributes;
318     }
319
320     /** Converts the object to textual representation.
321      * @return a text description of the issue
322      */

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

342     public int compareTo (Object JavaDoc o) {
343         Issue i = (Issue)o;
344         return getId () - i.getId ();
345     }
346
347     /**
348      * Formats the list of long_desc's into one String
349      *
350      * @return the long descriptions in one String
351      */

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

376     public final static class Description {
377         static final String JavaDoc WHO = "who";
378         static final String JavaDoc ISSUE_WHEN = "issue_when";
379         static final String JavaDoc BODY = "body";
380         static final String JavaDoc THETEXT = "thetext";
381
382         /** Holds value of property who. */
383         private String JavaDoc who;
384
385         /** Holds value of property issue_when. */
386         private Date JavaDoc when;
387
388         /** Holds value of property thetext. */
389         private String JavaDoc body;
390
391         /** Name of the author of the issue.
392          * @return Value of property who.
393          */

394         public String JavaDoc getWho() {
395             return who;
396         }
397
398         /** Setter for property who.
399          * @param who New value of property who.
400          */

401         void setWho(String JavaDoc who) {
402             this.who = who;
403         }
404
405         /** When this comment has been added.
406          * @return Value of property issue_when.
407          */

408         public java.util.Date JavaDoc getWhen() {
409             return when;
410         }
411
412         /** Setter for property issue_when.
413          * @param issue_when New value of property issue_when.
414          */

415         void setIssueWhen(Date JavaDoc when) {
416             this.when = when;
417         }
418
419         /** The actual text of the issue.
420          * @return Value of property thetext.
421          */

422         public String JavaDoc getBody() {
423             return body;
424         }
425
426         /** Textual description.
427          * @return string representation of the description.
428          */

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

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