1   /*
2    * Copyright 2003 - 2013 The eFaps Team
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Revision:        $Rev$
17   * Last Changed:    $Date$
18   * Last Changed By: $Author$
19   */
20  
21  package org.efaps.bpm.runtime;
22  
23  import javax.persistence.EntityManagerFactory;
24  
25  import org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment;
26  import org.jbpm.services.task.HumanTaskServiceFactory;
27  import org.jbpm.services.task.audit.JPATaskLifeCycleEventListener;
28  import org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener;
29  import org.kie.api.runtime.manager.RuntimeEnvironment;
30  import org.kie.api.task.TaskService;
31  import org.kie.internal.runtime.manager.TaskServiceFactory;
32  
33  /**
34   * TODO comment!
35   *
36   * @author The eFaps Team
37   * @version $Id$
38   */
39  public class LocalTaskServiceFactoryImpl
40      implements TaskServiceFactory
41  {
42  
43      /**
44       * RuntimeEnvironment.
45       */
46      private final RuntimeEnvironment runtimeEnvironment;
47  
48      /**
49       * @param _runtimeEnvironment RuntimeEnvironment to be used
50       */
51      public LocalTaskServiceFactoryImpl(final RuntimeEnvironment _runtimeEnvironment)
52      {
53          this.runtimeEnvironment = _runtimeEnvironment;
54      }
55  
56      @Override
57      public TaskService newTaskService()
58      {
59          final EntityManagerFactory emf = ((SimpleRuntimeEnvironment) this.runtimeEnvironment).getEmf();
60          TaskService ret = null;
61          if (emf != null) {
62              ret = HumanTaskServiceFactory.newTaskServiceConfigurator()
63                          .environment(this.runtimeEnvironment.getEnvironment())
64                          .entityManagerFactory(emf)
65                          .listener(new JPATaskLifeCycleEventListener(true))
66                          .listener(new BAMTaskEventListener(true))
67                          .userGroupCallback(this.runtimeEnvironment.getUserGroupCallback())
68                          .getTaskService();
69          }
70          return ret;
71      }
72  
73      @Override
74      public void close()
75      {
76          // no action required
77      }
78  }