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