001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actionitem.dao;
018:
019: import java.sql.Timestamp;
020: import java.util.Collection;
021: import java.util.Date;
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.Map;
025:
026: import org.apache.ojb.broker.query.Criteria;
027: import org.apache.ojb.broker.query.QueryByCriteria;
028: import org.apache.ojb.broker.query.QueryFactory;
029: import org.apache.ojb.broker.query.ReportQueryByCriteria;
030: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
031:
032: import edu.iu.uis.eden.KEWServiceLocator;
033: import edu.iu.uis.eden.actionitem.ActionItem;
034: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
035: import edu.iu.uis.eden.user.UserService;
036: import edu.iu.uis.eden.user.WorkflowUser;
037: import edu.iu.uis.eden.user.WorkflowUserId;
038: import edu.iu.uis.eden.workgroup.WorkflowGroupId;
039: import edu.iu.uis.eden.workgroup.WorkgroupService;
040:
041: /**
042: * OJB implementation of {@link ActionItemDAO}.
043: *
044: * @author rkirkend
045: * @author ewestfal
046: */
047: public class ActionItemDAOOjbImpl extends PersistenceBrokerDaoSupport
048: implements ActionItemDAO {
049:
050: public ActionItem findByActionItemId(Long actionItemId) {
051: Criteria crit = new Criteria();
052: crit.addEqualTo("actionItemId", actionItemId);
053: return (ActionItem) this .getPersistenceBrokerTemplate()
054: .getObjectByQuery(
055: new QueryByCriteria(ActionItem.class, crit));
056: }
057:
058: public void deleteActionItems(Long actionRequestId) {
059: Criteria crit = new Criteria();
060: crit.addEqualTo("actionRequestId", actionRequestId);
061: this .getPersistenceBrokerTemplate().deleteByQuery(
062: new QueryByCriteria(ActionItem.class, crit));
063: }
064:
065: public void deleteActionItem(ActionItem actionItem) {
066: this .getPersistenceBrokerTemplate().delete(actionItem);
067: }
068:
069: public void deleteByRouteHeaderIdWorkflowUserId(Long routeHeaderId,
070: String workflowUserId) {
071: Criteria crit = new Criteria();
072: crit.addEqualTo("routeHeaderId", routeHeaderId);
073: crit.addEqualTo("workflowId", workflowUserId);
074: this .getPersistenceBrokerTemplate().deleteByQuery(
075: new QueryByCriteria(ActionItem.class, crit));
076: }
077:
078: public void deleteByRouteHeaderId(Long routeHeaderId) {
079: Criteria crit = new Criteria();
080: crit.addEqualTo("routeHeaderId", routeHeaderId);
081: this .getPersistenceBrokerTemplate().deleteByQuery(
082: new QueryByCriteria(ActionItem.class, crit));
083: }
084:
085: public Collection findByWorkflowUser(WorkflowUser workflowUser) {
086: Criteria crit = new Criteria();
087: crit.addEqualTo("workflowId", workflowUser.getWorkflowUserId()
088: .getWorkflowId());
089: QueryByCriteria query = new QueryByCriteria(ActionItem.class,
090: crit);
091: query.addOrderByAscending("routeHeader.routeHeaderId");
092: return this .getPersistenceBrokerTemplate()
093: .getCollectionByQuery(query);
094: }
095:
096: public Collection findByWorkflowUserRouteHeaderId(
097: String workflowId, Long routeHeaderId) {
098: Criteria crit = new Criteria();
099: crit.addEqualTo("workflowId", workflowId);
100: crit.addEqualTo("routeHeaderId", routeHeaderId);
101: return this .getPersistenceBrokerTemplate()
102: .getCollectionByQuery(
103: new QueryByCriteria(ActionItem.class, crit));
104: }
105:
106: public Collection findByRouteHeaderId(Long routeHeaderId) {
107: Criteria crit = new Criteria();
108: crit.addEqualTo("routeHeaderId", routeHeaderId);
109: return this .getPersistenceBrokerTemplate()
110: .getCollectionByQuery(
111: new QueryByCriteria(ActionItem.class, crit));
112: }
113:
114: public Collection findByActionRequestId(Long actionRequestId) {
115: Criteria crit = new Criteria();
116: crit.addEqualTo("actionRequestId", actionRequestId);
117: return this .getPersistenceBrokerTemplate()
118: .getCollectionByQuery(
119: new QueryByCriteria(ActionItem.class, crit));
120: }
121:
122: public void saveActionItem(ActionItem actionItem) {
123: if (actionItem.getDateAssigned() == null) {
124: actionItem.setDateAssigned(new Timestamp(new Date()
125: .getTime()));
126: }
127: this .getPersistenceBrokerTemplate().store(actionItem);
128: }
129:
130: public Collection findDelegators(WorkflowUser user,
131: String delegationType) throws EdenUserNotFoundException {
132: Criteria notNullWorkflowCriteria = new Criteria();
133: notNullWorkflowCriteria.addNotNull("delegatorWorkflowId");
134: Criteria notNullWorkgroupCriteria = new Criteria();
135: notNullWorkgroupCriteria.addNotNull("delegatorWorkgroupId");
136: Criteria orCriteria = new Criteria();
137: orCriteria.addOrCriteria(notNullWorkflowCriteria);
138: orCriteria.addOrCriteria(notNullWorkgroupCriteria);
139: Criteria criteria = new Criteria();
140: criteria.addEqualTo("workflowId", user.getWorkflowUserId()
141: .getWorkflowId());
142: if (delegationType != null && !"".equals(delegationType)) {
143: criteria.addEqualTo("delegationType", delegationType);
144: }
145: criteria.addAndCriteria(orCriteria);
146: ReportQueryByCriteria query = QueryFactory.newReportQuery(
147: ActionItem.class, criteria);
148:
149: query.setAttributes(new String[] { "delegatorWorkflowId",
150: "delegatorWorkgroupId" });
151: Map delegators = new HashMap();
152: Iterator iterator = this .getPersistenceBrokerTemplate()
153: .getReportQueryIteratorByQuery(query);
154: while (iterator.hasNext()) {
155: Object[] ids = (Object[]) iterator.next();
156: if (ids[0] != null
157: && !delegators.containsKey((String) ids[0])) {
158: delegators.put((String) ids[0], getUserService()
159: .getWorkflowUser(
160: new WorkflowUserId((String) ids[0])));
161: } else if (ids[1] != null) {
162: Long workgroupId = new Long(ids[1].toString());
163: if (!delegators.containsKey(workgroupId)) {
164: delegators.put(workgroupId, getWorkgroupService()
165: .getWorkgroup(
166: new WorkflowGroupId(workgroupId)));
167: }
168: }
169: }
170: return delegators.values();
171: }
172:
173: private UserService getUserService() {
174: return (UserService) KEWServiceLocator
175: .getService(KEWServiceLocator.USER_SERVICE);
176: }
177:
178: private WorkgroupService getWorkgroupService() {
179: return (WorkgroupService) KEWServiceLocator
180: .getService(KEWServiceLocator.WORKGROUP_SRV);
181: }
182:
183: }
|