From 9d10081c5b09d65944d3448c7655803ec31666f9 Mon Sep 17 00:00:00 2001 From: Emmanuel Duchastenier Date: Mon, 4 Sep 2023 10:08:05 +0200 Subject: [PATCH] chore(accessor): stop using deprecated TenantServiceAccessor (#2676) use ServiceAccessor instead Also, I deprecated TenantServiceSingleton in favor of new class ServiceAccessorSingleton --- .../PermissionCachingBenchmark.java | 4 +- .../TransactionSynchronizationBenchmark.java | 10 +- .../bonitasoft/engine/profile/ProfileIT.java | 1 + .../java/org/bonitasoft/engine/SQLUtils.java | 8 +- .../installer/ApplicationInstallerIT.java | 6 +- .../ApplicationInstallerUpdateIT.java | 6 +- .../engine/bpm/RecoveryMechanismIT.java | 6 +- .../connector/ConnectorExecutionsLocalIT.java | 22 +- .../bpm/process/DeleteProcessInstancesIT.java | 30 +- .../business/data/BDRepositoryLocalIT.java | 14 +- .../bonitasoft/engine/job/JobExecutionIT.java | 25 +- .../tenant/TenantMaintenanceLocalIT.java | 12 +- .../bonitasoft/engine/test/BPMLocalIT.java | 55 +- .../engine/test/CommonAPILocalIT.java | 13 +- .../engine/test/PermissionAPIIT.java | 6 +- .../engine/test/ProcessArchiveIT.java | 10 +- .../test/ProcessWithExpressionLocalIT.java | 30 +- .../servlet/BonitaServletContextListener.java | 69 - .../bonitasoft/engine/api/impl/APIUtils.java | 8 +- .../engine/api/impl/ApplicationAPIImpl.java | 78 +- .../engine/api/impl/BusinessDataAPIImpl.java | 15 +- .../engine/api/impl/CommandAPIImpl.java | 91 +- .../engine/api/impl/DocumentAPIImpl.java | 136 +- .../engine/api/impl/IdentityAPIImpl.java | 350 ++-- .../engine/api/impl/LoginAPIImpl.java | 14 +- .../engine/api/impl/OrganizationAPIImpl.java | 36 +- .../engine/api/impl/PageAPIImpl.java | 37 +- .../engine/api/impl/PermissionAPIImpl.java | 14 +- .../engine/api/impl/ProcessAPIImpl.java | 1638 ++++++++--------- .../api/impl/ProcessConfigurationAPIImpl.java | 21 +- .../impl/ProcessDeploymentAPIDelegate.java | 39 +- .../api/impl/ProcessInvolvementDelegate.java | 33 +- .../ProcessManagementAPIImplDelegate.java | 43 +- .../engine/api/impl/ProcessStarter.java | 28 +- .../engine/api/impl/ServerAPIImpl.java | 27 +- .../engine/api/impl/SessionInfos.java | 3 +- .../api/impl/TaskInvolvementDelegate.java | 30 +- .../api/impl/TenantAdministrationAPIImpl.java | 52 +- .../installer/ApplicationInstaller.java | 51 +- .../LivingApplicationAPIDelegate.java | 19 +- .../LivingApplicationMenuAPIDelegate.java | 19 +- .../LivingApplicationPageAPIDelegate.java | 24 +- .../organization/OrganizationAPIDelegate.java | 4 +- .../engine/api/impl/page/PageAPIDelegate.java | 74 +- .../api/impl/profile/ProfileAPIDelegate.java | 35 +- .../BusinessArchiveArtifactsManager.java | 24 +- .../bonitasoft/engine/command/Command.java | 3 +- .../connector/ConnectorAPIAccessorImpl.java | 10 +- .../ArchiveProcessInstancesHandler.java | 3 +- .../work/ExecuteConnectorOfActivity.java | 36 +- .../work/ExecuteConnectorOfProcess.java | 28 +- .../execution/work/ExecuteConnectorWork.java | 40 +- .../execution/work/ExecuteFlowNodeWork.java | 25 +- .../work/ExecuteMessageCoupleWork.java | 16 +- .../execution/work/InSessionBonitaWork.java | 18 +- .../work/LockProcessInstanceWork.java | 2 +- .../work/NotifyChildFinishedWork.java | 26 +- .../execution/work/TenantAwareBonitaWork.java | 8 +- .../engine/execution/work/TxBonitaWork.java | 6 +- ...wNodeDefinitionAndInstanceContextWork.java | 6 +- .../ProcessDefinitionContextWork.java | 6 +- .../ProcessInstanceContextWork.java | 6 +- .../failurewrapping/TriggerSignalWork.java | 8 +- .../TxInHandleFailureWrappingWork.java | 16 +- .../bonitasoft/engine/jobs/InternalJob.java | 8 +- .../engine/jobs/TriggerTimerEventJob.java | 10 +- .../engine/platform/PlatformManager.java | 4 +- .../ProcessEngineServicesResolver.java | 3 +- .../service/ServiceAccessorSingleton.java | 45 + .../service/TenantServiceSingleton.java | 2 + .../service/impl/SpringServiceAccessor.java | 9 +- .../service/impl/SpringServiceAccessors.java | 14 +- .../tenant/ChangesServicesStateCallable.java | 12 +- .../api/impl/BusinessDataAPIImplTest.java | 6 +- .../engine/api/impl/IdentityAPIImplTest.java | 8 +- .../api/impl/OrganizationAPIImplTest.java | 8 +- .../api/impl/PermissionAPIImplTest.java | 8 +- .../engine/api/impl/ProcessAPIImplTest.java | 179 +- .../ProcessDeploymentAPIDelegateTest.java | 2 +- .../impl/ProcessInvolvementDelegateTest.java | 8 +- .../ProcessManagementAPIImplDelegateTest.java | 12 +- .../engine/api/impl/ServerAPIImplTest.java | 22 +- .../api/impl/TaskInvolvementDelegateTest.java | 12 +- .../impl/TenantAdministrationAPIImplTest.java | 20 +- .../LivingApplicationAPIDelegateTest.java | 4 +- .../LivingApplicationMenuAPIDelegateTest.java | 8 +- .../LivingApplicationPageAPIDelegateTest.java | 9 +- .../api/impl/page/PageAPIDelegateTest.java | 65 +- ...ataBusinessArchiveArtifactManagerTest.java | 6 +- ...FormMappingAndPageArtifactManagerTest.java | 26 +- .../AdvancedStartProcessCommandTest.java | 4 +- .../command/ExecuteBDMQueryCommandTest.java | 16 +- .../GetBusinessDataByIdCommandTest.java | 20 +- .../GetBusinessDataByIdsCommandTest.java | 14 +- .../GetBusinessDataByQueryCommandTest.java | 22 +- .../work/ExecuteConnectorOfActivityTest.java | 6 +- .../work/ExecuteConnectorWorkTest.java | 32 +- .../work/ExecuteFlowNodeWorkTest.java | 10 +- .../work/ExecuteMessageCoupleWorkTest.java | 31 +- .../work/InSessionBonitaWorkTest.java | 45 +- .../work/LockProcessInstanceWorkTest.java | 22 +- .../work/NotifyChildFinishedWorkTest.java | 16 +- .../execution/work/TxBonitaWorkTest.java | 19 +- .../AbstractContextWorkTest.java | 42 +- ...rDefinitionAndInstanceContextWorkTest.java | 23 +- ...eDefinitionAndInstanceContextWorkTest.java | 8 +- .../MessageInstanceContextWorkTest.java | 7 +- .../ProcessDefinitionContextWorkTest.java | 10 +- .../ProcessInstanceContextWorkTest.java | 14 +- .../TriggerSignalWorkTest.java | 22 +- .../CustomUserInfoDefinitionImporterTest.java | 4 - .../engine/identity/UserImporterTest.java | 44 +- .../engine/jobs/TriggerTimerEventJobTest.java | 20 +- .../activity/SearchActivityInstancesTest.java | 4 - 114 files changed, 2031 insertions(+), 2467 deletions(-) delete mode 100644 bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/BonitaServletContextListener.java create mode 100644 bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ServiceAccessorSingleton.java diff --git a/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/PermissionCachingBenchmark.java b/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/PermissionCachingBenchmark.java index 451fa504985..0300ca93eaf 100644 --- a/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/PermissionCachingBenchmark.java +++ b/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/PermissionCachingBenchmark.java @@ -16,7 +16,7 @@ import org.bonitasoft.engine.authorization.properties.ConfigurationFilesManager; import org.bonitasoft.engine.authorization.properties.ResourcesPermissionsMapping; import org.bonitasoft.engine.cache.CacheService; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.test.TestEngine; import org.bonitasoft.engine.test.TestEngineImpl; import org.openjdk.jmh.annotations.Benchmark; @@ -36,7 +36,7 @@ public class PermissionCachingBenchmark { public void setup() throws Exception { engine = TestEngineImpl.getInstance(); engine.start(); - cacheService = TenantServiceSingleton.getInstance().getCacheService(); + cacheService = ServiceAccessorSingleton.getInstance().getCacheService(); resourcesPermissionsMapping = new ResourcesPermissionsMapping(1L, cacheService, new ConfigurationFilesManager()); } diff --git a/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/TransactionSynchronizationBenchmark.java b/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/TransactionSynchronizationBenchmark.java index 665b81298c3..03bf0afe710 100644 --- a/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/TransactionSynchronizationBenchmark.java +++ b/bonita-integration-tests/benchmarks/src/jmh/java/org/bonitasoft/engine/benchmarks/TransactionSynchronizationBenchmark.java @@ -17,7 +17,8 @@ import java.util.concurrent.CompletableFuture; import org.bonitasoft.engine.execution.work.BPMWorkFactory; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.test.TestEngine; import org.bonitasoft.engine.test.TestEngineImpl; import org.bonitasoft.engine.transaction.UserTransactionService; @@ -41,9 +42,10 @@ public class TransactionSynchronizationBenchmark { public void setup() throws Exception { engine = TestEngineImpl.getInstance(); engine.start(); - userTransactionService = TenantServiceSingleton.getInstance().getUserTransactionService(); - workService = TenantServiceSingleton.getInstance().getWorkService(); - BPMWorkFactory bpmWorkFactory = TenantServiceSingleton.getInstance().getBPMWorkFactory(); + final ServiceAccessor serviceAccessor = ServiceAccessorSingleton.getInstance(); + userTransactionService = serviceAccessor.getUserTransactionService(); + workService = serviceAccessor.getWorkService(); + BPMWorkFactory bpmWorkFactory = serviceAccessor.getBPMWorkFactory(); bpmWorkFactory.addExtension("BENCHMARK_WORK", workDescriptor -> new BonitaWork() { @Override diff --git a/bonita-integration-tests/bonita-integration-tests-client/src/test/java/org/bonitasoft/engine/profile/ProfileIT.java b/bonita-integration-tests/bonita-integration-tests-client/src/test/java/org/bonitasoft/engine/profile/ProfileIT.java index aefe916afe3..24d8020ccf8 100644 --- a/bonita-integration-tests/bonita-integration-tests-client/src/test/java/org/bonitasoft/engine/profile/ProfileIT.java +++ b/bonita-integration-tests/bonita-integration-tests-client/src/test/java/org/bonitasoft/engine/profile/ProfileIT.java @@ -135,6 +135,7 @@ private void shouldProfileMemberOperation_update_profile_metadata(final ProfileM // when logoutOnTenant(); loginOnDefaultTenantWith("userName3", "User3Pwd"); + Thread.sleep(10); final ProfileMember createProfileMember = getProfileAPI().createProfileMember(creator); // then diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/SQLUtils.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/SQLUtils.java index 31b070fc818..d5e1f79b787 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/SQLUtils.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/SQLUtils.java @@ -18,7 +18,7 @@ import org.bonitasoft.engine.persistence.AbstractHibernatePersistenceService; import org.bonitasoft.engine.persistence.ReadPersistenceService; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.hibernate.SessionFactory; public class SQLUtils { @@ -26,12 +26,12 @@ public class SQLUtils { private static SessionFactory sessionFactory; public static List query(String query) throws Exception { - return TenantServiceSingleton.getInstance().getUserTransactionService() + return ServiceAccessorSingleton.getInstance().getUserTransactionService() .executeInTransaction(() -> getSessionFactory().getCurrentSession().createSQLQuery(query).list()); } public static int execute(String query) throws Exception { - return TenantServiceSingleton.getInstance().getUserTransactionService() + return ServiceAccessorSingleton.getInstance().getUserTransactionService() .executeInTransaction( () -> getSessionFactory().getCurrentSession().createSQLQuery(query).executeUpdate()); } @@ -44,7 +44,7 @@ private static SessionFactory getSessionFactory() throws NoSuchFieldException, I } private static SessionFactory createSessionFactory() throws NoSuchFieldException, IllegalAccessException { - ReadPersistenceService persistenceService = TenantServiceSingleton.getInstance().getReadPersistenceService(); + ReadPersistenceService persistenceService = ServiceAccessorSingleton.getInstance().getReadPersistenceService(); Field sessionFactoryField = AbstractHibernatePersistenceService.class.getDeclaredField("sessionFactory"); sessionFactoryField.setAccessible(true); return (SessionFactory) sessionFactoryField.get(persistenceService); diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerIT.java index eda3f6b0ea2..62929b12096 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerIT.java @@ -37,7 +37,7 @@ import org.bonitasoft.engine.business.application.ApplicationNotFoundException; import org.bonitasoft.engine.exception.ApplicationInstallationException; import org.bonitasoft.engine.identity.User; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -65,7 +65,7 @@ public void custom_application_should_be_deployed_entirely() throws Exception { // given: final InputStream applicationAsStream = this.getClass().getResourceAsStream("/customer-application.zip"); - ApplicationInstaller applicationInstallerImpl = TenantServiceSingleton.getInstance() + ApplicationInstaller applicationInstallerImpl = ServiceAccessorSingleton.getInstance() .lookup(ApplicationInstaller.class); final ApplicationArchiveReader applicationArchiveReader = new ApplicationArchiveReader( new ArtifactTypeDetector(new BdmDetector(), @@ -104,7 +104,7 @@ public void custom_application_should_be_deployed_entirely() throws Exception { public void empty_custom_application_should_throw_an_exception() throws Exception { // given: final InputStream applicationAsStream = this.getClass().getResourceAsStream("/empty-customer-application.zip"); - ApplicationInstaller applicationInstaller = TenantServiceSingleton.getInstance() + ApplicationInstaller applicationInstaller = ServiceAccessorSingleton.getInstance() .lookup(ApplicationInstaller.class); final ApplicationArchiveReader applicationArchiveReader = new ApplicationArchiveReader( new ArtifactTypeDetector(new BdmDetector(), diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerUpdateIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerUpdateIT.java index c0aa03a280b..8f2f8d92c23 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerUpdateIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/application/installer/ApplicationInstallerUpdateIT.java @@ -37,7 +37,7 @@ import org.bonitasoft.engine.page.Page; import org.bonitasoft.engine.page.PageNotFoundException; import org.bonitasoft.engine.search.SearchOptionsBuilder; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.tenant.TenantResource; import org.junit.After; import org.junit.Before; @@ -56,7 +56,7 @@ public class ApplicationInstallerUpdateIT extends CommonAPIIT { public void before() throws Exception { loginOnDefaultTenantWithDefaultTechnicalUser(); - applicationInstaller = TenantServiceSingleton.getInstance() + applicationInstaller = ServiceAccessorSingleton.getInstance() .lookup(ApplicationInstaller.class);; applicationArchiveReader = new ApplicationArchiveReader( new ArtifactTypeDetector(new BdmDetector(), @@ -193,7 +193,7 @@ public void process_update_custom_application_with_new_version() // fetch application menus ApplicationPage healthzPage = getApplicationAPI().searchApplicationPages( new SearchOptionsBuilder(0, Integer.MAX_VALUE) - .filter("applicationId", updatedApplication.getId()) + .filter("applicationId", (Long) updatedApplication.getId()) .done()) .getResult().get(0); assertThat(healthzPage.getToken()).isEqualTo("healthz"); diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/RecoveryMechanismIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/RecoveryMechanismIT.java index ee72ecf415e..3760dcec48a 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/RecoveryMechanismIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/RecoveryMechanismIT.java @@ -36,7 +36,7 @@ public class RecoveryMechanismIT extends CommonAPILocalIT { @Before public void before() throws BonitaException { loginOnDefaultTenantWithDefaultTechnicalUser(); - recoveryService = getTenantAccessor().lookup("recoveryService"); + recoveryService = getServiceAccessor().lookup("recoveryService"); recoveryService.setConsiderElementsOlderThan("PT0S"); } @@ -56,8 +56,8 @@ public void should_recover_elements_after_incident() throws Exception { ProcessInstance processInstance = getProcessAPI().startProcess(processDefinition.getId()); TimeUnit.MILLISECONDS.sleep(100); - getTenantAccessor().getWorkExecutorService().pause(); - getTenantAccessor().getWorkExecutorService().resume(); + getServiceAccessor().getWorkExecutorService().pause(); + getServiceAccessor().getWorkExecutorService().resume(); TimeUnit.MILLISECONDS.sleep(500); assertThat(getProcessAPI().getProcessInstance(processInstance.getId()).getState()) diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/connector/ConnectorExecutionsLocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/connector/ConnectorExecutionsLocalIT.java index 08c5fe1ed91..9019f8726f5 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/connector/ConnectorExecutionsLocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/connector/ConnectorExecutionsLocalIT.java @@ -18,11 +18,7 @@ import java.io.IOException; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.apache.commons.io.IOUtils; import org.bonitasoft.engine.archive.model.TestLogBuilder; @@ -32,11 +28,7 @@ import org.bonitasoft.engine.bpm.flownode.ActivityInstance; import org.bonitasoft.engine.bpm.flownode.TimerType; import org.bonitasoft.engine.bpm.flownode.impl.internal.FlowElementContainerDefinitionImpl; -import org.bonitasoft.engine.bpm.process.ConfigurationState; -import org.bonitasoft.engine.bpm.process.Problem; -import org.bonitasoft.engine.bpm.process.ProcessDefinition; -import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo; -import org.bonitasoft.engine.bpm.process.ProcessInstance; +import org.bonitasoft.engine.bpm.process.*; import org.bonitasoft.engine.bpm.process.impl.AutomaticTaskDefinitionBuilder; import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder; import org.bonitasoft.engine.bpm.process.impl.UserTaskDefinitionBuilder; @@ -57,8 +49,8 @@ import org.bonitasoft.engine.operation.OperatorType; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; import org.bonitasoft.engine.test.BlockingConnector; @@ -75,9 +67,9 @@ @SuppressWarnings("javadoc") public class ConnectorExecutionsLocalIT extends ConnectorExecutionIT { - protected TenantServiceAccessor getTenantAccessor() { + protected ServiceAccessor getServiceAccessor() { try { - return TenantServiceSingleton.getInstance(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } @@ -725,7 +717,7 @@ public void getConnectorImplementationWorksAfterCacheCleared() throws Exception final SessionAccessor sessionAccessor = ServiceAccessorFactory.getInstance().createSessionAccessor(); sessionAccessor.setSessionInfo(getSession().getId(), getSession().getTenantId()); - final CacheService cacheservice = getTenantAccessor().getCacheService(); + final CacheService cacheservice = getServiceAccessor().getCacheService(); cacheservice.clearAll(); sessionAccessor.deleteSessionId(); diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/process/DeleteProcessInstancesIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/process/DeleteProcessInstancesIT.java index b0feaf6ffb3..f3784f756fb 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/process/DeleteProcessInstancesIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/bpm/process/DeleteProcessInstancesIT.java @@ -80,10 +80,10 @@ public void should_delete_complete_archived_process_instances() throws Exception getProcessAPI().deleteArchivedProcessInstancesInAllStates(processInstances); - getTenantAccessor().getUserTransactionService().executeInTransaction((Callable) () -> { + getServiceAccessor().getUserTransactionService().executeInTransaction((Callable) () -> { for (Long userTaskInstance : userTaskInstances) { try { - getTenantAccessor().getContractDataService().getArchivedUserTaskDataValue(userTaskInstance, + getServiceAccessor().getContractDataService().getArchivedUserTaskDataValue(userTaskInstance, inputName()); fail("should have deleted archived contract data on activity instance"); } catch (SContractDataNotFoundException e) { @@ -92,7 +92,7 @@ public void should_delete_complete_archived_process_instances() throws Exception } for (Long processInstance : processInstances) { try { - getTenantAccessor().getContractDataService().getArchivedProcessDataValue(processInstance, + getServiceAccessor().getContractDataService().getArchivedProcessDataValue(processInstance, "simpleInput1"); fail("should have deleted archived contract data on process instance"); } catch (SContractDataNotFoundException e) { @@ -105,19 +105,19 @@ public void should_delete_complete_archived_process_instances() throws Exception soft.assertThat(searchAllArchProcessInstances()).isEmpty(); soft.assertThat(searchAllArchFlowNodes()).isEmpty(); soft.assertThat( - getTenantAccessor().getCommentService().searchArchivedComments(new QueryOptions(0, 1000))) + getServiceAccessor().getCommentService().searchArchivedComments(new QueryOptions(0, 1000))) .isEmpty(); - soft.assertThat(getTenantAccessor().getConnectorInstanceService().searchArchivedConnectorInstance( + soft.assertThat(getServiceAccessor().getConnectorInstanceService().searchArchivedConnectorInstance( new QueryOptions(0, 100, SAConnectorInstance.class, null, null), - getTenantAccessor().getReadPersistenceService())).isEmpty(); - soft.assertThat(getTenantAccessor().getDocumentService() + getServiceAccessor().getReadPersistenceService())).isEmpty(); + soft.assertThat(getServiceAccessor().getDocumentService() .getNumberOfArchivedDocuments(new QueryOptions(0, 100))).isEqualTo(0); for (SAFlowNodeInstance flowNodeInstance : allArchFlowNodesBeforeDelete) { - soft.assertThat(getTenantAccessor().getDataInstanceService().getLocalSADataInstances( + soft.assertThat(getServiceAccessor().getDataInstanceService().getLocalSADataInstances( flowNodeInstance.getSourceObjectId(), ACTIVITY_INSTANCE.toString(), 0, 1)).isEmpty(); } for (SAProcessInstance processInstance : allArchProcessInstancesBeforeDelete) { - soft.assertThat(getTenantAccessor().getDataInstanceService().getLocalSADataInstances( + soft.assertThat(getServiceAccessor().getDataInstanceService().getLocalSADataInstances( processInstance.getSourceObjectId(), PROCESS_INSTANCE.toString(), 0, 1)).isEmpty(); } } catch (Exception e) { @@ -166,17 +166,17 @@ protected String inputName() { } protected List getAllProcessInstances() throws Exception { - return getTenantAccessor() + return getServiceAccessor() .getUserTransactionService().executeInTransaction(this::searchAllArchProcessInstances); } protected List getAllArchFlowNodes() throws Exception { - return getTenantAccessor().getUserTransactionService() + return getServiceAccessor().getUserTransactionService() .executeInTransaction(this::searchAllArchFlowNodes); } protected List getAllFlowNodes() throws Exception { - return getTenantAccessor().getUserTransactionService() + return getServiceAccessor().getUserTransactionService() .executeInTransaction(this::searchAllFlowNodes); } @@ -241,19 +241,19 @@ protected ProcessDefinition createSubProcessDefinitionWithUserTask(User user) th } private List searchAllArchProcessInstances() throws SBonitaReadException { - return getTenantAccessor().getProcessInstanceService() + return getServiceAccessor().getProcessInstanceService() .searchArchivedProcessInstances(new QueryOptions(0, 1000)); } private List searchAllArchFlowNodes() throws org.bonitasoft.engine.persistence.SBonitaReadException { - return getTenantAccessor().getActivityInstanceService() + return getServiceAccessor().getActivityInstanceService() .searchArchivedFlowNodeInstances(SAFlowNodeInstance.class, new QueryOptions(0, 1000)); } private List searchAllFlowNodes() throws org.bonitasoft.engine.persistence.SBonitaReadException { - return getTenantAccessor().getActivityInstanceService() + return getServiceAccessor().getActivityInstanceService() .searchFlowNodeInstances(SFlowNodeInstance.class, new QueryOptions(0, 1000)); } diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/business/data/BDRepositoryLocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/business/data/BDRepositoryLocalIT.java index 0220ae757cc..32edff41d5d 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/business/data/BDRepositoryLocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/business/data/BDRepositoryLocalIT.java @@ -41,17 +41,13 @@ import org.bonitasoft.engine.operation.LeftOperandBuilder; import org.bonitasoft.engine.operation.OperationBuilder; import org.bonitasoft.engine.operation.OperatorType; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.junit.*; import org.junit.rules.TemporaryFolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class BDRepositoryLocalIT extends CommonAPIIT { - private static final Logger log = LoggerFactory.getLogger(BDRepositoryLocalIT.class); - private static final String FIND_BY_FIRST_NAME_AND_LAST_NAME_NEW_ORDER = "findByFirstNameAndLastNameNewOrder"; private static final String BIZ_GRENOBLE_ADDRESS = "bizGrenobleAddress"; @@ -513,9 +509,9 @@ public void deploy_a_BDR_and_verify_sequence_behaviour_by_DBVendor() throws Exce } private List execute_native_sql(String query) throws Exception { - TenantServiceAccessor tenantServiceAccessor = TenantServiceSingleton.getInstance(); - return tenantServiceAccessor.getUserTransactionService().executeInTransaction( - () -> ((JPABusinessDataRepositoryImpl) (tenantServiceAccessor.getBusinessDataRepository())) + ServiceAccessor serviceAccessor = ServiceAccessorSingleton.getInstance(); + return serviceAccessor.getUserTransactionService().executeInTransaction( + () -> ((JPABusinessDataRepositoryImpl) (serviceAccessor.getBusinessDataRepository())) .getEntityManagerFactory().createEntityManager().createNativeQuery(query).getResultList()); } diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/job/JobExecutionIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/job/JobExecutionIT.java index d488dfddc2b..5ae38714d7a 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/job/JobExecutionIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/job/JobExecutionIT.java @@ -27,14 +27,12 @@ import java.util.concurrent.Callable; import org.bonitasoft.engine.connectors.VariableStorage; -import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.persistence.FilterOption; import org.bonitasoft.engine.persistence.QueryOptions; import org.bonitasoft.engine.scheduler.JobService; import org.bonitasoft.engine.scheduler.model.SJobDescriptor; import org.bonitasoft.engine.scheduler.model.SJobLog; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.test.CommonAPILocalIT; import org.bonitasoft.engine.test.WaitUntil; import org.bonitasoft.engine.transaction.UserTransactionService; @@ -116,9 +114,9 @@ public void retryAJob_should_execute_again_a_failed_job_and_clean_related_job_lo private void searchJobLogs(final long jobDescriptorId, final int nbOfExpectedJobLogs) throws Exception { setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); - final JobService jobService = tenantAccessor.getJobService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); + final JobService jobService = serviceAccessor.getJobService(); final QueryOptions options = new QueryOptions(0, 1, null, Collections.singletonList(new FilterOption(SJobLog.class, "jobDescriptorId", jobDescriptorId)), null); @@ -130,9 +128,9 @@ private void searchJobLogs(final long jobDescriptorId, final int nbOfExpectedJob private List searchJobDescriptors(final int nbOfExpectedJobDescriptors) throws Exception { setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final JobService jobService = tenantAccessor.getJobService(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final JobService jobService = serviceAccessor.getJobService(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final List filters = Collections .singletonList( @@ -216,13 +214,4 @@ private FailedJob getFailingJob() { return searchJob; } - @Override - protected TenantServiceAccessor getTenantAccessor() { - try { - return TenantServiceSingleton.getInstance(); - } catch (final Exception e) { - throw new BonitaRuntimeException(e); - } - } - } diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/tenant/TenantMaintenanceLocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/tenant/TenantMaintenanceLocalIT.java index f4d8f88dd13..8b69e14e49c 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/tenant/TenantMaintenanceLocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/tenant/TenantMaintenanceLocalIT.java @@ -22,8 +22,8 @@ import org.bonitasoft.engine.bpm.process.ProcessInstance; import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder; import org.bonitasoft.engine.expression.ExpressionBuilder; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.work.WorkService; import org.junit.Rule; import org.junit.Test; @@ -42,7 +42,7 @@ public class TenantMaintenanceLocalIT extends TestWithUser { public void should_pause_tenant_then_stop_start_node_start_pageService_again_but_dont_restart_elements_but_resume_restart_them() throws Exception { // given: tenant is paused - WorkService workService = getTenantAccessor().getWorkService(); + WorkService workService = getServiceAccessor().getWorkService(); assertFalse(workService.isStopped()); logoutThenloginAs(USERNAME, PASSWORD); @@ -69,7 +69,7 @@ public void should_pause_tenant_then_stop_start_node_start_pageService_again_but // assert that provided mandatory pages have re-imported again even though the tenant is paused assertTrue(systemOutRule.getLog().contains("Import of Bonita mandatory pages completed")); // then: work service is not running - workService = getTenantAccessor().getWorkService(); + workService = getServiceAccessor().getWorkService(); assertTrue(workService.isStopped()); // cleanup @@ -80,8 +80,8 @@ public void should_pause_tenant_then_stop_start_node_start_pageService_again_but disableAndDeleteProcess(pd); } - protected TenantServiceAccessor getTenantAccessor() { - return TenantServiceSingleton.getInstance(); + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } } diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java index 1751c11772f..4bba100bc86 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/BPMLocalIT.java @@ -13,9 +13,7 @@ **/ package org.bonitasoft.engine.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; @@ -33,21 +31,12 @@ import org.assertj.core.api.Assertions; import org.bonitasoft.engine.actor.mapping.model.SActor; import org.bonitasoft.engine.actor.mapping.model.SActorMember; -import org.bonitasoft.engine.api.ApiAccessType; -import org.bonitasoft.engine.api.IdentityAPI; -import org.bonitasoft.engine.api.LoginAPI; -import org.bonitasoft.engine.api.PlatformAPI; -import org.bonitasoft.engine.api.PlatformAPIAccessor; -import org.bonitasoft.engine.api.TenantAPIAccessor; +import org.bonitasoft.engine.api.*; import org.bonitasoft.engine.bpm.bar.BarResource; import org.bonitasoft.engine.bpm.bar.BusinessArchive; import org.bonitasoft.engine.bpm.bar.BusinessArchiveBuilder; import org.bonitasoft.engine.bpm.connector.ConnectorEvent; -import org.bonitasoft.engine.bpm.flownode.ActivityExecutionException; -import org.bonitasoft.engine.bpm.flownode.ActivityInstanceNotFoundException; -import org.bonitasoft.engine.bpm.flownode.ActivityStates; -import org.bonitasoft.engine.bpm.flownode.FlowNodeInstance; -import org.bonitasoft.engine.bpm.flownode.FlowNodeInstanceSearchDescriptor; +import org.bonitasoft.engine.bpm.flownode.*; import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.bpm.process.ProcessInstance; import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder; @@ -68,7 +57,7 @@ import org.bonitasoft.engine.platform.Platform; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.session.InvalidSessionException; import org.bonitasoft.engine.session.PlatformSession; @@ -119,9 +108,9 @@ public void useAFakeSessionId() throws BonitaException { @Test public void checkProcessCommentAreArchived() throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SCommentService commentService = tenantAccessor.getCommentService(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SCommentService commentService = serviceAccessor.getCommentService(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final ProcessDefinitionBuilder processDef = new ProcessDefinitionBuilder() .createNewInstance("processToTestComment", "1.0"); processDef.addStartEvent("start"); @@ -163,9 +152,9 @@ public void checkProcessCommentAreArchived() throws Exception { @Test public void checkPendingMappingAreDeleted() throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final ProcessDefinitionBuilder processDef = new ProcessDefinitionBuilder() .createNewInstance("processToTestComment", "1.0"); processDef.addShortTextData("kikoo", new ExpressionBuilder().createConstantStringExpression("lol")); @@ -199,9 +188,9 @@ public void checkPendingMappingAreDeleted() throws Exception { @Test public void checkDependenciesAreDeletedWhenProcessIsDeleted() throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DependencyService dependencyService = tenantAccessor.getDependencyService(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DependencyService dependencyService = serviceAccessor.getDependencyService(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final ProcessDefinitionBuilder processDef = new ProcessDefinitionBuilder() .createNewInstance("processToTestTransitions", "1.0"); processDef.addStartEvent("start"); @@ -237,9 +226,9 @@ public void checkDependenciesAreDeletedWhenProcessIsDeleted() throws Exception { @Test public void checkMoreThan20DependenciesAreDeletedWhenProcessIsDeleted() throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DependencyService dependencyService = tenantAccessor.getDependencyService(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DependencyService dependencyService = serviceAccessor.getDependencyService(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final ProcessDefinitionBuilder processDef = new ProcessDefinitionBuilder() .createNewInstance("processToTestTransitions", "1.0"); processDef.addStartEvent("start").addUserTask("step1", ACTOR_NAME).addEndEvent("end"); @@ -276,8 +265,8 @@ public void checkMoreThan20DependenciesAreDeletedWhenProcessIsDeleted() throws E @Test public void deletingProcessDeletesActors() throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final String userTaskName = "actNaturally"; final ProcessDefinition definition = deployAndEnableProcessWithOneHumanTask("deletingProcessDeletesActors", "CandidateForOscarReward", userTaskName); @@ -290,7 +279,7 @@ public void deletingProcessDeletesActors() throws Exception { setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved final List actors = transactionService.executeInTransaction(() -> { final QueryOptions queryOptions = new QueryOptions(0, 1, SActor.class, "id", OrderByType.ASC); - return getTenantAccessor().getActorMappingService().getActors(definition.getId(), queryOptions); + return getServiceAccessor().getActorMappingService().getActors(definition.getId(), queryOptions); }); // Check there is no actor left: @@ -299,8 +288,8 @@ public void deletingProcessDeletesActors() throws Exception { @Test public void deletingProcessDeletesActorMappings() throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); final String userTaskName = "actNaturally"; final ProcessDefinition definition = deployAndEnableProcessWithOneHumanTask( "deletingProcessDeletesActorMappings", "CandidateForOscarReward", @@ -314,7 +303,7 @@ public void deletingProcessDeletesActorMappings() throws Exception { setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved final List actorMembers = transactionService .executeInTransaction( - () -> getTenantAccessor().getActorMappingService().getActorMembersOfUser(john.getId(), 0, 1)); + () -> getServiceAccessor().getActorMappingService().getActorMembersOfUser(john.getId(), 0, 1)); // Check there is no actor left: assertEquals(0, actorMembers.size()); diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/CommonAPILocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/CommonAPILocalIT.java index 64a324af28c..532f2ee0444 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/CommonAPILocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/CommonAPILocalIT.java @@ -16,8 +16,7 @@ import org.bonitasoft.engine.CommonAPIIT; import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; @@ -27,17 +26,9 @@ */ public class CommonAPILocalIT extends CommonAPIIT { - protected TenantServiceAccessor getTenantAccessor() { - try { - return TenantServiceSingleton.getInstance(); - } catch (final Exception e) { - throw new BonitaRuntimeException(e); - } - } - protected ServiceAccessor getServiceAccessor() { try { - return ServiceAccessorFactory.getInstance().createServiceAccessor(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/PermissionAPIIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/PermissionAPIIT.java index 8b015cc6345..4dec9108ddc 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/PermissionAPIIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/PermissionAPIIT.java @@ -28,7 +28,7 @@ import org.bonitasoft.engine.exception.ExecutionException; import org.bonitasoft.engine.exception.NotFoundException; import org.bonitasoft.engine.identity.User; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.platform.configuration.ConfigurationService; import org.bonitasoft.platform.configuration.model.BonitaConfiguration; import org.bonitasoft.platform.setup.PlatformSetupAccessor; @@ -132,9 +132,9 @@ private void writeScriptToBonitaHome(final String scriptFileContent, final Strin configurationService.storeTenantSecurityScripts( Collections.singletonList(new BonitaConfiguration(path, scriptFileContent.getBytes())), - getTenantAccessor().getTenantId()); + getServiceAccessor().getTenantId()); - final PermissionService permissionService = TenantServiceSingleton.getInstance().getPermissionService(); + final PermissionService permissionService = ServiceAccessorSingleton.getInstance().getPermissionService(); //restart the service to reload scripts permissionService.stop(); permissionService.start(); diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessArchiveIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessArchiveIT.java index 79355b2512c..900876742e2 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessArchiveIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessArchiveIT.java @@ -39,7 +39,7 @@ import org.bonitasoft.engine.operation.OperatorType; import org.bonitasoft.engine.persistence.QueryOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.junit.After; import org.junit.Before; @@ -64,10 +64,10 @@ public void afterTest() throws BonitaException { @Test() public void deleteProcessDefinitionDeleteArchivedInstancesWithDataAndComments() throws Exception { setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SCommentService commentService = tenantAccessor.getCommentService(); - final UserTransactionService userTransactionService = tenantAccessor.getUserTransactionService(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SCommentService commentService = serviceAccessor.getCommentService(); + final UserTransactionService userTransactionService = serviceAccessor.getUserTransactionService(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); final long initialNumberOfArchivedProcessInstance = getProcessAPI().getNumberOfArchivedProcessInstances(); final ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder() .createNewInstance("ProcessToDelete", "1.0"); diff --git a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessWithExpressionLocalIT.java b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessWithExpressionLocalIT.java index a124550adcd..5731f11a071 100644 --- a/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessWithExpressionLocalIT.java +++ b/bonita-integration-tests/bonita-integration-tests-local/src/test/java/org/bonitasoft/engine/test/ProcessWithExpressionLocalIT.java @@ -13,11 +13,11 @@ **/ package org.bonitasoft.engine.test; +import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import java.io.Serializable; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -27,21 +27,16 @@ import org.bonitasoft.engine.bpm.process.DesignProcessDefinition; import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.bpm.process.impl.ProcessDefinitionBuilder; -import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.exception.UpdateException; -import org.bonitasoft.engine.expression.ComparisonOperator; -import org.bonitasoft.engine.expression.Expression; -import org.bonitasoft.engine.expression.ExpressionBuilder; -import org.bonitasoft.engine.expression.ExpressionEvaluationException; -import org.bonitasoft.engine.expression.InvalidExpressionException; +import org.bonitasoft.engine.expression.*; import org.bonitasoft.engine.operation.LeftOperand; import org.bonitasoft.engine.operation.Operation; import org.bonitasoft.engine.operation.OperationBuilder; import org.bonitasoft.engine.operation.OperatorType; import org.bonitasoft.engine.process.Employee; import org.bonitasoft.engine.process.Secretary; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.junit.Test; /** @@ -152,19 +147,15 @@ public void should_operation_with_transient_data_reevaluate_the_definition_if_lo // evaluate it: it should return the updated value assertThat(evaluateTransientDataWithExpression(step1).get("tData")).isEqualTo("The updated value"); // clear the cache - getTenantAccessor().getCacheService().clear("transient_data"); + getServiceAccessor().getCacheService().clear("transient_data"); // evaluate it: it should return the default value assertThat(evaluateTransientDataWithExpression(step1).get("tData")).isEqualTo("The default value"); disableAndDeleteProcess(processDefinition); } - protected TenantServiceAccessor getTenantAccessor() { - try { - return TenantServiceSingleton.getInstance(); - } catch (final Exception e) { - throw new BonitaRuntimeException(e); - } + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } private void updateDataWithOperation(final HumanTaskInstance step1, final String value, final String name) @@ -174,16 +165,15 @@ private void updateDataWithOperation(final HumanTaskInstance step1, final String .setLeftOperand(name, LeftOperand.TYPE_TRANSIENT_DATA) .setRightOperand(new ExpressionBuilder().createConstantStringExpression(value)) .setType(OperatorType.ASSIGNMENT).done(); - getProcessAPI().updateActivityInstanceVariables(Arrays.asList(operation), step1.getId(), null); + getProcessAPI().updateActivityInstanceVariables(singletonList(operation), step1.getId(), null); } private Map evaluateTransientDataWithExpression(final HumanTaskInstance step1) throws ExpressionEvaluationException, InvalidExpressionException { final Map> expressionMap = new HashMap<>(); - expressionMap - .put(new ExpressionBuilder().createTransientDataExpression("tData", String.class.getName()), - Collections.emptyMap()); + expressionMap.put(new ExpressionBuilder().createTransientDataExpression("tData", String.class.getName()), + Collections.emptyMap()); return getProcessAPI().evaluateExpressionsOnActivityInstance(step1.getId(), expressionMap); } diff --git a/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/BonitaServletContextListener.java b/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/BonitaServletContextListener.java deleted file mode 100644 index f312c53fa35..00000000000 --- a/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/BonitaServletContextListener.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (C) 2019 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.api.internal.servlet; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.bonitasoft.engine.api.impl.PlatformAPIImpl; -import org.bonitasoft.engine.exception.BonitaRuntimeException; -import org.bonitasoft.engine.platform.session.PlatformSessionService; -import org.bonitasoft.engine.platform.session.model.SPlatformSession; -import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; -import org.bonitasoft.engine.sessionaccessor.SessionAccessor; - -/** - * Used to initialize the spring context if not yet initialized. - * Also, starts the node if the platform exists. - * - * @author Baptiste Mesta - */ -public class BonitaServletContextListener implements ServletContextListener { - - @Override - public void contextInitialized(final ServletContextEvent sce) { - try { - ServiceAccessor serviceAccessor = getServiceAccessor(); - final SessionAccessor sessionAccessor = ServiceAccessorFactory.getInstance().createSessionAccessor(); - PlatformSessionService platformSessionService = serviceAccessor.getPlatformSessionService(); - SPlatformSession createSession = platformSessionService.createSession("john"); - sessionAccessor.setSessionInfo(createSession.getId(), -1); - PlatformAPIImpl platformAPI = new PlatformAPIImpl(); - if (platformAPI.isPlatformCreated()) { - platformAPI.startNode(); - } - platformSessionService.deleteSession(createSession.getId()); - sessionAccessor.deleteSessionId(); - } catch (final Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - - } - - protected ServiceAccessor getServiceAccessor() { - try { - return ServiceAccessorFactory.getInstance().createServiceAccessor(); - } catch (final Exception e) { - throw new BonitaRuntimeException(e); - } - } - - @Override - public void contextDestroyed(final ServletContextEvent sce) { - - } - -} diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/APIUtils.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/APIUtils.java index 99601b3d5f0..cc4bf8fbcb5 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/APIUtils.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/APIUtils.java @@ -13,8 +13,8 @@ **/ package org.bonitasoft.engine.api.impl; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Baptiste Mesta @@ -25,9 +25,9 @@ protected static long getUserId() { return SessionInfos.getUserIdFromSession(); } - protected static TenantServiceAccessor getTenantAccessor() { + protected static ServiceAccessor getServiceAccessor() { try { - return TenantServiceSingleton.getInstance(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new RuntimeException(e); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java index f8aa10efc61..1f380d0aaf0 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java @@ -34,38 +34,15 @@ import org.bonitasoft.engine.api.impl.transaction.application.SearchApplicationPages; import org.bonitasoft.engine.api.impl.transaction.application.SearchApplications; import org.bonitasoft.engine.api.impl.transaction.application.SearchApplicationsOfUser; -import org.bonitasoft.engine.business.application.Application; -import org.bonitasoft.engine.business.application.ApplicationCreator; -import org.bonitasoft.engine.business.application.ApplicationImportPolicy; -import org.bonitasoft.engine.business.application.ApplicationMenu; -import org.bonitasoft.engine.business.application.ApplicationMenuCreator; -import org.bonitasoft.engine.business.application.ApplicationMenuNotFoundException; -import org.bonitasoft.engine.business.application.ApplicationMenuUpdater; -import org.bonitasoft.engine.business.application.ApplicationNotFoundException; -import org.bonitasoft.engine.business.application.ApplicationPage; -import org.bonitasoft.engine.business.application.ApplicationPageNotFoundException; -import org.bonitasoft.engine.business.application.ApplicationService; -import org.bonitasoft.engine.business.application.ApplicationUpdater; -import org.bonitasoft.engine.business.application.Icon; -import org.bonitasoft.engine.business.application.converter.ApplicationMenuToNodeConverter; -import org.bonitasoft.engine.business.application.converter.ApplicationPageToNodeConverter; -import org.bonitasoft.engine.business.application.converter.ApplicationToNodeConverter; -import org.bonitasoft.engine.business.application.converter.ApplicationsToNodeContainerConverter; -import org.bonitasoft.engine.business.application.converter.NodeToApplicationConverter; +import org.bonitasoft.engine.business.application.*; +import org.bonitasoft.engine.business.application.converter.*; import org.bonitasoft.engine.business.application.exporter.ApplicationContainerExporter; import org.bonitasoft.engine.business.application.exporter.ApplicationExporter; import org.bonitasoft.engine.business.application.importer.StrategySelector; import org.bonitasoft.engine.business.application.importer.validator.ApplicationImportValidator; import org.bonitasoft.engine.business.application.importer.validator.ApplicationMenuCreatorValidator; import org.bonitasoft.engine.business.application.importer.validator.ApplicationTokenValidator; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.BonitaRuntimeException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.ExportException; -import org.bonitasoft.engine.exception.ImportException; -import org.bonitasoft.engine.exception.SearchException; -import org.bonitasoft.engine.exception.UpdateException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.page.PageService; import org.bonitasoft.engine.profile.ProfileService; import org.bonitasoft.engine.search.SearchOptions; @@ -75,11 +52,9 @@ import org.bonitasoft.engine.search.descriptor.SearchApplicationMenuDescriptor; import org.bonitasoft.engine.search.descriptor.SearchApplicationPageDescriptor; import org.bonitasoft.engine.search.impl.SearchFilter; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; import org.bonitasoft.engine.session.SessionService; -import org.bonitasoft.engine.sessionaccessor.SessionAccessor; /** * @author Elias Ricken de Medeiros @@ -94,8 +69,8 @@ public Application createApplication(final ApplicationCreator applicationCreator } private LivingApplicationAPIDelegate getLivingApplicationAPIDelegate() { - return new LivingApplicationAPIDelegate(getTenantAccessor(), - getApplicationModelConverter(getTenantAccessor().getPageService()), + return new LivingApplicationAPIDelegate(getServiceAccessor(), + getApplicationModelConverter(getServiceAccessor().getPageService()), SessionInfos.getUserIdFromSession(), new ApplicationTokenValidator()); } @@ -104,23 +79,23 @@ protected ApplicationModelConverter getApplicationModelConverter(final PageServi } private LivingApplicationPageAPIDelegate getApplicationPageAPIDelegate() { - return new LivingApplicationPageAPIDelegate(getTenantAccessor(), new ApplicationPageModelConverter(), + return new LivingApplicationPageAPIDelegate(getServiceAccessor(), new ApplicationPageModelConverter(), SessionInfos.getUserIdFromSession(), new ApplicationTokenValidator()); } private LivingApplicationMenuAPIDelegate getApplicationMenuAPIDelegate() { - return new LivingApplicationMenuAPIDelegate(getTenantAccessor(), new ApplicationMenuModelConverter(), + return new LivingApplicationMenuAPIDelegate(getServiceAccessor(), new ApplicationMenuModelConverter(), new ApplicationMenuCreatorValidator(), SessionInfos.getUserIdFromSession()); } private LivingApplicationExporterDelegate getLivingApplicationExporterDelegate() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ApplicationService applicationService = tenantAccessor.getApplicationService(); - final PageService pageService = tenantAccessor.getPageService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ApplicationService applicationService = serviceAccessor.getApplicationService(); + final PageService pageService = serviceAccessor.getPageService(); ApplicationToNodeConverter applicationToNodeConverter = new ApplicationToNodeConverter( - tenantAccessor.getProfileService(), applicationService, + serviceAccessor.getProfileService(), applicationService, new ApplicationPageToNodeConverter(pageService), new ApplicationMenuToNodeConverter(applicationService), pageService); final ApplicationsToNodeContainerConverter applicationsToNodeContainerConverter = new ApplicationsToNodeContainerConverter( @@ -128,7 +103,7 @@ private LivingApplicationExporterDelegate getLivingApplicationExporterDelegate() final ApplicationContainerExporter applicationContainerExporter = new ApplicationContainerExporter(); final ApplicationExporter applicationExporter = new ApplicationExporter(applicationsToNodeContainerConverter, applicationContainerExporter); - return new LivingApplicationExporterDelegate(tenantAccessor.getApplicationService(), applicationExporter); + return new LivingApplicationExporterDelegate(serviceAccessor.getApplicationService(), applicationExporter); } protected NodeToApplicationConverter getNodeToApplicationConverter(final PageService pageService, @@ -159,10 +134,9 @@ public Application updateApplication(final long applicationId, final Application return getLivingApplicationAPIDelegate().updateApplication(applicationId, updater); } - protected TenantServiceAccessor getTenantAccessor() { + protected ServiceAccessor getServiceAccessor() { try { - final SessionAccessor sessionAccessor = ServiceAccessorFactory.getInstance().createSessionAccessor(); - return TenantServiceSingleton.getInstance(); + return ServiceAccessorFactory.getInstance().createServiceAccessor(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } @@ -170,11 +144,11 @@ protected TenantServiceAccessor getTenantAccessor() { @Override public SearchResult searchApplications(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchApplicationDescriptor appSearchDescriptor = tenantAccessor.getSearchEntitiesDescriptor() + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchApplicationDescriptor appSearchDescriptor = serviceAccessor.getSearchEntitiesDescriptor() .getSearchApplicationDescriptor(); - final ApplicationModelConverter converter = getApplicationModelConverter(tenantAccessor.getPageService()); - final ApplicationService applicationService = tenantAccessor.getApplicationService(); + final ApplicationModelConverter converter = getApplicationModelConverter(serviceAccessor.getPageService()); + final ApplicationService applicationService = serviceAccessor.getApplicationService(); final Optional filterOnUserId = searchOptions.getFilters().stream() .filter(s -> s.getField().equals(USER_ID)).findFirst(); if (filterOnUserId.isPresent()) { @@ -214,11 +188,11 @@ public ApplicationPage getApplicationPage(final String applicationName, final St @Override public SearchResult searchApplicationPages(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchApplicationPageDescriptor appPageSearchDescriptor = tenantAccessor.getSearchEntitiesDescriptor() + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchApplicationPageDescriptor appPageSearchDescriptor = serviceAccessor.getSearchEntitiesDescriptor() .getSearchApplicationPageDescriptor(); final ApplicationPageModelConverter converter = new ApplicationPageModelConverter(); - final ApplicationService applicationService = tenantAccessor.getApplicationService(); + final ApplicationService applicationService = serviceAccessor.getApplicationService(); final SearchApplicationPages searchApplicationPages = new SearchApplicationPages(applicationService, converter, appPageSearchDescriptor, searchOptions); return getApplicationPageAPIDelegate().searchApplicationPages(searchApplicationPages); @@ -271,10 +245,10 @@ public void deleteApplicationMenu(final long applicationMenuId) throws DeletionE @Override public SearchResult searchApplicationMenus(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ApplicationService applicationService = tenantAccessor.getApplicationService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ApplicationService applicationService = serviceAccessor.getApplicationService(); final ApplicationMenuModelConverter converter = new ApplicationMenuModelConverter(); - final SearchApplicationMenuDescriptor searchDescriptor = tenantAccessor.getSearchEntitiesDescriptor() + final SearchApplicationMenuDescriptor searchDescriptor = serviceAccessor.getSearchEntitiesDescriptor() .getSearchApplicationMenuDescriptor(); final SearchApplicationMenus searchApplicationMenus = new SearchApplicationMenus(applicationService, converter, searchDescriptor, searchOptions); @@ -299,7 +273,7 @@ public byte[] exportApplications(final long... applicationIds) throws ExportExce @Override public List importApplications(final byte[] xmlContent, final ApplicationImportPolicy policy) throws ImportException, AlreadyExistsException { - return getTenantAccessor().getApplicationImporter().importApplications(xmlContent, null, null, + return getServiceAccessor().getApplicationImporter().importApplications(xmlContent, null, null, SessionInfos.getUserIdFromSession(), new StrategySelector().selectStrategy(policy)); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImpl.java index 90d4c75a42f..b1f3a8be10c 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImpl.java @@ -27,23 +27,24 @@ import org.bonitasoft.engine.core.process.instance.model.business.data.SSimpleRefBusinessDataInstance; import org.bonitasoft.engine.exception.RetrieveException; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Elias Ricken de Medeiros */ public class BusinessDataAPIImpl implements BusinessDataAPI { - protected TenantServiceAccessor getTenantAccessor() { - return APIUtils.getTenantAccessor(); + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } @Override public BusinessDataReference getProcessBusinessDataReference(final String businessDataName, final long processInstanceId) throws DataNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - final RefBusinessDataService refBusinessDataService = tenantAccessor.getRefBusinessDataService(); + final RefBusinessDataService refBusinessDataService = serviceAccessor.getRefBusinessDataService(); final SRefBusinessDataInstance sReference = refBusinessDataService.getRefBusinessDataInstance( businessDataName, processInstanceId); @@ -64,9 +65,9 @@ public BusinessDataReference getProcessBusinessDataReference(final String busine @Override public List getProcessBusinessDataReferences(final long processInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - final RefBusinessDataService refBusinessDataService = tenantAccessor.getRefBusinessDataService(); + final RefBusinessDataService refBusinessDataService = serviceAccessor.getRefBusinessDataService(); final List sReferences = refBusinessDataService .getRefBusinessDataInstances(processInstanceId, startIndex, maxResults); final List references = new ArrayList(); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/CommandAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/CommandAPIImpl.java index 3f50c814b31..94cbef73307 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/CommandAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/CommandAPIImpl.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.Callable; import org.bonitasoft.engine.api.CommandAPI; import org.bonitasoft.engine.api.impl.transaction.CustomTransactions; @@ -40,19 +39,15 @@ import org.bonitasoft.engine.dependency.SDependencyException; import org.bonitasoft.engine.dependency.SDependencyNotFoundException; import org.bonitasoft.engine.dependency.model.ScopeType; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; -import org.bonitasoft.engine.exception.UpdateException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchCommands; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.search.descriptor.SearchEntitiesDescriptor; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.transaction.UserTransactionService; /** @@ -64,20 +59,20 @@ */ public class CommandAPIImpl implements CommandAPI { - protected static TenantServiceAccessor getTenantAccessor() { - return APIUtils.getTenantAccessor(); + protected static ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } @Override - public void addDependency(final String name, final byte[] jar) throws AlreadyExistsException, CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DependencyService dependencyService = tenantAccessor.getDependencyService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); + public void addDependency(final String name, final byte[] jar) throws CreationException { + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DependencyService dependencyService = serviceAccessor.getDependencyService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); try { - dependencyService.createMappedDependency(name, jar, name + ".jar", tenantAccessor.getTenantId(), + dependencyService.createMappedDependency(name, jar, name + ".jar", serviceAccessor.getTenantId(), ScopeType.TENANT); classLoaderService - .refreshClassLoaderAfterUpdate(identifier(ScopeType.TENANT, tenantAccessor.getTenantId())); + .refreshClassLoaderAfterUpdate(identifier(ScopeType.TENANT, serviceAccessor.getTenantId())); } catch (final SDependencyAlreadyExistsException e) { throw new AlreadyExistsException(e); } catch (final SDependencyException | SClassLoaderException sbe) { @@ -87,13 +82,13 @@ public void addDependency(final String name, final byte[] jar) throws AlreadyExi @Override public void removeDependency(final String name) throws DependencyNotFoundException, DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DependencyService dependencyService = tenantAccessor.getDependencyService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DependencyService dependencyService = serviceAccessor.getDependencyService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); try { dependencyService.deleteDependency(name); classLoaderService - .refreshClassLoaderAfterUpdate(identifier(ScopeType.TENANT, tenantAccessor.getTenantId())); + .refreshClassLoaderAfterUpdate(identifier(ScopeType.TENANT, serviceAccessor.getTenantId())); } catch (final SDependencyNotFoundException e) { throw new DependencyNotFoundException(e); } catch (final SBonitaException e) { @@ -103,8 +98,7 @@ public void removeDependency(final String name) throws DependencyNotFoundExcepti @Override public CommandDescriptor register(final String name, final String description, final String implementation) - throws AlreadyExistsException, - CreationException { + throws CreationException { CommandDescriptor existingCommandDescriptor = null; try { existingCommandDescriptor = getCommand(name); @@ -114,8 +108,8 @@ public CommandDescriptor register(final String name, final String description, f if (existingCommandDescriptor != null) { throw new AlreadyExistsException("A command with name \"" + name + "\" already exists"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CommandService commandService = tenantAccessor.getCommandService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CommandService commandService = serviceAccessor.getCommandService(); final SCommand sCommand = SCommand.builder() .name(name) .description(description) @@ -129,17 +123,16 @@ public CommandDescriptor register(final String name, final String description, f } private RuntimeCommand fetchRuntimeCommand(final SCommandFetcher commandFetcher, - final boolean transactionManagedManually) throws SCommandNotFoundException, - SCommandParameterizationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - + final boolean transactionManagedManually) + throws SCommandNotFoundException, SCommandParameterizationException { + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { final SCommand sCommand; if (transactionManagedManually) { - sCommand = commandFetcher.fetchInTransaction(tenantAccessor.getUserTransactionService(), - tenantAccessor.getCommandService()); + sCommand = commandFetcher.fetchInTransaction(serviceAccessor.getUserTransactionService(), + serviceAccessor.getCommandService()); } else { - sCommand = commandFetcher.fetch(tenantAccessor.getCommandService()); + sCommand = commandFetcher.fetch(serviceAccessor.getCommandService()); } final String runtimeCommandClassName = sCommand.getImplementation(); @@ -196,11 +189,10 @@ private Serializable executeCommand(final SCommandFetcher commandFetcher, final Map parameters, final boolean transactionManagedManually) throws CommandNotFoundException, CommandParameterizationException, CommandExecutionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { final RuntimeCommand runtimeCommand = fetchRuntimeCommand(commandFetcher, transactionManagedManually); - return runtimeCommand.execute(parameters, tenantAccessor); + return runtimeCommand.execute(parameters, serviceAccessor); } catch (final SCommandExecutionException scee) { throw new CommandExecutionException(scee); } catch (final SCommandParameterizationException scpe) { @@ -212,7 +204,7 @@ private Serializable executeCommand(final SCommandFetcher commandFetcher, @Override public void unregister(final long commandId) throws CommandNotFoundException, DeletionException { - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); final DeleteSCommand deleteCommand = new DeleteSCommand(commandService, commandId); unregister(deleteCommand); } @@ -223,7 +215,7 @@ public void unregister(final String name) throws CommandNotFoundException, Delet // FIXME: throw IllegalArgumentException instead, and make bonita interceptor catch all exceptions and wrap it into BonitaRuntimeException: throw new DeletionException("Command name can not be null!"); } - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); final DeleteSCommand deleteCommand = new DeleteSCommand(commandService, name); unregister(deleteCommand); } @@ -240,7 +232,7 @@ private void unregister(final DeleteSCommand deleteCommand) throws CommandNotFou @Override public void unregisterAll() throws DeletionException { - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); try { commandService.deleteAll(); } catch (final SCommandDeletionException sde) { @@ -259,7 +251,7 @@ public CommandDescriptor getCommand(final String commandName) throws CommandNotF } private CommandDescriptor getCommand(final SCommandFetcher commandFetcher) throws CommandNotFoundException { - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); try { final SCommand sCommand = commandFetcher.fetch(commandService); return ModelConvertor.toCommandDescriptor(sCommand); @@ -271,14 +263,14 @@ private CommandDescriptor getCommand(final SCommandFetcher commandFetcher) throw @Override public List getAllCommands(final int startIndex, final int maxResults, final CommandCriterion sort) { - SCommandCriterion sCommandCriterion = null; + SCommandCriterion sCommandCriterion; if (CommandCriterion.NAME_ASC.equals(sort)) { sCommandCriterion = SCommandCriterion.NAME_ASC; } else { sCommandCriterion = SCommandCriterion.NAME_DESC; } - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); try { final List commands = commandService.getAllCommands(startIndex, maxResults, sCommandCriterion); return ModelConvertor.toCommandDescriptors(commands); @@ -305,7 +297,7 @@ private void update(final SCommandFetcher commandFetcher, final CommandUpdater u final SCommandUpdateBuilderFactory fact = BuilderFactory.get(SCommandUpdateBuilderFactory.class); final SCommandUpdateBuilder commandUpdateBuilder = fact.createNewInstance(); - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); try { final EntityUpdateDescriptor changeDescriptor = getCommandUpdateDescriptor(updateDescriptor, commandUpdateBuilder); @@ -338,7 +330,7 @@ private EntityUpdateDescriptor getCommandUpdateDescriptor(final CommandUpdater u @Override public List getUserCommands(final int startIndex, final int maxResults, final CommandCriterion sort) { - final CommandService commandService = getTenantAccessor().getCommandService(); + final CommandService commandService = getServiceAccessor().getCommandService(); try { final GetCommands getCommands = new GetCommands(commandService, startIndex, maxResults, sort); getCommands.execute(); @@ -350,9 +342,9 @@ public List getUserCommands(final int startIndex, final int m @Override public SearchResult searchCommands(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CommandService commandService = tenantAccessor.getCommandService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CommandService commandService = serviceAccessor.getCommandService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchCommands searchCommands = new SearchCommands(commandService, searchEntitiesDescriptor.getSearchCommandDescriptor(), searchOptions); try { @@ -371,17 +363,10 @@ private abstract static class SCommandFetcher { SCommand fetchInTransaction(final UserTransactionService userTransactionService, final CommandService commandService) throws SCommandNotFoundException { try { - return userTransactionService.executeInTransaction(new Callable() { - - @Override - public SCommand call() throws Exception { - return fetch(commandService); - } - }); + return userTransactionService.executeInTransaction(() -> fetch(commandService)); } catch (final Exception e) { throw new SCommandNotFoundException(e); } - } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/DocumentAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/DocumentAPIImpl.java index cbf03b2450e..55293b037fa 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/DocumentAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/DocumentAPIImpl.java @@ -19,14 +19,7 @@ import org.bonitasoft.engine.api.DocumentAPI; import org.bonitasoft.engine.api.impl.transaction.document.GetDocumentByNameAtProcessInstantiation; -import org.bonitasoft.engine.bpm.document.ArchivedDocument; -import org.bonitasoft.engine.bpm.document.ArchivedDocumentNotFoundException; -import org.bonitasoft.engine.bpm.document.Document; -import org.bonitasoft.engine.bpm.document.DocumentAttachmentException; -import org.bonitasoft.engine.bpm.document.DocumentCriterion; -import org.bonitasoft.engine.bpm.document.DocumentException; -import org.bonitasoft.engine.bpm.document.DocumentNotFoundException; -import org.bonitasoft.engine.bpm.document.DocumentValue; +import org.bonitasoft.engine.bpm.document.*; import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.commons.exceptions.SObjectAlreadyExistsException; import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; @@ -40,11 +33,7 @@ import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; import org.bonitasoft.engine.core.process.instance.api.ProcessInstanceService; import org.bonitasoft.engine.core.process.instance.model.archive.SAActivityInstance; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.BonitaException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.persistence.OrderAndField; import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.search.SearchOptions; @@ -55,7 +44,8 @@ import org.bonitasoft.engine.search.document.SearchDocuments; import org.bonitasoft.engine.search.document.SearchDocumentsSupervisedBy; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Baptiste Mesta @@ -90,12 +80,12 @@ public Document attachDocument(final long processInstanceId, final String docume public Document addDocument(final long processInstanceId, final String documentName, final String description, final DocumentValue documentValue) throws DocumentAttachmentException, AlreadyExistsException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final DocumentHelper documentHelper = new DocumentHelper(documentService, - tenantAccessor.getProcessDefinitionService(), - tenantAccessor.getProcessInstanceService()); + serviceAccessor.getProcessDefinitionService(), + serviceAccessor.getProcessInstanceService()); final SDocument sDocument = buildSDocument(documentValue); int index = documentValue.getIndex(); try { @@ -137,8 +127,8 @@ public Document addDocument(final long processInstanceId, final String documentN @Override public Document updateDocument(final long documentId, final DocumentValue documentValue) throws DocumentAttachmentException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { final SMappedDocument document = documentService.updateDocument(documentId, buildSDocument(documentValue)); return ModelConvertor.toDocument(document, documentService); @@ -183,15 +173,15 @@ public Document attachDocument(final long processInstanceId, final String docume } } - TenantServiceAccessor getTenantAccessor() { - return APIUtils.getTenantAccessor(); + ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } @Override public Document attachNewDocumentVersion(final long processInstanceId, final String documentName, final String fileName, final String mimeType, final String url) throws DocumentAttachmentException { - final DocumentService documentService = getTenantAccessor().getDocumentService(); + final DocumentService documentService = getServiceAccessor().getDocumentService(); try { return ModelConvertor.toDocument( documentService.updateDocument(documentService.getMappedDocument(processInstanceId, documentName), @@ -206,7 +196,7 @@ public Document attachNewDocumentVersion(final long processInstanceId, final Str public Document attachNewDocumentVersion(final long processInstanceId, final String documentName, final String contentFileName, final String contentMimeType, final byte[] documentContent) throws DocumentAttachmentException { - final DocumentService documentService = getTenantAccessor().getDocumentService(); + final DocumentService documentService = getServiceAccessor().getDocumentService(); try { return ModelConvertor.toDocument( documentService.updateDocument(documentService.getMappedDocument(processInstanceId, documentName), @@ -219,8 +209,8 @@ public Document attachNewDocumentVersion(final long processInstanceId, final Str @Override public Document getDocument(final long documentId) throws DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { return ModelConvertor.toDocument(documentService.getMappedDocument(documentId), documentService); } catch (final SObjectNotFoundException | SBonitaReadException e) { @@ -232,8 +222,8 @@ public Document getDocument(final long documentId) throws DocumentNotFoundExcept public List getLastVersionOfDocuments(final long processInstanceId, final int pageIndex, final int numberPerPage, final DocumentCriterion pagingCriterion) throws DocumentException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForDocument(pagingCriterion); try { @@ -241,7 +231,7 @@ public List getLastVersionOfDocuments(final long processInstanceId, fi processInstanceId, pageIndex, numberPerPage, orderAndField.getField(), orderAndField.getOrder()); if (mappedDocuments != null && !mappedDocuments.isEmpty()) { - final List result = new ArrayList(mappedDocuments.size()); + final List result = new ArrayList<>(mappedDocuments.size()); for (final SMappedDocument mappedDocument : mappedDocuments) { result.add(ModelConvertor.toDocument(mappedDocument, documentService)); } @@ -255,8 +245,8 @@ public List getLastVersionOfDocuments(final long processInstanceId, fi @Override public byte[] getDocumentContent(final String documentStorageId) throws DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { return documentService.getDocumentContent(documentStorageId); } catch (final SObjectNotFoundException sbe) { @@ -267,8 +257,8 @@ public byte[] getDocumentContent(final String documentStorageId) throws Document @Override public Document getLastDocument(final long processInstanceId, final String documentName) throws DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { return ModelConvertor.toDocument(documentService.getMappedDocument(processInstanceId, documentName), documentService); @@ -279,8 +269,8 @@ public Document getLastDocument(final long processInstanceId, final String docum @Override public long getNumberOfDocuments(final long processInstanceId) throws DocumentException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { return documentService.getNumberOfDocumentsOfProcessInstance(processInstanceId); } catch (final SBonitaReadException e) { @@ -291,15 +281,15 @@ public long getNumberOfDocuments(final long processInstanceId) throws DocumentEx @Override public Document getDocumentAtProcessInstantiation(final long processInstanceId, final String documentName) throws DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); try { final GetDocumentByNameAtProcessInstantiation transactionContent = new GetDocumentByNameAtProcessInstantiation( documentService, - processInstanceService, tenantAccessor.getProcessDefinitionService(), searchEntitiesDescriptor, + processInstanceService, serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor, processInstanceId, documentName); transactionContent.execute(); final AbstractSMappedDocument attachment = transactionContent.getResult(); @@ -312,9 +302,9 @@ public Document getDocumentAtProcessInstantiation(final long processInstanceId, @Override public Document getDocumentAtActivityInstanceCompletion(final long activityInstanceId, final String documentName) throws DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final SAActivityInstance instance = activityInstanceService .getMostRecentArchivedActivityInstance(activityInstanceId); @@ -328,10 +318,10 @@ public Document getDocumentAtActivityInstanceCompletion(final long activityInsta @Override public SearchResult searchDocuments(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final SearchDocuments searchDocuments = new SearchDocuments(documentService, searchEntitiesDescriptor.getSearchDocumentDescriptor(), @@ -347,10 +337,10 @@ public SearchResult searchDocuments(final SearchOptions searchOptions) @Override public SearchResult searchDocumentsSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final SearchDocumentsSupervisedBy searchDocuments = new SearchDocumentsSupervisedBy(documentService, searchEntitiesDescriptor.getSearchDocumentDescriptor(), searchOptions, userId); @@ -365,10 +355,10 @@ public SearchResult searchDocumentsSupervisedBy(final long userId, fin @Override public SearchResult searchArchivedDocuments(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final SearchArchivedDocuments searchDocuments = new SearchArchivedDocuments(documentService, searchEntitiesDescriptor.getSearchArchivedDocumentDescriptor(), searchOptions); try { @@ -382,10 +372,10 @@ public SearchResult searchArchivedDocuments(final SearchOption @Override public SearchResult searchArchivedDocumentsSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final SearchArchivedDocumentsSupervisedBy searchDocuments = new SearchArchivedDocumentsSupervisedBy(userId, documentService, searchEntitiesDescriptor.getSearchArchivedDocumentDescriptor(), searchOptions); @@ -400,8 +390,8 @@ public SearchResult searchArchivedDocumentsSupervisedBy(final @Override public ArchivedDocument getArchivedVersionOfProcessDocument(final long sourceObjectId) throws ArchivedDocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { return ModelConvertor.toArchivedDocument( @@ -414,8 +404,8 @@ public ArchivedDocument getArchivedVersionOfProcessDocument(final long sourceObj @Override public ArchivedDocument getArchivedProcessDocument(final long archivedProcessDocumentId) throws ArchivedDocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { return ModelConvertor.toArchivedDocument(documentService.getArchivedDocument(archivedProcessDocumentId), documentService); @@ -426,11 +416,11 @@ public ArchivedDocument getArchivedProcessDocument(final long archivedProcessDoc @Override public Document removeDocument(final long documentId) throws DocumentNotFoundException, DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); final DocumentHelper documentHelper = new DocumentHelper(documentService, - tenantAccessor.getProcessDefinitionService(), - tenantAccessor.getProcessInstanceService()); + serviceAccessor.getProcessDefinitionService(), + serviceAccessor.getProcessInstanceService()); try { final SMappedDocument document = documentService.getMappedDocument(documentId); final int index = document.getIndex(); @@ -458,10 +448,10 @@ public Document removeDocument(final long documentId) throws DocumentNotFoundExc public List getDocumentList(final long processInstanceId, final String name, final int fromIndex, final int numberOfResult) throws DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentService documentService = serviceAccessor.getDocumentService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final DocumentHelper documentHelper = new DocumentHelper(documentService, processDefinitionService, processInstanceService); try { @@ -482,10 +472,10 @@ public List getDocumentList(final long processInstanceId, final String @Override public void setDocumentList(final long processInstanceId, final String name, final List documentsValues) throws DocumentException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DocumentHelper documentHelper = new DocumentHelper(tenantAccessor.getDocumentService(), - tenantAccessor.getProcessDefinitionService(), - tenantAccessor.getProcessInstanceService()); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DocumentHelper documentHelper = new DocumentHelper(serviceAccessor.getDocumentService(), + serviceAccessor.getProcessDefinitionService(), + serviceAccessor.getProcessInstanceService()); try { documentHelper.setDocumentList(documentsValues, name, processInstanceId, getUserId()); } catch (final SBonitaException e) { @@ -497,8 +487,8 @@ public void setDocumentList(final long processInstanceId, final String name, @Override public void deleteContentOfArchivedDocument(final long archivedDocumentId) throws DocumentException, DocumentNotFoundException { - final TenantServiceAccessor tenantAccessor = APIUtils.getTenantAccessor(); - final DocumentService documentService = tenantAccessor.getDocumentService(); + final ServiceAccessor serviceAccessor = ServiceAccessorSingleton.getInstance(); + final DocumentService documentService = serviceAccessor.getDocumentService(); try { documentService.deleteContentOfArchivedDocument(archivedDocumentId); } catch (final SObjectNotFoundException e) { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java index f81838e225f..afc7ede8ba3 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java @@ -50,10 +50,8 @@ import org.bonitasoft.engine.search.identity.SearchRoles; import org.bonitasoft.engine.search.identity.SearchUsers; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; -import org.bonitasoft.engine.sessionaccessor.SessionAccessor; /** * @author Matthieu Chaffotte @@ -69,10 +67,9 @@ @Slf4j public class IdentityAPIImpl implements IdentityAPI { - protected TenantServiceAccessor getTenantAccessor() { + protected ServiceAccessor getServiceAccessor() { try { - final SessionAccessor sessionAccessor = ServiceAccessorFactory.getInstance().createSessionAccessor(); - return TenantServiceSingleton.getInstance(); + return ServiceAccessorFactory.getInstance().createServiceAccessor(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } @@ -83,8 +80,7 @@ protected OrganizationAPIDelegate getOrganizationAPIDelegate() { } @Override - public User createUser(final String userName, final String password) - throws AlreadyExistsException, CreationException { + public User createUser(final String userName, final String password) throws CreationException { final UserCreator creator = new UserCreator(userName, password); creator.setEnabled(true); return createUser(creator); @@ -92,8 +88,7 @@ public User createUser(final String userName, final String password) @Override public User createUser(final String userName, final String password, final String firstName, final String lastName) - throws AlreadyExistsException, - CreationException { + throws CreationException { final UserCreator creator = new UserCreator(userName, password); creator.setFirstName(firstName).setLastName(lastName); creator.setEnabled(true); @@ -103,8 +98,8 @@ public User createUser(final String userName, final String password, final Strin @Override public User createUser(final UserCreator creator) throws CreationException { validateUserCreator(creator); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + IdentityService identityService = serviceAccessor.getIdentityService(); if (creator.getFields().containsKey(UserCreator.UserField.ICON_NAME) || creator.getFields().containsKey(UserCreator.UserField.ICON_PATH)) { log.warn("setIconName and setIconPath are deprecated, use setIcon instead"); @@ -148,9 +143,9 @@ public User updateUser(final long userId, final UserUpdater updater) throws User throw new UpdateException("The update descriptor does not contain field updates"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); // User change final EntityUpdateDescriptor userUpdateDescriptor = getUserUpdateDescriptor(updater); @@ -303,15 +298,15 @@ private EntityUpdateDescriptor getUserContactInfoUpdateDescriptor(final ContactD @Override public void deleteUser(final long userId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); try { final DeleteUser deleteUser = new DeleteUser(identityService, actorMappingService, profileService, userId); deleteUser.execute(); final Set removedActorIds = deleteUser.getRemovedActorIds(); - updateActorProcessDependencies(tenantAccessor, actorMappingService, removedActorIds); + updateActorProcessDependencies(serviceAccessor, actorMappingService, removedActorIds); } catch (final SBonitaException sbe) { throw new DeletionException(sbe); } @@ -322,16 +317,16 @@ public void deleteUser(final String userName) throws DeletionException { if (userName == null) { throw new DeletionException("User name can not be null!"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); try { final DeleteUser deleteUser = new DeleteUser(identityService, actorMappingService, profileService, userName); deleteUser.execute(); final Set removedActorIds = deleteUser.getRemovedActorIds(); - updateActorProcessDependencies(tenantAccessor, actorMappingService, removedActorIds); + updateActorProcessDependencies(serviceAccessor, actorMappingService, removedActorIds); } catch (final SBonitaException sbe) { throw new DeletionException(sbe); } @@ -340,10 +335,10 @@ public void deleteUser(final String userName) throws DeletionException { @Override public void deleteUsers(final List userIds) throws DeletionException { if (userIds != null && !userIds.isEmpty()) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); try { final DeleteUsers deleteUsers = new DeleteUsers(identityService, actorMappingService, profileService, userIds); @@ -359,8 +354,8 @@ public User getUser(final long userId) throws UserNotFoundException { if (userId == -1) { throw new UserNotFoundException("The technical user is not a usable user"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetSUser transactionContent = new GetSUser(identityService, userId); transactionContent.execute(); @@ -374,8 +369,8 @@ public User getUser(final long userId) throws UserNotFoundException { @Override public User getUserByUserName(final String userName) throws UserNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetSUser transactionContent = new GetSUser(identityService, userName); transactionContent.execute(); @@ -399,8 +394,8 @@ public ContactData getUserContactData(final long userId, final boolean personal) if (userId == -1) { throw new UserNotFoundException("The technical user is not a usable user"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetSContactInfo txContent = new GetSContactInfo(userId, identityService, personal); txContent.execute(); @@ -416,8 +411,8 @@ public ContactData getUserContactData(final long userId, final boolean personal) @Override public long getNumberOfUsers() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetNumberOfInstance transactionContent = new GetNumberOfInstance("getNumberOfUsers", identityService); transactionContent.execute(); @@ -430,9 +425,9 @@ public long getNumberOfUsers() { @Override // FIXME rewrite ME!!! public List getUsers(final int startIndex, final int maxResults, final UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - final IdentityService identityService = tenantAccessor.getIdentityService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); return getUsersWithOrder(startIndex, maxResults, criterion, identityService); } catch (final SBonitaException sbe) { throw new RetrieveException(sbe); @@ -441,8 +436,8 @@ public List getUsers(final int startIndex, final int maxResults, final Use @Override public Map getUsers(final List userIds) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final Map users = new HashMap<>(); try { final List sUsers = identityService.getUsers(userIds); @@ -457,8 +452,8 @@ public Map getUsers(final List userIds) { @Override public Map getUsersByUsernames(final List userNames) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final Map users = new HashMap<>(); try { final List sUsers = identityService.getUsersByUsername(userNames); @@ -473,9 +468,9 @@ public Map getUsersByUsernames(final List userNames) { @Override public SearchResult searchUsers(final SearchOptions options) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchUsers searchUsers = new SearchUsers(identityService, searchEntitiesDescriptor.getSearchUserDescriptor(), options); try { @@ -488,8 +483,8 @@ public SearchResult searchUsers(final SearchOptions options) throws Search @Override public long getNumberOfUsersInRole(final long roleId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetNumberOfUsersInType transactionContentWithResult = new GetNumberOfUsersInType(roleId, "getNumberOfUsersInRole", identityService); @@ -503,8 +498,8 @@ public long getNumberOfUsersInRole(final long roleId) { @Override public List getUsersInRole(final long roleId, final int startIndex, final int maxResults, final UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers( @@ -516,8 +511,8 @@ public List getUsersInRole(final long roleId, final int startIndex, final @Override public List getActiveUsersInRole(long roleId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers(identityService.getActiveUsersWithRole(roleId, startIndex, maxResults, @@ -529,8 +524,8 @@ public List getActiveUsersInRole(long roleId, int startIndex, int maxResul @Override public List getInactiveUsersInRole(long roleId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers(identityService.getInactiveUsersWithRole(roleId, startIndex, maxResults, @@ -542,8 +537,8 @@ public List getInactiveUsersInRole(long roleId, int startIndex, int maxRes @Override public List getUsersWithManager(long managerId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers(identityService.getUsersWithManager(managerId, startIndex, maxResults, @@ -556,8 +551,8 @@ public List getUsersWithManager(long managerId, int startIndex, int maxRes @Override public List getActiveUsersWithManager(long managerId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers(identityService.getActiveUsersWithManager(managerId, startIndex, maxResults, @@ -570,8 +565,8 @@ public List getActiveUsersWithManager(long managerId, int startIndex, int @Override public List getInactiveUsersWithManager(long managerId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers(identityService.getInactiveUsersWithManager(managerId, startIndex, maxResults, @@ -583,8 +578,8 @@ public List getInactiveUsersWithManager(long managerId, int startIndex, in @Override public long getNumberOfUsersInGroup(final long groupId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final GetNumberOfUsersInType transactionContentWithResult = new GetNumberOfUsersInType(groupId, "getNumberOfUsersInGroup", identityService); try { @@ -598,8 +593,8 @@ public long getNumberOfUsersInGroup(final long groupId) { @Override public List getUsersInGroup(final long groupId, final int startIndex, final int maxResults, final UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor @@ -612,8 +607,8 @@ public List getUsersInGroup(final long groupId, final int startIndex, fina @Override public List getActiveUsersInGroup(long groupId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor @@ -627,8 +622,8 @@ public List getActiveUsersInGroup(long groupId, int startIndex, int maxRes @Override public List getInactiveUsersInGroup(long groupId, int startIndex, int maxResults, UserCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); Sort sort = getSortFromCriterion(criterion); try { return ModelConvertor.toUsers(identityService.getInactiveUsersInGroup(groupId, startIndex, maxResults, @@ -641,8 +636,8 @@ public List getInactiveUsersInGroup(long groupId, int startIndex, int maxR @Override public List getUserIdsWithCustomUserInfo(String infoName, String infoValue, boolean usePartialMatch, int startIndex, int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { return identityService.getUserIdsWithCustomUserInfo(infoName, infoValue, usePartialMatch, startIndex, maxResults); @@ -652,20 +647,20 @@ public List getUserIdsWithCustomUserInfo(String infoName, String infoValue } @Override - public Role createRole(final String roleName) throws AlreadyExistsException, CreationException { + public Role createRole(final String roleName) throws CreationException { return createRole(new RoleCreator(roleName)); } @Override - public Role createRole(final RoleCreator creator) throws AlreadyExistsException, CreationException { + public Role createRole(final RoleCreator creator) throws CreationException { if (creator == null) { throw new CreationException("Unable to create a role with a null RoleCreator object"); } if (creator.getFields().get(org.bonitasoft.engine.identity.RoleCreator.RoleField.NAME) == null) { throw new CreationException("Unable to create a role with a null name"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); if (creator.getFields().containsKey(RoleCreator.RoleField.ICON_NAME) || creator.getFields().containsKey(RoleCreator.RoleField.ICON_PATH)) { log.warn("setIconName and setIconPath are deprecated, use setIcon instead"); @@ -693,8 +688,8 @@ public Role updateRole(final long roleId, final RoleUpdater updateDescriptor) if (updateDescriptor == null || updateDescriptor.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final EntityUpdateDescriptor changeDescriptor = getRoleUpdateDescriptor(updateDescriptor); return ModelConvertor.toRole(identityService.updateRole(identityService.getRole(roleId), changeDescriptor, @@ -722,7 +717,7 @@ private EntityUpdateDescriptor getRoleUpdateDescriptor(final RoleUpdater updateD roleUpdateBuilder.updateDescription((String) field.getValue()); break; case ICON_NAME: - log.warn("setIconPath is deprecated, use setIcon instead"); + log.warn("setIconName is deprecated, use setIcon instead"); break; case ICON_PATH: log.warn("setIconPath is deprecated, use setIcon instead"); @@ -737,16 +732,16 @@ private EntityUpdateDescriptor getRoleUpdateDescriptor(final RoleUpdater updateD @Override public void deleteRole(final long roleId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ProfileService profileService = serviceAccessor.getProfileService(); final DeleteRole deleteRole = new DeleteRole(identityService, actorMappingService, profileService, roleId); try { deleteRole.execute(); final Set removedActorIds = deleteRole.getRemovedActorIds(); - updateActorProcessDependencies(tenantAccessor, actorMappingService, removedActorIds); + updateActorProcessDependencies(serviceAccessor, actorMappingService, removedActorIds); } catch (final SRoleNotFoundException ignored) { } catch (final SBonitaException sbe) { throw new DeletionException(sbe); @@ -760,10 +755,10 @@ public void deleteRoles(final List roleIds) throws DeletionException { } catch (final IllegalArgumentException e) { throw new DeletionException(e); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); final DeleteRoles deleteRoles = new DeleteRoles(identityService, actorMappingService, profileService, roleIds); try { deleteRoles.execute(); @@ -774,8 +769,8 @@ public void deleteRoles(final List roleIds) throws DeletionException { @Override public Role getRole(final long roleId) throws RoleNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { return ModelConvertor.toRole(identityService.getRole(roleId)); } catch (SRoleNotFoundException e) { @@ -785,8 +780,8 @@ public Role getRole(final long roleId) throws RoleNotFoundException { @Override public Role getRoleByName(final String roleName) throws RoleNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { return ModelConvertor.toRole(identityService.getRoleByName(roleName)); } catch (final SRoleNotFoundException e) { @@ -796,8 +791,8 @@ public Role getRoleByName(final String roleName) throws RoleNotFoundException { @Override public long getNumberOfRoles() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetNumberOfInstance getNumberOfInstance = new GetNumberOfInstance("getNumberOfRoles", identityService); @@ -810,10 +805,10 @@ public long getNumberOfRoles() { @Override public List getRoles(final int startIndex, final int maxResults, final RoleCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - String field = null; - OrderByType order = null; + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + String field; + OrderByType order; switch (criterion) { case NAME_ASC: field = SRole.NAME; @@ -859,9 +854,9 @@ public Map getRoles(final List roleIds) { @Override public SearchResult searchRoles(final SearchOptions options) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchRoles searchRoles = new SearchRoles(identityService, searchEntitiesDescriptor.getSearchRoleDescriptor(), options); try { @@ -888,8 +883,8 @@ public Group createGroup(final GroupCreator creator) throws CreationException { if (groupName.contains("/")) { throw new InvalidGroupNameException("Cannot create a group with '/' in its name"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); if (creator.getFields().containsKey(GroupCreator.GroupField.ICON_NAME) || creator.getFields().containsKey(GroupCreator.GroupField.ICON_PATH)) { log.warn("setIconName and setIconPath are deprecated, use setIcon instead"); @@ -917,10 +912,10 @@ public Group updateGroup(final long groupId, final GroupUpdater updater) if (updater == null || updater.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { - checkPathUnicity(groupId, updater, identityService); + checkPathUniqueness(groupId, updater, identityService); final EntityUpdateDescriptor changeDescriptor = getGroupUpdateDescriptor(updater); return ModelConvertor.toGroup( new UpdateGroup(groupId, changeDescriptor, identityService, getIconUpdater(updater)).update()); @@ -931,7 +926,7 @@ public Group updateGroup(final long groupId, final GroupUpdater updater) } } - private void checkPathUnicity(long groupId, GroupUpdater updater, IdentityService identityService) + private void checkPathUniqueness(long groupId, GroupUpdater updater, IdentityService identityService) throws SGroupNotFoundException, AlreadyExistsException { final Serializable updatedName = updater.getFields().get(GroupField.NAME); SGroup sGroupToBeUpdated = identityService.getGroup(groupId); @@ -947,7 +942,7 @@ private void checkPathUnicity(long groupId, GroupUpdater updater, IdentityServic throw new AlreadyExistsException("Group named \"" + name + "\" already exists"); } } - } catch (final SGroupNotFoundException e) { + } catch (final SGroupNotFoundException ignored) { } } @@ -975,7 +970,6 @@ private EntityUpdateDescriptor getGroupUpdateDescriptor(final GroupUpdater updat log.warn("updateIconPath is deprecated, use updateIcon instead"); break; case ICON_CONTENT: - break; case ICON_FILENAME: break; case PARENT_PATH: @@ -992,14 +986,14 @@ private EntityUpdateDescriptor getGroupUpdateDescriptor(final GroupUpdater updat @Override public void deleteGroup(final long groupId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); final DeleteGroup deleteGroup = new DeleteGroup(identityService, actorMappingService, profileService, groupId); try { deleteGroup.execute(); - updateActorProcessDependencies(tenantAccessor, actorMappingService, deleteGroup.getRemovedActorIds()); + updateActorProcessDependencies(serviceAccessor, actorMappingService, deleteGroup.getRemovedActorIds()); } catch (final SGroupNotFoundException sgnfe) { throw new DeletionException(new GroupNotFoundException(sgnfe)); } catch (final SBonitaException sbe) { @@ -1013,15 +1007,15 @@ public void deleteGroups(final List groupIds) throws DeletionException { throw new IllegalArgumentException("the list of groups is null"); } if (!groupIds.isEmpty()) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); try { final DeleteGroups deleteGroups = new DeleteGroups(identityService, actorMappingService, profileService, groupIds); deleteGroups.execute(); - updateActorProcessDependencies(tenantAccessor, actorMappingService, deleteGroups.getRemovedActorIds()); + updateActorProcessDependencies(serviceAccessor, actorMappingService, deleteGroups.getRemovedActorIds()); } catch (final SGroupNotFoundException sgnfe) { throw new DeletionException(new GroupNotFoundException(sgnfe)); } catch (final SBonitaException e) { @@ -1032,9 +1026,9 @@ public void deleteGroups(final List groupIds) throws DeletionException { @Override public Group getGroup(final long groupId) throws GroupNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - return ModelConvertor.toGroup(tenantAccessor.getIdentityService().getGroup(groupId)); + return ModelConvertor.toGroup(serviceAccessor.getIdentityService().getGroup(groupId)); } catch (final SGroupNotFoundException e) { throw new GroupNotFoundException(e); } @@ -1043,7 +1037,7 @@ public Group getGroup(final long groupId) throws GroupNotFoundException { @Override public Group getGroupByPath(final String groupPath) throws GroupNotFoundException { try { - return ModelConvertor.toGroup(getTenantAccessor().getIdentityService().getGroupByPath(groupPath)); + return ModelConvertor.toGroup(getServiceAccessor().getIdentityService().getGroupByPath(groupPath)); } catch (final SGroupNotFoundException e) { throw new GroupNotFoundException(e); } @@ -1051,8 +1045,8 @@ public Group getGroupByPath(final String groupPath) throws GroupNotFoundExceptio @Override public long getNumberOfGroups() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetNumberOfInstance getNumberOfInstance = new GetNumberOfInstance("getNumberOfGroups", identityService); @@ -1079,10 +1073,10 @@ public Map getGroups(final List groupIds) { @Override public List getGroups(final int startIndex, final int maxResults, final GroupCriterion pagingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - String field = null; - OrderByType order = null; + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + String field; + OrderByType order; switch (pagingCriterion) { case NAME_ASC: field = SGroup.NAME; @@ -1114,9 +1108,9 @@ public List getGroups(final int startIndex, final int maxResults, final G @Override public SearchResult searchGroups(final SearchOptions options) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchGroups searchGroups = new SearchGroups(identityService, searchEntitiesDescriptor.getSearchGroupDescriptor(), options); try { @@ -1130,7 +1124,7 @@ public SearchResult searchGroups(final SearchOptions options) throws Sear /** * Check / update process resolution information, for all processes in a list of actor IDs. */ - private void updateActorProcessDependencies(final TenantServiceAccessor tenantAccessor, + private void updateActorProcessDependencies(final ServiceAccessor serviceAccessor, final ActorMappingService actorMappingService, final Set removedActorIds) throws SBonitaException { final Set processDefinitionIds = new HashSet<>(removedActorIds.size()); @@ -1141,8 +1135,8 @@ private void updateActorProcessDependencies(final TenantServiceAccessor tenantAc final Long processDefId = actor.getScopeId(); if (!processDefinitionIds.contains(processDefId)) { processDefinitionIds.add(processDefId); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(actor.getScopeId(), - tenantAccessor); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(actor.getScopeId(), + serviceAccessor); } } } @@ -1159,7 +1153,7 @@ private List getUsersWithOrder(final int startIndex, final int maxResults, } private OrderByType getUserOrderByType(final UserCriterion pagingCriterion) { - OrderByType order = null; + OrderByType order; switch (pagingCriterion) { case USER_NAME_ASC: order = OrderByType.ASC; @@ -1186,7 +1180,7 @@ private OrderByType getUserOrderByType(final UserCriterion pagingCriterion) { } private String getUserFieldKey(final UserCriterion pagingCriterion) { - String field = null; + String field; switch (pagingCriterion) { case USER_NAME_ASC: field = SUser.USER_NAME; @@ -1214,9 +1208,9 @@ private String getUserFieldKey(final UserCriterion pagingCriterion) { @Override public UserMembership addUserMembership(final long userId, final long groupId, final long roleId) - throws AlreadyExistsException, CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + throws CreationException { + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final long assignedBy = SessionInfos.getUserIdFromSession(); try { final GetUserMembership getUserMembership = new GetUserMembership(userId, groupId, roleId, identityService); @@ -1242,10 +1236,10 @@ public UserMembership addUserMembership(final long userId, final long groupId, f @Override public void addUserMemberships(final List userIds, final long groupId, final long roleId) - throws AlreadyExistsException, CreationException { + throws CreationException { // FIXME rewrite - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final long currentUserId = SessionInfos.getUserIdFromSession(); try { final AddUserMemberships transactionContent = new AddUserMemberships(groupId, roleId, userIds, @@ -1259,8 +1253,8 @@ public void addUserMemberships(final List userIds, final long groupId, fin @Override public UserMembership updateUserMembership(final long userMembershipId, final long newGroupId, final long newRoleId) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final EntityUpdateDescriptor changeDescriptor = BuilderFactory.get(SUserMembershipUpdateBuilderFactory.class) .createNewInstance() .updateGroupId(newGroupId).updateRoleId(newRoleId).done(); @@ -1279,8 +1273,8 @@ public UserMembership updateUserMembership(final long userMembershipId, final lo @Override public void deleteUserMembership(final long userMembershipId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { identityService.deleteUserMembership(userMembershipId); } catch (final SIdentityException e) { @@ -1291,8 +1285,8 @@ public void deleteUserMembership(final long userMembershipId) throws DeletionExc @Override public void deleteUserMembership(final long userId, final long groupId, final long roleId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { identityService.deleteLightUserMembership(identityService.getLightUserMembership(userId, groupId, roleId)); } catch (final SIdentityException e) { @@ -1303,8 +1297,8 @@ public void deleteUserMembership(final long userId, final long groupId, final lo @Override public void deleteUserMemberships(final List userIds, final long groupId, final long roleId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { for (final long userId : userIds) { final SUserMembership userMembership = identityService.getLightUserMembership(userId, groupId, roleId); @@ -1317,8 +1311,8 @@ public void deleteUserMemberships(final List userIds, final long groupId, @Override public UserMembership getUserMembership(final long userMembershipId) throws MembershipNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final GetUserMembership getUserMembership = new GetUserMembership(userMembershipId, identityService); try { getUserMembership.execute(); @@ -1331,8 +1325,8 @@ public UserMembership getUserMembership(final long userMembershipId) throws Memb @Override public long getNumberOfUserMemberships(final long userId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final TransactionContentWithResult transactionContent = new GetNumberOfUserMemberships(userId, identityService); @@ -1346,9 +1340,9 @@ public long getNumberOfUserMemberships(final long userId) { @Override public List getUserMemberships(final long userId, final int startIndex, final int maxResults, final UserMembershipCriterion pagingCrterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - final IdentityService identityService = tenantAccessor.getIdentityService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); OrderByOption orderByOption; switch (pagingCrterion) { case ROLE_NAME_DESC: @@ -1387,25 +1381,14 @@ public List getUserMemberships(final long userId, final int star } private List getUserMemberships(final long userId, final int startIndex, final int maxResults, - final OrderByOption orderByOption, - final IdentityService identityService) throws SBonitaException { - return getUserMemberships(userId, startIndex, maxResults, null, null, orderByOption, identityService); - } - - private List getUserMemberships(final long userId, final int startIndex, final int maxResults, - final OrderByType orderExecutor, - final String fieldExecutor, final OrderByOption orderByOption, final IdentityService identityService) - throws SBonitaException { + final OrderByOption orderByOption, final IdentityService identityService) throws SBonitaException { List sUserMemberships; if (userId == -1) { sUserMemberships = identityService.getUserMemberships(startIndex, maxResults, orderByOption); } else if (orderByOption != null) { sUserMemberships = identityService.getUserMembershipsOfUser(userId, startIndex, maxResults, orderByOption); - } else if (fieldExecutor == null) { - sUserMemberships = identityService.getUserMembershipsOfUser(userId, startIndex, maxResults); } else { - sUserMemberships = identityService.getUserMembershipsOfUser(userId, startIndex, maxResults, fieldExecutor, - orderExecutor); + sUserMemberships = identityService.getUserMembershipsOfUser(userId, startIndex, maxResults); } return ModelConvertor.toUserMembership(sUserMemberships); } @@ -1413,8 +1396,8 @@ private List getUserMemberships(final long userId, final int sta @Override public List getUserMembershipsByGroup(final long groupId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final GetUserMembershipsOfGroup transactionContentWithResult = new GetUserMembershipsOfGroup(groupId, identityService, startIndex, maxResults); try { @@ -1428,8 +1411,8 @@ public List getUserMembershipsByGroup(final long groupId, final @Override public List getUserMembershipsByRole(final long roleId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final GetUserMembershipsOfRole transactionContentWithResult = new GetUserMembershipsOfRole(roleId, identityService, startIndex, maxResults); @@ -1442,7 +1425,7 @@ public List getUserMembershipsByRole(final long roleId, final in @Override public void deleteOrganization() throws DeletionException { - final OrganizationAPIImpl organizationAPIImpl = new OrganizationAPIImpl(getTenantAccessor(), 100); + final OrganizationAPIImpl organizationAPIImpl = new OrganizationAPIImpl(getServiceAccessor(), 100); organizationAPIImpl.deleteOrganization(); } @@ -1459,9 +1442,9 @@ public List importOrganizationWithWarnings(String organizationContent, I @Override public String exportOrganization() throws OrganizationExportException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final int maxResults = 100; - final ExportOrganization exportOrganization = new ExportOrganization(tenantAccessor.getIdentityService(), + final ExportOrganization exportOrganization = new ExportOrganization(serviceAccessor.getIdentityService(), maxResults); try { exportOrganization.execute(); @@ -1473,8 +1456,7 @@ public String exportOrganization() throws OrganizationExportException { @Override public CustomUserInfoDefinition createCustomUserInfoDefinition(final CustomUserInfoDefinitionCreator creator) - throws CreationException, - AlreadyExistsException { + throws CreationException { return createCustomUserInfoDefinitionAPI().create(creator); } @@ -1507,7 +1489,7 @@ public List getCustomUserInfo(final long userId, final int start public SearchResult searchCustomUserInfoValues(final SearchOptions options) { try { return createCustomUserInfoValueAPI().search( - getTenantAccessor().getSearchEntitiesDescriptor().getSearchCustomUserInfoValueDescriptor(), + getServiceAccessor().getSearchEntitiesDescriptor().getSearchCustomUserInfoValueDescriptor(), options); } catch (final SBonitaException e) { throw new RetrieveException(e); @@ -1527,7 +1509,7 @@ public CustomUserInfoValue setCustomUserInfoValue(final long definitionId, final @Override public Icon getIcon(long id) throws NotFoundException { try { - SIcon icon = getTenantAccessor().getIconService().getIcon(id); + SIcon icon = getServiceAccessor().getIconService().getIcon(id); if (icon == null) { throw new NotFoundException("unable to find icon with id " + id); } @@ -1571,30 +1553,24 @@ private Sort getSortFromCriterion(UserCriterion criterion) { } private CustomUserInfoAPIDelegate createCustomUserInfoAPI() { - return new CustomUserInfoAPIDelegate(getTenantAccessor().getIdentityService()); + return new CustomUserInfoAPIDelegate(getServiceAccessor().getIdentityService()); } private CustomUserInfoDefinitionAPIDelegate createCustomUserInfoDefinitionAPI() { - return new CustomUserInfoDefinitionAPIDelegate(getTenantAccessor().getIdentityService()); + return new CustomUserInfoDefinitionAPIDelegate(getServiceAccessor().getIdentityService()); } private SCustomUserInfoValueAPI createCustomUserInfoValueAPI() { - return new SCustomUserInfoValueAPI(getTenantAccessor().getIdentityService(), + return new SCustomUserInfoValueAPI(getServiceAccessor().getIdentityService(), BuilderFactory.get(SCustomUserInfoValueUpdateBuilderFactory.class)); } - private class Sort { + private static class Sort { private String field = null; private OrderByType order = null; private Sort() { - - } - - private Sort(String field, OrderByType order) { - this.field = field; - this.order = order; } private String getField() { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java index 73246f67a58..314398f495f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java @@ -13,6 +13,7 @@ **/ package org.bonitasoft.engine.api.impl; +import java.io.IOException; import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -25,6 +26,7 @@ import org.bonitasoft.engine.core.login.LoginService; import org.bonitasoft.engine.core.login.SLoginException; import org.bonitasoft.engine.core.login.TechnicalUser; +import org.bonitasoft.engine.exception.BonitaHomeConfigurationException; import org.bonitasoft.engine.exception.TenantStatusException; import org.bonitasoft.engine.platform.LoginException; import org.bonitasoft.engine.platform.LogoutException; @@ -32,8 +34,6 @@ import org.bonitasoft.engine.platform.model.STenant; import org.bonitasoft.engine.service.ModelConvertor; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.session.SSessionNotFoundException; @@ -167,14 +167,18 @@ protected void checkThatWeCanLogin(final String userName, final STenant sTenant, } } - protected TenantServiceAccessor getTenantServiceAccessor() { - return TenantServiceSingleton.getInstance(); + protected ServiceAccessor getServiceAccessor() { + try { + return ServiceAccessorFactory.getInstance().createServiceAccessor(); + } catch (BonitaHomeConfigurationException | IOException | ReflectiveOperationException e) { + throw new RuntimeException(e); + } } @Override @CustomTransactions public void logout(final APISession session) throws LogoutException, SessionNotFoundException { - final TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { serviceAccessor.getLoginService().logout(session.getId()); } catch (final SSessionNotFoundException sbe) { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java index 55449c5883e..77f7dd0dfdd 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java @@ -29,7 +29,7 @@ import org.bonitasoft.engine.identity.model.SCustomUserInfoDefinition; import org.bonitasoft.engine.persistence.QueryOptions; import org.bonitasoft.engine.profile.ProfileService; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.supervisor.mapping.SupervisorMappingService; /** @@ -37,19 +37,19 @@ */ public class OrganizationAPIImpl { - private final TenantServiceAccessor tenantAccessor; + private final ServiceAccessor serviceAccessor; private final int pageSize; - public OrganizationAPIImpl(TenantServiceAccessor tenantAccessor, int pageSize) { - this.tenantAccessor = tenantAccessor; + public OrganizationAPIImpl(ServiceAccessor serviceAccessor, int pageSize) { + this.serviceAccessor = serviceAccessor; this.pageSize = pageSize; } public void deleteOrganization() throws DeletionException { - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SCommentService commentService = tenantAccessor.getCommentService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SCommentService commentService = serviceAccessor.getCommentService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final QueryOptions queryOptions = new QueryOptions(0, 1); @@ -58,7 +58,7 @@ public void deleteOrganization() throws DeletionException { && commentService.getNumberOfComments(queryOptions) == 0; if (canDeleteOrganization) { deleteOrganizationElements(activityInstanceService); - updateActorProcessDependenciesForAllActors(tenantAccessor); + updateActorProcessDependenciesForAllActors(serviceAccessor); } else { throw new DeletionException( "Can't delete a organization when a process, a human tasks, or a comment is active !!."); @@ -70,11 +70,11 @@ public void deleteOrganization() throws DeletionException { private void deleteOrganizationElements(final ActivityInstanceService activityInstanceService) throws SBonitaException { - final IdentityService identityService = tenantAccessor.getIdentityService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ProfileService profileService = tenantAccessor.getProfileService(); - final SupervisorMappingService supervisorService = tenantAccessor.getSupervisorService(); - final ExternalIdentityMappingService externalIdentityMappingService = tenantAccessor + final IdentityService identityService = serviceAccessor.getIdentityService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ProfileService profileService = serviceAccessor.getProfileService(); + final SupervisorMappingService supervisorService = serviceAccessor.getSupervisorService(); + final ExternalIdentityMappingService externalIdentityMappingService = serviceAccessor .getExternalIdentityMappingService(); deleteCustomUserInfo(identityService); @@ -110,17 +110,17 @@ private void deleteCustomUserInfo(List customUserInfo /** * Check / update process resolution information, for all processes in a list of actor IDs. */ - private void updateActorProcessDependenciesForAllActors(final TenantServiceAccessor tenantAccessor) + private void updateActorProcessDependenciesForAllActors(final ServiceAccessor serviceAccessor) throws SBonitaException { - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); List processDefinitionIds; final ActorBusinessArchiveArtifactManager dependencyResolver = new ActorBusinessArchiveArtifactManager( - tenantAccessor.getActorMappingService(), tenantAccessor.getIdentityService()); + serviceAccessor.getActorMappingService(), serviceAccessor.getIdentityService()); do { processDefinitionIds = processDefinitionService.getProcessDefinitionIds(0, 100); for (final Long processDefinitionId : processDefinitionIds) { - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, - tenantAccessor, dependencyResolver); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, + serviceAccessor, dependencyResolver); } } while (processDefinitionIds.size() == 100); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java index 18c57d51f4f..03991970d07 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java @@ -22,44 +22,21 @@ import org.bonitasoft.engine.api.impl.page.PageAPIDelegate; import org.bonitasoft.engine.commons.exceptions.SExecutionException; import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.BonitaRuntimeException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.ExecutionException; -import org.bonitasoft.engine.exception.InvalidPageTokenException; -import org.bonitasoft.engine.exception.InvalidPageZipInconsistentException; -import org.bonitasoft.engine.exception.InvalidPageZipMissingAPropertyException; -import org.bonitasoft.engine.exception.InvalidPageZipMissingIndexException; -import org.bonitasoft.engine.exception.InvalidPageZipMissingPropertiesException; -import org.bonitasoft.engine.exception.NotFoundException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; -import org.bonitasoft.engine.exception.UnauthorizedAccessException; -import org.bonitasoft.engine.exception.UpdateException; -import org.bonitasoft.engine.page.Page; -import org.bonitasoft.engine.page.PageCreator; -import org.bonitasoft.engine.page.PageMappingService; -import org.bonitasoft.engine.page.PageNotFoundException; -import org.bonitasoft.engine.page.PageURL; -import org.bonitasoft.engine.page.PageUpdater; -import org.bonitasoft.engine.page.SAuthorizationException; +import org.bonitasoft.engine.exception.*; +import org.bonitasoft.engine.page.*; import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; -import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; -import org.bonitasoft.engine.sessionaccessor.SessionAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; @AvailableWhenTenantIsPaused public class PageAPIImpl implements PageAPI { - protected TenantServiceAccessor getTenantAccessor() { + protected ServiceAccessor getServiceAccessor() { try { - final SessionAccessor sessionAccessor = ServiceAccessorFactory.getInstance().createSessionAccessor(); - return TenantServiceSingleton.getInstance(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } @@ -154,7 +131,7 @@ public PageURL resolvePageOrURL(String key, Map context, b } PageMappingService retrievePageMappingService() { - return getTenantAccessor().getPageMappingService(); + return getServiceAccessor().getPageMappingService(); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java index 3aaf039e58d..0d8f4278907 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java @@ -22,8 +22,8 @@ import org.bonitasoft.engine.commons.exceptions.SExecutionException; import org.bonitasoft.engine.exception.ExecutionException; import org.bonitasoft.engine.exception.NotFoundException; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Baptiste Mesta @@ -35,7 +35,7 @@ public class PermissionAPIImpl implements PermissionAPI { @Deprecated(forRemoval = true, since = "7.14.0") public boolean checkAPICallWithScript(String className, APICallContext context, boolean reload) throws ExecutionException, NotFoundException { - TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); PermissionService permissionService = serviceAccessor.getPermissionService(); try { return permissionService.checkAPICallWithScript(className, context, reload); @@ -50,7 +50,7 @@ public boolean checkAPICallWithScript(String className, APICallContext context, @Override public boolean isAuthorized(APICallContext apiCallContext) throws ExecutionException { - TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); try { return serviceAccessor.getPermissionService().isAuthorized(apiCallContext); } catch (SExecutionException e) { @@ -60,12 +60,12 @@ public boolean isAuthorized(APICallContext apiCallContext) throws ExecutionExcep @Override public Set getResourcePermissions(String resourceKey) { - TenantServiceAccessor serviceAccessor = getTenantServiceAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); return serviceAccessor.getPermissionService().getResourcePermissions(resourceKey); } - TenantServiceAccessor getTenantServiceAccessor() { - return TenantServiceSingleton.getInstance(); + ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessAPIImpl.java index 362aa7b16eb..84ca1fb8317 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessAPIImpl.java @@ -95,7 +95,6 @@ import org.bonitasoft.engine.commons.transaction.TransactionContentWithResult; import org.bonitasoft.engine.core.category.CategoryService; import org.bonitasoft.engine.core.category.exception.SCategoryAlreadyExistsException; -import org.bonitasoft.engine.core.category.exception.SCategoryException; import org.bonitasoft.engine.core.category.exception.SCategoryInProcessAlreadyExistsException; import org.bonitasoft.engine.core.category.exception.SCategoryNotFoundException; import org.bonitasoft.engine.core.category.model.SCategory; @@ -159,7 +158,6 @@ import org.bonitasoft.engine.data.instance.model.archive.SADataInstance; import org.bonitasoft.engine.dependency.model.ScopeType; import org.bonitasoft.engine.exception.*; -import org.bonitasoft.engine.execution.FlowNodeExecutor; import org.bonitasoft.engine.execution.ProcessInstanceInterruptor; import org.bonitasoft.engine.execution.SUnreleasableTaskException; import org.bonitasoft.engine.execution.event.EventsHandler; @@ -174,7 +172,6 @@ import org.bonitasoft.engine.expression.model.SExpression; import org.bonitasoft.engine.form.FormMapping; import org.bonitasoft.engine.identity.IdentityService; -import org.bonitasoft.engine.identity.SUserNotFoundException; import org.bonitasoft.engine.identity.User; import org.bonitasoft.engine.identity.UserNotFoundException; import org.bonitasoft.engine.identity.model.SUser; @@ -220,7 +217,8 @@ import org.bonitasoft.engine.search.task.SearchArchivedTasks; import org.bonitasoft.engine.search.task.SearchArchivedTasksManagedBy; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.session.model.SSession; import org.bonitasoft.engine.supervisor.mapping.SSupervisorDeletionException; import org.bonitasoft.engine.supervisor.mapping.SSupervisorNotFoundException; @@ -282,10 +280,10 @@ public ProcessAPIImpl(final ProcessManagementAPIImplDelegate processManagementAP @Override public SearchResult searchHumanTaskInstances(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); return AbstractHumanTaskInstanceSearchEntity .searchHumanTaskInstance(searchEntitiesDescriptor.getSearchHumanTaskInstanceDescriptor(), searchOptions, @@ -301,7 +299,7 @@ public void deleteProcessDefinition(final long processDefinitionId) throws Delet builder.filter(ProcessInstanceSearchDescriptor.PROCESS_DEFINITION_ID, processDefinitionId); final SearchOptions searchOptions = builder.done(); try { - final boolean hasOpenProcessInstances = searchProcessInstances(getTenantAccessor(), searchOptions) + final boolean hasOpenProcessInstances = searchProcessInstances(getServiceAccessor(), searchOptions) .getCount() > 0; checkIfItIsPossibleToDeleteProcessInstance(processDefinitionId, hasOpenProcessInstances); final boolean hasArchivedProcessInstances = searchArchivedProcessInstances(searchOptions).getCount() > 0; @@ -333,8 +331,7 @@ public void deleteProcessDefinitions(final List processDefinitionIds) thro } } - private void releaseLocks(final TenantServiceAccessor tenantAccessor, final LockService lockService, - final List locks, final long tenantId) { + private void releaseLocks(final LockService lockService, final List locks, final long tenantId) { if (locks == null) { return; } @@ -342,7 +339,7 @@ private void releaseLocks(final TenantServiceAccessor tenantAccessor, final Lock try { lockService.unlock(lock, tenantId); } catch (final SLockException e) { - logError(tenantAccessor, e); + logError(e); } } } @@ -400,7 +397,7 @@ public byte[] exportBarProcessContentUnderHome(final long processDefinitionId) t try { barExport = File.createTempFile("barExport", ".bar"); barExport.delete(); - final BusinessArchive export = getTenantAccessor().getBusinessArchiveService().export(processDefinitionId); + final BusinessArchive export = getServiceAccessor().getBusinessArchiveService().export(processDefinitionId); BusinessArchiveFactory.writeBusinessArchiveToFile(export, barExport); return FileUtils.readFileToByteArray(barExport); } catch (IOException | InvalidBusinessArchiveFormatException | SBonitaException e) { @@ -450,7 +447,7 @@ public void executeFlowNode(final long flownodeInstanceId) throws FlowNodeExecut @Override public void executeFlowNode(final long userId, final long flownodeInstanceId) throws FlowNodeExecutionException { try { - ActivityInstanceService activityInstanceService = getTenantAccessor().getActivityInstanceService(); + ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); SFlowNodeInstance flowNodeInstance = activityInstanceService.getFlowNodeInstance(flownodeInstanceId); log.warn(String.format( "executeFlowNode was called: <%s> is forcing the execution of the flow node with name = <%s> id = <%d> and type <%s> in current state <%s: %s>. " @@ -463,7 +460,7 @@ public void executeFlowNode(final long userId, final long flownodeInstanceId) th getLoggedUsername(), flowNodeInstance.getName(), flowNodeInstance.getId(), flowNodeInstance.getType().name(), flowNodeInstance.getStateId(), flowNodeInstance.getStateName())); - executeFlowNode(userId, flownodeInstanceId, new HashMap(), false); + executeFlowNode(userId, flownodeInstanceId, new HashMap<>(), false); } catch (final ContractViolationException | SBonitaException e) { throw new FlowNodeExecutionException(e); } @@ -472,9 +469,9 @@ public void executeFlowNode(final long userId, final long flownodeInstanceId) th @Override public List getActivities(final long processInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); try { return ModelConvertor.toActivityInstances( activityInstanceService.getActivityInstances(processInstanceId, startIndex, maxResults), @@ -486,8 +483,8 @@ public List getActivities(final long processInstanceId, final @Override public long getNumberOfProcessDeploymentInfos() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final TransactionContentWithResult transactionContentWithResult = new GetNumberOfProcessDeploymentInfos( processDefinitionService); try { @@ -501,8 +498,8 @@ public long getNumberOfProcessDeploymentInfos() { @Override public ProcessDefinition getProcessDefinition(final long processDefinitionId) throws ProcessDefinitionNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -518,7 +515,7 @@ public ProcessDefinition getProcessDefinition(final long processDefinitionId) public DesignProcessDefinition getDesignProcessDefinition(final long processDefinitionId) throws ProcessDefinitionNotFoundException { try { - return getTenantAccessor().getProcessDefinitionService().getDesignProcessDefinition(processDefinitionId); + return getServiceAccessor().getProcessDefinitionService().getDesignProcessDefinition(processDefinitionId); } catch (SBonitaReadException | SProcessDefinitionNotFoundException e) { throw new ProcessDefinitionNotFoundException(processDefinitionId, e); } @@ -530,13 +527,13 @@ public ProcessDeploymentInfo getProcessDeploymentInfo(final long processDefiniti return processDeploymentAPIDelegate.getProcessDeploymentInfo(processDefinitionId); } - private void logError(final TenantServiceAccessor tenantAccessor, final Exception e) { + private void logError(final Exception e) { if (log.isErrorEnabled()) { log.error("", e); } } - private void logInstanceNotFound(final TenantServiceAccessor tenantAccessor, final SBonitaException e) { + private void logInstanceNotFound(final SBonitaException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage() + ". It may have been completed."); } @@ -544,8 +541,8 @@ private void logInstanceNotFound(final TenantServiceAccessor tenantAccessor, fin @Override public ProcessInstance getProcessInstance(final long processInstanceId) throws ProcessInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessInstance sProcessInstance = getSProcessInstance(processInstanceId); return ModelConvertor @@ -559,26 +556,26 @@ public ProcessInstance getProcessInstance(final long processInstanceId) throws P protected SProcessInstance getSProcessInstance(final long processInstanceId) throws SProcessInstanceNotFoundException, SProcessInstanceReadException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); return processInstanceService.getProcessInstance(processInstanceId); } @Override public List getArchivedProcessInstances(final long processInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final GetArchivedProcessInstanceList getProcessInstanceList = new GetArchivedProcessInstanceList( processInstanceService, - tenantAccessor.getProcessDefinitionService(), searchEntitiesDescriptor, processInstanceId, startIndex, + serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor, processInstanceId, startIndex, maxResults); try { getProcessInstanceList.execute(); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new RetrieveException(e); } return getProcessInstanceList.getResult(); @@ -587,9 +584,9 @@ public List getArchivedProcessInstances(final long proc @Override public ArchivedProcessInstance getArchivedProcessInstance(final long id) throws ArchivedProcessInstanceNotFoundException, RetrieveException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SAProcessInstance archivedProcessInstance = processInstanceService.getArchivedProcessInstance(id); if (archivedProcessInstance == null) { @@ -615,20 +612,20 @@ protected ArchivedProcessInstance toArchivedProcessInstance(final SAProcessInsta @Override public ArchivedProcessInstance getFinalArchivedProcessInstance(final long sourceProcessInstanceId) throws ArchivedProcessInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final GetLastArchivedProcessInstance getProcessInstance = new GetLastArchivedProcessInstance( processInstanceService, - tenantAccessor.getProcessDefinitionService(), sourceProcessInstanceId, - tenantAccessor.getSearchEntitiesDescriptor()); + serviceAccessor.getProcessDefinitionService(), sourceProcessInstanceId, + serviceAccessor.getSearchEntitiesDescriptor()); try { getProcessInstance.execute(); } catch (final SProcessInstanceNotFoundException e) { - logInstanceNotFound(tenantAccessor, e); + logInstanceNotFound(e); throw new ArchivedProcessInstanceNotFoundException(e); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new RetrieveException(e); } return getProcessInstance.getResult(); @@ -653,8 +650,8 @@ public ProcessInstance startProcess(final long userId, final long processDefinit @Override public int getNumberOfActors(final long processDefinitionId) throws ProcessDefinitionNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final GetNumberOfActors getNumberofActors = new GetNumberOfActors(processDefinitionService, processDefinitionId); @@ -669,23 +666,10 @@ public int getNumberOfActors(final long processDefinitionId) throws ProcessDefin @Override public List getActors(final long processDefinitionId, final int startIndex, final int maxResults, final ActorCriterion sort) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { - OrderByType order; - if (sort == null) { - order = OrderByType.ASC; - } else { - switch (sort) { - case NAME_ASC: - order = OrderByType.ASC; - break; - default: - order = OrderByType.DESC; - break; - } - } - final QueryOptions queryOptions = new QueryOptions(startIndex, maxResults, SActor.class, "name", order); + final QueryOptions queryOptions = getQueryOptions(startIndex, maxResults, sort); final List actors = actorMappingService.getActors(processDefinitionId, queryOptions); return ModelConvertor.toActors(actors); } catch (final SBonitaException e) { @@ -693,10 +677,27 @@ public List getActors(final long processDefinitionId, final int s } } + private static QueryOptions getQueryOptions(int startIndex, int maxResults, ActorCriterion sort) { + OrderByType order; + if (sort == null) { + order = OrderByType.ASC; + } else { + switch (sort) { + case NAME_ASC: + order = OrderByType.ASC; + break; + default: + order = OrderByType.DESC; + break; + } + } + return new QueryOptions(startIndex, maxResults, SActor.class, "name", order); + } + @Override public List getActorMembers(final long actorId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { final List actorMembers = actorMappingService.getActorMembers(actorId, startIndex, @@ -710,9 +711,9 @@ public List getActorMembers(final long actorId, final int startInde @Override public long getNumberOfActorMembers(final long actorId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetNumberOfActorMembers numberOfActorMembers = new GetNumberOfActorMembers(actorMappingService, actorId); try { numberOfActorMembers.execute(); @@ -724,9 +725,9 @@ public long getNumberOfActorMembers(final long actorId) { @Override public long getNumberOfUsersOfActor(final long actorId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetNumberOfUsersOfActor numberOfUsersOfActor = new GetNumberOfUsersOfActor(actorMappingService, actorId); numberOfUsersOfActor.execute(); return numberOfUsersOfActor.getResult(); @@ -734,9 +735,9 @@ public long getNumberOfUsersOfActor(final long actorId) { @Override public long getNumberOfRolesOfActor(final long actorId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetNumberOfRolesOfActor numberOfRolesOfActor = new GetNumberOfRolesOfActor(actorMappingService, actorId); numberOfRolesOfActor.execute(); return numberOfRolesOfActor.getResult(); @@ -744,9 +745,9 @@ public long getNumberOfRolesOfActor(final long actorId) { @Override public long getNumberOfGroupsOfActor(final long actorId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetNumberOfGroupsOfActor numberOfGroupsOfActor = new GetNumberOfGroupsOfActor(actorMappingService, actorId); numberOfGroupsOfActor.execute(); @@ -755,9 +756,9 @@ public long getNumberOfGroupsOfActor(final long actorId) { @Override public long getNumberOfMembershipsOfActor(final long actorId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetNumberOfMembershipsOfActor getNumber = new GetNumberOfMembershipsOfActor(actorMappingService, actorId); getNumber.execute(); return getNumber.getResult(); @@ -769,9 +770,9 @@ public ActorInstance updateActor(final long actorId, final ActorUpdater descript if (descriptor == null || descriptor.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final SActorUpdateBuilder actorUpdateBuilder = BuilderFactory.get(SActorUpdateBuilderFactory.class) .createNewInstance(); final Map fields = descriptor.getFields(); @@ -801,8 +802,8 @@ public ActorInstance updateActor(final long actorId, final ActorUpdater descript @Override public ActorMember addUserToActor(final long actorId, final long userId) throws CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { // Check if the mapping already to throw a specific exception @@ -811,8 +812,8 @@ public ActorMember addUserToActor(final long actorId, final long userId) throws final SActorMember actorMember = actorMappingService.addUserToActor(actorId, userId); final long processDefinitionId = actorMappingService.getActor(actorId).getScopeId(); final ActorMember clientActorMember = ModelConvertor.toActorMember(actorMember); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, - tenantAccessor); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, + serviceAccessor); return clientActorMember; } catch (final SBonitaException sbe) { throw new CreationException(sbe); @@ -821,8 +822,8 @@ public ActorMember addUserToActor(final long actorId, final long userId) throws private void checkIfActorMappingForUserAlreadyExists(final long actorId, final long userId) throws AlreadyExistsException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { final SActorMember sActorMember = actorMappingService.getActorMember(actorId, userId, -1, -1); @@ -852,8 +853,8 @@ public ActorMember addUserToActor(final String actorName, final ProcessDefinitio @Override public ActorMember addGroupToActor(final long actorId, final long groupId) throws CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { // Check if the mapping already to throw a specific exception checkIfActorMappingForGroupAlreadyExists(actorId, groupId); @@ -861,8 +862,8 @@ public ActorMember addGroupToActor(final long actorId, final long groupId) throw final SActorMember actorMember = actorMappingService.addGroupToActor(actorId, groupId); final long processDefinitionId = actorMappingService.getActor(actorId).getScopeId(); final ActorMember clientActorMember = ModelConvertor.toActorMember(actorMember); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, - tenantAccessor); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, + serviceAccessor); return clientActorMember; } catch (final SBonitaException e) { throw new CreationException(e); @@ -871,8 +872,8 @@ public ActorMember addGroupToActor(final long actorId, final long groupId) throw private void checkIfActorMappingForGroupAlreadyExists(final long actorId, final long groupId) throws AlreadyExistsException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { final SActorMember sActorMember = actorMappingService.getActorMember(actorId, -1, groupId, -1); @@ -902,8 +903,8 @@ public ActorMember addGroupToActor(final String actorName, final long groupId, @Override public ActorMember addRoleToActor(final long actorId, final long roleId) throws CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { // Check if the mapping already to throw a specific exception @@ -912,8 +913,8 @@ public ActorMember addRoleToActor(final long actorId, final long roleId) throws final SActorMember actorMember = actorMappingService.addRoleToActor(actorId, roleId); final long processDefinitionId = actorMappingService.getActor(actorId).getScopeId(); final ActorMember clientActorMember = ModelConvertor.toActorMember(actorMember); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, - tenantAccessor); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, + serviceAccessor); return clientActorMember; } catch (final SBonitaException sbe) { throw new CreationException(sbe); @@ -922,8 +923,8 @@ public ActorMember addRoleToActor(final long actorId, final long roleId) throws private void checkIfActorMappingForRoleAlreadyExists(final long actorId, final long roleId) throws AlreadyExistsException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { final SActorMember sActorMember = actorMappingService.getActorMember(actorId, -1, -1, roleId); @@ -969,8 +970,8 @@ public ActorMember addRoleAndGroupToActor(final String actorName, final ProcessD @Override public ActorMember addRoleAndGroupToActor(final long actorId, final long roleId, final long groupId) throws CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { checkIfActorMappingForMembershipAlreadyExists(actorId, roleId, groupId); @@ -978,8 +979,8 @@ public ActorMember addRoleAndGroupToActor(final long actorId, final long roleId, final SActorMember actorMember = actorMappingService.addRoleAndGroupToActor(actorId, roleId, groupId); final long processDefinitionId = actorMappingService.getActor(actorId).getScopeId(); final ActorMember clientActorMember = ModelConvertor.toActorMember(actorMember); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, - tenantAccessor); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, + serviceAccessor); return clientActorMember; } catch (final SBonitaException sbe) { throw new CreationException(sbe); @@ -988,8 +989,8 @@ public ActorMember addRoleAndGroupToActor(final long actorId, final long roleId, private void checkIfActorMappingForMembershipAlreadyExists(final long actorId, final long roleId, final long groupId) throws AlreadyExistsException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); try { final SActorMember sActorMember = actorMappingService.getActorMember(actorId, -1, groupId, roleId); @@ -1005,17 +1006,17 @@ private void checkIfActorMappingForMembershipAlreadyExists(final long actorId, f @Override public void removeActorMember(final long actorMemberId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final RemoveActorMember removeActorMember = new RemoveActorMember(actorMappingService, actorMemberId); // FIXME remove an actor member when process is running! try { removeActorMember.execute(); final SActorMember actorMember = removeActorMember.getResult(); final long processDefinitionId = getActor(actorMember.getActorId()).getProcessDefinitionId(); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, - tenantAccessor); + serviceAccessor.getBusinessArchiveArtifactsManager().resolveDependencies(processDefinitionId, + serviceAccessor); } catch (final SBonitaException | ActorNotFoundException sbe) { throw new DeletionException(sbe); } @@ -1024,8 +1025,8 @@ public void removeActorMember(final long actorMemberId) throws DeletionException @Override public ActorInstance getActor(final long actorId) throws ActorNotFoundException { try { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetActor getActor = new GetActor(actorMappingService, actorId); getActor.execute(); @@ -1038,9 +1039,9 @@ public ActorInstance getActor(final long actorId) throws ActorNotFoundException @Override public ActivityInstance getActivityInstance(final long activityInstanceId) throws ActivityInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SActivityInstance sActivityInstance; try { sActivityInstance = getSActivityInstance(activityInstanceId); @@ -1054,18 +1055,18 @@ public ActivityInstance getActivityInstance(final long activityInstanceId) protected SActivityInstance getSActivityInstance(final long activityInstanceId) throws SActivityInstanceNotFoundException, SActivityReadException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); return activityInstanceService.getActivityInstance(activityInstanceId); } @Override public FlowNodeInstance getFlowNodeInstance(final long flowNodeInstanceId) throws FlowNodeInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); try { final SFlowNodeInstance flowNodeInstance = activityInstanceService.getFlowNodeInstance(flowNodeInstanceId); return ModelConvertor.toFlowNodeInstance(flowNodeInstance, flowNodeStateManager); @@ -1080,11 +1081,11 @@ public FlowNodeInstance getFlowNodeInstance(final long flowNodeInstanceId) public List getAssignedHumanTaskInstances(final long userId, final int startIndex, final int maxResults, final ActivityInstanceCriterion pagingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForActivityInstance(pagingCriterion); - final ActivityInstanceService instanceService = tenantAccessor.getActivityInstanceService(); + final ActivityInstanceService instanceService = serviceAccessor.getActivityInstanceService(); try { final GetAssignedTasks getAssignedTasks = new GetAssignedTasks(instanceService, userId, startIndex, maxResults, orderAndField.getField(), @@ -1092,8 +1093,6 @@ public List getAssignedHumanTaskInstances(final long userId, getAssignedTasks.execute(); final List assignedTasks = getAssignedTasks.getResult(); return ModelConvertor.toHumanTaskInstances(assignedTasks, flowNodeStateManager); - } catch (final SUserNotFoundException e) { - return Collections.emptyList(); } catch (final SBonitaException e) { return Collections.emptyList(); } @@ -1101,11 +1100,11 @@ public List getAssignedHumanTaskInstances(final long userId, @Override public long getNumberOfPendingHumanTaskInstances(final long userId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); - final ProcessDefinitionService processDefService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefService = serviceAccessor.getProcessDefinitionService(); try { final Set actorIds = getActorsForUser(userId, actorMappingService, processDefService); if (actorIds.isEmpty()) { @@ -1121,13 +1120,13 @@ public long getNumberOfPendingHumanTaskInstances(final long userId) { public List getPendingHumanTaskInstances(final long userId, final int startIndex, final int maxResults, final ActivityInstanceCriterion pagingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForActivityInstance(pagingCriterion); - final ProcessDefinitionService definitionService = tenantAccessor.getProcessDefinitionService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ProcessDefinitionService definitionService = serviceAccessor.getProcessDefinitionService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final Set actorIds = getActorsForUser(userId, actorMappingService, definitionService); final List pendingTasks = activityInstanceService.getPendingTasks(userId, actorIds, @@ -1157,9 +1156,9 @@ private Set getActorsForUser(final long userId, final ActorMappingService @Override public ArchivedActivityInstance getArchivedActivityInstance(final long sourceActivityInstanceId) throws ActivityInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final GetArchivedActivityInstance getActivityInstance = new GetArchivedActivityInstance(activityInstanceService, sourceActivityInstanceId); try { @@ -1176,10 +1175,10 @@ public ArchivedActivityInstance getArchivedActivityInstance(final long sourceAct public ArchivedFlowNodeInstance getArchivedFlowNodeInstance(final long archivedFlowNodeInstanceId) throws ArchivedFlowNodeInstanceNotFoundException, RetrieveException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); try { final SAFlowNodeInstance archivedFlowNodeInstance = activityInstanceService @@ -1195,14 +1194,14 @@ public ArchivedFlowNodeInstance getArchivedFlowNodeInstance(final long archivedF @Override public List getProcessInstances(final int startIndex, final int maxResults, final ProcessInstanceCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForProcessInstance(criterion); final SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(startIndex, maxResults); searchOptionsBuilder.sort(orderAndField.getField(), Order.valueOf(orderAndField.getOrder().name())); List result; try { - result = searchProcessInstances(tenantAccessor, searchOptionsBuilder.done()).getResult(); + result = searchProcessInstances(serviceAccessor, searchOptionsBuilder.done()).getResult(); } catch (final SBonitaException e) { result = Collections.emptyList(); } @@ -1211,11 +1210,11 @@ public List getProcessInstances(final int startIndex, final int @Override public long getNumberOfProcessInstances() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); try { final TransactionContentWithResult transactionContent = new GetNumberOfProcessInstance( @@ -1228,12 +1227,12 @@ public long getNumberOfProcessInstances() { } } - protected SearchResult searchProcessInstances(final TenantServiceAccessor tenantAccessor, + protected SearchResult searchProcessInstances(final ServiceAccessor serviceAccessor, final SearchOptions searchOptions) throws SBonitaException { - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchProcessInstances searchProcessInstances = new SearchProcessInstances(processInstanceService, searchEntitiesDescriptor.getSearchProcessInstanceDescriptor(), searchOptions, processDefinitionService); @@ -1244,7 +1243,7 @@ protected SearchResult searchProcessInstances(final TenantServi @Override public List getArchivedProcessInstances(final int startIndex, final int maxResults, final ProcessInstanceCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForProcessInstance(criterion); @@ -1254,7 +1253,7 @@ public List getArchivedProcessInstances(final int start ProcessInstanceState.COMPLETED.getId()); searchOptionsBuilder.filter(ArchivedProcessInstancesSearchDescriptor.CALLER_ID, -1); final SearchArchivedProcessInstances searchArchivedProcessInstances = searchArchivedProcessInstances( - tenantAccessor, searchOptionsBuilder.done()); + serviceAccessor, searchOptionsBuilder.done()); try { searchArchivedProcessInstances.execute(); } catch (final SBonitaException e) { @@ -1264,19 +1263,19 @@ public List getArchivedProcessInstances(final int start return searchArchivedProcessInstances.getResult().getResult(); } - private SearchArchivedProcessInstances searchArchivedProcessInstances(final TenantServiceAccessor tenantAccessor, + private SearchArchivedProcessInstances searchArchivedProcessInstances(final ServiceAccessor serviceAccessor, final SearchOptions searchOptions) throws RetrieveException { - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - return new SearchArchivedProcessInstances(processInstanceService, tenantAccessor.getProcessDefinitionService(), + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + return new SearchArchivedProcessInstances(processInstanceService, serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor.getSearchArchivedProcessInstanceDescriptor(), searchOptions); } @Override public long getNumberOfArchivedProcessInstances() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); try { final SAProcessInstanceBuilderFactory saProcessInstanceBuilder = BuilderFactory .get(SAProcessInstanceBuilderFactory.class); @@ -1285,11 +1284,10 @@ public long getNumberOfArchivedProcessInstances() { ProcessInstanceState.COMPLETED.getId())); filterOptions.add(new FilterOption(SAProcessInstance.class, saProcessInstanceBuilder.getCallerIdKey(), -1)); final QueryOptions queryOptions = new QueryOptions(0, QueryOptions.UNLIMITED_NUMBER_OF_RESULTS, - Collections. emptyList(), - filterOptions, null); + Collections.emptyList(), filterOptions, null); return processInstanceService.getNumberOfArchivedProcessInstances(queryOptions); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new RetrieveException(e); } } @@ -1297,11 +1295,11 @@ Collections. emptyList(), @Override public SearchResult searchArchivedProcessInstances(final SearchOptions searchOptions) throws RetrieveException, SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchArchivedProcessInstancesWithoutSubProcess searchArchivedProcessInstances = new SearchArchivedProcessInstancesWithoutSubProcess( - processInstanceService, tenantAccessor.getProcessDefinitionService(), + processInstanceService, serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor.getSearchArchivedProcessInstanceDescriptor(), searchOptions); try { @@ -1315,12 +1313,12 @@ public SearchResult searchArchivedProcessInstances(fina @Override public SearchResult searchArchivedProcessInstancesInAllStates( final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchArchivedProcessInstances searchArchivedProcessInstances = new SearchArchivedProcessInstances( processInstanceService, - tenantAccessor.getProcessDefinitionService(), + serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor.getSearchArchivedProcessInstanceDescriptor(), searchOptions); try { searchArchivedProcessInstances.execute(); @@ -1334,9 +1332,9 @@ public SearchResult searchArchivedProcessInstancesInAll public List getOpenActivityInstances(final long processInstanceId, final int startIndex, final int maxResults, final ActivityInstanceCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); try { final int totalNumber = activityInstanceService.getNumberOfOpenActivityInstances(processInstanceId); @@ -1357,22 +1355,18 @@ public List getOpenActivityInstances(final long processInstanc @Override public List getArchivedActivityInstances(final long processInstanceId, - final int startIndex, final int maxResults, - final ActivityInstanceCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final List archivedActivityInstances = getArchivedActivityInstances(processInstanceId, - startIndex, maxResults, criterion, - tenantAccessor); - return archivedActivityInstances; + final int startIndex, final int maxResults, final ActivityInstanceCriterion criterion) { + final ServiceAccessor serviceAccessor = getServiceAccessor(); + return getArchivedActivityInstances(processInstanceId, startIndex, maxResults, criterion, serviceAccessor); } private List getArchivedActivityInstances(final long processInstanceId, final int pageIndex, final int numberPerPage, - final ActivityInstanceCriterion pagingCriterion, final TenantServiceAccessor tenantAccessor) + final ActivityInstanceCriterion pagingCriterion, final ServiceAccessor serviceAccessor) throws RetrieveException { - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForActivityInstance(pagingCriterion); final GetArchivedActivityInstances getActivityInstances = new GetArchivedActivityInstances( activityInstanceService, processInstanceId, pageIndex, @@ -1380,7 +1374,7 @@ private List getArchivedActivityInstances(final long p try { getActivityInstances.execute(); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new RetrieveException(e); } return ModelConvertor.toArchivedActivityInstances(getActivityInstances.getResult(), flowNodeStateManager); @@ -1388,8 +1382,8 @@ private List getArchivedActivityInstances(final long p @Override public int getNumberOfOpenedActivityInstances(final long processInstanceId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final TransactionContentWithResult transactionContentWithResult = new GetNumberOfActivityInstance( processInstanceId, activityInstanceService); @@ -1402,10 +1396,9 @@ public int getNumberOfOpenedActivityInstances(final long processInstanceId) { } @Override - public Category createCategory(final String name, final String description) - throws AlreadyExistsException, CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + public Category createCategory(final String name, final String description) throws CreationException { + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); try { final CreateCategory createCategory = new CreateCategory(name, description, categoryService); @@ -1420,9 +1413,9 @@ public Category createCategory(final String name, final String description) @Override public Category getCategory(final long categoryId) throws CategoryNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); try { final GetCategory getCategory = new GetCategory(categoryService, categoryId); getCategory.execute(); @@ -1435,7 +1428,7 @@ public Category getCategory(final long categoryId) throws CategoryNotFoundExcept @Override public long getNumberOfCategories() { - final CategoryService categoryService = getTenantAccessor().getCategoryService(); + final CategoryService categoryService = getServiceAccessor().getCategoryService(); try { final GetNumberOfCategories getNumberOfCategories = new GetNumberOfCategories(categoryService); getNumberOfCategories.execute(); @@ -1448,10 +1441,10 @@ public long getNumberOfCategories() { @Override public List getCategories(final int startIndex, final int maxResults, final CategoryCriterion sortCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); - String field = null; - OrderByType order = null; + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); + String field; + OrderByType order; switch (sortCriterion) { case NAME_ASC: field = SCategory.NAME; @@ -1476,10 +1469,11 @@ public List getCategories(final int startIndex, final int maxResults, @Override public void addCategoriesToProcess(final long processDefinitionId, final List categoryIds) - throws AlreadyExistsException, CreationException { + throws CreationException { try { - final CategoryService categoryService = getTenantAccessor().getCategoryService(); - final ProcessDefinitionService processDefinitionService = getTenantAccessor().getProcessDefinitionService(); + final CategoryService categoryService = getServiceAccessor().getCategoryService(); + final ProcessDefinitionService processDefinitionService = getServiceAccessor() + .getProcessDefinitionService(); for (final Long categoryId : categoryIds) { new AddProcessDefinitionToCategory(categoryId, processDefinitionId, categoryService, processDefinitionService).execute(); @@ -1495,7 +1489,7 @@ public void addCategoriesToProcess(final long processDefinitionId, final List categoryIds) throws DeletionException { try { - final CategoryService categoryService = getTenantAccessor().getCategoryService(); + final CategoryService categoryService = getServiceAccessor().getCategoryService(); final TransactionContent transactionContent = new RemoveCategoriesFromProcessDefinition(processDefinitionId, categoryIds, categoryService); transactionContent.execute(); @@ -1506,18 +1500,15 @@ public void removeCategoriesFromProcess(final long processDefinitionId, final Li @Override public void addProcessDefinitionToCategory(final long categoryId, final long processDefinitionId) - throws AlreadyExistsException, CreationException { + throws CreationException { try { - final CategoryService categoryService = getTenantAccessor().getCategoryService(); - final ProcessDefinitionService processDefinitionService = getTenantAccessor().getProcessDefinitionService(); + final CategoryService categoryService = getServiceAccessor().getCategoryService(); + final ProcessDefinitionService processDefinitionService = getServiceAccessor() + .getProcessDefinitionService(); final TransactionContent transactionContent = new AddProcessDefinitionToCategory(categoryId, processDefinitionId, categoryService, processDefinitionService); transactionContent.execute(); - } catch (final SProcessDefinitionNotFoundException e) { - throw new CreationException(e); - } catch (final SCategoryNotFoundException scnfe) { - throw new CreationException(scnfe); } catch (final SCategoryInProcessAlreadyExistsException cipaee) { throw new AlreadyExistsException(cipaee); } catch (final SBonitaException sbe) { @@ -1527,18 +1518,15 @@ public void addProcessDefinitionToCategory(final long categoryId, final long pro @Override public void addProcessDefinitionsToCategory(final long categoryId, final List processDefinitionIds) - throws AlreadyExistsException, CreationException { + throws CreationException { try { - final CategoryService categoryService = getTenantAccessor().getCategoryService(); - final ProcessDefinitionService processDefinitionService = getTenantAccessor().getProcessDefinitionService(); + final CategoryService categoryService = getServiceAccessor().getCategoryService(); + final ProcessDefinitionService processDefinitionService = getServiceAccessor() + .getProcessDefinitionService(); for (final Long processDefinitionId : processDefinitionIds) { new AddProcessDefinitionToCategory(categoryId, processDefinitionId, categoryService, processDefinitionService).execute(); } - } catch (final SProcessDefinitionNotFoundException e) { - throw new CreationException(e); - } catch (final SCategoryNotFoundException scnfe) { - throw new CreationException(scnfe); } catch (final SCategoryInProcessAlreadyExistsException cipaee) { throw new AlreadyExistsException(cipaee); } catch (final SBonitaException sbe) { @@ -1549,9 +1537,9 @@ public void addProcessDefinitionsToCategory(final long categoryId, final List getProcessDeploymentInfosOfCategory(final lon if (sortCriterion == null) { throw new IllegalArgumentException("You must to have a criterion to sort your result."); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final OrderByType order = buildOrderByType(sortCriterion.getOrder()); final String field = sortCriterion.getField(); try { @@ -1597,9 +1585,9 @@ public List getProcessDeploymentInfosOfCategory(final lon public List getCategoriesOfProcessDefinition(final long processDefinitionId, final int startIndex, final int maxResults, final CategoryCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); try { final OrderByType order = buildOrderByType(sortingCriterion.getOrder()); return ModelConvertor.toCategories(categoryService.getCategoriesOfProcessDefinition(processDefinitionId, @@ -1617,9 +1605,9 @@ private OrderByType buildOrderByType(final Order order) { public List getCategoriesUnrelatedToProcessDefinition(final long processDefinitionId, final int startIndex, final int maxResults, final CategoryCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); try { final OrderByType order = buildOrderByType(sortingCriterion.getOrder()); return ModelConvertor.toCategories(categoryService @@ -1635,8 +1623,8 @@ public void updateCategory(final long categoryId, final CategoryUpdater updater) if (updater == null || updater.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); try { final SCategoryUpdateBuilderFactory fact = BuilderFactory.get(SCategoryUpdateBuilderFactory.class); @@ -1670,8 +1658,8 @@ public void deleteCategory(final long categoryId) throws DeletionException { if (categoryId <= 0) { throw new DeletionException("Category id can not be less than 0!"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); final DeleteSCategory deleteSCategory = new DeleteSCategory(categoryService, categoryId); try { @@ -1685,10 +1673,10 @@ public void deleteCategory(final long categoryId) throws DeletionException { @Override public long getNumberOfUncategorizedProcessDefinitions() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); try { final List processDefinitionIds = processDefinitionService.getProcessDefinitionIds(0, Integer.MAX_VALUE); @@ -1709,8 +1697,8 @@ public long getNumberOfUncategorizedProcessDefinitions() { public List getUncategorizedProcessDeploymentInfos(final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final QueryOptions queryOptions = new QueryOptions(startIndex, maxResults, SProcessDefinitionDeployInfo.class, sortCriterion.getField(), @@ -1726,8 +1714,8 @@ public List getUncategorizedProcessDeploymentInfos(final @Override public long getNumberOfProcessDeploymentInfosUnrelatedToCategory(final long categoryId) { try { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final GetNumberOfProcessDeploymentInfosUnrelatedToCategory transactionContentWithResult = new GetNumberOfProcessDeploymentInfosUnrelatedToCategory( categoryId, processDefinitionService); @@ -1742,8 +1730,8 @@ public long getNumberOfProcessDeploymentInfosUnrelatedToCategory(final long cate public List getProcessDeploymentInfosUnrelatedToCategory(final long categoryId, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { return ModelConvertor.toProcessDeploymentInfo( @@ -1757,8 +1745,8 @@ public List getProcessDeploymentInfosUnrelatedToCategory( @Override public long removeCategoriesFromProcessDefinition(final long processDefinitionId, final int startIndex, final int maxResults) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); final SProcessCategoryMappingBuilderFactory fact = BuilderFactory .get(SProcessCategoryMappingBuilderFactory.class); @@ -1778,15 +1766,15 @@ public long removeCategoriesFromProcessDefinition(final long processDefinitionId } private void removeAllCategoriesFromProcessDefinition(final long processDefinitionId) - throws SCategoryException, DeletionException { + throws DeletionException { removeCategoriesFromProcessDefinition(processDefinitionId, 0, Integer.MAX_VALUE); } @Override public long removeProcessDefinitionsFromCategory(final long categoryId, final int startIndex, final int maxResults) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final CategoryService categoryService = tenantAccessor.getCategoryService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final CategoryService categoryService = serviceAccessor.getCategoryService(); final SProcessCategoryMappingBuilderFactory fact = BuilderFactory .get(SProcessCategoryMappingBuilderFactory.class); @@ -1808,10 +1796,10 @@ public long removeProcessDefinitionsFromCategory(final long categoryId, final in @Override public List getEventInstances(final long rootContainerId, final int startIndex, final int maxResults, final EventCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final EventInstanceService eventInstanceService = tenantAccessor.getEventInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final EventInstanceService eventInstanceService = serviceAccessor.getEventInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForEvent(criterion); final GetEventInstances getEventInstances = new GetEventInstances(eventInstanceService, rootContainerId, startIndex, maxResults, @@ -1827,16 +1815,12 @@ public List getEventInstances(final long rootContainerId, final i @Override public void assignUserTask(final long userTaskId, final long userId) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final AssignOrUnassignUserTask assignUserTask = new AssignOrUnassignUserTask(userId, userTaskId, - activityInstanceService, tenantAccessor.getFlowNodeStateManager().getStateBehaviors()); + activityInstanceService, serviceAccessor.getFlowNodeStateManager().getStateBehaviors()); assignUserTask.execute(); - } catch (final SUserNotFoundException sunfe) { - throw new UpdateException(sunfe); - } catch (final SActivityInstanceNotFoundException sainfe) { - throw new UpdateException(sainfe); } catch (final SBonitaException sbe) { throw new UpdateException(sbe); } @@ -1844,11 +1828,11 @@ public void assignUserTask(final long userTaskId, final long userId) throws Upda @Override public void assignUserTaskIfNotAssigned(final long userTaskId, final long userId) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final AssignUserTaskIfNotAssigned assignUserTask = new AssignUserTaskIfNotAssigned(userId, userTaskId, - activityInstanceService, tenantAccessor.getFlowNodeStateManager().getStateBehaviors()); + activityInstanceService, serviceAccessor.getFlowNodeStateManager().getStateBehaviors()); assignUserTask.execute(); } catch (final SBonitaException sbe) { throw new UpdateException("Unable to assign user task (id: " + userTaskId + ")" @@ -1859,7 +1843,7 @@ public void assignUserTaskIfNotAssigned(final long userTaskId, final long userId @CustomTransactions @Override public void assignAndExecuteUserTask(long userId, long userTaskInstanceId, Map inputs) - throws UpdateException, UserTaskNotFoundException, ContractViolationException, FlowNodeExecutionException { + throws UserTaskNotFoundException, ContractViolationException, FlowNodeExecutionException { try { inTx(() -> { assignUserTask(userTaskInstanceId, userId); @@ -1878,7 +1862,7 @@ public void assignAndExecuteUserTask(long userId, long userTaskInstanceId, Map userIds = result.getResult(); for (final Long userId : userIds) { createPendingMappingForUser(humanTaskInstanceId, userId); } if (userIds.size() == 1 && result.shouldAutoAssignTaskIfSingleResult()) { - tenantAccessor.getActivityInstanceService().assignHumanTask(humanTaskInstanceId, userIds.get(0)); + serviceAccessor.getActivityInstanceService().assignHumanTask(humanTaskInstanceId, userIds.get(0)); } } @@ -1939,9 +1923,9 @@ private FilterResult executeFilter(final long processDefinitionId, final long hu final String actorName, final SUserFilterDefinition sUserFilterDefinition) throws SUserFilterExecutionException, SClassLoaderException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final UserFilterService userFilterService = tenantAccessor.getUserFilterService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final UserFilterService userFilterService = serviceAccessor.getUserFilterService(); final ClassLoader processClassloader = classLoaderService.getClassLoader( identifier(ScopeType.PROCESS, processDefinitionId)); final SExpressionContext expressionContext = new SExpressionContext(humanTaskInstanceId, @@ -1955,8 +1939,8 @@ private FilterResult executeFilter(final long processDefinitionId, final long hu private void cleanPendingMappingsAndUnassignHumanTask(final long userTaskId, final SHumanTaskInstance humanTaskInstance) throws SFlowNodeNotFoundException, SFlowNodeReadException, SActivityModificationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); // release if (humanTaskInstance.getAssigneeId() > 0) { activityInstanceService.assignHumanTask(userTaskId, 0); @@ -1966,8 +1950,8 @@ private void cleanPendingMappingsAndUnassignHumanTask(final long userTaskId, private SHumanTaskInstance getSHumanTaskInstance(final long userTaskId) throws SFlowNodeNotFoundException, SFlowNodeReadException, UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SFlowNodeInstance flowNodeInstance = tenantAccessor.getActivityInstanceService() + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SFlowNodeInstance flowNodeInstance = serviceAccessor.getActivityInstanceService() .getFlowNodeInstance(userTaskId); if (!(flowNodeInstance instanceof SHumanTaskInstance)) { throw new UpdateException("The identifier does not refer to a human task"); @@ -1977,8 +1961,8 @@ private SHumanTaskInstance getSHumanTaskInstance(final long userTaskId) private void createPendingMappingForUser(final long humanTaskInstanceId, final Long userId) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final SPendingActivityMapping mapping = SPendingActivityMapping.builder().activityId(humanTaskInstanceId) .userId(userId) .build(); @@ -1990,12 +1974,12 @@ public List getActivityDataDefinitions(final long processDefinit final int startIndex, final int maxResults) throws ActivityDefinitionNotFoundException, ProcessDefinitionNotFoundException { - List subDataDefinitionList = Collections.emptyList(); + List subDataDefinitionList; List sdataDefinitionList = Collections.emptyList(); - final TenantServiceAccessor tenantAccessor; - tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor; + serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -2030,11 +2014,11 @@ public List getActivityDataDefinitions(final long processDefinit public List getProcessDataDefinitions(final long processDefinitionId, final int startIndex, final int maxResults) throws ProcessDefinitionNotFoundException { - List subDataDefinitionList = Collections.emptyList(); - final TenantServiceAccessor tenantAccessor; - tenantAccessor = getTenantAccessor(); + List subDataDefinitionList; + final ServiceAccessor serviceAccessor; + serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -2057,10 +2041,10 @@ public List getProcessDataDefinitions(final long processDefiniti @Override public HumanTaskInstance getHumanTaskInstance(final long activityInstanceId) throws ActivityInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final GetHumanTaskInstance getHumanTaskInstance = new GetHumanTaskInstance(activityInstanceService, activityInstanceId); try { @@ -2075,8 +2059,8 @@ public HumanTaskInstance getHumanTaskInstance(final long activityInstanceId) @Override public long getNumberOfAssignedHumanTaskInstances(final long userId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { return activityInstanceService.getNumberOfAssignedHumanTaskInstances(userId); } catch (final SActivityReadException e) { @@ -2086,8 +2070,8 @@ public long getNumberOfAssignedHumanTaskInstances(final long userId) { @Override public Map getNumberOfOpenTasks(final List userIds) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final GetNumberOfOpenTasksForUsers transactionContent = new GetNumberOfOpenTasksForUsers(userIds, @@ -2103,7 +2087,7 @@ public Map getNumberOfOpenTasks(final List userIds) { public Map getProcessResources(final long processDefinitionId, final String filenamesPattern) throws RetrieveException { try { - BusinessArchive businessArchive = getTenantAccessor().getBusinessArchiveService() + BusinessArchive businessArchive = getServiceAccessor().getBusinessArchiveService() .export(processDefinitionId); return businessArchive.getResources(filenamesPattern); } catch (SBonitaException | InvalidBusinessArchiveFormatException e) { @@ -2116,7 +2100,7 @@ public byte[] getExternalProcessResource(final long processDefinitionId, final S throws RetrieveException, FileNotFoundException { SBARResource resource; try { - resource = getTenantAccessor().getProcessResourcesService().get(processDefinitionId, + resource = getServiceAccessor().getProcessResourcesService().get(processDefinitionId, BARResourceType.EXTERNAL, fileName); } catch (SBonitaException e) { throw new RetrieveException(e); @@ -2129,8 +2113,8 @@ public byte[] getExternalProcessResource(final long processDefinitionId, final S @Override public long getLatestProcessDefinitionId(final String processName) throws ProcessDefinitionNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final TransactionContentWithResult transactionContent = new GetLatestProcessDefinitionId( processDefinitionService, processName); @@ -2145,12 +2129,12 @@ public long getLatestProcessDefinitionId(final String processName) throws Proces @Override public List getProcessDataInstances(final long processInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final long processDefinitionId = processInstanceService.getProcessInstance(processInstanceId) @@ -2173,12 +2157,12 @@ public List getProcessDataInstances(final long processInstanceId, @Override public DataInstance getProcessDataInstance(final String dataName, final long processInstanceId) throws DataNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final long processDefinitionId = processInstanceService.getProcessInstance(processInstanceId) @@ -2205,21 +2189,19 @@ public void updateProcessDataInstance(final String dataName, final long processI @Override public void updateProcessDataInstances(final long processInstanceId, final Map dataNameValues) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { - final ClassLoader processClassLoader = getProcessInstanceClassloader(tenantAccessor, processInstanceId); + final ClassLoader processClassLoader = getProcessInstanceClassloader(serviceAccessor, processInstanceId); Thread.currentThread().setContextClassLoader(processClassLoader); final List dataNames = new ArrayList<>(dataNameValues.keySet()); final List sDataInstances = dataInstanceService.getDataInstances(dataNames, processInstanceId, DataInstanceContainer.PROCESS_INSTANCE.toString(), parentContainerResolver); updateDataInstances(sDataInstances, dataNameValues, processClassLoader); - } catch (final SBonitaException e) { - throw new UpdateException(e); - } catch (final ClassNotFoundException e) { + } catch (final SBonitaException | ClassNotFoundException e) { throw new UpdateException(e); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); @@ -2230,8 +2212,8 @@ protected void updateDataInstances(final List sDataInstances, final Map dataNameValues, ClassLoader classLoader) throws ClassNotFoundException, UpdateException, SDataInstanceException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); for (final SDataInstance sDataInstance : sDataInstances) { final Serializable dataValue = dataNameValues.get(sDataInstance.getName()); updateDataInstance(dataInstanceService, sDataInstance, dataValue, classLoader); @@ -2272,19 +2254,11 @@ private EntityUpdateDescriptor buildEntityUpdateDescriptorForData(final Serializ return entityUpdateDescriptor; } - /** - * @param tenantAccessor - * @param processInstanceId - * @return - * @throws SProcessInstanceNotFoundException - * @throws SProcessInstanceReadException - * @throws SClassLoaderException - */ - protected ClassLoader getProcessInstanceClassloader(final TenantServiceAccessor tenantAccessor, + protected ClassLoader getProcessInstanceClassloader(final ServiceAccessor serviceAccessor, final long processInstanceId) throws SProcessInstanceNotFoundException, SProcessInstanceReadException, SClassLoaderException { - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final long processDefinitionId = processInstanceService.getProcessInstance(processInstanceId) .getProcessDefinitionId(); return classLoaderService.getClassLoader(identifier(ScopeType.PROCESS, processDefinitionId)); @@ -2293,12 +2267,12 @@ protected ClassLoader getProcessInstanceClassloader(final TenantServiceAccessor @Override public List getActivityDataInstances(final long activityInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -2323,12 +2297,12 @@ public List getActivityDataInstances(final long activityInstanceId @Override public DataInstance getActivityDataInstance(final String dataName, final long activityInstanceId) throws DataNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -2353,12 +2327,12 @@ public DataInstance getActivityDataInstance(final String dataName, final long ac @Override public void updateActivityDataInstance(final String dataName, final long activityInstanceId, final Serializable dataValue) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -2381,11 +2355,11 @@ public void updateActivityDataInstance(final String dataName, final long activit @Override public DataInstance getActivityTransientDataInstance(final String dataName, final long activityInstanceId) throws DataNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final TransientDataService transientDataService = tenantAccessor.getTransientDataService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final TransientDataService transientDataService = serviceAccessor.getTransientDataService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -2416,11 +2390,11 @@ protected DataInstance convertModeltoDataInstance(final SDataInstance data) { @Override public List getActivityTransientDataInstances(final long activityInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final TransientDataService transientDataService = tenantAccessor.getTransientDataService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final TransientDataService transientDataService = serviceAccessor.getTransientDataService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -2451,11 +2425,11 @@ protected List convertModelToDataInstances(final List getSupportedStates(final FlowNodeType nodeType) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); return flowNodeStateManager.getSupportedState(SFlowNodeType.valueOf(nodeType.toString())); } @Override public void updateActivityInstanceVariables(final long activityInstanceId, final Map variables) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -2651,11 +2623,11 @@ public void updateActivityInstanceVariables(final long activityInstanceId, @Override public void updateActivityInstanceVariables(final List operations, final long activityInstanceId, final Map expressionContexts) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final OperationService operationService = tenantAccessor.getOperationService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); + final OperationService operationService = serviceAccessor.getOperationService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final SActivityInstance activityInstance = activityInstanceService.getActivityInstance(activityInstanceId); @@ -2676,10 +2648,6 @@ public void updateActivityInstanceVariables(final List operations, fi } } - protected SOperation convertOperation(final Operation operation) { - return ModelConvertor.convertOperation(operation); - } - protected List convertOperations(final List operations) { return ModelConvertor.convertOperations(operations); } @@ -2729,18 +2697,18 @@ public long getOneAssignedUserTaskInstanceOfProcessDefinition(final long process @Override public String getActivityInstanceState(final long activityInstanceId) throws ActivityInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); try { final SActivityInstance sActivityInstance = getSActivityInstance(activityInstanceId); final ActivityInstance activityInstance = ModelConvertor.toActivityInstance(sActivityInstance, flowNodeStateManager); return activityInstance.getState(); } catch (final SActivityInstanceNotFoundException e) { - logInstanceNotFound(tenantAccessor, e); + logInstanceNotFound(e); throw new ActivityInstanceNotFoundException(activityInstanceId); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new ActivityInstanceNotFoundException(e); } } @@ -2761,13 +2729,13 @@ public long getProcessDefinitionId(final String name, final String version) @Override public void releaseUserTask(final long userTaskId) throws ActivityInstanceNotFoundException, UpdateException { - final TenantServiceAccessor tenantAccessor; - tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor; + serviceAccessor = getServiceAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final AssignOrUnassignUserTask assignUserTask = new AssignOrUnassignUserTask(0, userTaskId, - activityInstanceService, tenantAccessor + activityInstanceService, serviceAccessor .getFlowNodeStateManager().getStateBehaviors()); assignUserTask.execute(); } catch (final SUnreleasableTaskException e) { @@ -2775,7 +2743,7 @@ public void releaseUserTask(final long userTaskId) throws ActivityInstanceNotFou } catch (final SActivityInstanceNotFoundException e) { throw new ActivityInstanceNotFoundException(e); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new UpdateException(e); } } @@ -2787,9 +2755,9 @@ public void updateProcessDeploymentInfo(final long processDefinitionId, if (processDeploymentInfoUpdater == null || processDeploymentInfoUpdater.getFields().isEmpty()) { throw new UpdateException("The update descriptor does not contain field updates"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final UpdateProcessDeploymentInfo updateProcessDeploymentInfo = new UpdateProcessDeploymentInfo( processDefinitionService, processDefinitionId, @@ -2807,8 +2775,8 @@ public void updateProcessDeploymentInfo(final long processDefinitionId, public List getStartableProcessDeploymentInfosForActors(final Set actorIds, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final Set processDefIds = getIdOfStartableProcessDeploymentInfosForActors(actorIds); @@ -2864,8 +2832,8 @@ public List getStartableProcessDeploymentInfosForActors(f private Set getIdOfStartableProcessDeploymentInfosForActors(final Set actorIds) throws SActorNotFoundException, SBonitaReadException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final List actors = actorMappingService.getActors(new ArrayList<>(actorIds)); final Set processDefIds = new HashSet<>(actors.size()); @@ -2879,8 +2847,8 @@ private Set getIdOfStartableProcessDeploymentInfosForActors(final Set actorIds) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final GetActorsByActorIds getActorsByActorIds = new GetActorsByActorIds(actorMappingService, new ArrayList<>(actorIds)); @@ -2904,11 +2872,11 @@ public boolean isAllowedToStartProcess(final long processDefinitionId, final Set @Override public ActorInstance getActorInitiator(final long processDefinitionId) throws ActorNotFoundException, ProcessDefinitionNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); - ActorInstance actorInstance = null; + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); + ActorInstance actorInstance; try { final SProcessDefinition definition = processDefinitionService.getProcessDefinition(processDefinitionId); final SActorDefinition sActorDefinition = definition.getActorInitiator(); @@ -2932,9 +2900,9 @@ public int getNumberOfActivityDataDefinitions(final long processDefinitionId, fi throws ProcessDefinitionNotFoundException, ActivityDefinitionNotFoundException { List sdataDefinitionList = Collections.emptyList(); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -2963,8 +2931,8 @@ public int getNumberOfActivityDataDefinitions(final long processDefinitionId, fi @Override public int getNumberOfProcessDataDefinitions(final long processDefinitionId) throws ProcessDefinitionNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -3012,7 +2980,7 @@ public ProcessInstance startProcess(final long userId, final long processDefinit protected List createSetDataOperation(final long processDefinitionId, final Map initialVariables) throws ProcessExecutionException { - final ClassLoaderService classLoaderService = getTenantAccessor().getClassLoaderService(); + final ClassLoaderService classLoaderService = getServiceAccessor().getClassLoaderService(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); final List operations = new ArrayList<>(); try { @@ -3029,10 +2997,8 @@ protected List createSetDataOperation(final long processDefinitionId, operations.add(operation); } } - } catch (final SClassLoaderException cle) { + } catch (final SClassLoaderException | InvalidExpressionException cle) { throw new ProcessExecutionException(cle); - } catch (final InvalidExpressionException iee) { - throw new ProcessExecutionException(iee); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } @@ -3076,9 +3042,9 @@ public long getNumberOfActivityDataInstances(final long activityInstanceId) private long getNumberOfDataInstancesOfContainer(final long instanceId, final DataInstanceContainer containerType) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); return dataInstanceService.getNumberOfDataInstances(instanceId, containerType.name(), parentContainerResolver); } @@ -3095,9 +3061,9 @@ protected Map executeOperations(final ConnectorResult conn final List operations, final Map operationInputValues, final SExpressionContext expressionContext, final ClassLoader classLoader, - final TenantServiceAccessor tenantAccessor) throws SBonitaException { - final ConnectorService connectorService = tenantAccessor.getConnectorService(); - final OperationService operationService = tenantAccessor.getOperationService(); + final ServiceAccessor serviceAccessor) throws SBonitaException { + final ConnectorService connectorService = serviceAccessor.getConnectorService(); + final OperationService operationService = serviceAccessor.getOperationService(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); @@ -3105,7 +3071,7 @@ protected Map executeOperations(final ConnectorResult conn // convert the client operation to server operation final List sOperations = convertOperations(operations); // set input values of expression with connector result + provided input for this operation - final HashMap inputValues = new HashMap(operationInputValues); + final HashMap inputValues = new HashMap<>(operationInputValues); inputValues.putAll(connectorResult.getResult()); expressionContext.setInputValues(inputValues); // execute @@ -3169,9 +3135,6 @@ public Map executeConnectorOnProcessDefinition(final Strin /** * execute the connector and return connector output if there is no operation or operation output if there is * operation - * - * @param operations - * @param operationInputValues */ private Map executeConnectorOnProcessDefinitionWithOrWithoutOperations( final String connectorDefinitionId, @@ -3180,10 +3143,10 @@ private Map executeConnectorOnProcessDefinitionWithOrWitho final Map operationInputValues, final long processDefinitionId) throws ConnectorExecutionException { checkConnectorParameters(connectorInputParameters, inputValues); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ConnectorService connectorService = tenantAccessor.getConnectorService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ConnectorService connectorService = serviceAccessor.getConnectorService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); try { final ClassLoader classLoader = classLoaderService.getClassLoader( @@ -3204,12 +3167,10 @@ private Map executeConnectorOnProcessDefinitionWithOrWitho if (operations != null) { // execute operations return executeOperations(connectorResult, operations, operationInputValues, expcontext, classLoader, - tenantAccessor); + serviceAccessor); } return getSerializableResultOfConnector(connectorDefinitionVersion, connectorResult, connectorService); - } catch (final SBonitaException e) { - throw new ConnectorExecutionException(e); - } catch (final NotSerializableException e) { + } catch (final SBonitaException | NotSerializableException e) { throw new ConnectorExecutionException(e); } } @@ -3239,9 +3200,9 @@ public void setActivityStateByName(final long activityInstanceId, final String s @Override public void setActivityStateById(final long activityInstanceId, final int stateId) throws UpdateException { try { - ActivityInstanceService activityInstanceService = getTenantAccessor().getActivityInstanceService(); + ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); SFlowNodeInstance flowNodeInstance = activityInstanceService.getFlowNodeInstance(activityInstanceId); - FlowNodeState state = getTenantAccessor().getFlowNodeStateManager().getState(stateId); + FlowNodeState state = getServiceAccessor().getFlowNodeStateManager().getState(stateId); log.warn(String.format( "setActivityStateById was called: <%s> is forcing state of the flow node with name = <%s> id = <%d> and type <%s> in current state <%s: %s> to the state <%s: %s>. " + @@ -3252,7 +3213,7 @@ public void setActivityStateById(final long activityInstanceId, final int stateI flowNodeInstance.getType().name(), flowNodeInstance.getStateId(), flowNodeInstance.getStateName(), stateId, state.getName())); - getTenantAccessor().getFlowNodeExecutor().setStateByStateId(activityInstanceId, stateId); + getServiceAccessor().getFlowNodeExecutor().setStateByStateId(activityInstanceId, stateId); } catch (final SBonitaException e) { throw new UpdateException(e); } @@ -3265,18 +3226,18 @@ private String getLoggedUsername() { } long userId = session.getUserId(); try { - return getTenantAccessor().getIdentityService().getUser(userId).getUserName(); - } catch (Exception ignored) { + return getServiceAccessor().getIdentityService().getUser(userId).getUserName(); + } catch (Exception e) { log.warn("Unable to retrieve user with id " + userId - + " exception: " + ignored.getClass().getName() + " " + ignored.getMessage()); + + " exception: " + e.getClass().getName() + " " + e.getMessage()); } return String.valueOf(userId); } @Override public void setTaskPriority(final long humanTaskInstanceId, final TaskPriority priority) throws UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final SetTaskPriority transactionContent = new SetTaskPriority(activityInstanceService, humanTaskInstanceId, @@ -3287,24 +3248,19 @@ public void setTaskPriority(final long humanTaskInstanceId, final TaskPriority p } } - private void deleteProcessInstanceInTransaction(final TenantServiceAccessor tenantAccessor, + private void deleteProcessInstanceInTransaction(final ServiceAccessor serviceAccessor, final long processInstanceId) throws SBonitaException { - final UserTransactionService userTransactionService = tenantAccessor.getUserTransactionService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final UserTransactionService userTransactionService = serviceAccessor.getUserTransactionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); try { - userTransactionService.executeInTransaction(new Callable() { - - @Override - public Void call() throws Exception { - final SProcessInstance sProcessInstance = processInstanceService - .getProcessInstance(processInstanceId); - - deleteJobsOnProcessInstance(sProcessInstance); - processInstanceService.deleteParentProcessInstanceAndElements(sProcessInstance); - return null; - } + userTransactionService.executeInTransaction((Callable) () -> { + final SProcessInstance sProcessInstance = processInstanceService + .getProcessInstance(processInstanceId); + deleteJobsOnProcessInstance(sProcessInstance); + processInstanceService.deleteParentProcessInstanceAndElements(sProcessInstance); + return null; }); } catch (final SBonitaException e) { throw e; @@ -3317,61 +3273,53 @@ public Void call() throws Exception { @CustomTransactions public long deleteProcessInstances(final long processDefinitionId, final int startIndex, final int maxResults) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final UserTransactionService userTxService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final UserTransactionService userTxService = serviceAccessor.getUserTransactionService(); try { final Map> processInstancesWithChildrenIds = userTxService - .executeInTransaction(new Callable>>() { - - @Override - public Map> call() throws SBonitaReadException { - final List sProcessInstances1 = searchProcessInstancesFromProcessDefinition( - processInstanceService, - processDefinitionId, startIndex, maxResults); - final Map> sProcessInstanceListHashMap = new LinkedHashMap<>( - sProcessInstances1.size()); - for (final SProcessInstance rootProcessInstance : sProcessInstances1) { - List tmpList; - final List childrenProcessInstanceIds = new ArrayList<>(); - int fromIndex = 0; - do { - // from index always will be zero because elements will be deleted - tmpList = processInstanceService - .getArchivedChildrenSourceObjectIdsFromRootProcessInstance( - rootProcessInstance.getId(), - fromIndex, BATCH_SIZE, OrderByType.ASC); - childrenProcessInstanceIds.addAll(tmpList); - fromIndex += BATCH_SIZE; - } while (tmpList.size() == BATCH_SIZE); - sProcessInstanceListHashMap.put(rootProcessInstance, childrenProcessInstanceIds); - } - return sProcessInstanceListHashMap; + .executeInTransaction(() -> { + final List sProcessInstances1 = searchProcessInstancesFromProcessDefinition( + processInstanceService, + processDefinitionId, startIndex, maxResults); + final Map> sProcessInstanceListHashMap = new LinkedHashMap<>( + sProcessInstances1.size()); + for (final SProcessInstance rootProcessInstance : sProcessInstances1) { + List tmpList; + final List childrenProcessInstanceIds = new ArrayList<>(); + int fromIndex = 0; + do { + // from index always will be zero because elements will be deleted + tmpList = processInstanceService + .getArchivedChildrenSourceObjectIdsFromRootProcessInstance( + rootProcessInstance.getId(), + fromIndex, BATCH_SIZE, OrderByType.ASC); + childrenProcessInstanceIds.addAll(tmpList); + fromIndex += BATCH_SIZE; + } while (tmpList.size() == BATCH_SIZE); + sProcessInstanceListHashMap.put(rootProcessInstance, childrenProcessInstanceIds); } + return sProcessInstanceListHashMap; }); if (processInstancesWithChildrenIds.isEmpty()) { return 0; } - final LockService lockService = tenantAccessor.getLockService(); + final LockService lockService = serviceAccessor.getLockService(); final String objectType = SFlowElementsContainerType.PROCESS.name(); List locks = null; try { locks = createLockProcessInstances(lockService, objectType, processInstancesWithChildrenIds, - tenantAccessor.getTenantId()); - return userTxService.executeInTransaction(new Callable() { - - @Override - public Long call() throws Exception { - final List sProcessInstances = new ArrayList<>( - processInstancesWithChildrenIds.keySet()); - deleteJobsOnProcessInstance(processDefinitionId, sProcessInstances); - return processInstanceService.deleteParentProcessInstanceAndElements(sProcessInstances); - } + serviceAccessor.getTenantId()); + return userTxService.executeInTransaction(() -> { + final List sProcessInstances = new ArrayList<>( + processInstancesWithChildrenIds.keySet()); + deleteJobsOnProcessInstance(processDefinitionId, sProcessInstances); + return processInstanceService.deleteParentProcessInstanceAndElements(sProcessInstances); }); } finally { - releaseLocks(tenantAccessor, lockService, locks, tenantAccessor.getTenantId()); + releaseLocks(lockService, locks, serviceAccessor.getTenantId()); } } catch (final SProcessInstanceHierarchicalDeletionException e) { @@ -3407,7 +3355,7 @@ private void deleteJobsOnEventSubProcess(final SProcessDefinition processDefinit final SProcessInstance sProcessInstance, final SSubProcessDefinition sSubProcessDefinition, final List sCatchEventDefinitions) { - final SchedulerService schedulerService = getTenantAccessor().getSchedulerService(); + final SchedulerService schedulerService = getServiceAccessor().getSchedulerService(); for (final SCatchEventDefinition sCatchEventDefinition : sCatchEventDefinitions) { try { @@ -3440,7 +3388,7 @@ void deleteJobsOnProcessInstance(final SProcessInstance sProcessInstance) throws private void deleteJobsOnProcessInstance(final long processDefinitionId, final List sProcessInstances) throws SBonitaException { - final SProcessDefinition processDefinition = getTenantAccessor().getProcessDefinitionService() + final SProcessDefinition processDefinition = getServiceAccessor().getProcessDefinitionService() .getProcessDefinition(processDefinitionId); for (final SProcessInstance sProcessInstance : sProcessInstances) { @@ -3472,7 +3420,7 @@ private void deleteJobsOnProcessInstance(final SProcessDefinition processDefinit private void deleteJobsOnCallActivitiesOfProcessInstance(final long processInstanceId) throws SBonitaReadException { List flowNodeInstances; int index = 0; - final ProcessInstanceService processInstanceService = getTenantAccessor().getProcessInstanceService(); + final ProcessInstanceService processInstanceService = getServiceAccessor().getProcessInstanceService(); do { try { flowNodeInstances = searchActivities(new SearchOptionsBuilder(index, index + BATCH_SIZE) @@ -3510,7 +3458,7 @@ private void deleteJobsOnProcessInstance(final SProcessDefinition processDefinit private void deleteJobsOnFlowNodeInstances(final SProcessDefinition processDefinition, final SCatchEventDefinition sCatchEventDefinition, final SProcessInstance sProcessInstance) throws SBonitaReadException { - final ActivityInstanceService activityInstanceService = getTenantAccessor().getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); final List orderByOptions = Collections .singletonList(new OrderByOption(SCatchEventInstance.class, "id", OrderByType.ASC)); @@ -3535,8 +3483,8 @@ private void deleteJobsOnFlowNodeInstances(final SProcessDefinition processDefin private void deleteJobsOnFlowNodeInstance(final SProcessDefinition processDefinition, final SCatchEventDefinition sCatchEventDefinition, final SCatchEventInstance sCatchEventInstance) { - final SchedulerService schedulerService = getTenantAccessor().getSchedulerService(); - EventInstanceService eventInstanceService = getTenantAccessor().getEventInstanceService(); + final SchedulerService schedulerService = getServiceAccessor().getSchedulerService(); + EventInstanceService eventInstanceService = getServiceAccessor().getEventInstanceService(); try { if (!sCatchEventDefinition.getTimerEventTriggerDefinitions().isEmpty()) { final String jobName = JobNameBuilder.getTimerEventJobName(processDefinition.getId(), @@ -3581,8 +3529,8 @@ private List searchProcessInstancesFromProcessDefinition( @Override public long deleteArchivedProcessInstances(final long processDefinitionId, final int startIndex, final int maxResults) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); try { List sourceProcessInstanceIds = processInstanceService @@ -3604,8 +3552,8 @@ public long deleteArchivedProcessInstancesInAllStates(final List sourcePro throw new IllegalArgumentException( "The identifier of the archived process instances to deleted are missing !!"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); try { return processInstanceService.deleteArchivedProcessInstances(sourceProcessInstanceIds); @@ -3625,14 +3573,12 @@ private List createLockProcessInstances(final LockService lockServic final Map> sProcessInstances, final long tenantId) throws SLockException, SLockTimeoutException { final List locks = new ArrayList<>(); - final HashSet uniqIds = new HashSet<>(); - for (final Entry> sProcessInstancewithChildrenIds : sProcessInstances.entrySet()) { - uniqIds.add(sProcessInstancewithChildrenIds.getKey().getId()); - for (final Long childId : sProcessInstancewithChildrenIds.getValue()) { - uniqIds.add(childId); - } + final HashSet uniqueIds = new HashSet<>(); + for (final Entry> processInstanceWithChildrenIds : sProcessInstances.entrySet()) { + uniqueIds.add(processInstanceWithChildrenIds.getKey().getId()); + uniqueIds.addAll(processInstanceWithChildrenIds.getValue()); } - for (final Long id : uniqIds) { + for (final Long id : uniqueIds) { final BonitaLock childLock = lockService.lock(id, objectType, tenantId); locks.add(childLock); } @@ -3642,13 +3588,13 @@ private List createLockProcessInstances(final LockService lockServic @Override @CustomTransactions public void deleteProcessInstance(final long processInstanceId) throws DeletionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final LockService lockService = tenantAccessor.getLockService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final LockService lockService = serviceAccessor.getLockService(); final String objectType = SFlowElementsContainerType.PROCESS.name(); BonitaLock lock = null; try { - lock = lockService.lock(processInstanceId, objectType, tenantAccessor.getTenantId()); - deleteProcessInstanceInTransaction(tenantAccessor, processInstanceId); + lock = lockService.lock(processInstanceId, objectType, serviceAccessor.getTenantId()); + deleteProcessInstanceInTransaction(serviceAccessor, processInstanceId); } catch (final SProcessInstanceHierarchicalDeletionException e) { throw new ProcessInstanceHierarchicalDeletionException(e.getMessage(), e.getProcessInstanceId()); } catch (final SProcessInstanceNotFoundException spinfe) { @@ -3658,7 +3604,7 @@ public void deleteProcessInstance(final long processInstanceId) throws DeletionE } finally { if (lock != null) { try { - lockService.unlock(lock, tenantAccessor.getTenantId()); + lockService.unlock(lock, serviceAccessor.getTenantId()); } catch (final SLockException e) { throw new DeletionException( "Lock was not released. Object type: " + objectType + ", id: " + processInstanceId, e); @@ -3676,7 +3622,7 @@ public SearchResult searchOpenProcessInstances(final SearchOpti ProcessInstanceState.COMPLETED.getId()); searchOptionsBuilder.filter(ProcessInstanceSearchDescriptor.CALLER_ID, -1); try { - return searchProcessInstances(getTenantAccessor(), searchOptionsBuilder.done()); + return searchProcessInstances(getServiceAccessor(), searchOptionsBuilder.done()); } catch (final SBonitaException e) { throw new SearchException(e); } @@ -3686,7 +3632,7 @@ public SearchResult searchOpenProcessInstances(final SearchOpti public SearchResult searchProcessInstances(final SearchOptions searchOptions) throws SearchException { try { - return searchProcessInstances(getTenantAccessor(), searchOptions); + return searchProcessInstances(getServiceAccessor(), searchOptions); } catch (final SBonitaException e) { throw new SearchException(e); } @@ -3695,10 +3641,10 @@ public SearchResult searchProcessInstances(final SearchOptions @Override public SearchResult searchFailedProcessInstances(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); try { final SearchFailedProcessInstances searchProcessInstances = new SearchFailedProcessInstances( @@ -3720,18 +3666,18 @@ public SearchResult searchFailedProcessInstances(final SearchOp @Override public SearchResult searchFailedProcessInstancesSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final GetSUser getUser = createTxUserGetter(userId, identityService); try { getUser.execute(); } catch (final SBonitaException e) { - return new SearchResultImpl<>(0, Collections. emptyList()); + return new SearchResultImpl<>(0, Collections.emptyList()); } - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchFailedProcessInstancesSupervisedBy searchFailedProcessInstances = createSearchFailedProcessInstancesSupervisedBy( userId, searchOptions, processInstanceService, searchEntitiesDescriptor, processDefinitionService); @@ -3760,18 +3706,18 @@ protected GetSUser createTxUserGetter(final long userId, final IdentityService i @Override public SearchResult searchOpenProcessInstancesSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final IdentityService identityService = tenantAccessor.getIdentityService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final GetSUser getUser = createTxUserGetter(userId, identityService); try { getUser.execute(); } catch (final SBonitaException e) { - return new SearchResultImpl<>(0, Collections. emptyList()); + return new SearchResultImpl<>(0, Collections.emptyList()); } - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchOpenProcessInstancesSupervisedBy searchOpenProcessInstances = new SearchOpenProcessInstancesSupervisedBy( processInstanceService, searchEntitiesDescriptor.getSearchProcessInstanceDescriptor(), userId, searchOptions, @@ -3788,10 +3734,10 @@ public SearchResult searchOpenProcessInstancesSupervisedBy(fina public SearchResult searchProcessDeploymentInfosStartedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchProcessDefinitionsDescriptor(); final SearchProcessDeploymentInfosStartedBy searcher = new SearchProcessDeploymentInfosStartedBy( @@ -3815,9 +3761,9 @@ public SearchResult searchProcessDeploymentInfos(final Se public SearchResult searchProcessDeploymentInfosCanBeStartedBy(final long userId, final SearchOptions searchOptions) throws RetrieveException, SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchProcessDefinitionsDescriptor(); final SearchProcessDeploymentInfosCanBeStartedBy transactionSearch = new SearchProcessDeploymentInfosCanBeStartedBy( @@ -3835,7 +3781,7 @@ public SearchResult searchProcessDeploymentInfosCanBeStar public SearchResult searchProcessDeploymentInfosCanBeStartedByUsersManagedBy( final long managerUserId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor @@ -3854,7 +3800,7 @@ public SearchResult searchProcessDeploymentInfosCanBeStar public SearchResult searchProcessDeploymentInfosWithAssignedOrPendingHumanTasksFor( final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor @@ -3873,7 +3819,7 @@ public SearchResult searchProcessDeploymentInfosWithAssig public SearchResult searchProcessDeploymentInfosWithAssignedOrPendingHumanTasksSupervisedBy( final long supervisorId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor @@ -3892,7 +3838,7 @@ public SearchResult searchProcessDeploymentInfosWithAssig public SearchResult searchProcessDeploymentInfosWithAssignedOrPendingHumanTasks( final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor @@ -3910,7 +3856,7 @@ public SearchResult searchProcessDeploymentInfosWithAssig @Override public Map> getActiveFlownodeStateCountersForProcessDefinition( final long processDefinitionId) throws ProcessDefinitionNotFoundException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final HashMap> countersForProcessDefinition = new HashMap<>(); try { //make sure a process definition with this Id exists @@ -3921,7 +3867,7 @@ public Map> getActiveFlownodeStateCountersForProcessDe processDefinitionId); for (final SFlowNodeInstanceStateCounter nodeCounter : flownodes) { final String flownodeName = nodeCounter.getFlownodeName(); - final Map flownodeCounters = getFlownodeCounters(countersForProcessDefinition, + final Map flownodeCounters = getFlowNodeCounters(countersForProcessDefinition, flownodeName); flownodeCounters.put(nodeCounter.getStateName(), nodeCounter.getNumberOf()); countersForProcessDefinition.put(flownodeName, flownodeCounters); @@ -3936,7 +3882,7 @@ public Map> getActiveFlownodeStateCountersForProcessDe @Override public Map> getFlownodeStateCounters(final long processInstanceId) { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final HashMap> countersForProcessInstance = new HashMap<>(); try { //make sure a process instance with this Id exists @@ -3949,7 +3895,7 @@ public Map> getFlownodeStateCounters(final long proces processInstanceId); for (final SFlowNodeInstanceStateCounter nodeCounter : flownodes) { final String flownodeName = nodeCounter.getFlownodeName(); - final Map flownodeCounters = getFlownodeCounters(countersForProcessInstance, + final Map flownodeCounters = getFlowNodeCounters(countersForProcessInstance, flownodeName); flownodeCounters.put(nodeCounter.getStateName(), nodeCounter.getNumberOf()); countersForProcessInstance.put(flownodeName, flownodeCounters); @@ -3960,7 +3906,7 @@ public Map> getFlownodeStateCounters(final long proces processInstanceId); for (final SFlowNodeInstanceStateCounter nodeCounter : archivedFlownodes) { final String flownodeName = nodeCounter.getFlownodeName(); - final Map flownodeCounters = getFlownodeCounters(countersForProcessInstance, + final Map flownodeCounters = getFlowNodeCounters(countersForProcessInstance, flownodeName); flownodeCounters.put(nodeCounter.getStateName(), nodeCounter.getNumberOf()); countersForProcessInstance.put(flownodeName, flownodeCounters); @@ -3974,21 +3920,16 @@ public Map> getFlownodeStateCounters(final long proces return countersForProcessInstance; } - private Map getFlownodeCounters(final HashMap> counters, - final String flownodeName) { - Map flownodeCounters = counters.get(flownodeName); - if (flownodeCounters == null) { - flownodeCounters = new HashMap<>(); - counters.put(flownodeName, flownodeCounters); - } - return flownodeCounters; + private Map getFlowNodeCounters(final HashMap> counters, + final String flowNodeName) { + return counters.computeIfAbsent(flowNodeName, k -> new HashMap<>()); } @Override public SearchResult searchProcessDeploymentInfosSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor @@ -4007,7 +3948,7 @@ public SearchResult searchProcessDeploymentInfosSupervise @Override public SearchResult searchAssignedTasksSupervisedBy(final long supervisorId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); @@ -4025,7 +3966,7 @@ public SearchResult searchAssignedTasksSupervisedBy(final lon public SearchResult searchArchivedHumanTasksSupervisedBy(final long supervisorId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); @@ -4045,7 +3986,7 @@ public SearchResult searchArchivedHumanTasksSupervise @Override public SearchResult searchProcessSupervisors(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final SupervisorMappingService supervisorService = serviceAccessor.getSupervisorService(); final SearchProcessSupervisorDescriptor searchDescriptor = new SearchProcessSupervisorDescriptor(); final SearchSupervisors searchSupervisorsTransaction = new SearchSupervisors(supervisorService, @@ -4060,7 +4001,7 @@ public SearchResult searchProcessSupervisors(final SearchOpti @Override public boolean isUserProcessSupervisor(final long processDefinitionId, final long userId) { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final SupervisorMappingService supervisorService = serviceAccessor.getSupervisorService(); try { return supervisorService.isProcessSupervisor(processDefinitionId, userId); @@ -4071,7 +4012,7 @@ public boolean isUserProcessSupervisor(final long processDefinitionId, final lon @Override public void deleteSupervisor(final long supervisorId) throws DeletionException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final SupervisorMappingService supervisorService = serviceAccessor.getSupervisorService(); try { supervisorService.deleteProcessSupervisor(supervisorId); @@ -4088,7 +4029,7 @@ public void deleteSupervisor(final long supervisorId) throws DeletionException { @Override public void deleteSupervisor(final Long processDefinitionId, final Long userId, final Long roleId, final Long groupId) throws DeletionException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final SupervisorMappingService supervisorService = serviceAccessor.getSupervisorService(); try { @@ -4131,35 +4072,33 @@ private void deleteAllSupervisorsOfProcess(final long processDefinitionId) throw @Override public ProcessSupervisor createProcessSupervisorForUser(final long processDefinitionId, final long userId) - throws CreationException, AlreadyExistsException { + throws CreationException { return createSupervisor(SProcessSupervisor.builder().processDefId(processDefinitionId).userId(userId).build()); } @Override public ProcessSupervisor createProcessSupervisorForRole(final long processDefinitionId, final long roleId) - throws CreationException, AlreadyExistsException { + throws CreationException { return createSupervisor(SProcessSupervisor.builder().processDefId(processDefinitionId).roleId(roleId).build()); } @Override public ProcessSupervisor createProcessSupervisorForGroup(final long processDefinitionId, final long groupId) - throws CreationException, - AlreadyExistsException { + throws CreationException { return createSupervisor( SProcessSupervisor.builder().processDefId(processDefinitionId).groupId(groupId).build()); } @Override public ProcessSupervisor createProcessSupervisorForMembership(final long processDefinitionId, final long groupId, - final long roleId) - throws CreationException, AlreadyExistsException { + final long roleId) throws CreationException { return createSupervisor( SProcessSupervisor.builder().processDefId(processDefinitionId).groupId(groupId).roleId(roleId).build()); } private ProcessSupervisor createSupervisor(final SProcessSupervisor sProcessSupervisor) throws CreationException { - final TenantServiceAccessor tenantServiceAccessor = getTenantAccessor(); - final SupervisorMappingService supervisorService = tenantServiceAccessor.getSupervisorService(); + final ServiceAccessor ServiceAccessor = getServiceAccessor(); + final SupervisorMappingService supervisorService = ServiceAccessor.getSupervisorService(); try { checkIfProcessSupervisorAlreadyExists(sProcessSupervisor.getProcessDefId(), sProcessSupervisor.getUserId(), @@ -4197,7 +4136,7 @@ private void checkIfProcessSupervisorAlreadyExists(final long processDefinitionI protected List searchSProcessSupervisors(final Long processDefinitionId, final Long userId, final Long groupId, final Long roleId) throws SBonitaReadException { - final TenantServiceAccessor serviceAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final SupervisorMappingService supervisorService = serviceAccessor.getSupervisorService(); final List oderByOptions = Collections.singletonList( @@ -4219,10 +4158,10 @@ protected List searchSProcessSupervisors(final Long processD public SearchResult searchUncategorizedProcessDeploymentInfosCanBeStartedBy( final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchProcessDefinitionsDescriptor(); final SearchUncategorizedProcessDeploymentInfosCanBeStartedBy transactionSearch = new SearchUncategorizedProcessDeploymentInfosCanBeStartedBy( @@ -4239,10 +4178,10 @@ public SearchResult searchUncategorizedProcessDeploymentI public SearchResult searchArchivedHumanTasksManagedBy(final long managerUserId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchArchivedTasksManagedBy searchTransaction = new SearchArchivedTasksManagedBy(managerUserId, searchOptions, activityInstanceService, flowNodeStateManager, searchEntitiesDescriptor.getSearchArchivedHumanTaskInstanceDescriptor()); @@ -4257,11 +4196,11 @@ public SearchResult searchArchivedHumanTasksManagedBy @Override public SearchResult searchOpenProcessInstancesInvolvingUser(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchOpenProcessInstancesInvolvingUser searchOpenProcessInstances = new SearchOpenProcessInstancesInvolvingUser( processInstanceService, searchEntitiesDescriptor.getSearchProcessInstanceDescriptor(), userId, searchOptions, @@ -4278,11 +4217,11 @@ public SearchResult searchOpenProcessInstancesInvolvingUser(fin public SearchResult searchOpenProcessInstancesInvolvingUsersManagedBy(final long managerUserId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchOpenProcessInstancesInvolvingUsersManagedBy searchOpenProcessInstances = new SearchOpenProcessInstancesInvolvingUsersManagedBy( processInstanceService, searchEntitiesDescriptor.getSearchProcessInstanceDescriptor(), managerUserId, searchOptions, processDefinitionService); @@ -4297,10 +4236,10 @@ public SearchResult searchOpenProcessInstancesInvolvingUsersMan @Override public SearchResult searchArchivedHumanTasks(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchArchivedTasks searchArchivedTasks = new SearchArchivedTasks(activityInstanceService, flowNodeStateManager, @@ -4316,10 +4255,10 @@ public SearchResult searchArchivedHumanTasks(final Se @Override public SearchResult searchAssignedTasksManagedBy(final long managerUserId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); return AbstractHumanTaskInstanceSearchEntity.searchHumanTaskInstance( searchEntitiesDescriptor.getSearchHumanTaskInstanceDescriptor(), searchOptions, @@ -4334,13 +4273,13 @@ public SearchResult searchAssignedTasksManagedBy(final long m public SearchResult searchArchivedProcessInstancesSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchArchivedProcessInstancesSupervisedBy searchArchivedProcessInstances = new SearchArchivedProcessInstancesSupervisedBy( userId, - processInstanceService, tenantAccessor.getProcessDefinitionService(), + processInstanceService, serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor.getSearchArchivedProcessInstanceDescriptor(), searchOptions); try { @@ -4355,13 +4294,13 @@ public SearchResult searchArchivedProcessInstancesSuper public SearchResult searchArchivedProcessInstancesInvolvingUser(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchArchivedProcessInstancesInvolvingUser searchArchivedProcessInstances = new SearchArchivedProcessInstancesInvolvingUser( userId, - processInstanceService, tenantAccessor.getProcessDefinitionService(), + processInstanceService, serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor.getSearchArchivedProcessInstanceDescriptor(), searchOptions); try { @@ -4385,15 +4324,13 @@ public SearchResult searchPendingTasksForUser(final long user * to other users. * PendingOrAssigned if we also want to retrieve tasks directly assigned to this user. * empty for the default behaviour; retrieve pending tasks for user. - * @throws SearchException */ private SearchResult searchTasksForUser(final long userId, final SearchOptions searchOptions, - final String queryType) - throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final String queryType) throws SearchException { + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); switch (queryType) { case PENDING_OR_ASSIGNED_OR_ASSIGNED_TO_OTHERS: @@ -4432,10 +4369,10 @@ private SearchResult searchTasksForUser(final long userId, fi @Override public SearchResult searchPendingTasksAssignedToUser(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); return AbstractHumanTaskInstanceSearchEntity .searchHumanTaskInstance(searchEntitiesDescriptor.getSearchHumanTaskInstanceDescriptor(), searchOptions, @@ -4461,10 +4398,10 @@ public SearchResult searchPendingOrAssignedToUserOrAssignedTo @Override public SearchResult searchPendingTasksSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); return AbstractHumanTaskInstanceSearchEntity .searchHumanTaskInstance(searchEntitiesDescriptor.getSearchHumanTaskInstanceDescriptor(), searchOptions, @@ -4477,10 +4414,10 @@ public SearchResult searchPendingTasksSupervisedBy(final long @Override public SearchResult searchComments(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SCommentService commentService = tenantAccessor.getCommentService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final SCommentService commentService = serviceAccessor.getCommentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchComments searchComments = new SearchComments(searchEntitiesDescriptor.getSearchCommentDescriptor(), searchOptions, commentService); try { @@ -4499,13 +4436,13 @@ public Comment addProcessComment(final long processInstanceId, final String comm @Override public Comment addProcessCommentOnBehalfOfUser(final long processInstanceId, final String comment, long userId) throws CreationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - tenantAccessor.getProcessInstanceService().getProcessInstance(processInstanceId); + serviceAccessor.getProcessInstanceService().getProcessInstance(processInstanceId); } catch (final SProcessInstanceReadException | SProcessInstanceNotFoundException e) { throw new RetrieveException(buildCantAddCommentOnProcessInstance(), e); // FIXME: should be another exception } - final SCommentService commentService = tenantAccessor.getCommentService(); + final SCommentService commentService = serviceAccessor.getCommentService(); try { SComment sComment = commentService.addComment(processInstanceId, comment, userId); return ModelConvertor.toComment(sComment); @@ -4596,13 +4533,13 @@ public SearchResult searchPendingTasksManagedBy(final long ma @Override public Map getNumberOfOverdueOpenTasks(final List userIds) throws RetrieveException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { return activityInstanceService.getNumberOfOverdueOpenTasksForUsers(userIds); } catch (final SBonitaException e) { - logError(tenantAccessor, e); + logError(e); throw new RetrieveException(e.getMessage()); } } @@ -4610,10 +4547,10 @@ public Map getNumberOfOverdueOpenTasks(final List userIds) thr @Override public SearchResult searchUncategorizedProcessDeploymentInfos( final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchProcessDefinitionsDescriptor(); final SearchUncategorizedProcessDeploymentInfos transactionSearch = new SearchUncategorizedProcessDeploymentInfos( @@ -4630,10 +4567,10 @@ public SearchResult searchUncategorizedProcessDeploymentI @Override public SearchResult searchCommentsManagedBy(final long managerUserId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SCommentService commentService = tenantAccessor.getCommentService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final SCommentService commentService = serviceAccessor.getCommentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchCommentsManagedBy searchComments = new SearchCommentsManagedBy( searchEntitiesDescriptor.getSearchCommentDescriptor(), searchOptions, commentService, managerUserId); @@ -4648,10 +4585,10 @@ public SearchResult searchCommentsManagedBy(final long managerUserId, f @Override public SearchResult searchCommentsInvolvingUser(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SCommentService commentService = tenantAccessor.getCommentService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final SCommentService commentService = serviceAccessor.getCommentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchCommentsInvolvingUser searchComments = new SearchCommentsInvolvingUser( searchEntitiesDescriptor.getSearchCommentDescriptor(), searchOptions, commentService, userId); @@ -4667,8 +4604,8 @@ public SearchResult searchCommentsInvolvingUser(final long userId, fina public List getChildrenInstanceIdsOfProcessInstance(final long processInstanceId, final int startIndex, final int maxResults, final ProcessInstanceCriterion criterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); long totalNumber; try { @@ -4689,10 +4626,10 @@ public List getChildrenInstanceIdsOfProcessInstance(final long processInst public SearchResult searchUncategorizedProcessDeploymentInfosSupervisedBy(final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchProcessDefinitionsDescriptor(); final SearchUncategorizedProcessDeploymentInfosSupervisedBy transactionSearch = new SearchUncategorizedProcessDeploymentInfosSupervisedBy( @@ -4715,9 +4652,9 @@ public Map getProcessDeploymentInfosFromIds(final L public List getConnectorImplementations(final long processDefinitionId, final int startIndex, final int maxsResults, final ConnectorCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ConnectorService connectorService = tenantAccessor.getConnectorService(); + final ConnectorService connectorService = serviceAccessor.getConnectorService(); final OrderAndField orderAndField = OrderAndFields.getOrderAndFieldForConnectorImplementation(sortingCriterion); try { final List sConnectorImplementationDescriptors = connectorService @@ -4731,9 +4668,9 @@ public List getConnectorImplementations(final @Override public long getNumberOfConnectorImplementations(final long processDefinitionId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ConnectorService connectorService = tenantAccessor.getConnectorService(); + final ConnectorService connectorService = serviceAccessor.getConnectorService(); try { return connectorService.getNumberOfConnectorImplementations(processDefinitionId); } catch (final SBonitaException e) { @@ -4743,11 +4680,11 @@ public long getNumberOfConnectorImplementations(final long processDefinitionId) @Override public SearchResult searchActivities(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchActivityInstances searchActivityInstancesTransaction; try { searchActivityInstancesTransaction = new SearchActivityInstances(activityInstanceService, @@ -4763,11 +4700,11 @@ public SearchResult searchActivities(final SearchOptions searc @Override public SearchResult searchArchivedFlowNodeInstances(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchArchivedFlowNodeInstances searchTransaction = new SearchArchivedFlowNodeInstances( activityInstanceService, flowNodeStateManager, searchEntitiesDescriptor.getSearchArchivedFlowNodeInstanceDescriptor(), searchOptions); @@ -4782,10 +4719,10 @@ public SearchResult searchArchivedFlowNodeInstances(fi @Override public SearchResult searchFlowNodeInstances(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchFlowNodeInstances searchFlowNodeInstancesTransaction = new SearchFlowNodeInstances( activityInstanceService, flowNodeStateManager, searchEntitiesDescriptor.getSearchFlowNodeInstanceDescriptor(), searchOptions); @@ -4801,9 +4738,9 @@ public SearchResult searchFlowNodeInstances(final SearchOption public SearchResult searchTimerEventTriggerInstances(final long processInstanceId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final EventInstanceService eventInstanceService = tenantAccessor.getEventInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final EventInstanceService eventInstanceService = serviceAccessor.getEventInstanceService(); final SearchTimerEventTriggerInstances transaction = new SearchTimerEventTriggerInstances(eventInstanceService, searchEntitiesDescriptor.getSearchEventTriggerInstanceDescriptor(), processInstanceId, searchOptions); try { @@ -4821,9 +4758,9 @@ public Date updateExecutionDateOfTimerEventTriggerInstance(final long timerEvent if (executionDate == null) { throw new UpdateException("The date must be not null !!"); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final EventInstanceService eventInstanceService = tenantAccessor.getEventInstanceService(); - final SchedulerService schedulerService = tenantAccessor.getSchedulerService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final EventInstanceService eventInstanceService = serviceAccessor.getEventInstanceService(); + final SchedulerService schedulerService = serviceAccessor.getSchedulerService(); final EntityUpdateDescriptor descriptor = new EntityUpdateDescriptor(); descriptor.addField(EXECUTION_DATE, executionDate.getTime()); @@ -4838,7 +4775,7 @@ public Date updateExecutionDateOfTimerEventTriggerInstance(final long timerEvent eventInstanceService.updateEventTriggerInstance(sTimerEventTriggerInstance, descriptor); return schedulerService .rescheduleJob(sTimerEventTriggerInstance.getJobTriggerName(), - String.valueOf(getTenantAccessor().getTenantId()), executionDate); + String.valueOf(getServiceAccessor().getTenantId()), executionDate); } catch (final SBonitaException sbe) { throw new UpdateException(sbe); } @@ -4847,11 +4784,11 @@ public Date updateExecutionDateOfTimerEventTriggerInstance(final long timerEvent @Override public SearchResult searchArchivedActivities(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchArchivedActivityInstances searchActivityInstancesTransaction = new SearchArchivedActivityInstances( activityInstanceService, flowNodeStateManager, searchEntitiesDescriptor.getSearchArchivedActivityInstanceDescriptor(), @@ -4868,9 +4805,9 @@ public SearchResult searchArchivedActivities(final Sea public ConnectorImplementationDescriptor getConnectorImplementation(final long processDefinitionId, final String connectorId, final String connectorVersion) throws ConnectorNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ConnectorService connectorService = tenantAccessor.getConnectorService(); + final ConnectorService connectorService = serviceAccessor.getConnectorService(); final GetConnectorImplementation transactionContent = new GetConnectorImplementation(connectorService, processDefinitionId, connectorId, connectorVersion); @@ -4887,14 +4824,14 @@ public ConnectorImplementationDescriptor getConnectorImplementation(final long p @Override public void cancelProcessInstance(final long processInstanceId) throws ProcessInstanceNotFoundException, UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final LockService lockService = tenantAccessor.getLockService(); - final ProcessInstanceInterruptor processInstanceInterruptor = tenantAccessor.getProcessInstanceInterruptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final LockService lockService = serviceAccessor.getLockService(); + final ProcessInstanceInterruptor processInstanceInterruptor = serviceAccessor.getProcessInstanceInterruptor(); // lock process execution final String objectType = SFlowElementsContainerType.PROCESS.name(); BonitaLock lock = null; try { - lock = lockService.lock(processInstanceId, objectType, tenantAccessor.getTenantId()); + lock = lockService.lock(processInstanceId, objectType, serviceAccessor.getTenantId()); processInstanceInterruptor.interruptProcessInstance(processInstanceId, SStateCategory.CANCELLING); } catch (final SProcessInstanceNotFoundException spinfe) { throw new ProcessInstanceNotFoundException(processInstanceId); @@ -4903,24 +4840,20 @@ public void cancelProcessInstance(final long processInstanceId) } finally { // unlock process execution try { - lockService.unlock(lock, tenantAccessor.getTenantId()); + lockService.unlock(lock, serviceAccessor.getTenantId()); } catch (final SLockException e) { // ignore it } } } - protected ProcessInstanceInterruptor buildProcessInstanceInterruptor(final TenantServiceAccessor tenantAccessor) { - return tenantAccessor.getProcessInstanceInterruptor(); - } - @Override public void setProcessInstanceState(final ProcessInstance processInstance, final String state) throws UpdateException { // NOW, is only available for COMPLETED, ABORTED, CANCELLED, STARTED - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); try { final ProcessInstanceState processInstanceState = ModelConvertor.getProcessInstanceState(state); final SetProcessInstanceState transactionContent = new SetProcessInstanceState(processInstanceService, @@ -4935,8 +4868,8 @@ public void setProcessInstanceState(final ProcessInstance processInstance, final @Override public Map getProcessDeploymentInfosFromProcessInstanceIds( final List processInstanceIds) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final Map sProcessDeploymentInfos = processDefinitionService @@ -4950,8 +4883,8 @@ public Map getProcessDeploymentInfosFromProcessInst @Override public Map getProcessDeploymentInfosFromArchivedProcessInstanceIds( final List archivedProcessInstantsIds) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final Map sProcessDeploymentInfos = processDefinitionService @@ -4992,20 +4925,20 @@ public SearchResult searchArchivedDocumentsSupervisedBy(final @Override public void retryTask(final long activityInstanceId) throws ActivityExecutionException, ActivityInstanceNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - ConnectorInstanceService connectorInstanceService = tenantAccessor.getConnectorInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + ConnectorInstanceService connectorInstanceService = serviceAccessor.getConnectorInstanceService(); ResetAllFailedConnectorStrategy strategy = new ResetAllFailedConnectorStrategy(connectorInstanceService, new ConnectorReseter(connectorInstanceService), BATCH_SIZE); - FlowNodeRetrier flowNodeRetrier = new FlowNodeRetrier(tenantAccessor.getContainerRegistry(), - tenantAccessor.getFlowNodeExecutor(), - tenantAccessor.getActivityInstanceService(), tenantAccessor.getFlowNodeStateManager(), strategy); + FlowNodeRetrier flowNodeRetrier = new FlowNodeRetrier(serviceAccessor.getContainerRegistry(), + serviceAccessor.getFlowNodeExecutor(), + serviceAccessor.getActivityInstanceService(), serviceAccessor.getFlowNodeStateManager(), strategy); flowNodeRetrier.retry(activityInstanceId); } @Override public void executeMessageCouple(final long messageInstanceId, final long waitingMessageId) throws ExecutionException { - MessagesHandlingService messagesHandlingService = getTenantAccessor().getMessagesHandlingService(); + MessagesHandlingService messagesHandlingService = getServiceAccessor().getMessagesHandlingService(); try { messagesHandlingService.resetMessageCouple(messageInstanceId, waitingMessageId); messagesHandlingService.triggerMatchingOfMessages(); @@ -5032,10 +4965,10 @@ public ArchivedDocument getArchivedProcessDocument(final long archivedProcessDoc @Override public SearchResult searchArchivedComments(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final SCommentService sCommentService = tenantAccessor.getCommentService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final SCommentService sCommentService = serviceAccessor.getCommentService(); final SearchArchivedComments searchArchivedComments = new SearchArchivedComments(sCommentService, searchEntitiesDescriptor.getSearchArchivedCommentsDescriptor(), searchOptions); try { @@ -5049,9 +4982,9 @@ public SearchResult searchArchivedComments(final SearchOptions @Override public ArchivedComment getArchivedComment(final long archivedCommentId) throws RetrieveException, NotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SCommentService sCommentService = tenantAccessor.getCommentService(); + final SCommentService sCommentService = serviceAccessor.getCommentService(); try { final SAComment archivedComment = sCommentService.getArchivedComment(archivedCommentId); return ModelConvertor.toArchivedComment(archivedComment); @@ -5064,10 +4997,10 @@ public ArchivedComment getArchivedComment(final long archivedCommentId) @Override public Map getActorsFromActorIds(final List actorIds) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final Map res = new HashMap<>(); - final ActorMappingService actormappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actormappingService = serviceAccessor.getActorMappingService(); final GetActorsByActorIds getActorsByActorIds = new GetActorsByActorIds(actormappingService, actorIds); try { getActorsByActorIds.execute(); @@ -5085,10 +5018,10 @@ public Map getActorsFromActorIds(final List actorIds) public Serializable evaluateExpressionOnProcessDefinition(final Expression expression, final Map context, final long processDefinitionId) throws ExpressionEvaluationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ExpressionResolverService expressionResolverService = tenantAccessor.getExpressionResolverService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ExpressionResolverService expressionResolverService = serviceAccessor.getExpressionResolverService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SExpression sExpression = ModelConvertor.constructSExpression(expression); final SExpressionContext expcontext = new SExpressionContext(); expcontext.setProcessDefinitionId(processDefinitionId); @@ -5098,7 +5031,7 @@ public Serializable evaluateExpressionOnProcessDefinition(final Expression expre if (processDef != null) { expcontext.setProcessDefinition(processDef); } - final HashMap hashMap = new HashMap(context); + final HashMap hashMap = new HashMap<>(context); expcontext.setInputValues(hashMap); return (Serializable) expressionResolverService.evaluate(sExpression, expcontext); } catch (final SExpressionEvaluationException e) { @@ -5112,13 +5045,11 @@ public Serializable evaluateExpressionOnProcessDefinition(final Expression expre @Override public void updateDueDateOfTask(final long userTaskId, final Date dueDate) throws UpdateException { - final ActivityInstanceService activityInstanceService = getTenantAccessor().getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); try { final SetExpectedEndDate updateProcessInstance = new SetExpectedEndDate(activityInstanceService, userTaskId, dueDate); updateProcessInstance.execute(); - } catch (final SFlowNodeNotFoundException e) { - throw new UpdateException(e); } catch (final SBonitaException e) { throw new UpdateException(e); } @@ -5144,9 +5075,9 @@ public long countAttachments(final SearchOptions searchOptions) throws SearchExc @Override public void sendSignal(final String signalName) throws SendEventException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final EventsHandler eventsHandler = tenantAccessor.getEventsHandler(); + final EventsHandler eventsHandler = serviceAccessor.getEventsHandler(); final SThrowSignalEventTriggerDefinition signalEventTriggerDefinition = BuilderFactory .get(SThrowSignalEventTriggerDefinitionBuilderFactory.class) .createNewInstance(signalName).done(); @@ -5170,10 +5101,10 @@ public void sendMessage(final String messageName, final Expression targetProcess if (correlations != null && correlations.size() > 5) { throw new SendEventException("Too many correlations: a message can not have more than 5 correlations."); } - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final EventsHandler eventsHandler = tenantAccessor.getEventsHandler(); - final ExpressionResolverService expressionResolverService = tenantAccessor.getExpressionResolverService(); + final EventsHandler eventsHandler = serviceAccessor.getEventsHandler(); + final ExpressionResolverService expressionResolverService = serviceAccessor.getExpressionResolverService(); final SExpression targetProcessNameExp = ModelConvertor.constructSExpression(targetProcess); SExpression targetFlowNodeNameExp = null; @@ -5202,9 +5133,9 @@ public void sendMessage(final String messageName, final Expression targetProcess public int deleteMessageByCreationDate(final long creationDate, SearchOptions searchOptions) throws ExecutionException { try { - return getTenantAccessor().getEventInstanceService() + return getServiceAccessor().getEventInstanceService() .deleteMessageAndDataInstanceOlderThanCreationDate(creationDate, buildQueryOptions(searchOptions, - getTenantAccessor().getSearchEntitiesDescriptor().getSearchMessageInstanceDescriptor())); + getServiceAccessor().getSearchEntitiesDescriptor().getSearchMessageInstanceDescriptor())); } catch (SBonitaException e) { throw new ExecutionException(e); } @@ -5213,7 +5144,7 @@ public int deleteMessageByCreationDate(final long creationDate, SearchOptions se /** * Utility method to convert a SearchOptions into a QueryOptions */ - private QueryOptions buildQueryOptions(SearchOptions searchOptions, + private QueryOptions buildQueryOptions(SearchOptions searchOptions, SearchEntityDescriptor searchEntityDescriptor) { if (searchOptions != null) { final List filters = searchOptions.getFilters(); @@ -5266,10 +5197,10 @@ public List getProcessResolutionProblems(final long processDefinitionId @Override public List getProcessDeploymentInfos(final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion pagingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfos transactionContentWithResult = new GetProcessDefinitionDeployInfos( @@ -5287,10 +5218,10 @@ public List getProcessDeploymentInfos(final int startInde public List getProcessDeploymentInfosWithActorOnlyForGroup(final long groupId, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfosWithActorOnlyForGroup transactionContentWithResult = new GetProcessDefinitionDeployInfosWithActorOnlyForGroup( @@ -5308,10 +5239,10 @@ public List getProcessDeploymentInfosWithActorOnlyForGrou public List getProcessDeploymentInfosWithActorOnlyForGroups(final List groupIds, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfosWithActorOnlyForGroups transactionContentWithResult = new GetProcessDefinitionDeployInfosWithActorOnlyForGroups( @@ -5329,10 +5260,10 @@ public List getProcessDeploymentInfosWithActorOnlyForGrou public List getProcessDeploymentInfosWithActorOnlyForRole(final long roleId, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfosWithActorOnlyForRole transactionContentWithResult = new GetProcessDefinitionDeployInfosWithActorOnlyForRole( @@ -5351,10 +5282,10 @@ public List getProcessDeploymentInfosWithActorOnlyForRole public List getProcessDeploymentInfosWithActorOnlyForRoles(final List roleIds, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfosWithActorOnlyForRoles transactionContentWithResult = new GetProcessDefinitionDeployInfosWithActorOnlyForRoles( @@ -5372,10 +5303,10 @@ public List getProcessDeploymentInfosWithActorOnlyForRole public List getProcessDeploymentInfosWithActorOnlyForUser(final long userId, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfosWithActorOnlyForUser transactionContentWithResult = new GetProcessDefinitionDeployInfosWithActorOnlyForUser( @@ -5393,10 +5324,10 @@ public List getProcessDeploymentInfosWithActorOnlyForUser public List getProcessDeploymentInfosWithActorOnlyForUsers(final List userIds, final int startIndex, final int maxResults, final ProcessDeploymentInfoCriterion sortingCriterion) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = tenantAccessor + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final SearchProcessDefinitionsDescriptor processDefinitionsDescriptor = serviceAccessor .getSearchEntitiesDescriptor() .getSearchProcessDefinitionsDescriptor(); final GetProcessDefinitionDeployInfosWithActorOnlyForUsers transactionContentWithResult = new GetProcessDefinitionDeployInfosWithActorOnlyForUsers( @@ -5413,16 +5344,16 @@ public List getProcessDeploymentInfosWithActorOnlyForUser @Override public SearchResult searchConnectorInstances(final SearchOptions searchOptions) throws RetrieveException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ConnectorInstanceService connectorInstanceService = tenantAccessor.getConnectorInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ConnectorInstanceService connectorInstanceService = serviceAccessor.getConnectorInstanceService(); if (searchOptions.getSorts().isEmpty()) { searchOptions.getSorts().add(new Sort(Order.ASC, ConnectorInstancesSearchDescriptor.EXECUTION_ORDER)); } try { return search(searchEntitiesDescriptor.getSearchConnectorInstanceDescriptor(), searchOptions, - sConnectorInstances -> ModelConvertor.toConnectorInstances(sConnectorInstances), + ModelConvertor::toConnectorInstances, connectorInstanceService::getNumberOfConnectorInstances, connectorInstanceService::searchConnectorInstances); } catch (SearchException e) { @@ -5433,11 +5364,11 @@ public SearchResult searchConnectorInstances(final SearchOpti @Override public SearchResult searchArchivedConnectorInstances(final SearchOptions searchOptions) throws RetrieveException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ConnectorInstanceService connectorInstanceService = tenantAccessor.getConnectorInstanceService(); - final ArchiveService archiveService = tenantAccessor.getArchiveService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ConnectorInstanceService connectorInstanceService = serviceAccessor.getConnectorInstanceService(); + final ArchiveService archiveService = serviceAccessor.getArchiveService(); final ReadPersistenceService persistenceService = archiveService.getDefinitiveArchiveReadPersistenceService(); final SearchArchivedConnectorInstance searchArchivedConnectorInstance = new SearchArchivedConnectorInstance( connectorInstanceService, @@ -5458,10 +5389,7 @@ public List getHumanTaskInstances(final long rootProcessInsta final List humanTaskInstances = getHumanTaskInstances(rootProcessInstanceId, taskName, startIndex, maxResults, HumanTaskInstanceSearchDescriptor.PROCESS_INSTANCE_ID, Order.ASC); - if (humanTaskInstances == null) { - return Collections.emptyList(); - } - return humanTaskInstances; + return Objects.requireNonNullElse(humanTaskInstances, Collections.emptyList()); } catch (final SearchException e) { throw new RetrieveException(e); } @@ -5498,10 +5426,10 @@ private List getHumanTaskInstances(final long processInstance public SearchResult searchUsersWhoCanStartProcessDefinition(final long processDefinitionId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchUserDescriptor searchDescriptor = searchEntitiesDescriptor.getSearchUserDescriptor(); final SearchUsersWhoCanStartProcessDeploymentInfo transactionSearch = new SearchUsersWhoCanStartProcessDeploymentInfo( processDefinitionService, @@ -5517,8 +5445,8 @@ public SearchResult searchUsersWhoCanStartProcessDefinition(final long pro @Override public Map evaluateExpressionsAtProcessInstanciation(final long processInstanceId, final Map> expressions) throws ExpressionEvaluationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); try { try { final SProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); @@ -5536,12 +5464,9 @@ public Map evaluateExpressionsAtProcessInstanciation(final // get it in the archive } final ArchivedProcessInstance archiveProcessInstance = getStartedArchivedProcessInstance(processInstanceId); - final Map evaluateExpressionInArchiveProcessInstance = evaluateExpressionsInstanceLevelAndArchived( - expressions, - processInstanceId, CONTAINER_TYPE_PROCESS_INSTANCE, archiveProcessInstance.getProcessDefinitionId(), - archiveProcessInstance.getStartDate() - .getTime()); - return evaluateExpressionInArchiveProcessInstance; + return evaluateExpressionsInstanceLevelAndArchived(expressions, processInstanceId, + CONTAINER_TYPE_PROCESS_INSTANCE, archiveProcessInstance.getProcessDefinitionId(), + archiveProcessInstance.getStartDate().getTime()); } catch (final SExpressionEvaluationException e) { throw new ExpressionEvaluationException(e, e.getExpressionName()); } catch (final SInvalidExpressionException e) { @@ -5630,13 +5555,11 @@ public Map evaluateExpressionsOnCompletedActivityInstance( return evaluateExpressionsInstanceLevelAndArchived(expressions, activityInstanceId, CONTAINER_TYPE_ACTIVITY_INSTANCE, lastArchivedProcessInstance.getProcessDefinitionId(), activityInstance.getArchiveDate().getTime()); - } catch (final ActivityInstanceNotFoundException e) { - throw new ExpressionEvaluationException(e, null); } catch (final SExpressionEvaluationException e) { throw new ExpressionEvaluationException(e, e.getExpressionName()); } catch (final SInvalidExpressionException e) { throw new ExpressionEvaluationException(e, e.getExpressionName()); - } catch (final SBonitaException e) { + } catch (final ActivityInstanceNotFoundException | SBonitaException e) { throw new ExpressionEvaluationException(e, null); } } @@ -5644,9 +5567,9 @@ public Map evaluateExpressionsOnCompletedActivityInstance( private Map evaluateExpressionsDefinitionLevel( final Map> expressionsAndTheirPartialContext, final long processDefinitionId) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ExpressionResolverService expressionResolverService = tenantAccessor.getExpressionResolverService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ExpressionResolverService expressionResolverService = serviceAccessor.getExpressionResolverService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final EvaluateExpressionsDefinitionLevel evaluations = createDefinitionLevelExpressionEvaluator( expressionsAndTheirPartialContext, processDefinitionId, expressionResolverService, processDefinitionService); @@ -5660,14 +5583,14 @@ protected EvaluateExpressionsDefinitionLevel createDefinitionLevelExpressionEval final ExpressionResolverService expressionResolverService, final ProcessDefinitionService processDefinitionService) { return new EvaluateExpressionsDefinitionLevel(expressionsAndTheirPartialContext, processDefinitionId, - expressionResolverService, processDefinitionService, getTenantAccessor().getBusinessDataRepository()); + expressionResolverService, processDefinitionService, getServiceAccessor().getBusinessDataRepository()); } private Map evaluateExpressionsInstanceLevel( final Map> expressions, final long containerId, final String containerType, final long processDefinitionId) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ExpressionResolverService expressionService = tenantAccessor.getExpressionResolverService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ExpressionResolverService expressionService = serviceAccessor.getExpressionResolverService(); final EvaluateExpressionsInstanceLevel evaluations = createInstanceLevelExpressionEvaluator(expressions, containerId, containerType, @@ -5681,15 +5604,15 @@ protected EvaluateExpressionsInstanceLevel createInstanceLevelExpressionEvaluato final long containerId, final String containerType, final long processDefinitionId, final ExpressionResolverService expressionService) { return new EvaluateExpressionsInstanceLevel(expressions, containerId, containerType, processDefinitionId, - expressionService, getTenantAccessor().getBusinessDataRepository()); + expressionService, getServiceAccessor().getBusinessDataRepository()); } private Map evaluateExpressionsInstanceLevelAndArchived( final Map> expressions, final long containerId, final String containerType, final long processDefinitionId, final long time) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ExpressionResolverService expressionService = tenantAccessor.getExpressionResolverService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ExpressionResolverService expressionService = serviceAccessor.getExpressionResolverService(); final EvaluateExpressionsInstanceLevelAndArchived evaluations = createInstanceAndArchivedLevelExpressionEvaluator( expressions, containerId, containerType, processDefinitionId, time, expressionService); @@ -5703,14 +5626,14 @@ protected EvaluateExpressionsInstanceLevelAndArchived createInstanceAndArchivedL final long time, final ExpressionResolverService expressionService) { return new EvaluateExpressionsInstanceLevelAndArchived(expressions, containerId, containerType, processDefinitionId, time, expressionService, - getTenantAccessor().getBusinessDataRepository()); + getServiceAccessor().getBusinessDataRepository()); } private ArchivedProcessInstance getStartedArchivedProcessInstance(final long processInstanceId) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 2); searchOptionsBuilder.sort(ArchivedProcessInstancesSearchDescriptor.ARCHIVE_DATE, Order.ASC); @@ -5719,7 +5642,7 @@ private ArchivedProcessInstance getStartedArchivedProcessInstance(final long pro ProcessInstanceState.STARTED.getId()); final SearchArchivedProcessInstances searchArchivedProcessInstances = new SearchArchivedProcessInstances( processInstanceService, - tenantAccessor.getProcessDefinitionService(), + serviceAccessor.getProcessDefinitionService(), searchEntitiesDescriptor.getSearchArchivedProcessInstanceDescriptor(), searchOptionsBuilder.done()); searchArchivedProcessInstances.execute(); @@ -5739,8 +5662,8 @@ protected ArchivedProcessInstance getLastArchivedProcessInstance(final long proc @Override public List getFailedJobs(final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final JobService jobService = tenantAccessor.getJobService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final JobService jobService = serviceAccessor.getJobService(); try { final List failedJobs = jobService.getFailedJobs(startIndex, maxResults); return ModelConvertor.toFailedJobs(failedJobs); @@ -5757,8 +5680,8 @@ public void replayFailedJob(final long jobDescriptorId) throws ExecutionExceptio @Override public void replayFailedJob(final long jobDescriptorId, final Map parameters) throws ExecutionException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SchedulerService schedulerService = tenantAccessor.getSchedulerService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SchedulerService schedulerService = serviceAccessor.getSchedulerService(); try { if (parameters == null || parameters.isEmpty()) { schedulerService.retryJobThatFailed(jobDescriptorId); @@ -5788,11 +5711,11 @@ protected SJobParameter buildSJobParameter(final String parameterKey, final Seri @Override public ArchivedDataInstance getArchivedProcessDataInstance(final String dataName, final long sourceProcessInstanceId) throws ArchivedDataNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final SAProcessInstance lastArchivedProcessInstance = processInstanceService @@ -5822,11 +5745,11 @@ public ArchivedDataInstance getArchivedProcessDataInstance(final String dataName public ArchivedDataInstance getArchivedActivityDataInstance(final String dataName, final long sourceActivityInstanceId) throws ArchivedDataNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ParentContainerResolver parentContainerResolver = tenantAccessor.getParentContainerResolver(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ParentContainerResolver parentContainerResolver = serviceAccessor.getParentContainerResolver(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -5853,10 +5776,10 @@ public ArchivedDataInstance getArchivedActivityDataInstance(final String dataNam @Override public List getArchivedProcessDataInstances(final long sourceProcessInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { final SAProcessInstance lastArchivedProcessInstance = processInstanceService @@ -5882,10 +5805,10 @@ public List getArchivedProcessDataInstances(final long sou @Override public List getArchivedActivityDataInstances(final long sourceActivityInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final int processDefinitionIndex = BuilderFactory.get(SAutomaticTaskInstanceBuilderFactory.class) .getProcessDefinitionIndex(); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @@ -5911,13 +5834,13 @@ public List getArchivedActivityDataInstances(final long so @Override public List getPossibleUsersOfPendingHumanTask(final long humanTaskInstanceId, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { // pagination of this method is based on order by username: final List userIds = activityInstanceService.getPossibleUserIdsOfPendingTasks(humanTaskInstanceId, startIndex, maxResults); - final IdentityService identityService = getTenantAccessor().getIdentityService(); + final IdentityService identityService = getServiceAccessor().getIdentityService(); // This method below is also ordered by username, so the order is preserved: final List sUsers = identityService.getUsers(userIds); return ModelConvertor.toUsers(sUsers); @@ -5929,8 +5852,8 @@ public List getPossibleUsersOfPendingHumanTask(final long humanTaskInstanc @Override public List getPossibleUsersOfHumanTask(final long processDefinitionId, final String humanTaskName, final int startIndex, final int maxResults) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition processDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -5940,9 +5863,9 @@ public List getPossibleUsersOfHumanTask(final long processDefinitionId, fi } final SHumanTaskDefinition humanTask = (SHumanTaskDefinition) flowNode; final String actorName = humanTask.getActorName(); - final List userIds = getUserIdsForActor(tenantAccessor, processDefinitionId, actorName, startIndex, + final List userIds = getUserIdsForActor(serviceAccessor, processDefinitionId, actorName, startIndex, maxResults); - final List users = tenantAccessor.getIdentityService().getUsers(userIds); + final List users = serviceAccessor.getIdentityService().getUsers(userIds); return ModelConvertor.toUsers(users); } catch (final SProcessDefinitionNotFoundException spdnfe) { return Collections.emptyList(); @@ -5951,10 +5874,10 @@ public List getPossibleUsersOfHumanTask(final long processDefinitionId, fi } } - private List getUserIdsForActor(final TenantServiceAccessor tenantAccessor, final long processDefinitionId, + private List getUserIdsForActor(final ServiceAccessor serviceAccessor, final long processDefinitionId, final String actorName, final int startIndex, final int maxResults) throws SActorNotFoundException, SBonitaReadException { - final ActorMappingService actorMappingService = tenantAccessor.getActorMappingService(); + final ActorMappingService actorMappingService = serviceAccessor.getActorMappingService(); final SActor actor = actorMappingService.getActor(actorName, processDefinitionId); return actorMappingService.getPossibleUserIdsOfActorId(actor.getId(), startIndex, maxResults); } @@ -5963,7 +5886,7 @@ private List getUserIdsForActor(final TenantServiceAccessor tenantAccessor public List getUserIdsForActor(final long processDefinitionId, final String actorName, final int startIndex, final int maxResults) { try { - return getUserIdsForActor(getTenantAccessor(), processDefinitionId, actorName, startIndex, maxResults); + return getUserIdsForActor(getServiceAccessor(), processDefinitionId, actorName, startIndex, maxResults); } catch (final SBonitaException e) { throw new RetrieveException(e); } @@ -5972,9 +5895,9 @@ public List getUserIdsForActor(final long processDefinitionId, final Strin @Override public SearchResult searchUsersWhoCanExecutePendingHumanTask(final long humanTaskInstanceId, final SearchOptions searchOptions) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchUserDescriptor searchDescriptor = searchEntitiesDescriptor.getSearchUserDescriptor(); final SearchUsersWhoCanExecutePendingHumanTaskDeploymentInfo searcher = new SearchUsersWhoCanExecutePendingHumanTaskDeploymentInfo( humanTaskInstanceId, activityInstanceService, searchDescriptor, searchOptions); @@ -5990,10 +5913,10 @@ public SearchResult searchUsersWhoCanExecutePendingHumanTask(final long hu public SearchResult searchAssignedAndPendingHumanTasksFor(final long rootProcessDefinitionId, final long userId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchHumanTaskInstanceDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchHumanTaskInstanceDescriptor(); return AbstractHumanTaskInstanceSearchEntity.searchHumanTaskInstance(searchDescriptor, @@ -6010,10 +5933,10 @@ public SearchResult searchAssignedAndPendingHumanTasksFor(fin public SearchResult searchAssignedAndPendingHumanTasks(final long rootProcessDefinitionId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchHumanTaskInstanceDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchHumanTaskInstanceDescriptor(); return AbstractHumanTaskInstanceSearchEntity.searchHumanTaskInstance(searchDescriptor, @@ -6029,10 +5952,10 @@ public SearchResult searchAssignedAndPendingHumanTasks(final @Override public SearchResult searchAssignedAndPendingHumanTasks(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final FlowNodeStateManager flowNodeStateManager = tenantAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); final SearchHumanTaskInstanceDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchHumanTaskInstanceDescriptor(); return AbstractHumanTaskInstanceSearchEntity.searchHumanTaskInstance(searchDescriptor, @@ -6044,14 +5967,14 @@ public SearchResult searchAssignedAndPendingHumanTasks(final @Override public ContractDefinition getUserTaskContract(final long userTaskId) throws UserTaskNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); try { final SHumanTaskInstance taskInstance = activityInstanceService.getHumanTaskInstance(userTaskId); if (!(taskInstance instanceof SUserTaskInstance)) { throw new UserTaskNotFoundException("Impossible to find a user task with id: " + userTaskId); } - final SProcessDefinition processDefinition = getTenantAccessor().getProcessDefinitionService() + final SProcessDefinition processDefinition = getServiceAccessor().getProcessDefinitionService() .getProcessDefinition( taskInstance.getProcessDefinitionId()); final SUserTaskDefinition userTask = (SUserTaskDefinition) processDefinition.getProcessContainer() @@ -6068,7 +5991,7 @@ public ContractDefinition getUserTaskContract(final long userTaskId) throws User public ContractDefinition getProcessContract(final long processDefinitionId) throws ProcessDefinitionNotFoundException { try { - final SProcessDefinition processDefinition = getTenantAccessor().getProcessDefinitionService() + final SProcessDefinition processDefinition = getServiceAccessor().getProcessDefinitionService() .getProcessDefinition(processDefinitionId); return ModelConvertor.toContract(processDefinition.getContract()); } catch (final SProcessDefinitionNotFoundException | SBonitaReadException e) { @@ -6110,7 +6033,7 @@ private void verifyIfTheActivityWasInTheCorrectStateAndThrowException(long flown SFlowNodeInstance flowNodeInstance; try { flowNodeInstance = inTx( - () -> getTenantAccessor().getActivityInstanceService().getFlowNodeInstance(flownodeInstanceId)); + () -> getServiceAccessor().getActivityInstanceService().getFlowNodeInstance(flownodeInstanceId)); } catch (SActivityInstanceNotFoundException e1) { throw new UserTaskNotFoundException( String.format("User task %s is not found, it might already be executed", flownodeInstanceId)); @@ -6129,7 +6052,7 @@ private void verifyIfTheActivityWasInTheCorrectStateAndThrowException(long flown } private T inTx(Callable booleanCallable) throws Exception { - return getTenantAccessor().getUserTransactionService().executeInTransaction(booleanCallable); + return getServiceAccessor().getUserTransactionService().executeInTransaction(booleanCallable); } private void checkIsHumanTaskInReadyState(SFlowNodeInstance flowNodeInstance) throws SFlowNodeExecutionException { @@ -6150,23 +6073,18 @@ private void checkIsHumanTaskInReadyState(SFlowNodeInstance flowNodeInstance) th * Execute a flow node. All methods that executes flow nodes and human tasks uses this one. * * @param userId the id of the user executing the task - * @param flowNodeInstanceId - * @param inputs * @param shouldBeReadyTask if true the method will only accept to execute human task in ready state - * @throws ContractViolationException - * @throws SBonitaException */ protected void executeFlowNode(final long userId, final long flowNodeInstanceId, final Map inputs, boolean shouldBeReadyTask) throws ContractViolationException, SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - ContractDataService contractDataService = tenantAccessor.getContractDataService(); - IdentityService identityService = tenantAccessor.getIdentityService(); - SCommentService commentService = tenantAccessor.getCommentService(); - FlowNodeExecutor flowNodeExecutor = tenantAccessor.getFlowNodeExecutor(); - WorkService workService = tenantAccessor.getWorkService(); - BPMWorkFactory workFactory = tenantAccessor.getBPMWorkFactory(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + ContractDataService contractDataService = serviceAccessor.getContractDataService(); + IdentityService identityService = serviceAccessor.getIdentityService(); + SCommentService commentService = serviceAccessor.getCommentService(); + WorkService workService = serviceAccessor.getWorkService(); + BPMWorkFactory workFactory = serviceAccessor.getBPMWorkFactory(); SFlowNodeInstance flowNodeInstance = activityInstanceService.getFlowNodeInstance(flowNodeInstanceId); if (shouldBeReadyTask) { @@ -6184,7 +6102,7 @@ protected void executeFlowNode(final long userId, final long flowNodeInstanceId, } if (flowNodeInstance instanceof SUserTaskInstance) { try { - throwContractViolationExceptionIfContractIsInvalid(inputs, tenantAccessor, flowNodeInstance); + throwContractViolationExceptionIfContractIsInvalid(inputs, serviceAccessor, flowNodeInstance); } catch (SContractViolationException e) { throw new ContractViolationException(e.getSimpleMessage(), e.getMessage(), e.getExplanations(), e.getCause()); @@ -6210,7 +6128,7 @@ protected void executeFlowNode(final long userId, final long flowNodeInstanceId, } // TODO: the following 4 instructions seem to be redundant with stepForward: // Cannot we factorize this? - tenantAccessor.getBPMArchiverService().archiveFlowNodeInstance(flowNodeInstance); + serviceAccessor.getBPMArchiverService().archiveFlowNodeInstance(flowNodeInstance); // flag as executing activityInstanceService.setExecuting(flowNodeInstance); activityInstanceService.setExecutedBy(flowNodeInstance, executerUserId); @@ -6245,16 +6163,16 @@ protected void executeFlowNode(final long userId, final long flowNodeInstanceId, } private void throwContractViolationExceptionIfContractIsInvalid(final Map inputs, - final TenantServiceAccessor tenantAccessor, final SFlowNodeInstance flowNodeInstance) + final ServiceAccessor serviceAccessor, final SFlowNodeInstance flowNodeInstance) throws SBonitaReadException, SProcessDefinitionNotFoundException, SContractViolationException { - final SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService() + final SProcessDefinition processDefinition = serviceAccessor.getProcessDefinitionService() .getProcessDefinition(flowNodeInstance.getProcessDefinitionId()); final SUserTaskDefinition userTaskDefinition = (SUserTaskDefinition) processDefinition.getProcessContainer() .getFlowNode( flowNodeInstance.getFlowNodeDefinitionId()); final SContractDefinition contractDefinition = userTaskDefinition.getContract(); final ContractValidator validator = new ContractValidatorFactory() - .createContractValidator(tenantAccessor.getExpressionService()); + .createContractValidator(serviceAccessor.getExpressionService()); validator.validate(flowNodeInstance.getProcessDefinitionId(), contractDefinition, inputs); } @@ -6284,8 +6202,8 @@ public void deleteContentOfArchivedDocument(final long archivedDocumentId) documentAPI.deleteContentOfArchivedDocument(archivedDocumentId); } - TenantServiceAccessor getTenantAccessor() { - return APIUtils.getTenantAccessor(); + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } long getUserId() { @@ -6316,7 +6234,7 @@ public void purgeClassLoader(final long processDefinitionId) @Override public Serializable getUserTaskContractVariableValue(final long userTaskInstanceId, final String name) throws ContractDataNotFoundException { - final ContractDataService contractDataService = getTenantAccessor().getContractDataService(); + final ContractDataService contractDataService = getServiceAccessor().getContractDataService(); try { return contractDataService.getArchivedUserTaskDataValue(userTaskInstanceId, name); } catch (final SContractDataNotFoundException scdnfe) { @@ -6330,7 +6248,7 @@ public Serializable getUserTaskContractVariableValue(final long userTaskInstance public Serializable getProcessInputValueDuringInitialization(long processInstanceId, String name) throws ContractDataNotFoundException { try { - return getTenantAccessor().getContractDataService().getProcessDataValue(processInstanceId, name); + return getServiceAccessor().getContractDataService().getProcessDataValue(processInstanceId, name); } catch (SContractDataNotFoundException | SBonitaReadException e) { throw new ContractDataNotFoundException(e); } @@ -6340,7 +6258,7 @@ public Serializable getProcessInputValueDuringInitialization(long processInstanc public Serializable getProcessInputValueAfterInitialization(long processInstanceId, String name) throws ContractDataNotFoundException { try { - return getTenantAccessor().getContractDataService().getArchivedProcessDataValue(processInstanceId, name); + return getServiceAccessor().getContractDataService().getArchivedProcessDataValue(processInstanceId, name); } catch (SContractDataNotFoundException | SBonitaReadException e) { throw new ContractDataNotFoundException(e); } @@ -6368,17 +6286,17 @@ public List getParameterInstances(final long processDefinitio @Override public Map getUserTaskExecutionContext(long userTaskInstanceId) throws UserTaskNotFoundException, ExpressionEvaluationException { - TenantServiceAccessor tenantAccessor = getTenantAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); try { - SFlowNodeInstance activityInstance = tenantAccessor.getActivityInstanceService() + SFlowNodeInstance activityInstance = serviceAccessor.getActivityInstanceService() .getFlowNodeInstance(userTaskInstanceId); - SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService() + SProcessDefinition processDefinition = serviceAccessor.getProcessDefinitionService() .getProcessDefinition(activityInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(userTaskInstanceId, processDefinition, CONTAINER_TYPE_ACTIVITY_INSTANCE, null); SFlowNodeDefinition flowNode = processDefinition.getProcessContainer() .getFlowNode(activityInstance.getFlowNodeDefinitionId()); - return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, + return evaluateContext(serviceAccessor.getExpressionResolverService(), expressionContext, ((SUserTaskDefinition) flowNode).getContext()); } catch (SFlowNodeNotFoundException | SBonitaReadException | SFlowNodeReadException | SProcessDefinitionNotFoundException e) { @@ -6393,18 +6311,18 @@ public Map getUserTaskExecutionContext(long userTaskInstan public Map getArchivedUserTaskExecutionContext(long archivedUserTaskInstanceId) throws UserTaskNotFoundException, ExpressionEvaluationException { - TenantServiceAccessor tenantAccessor = getTenantAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); try { - SAFlowNodeInstance archivedActivityInstance = tenantAccessor.getActivityInstanceService() + SAFlowNodeInstance archivedActivityInstance = serviceAccessor.getActivityInstanceService() .getArchivedFlowNodeInstance(archivedUserTaskInstanceId); - SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService() + SProcessDefinition processDefinition = serviceAccessor.getProcessDefinitionService() .getProcessDefinition(archivedActivityInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext( archivedActivityInstance.getSourceObjectId(), processDefinition, CONTAINER_TYPE_ACTIVITY_INSTANCE, archivedActivityInstance.getArchiveDate()); SFlowNodeDefinition flowNode = processDefinition.getProcessContainer() .getFlowNode(archivedActivityInstance.getFlowNodeDefinitionId()); - return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, + return evaluateContext(serviceAccessor.getExpressionResolverService(), expressionContext, ((SUserTaskDefinition) flowNode).getContext()); } catch (SFlowNodeNotFoundException | SBonitaReadException | SFlowNodeReadException | SProcessDefinitionNotFoundException e) { @@ -6419,18 +6337,18 @@ public Map getArchivedUserTaskExecutionContext(long archiv public Map getProcessInstanceExecutionContext(long processInstanceId) throws ProcessInstanceNotFoundException, ExpressionEvaluationException { - TenantServiceAccessor tenantAccessor = getTenantAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); try { - SProcessInstance processInstance = getProcessInstanceService(tenantAccessor) + SProcessInstance processInstance = getProcessInstanceService(serviceAccessor) .getProcessInstance(processInstanceId); if (processInstance == null) { throw new ProcessInstanceNotFoundException("Process Instance not found " + processInstanceId); } - SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService() + SProcessDefinition processDefinition = serviceAccessor.getProcessDefinitionService() .getProcessDefinition(processInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(processInstanceId, processDefinition, CONTAINER_TYPE_PROCESS_INSTANCE, null); - return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, + return evaluateContext(serviceAccessor.getExpressionResolverService(), expressionContext, processDefinition.getContext()); } catch (SProcessInstanceNotFoundException | SBonitaReadException | SProcessInstanceReadException | SProcessDefinitionNotFoundException e) { @@ -6445,20 +6363,20 @@ public Map getProcessInstanceExecutionContext(long process public Map getArchivedProcessInstanceExecutionContext(long archivedProcessInstanceId) throws ProcessInstanceNotFoundException, ExpressionEvaluationException { - TenantServiceAccessor tenantAccessor = getTenantAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); try { - SAProcessInstance processInstance = getProcessInstanceService(tenantAccessor) + SAProcessInstance processInstance = getProcessInstanceService(serviceAccessor) .getArchivedProcessInstance(archivedProcessInstanceId); if (processInstance == null) { throw new ProcessInstanceNotFoundException( "Archived Process Instance not found " + archivedProcessInstanceId); } - SProcessDefinition processDefinition = tenantAccessor.getProcessDefinitionService() + SProcessDefinition processDefinition = serviceAccessor.getProcessDefinitionService() .getProcessDefinition(processInstance.getProcessDefinitionId()); final SExpressionContext expressionContext = createExpressionContext(processInstance.getSourceObjectId(), processDefinition, CONTAINER_TYPE_PROCESS_INSTANCE, processInstance.getArchiveDate()); - return evaluateContext(tenantAccessor.getExpressionResolverService(), expressionContext, + return evaluateContext(serviceAccessor.getExpressionResolverService(), expressionContext, processDefinition.getContext()); } catch (SBonitaReadException | SProcessInstanceReadException | SProcessDefinitionNotFoundException e) { throw new ProcessInstanceNotFoundException(e); @@ -6497,8 +6415,8 @@ HashMap toResultMap(List context, List searchFormMappings(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - FormMappingService formMappingService = tenantAccessor.getFormMappingService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + FormMappingService formMappingService = serviceAccessor.getFormMappingService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); final SearchFormMappings searchFormMappings = new SearchFormMappings(formMappingService, - getTenantAccessor().getProcessDefinitionService(), + getServiceAccessor().getProcessDefinitionService(), searchEntitiesDescriptor.getSearchFormMappingDescriptor(), searchOptions); try { @@ -61,10 +58,10 @@ public SearchResult searchFormMappings(final SearchOptions searchOp } public FormMapping getFormMapping(long formMappingId) throws FormMappingNotFoundException { - final FormMappingService formMappingService = getTenantAccessor().getFormMappingService(); + final FormMappingService formMappingService = getServiceAccessor().getFormMappingService(); try { return ModelConvertor.toFormMapping(formMappingService.get(formMappingId), - new FormRequiredAnalyzer(getTenantAccessor() + new FormRequiredAnalyzer(getServiceAccessor() .getProcessDefinitionService())); } catch (SBonitaReadException e) { throw new RetrieveException(e); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegate.java index 0a9a3e86876..b665a8cec83 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegate.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; +import lombok.Getter; import org.bonitasoft.engine.api.impl.transaction.process.EnableProcess; import org.bonitasoft.engine.bar.BusinessArchiveService; import org.bonitasoft.engine.bpm.bar.BusinessArchive; @@ -40,30 +41,28 @@ import org.bonitasoft.engine.search.descriptor.SearchProcessDefinitionsDescriptor; import org.bonitasoft.engine.search.process.SearchProcessDeploymentInfos; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Emmanuel Duchastenier */ public class ProcessDeploymentAPIDelegate { + @Getter private static final ProcessDeploymentAPIDelegate instance = new ProcessDeploymentAPIDelegate(); private ProcessDeploymentAPIDelegate() { } - public static ProcessDeploymentAPIDelegate getInstance() { - return instance; - } - - protected TenantServiceAccessor getTenantServiceAccessor() { - return APIUtils.getTenantAccessor(); + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } public ProcessDefinition deploy(final BusinessArchive businessArchive) throws ProcessDeployException, AlreadyExistsException { validateBusinessArchive(businessArchive); - final BusinessArchiveService businessArchiveService = getTenantServiceAccessor().getBusinessArchiveService(); + final BusinessArchiveService businessArchiveService = getServiceAccessor().getBusinessArchiveService(); try { return ModelConvertor.toProcessDefinition(businessArchiveService.deploy(businessArchive)); } catch (SV6FormsDeployException e) { @@ -99,9 +98,9 @@ void validateBusinessArchive(BusinessArchive businessArchive) throws ProcessDepl public void enableProcess(final long processDefinitionId) throws ProcessDefinitionNotFoundException, ProcessEnablementException { - final ProcessDefinitionService processDefinitionService = getTenantServiceAccessor() + final ProcessDefinitionService processDefinitionService = getServiceAccessor() .getProcessDefinitionService(); - final EventsHandler eventsHandler = getTenantServiceAccessor().getEventsHandler(); + final EventsHandler eventsHandler = getServiceAccessor().getEventsHandler(); try { new EnableProcess(processDefinitionService, processDefinitionId, eventsHandler, SessionInfos.getUserNameFromSession()).execute(); @@ -115,7 +114,7 @@ public void enableProcess(final long processDefinitionId) public long getProcessDefinitionId(final String name, final String version) throws ProcessDefinitionNotFoundException { try { - return getTenantServiceAccessor().getProcessDefinitionService().getProcessDefinitionId(name, version); + return getServiceAccessor().getProcessDefinitionService().getProcessDefinitionId(name, version); } catch (final SProcessDefinitionNotFoundException e) { throw new ProcessDefinitionNotFoundException(e); } catch (final SBonitaReadException e) { @@ -125,19 +124,19 @@ public long getProcessDefinitionId(final String name, final String version) public List getProcessResolutionProblems(final long processDefinitionId) throws ProcessDefinitionNotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { SProcessDefinition processDefinition = processDefinitionService.getProcessDefinition(processDefinitionId); - return tenantAccessor.getBusinessArchiveArtifactsManager().getProcessResolutionProblems(processDefinition); + return serviceAccessor.getBusinessArchiveArtifactsManager().getProcessResolutionProblems(processDefinition); } catch (final SProcessDefinitionNotFoundException | SBonitaReadException e) { throw new ProcessDefinitionNotFoundException(e); } } public Map getProcessDeploymentInfosFromIds(final List processDefinitionIds) { - final TenantServiceAccessor tenantAccessor = getTenantServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final List processDefinitionDeployInfos = processDefinitionService .getProcessDeploymentInfos(processDefinitionIds); @@ -155,7 +154,7 @@ public Map getProcessDeploymentInfosFromIds(final L public ProcessDeploymentInfo getProcessDeploymentInfo(final long processDefinitionId) throws ProcessDefinitionNotFoundException { - final ProcessDefinitionService processDefinitionService = getTenantServiceAccessor() + final ProcessDefinitionService processDefinitionService = getServiceAccessor() .getProcessDefinitionService(); try { return ModelConvertor @@ -169,10 +168,10 @@ public ProcessDeploymentInfo getProcessDeploymentInfo(final long processDefiniti public SearchResult searchProcessDeploymentInfos(final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantAccessor = getTenantServiceAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantAccessor.getSearchEntitiesDescriptor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SearchProcessDefinitionsDescriptor searchDescriptor = searchEntitiesDescriptor .getSearchProcessDefinitionsDescriptor(); final SearchProcessDeploymentInfos transactionSearch = new SearchProcessDeploymentInfos( diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegate.java index f6210f29c52..6a74e956cbe 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegate.java @@ -41,14 +41,11 @@ import org.bonitasoft.engine.identity.IdentityService; import org.bonitasoft.engine.identity.SUserNotFoundException; import org.bonitasoft.engine.identity.model.SUser; -import org.bonitasoft.engine.persistence.FilterOption; -import org.bonitasoft.engine.persistence.OrderByOption; -import org.bonitasoft.engine.persistence.OrderByType; -import org.bonitasoft.engine.persistence.QueryOptions; -import org.bonitasoft.engine.persistence.SBonitaReadException; +import org.bonitasoft.engine.persistence.*; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.descriptor.SearchEntitiesDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Emmanuel Duchastenier @@ -57,8 +54,8 @@ public class ProcessInvolvementDelegate { private static final int BATCH_SIZE = 100; - protected TenantServiceAccessor getTenantServiceAccessor() { - return APIUtils.getTenantAccessor(); + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } private static QueryOptions buildArchivedTasksQueryOptions(final long processInstanceId) { @@ -116,13 +113,13 @@ public boolean isProcessOrArchivedProcessInitiator(long userId, long processInst private boolean isProcessInitiator(long userId, Long processInstanceId) throws SProcessInstanceNotFoundException, SProcessInstanceReadException { - final ProcessInstanceService processInstanceService = getTenantServiceAccessor().getProcessInstanceService(); + final ProcessInstanceService processInstanceService = getServiceAccessor().getProcessInstanceService(); final SProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); return userId == processInstance.getStartedBy(); } boolean isArchivedProcessInitiator(long userId, long processInstanceId) throws ProcessInstanceNotFoundException { - final ProcessInstanceService processInstanceService = getTenantServiceAccessor().getProcessInstanceService(); + final ProcessInstanceService processInstanceService = getServiceAccessor().getProcessInstanceService(); final List orderByOptions = Arrays.asList( new OrderByOption(SAProcessInstance.class, ArchivedProcessInstancesSearchDescriptor.ARCHIVE_DATE, OrderByType.DESC), @@ -146,11 +143,11 @@ boolean isArchivedProcessInitiator(long userId, long processInstanceId) throws P public boolean isManagerOfUserInvolvedInProcessInstance(final long managerUserId, final long processInstanceId) throws BonitaException { - final TenantServiceAccessor tenantServiceAccessor = getTenantServiceAccessor(); - final ProcessInstanceService processInstanceService = tenantServiceAccessor.getProcessInstanceService(); - final IdentityService identityService = tenantServiceAccessor.getIdentityService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); final TaskInvolvementDelegate taskInvolvementDelegate = new TaskInvolvementDelegate(); - final ActivityInstanceService activityInstanceService = tenantServiceAccessor.getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final List subordinates = getSubordinates(managerUserId, identityService); @@ -270,7 +267,7 @@ private boolean isTaskAssignedToAUserInTheList(final SHumanTaskInstance humanTas } private boolean isUserManagerOfProcessInstanceInitiator(final long userId, final long startedByUserId) { - final IdentityService identityService = getTenantServiceAccessor().getIdentityService(); + final IdentityService identityService = getServiceAccessor().getIdentityService(); SUser sUser; try { sUser = identityService.getUser(startedByUserId); @@ -282,10 +279,10 @@ private boolean isUserManagerOfProcessInstanceInitiator(final long userId, final public ArchivedProcessInstance getLastArchivedProcessInstance(final long processInstanceId) throws SBonitaException { - final ProcessInstanceService processInstanceService = getTenantServiceAccessor().getProcessInstanceService(); - final ProcessDefinitionService processDefinitionService = getTenantServiceAccessor() + final ProcessInstanceService processInstanceService = getServiceAccessor().getProcessInstanceService(); + final ProcessDefinitionService processDefinitionService = getServiceAccessor() .getProcessDefinitionService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = getTenantServiceAccessor() + final SearchEntitiesDescriptor searchEntitiesDescriptor = getServiceAccessor() .getSearchEntitiesDescriptor(); final GetLastArchivedProcessInstance searchArchivedProcessInstances = new GetLastArchivedProcessInstance( diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegate.java index 7d8d29a76b0..bbe61610b49 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegate.java @@ -47,7 +47,6 @@ import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.scheduler.SchedulerService; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; /** @@ -63,7 +62,7 @@ public static ProcessManagementAPIImplDelegate getInstance() { return instance; } - private static ServiceAccessor getServiceAccessor() { + protected ServiceAccessor getServiceAccessor() { try { return ServiceAccessorFactory.getInstance().createServiceAccessor(); } catch (final Exception e) { @@ -77,24 +76,19 @@ public static SProcessDefinition getServerProcessDefinition(final long processDe return processDefinitionService.getProcessDefinition(processDefinitionId); } - protected TenantServiceAccessor getTenantAccessor() { - return APIUtils.getTenantAccessor(); - } - public void deleteProcessDefinition(final long processDefinitionId) throws SBonitaException, BonitaHomeNotSetException, IOException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - tenantAccessor.getBusinessArchiveService().delete(processDefinitionId); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + serviceAccessor.getBusinessArchiveService().delete(processDefinitionId); log.info("The user <" + SessionInfos.getUserNameFromSession() + "> has deleted process with id = <" + processDefinitionId + ">"); } public void disableProcess(final long processId) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final ServiceAccessor serviceAccessor = getServiceAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final EventInstanceService eventInstanceService = tenantAccessor.getEventInstanceService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final EventInstanceService eventInstanceService = serviceAccessor.getEventInstanceService(); final SchedulerService schedulerService = serviceAccessor.getSchedulerService(); final DisableProcess disableProcess = new DisableProcess(processDefinitionService, processId, @@ -105,21 +99,21 @@ public void disableProcess(final long processId) throws SBonitaException { public void purgeClassLoader(final long processDefinitionId) throws ProcessDefinitionNotFoundException, UpdateException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinitionDeployInfo processDeploymentInfo = processDefinitionService .getProcessDeploymentInfo(processDefinitionId); if (!ActivationState.DISABLED.name().equals(processDeploymentInfo.getActivationState())) { throw new UpdateException("Purge can only be done on a disabled process"); } - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final long numberOfProcessInstances = processInstanceService .getNumberOfProcessInstances(processDefinitionId); if (numberOfProcessInstances != 0) { throw new UpdateException("Purge can only be done on a disabled process with no running instances"); } - tenantAccessor.getClassLoaderService().removeLocalClassloader(identifier(PROCESS, processDefinitionId)); + serviceAccessor.getClassLoaderService().removeLocalClassloader(identifier(PROCESS, processDefinitionId)); } catch (final SProcessDefinitionNotFoundException e) { throw new ProcessDefinitionNotFoundException(e); } catch (final SBonitaReadException e) { @@ -131,9 +125,9 @@ public void purgeClassLoader(final long processDefinitionId) public List getParameterInstances(final long processDefinitionId, final int startIndex, final int maxResults, final ParameterCriterion sort) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ParameterService parameterService = tenantAccessor.getParameterService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ParameterService parameterService = serviceAccessor.getParameterService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { OrderBy order; switch (sort) { @@ -153,8 +147,7 @@ public List getParameterInstances(final long processDefinitio final List parameters = parameterService.get(processDefinitionId, startIndex, maxResults, order); final List parameterInstances = new ArrayList<>(); - for (int i = 0; i < parameters.size(); i++) { - final SParameter parameter = parameters.get(i); + for (final SParameter parameter : parameters) { final String name = parameter.getName(); final String value = parameter.getValue(); final SParameterDefinition parameterDefinition = sProcessDefinition.getParameter(name); @@ -169,8 +162,8 @@ public List getParameterInstances(final long processDefinitio } public int getNumberOfParameterInstances(final long processDefinitionId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = getServerProcessDefinition(processDefinitionId, processDefinitionService); @@ -182,9 +175,9 @@ public int getNumberOfParameterInstances(final long processDefinitionId) { public ParameterInstance getParameterInstance(final long processDefinitionId, final String parameterName) throws NotFoundException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ParameterService parameterService = tenantAccessor.getParameterService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ParameterService parameterService = serviceAccessor.getParameterService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { final SProcessDefinition sProcessDefinition = getServerProcessDefinition(processDefinitionId, processDefinitionService); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessStarter.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessStarter.java index 149fc7aa758..c2235986869 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessStarter.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProcessStarter.java @@ -39,18 +39,14 @@ import org.bonitasoft.engine.core.process.instance.model.SProcessInstance; import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.execution.Filter; -import org.bonitasoft.engine.execution.FlowNodeNameFilter; -import org.bonitasoft.engine.execution.FlowNodeSelector; -import org.bonitasoft.engine.execution.ProcessExecutor; -import org.bonitasoft.engine.execution.StartFlowNodeFilter; +import org.bonitasoft.engine.execution.*; import org.bonitasoft.engine.identity.IdentityService; import org.bonitasoft.engine.identity.model.SUser; import org.bonitasoft.engine.operation.Operation; import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Elias Ricken de Medeiros @@ -123,9 +119,9 @@ public ProcessInstance start() public ProcessInstance start(final List connectorsWithInput) throws SProcessInstanceCreationException, SBonitaReadException, SProcessDefinitionException, SContractViolationException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final ProcessExecutor processExecutor = tenantAccessor.getProcessExecutor(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ProcessExecutor processExecutor = serviceAccessor.getProcessExecutor(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinitionIfIsEnabled(processDefinitionId); @@ -160,7 +156,7 @@ protected long getStarterUserId(final long starterSubstituteUserId) { protected Map getContext() { if (context != null) { - return new HashMap(context); + return new HashMap<>(context); } return Collections.emptyMap(); } @@ -193,11 +189,11 @@ private void logProcessInstanceStartedAndAddComment(final SProcessDefinition sPr protected void addSystemCommentOnProcessInstanceWhenStartingProcessFor(final SProcessInstance sProcessInstance, final long starterId, final long starterSubstituteId) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SCommentService commentService = tenantAccessor.getCommentService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SCommentService commentService = serviceAccessor.getCommentService(); if (starterId != starterSubstituteId) { - final IdentityService identityService = tenantAccessor.getIdentityService(); + final IdentityService identityService = serviceAccessor.getIdentityService(); try { final SUser starter = identityService.getUser(starterId); commentService.addSystemComment(sProcessInstance.getId(), @@ -210,9 +206,9 @@ protected void addSystemCommentOnProcessInstanceWhenStartingProcessFor(final SPr } } - protected TenantServiceAccessor getTenantAccessor() { + protected ServiceAccessor getServiceAccessor() { try { - return TenantServiceSingleton.getInstance(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java index e7cffdb597f..ec099c92391 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java @@ -54,7 +54,6 @@ import org.bonitasoft.engine.scheduler.exception.SSchedulerException; import org.bonitasoft.engine.service.APIAccessResolver; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; import org.bonitasoft.engine.session.*; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; @@ -80,7 +79,7 @@ */ public class ServerAPIImpl implements ServerAPI { - private static Logger logger = LoggerFactory.getLogger(ServerAPIImpl.class); + private static final Logger logger = LoggerFactory.getLogger(ServerAPIImpl.class); private static final String SESSION = "session"; private static final long serialVersionUID = -161775388604256321L; @@ -229,7 +228,7 @@ private ClassLoader beforeInvokeMethodForAPISession(SessionAccessor sessionAcces ServiceAccessor serviceAccessor, Session session) throws SBonitaException { checkTenantSession(serviceAccessor, session); long tenantId = ((APISession) session).getTenantId(); - SessionService sessionService = serviceAccessor.getTenantServiceAccessor().getSessionService(); + SessionService sessionService = serviceAccessor.getSessionService(); sessionService.renewSession(session.getId()); sessionAccessor.setSessionInfo(session.getId(), tenantId); return getTenantClassLoader(serviceAccessor, session); @@ -272,7 +271,7 @@ private Object invokeAPI(Object api, String apiInterfaceName, final String metho Supplier failureMessage = () -> MessageFormat.format( "Operation ''{0}.{1}'' requires exclusive access. Another operation is already launched with the same ''{2}'' access scope. You may try again after the other operation has finished.", apiInterfaceName, methodName, lockKey.orElse("")); - try (AutoCloseable functionalLock = withEventualLock(lockKey, session, failureMessage)) { + try (AutoCloseable ignored = withEventualLock(lockKey, session, failureMessage)) { // No session required means that there is no transaction if (method.isAnnotationPresent(CustomTransactions.class) || Class.forName(apiInterfaceName).isAnnotationPresent(NoSessionRequired.class)) { @@ -458,9 +457,7 @@ UserTransactionService selectUserTransactionService(final Session session, final transactionService = serviceAccessor.getTransactionService(); break; case API: - final TenantServiceAccessor tenantAccessor = serviceAccessor - .getTenantServiceAccessor(); - transactionService = tenantAccessor.getUserTransactionService(); + transactionService = serviceAccessor.getUserTransactionService(); break; default: throw new InvalidSessionException("Unknown session type: " + session.getClass().getName()); @@ -499,27 +496,23 @@ private Class[] getParameterTypes(final List classNameParameters) thr return parameterTypes; } - private void checkTenantSession(final ServiceAccessor platformAccessor, final Session session) + private void checkTenantSession(final ServiceAccessor serviceAccessor, final Session session) throws SSchedulerException { - final SchedulerService schedulerService = platformAccessor.getSchedulerService(); + final SchedulerService schedulerService = serviceAccessor.getSchedulerService(); if (!schedulerService.isStarted()) { logger.debug("The scheduler is not started!"); } final APISession apiSession = (APISession) session; - final TenantServiceAccessor tenantAccessor = platformAccessor - .getTenantServiceAccessor(); - final LoginService tenantLoginService = tenantAccessor.getLoginService(); + final LoginService tenantLoginService = serviceAccessor.getLoginService(); if (!tenantLoginService.isValid(apiSession.getId())) { throw new InvalidSessionException("Invalid session"); } } - private ClassLoader getTenantClassLoader(final ServiceAccessor serviceAccessor, - final Session session) throws SClassLoaderException { + private ClassLoader getTenantClassLoader(final ServiceAccessor serviceAccessor, final Session session) + throws SClassLoaderException { final APISession apiSession = (APISession) session; - final TenantServiceAccessor tenantAccessor = serviceAccessor - .getTenantServiceAccessor(); - final ClassLoaderService classLoaderService = tenantAccessor.getClassLoaderService(); + final ClassLoaderService classLoaderService = serviceAccessor.getClassLoaderService(); return classLoaderService.getClassLoader(identifier(ScopeType.TENANT, apiSession.getTenantId())); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/SessionInfos.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/SessionInfos.java index eaba627c663..b0cf70c9b25 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/SessionInfos.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/SessionInfos.java @@ -64,8 +64,7 @@ public static SSession getSession() { private static SessionService getSessionService() { try { - return ServiceAccessorFactory.getInstance().createServiceAccessor().getTenantServiceAccessor() - .getSessionService(); + return ServiceAccessorFactory.getInstance().createServiceAccessor().getSessionService(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegate.java index d634cae6eff..266c961464e 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegate.java @@ -13,7 +13,6 @@ **/ package org.bonitasoft.engine.api.impl; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -30,16 +29,13 @@ import org.bonitasoft.engine.exception.RetrieveException; import org.bonitasoft.engine.exception.SearchException; import org.bonitasoft.engine.execution.state.FlowNodeStateManager; -import org.bonitasoft.engine.persistence.FilterOption; -import org.bonitasoft.engine.persistence.OrderByOption; -import org.bonitasoft.engine.persistence.OrderByType; -import org.bonitasoft.engine.persistence.QueryOptions; -import org.bonitasoft.engine.persistence.SBonitaReadException; +import org.bonitasoft.engine.persistence.*; import org.bonitasoft.engine.search.AbstractHumanTaskInstanceSearchEntity; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.search.descriptor.SearchEntitiesDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Emmanuel Duchastenier @@ -48,13 +44,13 @@ public class TaskInvolvementDelegate { private static final int BATCH_SIZE = 100; - protected TenantServiceAccessor getTenantServiceAccessor() { - return APIUtils.getTenantAccessor(); + protected ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } public boolean isExecutorOfArchivedTaskOfProcess(long userId, Long rootProcessInstanceId) throws SBonitaReadException { - final ActivityInstanceService activityInstanceService = getTenantServiceAccessor().getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); QueryOptions archivedQueryOptions = buildArchivedTasksQueryOptions(rootProcessInstanceId); List sArchivedHumanTasks = activityInstanceService @@ -86,7 +82,7 @@ private static QueryOptions buildArchivedTasksQueryOptions(final long rootProces public boolean isInvolvedInHumanTaskInstance(long userId, long humanTaskInstanceId) throws ActivityInstanceNotFoundException { - final ActivityInstanceService activityInstanceService = getTenantServiceAccessor().getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); try { long assigneeId; final SHumanTaskInstance humanTaskInstance = activityInstanceService @@ -107,10 +103,10 @@ public boolean isInvolvedInHumanTaskInstance(long userId, long humanTaskInstance } public boolean hasUserPendingOrAssignedTasks(long userId, Long processInstanceId) throws SExecutionException { - final ActivityInstanceService activityInstanceService = getTenantServiceAccessor().getActivityInstanceService(); + final ActivityInstanceService activityInstanceService = getServiceAccessor().getActivityInstanceService(); // is user assigned or has pending tasks on this process instance: final QueryOptions queryOptions = new QueryOptions(0, 1, Collections.EMPTY_LIST, - Arrays.asList(new FilterOption(SHumanTaskInstance.class, + List.of(new FilterOption(SHumanTaskInstance.class, "logicalGroup2", processInstanceId)), null); try { @@ -122,10 +118,10 @@ public boolean hasUserPendingOrAssignedTasks(long userId, Long processInstanceId public SearchResult searchPendingTasksManagedBy(final long managerUserId, final SearchOptions searchOptions) throws SearchException { - final TenantServiceAccessor tenantServiceAccessor = getTenantServiceAccessor(); - final ActivityInstanceService activityInstanceService = tenantServiceAccessor.getActivityInstanceService(); - final SearchEntitiesDescriptor searchEntitiesDescriptor = tenantServiceAccessor.getSearchEntitiesDescriptor(); - final FlowNodeStateManager flowNodeStateManager = tenantServiceAccessor.getFlowNodeStateManager(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final SearchEntitiesDescriptor searchEntitiesDescriptor = serviceAccessor.getSearchEntitiesDescriptor(); + final FlowNodeStateManager flowNodeStateManager = serviceAccessor.getFlowNodeStateManager(); return AbstractHumanTaskInstanceSearchEntity.searchHumanTaskInstance( searchEntitiesDescriptor.getSearchHumanTaskInstanceDescriptor(), searchOptions, diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java index 57cdb73f38e..1132f662947 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java @@ -26,8 +26,6 @@ import org.bonitasoft.engine.resources.TenantResourcesService; import org.bonitasoft.engine.service.ModelConvertor; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; import org.bonitasoft.engine.tenant.TenantResource; @@ -73,10 +71,9 @@ public boolean isPaused() { @AvailableWhenTenantIsPaused @CustomTransactions public void pause() throws UpdateException { - TenantServiceAccessor tenantServiceAccessor = getServiceAccessorNoException() - .getTenantServiceAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessorNoException(); try { - tenantServiceAccessor.getTenantStateManager().pause(); + serviceAccessor.getTenantStateManager().pause(); } catch (Exception e) { throw new UpdateException(e); } @@ -86,11 +83,10 @@ public void pause() throws UpdateException { @AvailableWhenTenantIsPaused @CustomTransactions public void resume() throws UpdateException { - TenantServiceAccessor tenantServiceAccessor = getServiceAccessorNoException() - .getTenantServiceAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessorNoException(); try { - tenantServiceAccessor.getTenantStateManager().resume(); - tenantServiceAccessor.getUserTransactionService().executeInTransaction(() -> { + serviceAccessor.getTenantStateManager().resume(); + serviceAccessor.getUserTransactionService().executeInTransaction(() -> { resolveDependenciesForAllProcesses(); return null; }); @@ -100,8 +96,8 @@ public void resume() throws UpdateException { } private void resolveDependenciesForAllProcesses() { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - tenantAccessor.getBusinessArchiveArtifactsManager().resolveDependenciesForAllProcesses(tenantAccessor); + getServiceAccessor().getBusinessArchiveArtifactsManager() + .resolveDependenciesForAllProcesses(getServiceAccessor()); } @Override @@ -111,7 +107,7 @@ public TenantResource getBusinessDataModelResource() { } protected TenantResource getTenantResource(TenantResourceType type) { - TenantResourcesService tenantResourcesService = getTenantAccessor().getTenantResourcesService(); + TenantResourcesService tenantResourcesService = getServiceAccessor().getTenantResourcesService(); org.bonitasoft.engine.resources.TenantResourceType resourceType = org.bonitasoft.engine.resources.TenantResourceType .valueOf(type.name()); try { @@ -127,7 +123,7 @@ protected TenantResource getTenantResource(TenantResourceType type) { @AvailableWhenTenantIsPaused public String getBusinessDataModelVersion() throws BusinessDataRepositoryException { try { - final BusinessDataModelRepository modelRepository = getTenantAccessor().getBusinessDataModelRepository(); + final BusinessDataModelRepository modelRepository = getServiceAccessor().getBusinessDataModelRepository(); return modelRepository.getInstalledBDMVersion(); } catch (final SBusinessDataRepositoryException e) { throw new BusinessDataRepositoryException(e); @@ -137,7 +133,7 @@ public String getBusinessDataModelVersion() throws BusinessDataRepositoryExcepti private String installBusinessDataModel(final byte[] zip) throws InvalidBusinessDataModelException, BusinessDataRepositoryDeploymentException { log.info("Starting the installation of the BDM."); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); final long userId; try { userId = getUserId(); @@ -145,8 +141,8 @@ private String installBusinessDataModel(final byte[] zip) throw new BusinessDataRepositoryDeploymentException("Unable to determine user ID"); } try { - final BusinessDataModelRepository bdmRepository = tenantAccessor.getBusinessDataModelRepository(); - TenantStateManager tenantStateManager = tenantAccessor.getTenantStateManager(); + final BusinessDataModelRepository bdmRepository = serviceAccessor.getBusinessDataModelRepository(); + TenantStateManager tenantStateManager = serviceAccessor.getTenantStateManager(); String bdm_version = tenantStateManager.executeTenantManagementOperation("BDM Installation", () -> bdmRepository.install(zip, userId)); log.info("Installation of the BDM completed."); @@ -165,12 +161,12 @@ private String installBusinessDataModel(final byte[] zip) @WithLock(key = UPDATE_BDM) public void uninstallBusinessDataModel() throws BusinessDataRepositoryDeploymentException { log.info("Uninstalling the currently deployed BDM"); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - final BusinessDataModelRepository bdmRepository = tenantAccessor.getBusinessDataModelRepository(); - TenantStateManager tenantStateManager = tenantAccessor.getTenantStateManager(); + final BusinessDataModelRepository bdmRepository = serviceAccessor.getBusinessDataModelRepository(); + TenantStateManager tenantStateManager = serviceAccessor.getTenantStateManager(); tenantStateManager.executeTenantManagementOperation("BDM Uninstallation", () -> { - bdmRepository.uninstall(tenantAccessor.getTenantId()); + bdmRepository.uninstall(serviceAccessor.getTenantId()); return null; }); log.info("BDM successfully uninstalled"); @@ -203,12 +199,12 @@ public String updateBusinessDataModel(final byte[] zip) @AvailableWhenTenantIsPaused(onlyAvailableWhenPaused = true) @WithLock(key = UPDATE_BDM) public void cleanAndUninstallBusinessDataModel() throws BusinessDataRepositoryDeploymentException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); try { - final BusinessDataModelRepository bdmRepository = tenantAccessor.getBusinessDataModelRepository(); - TenantStateManager tenantStateManager = tenantAccessor.getTenantStateManager(); + final BusinessDataModelRepository bdmRepository = serviceAccessor.getBusinessDataModelRepository(); + TenantStateManager tenantStateManager = serviceAccessor.getTenantStateManager(); tenantStateManager.executeTenantManagementOperation("BDM Cleanup and uninstallation", () -> { - bdmRepository.dropAndUninstall(tenantAccessor.getTenantId()); + bdmRepository.dropAndUninstall(serviceAccessor.getTenantId()); return null; }); } catch (final SBusinessDataRepositoryException sbdre) { @@ -221,7 +217,7 @@ public void cleanAndUninstallBusinessDataModel() throws BusinessDataRepositoryDe @Override @AvailableWhenTenantIsPaused public byte[] getClientBDMZip() throws BusinessDataRepositoryException { - final BusinessDataModelRepository bdmRepository = getTenantAccessor().getBusinessDataModelRepository(); + final BusinessDataModelRepository bdmRepository = getServiceAccessor().getBusinessDataModelRepository(); try { return bdmRepository.getClientBDMZip(); } catch (final SBusinessDataRepositoryException e) { @@ -229,9 +225,9 @@ public byte[] getClientBDMZip() throws BusinessDataRepositoryException { } } - protected TenantServiceAccessor getTenantAccessor() { + protected ServiceAccessor getServiceAccessor() { try { - return TenantServiceSingleton.getInstance(); + return ServiceAccessorFactory.getInstance().createServiceAccessor(); } catch (final Exception e) { throw new BonitaRuntimeException(e); } @@ -244,7 +240,7 @@ private SessionAccessor getSessionAccessor() throws IOException, BonitaHomeConfi protected long getUserId() throws IllegalStateException { try { - return getTenantAccessor().getSessionService().getSession(getSessionAccessor().getSessionId()).getUserId(); + return getServiceAccessor().getSessionService().getSession(getSessionAccessor().getSessionId()).getUserId(); } catch (final Exception e) { throw new BonitaRuntimeException(e.getMessage()); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/application/installer/ApplicationInstaller.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/application/installer/ApplicationInstaller.java index 455c84efae7..460d4a8d5d7 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/application/installer/ApplicationInstaller.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/application/installer/ApplicationInstaller.java @@ -24,9 +24,19 @@ import static org.bonitasoft.engine.bpm.process.ConfigurationState.RESOLVED; import static org.bonitasoft.engine.business.application.ApplicationImportPolicy.FAIL_ON_DUPLICATES; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.Serializable; import java.nio.file.Files; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -47,13 +57,28 @@ import org.bonitasoft.engine.bpm.bar.BusinessArchive; import org.bonitasoft.engine.bpm.bar.BusinessArchiveFactory; import org.bonitasoft.engine.bpm.bar.InvalidBusinessArchiveFormatException; -import org.bonitasoft.engine.bpm.process.*; +import org.bonitasoft.engine.bpm.process.Problem; +import org.bonitasoft.engine.bpm.process.ProcessDefinitionNotFoundException; +import org.bonitasoft.engine.bpm.process.ProcessDeployException; +import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo; +import org.bonitasoft.engine.bpm.process.ProcessEnablementException; import org.bonitasoft.engine.business.application.ApplicationImportPolicy; import org.bonitasoft.engine.business.application.importer.ApplicationImporter; import org.bonitasoft.engine.business.application.importer.StrategySelector; -import org.bonitasoft.engine.business.data.*; +import org.bonitasoft.engine.business.data.BusinessDataModelRepository; +import org.bonitasoft.engine.business.data.BusinessDataRepositoryDeploymentException; +import org.bonitasoft.engine.business.data.InvalidBusinessDataModelException; +import org.bonitasoft.engine.business.data.SBusinessDataRepositoryDeploymentException; +import org.bonitasoft.engine.business.data.SBusinessDataRepositoryException; import org.bonitasoft.engine.commons.exceptions.SBonitaException; -import org.bonitasoft.engine.exception.*; +import org.bonitasoft.engine.exception.AlreadyExistsException; +import org.bonitasoft.engine.exception.ApplicationInstallationException; +import org.bonitasoft.engine.exception.BonitaException; +import org.bonitasoft.engine.exception.BonitaRuntimeException; +import org.bonitasoft.engine.exception.CreationException; +import org.bonitasoft.engine.exception.ImportException; +import org.bonitasoft.engine.exception.SearchException; +import org.bonitasoft.engine.exception.UpdateException; import org.bonitasoft.engine.identity.ImportPolicy; import org.bonitasoft.engine.identity.OrganizationImportException; import org.bonitasoft.engine.io.FileOperations; @@ -62,9 +87,8 @@ import org.bonitasoft.engine.page.PageSearchDescriptor; import org.bonitasoft.engine.page.PageUpdater; import org.bonitasoft.engine.search.SearchOptionsBuilder; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; -import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.session.SessionService; import org.bonitasoft.engine.session.model.SSession; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; @@ -218,7 +242,7 @@ public void resumeTenantInSession() throws Exception { try { tenantStateManager.resume(); transactionService.executeInTransaction(() -> { - businessArchiveArtifactsManager.resolveDependenciesForAllProcesses(getTenantAccessor()); + businessArchiveArtifactsManager.resolveDependenciesForAllProcesses(getServiceAccessor()); return null; }); } catch (Exception e) { @@ -757,13 +781,8 @@ public T inTransaction(Callable callable) throws ApplicationInstallationE } } - private TenantServiceAccessor getTenantAccessor() { - try { - ServiceAccessorFactory.getInstance().createSessionAccessor(); - } catch (Exception e) { - throw new RuntimeException(e); - } - return TenantServiceSingleton.getInstance(); + private ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } public void logInstallationResult(ExecutionResult result) { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegate.java index 901258f2557..48eb37dc702 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegate.java @@ -14,13 +14,7 @@ package org.bonitasoft.engine.api.impl.livingapplication; import org.bonitasoft.engine.api.impl.converter.ApplicationModelConverter; -import org.bonitasoft.engine.business.application.Application; -import org.bonitasoft.engine.business.application.ApplicationCreator; -import org.bonitasoft.engine.business.application.ApplicationField; -import org.bonitasoft.engine.business.application.ApplicationNotFoundException; -import org.bonitasoft.engine.business.application.ApplicationService; -import org.bonitasoft.engine.business.application.ApplicationUpdater; -import org.bonitasoft.engine.business.application.Icon; +import org.bonitasoft.engine.business.application.*; import org.bonitasoft.engine.business.application.impl.IconImpl; import org.bonitasoft.engine.business.application.importer.validator.ApplicationTokenValidator; import org.bonitasoft.engine.business.application.importer.validator.ValidationStatus; @@ -30,16 +24,11 @@ import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.commons.exceptions.SObjectAlreadyExistsException; import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; -import org.bonitasoft.engine.exception.UpdateException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.search.AbstractSearchEntity; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * @author Elias Ricken de Medeiros @@ -51,7 +40,7 @@ public class LivingApplicationAPIDelegate { private final ApplicationService applicationService; private final ApplicationTokenValidator tokenValidator; - public LivingApplicationAPIDelegate(final TenantServiceAccessor accessor, final ApplicationModelConverter converter, + public LivingApplicationAPIDelegate(final ServiceAccessor accessor, final ApplicationModelConverter converter, final long loggedUserId, final ApplicationTokenValidator tokenValidator) { this.tokenValidator = tokenValidator; applicationService = accessor.getApplicationService(); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegate.java index 1910c7aa01a..dd62b85e87a 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegate.java @@ -17,25 +17,16 @@ import org.bonitasoft.engine.api.impl.converter.ApplicationMenuModelConverter; import org.bonitasoft.engine.api.impl.transaction.application.SearchApplicationMenus; -import org.bonitasoft.engine.business.application.ApplicationMenu; -import org.bonitasoft.engine.business.application.ApplicationMenuCreator; -import org.bonitasoft.engine.business.application.ApplicationMenuNotFoundException; -import org.bonitasoft.engine.business.application.ApplicationMenuUpdater; -import org.bonitasoft.engine.business.application.ApplicationService; +import org.bonitasoft.engine.business.application.*; import org.bonitasoft.engine.business.application.importer.validator.ApplicationMenuCreatorValidator; import org.bonitasoft.engine.business.application.model.SApplicationMenu; import org.bonitasoft.engine.business.application.model.builder.SApplicationUpdateBuilder; import org.bonitasoft.engine.commons.exceptions.SBonitaException; -import org.bonitasoft.engine.commons.exceptions.SObjectModificationException; import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; -import org.bonitasoft.engine.exception.UpdateException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * @author Elias Ricken de Medeiros @@ -47,7 +38,7 @@ public class LivingApplicationMenuAPIDelegate { private final ApplicationMenuCreatorValidator creatorValidator; private final long loggedUserId; - public LivingApplicationMenuAPIDelegate(final TenantServiceAccessor accessor, + public LivingApplicationMenuAPIDelegate(final ServiceAccessor accessor, final ApplicationMenuModelConverter converter, final ApplicationMenuCreatorValidator creatorValidator, final long loggedUserId) { this.creatorValidator = creatorValidator; @@ -85,8 +76,6 @@ public ApplicationMenu updateApplicationMenu(final long applicationMenuId, final applicationService.updateApplication(sApplicationMenu.getApplicationId(), new SApplicationUpdateBuilder(loggedUserId).done()); return converter.toApplicationMenu(sApplicationMenu); - } catch (final SObjectModificationException e) { - throw new UpdateException(e); } catch (final SObjectNotFoundException e) { throw new ApplicationMenuNotFoundException(e.getMessage()); } catch (final SBonitaException e) { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegate.java index abc2f019775..83eb2c5ce3b 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegate.java @@ -27,17 +27,11 @@ import org.bonitasoft.engine.business.application.model.builder.SApplicationUpdateBuilder; import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.commons.exceptions.SObjectAlreadyExistsException; -import org.bonitasoft.engine.commons.exceptions.SObjectCreationException; import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; -import org.bonitasoft.engine.exception.UpdateException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * @author Elias Ricken de Medeiros @@ -49,7 +43,7 @@ public class LivingApplicationPageAPIDelegate { private final long loggedUserId; private final ApplicationTokenValidator tokenValidator; - public LivingApplicationPageAPIDelegate(final TenantServiceAccessor accessor, + public LivingApplicationPageAPIDelegate(final ServiceAccessor accessor, final ApplicationPageModelConverter converter, final long loggedUserId, final ApplicationTokenValidator tokenValidator) { this.tokenValidator = tokenValidator; @@ -72,8 +66,7 @@ public void setApplicationHomePage(final long applicationId, final long applicat } public ApplicationPage createApplicationPage(final long applicationId, final long pageId, final String token) - throws AlreadyExistsException, - CreationException { + throws CreationException { validateToken(token); final SApplicationPage.SApplicationPageBuilder pageBuilder = SApplicationPage.builder() .applicationId(applicationId).pageId(pageId).token(token); @@ -84,8 +77,6 @@ public ApplicationPage createApplicationPage(final long applicationId, final lon new SApplicationUpdateBuilder(loggedUserId) .done()); return converter.toApplicationPage(sAppPage); - } catch (final SObjectCreationException e) { - throw new CreationException(e); } catch (final SObjectAlreadyExistsException e) { throw new AlreadyExistsException(e.getMessage()); } catch (final SBonitaException e) { @@ -127,8 +118,8 @@ public ApplicationPage getApplicationPage(final long applicationPageId) throws A public void deleteApplicationPage(final long applicationPageId) throws DeletionException { try { final SApplicationPage deletedApplicationPage = applicationService.deleteApplicationPage(applicationPageId); - final SApplicationUpdateBuilder appBbuilder = new SApplicationUpdateBuilder(loggedUserId); - applicationService.updateApplication(deletedApplicationPage.getApplicationId(), appBbuilder.done()); + final SApplicationUpdateBuilder appBuilder = new SApplicationUpdateBuilder(loggedUserId); + applicationService.updateApplication(deletedApplicationPage.getApplicationId(), appBuilder.done()); } catch (final SObjectNotFoundException sonfe) { throw new DeletionException(new ApplicationPageNotFoundException(sonfe.getMessage())); } catch (final SBonitaException e) { @@ -137,9 +128,8 @@ public void deleteApplicationPage(final long applicationPageId) throws DeletionE } public ApplicationPage getApplicationHomePage(final long applicationId) throws ApplicationPageNotFoundException { - SApplicationPage sHomePage; try { - sHomePage = applicationService.getApplicationHomePage(applicationId); + SApplicationPage sHomePage = applicationService.getApplicationHomePage(applicationId); return converter.toApplicationPage(sHomePage); } catch (final SBonitaReadException e) { throw new RetrieveException(e); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/organization/OrganizationAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/organization/OrganizationAPIDelegate.java index 62e69f906d5..79c55fb848b 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/organization/OrganizationAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/organization/OrganizationAPIDelegate.java @@ -22,7 +22,7 @@ import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.identity.*; import org.bonitasoft.engine.identity.model.builder.SCustomUserInfoValueUpdateBuilderFactory; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Emmanuel Duchastenier @@ -38,7 +38,7 @@ private OrganizationAPIDelegate(IdentityService identityService) { public static OrganizationAPIDelegate getInstance() { if (organizationAPIDelegate == null) { - organizationAPIDelegate = new OrganizationAPIDelegate(TenantServiceSingleton.getInstance() + organizationAPIDelegate = new OrganizationAPIDelegate(ServiceAccessorSingleton.getInstance() .getIdentityService()); } return organizationAPIDelegate; diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegate.java index 39b772a6bfe..691ada75a12 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegate.java @@ -14,8 +14,13 @@ package org.bonitasoft.engine.api.impl.page; import java.io.Serializable; -import java.util.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.bonitasoft.engine.api.impl.converter.PageModelConverter; @@ -28,17 +33,49 @@ import org.bonitasoft.engine.commons.exceptions.SObjectNotFoundException; import org.bonitasoft.engine.core.form.FormMappingService; import org.bonitasoft.engine.core.form.SFormMapping; -import org.bonitasoft.engine.exception.*; +import org.bonitasoft.engine.exception.AlreadyExistsException; +import org.bonitasoft.engine.exception.CreationException; +import org.bonitasoft.engine.exception.DeletionException; +import org.bonitasoft.engine.exception.InvalidPageTokenException; +import org.bonitasoft.engine.exception.InvalidPageZipContentException; +import org.bonitasoft.engine.exception.InvalidPageZipInconsistentException; +import org.bonitasoft.engine.exception.InvalidPageZipMissingAPropertyException; +import org.bonitasoft.engine.exception.InvalidPageZipMissingIndexException; +import org.bonitasoft.engine.exception.InvalidPageZipMissingPropertiesException; +import org.bonitasoft.engine.exception.RetrieveException; +import org.bonitasoft.engine.exception.SearchException; +import org.bonitasoft.engine.exception.UpdateException; +import org.bonitasoft.engine.exception.UpdatingWithInvalidPageTokenException; +import org.bonitasoft.engine.exception.UpdatingWithInvalidPageZipContentException; import org.bonitasoft.engine.form.FormMappingSearchDescriptor; -import org.bonitasoft.engine.page.*; +import org.bonitasoft.engine.page.Page; +import org.bonitasoft.engine.page.PageCreator; +import org.bonitasoft.engine.page.PageMappingService; +import org.bonitasoft.engine.page.PageNotFoundException; import org.bonitasoft.engine.page.PageNotFoundException.PageAttribute; -import org.bonitasoft.engine.persistence.*; +import org.bonitasoft.engine.page.PageService; +import org.bonitasoft.engine.page.PageUpdater; +import org.bonitasoft.engine.page.SInvalidPageTokenException; +import org.bonitasoft.engine.page.SInvalidPageZipException; +import org.bonitasoft.engine.page.SInvalidPageZipInconsistentException; +import org.bonitasoft.engine.page.SInvalidPageZipMissingAPropertyException; +import org.bonitasoft.engine.page.SInvalidPageZipMissingIndexException; +import org.bonitasoft.engine.page.SInvalidPageZipMissingPropertiesException; +import org.bonitasoft.engine.page.SPage; +import org.bonitasoft.engine.page.SPageMapping; +import org.bonitasoft.engine.page.SPageUpdateBuilder; +import org.bonitasoft.engine.page.SPageUpdateBuilderFactory; +import org.bonitasoft.engine.persistence.FilterOption; +import org.bonitasoft.engine.persistence.OrderByOption; +import org.bonitasoft.engine.persistence.OrderByType; +import org.bonitasoft.engine.persistence.QueryOptions; +import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchResult; import org.bonitasoft.engine.search.descriptor.SearchEntitiesDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Emmanuel Duchastenier @@ -50,16 +87,16 @@ public class PageAPIDelegate { private final PageService pageService; private final SearchEntitiesDescriptor searchEntitiesDescriptor; - private final TenantServiceAccessor tenantAccessor; + private final ServiceAccessor serviceAccessor; private final PageMappingService pageMappingService; private final FormMappingService formMappingService; private final BusinessArchiveArtifactsManager businessArchiveArtifactsManager; - private PageAPIDelegate(TenantServiceAccessor serviceAccessor, + private PageAPIDelegate(ServiceAccessor serviceAccessor, BusinessArchiveArtifactsManager businessArchiveArtifactsManager, PageService pageService, PageMappingService pageMappingService, FormMappingService formMappingService, SearchEntitiesDescriptor searchEntitiesDescriptor) { - this.tenantAccessor = serviceAccessor; + this.serviceAccessor = serviceAccessor; this.businessArchiveArtifactsManager = businessArchiveArtifactsManager; this.pageService = pageService; this.pageMappingService = pageMappingService; @@ -69,13 +106,13 @@ private PageAPIDelegate(TenantServiceAccessor serviceAccessor, public static PageAPIDelegate getInstance() { if (pageAPIDelegate == null) { - TenantServiceAccessor tenantAccessor = TenantServiceSingleton.getInstance(); - pageAPIDelegate = new PageAPIDelegate(tenantAccessor, - tenantAccessor.getBusinessArchiveArtifactsManager(), - tenantAccessor.getPageService(), - tenantAccessor.getPageMappingService(), - tenantAccessor.getFormMappingService(), - tenantAccessor.getSearchEntitiesDescriptor()); + ServiceAccessor serviceAccessor = ServiceAccessorSingleton.getInstance(); + pageAPIDelegate = new PageAPIDelegate(serviceAccessor, + serviceAccessor.getBusinessArchiveArtifactsManager(), + serviceAccessor.getPageService(), + serviceAccessor.getPageMappingService(), + serviceAccessor.getFormMappingService(), + serviceAccessor.getSearchEntitiesDescriptor()); } return pageAPIDelegate; } @@ -186,7 +223,7 @@ Set updatePageMappings(long pageId) } private void updateProcessResolution(Long processDefinitionId) { - businessArchiveArtifactsManager.resolveDependencies(processDefinitionId, tenantAccessor); + businessArchiveArtifactsManager.resolveDependencies(processDefinitionId, serviceAccessor); } public void deletePages(final List pageIds) throws DeletionException { @@ -208,8 +245,7 @@ public Page getPageByName(final String name) throws PageNotFoundException { } public Page updatePage(final long pageId, final PageUpdater pageUpdater, long userIdFromSession) - throws UpdateException, AlreadyExistsException, - UpdatingWithInvalidPageTokenException, UpdatingWithInvalidPageZipContentException { + throws UpdateException, AlreadyExistsException { if (pageUpdater == null || pageUpdater.getFields().isEmpty()) { throw new UpdateException("The pageUpdater descriptor does not contain field updates"); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIDelegate.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIDelegate.java index 6cdaca12697..095f67a950e 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIDelegate.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIDelegate.java @@ -27,22 +27,12 @@ import org.bonitasoft.engine.command.SUserMembershipProfileMemberAlreadyExistsException; import org.bonitasoft.engine.command.SUserProfileMemberAlreadyExistsException; import org.bonitasoft.engine.commons.exceptions.SBonitaException; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.CreationException; -import org.bonitasoft.engine.exception.DeletionException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.SearchException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.identity.IdentityService; import org.bonitasoft.engine.identity.MemberType; import org.bonitasoft.engine.persistence.OrderByType; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.profile.Profile; -import org.bonitasoft.engine.profile.ProfileCriterion; -import org.bonitasoft.engine.profile.ProfileMember; -import org.bonitasoft.engine.profile.ProfileMemberNotFoundException; -import org.bonitasoft.engine.profile.ProfileMemberSearchDescriptor; -import org.bonitasoft.engine.profile.ProfileNotFoundException; -import org.bonitasoft.engine.profile.ProfileService; +import org.bonitasoft.engine.profile.*; import org.bonitasoft.engine.profile.exception.profile.SProfileNotFoundException; import org.bonitasoft.engine.profile.exception.profilemember.SProfileMemberNotFoundException; import org.bonitasoft.engine.profile.model.SProfileMember; @@ -54,8 +44,8 @@ import org.bonitasoft.engine.search.profile.SearchProfileMembersForProfile; import org.bonitasoft.engine.search.profile.SearchProfiles; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.session.SessionService; public class ProfileAPIDelegate { @@ -78,17 +68,17 @@ protected ProfileAPIDelegate(ProfileService profileService, IdentityService iden this.applicationService = applicationService; } - public static TenantServiceAccessor getTenantAccessor() { - return TenantServiceSingleton.getInstance(); + public static ServiceAccessor getServiceAccessor() { + return ServiceAccessorSingleton.getInstance(); } public static ProfileAPIDelegate getInstance() { if (profileAPIDelegate == null) { - TenantServiceAccessor tenantAccessor = getTenantAccessor(); - profileAPIDelegate = new ProfileAPIDelegate(tenantAccessor.getProfileService(), - tenantAccessor.getIdentityService(), - tenantAccessor.getSearchEntitiesDescriptor(), - tenantAccessor.getApplicationService()); + ServiceAccessor serviceAccessor = getServiceAccessor(); + profileAPIDelegate = new ProfileAPIDelegate(serviceAccessor.getProfileService(), + serviceAccessor.getIdentityService(), + serviceAccessor.getSearchEntitiesDescriptor(), + serviceAccessor.getApplicationService()); } return profileAPIDelegate; } @@ -165,8 +155,7 @@ public SearchResult searchProfileMembers(final String memberType, } public ProfileMember createProfileMember(final Long profileId, final Long userId, final Long groupId, - final Long roleId) throws CreationException, AlreadyExistsException { - + final Long roleId) throws CreationException { try { final MemberType memberType = getMemberType(userId, groupId, roleId); final CreateProfileMember createProfileMember = new CreateProfileMember(profileService, identityService, diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/resolver/BusinessArchiveArtifactsManager.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/resolver/BusinessArchiveArtifactsManager.java index f7c6e0f1eea..454e1700ff4 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/resolver/BusinessArchiveArtifactsManager.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/resolver/BusinessArchiveArtifactsManager.java @@ -34,7 +34,7 @@ import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.recorder.SRecorderException; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * Handles the resolution of Process Dependencies. A process can have a list of ProcessDependencyResolvers @@ -74,20 +74,19 @@ public boolean resolveDependencies(final BusinessArchive businessArchive, final return resolved; } - public void resolveDependenciesForAllProcesses(TenantServiceAccessor tenantAccessor) { + public void resolveDependenciesForAllProcesses(ServiceAccessor serviceAccessor) { try { - List processDefinitionIds = tenantAccessor.getProcessDefinitionService().getProcessDefinitionIds(0, + List processDefinitionIds = serviceAccessor.getProcessDefinitionService().getProcessDefinitionIds(0, Integer.MAX_VALUE); - resolveDependencies(processDefinitionIds, tenantAccessor); + resolveDependencies(processDefinitionIds, serviceAccessor); } catch (SBonitaReadException e) { log.error("Unable to retrieve tenant process definitions, dependency resolution aborted"); } } - private void resolveDependencies(final List processDefinitionIds, - final TenantServiceAccessor tenantAccessor) { + private void resolveDependencies(final List processDefinitionIds, final ServiceAccessor serviceAccessor) { for (Long id : processDefinitionIds) { - resolveDependencies(id, tenantAccessor); + resolveDependencies(id, serviceAccessor); } } @@ -105,14 +104,14 @@ public void deleteDependencies(final SProcessDefinition processDefinition) * modification * this does not throw exception, it only log because it can be retried after. */ - public void resolveDependencies(final long processDefinitionId, final TenantServiceAccessor tenantAccessor) { - resolveDependencies(processDefinitionId, tenantAccessor, - getArtifactManagers().toArray(new BusinessArchiveArtifactManager[getArtifactManagers().size()])); + public void resolveDependencies(final long processDefinitionId, final ServiceAccessor serviceAccessor) { + resolveDependencies(processDefinitionId, serviceAccessor, + getArtifactManagers().toArray(new BusinessArchiveArtifactManager[0])); } - public void resolveDependencies(final long processDefinitionId, final TenantServiceAccessor tenantAccessor, + public void resolveDependencies(final long processDefinitionId, final ServiceAccessor serviceAccessor, final BusinessArchiveArtifactManager... resolvers) { - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); try { boolean resolved = true; for (final BusinessArchiveArtifactManager dependencyResolver : resolvers) { @@ -122,7 +121,6 @@ public void resolveDependencies(final long processDefinitionId, final TenantServ } changeResolutionStatus(processDefinitionId, processDefinitionService, resolved); } catch (final SBonitaException e) { - final Class clazz = BusinessArchiveArtifactsManager.class; if (log.isDebugEnabled()) { log.debug(e.toString()); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/command/Command.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/command/Command.java index f696e74c371..148c1442702 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/command/Command.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/command/Command.java @@ -42,8 +42,7 @@ public interface Command { * a map of parameters that can be used by the command and that is given by the client when executing the * command * @param serviceAccessor - * the TenantServiceAccessor or PlatformServiceAccessor that provides access to the engine's server-side - * services + * the ServiceAccessor that provides access to the engine's server-side services * @return * a result that will be returned to the client * @throws SCommandParameterizationException diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/connector/ConnectorAPIAccessorImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/connector/ConnectorAPIAccessorImpl.java index 78baf2a75af..25cc9634fba 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/connector/ConnectorAPIAccessorImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/connector/ConnectorAPIAccessorImpl.java @@ -21,8 +21,8 @@ import org.bonitasoft.engine.api.internal.ServerAPI; import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.service.ModelConvertor; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.engine.session.SessionService; import org.bonitasoft.engine.session.model.SSession; @@ -47,9 +47,9 @@ public ConnectorAPIAccessorImpl(final long tenantId) { protected APISession getAPISession() { if (apiSession == null) { - final TenantServiceAccessor tenantServiceAccessor = TenantServiceSingleton.getInstance(); - final SessionAccessor sessionAccessor = tenantServiceAccessor.getSessionAccessor(); - final SessionService sessionService = tenantServiceAccessor.getSessionService(); + final ServiceAccessor serviceAccessor = ServiceAccessorSingleton.getInstance(); + final SessionAccessor sessionAccessor = serviceAccessor.getSessionAccessor(); + final SessionService sessionService = serviceAccessor.getSessionService(); try { final SSession session = sessionService.createSession(tenantId, ConnectorAPIAccessorImpl.class.getSimpleName());// FIXME get the diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/handler/ArchiveProcessInstancesHandler.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/handler/ArchiveProcessInstancesHandler.java index c6ae8338893..b858909d9a3 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/handler/ArchiveProcessInstancesHandler.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/handler/ArchiveProcessInstancesHandler.java @@ -49,8 +49,7 @@ public void execute(final SUpdateEvent event) throws SHandlerExecutionException } /** - * @return tenantServiceAccessor - * @throws SHandlerExecutionException + * @return ServiceAccessor */ private ServiceAccessor getServiceAccessor() throws SHandlerExecutionException { try { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivity.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivity.java index 67200d8261c..a8d53e88f95 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivity.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivity.java @@ -39,7 +39,7 @@ import org.bonitasoft.engine.data.instance.api.DataInstanceContainer; import org.bonitasoft.engine.execution.WaitingEventsInterrupter; import org.bonitasoft.engine.execution.event.EventsHandler; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.STransactionException; import org.bonitasoft.engine.work.WorkDescriptor; import org.bonitasoft.engine.work.WorkService; @@ -77,24 +77,24 @@ protected void evaluateOutput(final Map context, final Connector @Override protected void continueFlow(final Map context) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final FlowNodeInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); - final WorkService workService = tenantAccessor.getWorkService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final FlowNodeInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); + final WorkService workService = serviceAccessor.getWorkService(); final SFlowNodeInstance sFlowNodeInstance = activityInstanceService.getFlowNodeInstance(flowNodeInstanceId); - final WorkDescriptor executeFlowNodeWork = tenantAccessor.getBPMWorkFactory() + final WorkDescriptor executeFlowNodeWork = serviceAccessor.getBPMWorkFactory() .createExecuteFlowNodeWorkDescriptor(sFlowNodeInstance); workService.registerWork(executeFlowNodeWork); } @Override protected void setContainerInFail(final Map context) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); WaitingEventsInterrupter waitingEventsInterrupter = new WaitingEventsInterrupter( - tenantAccessor.getEventInstanceService(), - tenantAccessor.getSchedulerService()); + serviceAccessor.getEventInstanceService(), + serviceAccessor.getSchedulerService()); FailedStateSetter failedStateSetter = new FailedStateSetter(waitingEventsInterrupter, - tenantAccessor.getActivityInstanceService(), - tenantAccessor.getFlowNodeStateManager()); + serviceAccessor.getActivityInstanceService(), + serviceAccessor.getFlowNodeStateManager()); failedStateSetter.setAsFailed(flowNodeInstanceId); } @@ -102,9 +102,9 @@ protected void setContainerInFail(final Map context) throws SBon protected SThrowEventInstance createThrowErrorEventInstance(final Map context, final SEndEventDefinition eventDefinition) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final EventInstanceService eventInstanceService = tenantAccessor.getEventInstanceService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final EventInstanceService eventInstanceService = serviceAccessor.getEventInstanceService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final SFlowNodeInstance sFlowNodeInstance = activityInstanceService.getFlowNodeInstance(flowNodeInstanceId); final SEndEventInstanceBuilder builder = BuilderFactory.get(SEndEventInstanceBuilderFactory.class) @@ -123,10 +123,10 @@ protected void errorEventOnFail(final Map context, final SConnec final Throwable exception) throws SBonitaException { setConnectorAndContainerToFailed(context, exception); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final EventsHandler eventsHandler = tenantAccessor.getEventsHandler(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final EventsHandler eventsHandler = serviceAccessor.getEventsHandler(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final SFlowNodeInstance sFlowNodeInstance = activityInstanceService.getFlowNodeInstance(flowNodeInstanceId); @@ -146,7 +146,7 @@ protected void errorEventOnFail(final Map context, final SConnec eventsHandler.getHandler(SEventTriggerType.ERROR).handlePostThrowEvent(sProcessDefinition, eventDefinition, throwEventInstance, errorEventTriggerDefinition, sFlowNodeInstance); - tenantAccessor.getBPMArchiverService().archiveAndDeleteFlowNodeInstance(throwEventInstance, + serviceAccessor.getBPMArchiverService().archiveAndDeleteFlowNodeInstance(throwEventInstance, sProcessDefinition.getId()); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfProcess.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfProcess.java index 96d80618cce..34307b650e7 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfProcess.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfProcess.java @@ -42,14 +42,10 @@ import org.bonitasoft.engine.core.process.instance.model.SStateCategory; import org.bonitasoft.engine.core.process.instance.model.event.SThrowEventInstance; import org.bonitasoft.engine.data.instance.api.DataInstanceContainer; -import org.bonitasoft.engine.execution.Filter; -import org.bonitasoft.engine.execution.FlowNodeIdFilter; -import org.bonitasoft.engine.execution.FlowNodeSelector; -import org.bonitasoft.engine.execution.ProcessExecutor; -import org.bonitasoft.engine.execution.StartFlowNodeFilter; +import org.bonitasoft.engine.execution.*; import org.bonitasoft.engine.execution.event.EventsHandler; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * @author Baptiste Mesta @@ -94,10 +90,10 @@ protected void evaluateOutput(final Map context, final Connector @Override protected void continueFlow(final Map context) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final ProcessExecutor processExecutor = tenantAccessor.getProcessExecutor(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final ProcessExecutor processExecutor = serviceAccessor.getProcessExecutor(); final SProcessDefinition sProcessDefinition = processDefinitionService .getProcessDefinition(processDefinitionId); @@ -119,7 +115,7 @@ protected void continueFlow(final Map context) throws SBonitaExc @Override protected void setContainerInFail(final Map context) throws SBonitaException { - final ProcessInstanceService processInstanceService = getTenantAccessor(context).getProcessInstanceService(); + final ProcessInstanceService processInstanceService = getServiceAccessor(context).getProcessInstanceService(); final SProcessInstance intTxProcessInstance = processInstanceService.getProcessInstance(processInstanceId); processInstanceService.setState(intTxProcessInstance, ProcessInstanceState.ERROR); } @@ -128,7 +124,7 @@ protected void setContainerInFail(final Map context) throws SBon protected SThrowEventInstance createThrowErrorEventInstance(final Map context, final SEndEventDefinition eventDefinition) throws SBonitaException { - final BPMInstancesCreator bpmInstancesCreator = getTenantAccessor(context).getBPMInstancesCreator(); + final BPMInstancesCreator bpmInstancesCreator = getServiceAccessor(context).getBPMInstancesCreator(); final SFlowNodeInstance createFlowNodeInstance = bpmInstancesCreator.createFlowNodeInstance(processDefinitionId, rootProcessInstanceId, processInstanceId, SFlowElementsContainerType.PROCESS, eventDefinition, rootProcessInstanceId, @@ -141,9 +137,9 @@ protected SThrowEventInstance createThrowErrorEventInstance(final Map context, final SConnectorDefinition sConnectorDefinition, final Throwable exception) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final EventsHandler eventsHandler = tenantAccessor.getEventsHandler(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final EventsHandler eventsHandler = serviceAccessor.getEventsHandler(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); setConnectorOnlyToFailed(context, exception); // create a fake definition @@ -164,7 +160,7 @@ protected void errorEventOnFail(final Map context, final SConnec sProcessDefinition, eventDefinition, throwEventInstance, errorEventTriggerDefinition, throwEventInstance); - tenantAccessor.getBPMArchiverService().archiveAndDeleteFlowNodeInstance(throwEventInstance, + serviceAccessor.getBPMArchiverService().archiveAndDeleteFlowNodeInstance(throwEventInstance, sProcessDefinition.getId()); if (!hasActionToExecute) { setConnectorAndContainerToFailed(context, exception); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWork.java index 63055c57f63..ddf8f307549 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWork.java @@ -39,7 +39,7 @@ import org.bonitasoft.engine.core.process.instance.model.event.SThrowEventInstance; import org.bonitasoft.engine.dependency.model.ScopeType; import org.bonitasoft.engine.lock.BonitaLock; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.tracking.TimeTracker; import org.bonitasoft.engine.tracking.TimeTrackerRecords; import org.bonitasoft.engine.transaction.UserTransactionService; @@ -98,7 +98,7 @@ protected abstract void evaluateOutput(Map context, final Connec throws SBonitaException; protected ClassLoader getClassLoader(final Map context) throws SBonitaException { - return getTenantAccessor(context).getClassLoaderService().getClassLoader( + return getServiceAccessor(context).getClassLoaderService().getClassLoader( identifier(ScopeType.PROCESS, processDefinitionId)); } @@ -110,7 +110,7 @@ protected void setConnectorAndContainerToFailed(final Map contex protected void setConnectorOnlyToFailed(final Map context, final Throwable t) throws SBonitaException { - final ConnectorInstanceService connectorInstanceService = getTenantAccessor(context) + final ConnectorInstanceService connectorInstanceService = getServiceAccessor(context) .getConnectorInstanceService(); final SConnectorInstanceWithFailureInfo connectorInstanceWithFailure = connectorInstanceService .getConnectorInstanceWithFailureInfo(connectorInstanceId); @@ -119,11 +119,11 @@ protected void setConnectorOnlyToFailed(final Map context, final } protected void evaluateOutput(final Map context, final ConnectorResult result, - final SConnectorDefinition sConnectorDefinition, - final Long id, final String containerType) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final ConnectorInstanceService connectorInstanceService = tenantAccessor.getConnectorInstanceService(); - final ConnectorService connectorService = tenantAccessor.getConnectorService(); + final SConnectorDefinition sConnectorDefinition, final Long id, final String containerType) + throws SBonitaException { + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final ConnectorInstanceService connectorInstanceService = serviceAccessor.getConnectorInstanceService(); + final ConnectorService connectorService = serviceAccessor.getConnectorService(); final List outputs = sConnectorDefinition.getOutputs(); final SExpressionContext sExpressionContext = new SExpressionContext(id, containerType, processDefinitionId); @@ -135,12 +135,12 @@ protected void evaluateOutput(final Map context, final Connector @Override public CompletableFuture work(final Map context) throws Exception { final long startTime = System.currentTimeMillis(); - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final ConnectorService connectorService = tenantAccessor.getConnectorService(); - final ConnectorInstanceService connectorInstanceService = tenantAccessor.getConnectorInstanceService(); - final UserTransactionService userTransactionService = tenantAccessor.getUserTransactionService(); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); - final TimeTracker timeTracker = tenantAccessor.getTimeTracker(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final ConnectorService connectorService = serviceAccessor.getConnectorService(); + final ConnectorInstanceService connectorInstanceService = serviceAccessor.getConnectorInstanceService(); + final UserTransactionService userTransactionService = serviceAccessor.getUserTransactionService(); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); + final TimeTracker timeTracker = serviceAccessor.getTimeTracker(); final ClassLoader processClassloader = getClassLoader(context); final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { @@ -157,7 +157,7 @@ public CompletableFuture work(final Map context) throws Ex connectorImplementationDescriptor, processClassloader, callable.getInputParameters()).thenAccept(r -> { try { - executeOutputOperationsAndContinue(context, tenantAccessor, userTransactionService, + executeOutputOperationsAndContinue(context, serviceAccessor, userTransactionService, sConnectorDefinition, r); } catch (Exception e) { throw new CompletionException( @@ -184,11 +184,11 @@ public CompletableFuture work(final Map context) throws Ex } } - private void executeOutputOperationsAndContinue(Map context, TenantServiceAccessor tenantAccessor, + private void executeOutputOperationsAndContinue(Map context, ServiceAccessor serviceAccessor, UserTransactionService userTransactionService, SConnectorDefinition sConnectorDefinition, ConnectorResult r) throws Exception { // evaluate output and trigger the execution of the flow node - BonitaLock lock = tenantAccessor.getLockService().lock(processInstanceId, + BonitaLock lock = serviceAccessor.getLockService().lock(processInstanceId, SFlowElementsContainerType.PROCESS.name(), getTenantId()); try { userTransactionService.executeInTransaction(() -> { @@ -197,14 +197,14 @@ private void executeOutputOperationsAndContinue(Map context, Ten return null; }); } finally { - tenantAccessor.getLockService().unlock(lock, getTenantId()); + serviceAccessor.getLockService().unlock(lock, getTenantId()); } } @Override public void handleFailure(final Throwable e, final Map context) throws Exception { - final UserTransactionService userTransactionService = getTenantAccessor(context).getUserTransactionService(); - final ProcessDefinitionService processDefinitionService = getTenantAccessor(context) + final UserTransactionService userTransactionService = getServiceAccessor(context).getUserTransactionService(); + final ProcessDefinitionService processDefinitionService = getServiceAccessor(context) .getProcessDefinitionService(); final HandleConnectorOnFailEventTxContent callable = new HandleConnectorOnFailEventTxContent(e, diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWork.java index bf6a4490286..e21e5e70218 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWork.java @@ -20,7 +20,7 @@ import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeReadException; import org.bonitasoft.engine.core.process.instance.model.SFlowNodeInstance; import org.bonitasoft.engine.execution.WaitingEventsInterrupter; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.bonitasoft.engine.work.SWorkPreconditionException; @@ -57,18 +57,17 @@ public String getDescription() { @Override public CompletableFuture work(final Map context) throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - - SFlowNodeInstance flowNodeInstance = retrieveAndVerifyFlowNodeInstance(tenantAccessor); - tenantAccessor.getFlowNodeExecutor().executeFlowNode(flowNodeInstance, null, null); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + SFlowNodeInstance flowNodeInstance = retrieveAndVerifyFlowNodeInstance(serviceAccessor); + serviceAccessor.getFlowNodeExecutor().executeFlowNode(flowNodeInstance, null, null); return CompletableFuture.completedFuture(null); } - private SFlowNodeInstance retrieveAndVerifyFlowNodeInstance(TenantServiceAccessor tenantAccessor) + private SFlowNodeInstance retrieveAndVerifyFlowNodeInstance(ServiceAccessor serviceAccessor) throws SFlowNodeReadException, SWorkPreconditionException { SFlowNodeInstance flowNodeInstance; try { - flowNodeInstance = tenantAccessor.getActivityInstanceService().getFlowNodeInstance(flowNodeInstanceId); + flowNodeInstance = serviceAccessor.getActivityInstanceService().getFlowNodeInstance(flowNodeInstanceId); } catch (SFlowNodeNotFoundException e) { throw new SWorkPreconditionException(String.format("Flow node %d does not exists", flowNodeInstanceId), e); } @@ -91,14 +90,14 @@ private SFlowNodeInstance retrieveAndVerifyFlowNodeInstance(TenantServiceAccesso @Override public void handleFailure(final Throwable e, final Map context) throws Exception { - TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final UserTransactionService userTransactionService = tenantAccessor.getUserTransactionService(); + ServiceAccessor serviceAccessor = getServiceAccessor(context); + final UserTransactionService userTransactionService = serviceAccessor.getUserTransactionService(); WaitingEventsInterrupter waitingEventsInterrupter = new WaitingEventsInterrupter( - tenantAccessor.getEventInstanceService(), - tenantAccessor.getSchedulerService()); + serviceAccessor.getEventInstanceService(), + serviceAccessor.getSchedulerService()); FailedStateSetter failedStateSetter = new FailedStateSetter(waitingEventsInterrupter, - tenantAccessor.getActivityInstanceService(), - tenantAccessor.getFlowNodeStateManager()); + serviceAccessor.getActivityInstanceService(), + serviceAccessor.getFlowNodeStateManager()); userTransactionService.executeInTransaction(new SetInFailCallable(failedStateSetter, flowNodeInstanceId)); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWork.java index a2d32dd3768..f20291621d1 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWork.java @@ -27,7 +27,7 @@ import org.bonitasoft.engine.data.instance.api.DataInstanceContainer; import org.bonitasoft.engine.data.instance.api.DataInstanceService; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * @author Emmanuel Duchastenier @@ -70,13 +70,13 @@ public String getRecoveryProcedure() { @Override public CompletableFuture work(final Map context) throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final EventInstanceService eventInstanceService = tenantAccessor.getEventInstanceService(); - final DataInstanceService dataInstanceService = tenantAccessor.getDataInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final EventInstanceService eventInstanceService = serviceAccessor.getEventInstanceService(); + final DataInstanceService dataInstanceService = serviceAccessor.getDataInstanceService(); final SWaitingMessageEvent waitingMessage = eventInstanceService.getWaitingMessage(waitingMessageId); final SMessageInstance messageInstance = eventInstanceService.getMessageInstance(messageInstanceId); if (waitingMessage != null) { - tenantAccessor.getEventsHandler().triggerCatchEvent(waitingMessage, messageInstanceId); + serviceAccessor.getEventsHandler().triggerCatchEvent(waitingMessage, messageInstanceId); eventInstanceService.deleteMessageInstance(messageInstance); dataInstanceService.deleteLocalDataInstances(messageInstanceId, DataInstanceContainer.MESSAGE_INSTANCE.name(), true); @@ -86,9 +86,9 @@ public CompletableFuture work(final Map context) throws Ex @Override public void handleFailure(final Throwable e, final Map context) throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - tenantAccessor.getUserTransactionService().executeInTransaction(() -> { - resetWaitingMessage(waitingMessageId, tenantAccessor.getEventInstanceService()); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + serviceAccessor.getUserTransactionService().executeInTransaction(() -> { + resetWaitingMessage(waitingMessageId, serviceAccessor.getEventInstanceService()); return null; }); log.warn( diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/InSessionBonitaWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/InSessionBonitaWork.java index 4af05c1f0db..e083d4acde5 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/InSessionBonitaWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/InSessionBonitaWork.java @@ -16,8 +16,8 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; import org.bonitasoft.engine.work.BonitaWork; @@ -31,9 +31,9 @@ public InSessionBonitaWork(final BonitaWork work) { super(work); } - TenantServiceAccessor getTenantAccessor() { + ServiceAccessor getServiceAccessor() { try { - return TenantServiceSingleton.getInstance(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new RuntimeException(e); } @@ -41,9 +41,9 @@ TenantServiceAccessor getTenantAccessor() { @Override public CompletableFuture work(final Map context) throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(); - final SessionAccessor sessionAccessor = tenantAccessor.getSessionAccessor(); - context.put(TENANT_ACCESSOR, tenantAccessor); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + final SessionAccessor sessionAccessor = serviceAccessor.getSessionAccessor(); + context.put(SERVICE_ACCESSOR, serviceAccessor); try { sessionAccessor.setTenantId(getTenantId()); return getWrappedWork().work(context); @@ -54,8 +54,8 @@ public CompletableFuture work(final Map context) throws Ex @Override public void handleFailure(final Throwable e, final Map context) throws Exception { - TenantServiceAccessor tenantAccessor = getTenantAccessor(); - SessionAccessor sessionAccessor = tenantAccessor.getSessionAccessor(); + ServiceAccessor serviceAccessor = getServiceAccessor(); + SessionAccessor sessionAccessor = serviceAccessor.getSessionAccessor(); sessionAccessor.setTenantId(getTenantId()); try { getWrappedWork().handleFailure(e, context); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWork.java index abdfa472b45..5340d9f3c12 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWork.java @@ -50,7 +50,7 @@ public LockProcessInstanceWork(final BonitaWork wrappedWork, final long processI @Override public CompletableFuture work(final Map context) throws Exception { - final LockService lockService = getTenantAccessor(context).getLockService(); + final LockService lockService = getServiceAccessor(context).getLockService(); final String objectType = SFlowElementsContainerType.PROCESS.name(); BonitaLock lock = null; diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWork.java index c3d76e7763e..9cab121b515 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWork.java @@ -25,7 +25,7 @@ import org.bonitasoft.engine.dependency.model.ScopeType; import org.bonitasoft.engine.execution.ContainerRegistry; import org.bonitasoft.engine.execution.WaitingEventsInterrupter; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.bonitasoft.engine.work.SWorkPreconditionException; @@ -56,7 +56,7 @@ public class NotifyChildFinishedWork extends TenantAwareBonitaWork { } protected ClassLoader getClassLoader(final Map context) throws SBonitaException { - return getTenantAccessor(context).getClassLoaderService().getClassLoader( + return getServiceAccessor(context).getClassLoaderService().getClassLoader( identifier(ScopeType.PROCESS, processDefinitionId)); } @@ -66,9 +66,9 @@ public CompletableFuture work(final Map context) throws Ex final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(processClassloader); - TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - SFlowNodeInstance flowNodeInstance = retrieveAndVerifyFlowNodeInstance(tenantAccessor); - final ContainerRegistry containerRegistry = tenantAccessor.getContainerRegistry(); + ServiceAccessor serviceAccessor = getServiceAccessor(context); + SFlowNodeInstance flowNodeInstance = retrieveAndVerifyFlowNodeInstance(serviceAccessor); + final ContainerRegistry containerRegistry = serviceAccessor.getContainerRegistry(); containerRegistry.nodeReachedState(flowNodeInstance); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); @@ -76,11 +76,11 @@ public CompletableFuture work(final Map context) throws Ex return CompletableFuture.completedFuture(null); } - private SFlowNodeInstance retrieveAndVerifyFlowNodeInstance(TenantServiceAccessor tenantAccessor) + private SFlowNodeInstance retrieveAndVerifyFlowNodeInstance(ServiceAccessor serviceAccessor) throws SWorkPreconditionException, SFlowNodeReadException { SFlowNodeInstance flowNodeInstance; try { - flowNodeInstance = tenantAccessor.getActivityInstanceService().getFlowNodeInstance(flowNodeInstanceId); + flowNodeInstance = serviceAccessor.getActivityInstanceService().getFlowNodeInstance(flowNodeInstanceId); } catch (SFlowNodeNotFoundException e) { throw new SWorkPreconditionException( "Flow node " + flowNodeInstanceId + " is already completed ( not found )"); @@ -111,14 +111,14 @@ public String getDescription() { @Override public void handleFailure(final Throwable e, final Map context) throws Exception { - TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final UserTransactionService userTransactionService = tenantAccessor.getUserTransactionService(); + ServiceAccessor serviceAccessor = getServiceAccessor(context); + final UserTransactionService userTransactionService = serviceAccessor.getUserTransactionService(); WaitingEventsInterrupter waitingEventsInterrupter = new WaitingEventsInterrupter( - tenantAccessor.getEventInstanceService(), - tenantAccessor.getSchedulerService()); + serviceAccessor.getEventInstanceService(), + serviceAccessor.getSchedulerService()); FailedStateSetter failedStateSetter = new FailedStateSetter(waitingEventsInterrupter, - tenantAccessor.getActivityInstanceService(), - tenantAccessor.getFlowNodeStateManager()); + serviceAccessor.getActivityInstanceService(), + serviceAccessor.getFlowNodeStateManager()); userTransactionService.executeInTransaction(new SetInFailCallable(failedStateSetter, flowNodeInstanceId)); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TenantAwareBonitaWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TenantAwareBonitaWork.java index e6a4fb862bf..a6458be3a75 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TenantAwareBonitaWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TenantAwareBonitaWork.java @@ -15,7 +15,7 @@ import java.util.Map; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.work.BonitaWork; /** @@ -23,14 +23,14 @@ */ public abstract class TenantAwareBonitaWork extends BonitaWork { - public static final String TENANT_ACCESSOR = "tenantAccessor"; + public static final String SERVICE_ACCESSOR = "serviceAccessor"; public TenantAwareBonitaWork() { super(); } - protected TenantServiceAccessor getTenantAccessor(final Map context) { - return (TenantServiceAccessor) context.get(TenantAwareBonitaWork.TENANT_ACCESSOR); + protected ServiceAccessor getServiceAccessor(final Map context) { + return (ServiceAccessor) context.get(TenantAwareBonitaWork.SERVICE_ACCESSOR); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TxBonitaWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TxBonitaWork.java index 7d3eca7785a..c8ce1243756 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TxBonitaWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/TxBonitaWork.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.bonitasoft.engine.work.BonitaWork; @@ -36,8 +36,8 @@ public TxBonitaWork(final BonitaWork wrappedWork) { @Override public CompletableFuture work(final Map context) throws Exception { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final UserTransactionService userTransactionService = tenantAccessor.getUserTransactionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final UserTransactionService userTransactionService = serviceAccessor.getUserTransactionService(); return userTransactionService.executeInTransaction(() -> getWrappedWork().work(context)); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWork.java index 785ff8ae790..4bc2668c1e6 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWork.java @@ -19,7 +19,7 @@ import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; import org.bonitasoft.engine.core.process.instance.model.SFlowNodeInstance; import org.bonitasoft.engine.execution.work.WrappingBonitaWork; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * Adding context information about Flow Node & Process definition and instance to exception for better logging @@ -48,8 +48,8 @@ public FlowNodeDefinitionAndInstanceContextWork(final WrappingBonitaWork wrapped @Override protected void setExceptionContext(final SBonitaException sBonitaException, final Map context) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final ActivityInstanceService activityInstanceService = tenantAccessor.getActivityInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final ActivityInstanceService activityInstanceService = serviceAccessor.getActivityInstanceService(); final SFlowNodeInstance flowNodeInstance = activityInstanceService.getFlowNodeInstance(flowNodeInstanceId); sBonitaException.setFlowNodeDefinitionIdOnContext(flowNodeInstance.getFlowNodeDefinitionId()); sBonitaException.setFlowNodeInstanceIdOnContext(flowNodeInstanceId); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWork.java index 252099c2728..e06d4eaf2d8 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWork.java @@ -18,7 +18,7 @@ import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.core.process.definition.ProcessDefinitionService; import org.bonitasoft.engine.core.process.definition.model.SProcessDefinitionDeployInfo; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.work.BonitaWork; /** @@ -46,8 +46,8 @@ public ProcessDefinitionContextWork(final BonitaWork wrappedWork, final long pro @Override protected void setExceptionContext(final SBonitaException sBonitaException, final Map context) throws SBonitaException { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final ProcessDefinitionService processDefinitionService = tenantAccessor.getProcessDefinitionService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final ProcessDefinitionService processDefinitionService = serviceAccessor.getProcessDefinitionService(); final SProcessDefinitionDeployInfo processDeploymentInfo = processDefinitionService .getProcessDeploymentInfo(processDefinitionId); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWork.java index 7c5617adb64..bc96544b99f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWork.java @@ -19,7 +19,7 @@ import org.bonitasoft.engine.core.process.instance.api.ProcessInstanceService; import org.bonitasoft.engine.core.process.instance.model.SProcessInstance; import org.bonitasoft.engine.execution.work.WrappingBonitaWork; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * Adding context information about Process definition and instance to exception for better logging @@ -73,8 +73,8 @@ protected void setRootProcessInstanceId(final long id) { protected void setExceptionContext(final SBonitaException sBonitaException, final Map context) throws SBonitaException { if (rootProcessInstanceId < 0) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final ProcessInstanceService processInstanceService = tenantAccessor.getProcessInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final ProcessInstanceService processInstanceService = serviceAccessor.getProcessInstanceService(); final SProcessInstance sProcessInstance = processInstanceService.getProcessInstance(processInstanceId); rootProcessInstanceId = sProcessInstance.getRootProcessInstanceId(); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWork.java index 9349d8e8608..a12e472de06 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWork.java @@ -18,7 +18,7 @@ import org.bonitasoft.engine.core.process.instance.model.event.handling.SWaitingSignalEvent; import org.bonitasoft.engine.execution.work.TenantAwareBonitaWork; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; /** * @author Baptiste Mesta @@ -40,10 +40,10 @@ public String getDescription() { @Override public CompletableFuture work(Map context) throws Exception { - TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - SWaitingSignalEvent listeningSignal = tenantAccessor.getEventInstanceService() + ServiceAccessor serviceAccessor = getServiceAccessor(context); + SWaitingSignalEvent listeningSignal = serviceAccessor.getEventInstanceService() .getWaitingSignalEvent(signalId); - tenantAccessor.getEventsHandler().triggerCatchEvent(listeningSignal, null); + serviceAccessor.getEventsHandler().triggerCatchEvent(listeningSignal, null); return CompletableFuture.completedFuture(null); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TxInHandleFailureWrappingWork.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TxInHandleFailureWrappingWork.java index ae4e1f6cc10..c7a069faf4f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TxInHandleFailureWrappingWork.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/execution/work/failurewrapping/TxInHandleFailureWrappingWork.java @@ -19,7 +19,7 @@ import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.execution.work.WrappingBonitaWork; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.bonitasoft.engine.work.BonitaWork; @@ -44,16 +44,12 @@ public CompletableFuture work(final Map context) throws Ex public void handleFailure(final Throwable e, final Map context) throws Exception { // Enrich the exception before log it. if (e instanceof SBonitaException) { - final TenantServiceAccessor tenantAccessor = getTenantAccessor(context); - final UserTransactionService transactionService = tenantAccessor.getUserTransactionService(); - transactionService.executeInTransaction(new Callable() { + final ServiceAccessor serviceAccessor = getServiceAccessor(context); + final UserTransactionService transactionService = serviceAccessor.getUserTransactionService(); + transactionService.executeInTransaction((Callable) () -> { + setExceptionContext((SBonitaException) e, context); - @Override - public Void call() throws Exception { - setExceptionContext((SBonitaException) e, context); - - return null; - } + return null; }); } getWrappedWork().handleFailure(e, context); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/InternalJob.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/InternalJob.java index 8be4900d733..106ef3ee5cc 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/InternalJob.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/InternalJob.java @@ -15,8 +15,8 @@ import org.bonitasoft.engine.scheduler.StatelessJob; import org.bonitasoft.engine.scheduler.exception.SJobConfigurationException; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Baptiste Mesta @@ -25,9 +25,9 @@ public abstract class InternalJob implements StatelessJob { private static final long serialVersionUID = 5627886991070497312L; - protected TenantServiceAccessor getTenantServiceAccessor() throws SJobConfigurationException { + protected ServiceAccessor getServiceAccessor() throws SJobConfigurationException { try { - return TenantServiceSingleton.getInstance(); + return ServiceAccessorSingleton.getInstance(); } catch (final Exception e) { throw new SJobConfigurationException(e); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/TriggerTimerEventJob.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/TriggerTimerEventJob.java index fff7ae9ca86..f2794b0ecfe 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/TriggerTimerEventJob.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/jobs/TriggerTimerEventJob.java @@ -25,7 +25,7 @@ import org.bonitasoft.engine.execution.event.EventsHandler; import org.bonitasoft.engine.scheduler.exception.SJobConfigurationException; import org.bonitasoft.engine.scheduler.exception.SJobExecutionException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.tenant.TenantServicesManager; /** @@ -111,10 +111,10 @@ public void setAttributes(final Map attributes) throws SJo parentProcessInstanceId = (Long) attributes.get("processInstanceId"); rootProcessInstanceId = (Long) attributes.get("rootProcessInstanceId"); isInterrupting = (Boolean) attributes.get("isInterrupting"); - final TenantServiceAccessor tenantServiceAccessor = getTenantServiceAccessor(); - eventsHandler = tenantServiceAccessor.getEventsHandler(); - tenantServicesManager = tenantServiceAccessor.getTenantServicesManager(); - eventInstanceService = tenantServiceAccessor.getEventInstanceService(); + final ServiceAccessor serviceAccessor = getServiceAccessor(); + eventsHandler = serviceAccessor.getEventsHandler(); + tenantServicesManager = serviceAccessor.getTenantServicesManager(); + eventInstanceService = serviceAccessor.getEventInstanceService(); jobDescriptorId = (Long) attributes.get(JOB_DESCRIPTOR_ID); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/platform/PlatformManager.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/platform/PlatformManager.java index 8471c3c46fd..df8f4047889 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/platform/PlatformManager.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/platform/PlatformManager.java @@ -23,7 +23,7 @@ import org.bonitasoft.engine.platform.exception.STenantDeactivationException; import org.bonitasoft.engine.platform.model.STenant; import org.bonitasoft.engine.service.BonitaTaskExecutor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; import org.bonitasoft.engine.tenant.TenantStateManager; import org.bonitasoft.engine.transaction.UserTransactionService; import org.slf4j.Logger; @@ -110,7 +110,7 @@ public synchronized boolean start() throws Exception { } TenantStateManager getDefaultTenantStateManager() { - return TenantServiceSingleton.getInstance().getTenantStateManager(); + return ServiceAccessorSingleton.getInstance().getTenantStateManager(); } private void restartHandlersOfPlatform() { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ProcessEngineServicesResolver.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ProcessEngineServicesResolver.java index 8276eb03c9a..48384c5c5c6 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ProcessEngineServicesResolver.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ProcessEngineServicesResolver.java @@ -35,8 +35,7 @@ public T lookupOnTenant(Long tenantId, final String serviceName) { return lookupOnPlatform(serviceName); } try { - TenantServiceAccessor instance = TenantServiceSingleton.getInstance(); - return instance.lookup(serviceName); + return ServiceAccessorSingleton.getInstance().lookup(serviceName); } catch (Exception e) { throw new IllegalStateException("Unable to find the service " + serviceName, e); } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ServiceAccessorSingleton.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ServiceAccessorSingleton.java new file mode 100644 index 00000000000..8da13b0b684 --- /dev/null +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/ServiceAccessorSingleton.java @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2019-2023 Bonitasoft S.A. + * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble + * This library is free software; you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation + * version 2.1 of the License. + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + **/ +package org.bonitasoft.engine.service; + +import org.bonitasoft.engine.exception.BonitaRuntimeException; +import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; + +/** + * @author Matthieu Chaffotte + */ +public final class ServiceAccessorSingleton { + + private static ServiceAccessor instance = null; + + private ServiceAccessorSingleton() { + super(); + } + + private static synchronized ServiceAccessor createNewInstance() { + try { + return ServiceAccessorFactory.getInstance().createServiceAccessor(); + } catch (final Exception e) { + throw new BonitaRuntimeException(e); + } + } + + public static ServiceAccessor getInstance() { + if (instance == null) { + instance = createNewInstance(); + } + return instance; + } + +} diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/TenantServiceSingleton.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/TenantServiceSingleton.java index 0138acff755..a48dd925a08 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/TenantServiceSingleton.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/TenantServiceSingleton.java @@ -16,8 +16,10 @@ import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; /** + * @deprecated use {@link ServiceAccessorSingleton} instead * @author Matthieu Chaffotte */ +@Deprecated(since = "9.0.0", forRemoval = true) public final class TenantServiceSingleton { private static TenantServiceAccessor instance = null; diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessor.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessor.java index f2b1a22e020..46fd5449b94 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessor.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessor.java @@ -91,12 +91,7 @@ import org.bonitasoft.engine.scheduler.JobService; import org.bonitasoft.engine.scheduler.SchedulerService; import org.bonitasoft.engine.search.descriptor.SearchEntitiesDescriptor; -import org.bonitasoft.engine.service.BroadcastService; -import org.bonitasoft.engine.service.PlatformServiceAccessor; -import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.ServicesResolver; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.*; import org.bonitasoft.engine.services.QueriableLoggerService; import org.bonitasoft.engine.session.SessionService; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; @@ -602,7 +597,6 @@ public PlatformManager getPlatformManager() { @Override public CacheService getPlatformCacheService() { return beanAccessor.getService(CacheService.class); - } @Override @@ -639,4 +633,5 @@ public ApplicationContext getContext() { public PlatformRetriever getPlatformRetriever() { return beanAccessor.getService(PlatformRetriever.class); } + } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessors.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessors.java index d0dfea790d4..623779fe6cb 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessors.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/service/impl/SpringServiceAccessors.java @@ -25,14 +25,14 @@ public class SpringServiceAccessors implements ServiceAccessors { private SpringBeanAccessor platform; //---- Initialize spring contexts - protected synchronized SpringBeanAccessor getPlatformBeanAccessor() { + protected synchronized SpringBeanAccessor getBeanAccessor() { if (platform == null) { - platform = createPlatformBeanAccessor(); + platform = createBeanAccessor(); } return platform; } - protected SpringBeanAccessor createPlatformBeanAccessor() { + protected SpringBeanAccessor createBeanAccessor() { return new SpringBeanAccessor(); } @@ -40,22 +40,22 @@ protected SpringBeanAccessor createPlatformBeanAccessor() { @Override public PlatformInitServiceAccessor getPlatformInitServiceAccessor() { - return new SpringPlatformInitServiceAccessor(getPlatformBeanAccessor()); + return new SpringPlatformInitServiceAccessor(getBeanAccessor()); } @Override public ServiceAccessor getServiceAccessor() { - return new SpringServiceAccessor(getPlatformBeanAccessor()); + return new SpringServiceAccessor(getBeanAccessor()); } @Override public PlatformServiceAccessor getPlatformServiceAccessor() { - return new SpringPlatformServiceAccessor(getPlatformBeanAccessor()); + return new SpringPlatformServiceAccessor(getBeanAccessor()); } @Override public TenantServiceAccessor getTenantServiceAccessor() { - return new SpringTenantServiceAccessor(getPlatformBeanAccessor()); + return new SpringTenantServiceAccessor(getBeanAccessor()); } @Override diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/tenant/ChangesServicesStateCallable.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/tenant/ChangesServicesStateCallable.java index 4f5e59f060f..1cb684cc142 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/tenant/ChangesServicesStateCallable.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/tenant/ChangesServicesStateCallable.java @@ -16,15 +16,15 @@ import java.io.Serializable; import java.util.concurrent.Callable; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceSingleton; +import org.bonitasoft.engine.service.ServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessorSingleton; /** * @author Emmanuel Duchastenier */ class ChangesServicesStateCallable implements Callable, Serializable { - private TenantServicesManager.ServiceAction action; + private final TenantServicesManager.ServiceAction action; public ChangesServicesStateCallable(TenantServicesManager.ServiceAction action) { this.action = action; @@ -32,9 +32,9 @@ public ChangesServicesStateCallable(TenantServicesManager.ServiceAction action) @Override public Void call() throws Exception { - TenantServiceAccessor tenantServiceAccessor = TenantServiceSingleton.getInstance(); - TenantServicesManager tenantServicesManager = tenantServiceAccessor.getTenantServicesManager(); - TenantStateManager tenantStateManager = tenantServiceAccessor.getTenantStateManager(); + ServiceAccessor serviceAccessor = ServiceAccessorSingleton.getInstance(); + TenantServicesManager tenantServicesManager = serviceAccessor.getTenantServicesManager(); + TenantStateManager tenantStateManager = serviceAccessor.getTenantStateManager(); return tenantStateManager.executeTenantManagementOperation( "Executing received " + action.name().toLowerCase() + " operation", () -> { switch (action) { diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImplTest.java index fe2e061804f..cbf48529436 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/BusinessDataAPIImplTest.java @@ -30,7 +30,7 @@ import org.bonitasoft.engine.core.process.instance.model.business.data.SProcessSimpleRefBusinessDataInstance; import org.bonitasoft.engine.exception.RetrieveException; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,7 +42,7 @@ public class BusinessDataAPIImplTest { @Mock - private TenantServiceAccessor serviceAccessor; + private ServiceAccessor serviceAccessor; @Mock private RefBusinessDataService refBusinessDataService; @@ -52,7 +52,7 @@ public class BusinessDataAPIImplTest { @Before public void setUp() { - doReturn(serviceAccessor).when(businessDataAPI).getTenantAccessor(); + doReturn(serviceAccessor).when(businessDataAPI).getServiceAccessor(); when(serviceAccessor.getRefBusinessDataService()).thenReturn(refBusinessDataService); } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/IdentityAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/IdentityAPIImplTest.java index d9042645cbb..29d049f3b8a 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/IdentityAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/IdentityAPIImplTest.java @@ -24,7 +24,7 @@ import org.bonitasoft.engine.exception.RetrieveException; import org.bonitasoft.engine.identity.IdentityService; import org.bonitasoft.engine.identity.SIdentityException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,7 +36,7 @@ public class IdentityAPIImplTest { @Mock - private TenantServiceAccessor tenantAccessor; + private ServiceAccessor serviceAccessor; @Mock private IdentityService identityService; @@ -46,8 +46,8 @@ public class IdentityAPIImplTest { @Before public void setUp() { - doReturn(tenantAccessor).when(identityAPI).getTenantAccessor(); - given(tenantAccessor.getIdentityService()).willReturn(identityService); + doReturn(serviceAccessor).when(identityAPI).getServiceAccessor(); + given(serviceAccessor.getIdentityService()).willReturn(identityService); } @Test diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/OrganizationAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/OrganizationAPIImplTest.java index 722d8d7a158..23f56fc4d6c 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/OrganizationAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/OrganizationAPIImplTest.java @@ -20,7 +20,6 @@ import java.util.Collections; import org.bonitasoft.engine.actor.mapping.ActorMappingService; -import org.bonitasoft.engine.api.impl.resolver.BusinessArchiveArtifactsManager; import org.bonitasoft.engine.core.process.comment.api.SCommentService; import org.bonitasoft.engine.core.process.definition.ProcessDefinitionService; import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; @@ -29,7 +28,7 @@ import org.bonitasoft.engine.identity.IdentityService; import org.bonitasoft.engine.identity.model.SCustomUserInfoDefinition; import org.bonitasoft.engine.profile.ProfileService; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.supervisor.mapping.SupervisorMappingService; import org.junit.Before; import org.junit.Test; @@ -47,7 +46,7 @@ public class OrganizationAPIImplTest { private static final long CUSTOM_USER_INFO_DEF_ID2 = 12; @Mock - private TenantServiceAccessor serviceAccessor; + private ServiceAccessor serviceAccessor; @Mock private ProcessInstanceService processInstanceService; @@ -76,9 +75,6 @@ public class OrganizationAPIImplTest { @Mock private ProcessDefinitionService processDefinitionService; - @Mock - private BusinessArchiveArtifactsManager businessArchiveArtifactsManager; - @Mock private SCustomUserInfoDefinition userInfoDef1; diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/PermissionAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/PermissionAPIImplTest.java index 5a6fd1c31ef..9c63d14e4f2 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/PermissionAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/PermissionAPIImplTest.java @@ -22,7 +22,7 @@ import org.bonitasoft.engine.commons.exceptions.SExecutionException; import org.bonitasoft.engine.exception.ExecutionException; import org.bonitasoft.engine.exception.NotFoundException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,7 +33,7 @@ public class PermissionAPIImplTest { @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private PermissionService permissionService; private PermissionAPIImpl permissionAPI; @@ -42,8 +42,8 @@ public class PermissionAPIImplTest { @Before public void before() { permissionAPI = spy(new PermissionAPIImpl()); - doReturn(tenantServiceAccessor).when(permissionAPI).getTenantServiceAccessor(); - doReturn(permissionService).when(tenantServiceAccessor).getPermissionService(); + doReturn(serviceAccessor).when(permissionAPI).getServiceAccessor(); + doReturn(permissionService).when(serviceAccessor).getPermissionService(); apiCallContext = new APICallContext("GET", "identity", "user", "1", "query", "{\"body\":\"value\"}"); } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessAPIImplTest.java index ba73827d725..7efe06ed7df 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessAPIImplTest.java @@ -14,19 +14,13 @@ package org.bonitasoft.engine.api.impl; import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.anyList; -import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.anyMap; -import static org.mockito.Mockito.anySetOf; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.nullable; import java.io.FileNotFoundException; import java.io.Serializable; @@ -125,7 +119,7 @@ import org.bonitasoft.engine.search.descriptor.SearchMessageInstanceDescriptor; import org.bonitasoft.engine.search.impl.SearchOptionsImpl; import org.bonitasoft.engine.search.process.SearchFailedProcessInstancesSupervisedBy; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.session.model.SSession; import org.bonitasoft.engine.transaction.STransactionCommitException; import org.bonitasoft.engine.transaction.STransactionNotFoundException; @@ -163,7 +157,7 @@ public class ProcessAPIImplTest { @Mock private ProcessManagementAPIImplDelegate managementAPIImplDelegate; @Mock - private TenantServiceAccessor tenantAccessor; + private ServiceAccessor serviceAccessor; @Mock private TransientDataService transientDataService; @Mock @@ -220,8 +214,6 @@ public class ProcessAPIImplTest { @Captor private ArgumentCaptor> argument; @Captor - private ArgumentCaptor workArgumentCaptor; - @Captor private ArgumentCaptor pendingMappingArgumentCaptor; @Captor private ArgumentCaptor deleteOldMessageArgumentCaptor; @@ -234,32 +226,31 @@ public class ProcessAPIImplTest { @Before public void setup() throws Exception { - doReturn(tenantAccessor).when(processAPI).getTenantAccessor(); - when(tenantAccessor.getTenantId()).thenReturn(TENANT_ID); - when(tenantAccessor.getDataInstanceService()).thenReturn(dataInstanceService); - when(tenantAccessor.getOperationService()).thenReturn(operationService); - when(tenantAccessor.getActorMappingService()).thenReturn(actorMappingService); - when(tenantAccessor.getConnectorService()).thenReturn(connectorService); - when(tenantAccessor.getSchedulerService()).thenReturn(schedulerService); - when(tenantAccessor.getSearchEntitiesDescriptor()).thenReturn(searchEntitiesDescriptor); - when(tenantAccessor.getEventInstanceService()).thenReturn(eventInstanceService); - when(tenantAccessor.getFlowNodeStateManager()).thenReturn(flowNodeStateManager); - when(tenantAccessor.getParentContainerResolver()).thenReturn(parentContainerResolver); - when(tenantAccessor.getContractDataService()).thenReturn(contractDataService); - when(tenantAccessor.getTransientDataService()).thenReturn(transientDataService); - when(tenantAccessor.getExpressionResolverService()).thenReturn(expressionResolverService); - when(tenantAccessor.getActivityInstanceService()).thenReturn(activityInstanceService); - when(tenantAccessor.getClassLoaderService()).thenReturn(classLoaderService); - when(tenantAccessor.getProcessDefinitionService()).thenReturn(processDefinitionService); - when(tenantAccessor.getProcessInstanceService()).thenReturn(processInstanceService); - when(tenantAccessor.getFlowNodeExecutor()).thenReturn(flowNodeExecutor); - when(tenantAccessor.getWorkService()).thenReturn(workService); - when(tenantAccessor.getBPMWorkFactory()).thenReturn(workFactory); - when(tenantAccessor.getUserFilterService()).thenReturn(userFilterService); - when(tenantAccessor.getProcessResourcesService()).thenReturn(processResourcesService); - when(tenantAccessor.getBPMArchiverService()).thenReturn(bpmArchiverService); + doReturn(serviceAccessor).when(processAPI).getServiceAccessor(); + when(serviceAccessor.getTenantId()).thenReturn(TENANT_ID); + when(serviceAccessor.getDataInstanceService()).thenReturn(dataInstanceService); + when(serviceAccessor.getOperationService()).thenReturn(operationService); + when(serviceAccessor.getActorMappingService()).thenReturn(actorMappingService); + when(serviceAccessor.getConnectorService()).thenReturn(connectorService); + when(serviceAccessor.getSchedulerService()).thenReturn(schedulerService); + when(serviceAccessor.getSearchEntitiesDescriptor()).thenReturn(searchEntitiesDescriptor); + when(serviceAccessor.getEventInstanceService()).thenReturn(eventInstanceService); + when(serviceAccessor.getFlowNodeStateManager()).thenReturn(flowNodeStateManager); + when(serviceAccessor.getParentContainerResolver()).thenReturn(parentContainerResolver); + when(serviceAccessor.getContractDataService()).thenReturn(contractDataService); + when(serviceAccessor.getTransientDataService()).thenReturn(transientDataService); + when(serviceAccessor.getExpressionResolverService()).thenReturn(expressionResolverService); + when(serviceAccessor.getActivityInstanceService()).thenReturn(activityInstanceService); + when(serviceAccessor.getClassLoaderService()).thenReturn(classLoaderService); + when(serviceAccessor.getProcessDefinitionService()).thenReturn(processDefinitionService); + when(serviceAccessor.getProcessInstanceService()).thenReturn(processInstanceService); + when(serviceAccessor.getWorkService()).thenReturn(workService); + when(serviceAccessor.getBPMWorkFactory()).thenReturn(workFactory); + when(serviceAccessor.getUserFilterService()).thenReturn(userFilterService); + when(serviceAccessor.getProcessResourcesService()).thenReturn(processResourcesService); + when(serviceAccessor.getBPMArchiverService()).thenReturn(bpmArchiverService); userTransactionService = new TestUserTransactionService(); - when(tenantAccessor.getUserTransactionService()).thenReturn(userTransactionService); + when(serviceAccessor.getUserTransactionService()).thenReturn(userTransactionService); sUserTaskInstance = new SUserTaskInstance("userTaskName", FLOW_NODE_DEFINITION_ID, PROCESS_INSTANCE_ID, PROCESS_INSTANCE_ID, @@ -287,7 +278,7 @@ public void setup() throws Exception { .getSession(); doReturn("john").when(processAPI).getUserNameFromSession(); - when(tenantAccessor.getMessagesHandlingService()).thenReturn(messageHandlingService); + when(serviceAccessor.getMessagesHandlingService()).thenReturn(messageHandlingService); } @Test @@ -381,8 +372,8 @@ public void cancelAnUnknownProcessInstanceThrowsANotFoundException() throws Exce final LockService lockService = mock(LockService.class); final ProcessInstanceInterruptor interruptor = mock(ProcessInstanceInterruptor.class); - when(tenantAccessor.getLockService()).thenReturn(lockService); - doReturn(interruptor).when(tenantAccessor).getProcessInstanceInterruptor(); + when(serviceAccessor.getLockService()).thenReturn(lockService); + doReturn(interruptor).when(serviceAccessor).getProcessInstanceInterruptor(); doThrow(new SProcessInstanceNotFoundException(PROCESS_INSTANCE_ID)).when(interruptor).interruptProcessInstance( PROCESS_INSTANCE_ID, SStateCategory.CANCELLING); @@ -424,7 +415,7 @@ public void updateProcessDataInstances_should_update_data_instances_when_new_val // Given ClassLoader processClassLoader = mock(ClassLoader.class); when(processClassLoader.loadClass(String.class.getName())).thenReturn((Class) String.class); - doReturn(processClassLoader).when(processAPI).getProcessInstanceClassloader(any(TenantServiceAccessor.class), + doReturn(processClassLoader).when(processAPI).getProcessInstanceClassloader(any(ServiceAccessor.class), anyLong()); final SBlobDataInstance sDataFoo = new SBlobDataInstance(); @@ -463,7 +454,7 @@ public void updateProcessDataInstances_should_throw_exception_when_new_value_is_ final String dataName = "dataName"; ClassLoader processClassLoader = mock(ClassLoader.class); when(processClassLoader.loadClass(List.class.getName())).thenReturn((Class) List.class); - doReturn(processClassLoader).when(processAPI).getProcessInstanceClassloader(any(TenantServiceAccessor.class), + doReturn(processClassLoader).when(processAPI).getProcessInstanceClassloader(any(ServiceAccessor.class), anyLong()); final Map dataNameValues = singletonMap(dataName, "dataValue"); @@ -471,8 +462,8 @@ public void updateProcessDataInstances_should_throw_exception_when_new_value_is_ final SBlobDataInstance dataInstance = new SBlobDataInstance(); dataInstance.setClassName(List.class.getName()); dataInstance.setName(dataName); - doReturn(Collections.singletonList(dataInstance)).when(dataInstanceService).getDataInstances( - Collections.singletonList(dataName), + doReturn(singletonList(dataInstance)).when(dataInstanceService).getDataInstances( + singletonList(dataName), PROCESS_INSTANCE_ID, DataInstanceContainer.PROCESS_INSTANCE.toString(), parentContainerResolver); // When @@ -494,8 +485,8 @@ public void updateProcessDataInstances_should_throw_exception_when_new_value_is_ @Test public void should_updateProcessDataInstances_call_DataInstance_on_non_existing_data_throw_UpdateException() throws Exception { - final long processInstanceId = 42l; - doReturn(null).when(processAPI).getProcessInstanceClassloader(any(TenantServiceAccessor.class), anyLong()); + final long processInstanceId = 42L; + doReturn(null).when(processAPI).getProcessInstanceClassloader(any(ServiceAccessor.class), anyLong()); doThrow(new SDataInstanceReadException("Mocked")).when(dataInstanceService).getDataInstances(argument.capture(), anyLong(), anyString(), any(ParentContainerResolver.class)); @@ -528,7 +519,7 @@ public void replayingAFailedJobNoParamShouldExecuteAgainSchedulerServiceWithNoPa } @Test - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "rawtypes" }) public void replayingAFailedJobShouldExecuteAgainSchedulerServiceWithSomeParameters() throws Exception { final Map parameters = Collections.singletonMap("anyparam", Boolean.FALSE); final long jobDescriptorId = 544L; @@ -585,12 +576,12 @@ public void getActivityTransientDataInstances() throws Exception { final int nbResults = 100; final int startIndex = 0; final SDataInstance sDataInstance = mock(SDataInstance.class); - final List sDataInstances = Arrays.asList(sDataInstance); + final List sDataInstances = singletonList(sDataInstance); when(transientDataService.getDataInstances(FLOW_NODE_INSTANCE_ID, DataInstanceContainer.ACTIVITY_INSTANCE.name(), startIndex, nbResults)) .thenReturn(sDataInstances); final IntegerDataInstanceImpl dataInstance = mock(IntegerDataInstanceImpl.class); - doReturn(Arrays.asList(dataInstance)).when(processAPI).convertModelToDataInstances(sDataInstances); + doReturn(singletonList(dataInstance)).when(processAPI).convertModelToDataInstances(sDataInstances); final List dis = processAPI.getActivityTransientDataInstances(FLOW_NODE_INSTANCE_ID, startIndex, nbResults); @@ -600,9 +591,9 @@ public void getActivityTransientDataInstances() throws Exception { verify(processAPI).convertModelToDataInstances(sDataInstances); verify(transientDataService).getDataInstances(FLOW_NODE_INSTANCE_ID, DataInstanceContainer.ACTIVITY_INSTANCE.name(), startIndex, nbResults); - verify(tenantAccessor).getTransientDataService(); - verify(tenantAccessor).getClassLoaderService(); - verify(tenantAccessor).getActivityInstanceService(); + verify(serviceAccessor).getTransientDataService(); + verify(serviceAccessor).getClassLoaderService(); + verify(serviceAccessor).getActivityInstanceService(); verify(activityInstanceService).getFlowNodeInstance(FLOW_NODE_INSTANCE_ID); verify(classLoaderService) .getClassLoader(argThat(id -> id.getType().equals(ScopeType.PROCESS))); @@ -625,9 +616,9 @@ public void getActivityTransientDataInstance() throws Exception { verify(processAPI).convertModeltoDataInstance(sDataInstance); verify(transientDataService).getDataInstance(dataName, FLOW_NODE_INSTANCE_ID, DataInstanceContainer.ACTIVITY_INSTANCE.name()); - verify(tenantAccessor).getTransientDataService(); - verify(tenantAccessor).getClassLoaderService(); - verify(tenantAccessor).getActivityInstanceService(); + verify(serviceAccessor).getTransientDataService(); + verify(serviceAccessor).getClassLoaderService(); + verify(serviceAccessor).getActivityInstanceService(); verify(activityInstanceService).getFlowNodeInstance(FLOW_NODE_INSTANCE_ID); verify(classLoaderService) .getClassLoader(argThat(id -> id.getType().equals(ScopeType.PROCESS))); @@ -715,9 +706,9 @@ public void updateActivityTransientDataInstance_should_call_updateTransientData_ verify(processAPI).updateTransientData(dataName, FLOW_NODE_INSTANCE_ID, dataValue, transientDataService, contextClassLoader); - verify(tenantAccessor).getTransientDataService(); - verify(tenantAccessor).getClassLoaderService(); - verify(tenantAccessor).getActivityInstanceService(); + verify(serviceAccessor).getTransientDataService(); + verify(serviceAccessor).getClassLoaderService(); + verify(serviceAccessor).getActivityInstanceService(); verify(activityInstanceService).getFlowNodeInstance(FLOW_NODE_INSTANCE_ID); verify(classLoaderService) .getClassLoader(argThat(id -> id.getType().equals(ScopeType.PROCESS))); @@ -809,7 +800,7 @@ public void updateActivityInstanceVariables_should_load_processDef_classes() thr final List operations = new ArrayList<>(); operations.add(operation); - doReturn(Arrays.asList(mock(SOperation.class))).when(processAPI).convertOperations(operations); + doReturn(singletonList(mock(SOperation.class))).when(processAPI).convertOperations(operations); processAPI.updateActivityInstanceVariables(operations, 2, null); @@ -826,11 +817,10 @@ public void searchFailedProcessInstances_should_return_failed_process_instances( // Given final SearchOptions searchOptions = new SearchOptionsBuilder(0, 20).done(); final long numberOfFailedProcessInstances = 2L; - final List failedProcessInstances = Arrays - .asList((ProcessInstance) new ProcessInstanceImpl("name")); + final List failedProcessInstances = List.of(new ProcessInstanceImpl("name")); final long processDefinitionId = 9L; - final List sFailedProcessInstances = Arrays - .asList(new SProcessInstance("name", processDefinitionId)); + final List sFailedProcessInstances = List + .of(new SProcessInstance("name", processDefinitionId)); doReturn(numberOfFailedProcessInstances).when(processInstanceService) .getNumberOfFailedProcessInstances(any(QueryOptions.class)); doReturn(sFailedProcessInstances).when(processInstanceService) @@ -947,7 +937,7 @@ public void evaluateExpressionsOnCompletedActivityInstance_should_call_getLastAr //when processAPI.evaluateExpressionsOnCompletedActivityInstance(activityInstanceId, - new HashMap>()); + new HashMap<>()); //then verify(processAPI).getLastArchivedProcessInstance(processInstanceId); @@ -972,23 +962,24 @@ public void deleteArchivedProcessInstances_by_ids_should_throw_exception_when_nu public void deleteArchivedProcessInstances_by_ids_should_return_0_when_no_archived_process_instance_for_ids() throws Exception { // Given - final long archivedProcessInstanceId = 42l; + final long archivedProcessInstanceId = 42L; // When final long deleteArchivedProcessInstances = processAPI .deleteArchivedProcessInstancesInAllStates(archivedProcessInstanceId); // Then - assertThat(0L).isEqualTo(deleteArchivedProcessInstances) - .as("Must to return 0, when there are no archived process instance to delete."); + assertThat(deleteArchivedProcessInstances) + .as("Must to return 0, when there are no archived process instance to delete.") + .isEqualTo(0L); } @Test public void deleteArchivedProcessInstances_by_ids_should_return_number_of_deleted_archived_process_instance_when_exist() throws Exception { // Given - final long archivedProcessInstanceId = 42l; - doReturn(1).when(processInstanceService).deleteArchivedProcessInstances(anyListOf(Long.class)); + final long archivedProcessInstanceId = 42L; + doReturn(1).when(processInstanceService).deleteArchivedProcessInstances(anyList()); // When final long deleteArchivedProcessInstances = processAPI @@ -1003,20 +994,20 @@ public void deleteArchivedProcessInstances_by_ids_should_return_number_of_delete public void deleteArchivedProcessInstance_by_id_should_delete_archived_process_instance_when_exist() throws Exception { // Given - final long processInstanceId = 42l; + final long processInstanceId = 42L; // When processAPI.deleteArchivedProcessInstancesInAllStates(processInstanceId); // Then - verify(processInstanceService).deleteArchivedProcessInstances(asList(processInstanceId)); + verify(processInstanceService).deleteArchivedProcessInstances(List.of(processInstanceId)); } @Test(expected = DeletionException.class) public void deleteArchivedProcessInstance_by_id_should_throw_exception_when_getArchivedProcessInstance_throws_exception() throws Exception { // Given - final long archivedProcessInstanceId = 42l; + final long archivedProcessInstanceId = 42L; doThrow(new SProcessInstanceReadException(new Exception())).when(processInstanceService) .deleteArchivedProcessInstances(anyList()); @@ -1028,9 +1019,8 @@ public void deleteArchivedProcessInstance_by_id_should_throw_exception_when_getA public void deleteArchivedProcessInstance_by_id_should_throw_exception_when_deleteParentArchivedProcessInstanceAndElements_throws_exception() throws Exception { // Given - final long archivedProcessInstanceId = 42l; - doThrow(new SDeletionException("")).when(processInstanceService) - .deleteArchivedProcessInstances(anyListOf(Long.class)); + final long archivedProcessInstanceId = 42L; + doThrow(new SDeletionException("")).when(processInstanceService).deleteArchivedProcessInstances(anyList()); // When processAPI.deleteArchivedProcessInstancesInAllStates(archivedProcessInstanceId); @@ -1040,7 +1030,7 @@ public void deleteArchivedProcessInstance_by_id_should_throw_exception_when_dele public void searchEventTriggerInstances_should_throw_exception_when_transaction_throws_exception() throws Exception { // Given - final long processInstanceId = 42l; + final long processInstanceId = 42L; final SearchOptions searchOptions = new SearchOptionsBuilder(0, 10).done(); doThrow(new SBonitaReadException(new Exception())).when(eventInstanceService) @@ -1123,8 +1113,6 @@ public void searchHumanTaskInstancesWithSearchException() throws Exception { @Test public void getPendingHumanTaskInstances_should_return_user_tasks_of_enabled_and_disabled_processes() throws Exception { - final Set actorIds = new HashSet<>(); - actorIds.add(454545L); final long userId = 1983L; final List processDefinitionIds = new ArrayList<>(); processDefinitionIds.add(7897987L); @@ -1140,8 +1128,8 @@ public void getPendingHumanTaskInstances_should_return_user_tasks_of_enabled_and processAPI.getPendingHumanTaskInstances(userId, 0, 100, ActivityInstanceCriterion.NAME_DESC); verify(processDefinitionService).getProcessDefinitionIds(0, Integer.MAX_VALUE); - verify(actorMappingService).getActors(anySetOf(Long.class), eq(userId)); - verify(activityInstanceService).getPendingTasks(eq(userId), anySetOf(Long.class), eq(0), eq(100), + verify(actorMappingService).getActors(anySet(), eq(userId)); + verify(activityInstanceService).getPendingTasks(eq(userId), anySet(), eq(0), eq(100), eq(orderAndField.getField()), eq(orderAndField.getOrder())); } @@ -1166,6 +1154,7 @@ public void getUserTaskContractVariableValue_should_throw_an_exception_if_an_exc processAPI.getUserTaskContractVariableValue(1983L, "id"); } + @Test(expected = ContractDataNotFoundException.class) public void getUserTaskContractVariableValue_should_throw_an_exception_if_an_exception_occurs_when_getting_data() throws Exception { when(contractDataService.getArchivedUserTaskDataValue(1983L, "id")) @@ -1184,13 +1173,12 @@ public void getProcessContract_should_return_null_when_no_contract() throws Proc @Test public void getArchivedProcessInstance_Should_Return_Instance_Of_Disabled_Process() throws Exception { final long processInstanceId = PROCESS_INSTANCE_ID; - final long processDefinitionId = PROCESS_DEFINITION_ID; final SAProcessInstance saProcessInstance = mock(SAProcessInstance.class); when(processInstanceService.getArchivedProcessInstance(processInstanceId)).thenReturn(saProcessInstance); when(saProcessInstance.getProcessDefinitionId()).thenReturn(PROCESS_DEFINITION_ID); final SProcessDefinition sProcessDefinition = mock(SProcessDefinition.class); - when(processDefinitionService.getProcessDefinition(processDefinitionId)).thenReturn(sProcessDefinition); + when(processDefinitionService.getProcessDefinition(PROCESS_DEFINITION_ID)).thenReturn(sProcessDefinition); final ArchivedProcessInstance archivedProcessInstanceMocked = mock(ArchivedProcessInstance.class); doReturn(archivedProcessInstanceMocked).when(processAPI).toArchivedProcessInstance(saProcessInstance, @@ -1205,9 +1193,8 @@ public void getArchivedProcessInstance_Should_Return_Instance_Of_Disabled_Proces public void searchFailedProcessInstancesSupervisedBy_should_Return_ProcessInstances_And_Call_ProcessInstanceService() throws Exception { final long userId = 0; - final ProcessInstance mockedProcessInstance = mock(ProcessInstance.class); final IdentityService identityService = mock(IdentityService.class); - when(tenantAccessor.getIdentityService()).thenReturn(identityService); + when(serviceAccessor.getIdentityService()).thenReturn(identityService); doReturn(mock(GetSUser.class)).when(processAPI).createTxUserGetter(userId, identityService); final SearchOptions searchOptions = mock(SearchOptions.class); @@ -1230,9 +1217,8 @@ public void searchFailedProcessInstancesSupervisedBy_should_Return_ProcessInstan public void searchFailedProcessInstancesSupervisedBy_should_Return_Empty_Result_When_User_Does_Not_Exist() throws Exception { final long userId = 0; - final ProcessInstance mockedProcessInstance = mock(ProcessInstance.class); final IdentityService identityService = mock(IdentityService.class); - when(tenantAccessor.getIdentityService()).thenReturn(identityService); + when(serviceAccessor.getIdentityService()).thenReturn(identityService); final GetSUser getSUser = mock(GetSUser.class); doReturn(getSUser).when(processAPI).createTxUserGetter(userId, identityService); doThrow(new SBonitaException() { @@ -1315,7 +1301,7 @@ SExpressionImpl createExpression(String name) { public void getDesignProcessDefinition_Should_Return_Design() throws Exception { //given int processDefinitionId = 123; - doReturn(processDefinitionService).when(tenantAccessor).getProcessDefinitionService(); + doReturn(processDefinitionService).when(serviceAccessor).getProcessDefinitionService(); DesignProcessDefinition designProcessDefinition = mock(DesignProcessDefinition.class); when(processDefinitionService.getDesignProcessDefinition(processDefinitionId)) .thenReturn(designProcessDefinition); @@ -1330,7 +1316,7 @@ public void getDesignProcessDefinition_Should_Return_Design() throws Exception { @Test(expected = ProcessDefinitionNotFoundException.class) public void getDesignProcessDefinition_Should_ThrowException_When_No_ProcessDefinition_Exists() throws Exception { int processDefinitionId = 123; - doReturn(processDefinitionService).when(tenantAccessor).getProcessDefinitionService(); + doReturn(processDefinitionService).when(serviceAccessor).getProcessDefinitionService(); when(processDefinitionService.getDesignProcessDefinition(processDefinitionId)).thenThrow( new SProcessDefinitionNotFoundException("impossible to found given process definition")); processAPI.getDesignProcessDefinition(processDefinitionId); @@ -1450,7 +1436,7 @@ public void should_update_mapping_auto_assign_if_flag_is_set() throws Exception SUserFilterDefinitionImpl sUserFilterDefinition = new SUserFilterDefinitionImpl( new UserFilterDefinitionImpl("myUserFilter", "def", "version")); userTaskDefinition.setUserFilter(sUserFilterDefinition); - doReturn(new FilterResultImpl(Collections.singletonList(4L), true)).when(userFilterService).executeFilter( + doReturn(new FilterResultImpl(singletonList(4L), true)).when(userFilterService).executeFilter( anyLong(), eq(sUserFilterDefinition), anyMap(), nullable(ClassLoader.class), @@ -1469,7 +1455,7 @@ public void should_update_mapping_not_auto_assign_if_flag_is_not_set() throws Ex SUserFilterDefinitionImpl sUserFilterDefinition = new SUserFilterDefinitionImpl( new UserFilterDefinitionImpl("myUserFilter", "def", "version")); userTaskDefinition.setUserFilter(sUserFilterDefinition); - doReturn(new FilterResultImpl(Collections.singletonList(4L), false)).when(userFilterService).executeFilter( + doReturn(new FilterResultImpl(singletonList(4L), false)).when(userFilterService).executeFilter( anyLong(), eq(sUserFilterDefinition), anyMap(), nullable(ClassLoader.class), @@ -1484,7 +1470,7 @@ public void should_update_mapping_not_auto_assign_if_flag_is_not_set() throws Ex public void should_throw_Illegal_Arg_Exception_when_setState_with_unknown_state() throws UpdateException { expectedException.expect(IllegalArgumentException.class); - processAPI.setActivityStateByName(25l, "garbage"); + processAPI.setActivityStateByName(25L, "garbage"); } @Test @@ -1555,14 +1541,11 @@ public T executeInTransaction(Callable callable) throws Exception { } @Override - public void registerBonitaSynchronization(Synchronization txSync) - throws STransactionNotFoundException { - + public void registerBonitaSynchronization(Synchronization txSync) { } @Override - public void registerBeforeCommitCallable(Callable callable) throws STransactionNotFoundException { - + public void registerBeforeCommitCallable(Callable callable) { } @Override @@ -1669,7 +1652,7 @@ public void should_disconnect_connector_execution_when_output_operation_throw_an // When assertThatThrownBy(() -> processAPI.executeOperations(connectorResult, new ArrayList<>(), - new HashMap<>(), new SExpressionContext(), ProcessAPIImplTest.class.getClassLoader(), tenantAccessor)) + new HashMap<>(), new SExpressionContext(), ProcessAPIImplTest.class.getClassLoader(), serviceAccessor)) .isInstanceOf(SOperationExecutionException.class); // Then diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegateTest.java index ca4223c0cc3..5a717b55ba8 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessDeploymentAPIDelegateTest.java @@ -60,7 +60,7 @@ public void deploy_should_not_call_service_deploy_if_bar_validation_failed() thr // then: verifyNoMoreInteractions(businessArchive); - verify(processDeploymentAPIDelegate, times(0)).getTenantServiceAccessor(); + verify(processDeploymentAPIDelegate, times(0)).getServiceAccessor(); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegateTest.java index 34578c31f2c..118208fd269 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessInvolvementDelegateTest.java @@ -26,7 +26,7 @@ import org.bonitasoft.engine.core.process.instance.model.SProcessInstance; import org.bonitasoft.engine.core.process.instance.model.archive.SAProcessInstance; import org.bonitasoft.engine.persistence.QueryOptions; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.session.SessionService; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; import org.junit.Before; @@ -63,7 +63,7 @@ public class ProcessInvolvementDelegateTest { SAProcessInstance saProcessInstance; @Mock - TenantServiceAccessor tenantServiceAccessor; + ServiceAccessor serviceAccessor; @Spy @InjectMocks @@ -71,8 +71,8 @@ public class ProcessInvolvementDelegateTest { @Before public void before() { - doReturn(tenantServiceAccessor).when(processInvolvementDelegate).getTenantServiceAccessor(); - doReturn(processInstanceService).when(tenantServiceAccessor).getProcessInstanceService(); + doReturn(serviceAccessor).when(processInvolvementDelegate).getServiceAccessor(); + doReturn(processInstanceService).when(serviceAccessor).getProcessInstanceService(); } @Test diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegateTest.java index 8e57f7fddb3..b77490203e3 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProcessManagementAPIImplDelegateTest.java @@ -27,7 +27,7 @@ import org.bonitasoft.engine.exception.RetrieveException; import org.bonitasoft.engine.exception.UpdateException; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,7 +45,7 @@ public class ProcessManagementAPIImplDelegateTest { private ProcessInstanceService processInstanceService; @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Spy private ProcessManagementAPIImplDelegate delegate; @@ -58,10 +58,10 @@ public class ProcessManagementAPIImplDelegateTest { @Before public void setUp() { - doReturn(tenantServiceAccessor).when(delegate).getTenantAccessor(); - when(tenantServiceAccessor.getProcessDefinitionService()).thenReturn(processDefinitionService); - when(tenantServiceAccessor.getProcessInstanceService()).thenReturn(processInstanceService); - when(tenantServiceAccessor.getClassLoaderService()).thenReturn(classLoaderService); + doReturn(serviceAccessor).when(delegate).getServiceAccessor(); + when(serviceAccessor.getProcessDefinitionService()).thenReturn(processDefinitionService); + when(serviceAccessor.getProcessInstanceService()).thenReturn(processInstanceService); + when(serviceAccessor.getClassLoaderService()).thenReturn(classLoaderService); } @Test(expected = ProcessDefinitionNotFoundException.class) diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java index c06c7437845..e4079871639 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java @@ -36,24 +36,15 @@ import org.bonitasoft.engine.classloader.ClassLoaderService; import org.bonitasoft.engine.core.login.LoginService; import org.bonitasoft.engine.core.platform.login.PlatformLoginService; -import org.bonitasoft.engine.exception.APIImplementationNotFoundException; -import org.bonitasoft.engine.exception.BonitaHomeConfigurationException; -import org.bonitasoft.engine.exception.BonitaHomeNotSetException; -import org.bonitasoft.engine.exception.BonitaRuntimeException; -import org.bonitasoft.engine.exception.TenantStatusException; +import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.platform.PlatformManager; import org.bonitasoft.engine.platform.PlatformState; import org.bonitasoft.engine.platform.session.PlatformSessionService; import org.bonitasoft.engine.scheduler.SchedulerService; import org.bonitasoft.engine.service.APIAccessResolver; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.bonitasoft.engine.service.impl.ServiceAccessorFactory; -import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.engine.session.InvalidSessionException; -import org.bonitasoft.engine.session.PlatformSession; -import org.bonitasoft.engine.session.Session; -import org.bonitasoft.engine.session.SessionService; +import org.bonitasoft.engine.session.*; import org.bonitasoft.engine.session.impl.APISessionImpl; import org.bonitasoft.engine.session.impl.PlatformSessionImpl; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; @@ -90,8 +81,6 @@ public class ServerAPIImplTest { @Mock private ServiceAccessor serviceAccessor; @Mock - private TenantServiceAccessor tenantServiceAccessor; - @Mock private LoginService tenantLoginService; @Mock private SchedulerService schedulerService; @@ -131,11 +120,10 @@ public void createServerAPI() throws Exception { doReturn(schedulerService).when(serviceAccessor).getSchedulerService(); doReturn(platformLoginService).when(serviceAccessor).getPlatformLoginService(); doReturn(platformSessionService).when(serviceAccessor).getPlatformSessionService(); - doReturn(tenantServiceAccessor).when(serviceAccessor).getTenantServiceAccessor(); doReturn(platformManager).when(serviceAccessor).getPlatformManager(); - doReturn(tenantLoginService).when(tenantServiceAccessor).getLoginService(); - doReturn(sessionService).when(tenantServiceAccessor).getSessionService(); - doReturn(classLoaderService).when(tenantServiceAccessor).getClassLoaderService(); + doReturn(tenantLoginService).when(serviceAccessor).getLoginService(); + doReturn(sessionService).when(serviceAccessor).getSessionService(); + doReturn(classLoaderService).when(serviceAccessor).getClassLoaderService(); doReturn(true).when(tenantLoginService).isValid(TENANT_SESSION_ID); doReturn(true).when(platformLoginService).isValid(PLATFORM_SESSION_ID); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegateTest.java index 2843c9aca1d..a7b3b3e6538 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TaskInvolvementDelegateTest.java @@ -14,9 +14,7 @@ package org.bonitasoft.engine.api.impl; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -28,7 +26,7 @@ import org.bonitasoft.engine.core.process.instance.model.SUserTaskInstance; import org.bonitasoft.engine.persistence.QueryOptions; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -55,7 +53,7 @@ public class TaskInvolvementDelegateTest { private ActivityInstanceService activityInstanceService; @Mock - TenantServiceAccessor tenantServiceAccessor; + ServiceAccessor serviceAccessor; @Mock public ProcessAPIImpl processAPI; @@ -71,8 +69,8 @@ public class TaskInvolvementDelegateTest { @Before public void before() throws SBonitaException { - doReturn(tenantServiceAccessor).when(taskInvolvementDelegate).getTenantServiceAccessor(); - doReturn(activityInstanceService).when(tenantServiceAccessor).getActivityInstanceService(); + doReturn(serviceAccessor).when(taskInvolvementDelegate).getServiceAccessor(); + doReturn(activityInstanceService).when(serviceAccessor).getActivityInstanceService(); humanTaskInstance = new SUserTaskInstance(); humanTaskInstance.setId(EXISTING_TASK); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java index 2eb8f6d7163..3e9a243c59f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java @@ -30,7 +30,6 @@ import org.bonitasoft.engine.resources.TenantResourceType; import org.bonitasoft.engine.resources.TenantResourcesService; import org.bonitasoft.engine.service.ServiceAccessor; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.bonitasoft.engine.tenant.TenantResource; import org.bonitasoft.engine.tenant.TenantStateManager; import org.bonitasoft.engine.transaction.UserTransactionService; @@ -57,8 +56,6 @@ public class TenantAdministrationAPIImplTest { @Mock private ServiceAccessor serviceAccessor; @Mock - private TenantServiceAccessor tenantServiceAccessor; - @Mock private BusinessArchiveArtifactsManager businessArchiveArtifactsManager; @Mock private TenantStateManager tenantStateManager; @@ -72,16 +69,15 @@ public class TenantAdministrationAPIImplTest { @Before public void before() throws Exception { doReturn(serviceAccessor).when(tenantManagementAPI).getServiceAccessorNoException(); - doReturn(tenantServiceAccessor).when(tenantManagementAPI).getTenantAccessor(); - doReturn(tenantResourcesService).when(tenantServiceAccessor).getTenantResourcesService(); - doReturn(userTransactionService).when(tenantServiceAccessor).getUserTransactionService(); + doReturn(serviceAccessor).when(tenantManagementAPI).getServiceAccessor(); + doReturn(tenantResourcesService).when(serviceAccessor).getTenantResourcesService(); + doReturn(userTransactionService).when(serviceAccessor).getUserTransactionService(); doAnswer(invocation -> ((Callable) invocation.getArgument(0)).call()).when(userTransactionService) .executeInTransaction(any()); - when(serviceAccessor.getTenantServiceAccessor()).thenReturn(tenantServiceAccessor); - when(tenantServiceAccessor.getBusinessArchiveArtifactsManager()).thenReturn(businessArchiveArtifactsManager); - when(tenantServiceAccessor.getTenantStateManager()).thenReturn(tenantStateManager); + when(serviceAccessor.getBusinessArchiveArtifactsManager()).thenReturn(businessArchiveArtifactsManager); + when(serviceAccessor.getTenantStateManager()).thenReturn(tenantStateManager); } @Test @@ -122,7 +118,7 @@ public void pageApi_should_be_available_in_maintenance_mode() { public void resume_should_resolve_dependencies_for_deployed_processes() throws Exception { tenantManagementAPI.resume(); - verify(businessArchiveArtifactsManager).resolveDependenciesForAllProcesses(tenantServiceAccessor); + verify(businessArchiveArtifactsManager).resolveDependenciesForAllProcesses(serviceAccessor); } @Test @@ -151,7 +147,7 @@ public void uninstallBDR_should_be_available_when_tenant_is_paused_ONLY() throws public void uninstallBusinessDataModel_should_work() throws Exception { // Given final BusinessDataModelRepository repository = mock(BusinessDataModelRepository.class); - when(tenantServiceAccessor.getBusinessDataModelRepository()).thenReturn(repository); + when(serviceAccessor.getBusinessDataModelRepository()).thenReturn(repository); when(tenantStateManager.executeTenantManagementOperation(anyString(), any(Callable.class))) .thenAnswer(invocation -> { Object[] args = invocation.getArguments(); @@ -169,7 +165,7 @@ public void uninstallBusinessDataModel_should_work() throws Exception { public void uninstallBusinessDataModel_should_throw_BusinessDataRepositoryException() throws Exception { // Given final BusinessDataModelRepository repository = mock(BusinessDataModelRepository.class); - when(tenantServiceAccessor.getBusinessDataModelRepository()).thenReturn(repository); + when(serviceAccessor.getBusinessDataModelRepository()).thenReturn(repository); when(tenantStateManager.executeTenantManagementOperation(anyString(), any(Callable.class))) .thenAnswer(invocation -> { Object[] args = invocation.getArguments(); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegateTest.java index f20a7de6d5d..251551fae37 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationAPIDelegateTest.java @@ -46,7 +46,7 @@ import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -59,7 +59,7 @@ public class LivingApplicationAPIDelegateTest { @Mock - private TenantServiceAccessor accessor; + private ServiceAccessor accessor; @Mock private ApplicationModelConverter converter; diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegateTest.java index 5bf6633a5d7..c4d399247b4 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationMenuAPIDelegateTest.java @@ -14,9 +14,7 @@ package org.bonitasoft.engine.api.impl.livingapplication; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.*; @@ -43,7 +41,7 @@ import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,7 +52,7 @@ public class LivingApplicationMenuAPIDelegateTest { @Mock - private TenantServiceAccessor accessor; + private ServiceAccessor accessor; @Mock private ApplicationMenuModelConverter convertor; diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegateTest.java index dfe154ad1e9..9f2ca0cb3ea 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/livingapplication/LivingApplicationPageAPIDelegateTest.java @@ -14,10 +14,7 @@ package org.bonitasoft.engine.api.impl.livingapplication; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.*; @@ -43,7 +40,7 @@ import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchResult; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -56,7 +53,7 @@ public class LivingApplicationPageAPIDelegateTest { @Mock - private TenantServiceAccessor accessor; + private ServiceAccessor accessor; @Mock private ApplicationPageModelConverter converter; diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegateTest.java index 429a07b8ddf..a22c9eac201 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/page/PageAPIDelegateTest.java @@ -15,22 +15,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.bonitasoft.engine.commons.Pair.pair; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; +import java.util.*; import org.bonitasoft.engine.api.impl.resolver.BusinessArchiveArtifactsManager; import org.bonitasoft.engine.api.impl.transaction.page.SearchPages; @@ -38,36 +27,15 @@ import org.bonitasoft.engine.commons.io.IOUtil; import org.bonitasoft.engine.core.form.FormMappingService; import org.bonitasoft.engine.core.form.SFormMapping; -import org.bonitasoft.engine.exception.AlreadyExistsException; -import org.bonitasoft.engine.exception.InvalidPageTokenException; -import org.bonitasoft.engine.exception.InvalidPageZipInconsistentException; -import org.bonitasoft.engine.exception.InvalidPageZipMissingAPropertyException; -import org.bonitasoft.engine.exception.InvalidPageZipMissingIndexException; -import org.bonitasoft.engine.exception.InvalidPageZipMissingPropertiesException; -import org.bonitasoft.engine.exception.RetrieveException; -import org.bonitasoft.engine.exception.UpdateException; -import org.bonitasoft.engine.page.Page; -import org.bonitasoft.engine.page.PageCreator; -import org.bonitasoft.engine.page.PageMappingService; -import org.bonitasoft.engine.page.PageNotFoundException; -import org.bonitasoft.engine.page.PageService; -import org.bonitasoft.engine.page.PageUpdater; +import org.bonitasoft.engine.exception.*; +import org.bonitasoft.engine.page.*; import org.bonitasoft.engine.page.PageUpdater.PageUpdateField; -import org.bonitasoft.engine.page.SInvalidPageTokenException; -import org.bonitasoft.engine.page.SInvalidPageZipInconsistentException; -import org.bonitasoft.engine.page.SInvalidPageZipMissingAPropertyException; -import org.bonitasoft.engine.page.SInvalidPageZipMissingIndexException; -import org.bonitasoft.engine.page.SInvalidPageZipMissingPropertiesException; -import org.bonitasoft.engine.page.SPage; -import org.bonitasoft.engine.page.SPageMapping; -import org.bonitasoft.engine.page.SPageUpdateBuilder; -import org.bonitasoft.engine.page.SPageUpdateContentBuilder; import org.bonitasoft.engine.persistence.QueryOptions; import org.bonitasoft.engine.persistence.SBonitaReadException; import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -81,15 +49,15 @@ public class PageAPIDelegateTest { private static final long PAGE_ID = 4578; - private static final Long PROCESS_ID_1 = 566446515l; - private static final Long PROCESS_ID_2 = 566746515l; + private static final Long PROCESS_ID_1 = 566446515L; + private static final Long PROCESS_ID_2 = 566746515L; private final long userId = 123L; @Rule public ExpectedException expectedException = ExpectedException.none(); @Mock SearchPages searchPages; @Mock - TenantServiceAccessor tenantAccessor; + ServiceAccessor serviceAccessor; @Mock SPage sPage; @Mock @@ -98,8 +66,6 @@ public class PageAPIDelegateTest { private PageUpdater pageUpdater; @Mock private SPageUpdateBuilder sPageUpdateBuilder; - @Mock - private SPageUpdateContentBuilder sPageUpdateContentBuilder; @Mock private PageService pageService; @@ -162,13 +128,13 @@ public void testDeletePage() throws Exception { final long pageId = 123; final SFormMapping formMapping = new SFormMapping(); formMapping.setPageMapping(new SPageMapping()); - doReturn(Collections. singletonList(formMapping)).when(formMappingService) + doReturn(Collections.singletonList(formMapping)).when(formMappingService) .searchFormMappings(any(QueryOptions.class)); pageAPIDelegate.deletePage(pageId); verify(pageService).deletePage(pageId); - verify(pageMappingService).update(any(SPageMapping.class), isNull(Long.class)); // As the page has just been deleted + verify(pageMappingService).update(any(SPageMapping.class), isNull()); // As the page has just been deleted verify(formMappingService, times(1)).searchFormMappings(any(QueryOptions.class)); } @@ -191,8 +157,8 @@ public void deletePage_update_resolution_of_related_processes() throws Exception pageAPIDelegate.deletePage(PAGE_ID); - verify(businessArchiveArtifactsManager).resolveDependencies(PROCESS_ID_1, tenantAccessor); - verify(businessArchiveArtifactsManager).resolveDependencies(PROCESS_ID_2, tenantAccessor); + verify(businessArchiveArtifactsManager).resolveDependencies(PROCESS_ID_1, serviceAccessor); + verify(businessArchiveArtifactsManager).resolveDependencies(PROCESS_ID_2, serviceAccessor); } private SFormMapping formMapping(Long processId) { @@ -204,7 +170,7 @@ private SFormMapping formMapping(Long processId) { @Test public void testDeletePages() throws Exception { // given - final List pageIds = new ArrayList(); + final List pageIds = new ArrayList<>(); for (long pageId = 0; pageId < 10; pageId++) { pageIds.add(pageId); } @@ -253,7 +219,7 @@ public void testGetPageByNameNotFound() throws Exception { @Test(expected = UpdateException.class) public void testUpdatePageWithEmptyUpdateFileShouldThrowExceptions() throws Exception { // given - final Map map = new HashMap(); + final Map map = new HashMap<>(); doReturn(map).when(pageUpdater).getFields(); // when @@ -284,7 +250,7 @@ public void testUpdatePageContent() throws Exception { @Test public void testUpdatePage() throws Exception { - final Map map = new HashMap(); + final Map map = new HashMap<>(); doReturn(sPage).when(pageAPIDelegate).constructPage(any(PageUpdater.class), anyLong()); doReturn(page).when(pageAPIDelegate).convertToPage(nullable(SPage.class)); doReturn(sPageUpdateBuilder).when(pageAPIDelegate).getPageUpdateBuilder(); @@ -292,7 +258,6 @@ public void testUpdatePage() throws Exception { // given map.put(PageUpdateField.DISPLAY_NAME, "displayname"); - map.put(PageUpdateField.NAME, "name"); map.put(PageUpdateField.DESCRIPTION, "description"); map.put(PageUpdateField.CONTENT_NAME, "content.zip"); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/BusinessDataBusinessArchiveArtifactManagerTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/BusinessDataBusinessArchiveArtifactManagerTest.java index e96a0ed50a1..731f6d5a099 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/BusinessDataBusinessArchiveArtifactManagerTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/BusinessDataBusinessArchiveArtifactManagerTest.java @@ -27,7 +27,6 @@ import org.bonitasoft.engine.core.process.definition.model.impl.SBusinessDataDefinitionImpl; import org.bonitasoft.engine.core.process.definition.model.impl.SFlowElementContainerDefinitionImpl; import org.bonitasoft.engine.core.process.definition.model.impl.SProcessDefinitionImpl; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,9 +36,6 @@ @RunWith(MockitoJUnitRunner.class) public class BusinessDataBusinessArchiveArtifactManagerTest { - @Mock - private TenantServiceAccessor tenantAccessor; - @Mock private BusinessDataRepository businessDataRepository; @@ -48,7 +44,7 @@ public class BusinessDataBusinessArchiveArtifactManagerTest { @Before public void setUp() { resolver = new BusinessDataBusinessArchiveArtifactManager(businessDataRepository); - final Set entityClassNames = new HashSet(); + final Set entityClassNames = new HashSet<>(); entityClassNames.add("com.bonitasoft.Employee"); entityClassNames.add("com.bonitasoft.LeaveRequest"); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/FormMappingAndPageArtifactManagerTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/FormMappingAndPageArtifactManagerTest.java index 471bb31177d..2aa6d9fb2dc 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/FormMappingAndPageArtifactManagerTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/resolver/FormMappingAndPageArtifactManagerTest.java @@ -21,7 +21,14 @@ import static org.mockito.Mockito.*; import static org.mockito.Mockito.nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; import org.bonitasoft.engine.bpm.bar.BusinessArchive; import org.bonitasoft.engine.bpm.bar.BusinessArchiveBuilder; @@ -42,7 +49,6 @@ import org.bonitasoft.engine.page.SPage; import org.bonitasoft.engine.page.SPageMapping; import org.bonitasoft.engine.persistence.SBonitaReadException; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.bonitasoft.engine.session.SessionService; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; import org.junit.Before; @@ -64,13 +70,11 @@ public class FormMappingAndPageArtifactManagerTest { public static final String CUSTOMPAGE_STEP2_ZIP = "custompage_step2.zip"; public static final String DISPLAY_NAME = "display name"; public static final String DESCRIPTION = "description"; - private java.util.Map ressources; + private java.util.Map resources; @Mock private Properties properties; private FormMappingAndPageArtifactManager formMappingAndPageArtifactManager; @Mock - private TenantServiceAccessor tenantServiceAccessor; - @Mock private BusinessArchive businessArchive; @Mock private SProcessDefinition sDefinition; @@ -101,13 +105,13 @@ public void before() { doReturn(PROCESS_DEFINITION_ID).when(sDefinition).getId(); - ressources = new HashMap<>(); - ressources.put("resources/customPages/custompage_step1.zip", CONTENT1); - ressources.put("resources/customPages/custompage_step2.zip", CONTENT2); - ressources.put("resources/otherResource/data.txt", "data".getBytes()); + resources = new HashMap<>(); + resources.put("resources/customPages/custompage_step1.zip", CONTENT1); + resources.put("resources/customPages/custompage_step2.zip", CONTENT2); + resources.put("resources/otherResource/data.txt", "data".getBytes()); - doReturn(ressources).when(businessArchive).getResources(); - doReturn(14l).when(sessionService).getLoggedUserFromSession(sessionAccessor); + doReturn(resources).when(businessArchive).getResources(); + doReturn(14L).when(sessionService).getLoggedUserFromSession(sessionAccessor); when(businessArchive.getResources(anyString())).thenCallRealMethod(); } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/AdvancedStartProcessCommandTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/AdvancedStartProcessCommandTest.java index 2c96c3f93d6..083f8970ff4 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/AdvancedStartProcessCommandTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/AdvancedStartProcessCommandTest.java @@ -29,7 +29,7 @@ import org.bonitasoft.engine.core.process.definition.model.SProcessDefinition; import org.bonitasoft.engine.core.process.definition.model.SUserTaskDefinition; import org.bonitasoft.engine.core.process.definition.model.event.SBoundaryEventDefinition; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,7 +45,7 @@ public class AdvancedStartProcessCommandTest { private static final long PROCESS_DEFINITION_ID = 1234L; @Mock - private TenantServiceAccessor serviceAccessor; + private ServiceAccessor serviceAccessor; @Mock private ProcessDefinitionService processDefinitionService; diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/ExecuteBDMQueryCommandTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/ExecuteBDMQueryCommandTest.java index e7433388f59..ba05fc6b06d 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/ExecuteBDMQueryCommandTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/ExecuteBDMQueryCommandTest.java @@ -25,7 +25,7 @@ import org.bonitasoft.engine.business.data.BusinessDataRepository; import org.bonitasoft.engine.operation.pojo.Employee; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,11 +46,11 @@ public class ExecuteBDMQueryCommandTest { private BusinessDataRepository bdmRepository; @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Before public void setUp() { - when(tenantServiceAccessor.getBusinessDataRepository()).thenReturn(bdmRepository); + when(serviceAccessor.getBusinessDataRepository()).thenReturn(bdmRepository); } @Test @@ -66,7 +66,7 @@ public void execute_should_return_an_instance() throws Exception { .build(); // when - byte[] result = (byte[]) command.execute(parameters, tenantServiceAccessor); + byte[] result = (byte[]) command.execute(parameters, serviceAccessor); // then assertThat(new String(result)).isEqualTo( @@ -85,7 +85,7 @@ public void execute_should_return_an_instance_when_the_returnsList_parameter_is_ .build(); // when - byte[] result = (byte[]) command.execute(parameters, tenantServiceAccessor); + byte[] result = (byte[]) command.execute(parameters, serviceAccessor); // then assertThat(new String(result)).isEqualTo( @@ -107,7 +107,7 @@ public void execute_should_return_an_list() throws Exception { .build(); // when - byte[] result = (byte[]) command.execute(parameters, tenantServiceAccessor); + byte[] result = (byte[]) command.execute(parameters, serviceAccessor); // then assertThat(new String(result)).as("json result").isEqualTo( @@ -122,7 +122,7 @@ public void execute_should_fail_if_the_query_name_is_null() throws Exception { .build(); // when - Throwable thrown = catchThrowable(() -> command.execute(parameters, tenantServiceAccessor)); + Throwable thrown = catchThrowable(() -> command.execute(parameters, serviceAccessor)); // then assertThat(thrown).isInstanceOf(SCommandParameterizationException.class) @@ -137,7 +137,7 @@ public void execute_should_fail_if_the_return_type_is_empty() throws Exception { .build(); // when - Throwable thrown = catchThrowable(() -> command.execute(parameters, tenantServiceAccessor)); + Throwable thrown = catchThrowable(() -> command.execute(parameters, serviceAccessor)); // then assertThat(thrown).isInstanceOf(SCommandParameterizationException.class) diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdCommandTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdCommandTest.java index 6f415e7b35c..068f266bd9f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdCommandTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdCommandTest.java @@ -19,12 +19,11 @@ import java.util.HashMap; import java.util.Map; -import org.bonitasoft.engine.business.data.BusinessDataRepository; import org.bonitasoft.engine.business.data.BusinessDataService; import org.bonitasoft.engine.business.data.SBusinessDataNotFoundException; import org.bonitasoft.engine.business.data.SBusinessDataRepositoryException; import org.bonitasoft.engine.operation.pojo.Travel; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,10 +44,7 @@ public class GetBusinessDataByIdCommandTest { private GetBusinessDataByIdCommand command; @Mock - private BusinessDataRepository bdrService; - - @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private BusinessDataService businessDataService; @@ -62,13 +58,13 @@ public void setUp() throws Exception { parameters.put(GetBusinessDataByIdCommand.BUSINESS_DATA_ID, PARAMETER_IDENTIFIER); parameters.put(GetBusinessDataByIdCommand.ENTITY_CLASS_NAME, PARAMETER_CLASS_NAME); parameters.put(BusinessDataCommandField.BUSINESS_DATA_URI_PATTERN, PARAMETER_BUSINESSDATA_CLASS_URI_VALUE); - when(tenantServiceAccessor.getBusinessDataService()).thenReturn(businessDataService); + when(serviceAccessor.getBusinessDataService()).thenReturn(businessDataService); } @Test public void executeCommandWithEntity() throws Exception { //when - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); //then verify(businessDataService).getJsonEntity(PARAMETER_CLASS_NAME, PARAMETER_IDENTIFIER, @@ -83,7 +79,7 @@ public void executeCommandWithEntityShloudThrowException() throws Exception { PARAMETER_BUSINESSDATA_CLASS_URI_VALUE); //when then exception - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); } @Test(expected = SCommandExecutionException.class) @@ -96,7 +92,7 @@ public void executeCommandWithChildEntityShouldThrowException() throws Exception PARAMETER_BUSINESSDATA_CLASS_URI_VALUE); //when then exception - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); } @Test @@ -105,7 +101,7 @@ public void executeCommandWithEmptyChildName() throws Exception { parameters.put(GetBusinessDataByIdCommand.BUSINESS_DATA_CHILD_NAME, ""); //when - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); //then verify(businessDataService).getJsonEntity(PARAMETER_CLASS_NAME, PARAMETER_IDENTIFIER, @@ -118,7 +114,7 @@ public void executeCommandWithChildEntity() throws Exception { parameters.put(GetBusinessDataByIdCommand.BUSINESS_DATA_CHILD_NAME, PARAMETER_CHILDNAME); //when - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); //then verify(businessDataService).getJsonChildEntity(PARAMETER_CLASS_NAME, PARAMETER_IDENTIFIER, PARAMETER_CHILDNAME, diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdsCommandTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdsCommandTest.java index 634123b2b37..055e4cf0dd6 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdsCommandTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByIdsCommandTest.java @@ -21,11 +21,10 @@ import java.util.List; import java.util.Map; -import org.bonitasoft.engine.business.data.BusinessDataRepository; import org.bonitasoft.engine.business.data.BusinessDataService; import org.bonitasoft.engine.business.data.SBusinessDataRepositoryException; import org.bonitasoft.engine.operation.pojo.Travel; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,10 +49,7 @@ public class GetBusinessDataByIdsCommandTest { private GetBusinessDataByIdsCommand command; @Mock - private BusinessDataRepository bdrService; - - @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private BusinessDataService businessDataService; @@ -67,13 +63,13 @@ public void setUp() throws Exception { parameters.put(GetBusinessDataByIdsCommand.BUSINESS_DATA_IDS, (Serializable) identifers); parameters.put(GetBusinessDataByIdsCommand.ENTITY_CLASS_NAME, PARAMETER_CLASS_NAME); parameters.put(BusinessDataCommandField.BUSINESS_DATA_URI_PATTERN, PARAMETER_BUSINESSDATA_CLASS_URI_VALUE); - when(tenantServiceAccessor.getBusinessDataService()).thenReturn(businessDataService); + when(serviceAccessor.getBusinessDataService()).thenReturn(businessDataService); } @Test public void executeCommandWithEntities() throws Exception { //when - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); //then verify(businessDataService).getJsonEntities(PARAMETER_CLASS_NAME, identifers, @@ -88,7 +84,7 @@ public void executeCommandWithEntitiesShloudThrowException() throws Exception { PARAMETER_BUSINESSDATA_CLASS_URI_VALUE); //when then exception - command.execute(parameters, tenantServiceAccessor); + command.execute(parameters, serviceAccessor); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByQueryCommandTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByQueryCommandTest.java index dad599c55b8..898b187e7c3 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByQueryCommandTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/command/GetBusinessDataByQueryCommandTest.java @@ -13,17 +13,16 @@ **/ package org.bonitasoft.engine.command; -import static org.assertj.core.api.Fail.fail; +import static org.junit.Assert.fail; import static org.mockito.Mockito.*; import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import org.bonitasoft.engine.business.data.BusinessDataRepository; import org.bonitasoft.engine.business.data.BusinessDataService; import org.bonitasoft.engine.business.data.SBusinessDataRepositoryException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,10 +41,7 @@ public class GetBusinessDataByQueryCommandTest { private GetBusinessDataByQueryCommand command; @Mock - private BusinessDataRepository bdrService; - - @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private BusinessDataService businessDataService; @@ -57,10 +53,10 @@ public class GetBusinessDataByQueryCommandTest { public void setUp() throws Exception { command = new GetBusinessDataByQueryCommand(); - queryParameters = new HashMap(); + queryParameters = new HashMap<>(); queryParameters.put("param", "value"); - commandParameters = new HashMap(); + commandParameters = new HashMap<>(); commandParameters.put(GetBusinessDataByQueryCommand.QUERY_NAME, PARAMETER_QUERY_NAME); commandParameters.put(GetBusinessDataByQueryCommand.ENTITY_CLASS_NAME, PARAMETER_RETURN_TYPE); commandParameters.put(GetBusinessDataByQueryCommand.MAX_RESULTS, PARAMETER_MAX_RESULTS); @@ -68,13 +64,13 @@ public void setUp() throws Exception { commandParameters.put(GetBusinessDataByQueryCommand.QUERY_PARAMETERS, (Serializable) queryParameters); commandParameters.put(BusinessDataCommandField.BUSINESS_DATA_URI_PATTERN, PARAMETER_BUSINESS_DATA_CLASS_URI_VALUE); - when(tenantServiceAccessor.getBusinessDataService()).thenReturn(businessDataService); + when(serviceAccessor.getBusinessDataService()).thenReturn(businessDataService); } @Test public void executeCommand_should_call_service() throws Exception { //when - command.execute(commandParameters, tenantServiceAccessor); + command.execute(commandParameters, serviceAccessor); //then verify(businessDataService).getJsonQueryEntities(PARAMETER_RETURN_TYPE, PARAMETER_QUERY_NAME, queryParameters, @@ -92,7 +88,7 @@ public void executeCommand_should_throw_exception() throws Exception { PARAMETER_BUSINESS_DATA_CLASS_URI_VALUE); //when then exception - command.execute(commandParameters, tenantServiceAccessor); + command.execute(commandParameters, serviceAccessor); } @Test @@ -117,7 +113,7 @@ private void verify_command_checks_parameter(String mandatoryParameter) throws E commandParameters.remove(mandatoryParameter); //when then exception - command.execute(commandParameters, tenantServiceAccessor); + command.execute(commandParameters, serviceAccessor); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivityTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivityTest.java index 6ea22898071..6b1d283ed35 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivityTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorOfActivityTest.java @@ -26,7 +26,7 @@ import org.bonitasoft.engine.core.process.instance.model.STaskPriority; import org.bonitasoft.engine.core.process.instance.model.SUserTaskInstance; import org.bonitasoft.engine.core.process.instance.model.event.SThrowEventInstance; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,7 +39,7 @@ public class ExecuteConnectorOfActivityTest { private Map context; @Mock - private TenantServiceAccessor accessor; + private ServiceAccessor accessor; @Mock private ActivityInstanceService activityInstanceService; @@ -50,7 +50,7 @@ public class ExecuteConnectorOfActivityTest { @Before public void setUp() { context = new HashMap(); - context.put(TenantAwareBonitaWork.TENANT_ACCESSOR, accessor); + context.put(TenantAwareBonitaWork.SERVICE_ACCESSOR, accessor); when(accessor.getActivityInstanceService()).thenReturn(activityInstanceService); when(accessor.getEventInstanceService()).thenReturn(eventService); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWorkTest.java index 4ca1299d876..88ea3df0795 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteConnectorWorkTest.java @@ -17,10 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Collections; import java.util.HashMap; @@ -45,7 +42,7 @@ import org.bonitasoft.engine.core.process.instance.model.event.SThrowEventInstance; import org.bonitasoft.engine.lock.BonitaLock; import org.bonitasoft.engine.lock.LockService; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.tracking.TimeTracker; import org.bonitasoft.engine.transaction.UserTransactionService; import org.junit.Before; @@ -73,21 +70,22 @@ private interface EvaluateOutputCallable { private static final long TENANT_ID = 125L; @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private LockService lockService; @Mock private UserTransactionService userTransactionService; @Mock private ConnectorInstanceService connectorInstanceService; - private SConnectorDefinition sConnectorDefinition = new SConnectorDefinitionImpl("testDef", "connectorDef", "1.0", + private final SConnectorDefinition sConnectorDefinition = new SConnectorDefinitionImpl("testDef", "connectorDef", + "1.0", ConnectorEvent.ON_ENTER); private EvaluateOutputCallable evaluateOutput = () -> { }; - private SExpressionContext expressionContext = new SExpressionContext(PROCESS_INSTANCE_ID, "PROCESS", + private final SExpressionContext expressionContext = new SExpressionContext(PROCESS_INSTANCE_ID, "PROCESS", PROCESS_DEFINITION_ID); - private Map workContext = new HashMap<>(); - private ExecuteConnectorWork executeConnectorWork = new ExecuteConnectorWork(PROCESS_DEFINITION_ID, + private final Map workContext = new HashMap<>(); + private final ExecuteConnectorWork executeConnectorWork = new ExecuteConnectorWork(PROCESS_DEFINITION_ID, CONNECTOR_INSTANCE_ID, CONNECTOR_NAME, expressionContext, PROCESS_INSTANCE_ID) { @Override @@ -135,17 +133,17 @@ public String getDescription() { @Before public void before() throws Exception { - workContext.put(TenantAwareBonitaWork.TENANT_ACCESSOR, tenantServiceAccessor); - doReturn(lockService).when(tenantServiceAccessor).getLockService(); - doReturn(userTransactionService).when(tenantServiceAccessor).getUserTransactionService(); + workContext.put(TenantAwareBonitaWork.SERVICE_ACCESSOR, serviceAccessor); + doReturn(lockService).when(serviceAccessor).getLockService(); + doReturn(userTransactionService).when(serviceAccessor).getUserTransactionService(); doAnswer(args -> ((Callable) args.getArgument(0)).call()).when(userTransactionService) .executeInTransaction(any()); executeConnectorWork.setTenantId(TENANT_ID); - doReturn(classLoaderService).when(tenantServiceAccessor).getClassLoaderService(); + doReturn(classLoaderService).when(serviceAccessor).getClassLoaderService(); doReturn(this.getClass().getClassLoader()).when(classLoaderService).getClassLoader(any()); - doReturn(timeTracker).when(tenantServiceAccessor).getTimeTracker(); - doReturn(connectorService).when(tenantServiceAccessor).getConnectorService(); - doReturn(connectorInstanceService).when(tenantServiceAccessor).getConnectorInstanceService(); + doReturn(timeTracker).when(serviceAccessor).getTimeTracker(); + doReturn(connectorService).when(serviceAccessor).getConnectorService(); + doReturn(connectorInstanceService).when(serviceAccessor).getConnectorInstanceService(); } @Test diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWorkTest.java index 9dbb866e3c7..35932040a0b 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteFlowNodeWorkTest.java @@ -22,7 +22,7 @@ import org.bonitasoft.engine.core.process.instance.api.ActivityInstanceService; import org.bonitasoft.engine.core.process.instance.model.SUserTaskInstance; import org.bonitasoft.engine.execution.FlowNodeExecutor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.work.SWorkPreconditionException; import org.junit.Before; import org.junit.Rule; @@ -41,7 +41,7 @@ public class ExecuteFlowNodeWorkTest { public static final long FLOW_NODE_INSTANCE_ID = 564325L; public static final long PROCESS_INSTANCE_ID = 34552L; @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private ActivityInstanceService activityInstanceService; @Mock @@ -54,9 +54,9 @@ public class ExecuteFlowNodeWorkTest { @Before public void before() throws Exception { - context = Collections.singletonMap(TenantAwareBonitaWork.TENANT_ACCESSOR, tenantServiceAccessor); - doReturn(activityInstanceService).when(tenantServiceAccessor).getActivityInstanceService(); - doReturn(flowNodeExecutor).when(tenantServiceAccessor).getFlowNodeExecutor(); + context = Collections.singletonMap(TenantAwareBonitaWork.SERVICE_ACCESSOR, serviceAccessor); + doReturn(activityInstanceService).when(serviceAccessor).getActivityInstanceService(); + doReturn(flowNodeExecutor).when(serviceAccessor).getFlowNodeExecutor(); sHumanTaskInstance = new SUserTaskInstance(); sHumanTaskInstance.setId(FLOW_NODE_INSTANCE_ID); doReturn(sHumanTaskInstance).when(activityInstanceService).getFlowNodeInstance(FLOW_NODE_INSTANCE_ID); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWorkTest.java index 63d51b58b85..636eead9638 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/ExecuteMessageCoupleWorkTest.java @@ -13,12 +13,8 @@ **/ package org.bonitasoft.engine.execution.work; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; import java.util.HashMap; import java.util.Map; @@ -31,7 +27,7 @@ import org.bonitasoft.engine.data.instance.api.DataInstanceContainer; import org.bonitasoft.engine.data.instance.api.DataInstanceService; import org.bonitasoft.engine.execution.event.EventsHandler; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.junit.Before; import org.junit.Rule; @@ -51,7 +47,7 @@ public class ExecuteMessageCoupleWorkTest { @Mock private EventsHandler eventsHandler; @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private EventInstanceService eventInstanceService; @Mock @@ -60,24 +56,25 @@ public class ExecuteMessageCoupleWorkTest { private UserTransactionService userTransactionService; @Captor private ArgumentCaptor> callableArgumentCaptor; - private Map context = new HashMap<>(); + private final Map context = new HashMap<>(); - private ExecuteMessageCoupleWork executeMessageCoupleWork = new ExecuteMessageCoupleWork(MESSAGE_INSTANCE_ID, + private final ExecuteMessageCoupleWork executeMessageCoupleWork = new ExecuteMessageCoupleWork(MESSAGE_INSTANCE_ID, WAITING_MESSAGE_ID); - private SWaitingMessageEvent waitingMessageEvent = new SWaitingMessageEvent(SBPMEventType.BOUNDARY_EVENT, 4243252L, + private final SWaitingMessageEvent waitingMessageEvent = new SWaitingMessageEvent(SBPMEventType.BOUNDARY_EVENT, + 4243252L, "Process", 5435312, "flownode", "message"); - private SMessageInstance messageInstance = new SMessageInstance("message", "Process", "flowNode", 4243252L, + private final SMessageInstance messageInstance = new SMessageInstance("message", "Process", "flowNode", 4243252L, "flownode"); @Before public void before() { waitingMessageEvent.setId(WAITING_MESSAGE_ID); messageInstance.setId(MESSAGE_INSTANCE_ID); - context.put(TenantAwareBonitaWork.TENANT_ACCESSOR, tenantServiceAccessor); - doReturn(eventsHandler).when(tenantServiceAccessor).getEventsHandler(); - doReturn(eventInstanceService).when(tenantServiceAccessor).getEventInstanceService(); - doReturn(dataInstanceService).when(tenantServiceAccessor).getDataInstanceService(); - doReturn(userTransactionService).when(tenantServiceAccessor).getUserTransactionService(); + context.put(TenantAwareBonitaWork.SERVICE_ACCESSOR, serviceAccessor); + doReturn(eventsHandler).when(serviceAccessor).getEventsHandler(); + doReturn(eventInstanceService).when(serviceAccessor).getEventInstanceService(); + doReturn(dataInstanceService).when(serviceAccessor).getDataInstanceService(); + doReturn(userTransactionService).when(serviceAccessor).getUserTransactionService(); } @Test diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/InSessionBonitaWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/InSessionBonitaWorkTest.java index e12898383b0..70599e764ef 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/InSessionBonitaWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/InSessionBonitaWorkTest.java @@ -16,12 +16,11 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.*; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.bonitasoft.engine.commons.exceptions.SBonitaException; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.sessionaccessor.SessionAccessor; import org.bonitasoft.engine.work.BonitaWork; import org.junit.Before; @@ -36,24 +35,24 @@ public class InSessionBonitaWorkTest { @Mock private BonitaWork wrappedWork; @Mock - private TenantServiceAccessor tenantAccessor; + private ServiceAccessor serviceAccessor; @Mock private SessionAccessor sessionAccessor; - private InSessionBonitaWork txBonitawork; + private InSessionBonitaWork txBonitaWork; @Before public void before() { - txBonitawork = spy(new InSessionBonitaWork(wrappedWork)); + txBonitaWork = spy(new InSessionBonitaWork(wrappedWork)); - when(tenantAccessor.getSessionAccessor()).thenReturn(sessionAccessor); - doReturn(tenantAccessor).when(txBonitawork).getTenantAccessor(); + when(serviceAccessor.getSessionAccessor()).thenReturn(sessionAccessor); + doReturn(serviceAccessor).when(txBonitaWork).getServiceAccessor(); } @Test public void testWork() throws Exception { final Map singletonMap = new HashMap<>(); - txBonitawork.work(singletonMap); + txBonitaWork.work(singletonMap); verify(wrappedWork, times(1)).work(singletonMap); } @@ -61,7 +60,7 @@ public void testWork() throws Exception { public void testWorkFailureIsHandled() throws Throwable { final Map singletonMap = new HashMap<>(); final Exception e = new Exception(); - txBonitawork.handleFailure(e, singletonMap); + txBonitaWork.handleFailure(e, singletonMap); verify(wrappedWork).handleFailure(e, singletonMap); } @@ -71,61 +70,61 @@ public void testFailureHandlingFail() throws Throwable { final Exception e1 = new Exception(); final Exception e2 = new Exception(); doThrow(e2).when(wrappedWork).handleFailure(e1, singletonMap); - txBonitawork.handleFailure(e1, singletonMap); + txBonitaWork.handleFailure(e1, singletonMap); verify(wrappedWork).handleFailure(e1, singletonMap); } @Test public void putInMap() throws Exception { final Map singletonMap = new HashMap<>(); - txBonitawork.work(singletonMap); - assertEquals(tenantAccessor, singletonMap.get("tenantAccessor")); + txBonitaWork.work(singletonMap); + assertEquals(serviceAccessor, singletonMap.get("serviceAccessor")); } @Test public void getDescription() { when(wrappedWork.getDescription()).thenReturn("The description"); - assertEquals("The description", txBonitawork.getDescription()); + assertEquals("The description", txBonitaWork.getDescription()); } @Test public void getRecoveryProcedure() { when(wrappedWork.getRecoveryProcedure()).thenReturn("recoveryProcedure"); - assertEquals("recoveryProcedure", txBonitawork.getRecoveryProcedure()); + assertEquals("recoveryProcedure", txBonitaWork.getRecoveryProcedure()); } @Test public void handleFailure() throws Throwable { - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + final Map context = Map.of("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); verify(wrappedWork).handleFailure(e, context); } @Test public void getTenantId() { - when(wrappedWork.getTenantId()).thenReturn(12l); - assertEquals(12, txBonitawork.getTenantId()); + when(wrappedWork.getTenantId()).thenReturn(12L); + assertEquals(12, txBonitaWork.getTenantId()); } @Test public void setTenantId() { - txBonitawork.setTenantId(12l); - verify(wrappedWork).setTenantId(12l); + txBonitaWork.setTenantId(12L); + verify(wrappedWork).setTenantId(12L); } @Test public void getWrappedWork() { - assertEquals(wrappedWork, txBonitawork.getWrappedWork()); + assertEquals(wrappedWork, txBonitaWork.getWrappedWork()); } @Test public void testToString() { when(wrappedWork.toString()).thenReturn("the to string"); - assertEquals("the to string", txBonitawork.toString()); + assertEquals("the to string", txBonitaWork.toString()); } @Test(expected = Exception.class) @@ -133,7 +132,7 @@ public void should_throw_the_exception_of_wrapped_work() throws Throwable { final Map context = new HashMap<>(); final Exception e = new Exception(); doThrow(e).when(wrappedWork).work(context); - txBonitawork.work(context); + txBonitaWork.work(context); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWorkTest.java index 14de1cae2f9..ab8249c135f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/LockProcessInstanceWorkTest.java @@ -23,7 +23,7 @@ import org.bonitasoft.engine.lock.BonitaLock; import org.bonitasoft.engine.lock.LockService; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.work.BonitaWork; import org.bonitasoft.engine.work.LockTimeoutException; import org.bonitasoft.engine.work.WorkExecutorService; @@ -40,23 +40,21 @@ public class LockProcessInstanceWorkTest { private LockProcessInstanceWork lockProcessInstanceWork; - private TenantServiceAccessor tenantAccessor; + private ServiceAccessor serviceAccessor; private LockService lockService; - private WorkExecutorService workService; - private static final long TENANT_ID = 1; @Before public void before() { lockProcessInstanceWork = new LockProcessInstanceWork(wrappedWork, processInstanceId); when(wrappedWork.getTenantId()).thenReturn(TENANT_ID); - tenantAccessor = mock(TenantServiceAccessor.class); + serviceAccessor = mock(ServiceAccessor.class); lockService = mock(LockService.class); - workService = mock(WorkExecutorService.class); - when(tenantAccessor.getLockService()).thenReturn(lockService); - when(tenantAccessor.getWorkExecutorService()).thenReturn(workService); + WorkExecutorService workService = mock(WorkExecutorService.class); + when(serviceAccessor.getLockService()).thenReturn(lockService); + when(serviceAccessor.getWorkExecutorService()).thenReturn(workService); } @Test @@ -65,7 +63,7 @@ public void testWork() throws Exception { when(lockService.tryLock(eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID))) .thenReturn( bonitaLock); - Map singletonMap = Collections. singletonMap("tenantAccessor", tenantAccessor); + Map singletonMap = Collections.singletonMap("serviceAccessor", serviceAccessor); lockProcessInstanceWork.work(singletonMap); verify(lockService, times(1)).tryLock(eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID)); @@ -87,7 +85,7 @@ public void getRecoveryProcedure() { @Test public void handleFailure() throws Throwable { - Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + Map context = Collections.singletonMap("serviceAccessor", serviceAccessor); Exception e = new Exception(); lockProcessInstanceWork.handleFailure(e, context); verify(wrappedWork).handleFailure(e, context); @@ -117,13 +115,13 @@ public void testToString() { } @Test(expected = LockTimeoutException.class) - public void should_thow_exception_when_unable_to_lock() throws Exception { + public void should_throw_exception_when_unable_to_lock() throws Exception { // On first try to lock : exception to reschedule the work // On the second try : return a correct lock when(lockService.tryLock(eq(processInstanceId), eq(PROCESS), eq(20L), eq(TimeUnit.MILLISECONDS), eq(TENANT_ID))) .thenReturn(null); - lockProcessInstanceWork.work(Collections.singletonMap("tenantAccessor", tenantAccessor)); + lockProcessInstanceWork.work(Collections.singletonMap("serviceAccessor", serviceAccessor)); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWorkTest.java index d2760fe7d87..b6b4c9f25ff 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/NotifyChildFinishedWorkTest.java @@ -14,9 +14,7 @@ package org.bonitasoft.engine.execution.work; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import java.util.Collections; import java.util.Map; @@ -27,7 +25,7 @@ import org.bonitasoft.engine.core.process.instance.api.exceptions.SFlowNodeNotFoundException; import org.bonitasoft.engine.core.process.instance.model.SAutomaticTaskInstance; import org.bonitasoft.engine.execution.ContainerRegistry; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.work.SWorkPreconditionException; import org.junit.Before; import org.junit.Rule; @@ -44,7 +42,7 @@ public class NotifyChildFinishedWorkTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private ActivityInstanceService flowNodeInstanceService; @Mock @@ -60,10 +58,10 @@ public class NotifyChildFinishedWorkTest { @Before public void before() throws SClassLoaderException { doReturn(this.getClass().getClassLoader()).when(classLoaderService).getClassLoader(any()); - context = Collections.singletonMap(TenantAwareBonitaWork.TENANT_ACCESSOR, tenantServiceAccessor); + context = Collections.singletonMap(TenantAwareBonitaWork.SERVICE_ACCESSOR, serviceAccessor); - doReturn(classLoaderService).when(tenantServiceAccessor).getClassLoaderService(); - doReturn(flowNodeInstanceService).when(tenantServiceAccessor).getActivityInstanceService(); + doReturn(classLoaderService).when(serviceAccessor).getClassLoaderService(); + doReturn(flowNodeInstanceService).when(serviceAccessor).getActivityInstanceService(); } @Test @@ -117,7 +115,7 @@ public void should_throw_precondition_exception_when_flownode_changed() throws E public void should_notify_child_finished_if_flow_node_is_completed() throws Exception { notifyChildFinishedWork = new NotifyChildFinishedWork(PROCESS_DEFINITION_ID, FLOW_NODE_INSTANCE_ID, 2, false, false, false); - doReturn(containerRegistry).when(tenantServiceAccessor).getContainerRegistry(); + doReturn(containerRegistry).when(serviceAccessor).getContainerRegistry(); SAutomaticTaskInstance flowNodeInstance = new SAutomaticTaskInstance(); flowNodeInstance.setTerminal(true); flowNodeInstance.setStateId(2); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/TxBonitaWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/TxBonitaWorkTest.java index 5acbbdb8879..3313fa77fe8 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/TxBonitaWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/TxBonitaWorkTest.java @@ -20,7 +20,7 @@ import java.util.Collections; import java.util.Map; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.transaction.UserTransactionService; import org.bonitasoft.engine.work.BonitaWork; import org.junit.Before; @@ -32,22 +32,21 @@ public class TxBonitaWorkTest { private TxBonitaWork txBonitawork; - private TenantServiceAccessor tenantAccessor; + private ServiceAccessor serviceAccessor; private UserTransactionService userTransactionService; @Before public void before() { txBonitawork = new TxBonitaWork(wrappedWork); - tenantAccessor = mock(TenantServiceAccessor.class); + serviceAccessor = mock(ServiceAccessor.class); userTransactionService = mock(UserTransactionService.class); - when(tenantAccessor.getUserTransactionService()).thenReturn(userTransactionService); + when(serviceAccessor.getUserTransactionService()).thenReturn(userTransactionService); } - @SuppressWarnings("unchecked") @Test public void testWork() throws Exception { - Map singletonMap = Collections. singletonMap("tenantAccessor", tenantAccessor); + Map singletonMap = Collections.singletonMap("serviceAccessor", serviceAccessor); txBonitawork.work(singletonMap); verify(userTransactionService, times(1)).executeInTransaction(any()); } @@ -66,7 +65,7 @@ public void getRecoveryProcedure() { @Test public void handleFailure() throws Throwable { - Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + Map context = Collections.singletonMap("serviceAccessor", serviceAccessor); Exception e = new Exception(); txBonitawork.handleFailure(e, context); verify(wrappedWork).handleFailure(e, context); @@ -74,14 +73,14 @@ public void handleFailure() throws Throwable { @Test public void getTenantId() { - when(wrappedWork.getTenantId()).thenReturn(12l); + when(wrappedWork.getTenantId()).thenReturn(12L); assertEquals(12, txBonitawork.getTenantId()); } @Test public void setTenantId() { - txBonitawork.setTenantId(12l); - verify(wrappedWork).setTenantId(12l); + txBonitawork.setTenantId(12L); + verify(wrappedWork).setTenantId(12L); } @Test diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/AbstractContextWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/AbstractContextWorkTest.java index 7460f769e9c..32b925523f6 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/AbstractContextWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/AbstractContextWorkTest.java @@ -21,10 +21,7 @@ import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.execution.work.TransactionServiceForTest; -import org.bonitasoft.engine.incident.IncidentService; -import org.bonitasoft.engine.service.TenantServiceAccessor; -import org.bonitasoft.engine.session.SessionService; -import org.bonitasoft.engine.sessionaccessor.SessionAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -39,69 +36,60 @@ public abstract class AbstractContextWorkTest { protected TxInHandleFailureWrappingWork wrappedWork; @Mock - protected TenantServiceAccessor tenantAccessor; - - @Mock - private SessionService sessionService; - - @Mock - private IncidentService incidentService; - - @Mock - private SessionAccessor sessionAccessor; + protected ServiceAccessor serviceAccessor; @Spy private TransactionServiceForTest transactionService; - protected TxInHandleFailureWrappingWork txBonitawork; + protected TxInHandleFailureWrappingWork txBonitaWork; @Before public void before() throws SBonitaException { - doReturn(transactionService).when(tenantAccessor).getUserTransactionService(); + doReturn(transactionService).when(serviceAccessor).getUserTransactionService(); - doReturn("The description").when(txBonitawork).getDescription(); + doReturn("The description").when(txBonitaWork).getDescription(); } @Test public void work() throws Exception { - final Map singletonMap = new HashMap(); - txBonitawork.work(singletonMap); + final Map singletonMap = new HashMap<>(); + txBonitaWork.work(singletonMap); verify(wrappedWork, times(1)).work(singletonMap); } @Test public void getDescription() { - assertEquals("The description", txBonitawork.getDescription()); + assertEquals("The description", txBonitaWork.getDescription()); } @Test public void getRecoveryProcedure() { when(wrappedWork.getRecoveryProcedure()).thenReturn("recoveryProcedure"); - assertEquals("recoveryProcedure", txBonitawork.getRecoveryProcedure()); + assertEquals("recoveryProcedure", txBonitaWork.getRecoveryProcedure()); } @Test public void getTenantId() { - when(wrappedWork.getTenantId()).thenReturn(12l); - assertEquals(12, txBonitawork.getTenantId()); + when(wrappedWork.getTenantId()).thenReturn(12L); + assertEquals(12, txBonitaWork.getTenantId()); } @Test public void setTenantId() { - txBonitawork.setTenantId(12l); - verify(wrappedWork).setTenantId(12l); + txBonitaWork.setTenantId(12L); + verify(wrappedWork).setTenantId(12L); } @Test public void getWrappedWork() { - assertEquals(wrappedWork, txBonitawork.getWrappedWork()); + assertEquals(wrappedWork, txBonitaWork.getWrappedWork()); } @Test public void testToString() { when(wrappedWork.toString()).thenReturn("the to string"); - assertEquals("the to string", txBonitawork.toString()); + assertEquals("the to string", txBonitaWork.toString()); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ConnectorDefinitionAndInstanceContextWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ConnectorDefinitionAndInstanceContextWorkTest.java index d45c0ba6ce4..8637c54924f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ConnectorDefinitionAndInstanceContextWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ConnectorDefinitionAndInstanceContextWorkTest.java @@ -13,20 +13,17 @@ **/ package org.bonitasoft.engine.execution.work.failurewrapping; +import static java.util.Collections.singletonMap; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; -import java.util.Collections; import java.util.Map; import org.bonitasoft.engine.bpm.connector.ConnectorEvent; import org.bonitasoft.engine.commons.exceptions.SBonitaException; -import org.bonitasoft.engine.core.process.definition.ProcessDefinitionService; -import org.bonitasoft.engine.core.process.definition.model.SProcessDefinitionDeployInfo; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; /** @@ -42,29 +39,23 @@ public class ConnectorDefinitionAndInstanceContextWorkTest extends AbstractConte private static final long CONNECTOR_INSTANCE_ID = 10L; - @Mock - private ProcessDefinitionService processDefinitionService; - - @Mock - private SProcessDefinitionDeployInfo sProcessDefinitionDeployInfo; - @Override @Before public void before() throws SBonitaException { - txBonitawork = spy(new ConnectorDefinitionAndInstanceContextWork(wrappedWork, CONNECTOR_DEFINITION_NAME, + txBonitaWork = spy(new ConnectorDefinitionAndInstanceContextWork(wrappedWork, CONNECTOR_DEFINITION_NAME, CONNECTOR_INSTANCE_ID)); super.before(); } @Test public void handleFailureWithNameAndId() throws Throwable { - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + final Map context = singletonMap("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("CONNECTOR_IMPLEMENTATION_CLASS_NAME=" + CONNECTOR_DEFINITION_NAME)); assertTrue(e.getMessage().contains("CONNECTOR_INSTANCE_ID=" + CONNECTOR_INSTANCE_ID)); @@ -73,16 +64,16 @@ public void handleFailureWithNameAndId() throws Throwable { @Test public void handleFailureWithNameAndIdAndActivationEvent() throws Throwable { - txBonitawork = spy(new ConnectorDefinitionAndInstanceContextWork(wrappedWork, CONNECTOR_DEFINITION_NAME, + txBonitaWork = spy(new ConnectorDefinitionAndInstanceContextWork(wrappedWork, CONNECTOR_DEFINITION_NAME, CONNECTOR_INSTANCE_ID, ACTIVATION_EVENT)); - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + final Map context = singletonMap("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("CONNECTOR_IMPLEMENTATION_CLASS_NAME=" + CONNECTOR_DEFINITION_NAME)); assertTrue(e.getMessage().contains("CONNECTOR_INSTANCE_ID=" + CONNECTOR_INSTANCE_ID)); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWorkTest.java index c5209247ee1..713c3027daa 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/FlowNodeDefinitionAndInstanceContextWorkTest.java @@ -46,9 +46,9 @@ public class FlowNodeDefinitionAndInstanceContextWorkTest extends AbstractContex @Override @Before public void before() throws SBonitaException { - when(tenantAccessor.getActivityInstanceService()).thenReturn(activityInstanceService); + when(serviceAccessor.getActivityInstanceService()).thenReturn(activityInstanceService); - txBonitawork = spy(new FlowNodeDefinitionAndInstanceContextWork(wrappedWork, FLOW_NODE_INSTANCE_ID)); + txBonitaWork = spy(new FlowNodeDefinitionAndInstanceContextWork(wrappedWork, FLOW_NODE_INSTANCE_ID)); doReturn(flowNodeInstance).when(activityInstanceService).getFlowNodeInstance(FLOW_NODE_INSTANCE_ID); doReturn(FLOW_NODE_DEFINITION_ID).when(flowNodeInstance).getFlowNodeDefinitionId(); @@ -58,13 +58,13 @@ public void before() throws SBonitaException { @Test public void handleFailure() throws Throwable { - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + final Map context = Collections.singletonMap("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("FLOW_NODE_DEFINITION_ID=" + FLOW_NODE_DEFINITION_ID)); assertTrue(e.getMessage().contains("FLOW_NODE_NAME=" + FLOW_NODE_NAME)); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/MessageInstanceContextWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/MessageInstanceContextWorkTest.java index 127dfa44a03..7e602437f26 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/MessageInstanceContextWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/MessageInstanceContextWorkTest.java @@ -26,7 +26,6 @@ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; -@SuppressWarnings("javadoc") @RunWith(MockitoJUnitRunner.class) public class MessageInstanceContextWorkTest extends AbstractContextWorkTest { @@ -41,7 +40,7 @@ public class MessageInstanceContextWorkTest extends AbstractContextWorkTest { @Override @Before public void before() throws SBonitaException { - txBonitawork = spy( + txBonitaWork = spy( new MessageInstanceContextWork(wrappedWork, MESSAGE_INSTANCE_NAME, MESSAGE_INSTANCE_TARGET_PROCESS_NAME, MESSAGE_INSTANCE_TARGET_FLOW_NODE_NAME, WAITING_MESSAGE_EVENT_TYPE.name())); super.before(); @@ -49,13 +48,13 @@ public void before() throws SBonitaException { @Test public void handleFailure() throws Throwable { - final Map context = Collections.singletonMap("tenantAccessor", tenantAccessor); + final Map context = Collections.singletonMap("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("MESSAGE_INSTANCE_NAME=" + MESSAGE_INSTANCE_NAME)); assertTrue(e.getMessage() diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWorkTest.java index ab1b7b5cb89..e7a79978b98 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessDefinitionContextWorkTest.java @@ -31,7 +31,6 @@ /** * @author Celine Souchet */ -@SuppressWarnings("javadoc") @RunWith(MockitoJUnitRunner.class) public class ProcessDefinitionContextWorkTest extends AbstractContextWorkTest { @@ -55,22 +54,23 @@ public void before() throws SBonitaException { doReturn(sProcessDefinitionDeployInfo).when(processDefinitionService) .getProcessDeploymentInfo(PROCESS_DEFINITION_ID); - doReturn(processDefinitionService).when(tenantAccessor).getProcessDefinitionService(); + doReturn(processDefinitionService).when(serviceAccessor).getProcessDefinitionService(); - txBonitawork = spy(new ProcessDefinitionContextWork(wrappedWork, PROCESS_DEFINITION_ID)); + txBonitaWork = spy(new ProcessDefinitionContextWork(wrappedWork, PROCESS_DEFINITION_ID)); super.before(); } @Test public void handleFailure() throws Throwable { - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + final Map context = Collections.singletonMap("serviceAccessor", + serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("PROCESS_DEFINITION_ID=" + PROCESS_DEFINITION_ID)); assertTrue(e.getMessage().contains("PROCESS_NAME=" + NAME)); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWorkTest.java index 02c01092da9..1e19f023749 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/ProcessInstanceContextWorkTest.java @@ -50,20 +50,20 @@ public void before() throws SBonitaException { doReturn(ROOT_PROCESS_INSTANCE_ID).when(sProcessInstance).getRootProcessInstanceId(); doReturn(sProcessInstance).when(processInstanceService).getProcessInstance(PROCESS_INSTANCE_ID); - doReturn(processInstanceService).when(tenantAccessor).getProcessInstanceService(); - txBonitawork = spy(new ProcessInstanceContextWork(wrappedWork, PROCESS_INSTANCE_ID)); + doReturn(processInstanceService).when(serviceAccessor).getProcessInstanceService(); + txBonitaWork = spy(new ProcessInstanceContextWork(wrappedWork, PROCESS_INSTANCE_ID)); super.before(); } @Test public void handleFailureWithProcessInstanceId() throws Throwable { - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + final Map context = Collections.singletonMap("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("PROCESS_INSTANCE_ID=" + PROCESS_INSTANCE_ID)); assertTrue(e.getMessage().contains("ROOT_PROCESS_INSTANCE_ID=" + ROOT_PROCESS_INSTANCE_ID)); @@ -72,14 +72,14 @@ public void handleFailureWithProcessInstanceId() throws Throwable { @Test public void handleFailureWithProcessInstanceAndRootIds() throws Throwable { - txBonitawork = spy(new ProcessInstanceContextWork(wrappedWork, PROCESS_INSTANCE_ID, 5)); - final Map context = Collections. singletonMap("tenantAccessor", tenantAccessor); + txBonitaWork = spy(new ProcessInstanceContextWork(wrappedWork, PROCESS_INSTANCE_ID, 5)); + final Map context = Collections.singletonMap("serviceAccessor", serviceAccessor); final SBonitaException e = new SBonitaException() { private static final long serialVersionUID = -6748168976371554636L; }; - txBonitawork.handleFailure(e, context); + txBonitaWork.handleFailure(e, context); assertTrue(e.getMessage().contains("PROCESS_INSTANCE_ID=" + PROCESS_INSTANCE_ID)); assertTrue(e.getMessage().contains("ROOT_PROCESS_INSTANCE_ID=" + 5)); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWorkTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWorkTest.java index 8ced209c093..ceb0e0a8f91 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWorkTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/execution/work/failurewrapping/TriggerSignalWorkTest.java @@ -14,10 +14,7 @@ package org.bonitasoft.engine.execution.work.failurewrapping; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import java.util.HashMap; import java.util.Map; @@ -28,7 +25,7 @@ import org.bonitasoft.engine.core.process.instance.model.event.handling.SBPMEventType; import org.bonitasoft.engine.core.process.instance.model.event.handling.SWaitingSignalEvent; import org.bonitasoft.engine.execution.event.EventsHandler; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,11 +40,12 @@ public class TriggerSignalWorkTest { public static final long UNREADABLE_SIGNAL_ID = 58923749333L; private TriggerSignalWork triggerSignalWork; - private String SIGNAL_NAME = "theSignal"; - private long SIGNAL_ID = 5643261L; + private final String SIGNAL_NAME = "theSignal"; + private final long SIGNAL_ID = 5643261L; private Map context; + @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private EventsHandler eventsHandler; @Mock @@ -57,9 +55,9 @@ public class TriggerSignalWorkTest { @Before public void before() throws Exception { context = new HashMap<>(); - context.put("tenantAccessor", tenantServiceAccessor); - doReturn(eventInstanceService).when(tenantServiceAccessor).getEventInstanceService(); - doReturn(eventsHandler).when(tenantServiceAccessor).getEventsHandler(); + context.put("serviceAccessor", serviceAccessor); + doReturn(eventInstanceService).when(serviceAccessor).getEventInstanceService(); + doReturn(eventsHandler).when(serviceAccessor).getEventsHandler(); waitingSignalEvent = new SWaitingSignalEvent(SBPMEventType.EVENT_SUB_PROCESS, 654223L, "proc", 54362L, "flownode", SIGNAL_NAME); doThrow(SEventTriggerInstanceNotFoundException.class).when(eventInstanceService) @@ -93,7 +91,7 @@ public void should_throw_exception_when_we_are_unable_to_read_the_signal() throw } @Test - public void should_give_signal_name_in_recovery_procedure() throws Exception { + public void should_give_signal_name_in_recovery_procedure() { //given triggerSignalWork = new TriggerSignalWork(SIGNAL_ID, SIGNAL_NAME); //when diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/CustomUserInfoDefinitionImporterTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/CustomUserInfoDefinitionImporterTest.java index aa91d542fe3..fcdc1f570ab 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/CustomUserInfoDefinitionImporterTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/CustomUserInfoDefinitionImporterTest.java @@ -22,7 +22,6 @@ import org.bonitasoft.engine.identity.model.SCustomUserInfoDefinition; import org.bonitasoft.engine.identity.xml.ExportedCustomUserInfoDefinition; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,9 +38,6 @@ public class CustomUserInfoDefinitionImporterTest { private static final String SKILLS_NAME = "Skills"; - @Mock - private TenantServiceAccessor serviceAccessor; - @Mock private IdentityService identityService; diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/UserImporterTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/UserImporterTest.java index 8eb2701c4fe..b866207f1b8 100755 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/UserImporterTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/identity/UserImporterTest.java @@ -13,27 +13,23 @@ **/ package org.bonitasoft.engine.identity; +import static java.util.Collections.singletonList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.*; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import org.bonitasoft.engine.identity.model.SCustomUserInfoDefinition; import org.bonitasoft.engine.identity.model.SUser; import org.bonitasoft.engine.identity.xml.ExportedCustomUserInfoValue; import org.bonitasoft.engine.identity.xml.ExportedUser; import org.bonitasoft.engine.persistence.QueryOptions; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; -import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @@ -41,9 +37,7 @@ public class UserImporterTest { private static final long USER_ID = 10L; - private static final long LOCATION_ID = 51L; - private static final long SKILLS_ID = 50L; - private static final String lOCATION_VALUE = "engineering"; + private static final String LOCATION_VALUE = "engineering"; private static final String LOCATION_NAME = "location"; private static final String SKILLS_VALUE = "Java"; private static final String FIRST_USER = "first.user"; @@ -54,23 +48,16 @@ public class UserImporterTest { @Mock private ImportOrganizationStrategy strategy; @Mock - private TenantServiceAccessor serviceAccessor; - @Mock private CustomUserInfoValueImporter userInfoValueImporter; private UserImporter importer; @Mock - private SCustomUserInfoDefinition skills; - @Mock - private SCustomUserInfoDefinition location; - @Mock private SUser persistedUser; private ExportedUser userToImport; private ExportedCustomUserInfoValue skillsValue; private ExportedCustomUserInfoValue locationValue; - @Captor - private ArgumentCaptor captor; - private SUser manager; - private SUser currentUser; + + public UserImporterTest() { + } @Before public void setUp() throws SUserCreationException { @@ -79,18 +66,17 @@ public void setUp() throws SUserCreationException { given(persistedUser.getId()).willReturn(USER_ID); skillsValue = new ExportedCustomUserInfoValue(SKILLS_NAME, SKILLS_VALUE); - locationValue = new ExportedCustomUserInfoValue(LOCATION_NAME, lOCATION_VALUE); - manager = new SUser(); + locationValue = new ExportedCustomUserInfoValue(LOCATION_NAME, LOCATION_VALUE); + SUser manager = new SUser(); manager.setId(MANAGER_ID); manager.setUserName("manager"); - currentUser = new SUser(); - userToImport = getUser(FIRST_USER, Arrays.asList(skillsValue, locationValue)); + userToImport = getUser(Arrays.asList(skillsValue, locationValue)); } - private ExportedUser getUser(String username, List userInfoValues) { + private ExportedUser getUser(List userInfoValues) { ExportedUser userImpl = new ExportedUser(); - userImpl.setUserName(username); + userImpl.setUserName(UserImporterTest.FIRST_USER); for (ExportedCustomUserInfoValue infoValue : userInfoValues) { userImpl.addCustomUserInfoValues(infoValue); } @@ -98,13 +84,13 @@ private ExportedUser getUser(String username, List } @Test - public void importUsers_should_call_customUserInfoValueImporter_if_the_user_doesnt_exist() throws Exception { + public void importUsers_should_call_customUserInfoValueImporter_if_the_user_does_not_exist() throws Exception { // given given(identityService.getNumberOfUsers(any(QueryOptions.class))).willReturn(0L); given(identityService.createUser(any(SUser.class))).willReturn(persistedUser); // when - importer.importUsers(Arrays.asList(userToImport)); + importer.importUsers(singletonList(userToImport)); // then verify(userInfoValueImporter, times(1)).imporCustomUserInfoValues(Arrays.asList(skillsValue, locationValue), @@ -112,16 +98,16 @@ public void importUsers_should_call_customUserInfoValueImporter_if_the_user_does } @Test - public void importUsers_shouldnt_call_customUserInfoValueImporter_if_the_user_exists() throws Exception { + public void importUsers_should_not_call_customUserInfoValueImporter_if_the_user_exists() throws Exception { // given given(identityService.getNumberOfUsers(any(QueryOptions.class))).willReturn(1L); given(identityService.getUserByUserName(FIRST_USER)).willReturn(persistedUser); // when - importer.importUsers(Collections.singletonList(userToImport)); + importer.importUsers(singletonList(userToImport)); // then verify(userInfoValueImporter, never()) - .imporCustomUserInfoValues(ArgumentMatchers.> any(), anyLong()); + .imporCustomUserInfoValues(ArgumentMatchers.any(), anyLong()); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/jobs/TriggerTimerEventJobTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/jobs/TriggerTimerEventJobTest.java index 8944c975c58..fbdb8ea53f1 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/jobs/TriggerTimerEventJobTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/jobs/TriggerTimerEventJobTest.java @@ -32,7 +32,7 @@ import org.bonitasoft.engine.scheduler.StatelessJob; import org.bonitasoft.engine.scheduler.exception.SJobConfigurationException; import org.bonitasoft.engine.scheduler.model.SJobDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; +import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.tenant.TenantServicesManager; import org.junit.Before; import org.junit.Rule; @@ -46,15 +46,15 @@ public class TriggerTimerEventJobTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - private TriggerTimerEventJob triggerTimerEventJob = new TriggerTimerEventJob() { + private final TriggerTimerEventJob triggerTimerEventJob = new TriggerTimerEventJob() { @Override - protected TenantServiceAccessor getTenantServiceAccessor() { - return tenantServiceAccessor; + protected ServiceAccessor getServiceAccessor() { + return serviceAccessor; } }; @Mock - private TenantServiceAccessor tenantServiceAccessor; + private ServiceAccessor serviceAccessor; @Mock private EventsHandler eventsHandler; @Mock @@ -79,11 +79,11 @@ protected TenantServiceAccessor getTenantServiceAccessor() { @Before public void before() throws Exception { - doReturn(eventsHandler).when(tenantServiceAccessor).getEventsHandler(); - doReturn(jobService).when(tenantServiceAccessor).getJobService(); - doReturn(schedulerService).when(tenantServiceAccessor).getSchedulerService(); - doReturn(eventInstanceService).when(tenantServiceAccessor).getEventInstanceService(); - doReturn(tenantServicesManager).when(tenantServiceAccessor).getTenantServicesManager(); + doReturn(eventsHandler).when(serviceAccessor).getEventsHandler(); + doReturn(jobService).when(serviceAccessor).getJobService(); + doReturn(schedulerService).when(serviceAccessor).getSchedulerService(); + doReturn(eventInstanceService).when(serviceAccessor).getEventInstanceService(); + doReturn(tenantServicesManager).when(serviceAccessor).getTenantServicesManager(); doReturn(true).when(tenantServicesManager).isStarted(); } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/search/activity/SearchActivityInstancesTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/search/activity/SearchActivityInstancesTest.java index 7f07d3f9f9f..7e80c96014f 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/search/activity/SearchActivityInstancesTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/search/activity/SearchActivityInstancesTest.java @@ -23,7 +23,6 @@ import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.search.descriptor.SearchActivityInstanceDescriptor; import org.bonitasoft.engine.search.descriptor.SearchEntitiesDescriptor; -import org.bonitasoft.engine.service.TenantServiceAccessor; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -41,9 +40,6 @@ public class SearchActivityInstancesTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - @Mock - TenantServiceAccessor tenantAccessor; - @Mock SearchEntitiesDescriptor searchEntitiesDescriptor;