1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
37
38
39
40
41 public class SearchableAttributeDAOJpa implements SearchableAttributeDAO {
42
43 private EntityManager entityManager;
44 private DataObjectService dataObjectService;
45
46
47
48
49
50
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
74
75
76
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
97
98
99
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
120
121
122
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 }