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
88 System.setProperty("openwfe.xml.encoding", "UTF-8");
89 instance = this;
90 startEngine();
91 initializeWorkItemStore();
92 }
93
94 @Override
95 public void stop(ModuleLifecycleContext moduleLifecycleContext) {
96 JCRPersistedEngine engine = getEngine();
97 if (engine != null && engine.isRunning()) {
98 log.info("Stopping workflow engine..");
99 try {
100
101
102 ((SimpleExpressionPool) engine.getExpressionPool()).stop();
103 engine.stop();
104 }
105 catch (ServiceException se) {
106 log.error("Failed to stop Open WFE engine");
107 log.error(se.getMessage(), se);
108 }
109 }
110 }
111
112
113
114
115 private boolean cleanup = true;
116
117 protected void startEngine() {
118 try {
119 log.info("Starting openwfe engine");
120 wfEngine = new JCRPersistedEngine();
121 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_USER+".*"));
122 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_GROUP+".*"));
123 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_ROLE+".*"));
124 wfEngine.registerParticipant(new MgnlParticipant(WorkflowConstants.PARTICIPANT_PREFIX_COMMAND+".*"));
125 }
126 catch (Exception e) {
127 log.error("An exception arised when creating the workflow engine", e);
128 }
129 }
130
131 protected void initializeWorkItemStore() {
132 try {
133 workItemStore = new JCRWorkItemStore(this.isUseLifeTimeJCRSession(), this.isCleanup(), this.isBackupWorkItems());
134 }
135 catch (Exception e) {
136 log.error("can't initialize the workflow util", e);
137 }
138 }
139
140
141
142
143 static public JCRPersistedEngine getEngine() {
144 return instance.wfEngine;
145 }
146
147
148
149
150 static public JCRWorkItemStore getWorkItemStore() {
151 return instance.workItemStore;
152 }
153
154 public static FlowDefinitionManager getFlowDefinitionManager() {
155 return Components.getSingleton(FlowDefinitionManager.class);
156 }
157
158
159 public boolean isBackupWorkItems() {
160 return this.backupWorkItems;
161 }
162
163
164 public void setBackupWorkItems(boolean backupWorkItems) {
165 this.backupWorkItems = backupWorkItems;
166 }
167
168 public boolean isUseLifeTimeJCRSession() {
169 return useLifeTimeJCRSession;
170 }
171
172 public void setUseLifeTimeJCRSession(boolean useLifeTimeJCRSession) {
173 log.warn("Setting useLifeTimeJCRSession flag should not be used unless you really know what you do.");
174
175 this.useLifeTimeJCRSession = useLifeTimeJCRSession;
176 }
177
178 public boolean isCleanup() {
179 return cleanup;
180 }
181
182 public void setCleanup(boolean cleanup) {
183 log.warn("Setting cleanup flag should not be used unless you really know what you do.");
184 this.cleanup = cleanup;
185 }
186
187
188
189
190 public static WorkflowModule getInstance() {
191 DeprecationUtil.isDeprecated("Use IoC!");
192 return instance;
193 }
194
195 }