Skip to content

Commit

Permalink
chore(accessor): stop using deprecated TenantServiceAccessor (#2676)
Browse files Browse the repository at this point in the history
use ServiceAccessor instead

Also, I deprecated TenantServiceSingleton in favor of new class ServiceAccessorSingleton
  • Loading branch information
educhastenier authored Sep 4, 2023
1 parent 8f3d9c1 commit 9d10081
Show file tree
Hide file tree
Showing 114 changed files with 2,031 additions and 2,467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

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 {

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());
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public void should_delete_complete_archived_process_instances() throws Exception

getProcessAPI().deleteArchivedProcessInstancesInAllStates(processInstances);

getTenantAccessor().getUserTransactionService().executeInTransaction((Callable<Void>) () -> {
getServiceAccessor().getUserTransactionService().executeInTransaction((Callable<Void>) () -> {
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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -166,17 +166,17 @@ protected String inputName() {
}

protected List<SAProcessInstance> getAllProcessInstances() throws Exception {
return getTenantAccessor()
return getServiceAccessor()
.getUserTransactionService().executeInTransaction(this::searchAllArchProcessInstances);
}

protected List<SAFlowNodeInstance> getAllArchFlowNodes() throws Exception {
return getTenantAccessor().getUserTransactionService()
return getServiceAccessor().getUserTransactionService()
.executeInTransaction(this::searchAllArchFlowNodes);
}

protected List<SFlowNodeInstance> getAllFlowNodes() throws Exception {
return getTenantAccessor().getUserTransactionService()
return getServiceAccessor().getUserTransactionService()
.executeInTransaction(this::searchAllFlowNodes);
}

Expand Down Expand Up @@ -241,19 +241,19 @@ protected ProcessDefinition createSubProcessDefinitionWithUserTask(User user) th
}

private List<SAProcessInstance> searchAllArchProcessInstances() throws SBonitaReadException {
return getTenantAccessor().getProcessInstanceService()
return getServiceAccessor().getProcessInstanceService()
.searchArchivedProcessInstances(new QueryOptions(0, 1000));
}

private List<SAFlowNodeInstance> searchAllArchFlowNodes()
throws org.bonitasoft.engine.persistence.SBonitaReadException {
return getTenantAccessor().getActivityInstanceService()
return getServiceAccessor().getActivityInstanceService()
.searchArchivedFlowNodeInstances(SAFlowNodeInstance.class, new QueryOptions(0, 1000));
}

private List<SFlowNodeInstance> searchAllFlowNodes()
throws org.bonitasoft.engine.persistence.SBonitaReadException {
return getTenantAccessor().getActivityInstanceService()
return getServiceAccessor().getActivityInstanceService()
.searchFlowNodeInstances(SFlowNodeInstance.class, new QueryOptions(0, 1000));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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());
}

Expand Down
Loading

0 comments on commit 9d10081

Please sign in to comment.