1 13 package info.magnolia.module.workflow.commands; 14 15 import info.magnolia.cms.util.FactoryUtil; 16 import info.magnolia.commands.MgnlCommand; 17 import info.magnolia.context.Context; 18 import info.magnolia.context.MgnlContext; 19 import info.magnolia.context.WebContextImpl; 20 import info.magnolia.module.workflow.WorkflowConstants; 21 import info.magnolia.module.workflow.WorkflowModule; 22 import info.magnolia.module.workflow.WorkflowUtil; 23 import info.magnolia.module.workflow.flows.FlowDefinionException; 24 import info.magnolia.module.workflow.flows.FlowDefinitionManager; 25 26 import java.io.InputStream ; 27 import java.io.Serializable ; 28 import java.net.URL ; 29 import java.net.URLConnection ; 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.Map ; 33 34 import javax.servlet.http.HttpServletRequest ; 35 36 import openwfe.org.engine.workitem.AttributeUtils; 37 import openwfe.org.engine.workitem.LaunchItem; 38 import openwfe.org.engine.workitem.StringMapAttribute; 39 40 import org.slf4j.Logger; 41 import org.slf4j.LoggerFactory; 42 43 44 public class FlowCommand extends MgnlCommand { 45 46 49 private String workflowName = WorkflowConstants.DEFAULT_WORKFLOW; 50 51 private static Logger log = LoggerFactory.getLogger(FlowCommand.class); 52 53 public boolean execute(Context ctx) throws FlowDefinionException { 54 LaunchItem li = new LaunchItem(); 56 prepareLaunchItem(ctx, li); 57 WorkflowUtil.launchFlow(li, getWorkflowName()); 58 return true; 59 } 60 61 66 public void prepareLaunchItem(Context context, LaunchItem launchItem) { 67 Map map = context.getAttributes(Context.LOCAL_SCOPE); 68 Map serializableMap = new HashMap (); 70 for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { 71 Object key = iter.next(); 72 Object val = map.get(key); 73 if (val instanceof Serializable ) { 74 serializableMap.put(key, val); 75 } 76 } 77 serializableMap.put(WorkflowConstants.ATTRIBUTE_USERNAME, context.getUser().getName()); 78 StringMapAttribute attrs = AttributeUtils.java2attributes(serializableMap); 79 launchItem.setAttributes(attrs); 80 } 81 82 public String getWorkflowName() { 83 return workflowName; 84 } 85 86 public void setWorkflowName(String flowName) { 87 this.workflowName = flowName; 88 } 89 } 90 | Popular Tags |