| 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 | 0 | public class ActionTakenDAOOjbImpl extends PersistenceBrokerDaoSupport implements ActionTakenDAO { |
| 37 | |
|
| 38 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenDAOOjbImpl.class); |
| 39 | |
|
| 40 | |
public ActionTakenValue load(String id) { |
| 41 | 0 | LOG.debug("Loading Action Taken for the given id " + id); |
| 42 | 0 | Criteria crit = new Criteria(); |
| 43 | 0 | crit.addEqualTo("actionTakenId", id); |
| 44 | 0 | return (ActionTakenValue) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 45 | |
} |
| 46 | |
|
| 47 | |
public void deleteActionTaken(ActionTakenValue actionTaken) { |
| 48 | 0 | LOG.debug("deleting ActionTaken " + actionTaken.getActionTakenId()); |
| 49 | 0 | this.getPersistenceBrokerTemplate().delete(actionTaken); |
| 50 | 0 | } |
| 51 | |
|
| 52 | |
public ActionTakenValue findByActionTakenId(String actionTakenId) { |
| 53 | 0 | LOG.debug("finding Action Taken by actionTakenId " + actionTakenId); |
| 54 | 0 | Criteria crit = new Criteria(); |
| 55 | 0 | crit.addEqualTo("actionTakenId", actionTakenId); |
| 56 | 0 | crit.addEqualTo("currentIndicator", Boolean.TRUE); |
| 57 | 0 | return (ActionTakenValue) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 58 | |
} |
| 59 | |
|
| 60 | |
public Collection<ActionTakenValue> findByDocIdAndAction(String documentId, String action) { |
| 61 | 0 | LOG.debug("finding Action Taken by documentId " + documentId + " and action " + action); |
| 62 | 0 | Criteria crit = new Criteria(); |
| 63 | 0 | crit.addEqualTo("documentId", documentId); |
| 64 | 0 | crit.addEqualTo("actionTaken", action); |
| 65 | 0 | crit.addEqualTo("currentIndicator", Boolean.TRUE); |
| 66 | 0 | return (Collection<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 67 | |
} |
| 68 | |
|
| 69 | |
public Collection<ActionTakenValue> findByDocumentId(String documentId) { |
| 70 | 0 | LOG.debug("finding Action Takens by documentId " + documentId); |
| 71 | 0 | Criteria crit = new Criteria(); |
| 72 | 0 | crit.addEqualTo("documentId", documentId); |
| 73 | 0 | crit.addEqualTo("currentIndicator", Boolean.TRUE); |
| 74 | 0 | return (Collection<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 75 | |
} |
| 76 | |
|
| 77 | |
public List<ActionTakenValue> findByDocumentIdWorkflowId(String documentId, String principalId) { |
| 78 | 0 | LOG.debug("finding Action Takens by documentId " + documentId + " and principalId" + principalId); |
| 79 | 0 | Criteria crit = new Criteria(); |
| 80 | 0 | crit.addEqualTo("documentId", documentId); |
| 81 | 0 | crit.addEqualTo("principalId", principalId); |
| 82 | 0 | crit.addEqualTo("currentIndicator", Boolean.TRUE); |
| 83 | 0 | return (List<ActionTakenValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 84 | |
} |
| 85 | |
|
| 86 | |
public List findByDocumentIdIgnoreCurrentInd(String documentId) { |
| 87 | 0 | LOG.debug("finding ActionsTaken ignoring currentInd by documentId:" + documentId); |
| 88 | 0 | Criteria crit = new Criteria(); |
| 89 | 0 | crit.addEqualTo("documentId", documentId); |
| 90 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 91 | |
} |
| 92 | |
|
| 93 | |
public void saveActionTaken(ActionTakenValue actionTaken) { |
| 94 | 0 | LOG.debug("saving ActionTaken"); |
| 95 | 0 | checkNull(actionTaken.getDocumentId(), "Document ID"); |
| 96 | 0 | checkNull(actionTaken.getActionTaken(), "action taken code"); |
| 97 | 0 | checkNull(actionTaken.getDocVersion(), "doc version"); |
| 98 | 0 | checkNull(actionTaken.getPrincipal(), "user principalId"); |
| 99 | |
|
| 100 | 0 | if (actionTaken.getActionDate() == null) { |
| 101 | 0 | actionTaken.setActionDate(new Timestamp(System.currentTimeMillis())); |
| 102 | |
} |
| 103 | 0 | if (actionTaken.getCurrentIndicator() == null) { |
| 104 | 0 | actionTaken.setCurrentIndicator(Boolean.TRUE); |
| 105 | |
} |
| 106 | 0 | LOG.debug("saving ActionTaken: routeHeader " + actionTaken.getDocumentId() + |
| 107 | |
", actionTaken " + actionTaken.getActionTaken() + ", principalId " + actionTaken.getPrincipalId()); |
| 108 | 0 | this.getPersistenceBrokerTemplate().store(actionTaken); |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
|
| 112 | |
private void checkNull(Object value, String valueName) throws RuntimeException { |
| 113 | 0 | if (value == null) { |
| 114 | 0 | throw new RuntimeException("Null value for " + valueName); |
| 115 | |
} |
| 116 | 0 | } |
| 117 | |
|
| 118 | |
public void deleteByDocumentId(String documentId){ |
| 119 | 0 | Criteria crit = new Criteria(); |
| 120 | 0 | crit.addEqualTo("documentId", documentId); |
| 121 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit)); |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
public boolean hasUserTakenAction(String principalId, String documentId) { |
| 125 | 0 | Criteria crit = new Criteria(); |
| 126 | 0 | crit.addEqualTo("documentId", documentId); |
| 127 | 0 | crit.addEqualTo("principalId", principalId); |
| 128 | 0 | crit.addEqualTo("currentIndicator", Boolean.TRUE); |
| 129 | 0 | int count = getPersistenceBrokerTemplate().getCount(new QueryByCriteria(ActionTakenValue.class, crit)); |
| 130 | 0 | return count > 0; |
| 131 | |
} |
| 132 | |
|
| 133 | |
} |