1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actiontaken.dao.impl;
17
18 import org.apache.ojb.broker.query.Criteria;
19 import org.apache.ojb.broker.query.QueryByCriteria;
20 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
21 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
22 import org.kuali.rice.kew.actiontaken.dao.ActionTakenDAO;
23 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
24
25 import java.sql.Timestamp;
26 import java.util.Collection;
27 import java.util.List;
28
29
30
31
32
33
34
35 public class ActionTakenDAOOjbImpl extends PersistenceBrokerDaoSupport implements ActionTakenDAO {
36
37 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenDAOOjbImpl.class);
38
39 public ActionTakenValue load(String id) {
40 LOG.debug("Loading Action Taken for the given id " + id);
41 Criteria crit = new Criteria();
42 crit.addEqualTo("actionTakenId", id);
43 return (ActionTakenValue) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
44 }
45
46 public void deleteActionTaken(ActionTakenValue actionTaken) {
47 LOG.debug("deleting ActionTaken " + actionTaken.getActionTakenId());
48 this.getPersistenceBrokerTemplate().delete(actionTaken);
49 }
50
51 public ActionTakenValue findByActionTakenId(String actionTakenId) {
52 LOG.debug("finding Action Taken by actionTakenId " + actionTakenId);
53 Criteria crit = new Criteria();
54 crit.addEqualTo("actionTakenId", actionTakenId);
55 crit.addEqualTo("currentIndicator", Boolean.TRUE);
56 return (ActionTakenValue) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
57 }
58
59 public Collection<ActionTakenValue> findByDocIdAndAction(String documentId, String action) {
60 LOG.debug("finding Action Taken by documentId " + documentId + " and action " + action);
61 Criteria crit = new Criteria();
62 crit.addEqualTo("documentId", documentId);
63 crit.addEqualTo("actionTaken", action);
64 crit.addEqualTo("currentIndicator", Boolean.TRUE);
65 return (Collection<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
66 }
67
68 public Collection<ActionTakenValue> findByDocumentId(String documentId) {
69 LOG.debug("finding Action Takens by documentId " + documentId);
70 Criteria crit = new Criteria();
71 crit.addEqualTo("documentId", documentId);
72 crit.addEqualTo("currentIndicator", Boolean.TRUE);
73
74 QueryByCriteria qByCrit = new QueryByCriteria(ActionTakenValue.class, crit);
75
76 qByCrit.addOrderByAscending("actionDate");
77
78 return (Collection<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(qByCrit);
79 }
80
81 public List<ActionTakenValue> findByDocumentIdWorkflowId(String documentId, String principalId) {
82 LOG.debug("finding Action Takens by documentId " + documentId + " and principalId" + principalId);
83 Criteria crit = new Criteria();
84 crit.addEqualTo("documentId", documentId);
85 crit.addEqualTo("principalId", principalId);
86 crit.addEqualTo("currentIndicator", Boolean.TRUE);
87 return (List<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
88 }
89
90 public List findByDocumentIdIgnoreCurrentInd(String documentId) {
91 LOG.debug("finding ActionsTaken ignoring currentInd by documentId:" + documentId);
92 Criteria crit = new Criteria();
93 crit.addEqualTo("documentId", documentId);
94 QueryByCriteria qByCrit = new QueryByCriteria(ActionTakenValue.class, crit);
95
96 qByCrit.addOrderByAscending("actionDate");
97 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(qByCrit);
98 }
99
100 public void saveActionTaken(ActionTakenValue actionTaken) {
101 LOG.debug("saving ActionTaken");
102 checkNull(actionTaken.getDocumentId(), "Document ID");
103 checkNull(actionTaken.getActionTaken(), "action taken code");
104 checkNull(actionTaken.getDocVersion(), "doc version");
105 checkNull(actionTaken.getPrincipal(), "user principalId");
106
107 if (actionTaken.getActionDate() == null) {
108 actionTaken.setActionDate(new Timestamp(System.currentTimeMillis()));
109 }
110 if (actionTaken.getCurrentIndicator() == null) {
111 actionTaken.setCurrentIndicator(Boolean.TRUE);
112 }
113 LOG.debug("saving ActionTaken: routeHeader " + actionTaken.getDocumentId() +
114 ", actionTaken " + actionTaken.getActionTaken() + ", principalId " + actionTaken.getPrincipalId());
115 this.getPersistenceBrokerTemplate().store(actionTaken);
116 }
117
118
119 private void checkNull(Object value, String valueName) throws RuntimeException {
120 if (value == null) {
121 throw new RuntimeException("Null value for " + valueName);
122 }
123 }
124
125 public void deleteByDocumentId(String documentId){
126 Criteria crit = new Criteria();
127 crit.addEqualTo("documentId", documentId);
128 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
129 }
130
131 public boolean hasUserTakenAction(String principalId, String documentId) {
132 Criteria crit = new Criteria();
133 crit.addEqualTo("documentId", documentId);
134 crit.addEqualTo("principalId", principalId);
135 crit.addEqualTo("currentIndicator", Boolean.TRUE);
136 int count = getPersistenceBrokerTemplate().getCount(new QueryByCriteria(ActionTakenValue.class, crit));
137 return count > 0;
138 }
139
140 }