View Javadoc

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