View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.flowable.support;
20  
21  import java.util.Collections;
22  import java.util.Map;
23  import javax.sql.DataSource;
24  import org.apache.syncope.core.spring.security.AuthContextUtils;
25  import org.flowable.engine.DynamicBpmnService;
26  import org.flowable.engine.FormService;
27  import org.flowable.engine.HistoryService;
28  import org.flowable.engine.IdentityService;
29  import org.flowable.engine.ManagementService;
30  import org.flowable.engine.ProcessEngine;
31  import org.flowable.engine.ProcessEngineConfiguration;
32  import org.flowable.engine.ProcessMigrationService;
33  import org.flowable.engine.RepositoryService;
34  import org.flowable.engine.RuntimeService;
35  import org.flowable.engine.TaskService;
36  import org.flowable.engine.impl.ProcessEngineImpl;
37  
38  /**
39   * {@link ProcessEngine} delegating actual method invocation to the inner map of {@link ProcessEngine} instances,
40   * one for each Syncope domain.
41   */
42  public class DomainProcessEngine implements ProcessEngine {
43  
44      private final Map<String, ProcessEngine> engines;
45  
46      public DomainProcessEngine(final Map<String, ProcessEngine> engines) {
47          this.engines = Collections.synchronizedMap(engines);
48      }
49  
50      public Map<String, ProcessEngine> getEngines() {
51          return engines;
52      }
53  
54      @Override
55      public String getName() {
56          return engines.get(AuthContextUtils.getDomain()).getName();
57      }
58  
59      @Override
60      public void close() {
61          engines.values().forEach(ProcessEngine::close);
62      }
63  
64      @Override
65      public RepositoryService getRepositoryService() {
66          return engines.get(AuthContextUtils.getDomain()).getRepositoryService();
67      }
68  
69      @Override
70      public RuntimeService getRuntimeService() {
71          return engines.get(AuthContextUtils.getDomain()).getRuntimeService();
72      }
73  
74      @Override
75      public FormService getFormService() {
76          return engines.get(AuthContextUtils.getDomain()).getFormService();
77      }
78  
79      @Override
80      public TaskService getTaskService() {
81          return engines.get(AuthContextUtils.getDomain()).getTaskService();
82      }
83  
84      @Override
85      public HistoryService getHistoryService() {
86          return engines.get(AuthContextUtils.getDomain()).getHistoryService();
87      }
88  
89      @Override
90      public IdentityService getIdentityService() {
91          return engines.get(AuthContextUtils.getDomain()).getIdentityService();
92      }
93  
94      @Override
95      public ManagementService getManagementService() {
96          return engines.get(AuthContextUtils.getDomain()).getManagementService();
97      }
98  
99      @Override
100     public ProcessEngineConfiguration getProcessEngineConfiguration() {
101         return engines.get(AuthContextUtils.getDomain()).getProcessEngineConfiguration();
102     }
103 
104     @Override
105     public DynamicBpmnService getDynamicBpmnService() {
106         return engines.get(AuthContextUtils.getDomain()).getDynamicBpmnService();
107     }
108 
109     @Override
110     public ProcessMigrationService getProcessMigrationService() {
111         return engines.get(AuthContextUtils.getDomain()).getProcessMigrationService();
112     }
113 
114     @Override
115     public void startExecutors() {
116         engines.get(AuthContextUtils.getDomain()).startExecutors();
117     }
118 
119     public DataSource getDataSource() {
120         ProcessEngineImpl engine = (ProcessEngineImpl) engines.get(AuthContextUtils.getDomain());
121         return engine.getProcessEngineConfiguration().getDataSource();
122     }
123 }