| 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.kuali.rice.core.jpa.criteria.Criteria; |
| 20 | |
import org.kuali.rice.core.jpa.criteria.QueryByCriteria; |
| 21 | |
import org.kuali.rice.core.util.OrmUtils; |
| 22 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
| 23 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
| 24 | |
import org.kuali.rice.kew.actiontaken.dao.ActionTakenDAO; |
| 25 | |
|
| 26 | |
import javax.persistence.EntityManager; |
| 27 | |
import javax.persistence.PersistenceContext; |
| 28 | |
import java.io.Serializable; |
| 29 | |
import java.sql.Timestamp; |
| 30 | |
import java.util.Collection; |
| 31 | |
import java.util.List; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public class ActionTakenDAOJpaImpl implements ActionTakenDAO { |
| 40 | |
|
| 41 | |
@PersistenceContext(unitName="kew-unit") |
| 42 | |
private EntityManager entityManager; |
| 43 | |
|
| 44 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionTakenDAOJpaImpl.class); |
| 45 | |
|
| 46 | |
public ActionTakenValue load(Long id) { |
| 47 | 0 | LOG.debug("Loading Action Taken for the given id " + id); |
| 48 | 0 | return entityManager.find(ActionTakenValue.class, id); |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void deleteActionTaken(ActionTakenValue actionTaken) { |
| 52 | 0 | LOG.debug("deleting ActionTaken " + actionTaken.getActionTakenId()); |
| 53 | 0 | entityManager.remove(entityManager.find(ActionTakenValue.class, actionTaken.getActionTakenId())); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
public ActionTakenValue findByActionTakenId(Long actionTakenId) { |
| 57 | 0 | LOG.debug("finding Action Taken by actionTakenId " + actionTakenId); |
| 58 | 0 | Criteria crit = new Criteria(ActionTakenValue.class.getName()); |
| 59 | 0 | crit.eq("actionTakenId", actionTakenId); |
| 60 | 0 | crit.eq("currentIndicator", Boolean.TRUE); |
| 61 | 0 | return (ActionTakenValue) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 62 | |
} |
| 63 | |
|
| 64 | |
public Collection<ActionTakenValue> findByDocIdAndAction(Long routeHeaderId, String action) { |
| 65 | 0 | LOG.debug("finding Action Taken by routeHeaderId " + routeHeaderId + " and action " + action); |
| 66 | 0 | Criteria crit = new Criteria(ActionTakenValue.class.getName()); |
| 67 | 0 | crit.eq("routeHeaderId", routeHeaderId); |
| 68 | 0 | crit.eq("actionTaken", action); |
| 69 | 0 | crit.eq("currentIndicator", Boolean.TRUE); |
| 70 | 0 | return (Collection<ActionTakenValue>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 71 | |
} |
| 72 | |
|
| 73 | |
public Collection<ActionTakenValue> findByRouteHeaderId(Long routeHeaderId) { |
| 74 | 0 | LOG.debug("finding Action Takens by routeHeaderId " + routeHeaderId); |
| 75 | 0 | Criteria crit = new Criteria(ActionTakenValue.class.getName()); |
| 76 | 0 | crit.eq("routeHeaderId", routeHeaderId); |
| 77 | 0 | crit.eq("currentIndicator", Boolean.TRUE); |
| 78 | 0 | return (Collection<ActionTakenValue>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 79 | |
} |
| 80 | |
|
| 81 | |
public List<ActionTakenValue> findByRouteHeaderIdWorkflowId(Long routeHeaderId, String workflowId) { |
| 82 | 0 | LOG.debug("finding Action Takens by routeHeaderId " + routeHeaderId + " and workflowId" + workflowId); |
| 83 | 0 | Criteria crit = new Criteria(ActionTakenValue.class.getName()); |
| 84 | 0 | crit.eq("routeHeaderId", routeHeaderId); |
| 85 | 0 | crit.eq("principalId", workflowId); |
| 86 | 0 | crit.eq("currentIndicator", Boolean.TRUE); |
| 87 | 0 | return (List<ActionTakenValue>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 88 | |
} |
| 89 | |
|
| 90 | |
public List findByRouteHeaderIdIgnoreCurrentInd(Long routeHeaderId) { |
| 91 | 0 | LOG.debug("finding ActionsTaken ignoring currentInd by routeHeaderId:" + routeHeaderId); |
| 92 | 0 | Criteria crit = new Criteria(ActionTakenValue.class.getName()); |
| 93 | 0 | crit.eq("routeHeaderId", routeHeaderId); |
| 94 | 0 | return (List) new QueryByCriteria(entityManager, crit); |
| 95 | |
} |
| 96 | |
|
| 97 | |
public void saveActionTaken(ActionTakenValue actionTaken) { |
| 98 | 0 | LOG.debug("saving ActionTaken"); |
| 99 | 0 | checkNull(actionTaken.getRouteHeaderId(), "Document ID"); |
| 100 | 0 | checkNull(actionTaken.getActionTaken(), "action taken code"); |
| 101 | 0 | checkNull(actionTaken.getDocVersion(), "doc version"); |
| 102 | 0 | checkNull(actionTaken.getPrincipalId(), "principal ID"); |
| 103 | |
|
| 104 | 0 | if (actionTaken.getActionDate() == null) { |
| 105 | 0 | actionTaken.setActionDate(new Timestamp(System.currentTimeMillis())); |
| 106 | |
} |
| 107 | 0 | if (actionTaken.getCurrentIndicator() == null) { |
| 108 | 0 | actionTaken.setCurrentIndicator(Boolean.TRUE); |
| 109 | |
} |
| 110 | 0 | LOG.debug("saving ActionTaken: routeHeader " + actionTaken.getRouteHeaderId() + |
| 111 | |
", actionTaken " + actionTaken.getActionTaken() + ", principalId " + actionTaken.getPrincipalId()); |
| 112 | |
|
| 113 | 0 | if(actionTaken.getActionTakenId()==null){ |
| 114 | 0 | entityManager.persist(actionTaken); |
| 115 | |
}else{ |
| 116 | 0 | OrmUtils.merge(entityManager, actionTaken); |
| 117 | |
} |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
|
| 121 | |
private void checkNull(Serializable value, String valueName) throws RuntimeException { |
| 122 | 0 | if (value == null) { |
| 123 | 0 | throw new RuntimeException("Null value for " + valueName); |
| 124 | |
} |
| 125 | 0 | } |
| 126 | |
|
| 127 | |
public void deleteByRouteHeaderId(Long routeHeaderId){ |
| 128 | 0 | Criteria crit = new Criteria(ActionRequestValue.class.getName()); |
| 129 | 0 | crit.eq("routeHeaderId", routeHeaderId); |
| 130 | 0 | ActionRequestValue actionRequestValue = (ActionRequestValue) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
| 131 | 0 | entityManager.remove(actionRequestValue); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
public boolean hasUserTakenAction(String workflowId, Long routeHeaderId) { |
| 135 | 0 | Criteria crit = new Criteria(ActionTakenValue.class.getName()); |
| 136 | 0 | crit.eq("routeHeaderId", routeHeaderId); |
| 137 | 0 | crit.eq("principalId", workflowId); |
| 138 | 0 | crit.eq("currentIndicator", Boolean.TRUE); |
| 139 | 0 | int count = (Integer) new QueryByCriteria(entityManager, crit).toCountQuery().getSingleResult(); |
| 140 | 0 | return count > 0; |
| 141 | |
} |
| 142 | |
|
| 143 | |
public EntityManager getEntityManager() { |
| 144 | 0 | return this.entityManager; |
| 145 | |
} |
| 146 | |
|
| 147 | |
public void setEntityManager(EntityManager entityManager) { |
| 148 | 0 | this.entityManager = entityManager; |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
} |