1 13 package info.magnolia.module.workflow; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.module.RegisterException; 18 import info.magnolia.cms.util.ContentUtil; 19 import info.magnolia.cms.util.FactoryUtil; 20 import info.magnolia.module.admininterface.AbstractAdminModule; 21 import info.magnolia.module.workflow.flows.FlowDefinitionManager; 22 import info.magnolia.module.workflow.jcr.JCRPersistedEngine; 23 24 import javax.jcr.RepositoryException; 25 26 import openwfe.org.ServiceException; 27 import openwfe.org.engine.impl.expool.SimpleExpressionPool; 28 29 import org.slf4j.Logger; 30 import org.slf4j.LoggerFactory; 31 32 33 40 public class WorkflowModule extends AbstractAdminModule { 41 42 45 public static final String COMMANDS_CATALOG_PATH = "/modules/workflow/config/commands"; 46 47 public static final String CACHE_URL_DEFINITION = "/modules/workflow/config/cache"; 48 49 52 private static Logger log = LoggerFactory.getLogger(WorkflowModule.class); 53 54 57 private static JCRPersistedEngine wfEngine; 58 private static String cacheURL; 59 60 63 protected void onRegister(int registerState) throws RegisterException { 64 Content menu = ContentUtil.getContent(ContentRepository.CONFIG, "/modules/adminInterface/config/menu"); 65 try { 66 menu.orderBefore("inbox", "security"); 67 menu.save(); 68 } 69 catch (RepositoryException e) { 70 log.warn("can't move menupoint", e); 71 } 72 } 73 74 77 protected void onInit() { 78 registerCacheUrl(); 79 startEngine(); 80 } 81 82 public static String getCacheURL() { 83 return cacheURL; 84 } 85 86 private void registerCacheUrl() { 87 Content node = ContentUtil.getContent(ContentRepository.CONFIG, CACHE_URL_DEFINITION); 88 try { 89 if(node!=null && node.hasNodeData("serverURL")) { 90 String serverURL = node.getNodeData("serverURL").getString(); 91 if(serverURL !=null) { 92 cacheURL = serverURL; 93 log.info("Cache server base url for flows is set to:"+cacheURL); 94 } 95 } 96 } catch (Exception e) { 97 98 } 99 } 100 101 104 private void startEngine() { 105 try { 106 log.info("Starting openwfe engine"); 107 wfEngine = new JCRPersistedEngine(); 108 wfEngine.registerParticipant(new MgnlParticipant("user-.*")); 109 wfEngine.registerParticipant(new MgnlParticipant("group-.*")); 110 wfEngine.registerParticipant(new MgnlParticipant("role-.*")); 111 wfEngine.registerParticipant(new MgnlParticipant("command-.*")); 112 } 113 catch (Exception e) { 114 log.error("An exception arised when creating the workflow engine", e); 115 } 116 } 117 118 public void destroy() { 119 JCRPersistedEngine engine = getEngine(); 120 if (engine != null && engine.isRunning()) { 121 log.info("Stopping workflow engine.."); 122 try { 123 ((SimpleExpressionPool) engine.getExpressionPool()).stop(); 125 engine.stop(); 126 } 127 catch (ServiceException se) { 128 log.error("Failed to stop Open WFE engine"); 129 log.error(se.getMessage(), se); 130 } 131 } 132 } 133 134 137 static public JCRPersistedEngine getEngine() { 138 return wfEngine; 139 } 140 141 public static FlowDefinitionManager getFlowDefinitionManager(){ 142 return (FlowDefinitionManager) FactoryUtil.getSingleton(FlowDefinitionManager.class); 143 } 144 145 } | Popular Tags |