1 4 package info.magnolia.module.workflow.flows; 5 6 import info.magnolia.cms.util.ClasspathResourcesUtil; 7 import info.magnolia.module.workflow.WorkflowConstants; 8 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 import openwfe.org.engine.workitem.LaunchItem; 15 16 import org.apache.commons.io.IOUtils; 17 import org.apache.commons.lang.StringUtils; 18 import org.slf4j.Logger; 19 import org.slf4j.LoggerFactory; 20 21 22 28 public class SimpleFlowDefinitionManager implements FlowDefinitionManager { 29 30 33 private static Logger log = LoggerFactory.getLogger(SimpleFlowDefinitionManager.class); 34 35 public void configure(LaunchItem launchItem, String workflowName) throws FlowDefinionException { 36 if(!StringUtils.equals(workflowName, WorkflowConstants.DEFAULT_WORKFLOW)){ 37 throw new FlowDefinionException("only default workflow supported in Community Edition, will fallback to default flow"); 38 } 39 40 launchItem.setWorkflowDefinitionUrl(WorkflowConstants.ATTRIBUTE_WORKFLOW_DEFINITION_URL); 41 String flowDef = readDefinition(WorkflowConstants.DEFAULT_WORKFLOW); 42 launchItem.getAttributes().puts(WorkflowConstants.ATTRIBUTE_DEFINITION, flowDef); 43 } 44 45 public String readDefinition(String workflowName) throws FlowDefinionException{ 46 if(!StringUtils.equals(workflowName, WorkflowConstants.DEFAULT_WORKFLOW)){ 47 throw new FlowDefinionException("only default workflow supported in Community Edition, will fallback to default flow"); 48 } 49 50 InputStream stream = null; 51 try { 52 stream = ClasspathResourcesUtil.getStream("info/magnolia/module/workflow/default.xml"); 53 return IOUtils.toString(stream); 54 } 55 catch (IOException e) { 56 log.error("can't read flow definition", e); 57 } 58 finally{ 59 IOUtils.closeQuietly(stream); 60 } 61 return StringUtils.EMPTY; 62 } 63 64 public void saveDefinition(String definition) throws FlowDefinionException { 65 throw new FlowDefinionException("saving of workflow definitions is not supported in the Community Edition"); 66 } 67 68 public List getDefinitionNames() { 69 List list = new ArrayList (); 70 list.add("default"); 71 return list; 72 } 73 } 74 | Popular Tags |