1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule.dao.impl;
17
18 import org.kuali.rice.core.api.criteria.Predicate;
19 import org.kuali.rice.core.api.criteria.QueryByCriteria;
20 import org.kuali.rice.core.api.criteria.QueryResults;
21 import org.kuali.rice.kew.rule.bo.RuleAttribute;
22 import org.kuali.rice.kew.rule.dao.RuleAttributeDAO;
23 import org.kuali.rice.krad.data.DataObjectService;
24 import org.springframework.beans.factory.annotation.Required;
25
26 import javax.persistence.EntityManager;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
31 import static org.kuali.rice.core.api.criteria.PredicateFactory.likeIgnoreCase;
32
33 public class RuleAttributeDAOJpa implements RuleAttributeDAO {
34
35 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleAttributeDAOJpa.class);
36
37 private EntityManager entityManager;
38 private DataObjectService dataObjectService;
39
40
41 public void save(RuleAttribute ruleAttribute) {
42 getDataObjectService().save(ruleAttribute);
43 }
44
45 public void delete(String ruleAttributeId) {
46 RuleAttribute ruleAttribute = findByRuleAttributeId(ruleAttributeId);
47 getDataObjectService().delete(ruleAttribute);
48 }
49
50 public RuleAttribute findByRuleAttributeId(String ruleAttributeId) {
51 return getDataObjectService().find(RuleAttribute.class,ruleAttributeId);
52 }
53
54 public List<RuleAttribute> findByRuleAttribute(RuleAttribute ruleAttribute) {
55 QueryByCriteria.Builder builder =
56 QueryByCriteria.Builder.create();
57
58 List<Predicate> predicates = new ArrayList<Predicate>();
59 if (ruleAttribute.getName() != null) {
60 predicates.add(likeIgnoreCase("name",ruleAttribute.getName()));
61 }
62
63 if (ruleAttribute.getResourceDescriptor() != null) {
64 predicates.add(likeIgnoreCase("resourceDescriptor",ruleAttribute.getResourceDescriptor()));
65 }
66 if (ruleAttribute.getType() != null) {
67 predicates.add(likeIgnoreCase("type",ruleAttribute.getType()));
68 }
69 Predicate[] preds = predicates.toArray(new Predicate[predicates.size()]);
70 builder.setPredicates(preds);
71 QueryResults<RuleAttribute> results = getDataObjectService().findMatching(RuleAttribute.class, builder.build());
72 return results.getResults();
73
74 }
75
76 public List<RuleAttribute> getAllRuleAttributes() {
77 QueryByCriteria.Builder builder =
78 QueryByCriteria.Builder.create();
79 QueryResults<RuleAttribute> results = getDataObjectService().findMatching(RuleAttribute.class, builder.build());
80 return results.getResults();
81 }
82
83 public RuleAttribute findByName(String name) {
84 LOG.debug("findByName name=" + name);
85 QueryByCriteria.Builder builder =
86 QueryByCriteria.Builder.create();
87 builder.setPredicates(equal("name",name));
88 QueryResults<RuleAttribute> ruleAttributeQueryResults = getDataObjectService().
89 findMatching(RuleAttribute.class, builder.build());
90 if(ruleAttributeQueryResults != null && ruleAttributeQueryResults.getResults().size() > 0){
91 return ruleAttributeQueryResults.getResults().get(0);
92 }
93 return null;
94 }
95
96 public List<RuleAttribute> findByClassName(String classname) {
97 LOG.debug("findByClassName classname=" + classname);
98
99 QueryByCriteria.Builder builder =
100 QueryByCriteria.Builder.create();
101 builder.setPredicates(equal("resourceDescriptor",classname));
102 QueryResults<RuleAttribute> ruleAttributeQueryResults = getDataObjectService().
103 findMatching(RuleAttribute.class,builder.build());
104 return ruleAttributeQueryResults.getResults();
105
106 }
107
108
109 public DataObjectService getDataObjectService() {
110 return dataObjectService;
111 }
112
113 @Required
114 public void setDataObjectService(DataObjectService dataObjectService) {
115 this.dataObjectService = dataObjectService;
116 }
117
118
119
120
121
122 public EntityManager getEntityManager() {
123 return this.entityManager;
124 }
125
126
127
128
129 public void setEntityManager(EntityManager entityManager) {
130 this.entityManager = entityManager;
131 }
132
133 }