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.actiontaken;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.WorkflowServiceErrorException;
027: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
028: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
029: import edu.iu.uis.eden.actiontaken.dao.ActionTakenDAO;
030: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
031: import edu.iu.uis.eden.routeheader.RouteHeaderService;
032: import edu.iu.uis.eden.user.UserService;
033: import edu.iu.uis.eden.user.WorkflowUser;
034: import edu.iu.uis.eden.user.WorkflowUserId;
035: import edu.iu.uis.eden.workgroup.WorkgroupService;
036:
037: /**
038: * Default implementation of the {@link ActionTakenService}.
039: *
040: * @author rkirkend
041: * @author ewestfal
042: */
043: public class ActionTakenServiceImpl implements ActionTakenService {
044: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(ActionTakenServiceImpl.class);
046: private ActionTakenDAO actionTakenDAO;
047:
048: public ActionTakenValue load(Long id) {
049: return getActionTakenDAO().load(id);
050: }
051:
052: public ActionTakenValue findByActionTakenId(Long actionTakenId) {
053: return getActionTakenDAO().findByActionTakenId(actionTakenId);
054: }
055:
056: public ActionTakenValue getPreviousAction(
057: ActionRequestValue actionRequest)
058: throws EdenUserNotFoundException {
059: return getPreviousAction(actionRequest, null);
060: }
061:
062: public ActionTakenValue getPreviousAction(
063: ActionRequestValue actionRequest, List simulatedActionsTaken)
064: throws EdenUserNotFoundException {
065:
066: ActionTakenValue foundActionTaken = null;
067: List users = new ArrayList();
068: if (actionRequest.isWorkgroupRequest()) {
069: users.addAll(actionRequest.getWorkgroup().getUsers());
070: } else if (actionRequest.isUserRequest()) {
071: users.add(actionRequest.getWorkflowUser());
072: }
073:
074: for (Iterator iter = users.iterator(); iter.hasNext();) {
075: WorkflowUser user = (WorkflowUser) iter.next();
076: List actionsTakenByUser = getActionTakenDAO()
077: .findByRouteHeaderIdWorkflowId(
078: actionRequest.getRouteHeaderId(),
079: user.getWorkflowUserId().getWorkflowId());
080: if (simulatedActionsTaken != null) {
081: actionsTakenByUser.addAll(simulatedActionsTaken);
082: }
083:
084: for (Iterator iterator = actionsTakenByUser.iterator(); iterator
085: .hasNext();) {
086: ActionTakenValue actionTaken = (ActionTakenValue) iterator
087: .next();
088: if (ActionRequestValue.compareActionCode(actionTaken
089: .getActionTaken(), actionRequest
090: .getActionRequested()) >= 0) {
091: foundActionTaken = actionTaken;
092: }
093: }
094: }
095:
096: return foundActionTaken;
097: }
098:
099: public Collection findByDocIdAndAction(Long docId, String action) {
100: return getActionTakenDAO().findByDocIdAndAction(docId, action);
101: }
102:
103: public Collection findByRouteHeaderId(Long routeHeaderId) {
104: return getActionTakenDAO().findByRouteHeaderId(routeHeaderId);
105: }
106:
107: public List findByRouteHeaderIdWorkflowId(Long routeHeaderId,
108: String workflowId) {
109: return getActionTakenDAO().findByRouteHeaderIdWorkflowId(
110: routeHeaderId, workflowId);
111: }
112:
113: public Collection getActionsTaken(Long routeHeaderId) {
114: return getActionTakenDAO().findByRouteHeaderId(routeHeaderId);
115: }
116:
117: public List findByRouteHeaderIdIgnoreCurrentInd(Long routeHeaderId) {
118: return getActionTakenDAO().findByRouteHeaderIdIgnoreCurrentInd(
119: routeHeaderId);
120: }
121:
122: public void saveActionTaken(ActionTakenValue actionTaken) {
123: this .getActionTakenDAO().saveActionTaken(actionTaken);
124: }
125:
126: public void delete(ActionTakenValue actionTaken) {
127: getActionTakenDAO().deleteActionTaken(actionTaken);
128: }
129:
130: public ActionTakenDAO getActionTakenDAO() {
131: return actionTakenDAO;
132: }
133:
134: public void setActionTakenDAO(ActionTakenDAO actionTakenDAO) {
135: this .actionTakenDAO = actionTakenDAO;
136: }
137:
138: public WorkgroupService getWorkgroupService() {
139: return (WorkgroupService) KEWServiceLocator
140: .getService(KEWServiceLocator.WORKGROUP_SRV);
141: }
142:
143: public void deleteByRouteHeaderId(Long routeHeaderId) {
144: actionTakenDAO.deleteByRouteHeaderId(routeHeaderId);
145: }
146:
147: public void validateActionTaken(ActionTakenValue actionTaken) {
148: LOG.debug("Enter validateActionTaken(..)");
149: List errors = new ArrayList();
150:
151: Long routeHeaderId = actionTaken.getRouteHeaderId();
152: if (routeHeaderId == null) {
153: errors.add(new WorkflowServiceErrorImpl(
154: "ActionTaken routeheaderid null.",
155: "actiontaken.routeheaderid.empty", actionTaken
156: .getActionTakenId().toString()));
157: } else if (getRouteHeaderService()
158: .getRouteHeader(routeHeaderId) == null) {
159: errors.add(new WorkflowServiceErrorImpl(
160: "ActionTaken routeheaderid invalid.",
161: "actiontaken.routeheaderid.invalid", actionTaken
162: .getActionTakenId().toString()));
163: }
164:
165: String userId = actionTaken.getWorkflowId();
166: if (userId == null || userId.trim().equals("")) {
167: errors.add(new WorkflowServiceErrorImpl(
168: "ActionTaken personid null.",
169: "actiontaken.personid.empty", actionTaken
170: .getActionTakenId().toString()));
171: } else {
172: try {
173: getUserService().getWorkflowUser(
174: new WorkflowUserId(userId));
175: } catch (EdenUserNotFoundException e) {
176: errors.add(new WorkflowServiceErrorImpl(
177: "ActionTaken personid invalid.",
178: "actiontaken.personid.invalid", actionTaken
179: .getActionTakenId().toString()));
180: }
181: }
182: String actionTakenCd = actionTaken.getActionTaken();
183: if (actionTakenCd == null || actionTakenCd.trim().equals("")) {
184: errors.add(new WorkflowServiceErrorImpl(
185: "ActionTaken cd null.",
186: "actiontaken.actiontaken.empty", actionTaken
187: .getActionTakenId().toString()));
188: } else if (!EdenConstants.ACTION_TAKEN_CD
189: .containsKey(actionTakenCd)) {
190: errors.add(new WorkflowServiceErrorImpl(
191: "ActionTaken invalid.",
192: "actiontaken.actiontaken.invalid", actionTaken
193: .getActionTakenId().toString()));
194: }
195: if (actionTaken.getActionDate() == null) {
196: errors.add(new WorkflowServiceErrorImpl(
197: "ActionTaken actiondate null.",
198: "actiontaken.actiondate.empty", actionTaken
199: .getActionTakenId().toString()));
200: }
201:
202: if (actionTaken.getDocVersion() == null) {
203: errors.add(new WorkflowServiceErrorImpl(
204: "ActionTaken docversion null.",
205: "actiontaken.docverion.empty", actionTaken
206: .getActionTakenId().toString()));
207: }
208: LOG.debug("Exit validateActionRequest(..) ");
209: if (!errors.isEmpty()) {
210: throw new WorkflowServiceErrorException(
211: "ActionRequest Validation Error", errors);
212: }
213: }
214:
215: private RouteHeaderService getRouteHeaderService() {
216: return (RouteHeaderService) KEWServiceLocator
217: .getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
218: }
219:
220: private UserService getUserService() {
221: return (UserService) KEWServiceLocator
222: .getService(KEWServiceLocator.USER_SERVICE);
223: }
224: }
|