KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.lucene.document.Document;
20
21 /**
22  * Any updates to an Item (even a new insert) causes a snapshot of
23  * the item to be stored in the History table.
24  * In this way for each Item, a History view is available which
25  * shows the diffs, who made changes and when, etc.
26  */

27 public class History extends AbstractItem {
28     
29     private Integer JavaDoc type;
30     private String JavaDoc comment;
31     private Double JavaDoc actualEffort;
32     private Attachment attachment;
33
34     public History() {
35         // zero arg constructor
36
}
37     
38     public History(Item item) {
39         setStatus(item.getStatus());
40         setSummary(item.getSummary());
41         setDetail(item.getDetail());
42         setLoggedBy(item.getLoggedBy());
43         setAssignedTo(item.getAssignedTo());
44         // setTimeStamp(item.getTimeStamp());
45
setPlannedEffort(item.getPlannedEffort());
46         //==========================
47
for(Field.Name fieldName : Field.Name.values()) {
48             setValue(fieldName, item.getValue(fieldName));
49         }
50     }
51     
52     /**
53      * Lucene DocumentCreator implementation
54      */

55     public Document createDocument() {
56         Document d = new Document();
57         d.add(org.apache.lucene.document.Field.UnIndexed("id", getId() + ""));
58         d.add(org.apache.lucene.document.Field.UnIndexed("itemId", getParent().getId() + ""));
59         d.add(org.apache.lucene.document.Field.UnIndexed("type", "history"));
60         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
61         if (getSummary() != null) {
62             sb.append(getSummary());
63         }
64         if (getDetail() != null) {
65             if (sb.length() > 0) {
66                 sb.append(" | ");
67             }
68             sb.append(getDetail());
69         }
70         if (comment != null) {
71             if (sb.length() > 0) {
72                 sb.append(" | ");
73             }
74             sb.append(comment);
75         }
76         d.add(org.apache.lucene.document.Field.UnStored("text", sb.toString()));
77         return d;
78     }
79     
80     @Override JavaDoc
81     public String JavaDoc getRefId() {
82         return getParent().getRefId();
83     }
84     
85     @Override JavaDoc
86     public Space getSpace() {
87         return getParent().getSpace();
88     }
89     
90     public Integer JavaDoc getType() {
91         return type;
92     }
93
94     public void setType(Integer JavaDoc type) {
95         this.type = type;
96     }
97     
98     public String JavaDoc getComment() {
99         return comment;
100     }
101
102     public void setComment(String JavaDoc comment) {
103         this.comment = comment;
104     }
105
106     public Attachment getAttachment() {
107         return attachment;
108     }
109
110     public void setAttachment(Attachment attachment) {
111         this.attachment = attachment;
112     }
113
114     public Double JavaDoc getActualEffort() {
115         return actualEffort;
116     }
117
118     public void setActualEffort(Double JavaDoc actualEffort) {
119         this.actualEffort = actualEffort;
120     }
121     
122     @Override JavaDoc
123     public String JavaDoc toString() {
124         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
125         sb.append(super.toString());
126         sb.append("; comment [").append(comment);
127         sb.append("]; actualEffort [").append(actualEffort);
128         sb.append("]; attachment [").append(attachment);
129         sb.append("]");
130         return sb.toString();
131     }
132     
133 }
134
Popular Tags