1 19 20 package za.org.coefficient.interceptors; 21 22 import za.co.csir.icomtek.workflow.WorkflowData; 23 24 import za.org.coefficient.core.CoefficientInterceptor; 25 import za.org.coefficient.core.Project; 26 import za.org.coefficient.interfaces.CoefficientContext; 27 import za.org.coefficient.util.common.InvokerFactory; 28 29 34 public class ProjectSetupInterceptor extends CoefficientInterceptor { 35 37 private static final String PROJECT_ID = "projectId"; 38 private static final String CURRENT_WORKFLOW = "__current_workflow_data__"; 39 public static final String CURRENT_PROJECT = "__current_project__"; 40 41 43 protected int handleInvoke(CoefficientContext ctx) throws Exception { 44 int retVal = INVOKE_PROCESS_CHILD; 45 Long projectId = ctx.getParameterAsLong(PROJECT_ID, -1); 46 Project project = null; 47 String clearProject = ctx.getParameter("clearProject"); 48 WorkflowData wd = null; 49 if (projectId.longValue() > 0) { 50 project = (Project) ctx.getSessionAttribute(CURRENT_PROJECT); 51 if ((project == null) || !project.getId().equals(projectId) 52 || clearProject != null) { 53 project = (Project)InvokerFactory.getRemoteInvoker() 55 .invokeMethodOnModule("Project", "findProjectByPK", 56 new Object [] {projectId}); 57 58 wd = (WorkflowData)InvokerFactory.getRemoteInvoker() 60 .invokeMethodOnService("Project", "findWorkflowDataByLinkId", 61 new Object []{project.getId()}); 62 ctx.setProject(project); 63 ctx.setSessionAttribute(CURRENT_WORKFLOW, wd); 64 } 65 } else if (clearProject == null) { 66 project = (Project) ctx.getSessionAttribute(CURRENT_PROJECT); 67 wd = (WorkflowData) ctx.getSessionAttribute(CURRENT_WORKFLOW); 68 } else { 69 ctx.removeSessionAttribute(CURRENT_WORKFLOW); 70 ctx.removeSessionAttribute(CURRENT_PROJECT); 71 } 72 73 if ((project != null) && project.getIsWorkflow()) { 75 if (wd != null) { 76 Object context = InvokerFactory.getRemoteInvoker() 77 .invokeMethodOnService("WorkflowEvaluatorFacade", 78 "determineState", new Object []{ctx, wd}); 79 if(context instanceof CoefficientContext) { 80 ctx = (CoefficientContext)context; 81 } 82 ctx.setSessionAttribute(CURRENT_WORKFLOW, wd); 84 } 85 } 86 87 return retVal; 88 } 89 } 90 | Popular Tags |