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 return (Collection<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
74 }
75
76 public List<ActionTakenValue> findByDocumentIdWorkflowId(String documentId, String principalId) {
77 LOG.debug("finding Action Takens by documentId " + documentId + " and principalId" + principalId);
78 Criteria crit = new Criteria();
79 crit.addEqualTo("documentId", documentId);
80 crit.addEqualTo("principalId", principalId);
81 crit.addEqualTo("currentIndicator", Boolean.TRUE);
82 return (List<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
83 }
84
85 public List findByDocumentIdIgnoreCurrentInd(String documentId) {
86 LOG.debug("finding ActionsTaken ignoring currentInd by documentId:" + documentId);
87 Criteria crit = new Criteria();
88 crit.addEqualTo("documentId", documentId);
89 return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit));
90 }
91
92 public void saveActionTaken(ActionTakenValue actionTaken) {
93 LOG.debug("saving ActionTaken");
94 checkNull(actionTaken.getDocumentId(), "Document ID");
95 checkNull(actionTaken.getActionTaken(), "action taken code");
96 checkNull(actionTaken.getDocVersion(), "doc version");
97 checkNull(actionTaken.getPrincipal(), "user principalId");
98
99 if (actionTaken.getActionDate() == null) {
100 actionTaken.setActionDate(new Timestamp(System.currentTimeMillis()));
101 }
102 if (actionTaken.getCurrentIndicator() == null) {
103 actionTaken.setCurrentIndicator(Boolean.TRUE);
104 }
105 LOG.debug("saving ActionTaken: routeHeader " + actionTaken.getDocumentId() +
106 ", actionTaken " + actionTaken.getActionTaken() + ", principalId " + actionTaken.getPrincipalId());
107 this.getPersistenceBrokerTemplate().store(actionTaken);
108 }
109
110
111 private void checkNull(Object value, String valueName) throws RuntimeException {
112 if (value == null) {
113 throw new RuntimeException("Null value for " + valueName);
114 }
115 }
116
117 public void deleteByDocumentId(String documentId){
118 Criteria crit = new Criteria();
119 crit.addEqualTo("documentId", documentId);
120 this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
121 }
122
123 public boolean hasUserTakenAction(String principalId, String documentId) {
124 Criteria crit = new Criteria();
125 crit.addEqualTo("documentId", documentId);
126 crit.addEqualTo("principalId", principalId);
127 crit.addEqualTo("currentIndicator", Boolean.TRUE);
128 int count = getPersistenceBrokerTemplate().getCount(new QueryByCriteria(ActionTakenValue.class, crit));
129 return count > 0;
130 }
131
132 }