1 /*
2 * Copyright 2012 The Kuali Foundation.
3 *
4 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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 package org.kuali.ole.select.businessobject;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.DocumentUniqueIDPrefix;
20 import org.kuali.ole.docstore.common.document.Bib;
21 import org.kuali.ole.select.OleSelectConstant;
22 import org.kuali.ole.select.lookup.DocData;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.rice.kew.api.document.Document;
25 import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
26 import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
27 import org.kuali.rice.kim.api.identity.PersonService;
28 import org.kuali.rice.krad.bo.BusinessObjectBase;
29
30 import java.lang.reflect.Method;
31 import java.util.Date;
32 import java.util.List;
33
34 /**
35 * This class is the Business Object class for the Acquisition Search
36 */
37 public class OleAcquisitionSearchResult extends BusinessObjectBase {
38
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleAcquisitionSearchResult.class);
40
41 private String organizationDocumentNumber;
42 private String financialDocumentTypeCode;
43 private String documentDescription;
44 private String applicationDocumentStatus;
45 private String initiator;
46 private Date dateCreated;
47 private String purapDocumentIdentifier;
48 private String itemTitleId;
49 private String title;
50 private String author;
51 private String publisher;
52 private String isbn;
53 private String localIdentifier;
54 private PersonService personService;
55
56 /**
57 * Gets the organizationDocumentNumber attribute.
58 *
59 * @return Returns the organizationDocumentNumber.
60 */
61 public String getOrganizationDocumentNumber() {
62 return organizationDocumentNumber;
63 }
64
65 /**
66 * Sets the organizationDocumentNumber attribute value.
67 *
68 * @param organizationDocumentNumber The organizationDocumentNumber to set.
69 */
70 public void setOrganizationDocumentNumber(String organizationDocumentNumber) {
71 this.organizationDocumentNumber = organizationDocumentNumber;
72 }
73
74 /**
75 * Gets the financialDocumentTypeCode attribute.
76 *
77 * @return Returns the financialDocumentTypeCode.
78 */
79 public String getFinancialDocumentTypeCode() {
80 return financialDocumentTypeCode;
81 }
82
83 public String getLocalIdentifier() {
84 return localIdentifier;
85 }
86
87 public void setLocalIdentifier(String localIdentifier) {
88 this.localIdentifier = localIdentifier;
89 }
90
91 /**
92 * Sets the financialDocumentTypeCode attribute value.
93 *
94 * @param financialDocumentTypeCode The financialDocumentTypeCode to set .
95 */
96 public void setFinancialDocumentTypeCode(String financialDocumentTypeCode) {
97 this.financialDocumentTypeCode = financialDocumentTypeCode;
98 }
99
100 /**
101 * Gets the documentDescription attribute.
102 *
103 * @return Returns the documentDescription.
104 */
105 public String getDocumentDescription() {
106 return documentDescription;
107 }
108
109 /**
110 * Sets the documentDescription attribute value.
111 *
112 * @param documentDescription The documentDescription to set.
113 */
114 public void setDocumentDescription(String documentDescription) {
115 this.documentDescription = documentDescription;
116 }
117
118 /**
119 * Gets the applicationDocumentStatus attribute.
120 *
121 * @return Returns the applicationDocumentStatus.
122 */
123 public String getApplicationDocumentStatus() {
124 return applicationDocumentStatus;
125 }
126
127 /**
128 * Sets the applicationDocumentStatus attribute value.
129 *
130 * @param applicationDocumentStatus The applicationDocumentStatus to set.
131 */
132 public void setApplicationDocumentStatus(String applicationDocumentStatus) {
133 this.applicationDocumentStatus = applicationDocumentStatus;
134 }
135
136 /**
137 * Gets the initiator attribute.
138 *
139 * @return Returns the initiator.
140 */
141 public String getInitiator() {
142 return initiator;
143 }
144
145 /**
146 * Sets the initiator attribute value.
147 *
148 * @param initiator The initiator to set.
149 */
150 public void setInitiator(String initiator) {
151 this.initiator = initiator;
152 }
153
154 /**
155 * Gets the dateCreated attribute.
156 *
157 * @return Returns the dateCreated.
158 */
159 public Date getDateCreated() {
160 return dateCreated;
161 }
162
163 /**
164 * Sets the dateCreated attribute value.
165 *
166 * @param dateCreated The dateCreated to set.
167 */
168 public void setDateCreated(Date dateCreated) {
169 this.dateCreated = dateCreated;
170 }
171
172 /**
173 * Gets the purapDocumentIdentifier attribute.
174 *
175 * @return Returns the purapDocumentIdentifier.
176 */
177 public String getPurapDocumentIdentifier() {
178 return purapDocumentIdentifier;
179 }
180
181 /**
182 * Sets the purapDocumentIdentifier attribute value.
183 *
184 * @param purapDocumentIdentifier The purapDocumentIdentifier to set.
185 */
186 public void setPurapDocumentIdentifier(String purapDocumentIdentifier) {
187 this.purapDocumentIdentifier = purapDocumentIdentifier;
188 }
189
190 /**
191 * Gets the itemTitleId attribute.
192 *
193 * @return Returns the itemTitleId.
194 */
195 public String getItemTitleId() {
196 return itemTitleId;
197 }
198
199 /**
200 * Sets the itemTitleId attribute value.
201 *
202 * @param itemTitleId The itemTitleId to set.
203 */
204 public void setItemTitleId(String itemTitleId) {
205 this.itemTitleId = itemTitleId;
206 }
207
208 /**
209 * Gets the title attribute.
210 *
211 * @return Returns the title.
212 */
213 public String getTitle() {
214 return title;
215 }
216
217 /**
218 * Sets the title attribute value.
219 *
220 * @param title The title to set.
221 */
222 public void setTitle(String title) {
223 this.title = title;
224 }
225
226 /**
227 * Gets the author attribute.
228 *
229 * @return Returns the author.
230 */
231 public String getAuthor() {
232 return author;
233 }
234
235 /**
236 * Sets the author attribute value.
237 *
238 * @param author The author to set.
239 */
240 public void setAuthor(String author) {
241 this.author = author;
242 }
243
244 /**
245 * Gets the publisher attribute.
246 *
247 * @return Returns the publisher.
248 */
249 public String getPublisher() {
250 return publisher;
251 }
252
253 /**
254 * Sets the publisher attribute value.
255 *
256 * @param publisher The publisher to set.
257 */
258 public void setPublisher(String publisher) {
259 this.publisher = publisher;
260 }
261
262
263 /**
264 * Gets the isbn attribute.
265 *
266 * @return Returns the isbn.
267 */
268 public String getIsbn() {
269 return isbn;
270 }
271
272 /**
273 * Sets the isbn attribute value.
274 *
275 * @param isbn The isbn to set.
276 */
277 public void setIsbn(String isbn) {
278 this.isbn = isbn;
279 }
280
281
282 /**
283 * This method sets the result fields from the DocumentSearchResult and the
284 *
285 * @param isBibSearch
286 * @param searchResults
287 * @param docDatas
288 */
289 /* public void setResultDetails(boolean isBibSearch, DocumentSearchResult searchResult, List<DocData> docDatas) {
290 if (LOG.isDebugEnabled()) {
291 LOG.info("Inside setResultDetails method of OleAcquisitionSearchResult");
292 }
293 Document document = searchResult.getDocument();
294 List<DocumentAttribute> documentAttributes = searchResult.getDocumentAttributes();
295 for (DocumentAttribute docAttribute : documentAttributes) {
296 String name = docAttribute.getName();
297 if (OleSelectConstant.AcquisitionsSearch.RESULT_FIELDS.contains(name)) {
298 if (name.equals(OleSelectConstant.AcquisitionsSearch.PO_ID)) {
299 name = OleSelectConstant.AcquisitionsSearch.ACQ_PO_NUMBER;
300 }
301 Method getMethod;
302 try {
303 getMethod = getSetMethod(OleAcquisitionSearchResult.class, name, new Class[]{String.class});
304 getMethod.invoke(this, docAttribute.getValue().toString());
305 } catch (Exception ex) {
306 ex.printStackTrace();
307 }
308 }
309 this.setApplicationDocumentStatus(document.getApplicationDocumentStatus());
310 this.setOrganizationDocumentNumber(document.getDocumentId());
311 this.setFinancialDocumentTypeCode(document.getDocumentTypeName());
312 this.setInitiator((SpringContext.getBean(PersonService.class)).getPerson(document.getInitiatorPrincipalId()).getPrincipalName());
313 this.setDateCreated(document.getDateCreated().toDate());
314 }
315 if (isBibSearch && docDatas.size() > 0) {
316 for (DocData docData : docDatas) {
317 if (itemTitleId != null && this.itemTitleId.equals(docData.getUniqueId())) {
318 this.setTitle(docData.getTitle());
319 this.setAuthor(docData.getAuthor());
320 this.setPublisher(docData.getPublisher());
321 this.setIsbn(docData.getIsbn());
322 this.setLocalIdentifier(docData.getLocalIdentifier());
323 }
324 }
325 }
326 if (LOG.isDebugEnabled()) {
327 LOG.info("Leaving setResultDetails method of OleAcquisitionSearchResult");
328 }
329 }
330 */
331 public void setResultDetails(boolean isBibSearch, DocumentSearchResult searchResult, List<Bib> bibs) {
332 if (LOG.isDebugEnabled()) {
333 LOG.debug("Inside setResultDetails method of OleAcquisitionSearchResult");
334 }
335 Document document = searchResult.getDocument();
336 List<DocumentAttribute> documentAttributes = searchResult.getDocumentAttributes();
337 for (DocumentAttribute docAttribute : documentAttributes) {
338 String name = docAttribute.getName();
339 if (OleSelectConstant.AcquisitionsSearch.RESULT_FIELDS.contains(name)) {
340 if (name.equals(OleSelectConstant.AcquisitionsSearch.PO_ID)) {
341 name = OleSelectConstant.AcquisitionsSearch.ACQ_PO_NUMBER;
342 }
343 Method getMethod;
344 try {
345 getMethod = getSetMethod(OleAcquisitionSearchResult.class, name, new Class[]{String.class});
346 getMethod.invoke(this, docAttribute.getValue().toString());
347 } catch (Exception ex) {
348 ex.printStackTrace();
349 }
350 }
351 this.setApplicationDocumentStatus(document.getApplicationDocumentStatus());
352 this.setOrganizationDocumentNumber(document.getDocumentId());
353 this.setFinancialDocumentTypeCode(document.getDocumentTypeName());
354 this.setInitiator((SpringContext.getBean(PersonService.class)).getPerson(document.getInitiatorPrincipalId()).getPrincipalName());
355 this.setDateCreated(document.getDateCreated().toDate());
356 }
357 if (isBibSearch && bibs.size() > 0) {
358 for (Bib bib : bibs) {
359 //bib=(Bib)bib.deserializeContent(bib);
360 if (itemTitleId != null && this.itemTitleId.equals(bib.getId())) {
361 String localId = DocumentUniqueIDPrefix.getDocumentId(bib.getId());
362 if(StringUtils.isNotBlank(localId)){
363 this.setTitle(bib.getTitle());
364 this.setAuthor(bib.getAuthor());
365 this.setPublisher(bib.getPublisher());
366 this.setIsbn(bib.getIsbn());
367 this.setLocalIdentifier(localId);
368 break;
369 }
370
371 }
372 }
373 }
374 if (LOG.isDebugEnabled()) {
375 LOG.debug("Leaving setResultDetails method of OleAcquisitionSearchResult");
376 }
377 }
378
379 /**
380 * This method generates the setter method for the given attribute
381 *
382 * @param c
383 * @param attr
384 * @param objectAttributes
385 * @return
386 * @throws Exception
387 */
388 private Method getSetMethod(Class targetClass, String attr, Class[] objectAttributes) throws Exception {
389 Method method = targetClass.getMethod("set" + StringUtils.capitalize(attr), objectAttributes);
390 return method;
391 }
392
393 @Override
394 public void refresh() {
395 // TODO Auto-generated method stub
396
397 }
398
399 }