1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.edl.impl.dao.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.rice.core.api.criteria.Predicate;
22 import org.kuali.rice.core.api.criteria.QueryByCriteria;
23 import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
24 import org.kuali.rice.edl.impl.bo.EDocLiteDefinition;
25 import org.kuali.rice.edl.impl.dao.EDocLiteDAO;
26 import org.kuali.rice.krad.data.DataObjectService;
27 import org.kuali.rice.krad.data.PersistenceOption;
28
29 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
30
31
32
33
34
35
36 public class EDocLiteDAOJpaImpl implements EDocLiteDAO {
37 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EDocLiteDAOJpaImpl.class);
38
39
40 private static final String ACTIVE_IND_CRITERIA = "activeInd";
41
42
43 private static final String NAME_CRITERIA = "name";
44
45
46 private static final String EDL_NAME = "edlName";
47
48
49 private static final String UPPER = "UPPER";
50
51
52 private static final String DEFINITION = "definition";
53
54
55 private static final String STYLE = "style";
56
57
58 private DataObjectService dataObjectService;
59
60
61
62
63
64 public DataObjectService getDataObjectService() {
65 return this.dataObjectService;
66 }
67
68
69
70
71
72 public void setDataObjectService(DataObjectService dataObjectService) {
73 this.dataObjectService = dataObjectService;
74 }
75
76
77
78
79 @Override
80 public EDocLiteDefinition saveEDocLiteDefinition(final EDocLiteDefinition edocLiteData) {
81 return this.dataObjectService.save(edocLiteData, PersistenceOption.FLUSH);
82 }
83
84
85
86
87 @Override
88 public EDocLiteAssociation saveEDocLiteAssociation(final EDocLiteAssociation assoc) {
89 return this.dataObjectService.save(assoc, PersistenceOption.FLUSH);
90 }
91
92
93
94
95 @Override
96 public EDocLiteDefinition getEDocLiteDefinition(final String defName) {
97 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
98 criteria.setPredicates(equal(NAME_CRITERIA, defName), equal(ACTIVE_IND_CRITERIA, Boolean.TRUE));
99 List<EDocLiteDefinition> edls = this.dataObjectService.findMatching(EDocLiteDefinition.class,
100 criteria.build()).getResults();
101 if (null != edls && !edls.isEmpty()) {
102 return edls.get(0);
103 } else {
104 return null;
105 }
106 }
107
108
109
110
111 @Override
112 public EDocLiteAssociation getEDocLiteAssociation(final String docTypeName) {
113 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
114 criteria.setPredicates(equal(EDL_NAME, docTypeName), equal(ACTIVE_IND_CRITERIA, Boolean.TRUE));
115 List<EDocLiteAssociation> edls = this.dataObjectService.findMatching(EDocLiteAssociation.class,
116 criteria.build()).getResults();
117
118 if (null != edls && !edls.isEmpty()) {
119 return edls.get(0);
120 } else {
121 return null;
122 }
123 }
124
125
126
127
128 @Override
129 public List<String> getEDocLiteDefinitions() {
130 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
131 criteria.setPredicates(equal(ACTIVE_IND_CRITERIA, Boolean.TRUE));
132 List<EDocLiteDefinition> defs = this.dataObjectService.findMatching(EDocLiteDefinition.class,
133 criteria.build()).getResults();
134 ArrayList<String> names = new ArrayList<String>(defs.size());
135 if (!defs.isEmpty()) {
136 for (EDocLiteDefinition def : defs) {
137 names.add(def.getName());
138 }
139 }
140
141 return names;
142 }
143
144
145
146
147 @Override
148 public List<EDocLiteAssociation> getEDocLiteAssociations() {
149 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
150 criteria.setPredicates(equal(ACTIVE_IND_CRITERIA, Boolean.TRUE));
151 return this.dataObjectService.findMatching(EDocLiteAssociation.class, criteria.build()).getResults();
152 }
153
154
155
156
157 @Override
158 public List<EDocLiteAssociation> search(final EDocLiteAssociation edocLite) {
159 List<Predicate> predicates = new ArrayList<Predicate>();
160 if (edocLite.getActiveInd() != null) {
161 predicates.add(equal(ACTIVE_IND_CRITERIA, edocLite.getActiveInd()));
162 }
163 if (edocLite.getDefinition() != null) {
164 predicates.add(like(UPPER + "(" + DEFINITION + ")", "%" + edocLite.getDefinition().toUpperCase() + "%"));
165 }
166 if (edocLite.getEdlName() != null) {
167 predicates.add(like(UPPER + "(" + EDL_NAME + ")", "%" + edocLite.getEdlName().toUpperCase() + "%"));
168 }
169 if (edocLite.getStyle() != null) {
170 predicates.add(like(UPPER + "(" + STYLE + ")", "%" + edocLite.getStyle().toUpperCase() + "%"));
171 }
172 QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
173 builder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
174 return this.dataObjectService.findMatching(EDocLiteAssociation.class, builder.build()).getResults();
175
176 }
177
178
179
180
181 @Override
182 public EDocLiteAssociation getEDocLiteAssociation(final Long associationId) {
183 return dataObjectService.find(EDocLiteAssociation.class, associationId);
184 }
185 }