KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > 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.nbbuild;
21
22 import java.io.*;
23 import java.util.*;
24 import java.util.Date JavaDoc;
25
26 /** Represents on issue in issuezilla.
27  * Created by {@link Issuezilla#getBug}
28  *
29  * @author Ivan Bradac, refactored by Jaroslav Tulach
30  */

31 public final class Issue extends Object JavaDoc implements Comparable JavaDoc {
32     //static final String ENHANCEMENT = "ENHANCEMENT";
33
static final String JavaDoc ISSUE_TYPE = "issue_type";
34     static final String JavaDoc SHORT_DESC = "short_desc";
35     static final String JavaDoc LONG_DESC = "long_desc";
36     static final String JavaDoc COMMENT = "comment";
37     static final String JavaDoc ISSUE_ID = "issue_id";
38     static final String JavaDoc ISSUE_STATUS = "issue_status";
39     static final String JavaDoc RESOLUTION = "resolution";
40     static final String JavaDoc COMPONENT = "component";
41     static final String JavaDoc REPORTER = "reporter";
42     static final String JavaDoc VERSION = "version";
43     static final String JavaDoc SUBCOMPONENT = "subcomponent";
44     static final String JavaDoc REP_PLATFORM = "rep_platform";
45     static final String JavaDoc OP_SYS = "op_sys";
46     static final String JavaDoc PRIORITY = "priority";
47     static final String JavaDoc ASSIGNED_TO = "assigned_to";
48     static final String JavaDoc CC = "cc";
49     static final String JavaDoc DEPENDS_ON = "dependson";
50     static final String JavaDoc BLOCKS = "blocks";
51     static final String JavaDoc CREATED = "creation_ts";
52     static final String JavaDoc VOTES = "votes";
53     static final String JavaDoc KEYWORDS = "keywords";
54     static final String JavaDoc STATUS_WHITEBOARD = "status_whiteboard";
55     
56     /** The target milestone attribute name. */
57     static final String JavaDoc TARGET_MILESTONE = "target_milestone";
58
59     /** Name of the attribute containing the long_desc as a list */
60     static final String JavaDoc LONG_DESC_LIST = "long_desc_list";
61
62     private Map<String JavaDoc,Object JavaDoc> attributes = new HashMap<String JavaDoc,Object JavaDoc>(49);
63
64
65     /**
66      * Gets the id as an Integer.
67      *
68      * @return the issue_id as
69      */

70     public int getId() {
71         Object JavaDoc id = getAttribute(ISSUE_ID);
72         try {
73             return Integer.parseInt ((String JavaDoc) id);
74         } catch (Exception JavaDoc ex) {
75             return -1;
76         }
77     }
78
79     /** Who is assigned to this bug.
80      * @return name of person assigned to this bug
81      */

82     public String JavaDoc getAssignedTo () {
83         return string (ASSIGNED_TO);
84     }
85
86     /** Who reported the bug.
87      * @return name of the reporter
88      */

89     public String JavaDoc getReportedBy () {
90         return string (REPORTER);
91     }
92     
93     /** Everyone who is interested in the issue.
94      * @return array of names or empty array if nobody is
95      */

96     public String JavaDoc[] getObservedBy () {
97         List<?> l = (List<?>) getAttribute (CC);
98         if (l != null) {
99             return l.toArray(new String JavaDoc[0]);
100         } else {
101             return new String JavaDoc[0];
102         }
103     }
104
105     /** Status of the bug, verified, etc.
106      * @return textual name of the status.
107      */

108     public String JavaDoc getStatus () {
109         return string (ISSUE_STATUS);
110     }
111
112     /** Resolution: Fixed, etc...
113      * @return textual name of resolution.
114      */

115     public String JavaDoc getResolution () {
116         return string (RESOLUTION);
117     }
118
119     /** Type of the issue: Bug, Enhancement, Task, etc...
120      * @return textual name of issue type
121      */

122     public String JavaDoc getType () {
123         return string (ISSUE_TYPE);
124     }
125
126     /** Priority of the issue.
127      * @return integer describing priority, -1 if unknown
128      */

129     public int getPriority () {
130         String JavaDoc s = string (PRIORITY);
131         if (s.length () == 2 && s.charAt (0) == 'P') {
132             return s.charAt (1) - '0';
133         } else {
134             return -1;
135         }
136     }
137     
138     /** A time when this issue has been created.
139      * @return the date or begining of epoch if wrongly defined
140      */

141     public Date JavaDoc getCreated () {
142         Date JavaDoc d = (Date JavaDoc)getAttribute (CREATED);
143         return d == null ? new Date JavaDoc (0) : d;
144     }
145     
146     /** The summary or short description of the bug.
147      * @return string
148      */

149     public String JavaDoc getSummary () {
150         return string (SHORT_DESC);
151     }
152
153     /** Getter of descriptions.
154      * @return array of descriptions
155      */

156     public Description[] getDescriptions () {
157         Object JavaDoc obj = getAttribute(LONG_DESC_LIST);
158         if (obj == null) {
159             return new Description[0];
160         }
161
162         return ((List<?>) obj).toArray(new Description[0]);
163     }
164     
165     /** A list of bugs that depends on this one.
166      * @return array of integer numbers of those bugs or empty array
167      */

168     public int[] getDependsOn () {
169         return ints (DEPENDS_ON);
170     }
171     
172     /** A list of bugs that this issue blocks.
173      * @return array of integer numbers of those bugs or empty array
174      */

175     public int[] getBlocks () {
176         return ints (BLOCKS);
177     }
178     
179     /** Name of the milestone this issue should be resolved in.
180      * @return string name
181      */

182     public String JavaDoc getTargetMilestone () {
183         return string (TARGET_MILESTONE);
184     }
185     
186     /** Name of the component this issue belongs to.
187      * @return string name
188      */

189     public String JavaDoc getComponent () {
190         return string (COMPONENT);
191     }
192     
193     /** Name of subcomponent this issue belongs to.
194      * @return string name
195      */

196     public String JavaDoc getSubcomponent () {
197         return string (SUBCOMPONENT);
198     }
199
200     /**
201      * @deprecated Use <code>getWhiteboardAttribute("duration")</code> instead.
202      */

203     @Deprecated JavaDoc
204     public String JavaDoc getDuration () {
205         String JavaDoc val = getWhiteboardAttribute("duration");
206         return val == null ? "" : val;
207     }
208
209     /**
210      * Get status white board attribute. Status whiteboard attributes
211      * are convetionally defined in form <tt>name:WORD=value:WORD</tt> e.g.
212      * <tt>duration=50</tt> or <tt>lines=1000</tt>.
213      * @param attribute name
214      * @return token representing attribute value or <code>null</code>
215      */

216     public final String JavaDoc getWhiteboardAttribute(String JavaDoc attribute) {
217         String JavaDoc ret = null;
218         String JavaDoc swb = string (STATUS_WHITEBOARD);
219         StringTokenizer st = new StringTokenizer (swb);
220         while (st.hasMoreTokens()) {
221             String JavaDoc token = st.nextToken();
222             if ( token.startsWith (attribute + '=') ) {
223                 ret = token.substring (token.indexOf ('=') + 1);
224                 break;
225             }
226         }
227         return ret;
228     }
229
230     /** Number of votes for given component.
231      * @return integer representing number of votes or 0 is no votes present
232      */

233     public int getVotes () {
234         try {
235             String JavaDoc s = string (VOTES);
236             return Integer.parseInt (s);
237         } catch (Exception JavaDoc ex) {
238             return 0;
239         }
240     }
241
242     /** All keywords of the issue.
243      * @return Keywords deliminated by comma or empty string
244      */

245     public String JavaDoc getKeywords () {
246         try {
247             return string (KEYWORDS);
248         } catch (Exception JavaDoc ex) {
249             return "";
250         }
251     }
252     
253     /** Check if the this issue has the specified keyword
254      * @return <code>true</code> if specified keyword is set in this issue,
255      * otherwise <code>false</code>.
256      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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