1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.document.search; |
17 | |
|
18 | |
import org.kuali.rice.core.api.CoreConstants; |
19 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
20 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
21 | |
import org.kuali.rice.kew.api.document.Document; |
22 | |
import org.kuali.rice.kew.api.document.attribute.DocumentAttribute; |
23 | |
import org.kuali.rice.kew.api.document.attribute.DocumentAttributeContract; |
24 | |
import org.kuali.rice.kew.api.document.attribute.DocumentAttributeFactory; |
25 | |
import org.w3c.dom.Element; |
26 | |
|
27 | |
import javax.xml.bind.annotation.XmlAccessType; |
28 | |
import javax.xml.bind.annotation.XmlAccessorType; |
29 | |
import javax.xml.bind.annotation.XmlAnyElement; |
30 | |
import javax.xml.bind.annotation.XmlElement; |
31 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
32 | |
import javax.xml.bind.annotation.XmlRootElement; |
33 | |
import javax.xml.bind.annotation.XmlType; |
34 | |
import java.io.Serializable; |
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Collection; |
37 | |
import java.util.Collections; |
38 | |
import java.util.List; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | @XmlRootElement(name = DocumentSearchResult.Constants.ROOT_ELEMENT_NAME) |
47 | |
@XmlAccessorType(XmlAccessType.NONE) |
48 | |
@XmlType(name = DocumentSearchResult.Constants.TYPE_NAME, propOrder = { |
49 | |
DocumentSearchResult.Elements.DOCUMENT, |
50 | |
DocumentSearchResult.Elements.DOCUMENT_ATTRIBUTES, |
51 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
52 | |
}) |
53 | 0 | public final class DocumentSearchResult extends AbstractDataTransferObject implements DocumentSearchResultContract { |
54 | |
|
55 | |
@XmlElement(name = Elements.DOCUMENT, required = false) |
56 | |
private final Document document; |
57 | |
|
58 | |
@XmlElementWrapper(name = Elements.DOCUMENT_ATTRIBUTES, required = true) |
59 | |
@XmlElement(name = Elements.DOCUMENT_ATTRIBUTE, required = false) |
60 | |
private final List<DocumentAttribute> documentAttributes; |
61 | |
|
62 | 0 | @SuppressWarnings("unused") |
63 | |
@XmlAnyElement |
64 | |
private final Collection<Element> _futureElements = null; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@SuppressWarnings("unused") |
70 | 0 | private DocumentSearchResult() { |
71 | 0 | this.document = null; |
72 | 0 | this.documentAttributes = null; |
73 | 0 | } |
74 | |
|
75 | 0 | private DocumentSearchResult(Builder builder) { |
76 | 0 | this.document = builder.getDocument().build(); |
77 | 0 | List<DocumentAttribute> documentAttributes = new ArrayList<DocumentAttribute>(); |
78 | 0 | for (DocumentAttribute.AbstractBuilder<?> documentAttribute : builder.getDocumentAttributes()) { |
79 | 0 | documentAttributes.add(documentAttribute.build()); |
80 | |
} |
81 | 0 | this.documentAttributes = Collections.unmodifiableList(documentAttributes); |
82 | 0 | } |
83 | |
|
84 | |
@Override |
85 | |
public Document getDocument() { |
86 | 0 | return this.document; |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public List<DocumentAttribute> getDocumentAttributes() { |
91 | 0 | return this.documentAttributes; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public List<DocumentAttribute> getDocumentAttributeByName(String attributeName) { |
103 | 0 | List<DocumentAttribute> namedAttributes = new ArrayList<DocumentAttribute>(); |
104 | 0 | for (DocumentAttribute attribute : getDocumentAttributes()) { |
105 | 0 | if (attribute.getName().equals(attributeName)) { |
106 | 0 | namedAttributes.add(attribute); |
107 | |
} |
108 | |
} |
109 | 0 | return Collections.unmodifiableList(namedAttributes); |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public DocumentAttribute getSingleDocumentAttributeByName(String attributeName) { |
122 | 0 | List<DocumentAttribute> namedAttributes = getDocumentAttributeByName(attributeName); |
123 | 0 | if (namedAttributes.isEmpty()) { |
124 | 0 | return null; |
125 | |
} |
126 | 0 | return namedAttributes.get(0); |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 0 | public final static class Builder implements Serializable, ModelBuilder, DocumentSearchResultContract { |
134 | |
|
135 | |
private Document.Builder document; |
136 | |
private List<DocumentAttribute.AbstractBuilder<?>> documentAttributes; |
137 | |
|
138 | 0 | private Builder(Document.Builder document) { |
139 | 0 | setDocument(document); |
140 | 0 | setDocumentAttributes(new ArrayList<DocumentAttribute.AbstractBuilder<?>>()); |
141 | 0 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
public static Builder create(Document.Builder document) { |
154 | 0 | return new Builder(document); |
155 | |
} |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
public static Builder create(DocumentSearchResultContract contract) { |
167 | 0 | if (contract == null) { |
168 | 0 | throw new IllegalArgumentException("contract was null"); |
169 | |
} |
170 | 0 | Document.Builder documentBuilder = Document.Builder.create(contract.getDocument()); |
171 | 0 | Builder builder = create(documentBuilder); |
172 | 0 | List<DocumentAttribute.AbstractBuilder<?>> documentAttributes = new ArrayList<DocumentAttribute.AbstractBuilder<?>>(); |
173 | 0 | for (DocumentAttributeContract documentAttributeContract : contract.getDocumentAttributes()) { |
174 | 0 | documentAttributes.add(DocumentAttributeFactory.loadContractIntoBuilder(documentAttributeContract)); |
175 | |
} |
176 | 0 | builder.setDocumentAttributes(documentAttributes); |
177 | 0 | return builder; |
178 | |
} |
179 | |
|
180 | |
public DocumentSearchResult build() { |
181 | 0 | return new DocumentSearchResult(this); |
182 | |
} |
183 | |
|
184 | |
@Override |
185 | |
public Document.Builder getDocument() { |
186 | 0 | return this.document; |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public List<DocumentAttribute.AbstractBuilder<?>> getDocumentAttributes() { |
191 | 0 | return this.documentAttributes; |
192 | |
} |
193 | |
|
194 | |
public void setDocument(Document.Builder document) { |
195 | 0 | if (document == null) { |
196 | 0 | throw new IllegalArgumentException("document was null"); |
197 | |
} |
198 | 0 | this.document = document; |
199 | 0 | } |
200 | |
|
201 | |
public void setDocumentAttributes(List<DocumentAttribute.AbstractBuilder<?>> documentAttributes) { |
202 | 0 | this.documentAttributes = documentAttributes; |
203 | 0 | } |
204 | |
|
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | 0 | static class Constants { |
211 | |
final static String ROOT_ELEMENT_NAME = "documentSearchResult"; |
212 | |
final static String TYPE_NAME = "DocumentSearchResultType"; |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | 0 | static class Elements { |
219 | |
final static String DOCUMENT = "document"; |
220 | |
final static String DOCUMENT_ATTRIBUTES = "documentAttributes"; |
221 | |
final static String DOCUMENT_ATTRIBUTE = "documentAttribute"; |
222 | |
} |
223 | |
|
224 | |
} |