1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.workflow;
35
36 import info.magnolia.cms.util.DeprecationUtil;
37 import info.magnolia.module.ModuleLifecycle;
38 import info.magnolia.module.ModuleLifecycleContext;
39 import info.magnolia.module.workflow.flows.FlowDefinitionManager;
40 import info.magnolia.module.workflow.jcr.JCRPersistedEngine;
41 import info.magnolia.module.workflow.jcr.JCRWorkItemStore;
42 import info.magnolia.objectfactory.Components;
43 import openwfe.org.ServiceException;
44 import openwfe.org.engine.impl.expool.SimpleExpressionPool;
45
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49
50
51
52
53
54
55
56
57
58 public class WorkflowModule implements ModuleLifecycle {
59
60 private static final Logger log = LoggerFactory.getLogger(WorkflowModule.class);
61
62
63
64
65 private static WorkflowModule instance;
66
67
68
69
70 private JCRPersistedEngine wfEngine;
71
72 private JCRWorkItemStore workItemStore;
73
74
75
76
77 private boolean backupWorkItems = false;
78
79
80
81
82 private boolean useLifeTimeJCRSession = true;
83
84
85 @Override
86 public void start(ModuleLifecycleContext moduleLifecycleContext) {
87 instance = this;
88 startEngine();
89 initializeWorkItemStore();
90 }
91
92 @Override
93 public void stop(ModuleLifecycleContext moduleLifecycleContext) {
94 JCRPersistedEngine engine = getEngine();
95 if (engine != null && engine.isRunning()) {
96 log.info("Stopping workflow engine..");
97 try {
98
99
100 ((SimpleExpressionPool) engine.getExpressionPool()).stop();
101 engine.stop();
102 }
103 catch (ServiceException se) {
104 log.error("Failed to stop Open WFE engine");
105 log.error(se.getMessage(), se);
106 }
107 }
108 }
109
110
111
112
113 private boolean cleanup = true;
114
115 protected void startEngine() {
116 try {
117 log.info("Starting openwfe engine");
118 wfEngine = new JCRPersistedEngine();
119 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_USER+".*"));
120 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_GROUP+".*"));
121 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_ROLE+".*"));
122 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_COMMAND+".*"));
123 }
124 catch (Exception e) {
125 log.error("An exception arised when creating the workflow engine", e);
126 }
127 }
128
129 protected void initializeWorkItemStore() {
130 try {
131 workItemStore = new JCRWorkItemStore(this.isUseLifeTimeJCRSession(), this.isCleanup(), this.isBackupWorkItems());
132 }
133 catch (Exception e) {
134 log.error("can't initialize the workflow util", e);
135 }
136 }
137
138
139
140
141 static public JCRPersistedEngine getEngine() {
142 return instance.wfEngine;
143 }
144
145
146
147
148 static public JCRWorkItemStore getWorkItemStore() {
149 return instance.workItemStore;
150 }
151
152 public static FlowDefinitionManager getFlowDefinitionManager() {
153 return Components.getSingleton(FlowDefinitionManager.class);
154 }
155
156
157 public boolean isBackupWorkItems() {
158 return this.backupWorkItems;
159 }
160
161
162 public void setBackupWorkItems(boolean backupWorkItems) {
163 this.backupWorkItems = backupWorkItems;
164 }
165
166 public boolean isUseLifeTimeJCRSession() {
167 return useLifeTimeJCRSession;
168 }
169
170 public void setUseLifeTimeJCRSession(boolean useLifeTimeJCRSession) {
171 log.warn("Setting useLifeTimeJCRSession flag should not be used unless you really know what you do.");
172
173 this.useLifeTimeJCRSession = useLifeTimeJCRSession;
174 }
175
176 public boolean isCleanup() {
177 return cleanup;
178 }
179
180 public void setCleanup(boolean cleanup) {
181 log.warn("Setting cleanup flag should not be used unless you really know what you do.");
182 this.cleanup = cleanup;
183 }
184
185
186
187
188 public static WorkflowModule getInstance() {
189 DeprecationUtil.isDeprecated("Use IoC!");
190 return instance;
191 }
192
193 }