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 java.util.LinkedHashSet;
020: import java.util.List;
021: import java.util.Map;
022: import java.util.Set;
023: import org.apache.lucene.document.Document;
024: import org.apache.lucene.document.Field.Index;
025: import org.apache.lucene.document.Field.Store;
026:
027: /**
028: * This object represents a generic item which can be an issue, defect, task etc.
029: * some logic for field accessors and conversion of keys to display values
030: * is contained in the AbstractItem class
031: */
032: public class Item extends AbstractItem {
033:
034: private Integer type;
035: private Space space;
036: private long sequenceNum;
037:
038: private Set<History> history;
039: private Set<Item> children;
040: private Set<Attachment> attachments;
041:
042: // should be ideally in form backing object but for convenience
043: private String editReason;
044:
045: @Override
046: public String getRefId() {
047: return getSpace().getPrefixCode() + "-" + sequenceNum;
048: }
049:
050: public Map<Integer, String> getPermittedTransitions(User user) {
051: return user.getPermittedTransitions(space, getStatus());
052: }
053:
054: public List<Field> getEditableFieldList(User user) {
055: return user.getEditableFieldList(space, getStatus());
056: }
057:
058: public void add(History h) {
059: if (this .history == null) {
060: this .history = new LinkedHashSet<History>();
061: }
062: h.setParent(this );
063: this .history.add(h);
064: }
065:
066: public void add(Attachment attachment) {
067: if (attachments == null) {
068: attachments = new LinkedHashSet<Attachment>();
069: }
070: attachments.add(attachment);
071: }
072:
073: public void addRelated(Item relatedItem, int relationType) {
074: if (getRelatedItems() == null) {
075: setRelatedItems(new LinkedHashSet<ItemItem>());
076: }
077: ItemItem itemItem = new ItemItem(this , relatedItem,
078: relationType);
079: getRelatedItems().add(itemItem);
080: }
081:
082: /**
083: * Lucene DocumentCreator implementation
084: */
085: public Document createDocument() {
086: Document d = new Document();
087: d.add(new org.apache.lucene.document.Field("id", getId() + "",
088: Store.YES, Index.NO));
089: d.add(new org.apache.lucene.document.Field("type", "item",
090: Store.YES, Index.NO));
091: StringBuffer sb = new StringBuffer();
092: if (getSummary() != null) {
093: sb.append(getSummary());
094: }
095: if (getDetail() != null) {
096: if (sb.length() > 0) {
097: sb.append(" | ");
098: }
099: sb.append(getDetail());
100: }
101: d.add(new org.apache.lucene.document.Field("text", sb
102: .toString(), Store.NO, Index.TOKENIZED));
103: return d;
104: }
105:
106: public History getLatestHistory() {
107: if (history == null) {
108: return null;
109: }
110: History out = null;
111: for (History h : history) {
112: out = h;
113: }
114: return out;
115: }
116:
117: //===========================================================
118:
119: @Override
120: public Space getSpace() {
121: return space;
122: }
123:
124: public Integer getType() {
125: return type;
126: }
127:
128: public void setType(Integer type) {
129: this .type = type;
130: }
131:
132: public void setSpace(Space space) {
133: this .space = space;
134: }
135:
136: public long getSequenceNum() {
137: return sequenceNum;
138: }
139:
140: public void setSequenceNum(long sequenceNum) {
141: this .sequenceNum = sequenceNum;
142: }
143:
144: public Set<History> getHistory() {
145: return history;
146: }
147:
148: public void setHistory(Set<History> history) {
149: this .history = history;
150: }
151:
152: public Set<Item> getChildren() {
153: return children;
154: }
155:
156: public void setChildren(Set<Item> children) {
157: this .children = children;
158: }
159:
160: public Set<Attachment> getAttachments() {
161: return attachments;
162: }
163:
164: public void setAttachments(Set<Attachment> attachments) {
165: this .attachments = attachments;
166: }
167:
168: public String getEditReason() {
169: return editReason;
170: }
171:
172: public void setEditReason(String editReason) {
173: this .editReason = editReason;
174: }
175:
176: @Override
177: public String toString() {
178: StringBuffer sb = new StringBuffer();
179: sb.append(super .toString());
180: sb.append("; type [").append(type);
181: sb.append("]; space [").append(space);
182: sb.append("]; sequenceNum [").append(sequenceNum);
183: sb.append("]");
184: return sb.toString();
185: }
186:
187: }
|