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.routelog.web;
018:
019: import java.util.Collections;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.struts.action.ActionForm;
027: import org.apache.struts.action.ActionForward;
028: import org.apache.struts.action.ActionMapping;
029: import org.apache.struts.action.ActionMessages;
030:
031: import edu.iu.uis.eden.EdenConstants;
032: import edu.iu.uis.eden.KEWServiceLocator;
033: import edu.iu.uis.eden.actionrequests.ActionRequestService;
034: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
035: import edu.iu.uis.eden.actiontaken.ActionTakenValue;
036: import edu.iu.uis.eden.engine.simulation.SimulationCriteria;
037: import edu.iu.uis.eden.engine.simulation.SimulationEngine;
038: import edu.iu.uis.eden.engine.simulation.SimulationResults;
039: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
040: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
041: import edu.iu.uis.eden.util.Utilities;
042: import edu.iu.uis.eden.web.WorkflowAction;
043:
044: /**
045: * A Struts Action used to display the routelog.
046: *
047: * @author rkirkend
048: * @author temay
049: */
050: public class RouteLogAction extends WorkflowAction {
051:
052: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
053: .getLogger(RouteLogAction.class);
054:
055: public ActionForward start(ActionMapping mapping, ActionForm form,
056: HttpServletRequest request, HttpServletResponse response)
057: throws Exception {
058:
059: RouteLogForm rlForm = (RouteLogForm) form;
060: Long routeHeaderId = null;
061: if (!Utilities.isEmpty(rlForm.getRouteHeaderId())) {
062: routeHeaderId = new Long(rlForm.getRouteHeaderId());
063: } else if (!Utilities.isEmpty(rlForm.getDocId())) {
064: routeHeaderId = new Long(rlForm.getDocId());
065: } else {
066: throw new WorkflowRuntimeException(
067: "No paramater provided to fetch document");
068: }
069:
070: DocumentRouteHeaderValue routeHeader = KEWServiceLocator
071: .getRouteHeaderService().getRouteHeader(routeHeaderId);
072: for (Iterator iter = routeHeader.getActionsTaken().iterator(); iter
073: .hasNext();) {
074: ActionTakenValue actionTaken = (ActionTakenValue) iter
075: .next();
076: Collections.sort((List) actionTaken.getActionRequests(),
077: new Utilities().new RouteLogActionRequestSorter());
078: }
079:
080: populateRouteLogFormActionRequests(rlForm, routeHeader);
081:
082: rlForm.setLookFuture(routeHeader.getDocumentType()
083: .getLookIntoFuturePolicy().getPolicyValue()
084: .booleanValue());
085:
086: if (rlForm.isShowFuture()) {
087: try {
088: populateRouteLogFutureRequests(rlForm, routeHeader);
089: } catch (Exception e) {
090: String errorMsg = "Found Error while getting Future Action Requests: "
091: + e.getMessage();
092: LOG.info(errorMsg, e);
093: rlForm.setShowFutureError(errorMsg);
094: }
095: }
096:
097: if (routeHeader.isLocked()) {
098: return mapping.findForward("documentLocked");
099: }
100:
101: request.setAttribute("routeHeader", routeHeader);
102: return mapping.findForward("viewRouteLog");
103: }
104:
105: public void populateRouteLogFormActionRequests(RouteLogForm rlForm,
106: DocumentRouteHeaderValue routeHeader) {
107: List rootRequests = getActionRequestService().getRootRequests(
108: routeHeader.getActionRequests());
109: Collections.sort(rootRequests,
110: new Utilities().new RouteLogActionRequestSorter());
111: int arCount = 0;
112: for (Iterator iterator = rootRequests.iterator(); iterator
113: .hasNext();) {
114: ActionRequestValue actionRequest = (ActionRequestValue) iterator
115: .next();
116: if (actionRequest.isPending()) {
117: arCount++;
118:
119: if (EdenConstants.ACTION_REQUEST_INITIALIZED
120: .equals(actionRequest.getStatus())) {
121: actionRequest.setDisplayStatus("PENDING");
122: } else if (EdenConstants.ACTION_REQUEST_ACTIVATED
123: .equals(actionRequest.getStatus())) {
124: actionRequest.setDisplayStatus("IN ACTION LIST");
125: }
126: }
127: }
128: rlForm.setRootRequests(rootRequests);
129: rlForm.setPendingActionRequestCount(arCount);
130: }
131:
132: private void populateRouteLogFutureRequests(RouteLogForm rlForm,
133: DocumentRouteHeaderValue document) throws Exception {
134: SimulationEngine simEngine = new SimulationEngine();
135: SimulationResults simResults = simEngine
136: .runSimulation(new SimulationCriteria(document
137: .getRouteHeaderId()));
138: // should now be sorted list
139: List rootRequests = getActionRequestService().getRootRequests(
140: simResults.getSimulatedActionRequests());
141: Collections.sort(rootRequests,
142: new Utilities().new RouteLogActionRequestSorter());
143: int arCount = 0;
144: for (Iterator iterator = rootRequests.iterator(); iterator
145: .hasNext();) {
146: ActionRequestValue actionRequest = (ActionRequestValue) iterator
147: .next();
148: if (actionRequest.isPending()) {
149: arCount++;
150:
151: if (EdenConstants.ACTION_REQUEST_INITIALIZED
152: .equals(actionRequest.getStatus())) {
153: actionRequest.setDisplayStatus("PENDING");
154: } else if (EdenConstants.ACTION_REQUEST_ACTIVATED
155: .equals(actionRequest.getStatus())) {
156: actionRequest.setDisplayStatus("IN ACTION LIST");
157: }
158: }
159: }
160: rlForm.setFutureRootRequests(rootRequests);
161: rlForm.setFutureActionRequestCount(arCount);
162: }
163:
164: public ActionMessages establishRequiredState(
165: HttpServletRequest request, ActionForm form)
166: throws Exception {
167: return null;
168: }
169:
170: private ActionRequestService getActionRequestService() {
171: return (ActionRequestService) KEWServiceLocator
172: .getService(KEWServiceLocator.ACTION_REQUEST_SRV);
173: }
174: }
|