1 16 17 package info.jtrac.domain; 18 19 import java.util.LinkedHashSet ; 20 import java.util.List ; 21 import java.util.Map ; 22 import java.util.Set ; 23 import org.apache.lucene.document.Document; 24 25 30 public class Item extends AbstractItem { 31 32 private Integer type; 33 private Space space; 34 private long sequenceNum; 35 36 private Set <History> history; 37 private Set <Item> children; 38 private Set <Attachment> attachments; 39 40 @Override 41 public String getRefId() { 42 return getSpace().getPrefixCode() + "-" + sequenceNum; 43 } 44 45 public Map <Integer , String > getPermittedTransitions(User user) { 46 return user.getPermittedTransitions(space, getStatus()); 47 } 48 49 public List <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 <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 <Attachment>(); 64 } 65 attachments.add(attachment); 66 } 67 68 public void add(ItemItem itemItem) { 69 if (getRelatedItems() == null) { 70 setRelatedItems(new LinkedHashSet <ItemItem>()); 71 } 72 itemItem.setItem(this); 73 getRelatedItems().add(itemItem); 74 } 75 76 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 sb = new StringBuffer (); 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 110 @Override 111 public Space getSpace() { 112 return space; 113 } 114 115 public Integer getType() { 116 return type; 117 } 118 119 public void setType(Integer 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 <History> getHistory() { 136 return history; 137 } 138 139 public void setHistory(Set <History> history) { 140 this.history = history; 141 } 142 143 public Set <Item> getChildren() { 144 return children; 145 } 146 147 public void setChildren(Set <Item> children) { 148 this.children = children; 149 } 150 151 public Set <Attachment> getAttachments() { 152 return attachments; 153 } 154 155 public void setAttachments(Set <Attachment> attachments) { 156 this.attachments = attachments; 157 } 158 159 @Override 160 public String toString() { 161 StringBuffer sb = new StringBuffer (); 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 |