WflEndAction.java
package com.mycim.webapp.actions.operation;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.mycim.framework.context.spring.SpringContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.CollectionUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.server.ocap.service.OcapService;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.prp.Operation;
import com.mycim.valueobject.wip.Job;
import com.mycim.valueobject.wip.Lot;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.WipSetupAction;
import com.mycim.webapp.forms.RootForm;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
public final class WflEndAction extends WipSetupAction {
private OcapService ocapService = SpringContext.getBean(OcapService.class);
@Override
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
RootForm theform = (RootForm) form;
HashMap parameters = (HashMap) request.getAttribute(SessionNames.PARAMETERSINFO_KEY);
List lots = (List) request.getAttribute(SessionNames.COLLECTION_KEY);
if (CollectionUtils.isEmpty(lots)) {
lots = (List) WebUtils.getCacheString2Obj(theform.getCacheCollection());
}
request.setAttribute("currentlots", lots);
String ocapFLag = MapUtils.getString(parameters, SessionNames.OCAP_FLAG);
if (MapUtils.getBooleanValue(parameters, SessionNames.LABISSUE_FLAG, false)) {
return mapping.findForward("labissueEnd");
} else {
// redirect to the login page if there is no session
Job job = (Job) request.getAttribute(SessionNames.JOB_KEY);
// add by ben 2005-04-12
String sysbusy = request.getParameter("sysbusy");
if (sysbusy != null && sysbusy.equalsIgnoreCase("Y")) {
return (mapping.findForward("sysbusy"));
}
// end by ben 2005-04-12
Assert.isFalse(job == null, Errors.create().content("Parameters are not enough!").build());
clearupExcutionInfo(job);
String type = getWFLType(request.getParameter("WFL_RRN"), job.getOperationRrn());
if (parameters.get("binning") != null && parameters.get("binning").toString().equalsIgnoreCase("true")) {
return (mapping.findForward("showbinninginfo"));
}
if (type == null) {
return (mapping.findForward("success"));
} else if (type.equals("movein")) {
if (StringUtils.isNotBlank(request.getParameter("automovein"))) {
request.setAttribute("automovein", "automovein");
}
clearProcessStepInfosFromSession(request);
if (request.getAttribute("wfldetail") != null && request.getAttribute("wfldetail").equals("moveout")) {
return (mapping.findForward("shownextstepinfo"));
} else {
return (mapping.findForward("showcurrentstepinfo"));
}
} else if (type.equals("moveout")) {
if (StringUtils.isNotBlank(request.getParameter("automoveout"))) {
request.setAttribute("automoveout", "automoveout");
}
clearProcessStepInfosFromSession(request);
return (mapping.findForward("shownextstepinfo"));
} else {
return (mapping.findForward("success"));
}
}
}
/**
* @param request
*/
private void clearProcessStepInfosFromSession(HttpServletRequest request) {
Object processNextStepInfos = request.getAttribute(SessionNames.PROCESS_NEXT_STEP_INFO_KEY);
Collection processNextStepInfosCopy = new ArrayList();
if (processNextStepInfos != null) {
Collection processNextStepInfosCollection = (Collection) processNextStepInfos;
Iterator iterator = processNextStepInfosCollection.iterator();
while (iterator.hasNext()) {
Map infoMap = (Map) iterator.next();
String lotRrn = MapUtils.getString(infoMap, "lotRrn");
Lot lot = lotQueryService.getLot(Long.parseLong(lotRrn));
infoMap.put("operationId", lot.getOperationId());
Map lotinfo = new HashMap();
lotinfo.put("lotRrn", lotRrn);
processNextStepInfosCopy.add(infoMap);
}
}
request.setAttribute(SessionNames.PROCESS_NEXT_STEP_INFO_KEY, processNextStepInfosCopy);
}
private String getWFLType(String wflRrn, Long operationRrn) {
String wflType = "movein";
Operation o = prpService.getOperation(operationRrn);
Assert.isFalse(o == null, Errors.create().key(MessageIdList.OPERATION_MISSING).content("Error Step!").build());
if (o.getMvinWflRrn() != null && o.getMvinWflRrn().equals(new Long(wflRrn))) {
wflType = "movein";
} else if (o.getMvouWflRrn() != null && o.getMvouWflRrn().equals(new Long(wflRrn))) {
wflType = "moveout";
} else if (o.getAbortWflRrn() != null && o.getAbortWflRrn().equals(new Long(wflRrn))) {
wflType = "moveout";
} else {
wflType = "moveout";
}
return wflType;
}
private void clearupExcutionInfo(Job job) {
wipService.clearUpExecutionInfo(job.getJobRrn());
}
}