View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.kew.docsearch.dao.impl;
17  
18  import org.kuali.rice.core.api.criteria.QueryByCriteria;
19  import org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue;
20  import org.kuali.rice.kew.docsearch.SearchableAttributeFloatValue;
21  import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue;
22  import org.kuali.rice.kew.docsearch.SearchableAttributeStringValue;
23  import org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO;
24  import org.kuali.rice.krad.data.DataObjectService;
25  import org.springframework.beans.factory.annotation.Required;
26  
27  import javax.persistence.EntityManager;
28  import java.math.BigDecimal;
29  import java.sql.Timestamp;
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
34  
35  /**
36   * JPA implementation of SearchableAttributeDAO
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   *
40   */
41  public class SearchableAttributeDAOJpa implements SearchableAttributeDAO {
42  
43  	private EntityManager entityManager;
44      private DataObjectService dataObjectService;
45  
46  	/**
47  	 * This overridden method queries the SearchableAttributeDateTimeValue persistence class
48  	 *
49  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeDateTimeValuesByKey(
50       * java.lang.String,java.lang.String)
51  	 */
52  	public List<Timestamp> getSearchableAttributeDateTimeValuesByKey(
53  			String documentId, String key) {
54  
55  		List<Timestamp> lRet = null;
56          QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
57          builder.setPredicates(equal("documentId",documentId),
58                                 equal("searchableAttributeKey",key));
59  
60  
61          List<SearchableAttributeDateTimeValue> results = getDataObjectService().findMatching(
62                              SearchableAttributeDateTimeValue.class,builder.build()).getResults();
63          if (!results.isEmpty()) {
64          	lRet = new ArrayList<Timestamp>();
65              for (SearchableAttributeDateTimeValue attribute: results) {
66              	lRet.add(attribute.getSearchableAttributeValue());
67              }
68          }
69  		return lRet;
70  	}
71  
72  	/**
73  	 * This overridden method queries the SearchableAttributeFloatValue persistence class
74  	 *
75  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeFloatValuesByKey(
76       * java.lang.String,java.lang.String)
77  	 */
78  	public List<BigDecimal> getSearchableAttributeFloatValuesByKey(
79  			String documentId, String key) {
80  		List<BigDecimal> lRet = null;
81          QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
82          builder.setPredicates(equal("documentId",documentId),
83                  equal("searchableAttributeKey",key));
84          List<SearchableAttributeFloatValue> results = getDataObjectService().findMatching(
85                  SearchableAttributeFloatValue.class,builder.build()).getResults();
86          if (!results.isEmpty()) {
87          	lRet = new ArrayList<BigDecimal>();
88              for (SearchableAttributeFloatValue attribute: results) {
89              	lRet.add(attribute.getSearchableAttributeValue());
90              }
91          }
92  		return lRet;
93  	}
94  
95  	/**
96  	 * This overridden method queries the searchableAttributeKey persistence class
97  	 *
98  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeLongValuesByKey(
99       * java.lang.String,java.lang.String)
100 	 */
101 	public List<Long> getSearchableAttributeLongValuesByKey(String documentId,
102 			String key) {
103 		List<Long> lRet = null;
104         QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
105         builder.setPredicates(equal("documentId",documentId),
106                 equal("searchableAttributeKey",key));
107         List<SearchableAttributeLongValue> results = getDataObjectService().findMatching(
108                 SearchableAttributeLongValue.class,builder.build()).getResults();
109         if (!results.isEmpty()) {
110         	lRet = new ArrayList<Long>();
111             for (SearchableAttributeLongValue attribute: results) {
112             	lRet.add(attribute.getSearchableAttributeValue());
113             }
114         }
115 		return lRet;
116 	}
117 
118 	/**
119 	 * This overridden method queries the SearchableAttributeStringValue persistence class
120 	 *
121 	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeStringValuesByKey(
122      * java.lang.String,java.lang.String)
123 	 */
124 	public List<String> getSearchableAttributeStringValuesByKey(
125 			String documentId, String key) {
126 		List<String> lRet = null;
127         QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
128         builder.setPredicates(equal("documentId",documentId),
129                 equal("searchableAttributeKey",key));
130         List<SearchableAttributeStringValue> results = getDataObjectService().findMatching(
131                 SearchableAttributeStringValue.class,builder.build()).getResults();
132         if (!results.isEmpty()) {
133         	lRet = new ArrayList<String>();
134             for (SearchableAttributeStringValue attribute: results) {
135             	lRet.add(attribute.getSearchableAttributeValue());
136             }
137         }
138 		return lRet;
139 	}
140 
141     public EntityManager getEntityManager() {
142         return this.entityManager;
143     }
144 
145     public void setEntityManager(EntityManager entityManager) {
146         this.entityManager = entityManager;
147     }
148 
149 
150     public DataObjectService getDataObjectService() {
151         return dataObjectService;
152     }
153 
154     @Required
155     public void setDataObjectService(DataObjectService dataObjectService) {
156         this.dataObjectService = dataObjectService;
157     }
158 
159 
160 }