1 24 25 package org.infoglue.cms.controllers.kernel.impl.simple; 26 27 import java.util.ArrayList ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 33 import javax.servlet.http.HttpServletRequest ; 34 35 import org.apache.log4j.Logger; 36 import org.exolab.castor.jdo.Database; 37 import org.infoglue.cms.entities.kernel.BaseEntityVO; 38 import org.infoglue.cms.entities.mydesktop.WorkflowActionVO; 39 import org.infoglue.cms.entities.mydesktop.WorkflowVO; 40 import org.infoglue.cms.exception.Bug; 41 import org.infoglue.cms.exception.SystemException; 42 import org.infoglue.cms.security.InfoGluePrincipal; 43 import org.infoglue.cms.util.CmsPropertyHandler; 44 import org.infoglue.cms.util.workflow.WorkflowFacade; 45 46 import com.opensymphony.module.propertyset.PropertySet; 47 import com.opensymphony.workflow.WorkflowException; 48 49 54 public class WorkflowController extends BaseController 55 { 56 private final static Logger logger = Logger.getLogger(UserPropertiesController.class.getName()); 57 58 private static final WorkflowController controller = new WorkflowController(); 59 60 64 public static WorkflowController getController() 65 { 66 return controller; 67 } 68 69 private WorkflowController() {} 70 71 74 public static Map createWorkflowParameters(final HttpServletRequest request) 75 { 76 final Map parameters = new HashMap (); 77 parameters.putAll(request.getParameterMap()); 78 parameters.put("request", request); 79 return parameters; 80 } 81 82 90 public WorkflowVO initializeWorkflow(InfoGluePrincipal principal, String name, int actionId, Map inputs) throws SystemException 91 { 92 try 93 { 94 if(getIsAccessApproved(name, principal)) 95 { 96 return new WorkflowFacade(principal, name, actionId, inputs).createWorkflowVO(); 97 } 98 throw new Bug("You are not allowed to create " + name + " workflows."); 99 } 100 catch (Exception e) 101 { 102 throw new SystemException(e); 103 } 104 } 105 106 111 public List getAvailableWorkflowVOList(InfoGluePrincipal userPrincipal) throws SystemException 112 { 113 final List allWorkflows = new WorkflowFacade(userPrincipal).getDeclaredWorkflows(); 114 final List accessibleWorkflows = new ArrayList (); 115 for(final Iterator i = allWorkflows.iterator(); i.hasNext(); ) 116 { 117 final WorkflowVO workflowVO = (WorkflowVO) i.next(); 118 if(getIsAccessApproved(workflowVO.getName(), userPrincipal)) 119 { 120 accessibleWorkflows.add(workflowVO); 121 } 122 } 123 124 return accessibleWorkflows; 125 } 126 127 130 131 public boolean getIsAccessApproved(String workflowName, InfoGluePrincipal infoGluePrincipal) throws SystemException 132 { 133 final String protectWorkflows = CmsPropertyHandler.getProtectWorkflows(); 134 if(protectWorkflows == null || !protectWorkflows.equalsIgnoreCase("true")) 135 { 136 return true; 137 } 138 139 logger.info("getIsAccessApproved for " + workflowName + " AND " + infoGluePrincipal); 140 boolean hasAccess = false; 141 142 Database db = CastorDatabaseService.getDatabase(); 143 beginTransaction(db); 144 145 try 146 { 147 hasAccess = AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "Workflow.Create", workflowName); 148 commitTransaction(db); 149 } 150 catch(Exception e) 151 { 152 logger.error("An error occurred so we should not complete the transaction:" + e, e); 153 rollbackTransaction(db); 154 throw new SystemException(e.getMessage()); 155 } 156 157 return hasAccess; 158 } 159 160 166 public List getCurrentWorkflowVOList(InfoGluePrincipal userPrincipal) throws SystemException 167 { 168 return new WorkflowFacade(userPrincipal).getActiveWorkflows(); 169 } 170 171 178 public List getMyCurrentWorkflowVOList(InfoGluePrincipal userPrincipal) throws SystemException 179 { 180 return new WorkflowFacade(userPrincipal).getMyActiveWorkflows(userPrincipal); 181 } 182 183 184 193 public WorkflowVO invokeAction(InfoGluePrincipal principal, long workflowId, int actionId, Map inputs) throws WorkflowException 194 { 195 WorkflowFacade workflow = new WorkflowFacade(principal, workflowId); 196 workflow.doAction(actionId, inputs); 197 return workflow.createWorkflowVO(); 198 } 199 200 204 public PropertySet getPropertySet(InfoGluePrincipal userPrincipal, long workflowId) 205 { 206 return new WorkflowFacade(userPrincipal, workflowId).getPropertySet(); 207 } 208 209 215 public Map getProperties(InfoGluePrincipal userPrincipal, long workflowId) 216 { 217 logger.info("userPrincipal:" + userPrincipal); 218 logger.info("workflowId:" + workflowId); 219 220 PropertySet propertySet = getPropertySet(userPrincipal, workflowId); 221 Map parameters = new HashMap (); 222 for (Iterator keys = getPropertySet(userPrincipal, workflowId).getKeys().iterator(); keys.hasNext();) 223 { 224 String key = (String )keys.next(); 225 parameters.put(key, propertySet.getString(key)); 226 } 227 228 return parameters; 229 } 230 231 237 public List getHistorySteps(InfoGluePrincipal userPrincipal, long workflowId) 238 { 239 return new WorkflowFacade(userPrincipal, workflowId).getHistorySteps(); 240 } 241 242 248 public List getCurrentSteps(InfoGluePrincipal userPrincipal, long workflowId) 249 { 250 return new WorkflowFacade(userPrincipal, workflowId).getCurrentSteps(); 251 } 252 253 260 public List getAllSteps(InfoGluePrincipal userPrincipal, long workflowId) 261 { 262 return new WorkflowFacade(userPrincipal, workflowId).getDeclaredSteps(); 263 } 264 265 270 public BaseEntityVO getNewVO() 271 { 272 return new WorkflowActionVO(); 273 } 274 } 275 | Popular Tags |