001/* 002 * Copyright 2012 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php 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 */ 016package org.kuali.ole.select.businessobject; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.ole.DocumentUniqueIDPrefix; 020import org.kuali.ole.docstore.common.document.Bib; 021import org.kuali.ole.select.OleSelectConstant; 022import org.kuali.ole.select.lookup.DocData; 023import org.kuali.ole.sys.context.SpringContext; 024import org.kuali.rice.kew.api.document.Document; 025import org.kuali.rice.kew.api.document.attribute.DocumentAttribute; 026import org.kuali.rice.kew.api.document.search.DocumentSearchResult; 027import org.kuali.rice.kim.api.identity.PersonService; 028import org.kuali.rice.krad.bo.BusinessObjectBase; 029 030import java.lang.reflect.Method; 031import java.util.Date; 032import java.util.List; 033 034/** 035 * This class is the Business Object class for the Acquisition Search 036 */ 037public class OleAcquisitionSearchResult extends BusinessObjectBase { 038 039 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleAcquisitionSearchResult.class); 040 041 private String organizationDocumentNumber; 042 private String financialDocumentTypeCode; 043 private String documentDescription; 044 private String applicationDocumentStatus; 045 private String initiator; 046 private Date dateCreated; 047 private String purapDocumentIdentifier; 048 private String itemTitleId; 049 private String title; 050 private String author; 051 private String publisher; 052 private String isbn; 053 private String localIdentifier; 054 private PersonService personService; 055 056 /** 057 * Gets the organizationDocumentNumber attribute. 058 * 059 * @return Returns the organizationDocumentNumber. 060 */ 061 public String getOrganizationDocumentNumber() { 062 return organizationDocumentNumber; 063 } 064 065 /** 066 * Sets the organizationDocumentNumber attribute value. 067 * 068 * @param organizationDocumentNumber The organizationDocumentNumber to set. 069 */ 070 public void setOrganizationDocumentNumber(String organizationDocumentNumber) { 071 this.organizationDocumentNumber = organizationDocumentNumber; 072 } 073 074 /** 075 * Gets the financialDocumentTypeCode attribute. 076 * 077 * @return Returns the financialDocumentTypeCode. 078 */ 079 public String getFinancialDocumentTypeCode() { 080 return financialDocumentTypeCode; 081 } 082 083 public String getLocalIdentifier() { 084 return localIdentifier; 085 } 086 087 public void setLocalIdentifier(String localIdentifier) { 088 this.localIdentifier = localIdentifier; 089 } 090 091 /** 092 * Sets the financialDocumentTypeCode attribute value. 093 * 094 * @param financialDocumentTypeCode The financialDocumentTypeCode to set . 095 */ 096 public void setFinancialDocumentTypeCode(String financialDocumentTypeCode) { 097 this.financialDocumentTypeCode = financialDocumentTypeCode; 098 } 099 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}