KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > domain > Item


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package info.jtrac.domain;
18
19 import java.util.LinkedHashSet JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23 import org.apache.lucene.document.Document;
24
25 /**
26  * This object represents a generic item which can be an issue, defect, task etc.
27  * some logic for field accessors and conversion of keys to display values
28  * is contained in the AbstractItem class
29  */

30 public class Item extends AbstractItem {
31
32     private Integer JavaDoc type;
33     private Space space;
34     private long sequenceNum;
35     
36     private Set JavaDoc<History> history;
37     private Set JavaDoc<Item> children;
38     private Set JavaDoc<Attachment> attachments;
39
40     @Override JavaDoc
41     public String JavaDoc getRefId() {
42         return getSpace().getPrefixCode() + "-" + sequenceNum;
43     }
44     
45     public Map JavaDoc<Integer JavaDoc, String JavaDoc> getPermittedTransitions(User user) {
46         return user.getPermittedTransitions(space, getStatus());
47     }
48     
49     public List JavaDoc<Field> getEditableFieldList(User user) {
50         return user.getEditableFieldList(space, getStatus());
51     }
52     
53     public void add(History h) {
54         if (this.history == null) {
55             this.history = new LinkedHashSet JavaDoc<History>();
56         }
57         h.setParent(this);
58         this.history.add(h);
59     }
60     
61     public void add(Attachment attachment) {
62         if (attachments == null) {
63             attachments = new LinkedHashSet JavaDoc<Attachment>();
64         }
65         attachments.add(attachment);
66     }
67     
68     public void add(ItemItem itemItem) {
69         if (getRelatedItems() == null) {
70             setRelatedItems(new LinkedHashSet JavaDoc<ItemItem>());
71         }
72         itemItem.setItem(this);
73         getRelatedItems().add(itemItem);
74     }
75     
76     /**
77      * Lucene DocumentCreator implementation
78      */

79     public Document createDocument() {
80         Document d = new Document();
81         d.add(org.apache.lucene.document.Field.UnIndexed("id", getId() + ""));
82         d.add(org.apache.lucene.document.Field.UnIndexed("type", "item"));
83         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
84         if (getSummary() != null) {
85             sb.append(getSummary());
86         }
87         if (getDetail() != null) {
88             if (sb.length() > 0) {
89                 sb.append(" | ");
90             }
91             sb.append(getDetail());
92         }
93         d.add(org.apache.lucene.document.Field.UnStored("text", sb.toString()));
94         return d;
95     }
96     
97     public History getLatestHistory() {
98         if (history == null) {
99             return null;
100         }
101         History out = null;
102         for(History h : history) {
103             out = h;
104         }
105         return out;
106     }
107     
108     //===========================================================
109

110     @Override JavaDoc
111     public Space getSpace() {
112         return space;
113     }
114     
115     public Integer JavaDoc getType() {
116         return type;
117     }
118
119     public void setType(Integer JavaDoc type) {
120         this.type = type;
121     }
122
123     public void setSpace(Space space) {
124         this.space = space;
125     }
126     
127     public long getSequenceNum() {
128         return sequenceNum;
129     }
130
131     public void setSequenceNum(long sequenceNum) {
132         this.sequenceNum = sequenceNum;
133     }
134     
135     public Set JavaDoc<History> getHistory() {
136         return history;
137     }
138
139     public void setHistory(Set JavaDoc<History> history) {
140         this.history = history;
141     }
142
143     public Set JavaDoc<Item> getChildren() {
144         return children;
145     }
146
147     public void setChildren(Set JavaDoc<Item> children) {
148         this.children = children;
149     }
150
151     public Set JavaDoc<Attachment> getAttachments() {
152         return attachments;
153     }
154
155     public void setAttachments(Set JavaDoc<Attachment> attachments) {
156         this.attachments = attachments;
157     }
158     
159     @Override JavaDoc
160     public String JavaDoc toString() {
161         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
162         sb.append(super.toString());
163         sb.append("; type [").append(type);
164         sb.append("]; space [").append(space);
165         sb.append("]; sequenceNum [").append(sequenceNum);
166         sb.append("]");
167         return sb.toString();
168     }
169     
170 }
171
Popular Tags