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