001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package info.jtrac.domain;
018:
019: import org.apache.lucene.document.Document;
020: import org.apache.lucene.document.Field.Index;
021: import org.apache.lucene.document.Field.Store;
022:
023: /**
024: * Any updates to an Item (even a new insert) causes a snapshot of
025: * the item to be stored in the History table.
026: * In this way for each Item, a History view is available which
027: * shows the diffs, who made changes and when, etc.
028: */
029: public class History extends AbstractItem {
030:
031: private Integer type;
032: private String comment;
033: private Double actualEffort;
034: private Attachment attachment;
035:
036: public History() {
037: // zero arg constructor
038: }
039:
040: /**
041: * this is used a) when creating snapshot of item when inserting history
042: * and b) to create snapshot of item when editing item in which case
043: * the status, loggedBy and assignedTo fields are additionally tweaked
044: */
045: public History(Item item) {
046: setStatus(item.getStatus());
047: setSummary(item.getSummary());
048: setDetail(item.getDetail());
049: setLoggedBy(item.getLoggedBy());
050: setAssignedTo(item.getAssignedTo());
051: // setTimeStamp(item.getTimeStamp());
052: setPlannedEffort(item.getPlannedEffort());
053: //==========================
054: for (Field.Name fieldName : Field.Name.values()) {
055: setValue(fieldName, item.getValue(fieldName));
056: }
057: }
058:
059: /**
060: * Lucene DocumentCreator implementation
061: */
062: public Document createDocument() {
063: Document d = new Document();
064: d.add(new org.apache.lucene.document.Field("id", getId() + "",
065: Store.YES, Index.NO));
066: d.add(new org.apache.lucene.document.Field("itemId",
067: getParent().getId() + "", Store.YES, Index.NO));
068: d.add(new org.apache.lucene.document.Field("type", "history",
069: Store.YES, Index.NO));
070: StringBuffer sb = new StringBuffer();
071: if (getSummary() != null) {
072: sb.append(getSummary());
073: }
074: if (getDetail() != null) {
075: if (sb.length() > 0) {
076: sb.append(" | ");
077: }
078: sb.append(getDetail());
079: }
080: if (comment != null) {
081: if (sb.length() > 0) {
082: sb.append(" | ");
083: }
084: sb.append(comment);
085: }
086: d.add(new org.apache.lucene.document.Field("text", sb
087: .toString(), Store.NO, Index.TOKENIZED));
088: return d;
089: }
090:
091: @Override
092: public String getRefId() {
093: return getParent().getRefId();
094: }
095:
096: @Override
097: public Space getSpace() {
098: return getParent().getSpace();
099: }
100:
101: public int getIndex() {
102: int index = 0;
103: for (History h : getParent().getHistory()) {
104: if (getId() == h.getId()) {
105: return index;
106: }
107: index++;
108: }
109: return -1;
110: }
111:
112: //==========================================================================
113:
114: public Integer getType() {
115: return type;
116: }
117:
118: public void setType(Integer type) {
119: this .type = type;
120: }
121:
122: public String getComment() {
123: return comment;
124: }
125:
126: public void setComment(String comment) {
127: this .comment = comment;
128: }
129:
130: public Attachment getAttachment() {
131: return attachment;
132: }
133:
134: public void setAttachment(Attachment attachment) {
135: this .attachment = attachment;
136: }
137:
138: public Double getActualEffort() {
139: return actualEffort;
140: }
141:
142: public void setActualEffort(Double actualEffort) {
143: this .actualEffort = actualEffort;
144: }
145:
146: @Override
147: public String toString() {
148: StringBuffer sb = new StringBuffer();
149: sb.append(super .toString());
150: sb.append("; comment [").append(comment);
151: sb.append("]; actualEffort [").append(actualEffort);
152: sb.append("]; attachment [").append(attachment);
153: sb.append("]");
154: return sb.toString();
155: }
156:
157: }
|