You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/01/09 09:51:37 UTC
[isis] 02/06: ISIS-2033: make IsisSessionFactory an interface
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2033-IoC
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 0d2c556df046812ee38175745316f608f0e0e97b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jan 9 06:32:03 2019 +0100
ISIS-2033: make IsisSessionFactory an interface
Task-Url: https://issues.apache.org/jira/browse/ISIS-2033
---
.../isis/tool/mavenplugin/IsisMojoAbstract.java | 3 +-
.../isis/core/runtime/headless/IsisSystem.java | 3 +-
.../runtime/system/session/IsisSessionFactory.java | 277 ++-------------------
.../system/session/IsisSessionFactoryBuilder.java | 28 +--
...Factory.java => IsisSessionFactoryDefault.java} | 116 +++------
.../serviceactions/ServiceActionUtil.java | 5 +-
.../components/actions/ActionParametersForm.java | 4 +-
.../viewer/wicket/ui/panels/PanelAbstract.java | 7 +-
.../isis/viewer/wicket/ui/panels/PanelUtil.java | 10 +-
migration-notes.adoc | 30 +++
10 files changed, 100 insertions(+), 383 deletions(-)
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
index 302a33b..6b7a5f3 100644
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
+++ b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
@@ -40,6 +40,7 @@ import org.apache.isis.core.runtime.logging.IsisLoggingConfigurer;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
import org.apache.isis.core.runtime.system.session.IsisSessionFactoryBuilder;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactoryDefault;
import org.apache.isis.core.runtime.systemusinginstallers.IsisComponentProvider;
import org.apache.isis.tool.mavenplugin.util.MavenProjects;
@@ -76,7 +77,7 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
IsisSessionFactory isisSessionFactory = null;
try {
- isisSessionFactory = isisSessionFactoryBuilder.buildSessionFactory(IsisSessionFactory::new);
+ isisSessionFactory = isisSessionFactoryBuilder.buildSessionFactory(IsisSessionFactoryDefault::new);
if(!isisSessionFactoryBuilder.isMetaModelValid()) {
MetaModelInvalidException metaModelInvalidException = IsisContext
.getMetaModelInvalidExceptionIfAny();
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
index 2db9a9c..3872a29 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
@@ -32,6 +32,7 @@ import org.apache.isis.core.runtime.headless.auth.AuthenticationRequestNameOnly;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
import org.apache.isis.core.runtime.system.session.IsisSessionFactoryBuilder;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactoryDefault;
import org.apache.isis.core.runtime.systemusinginstallers.IsisComponentProvider;
import org.apache.isis.core.security.authentication.AuthenticationRequest;
import org.apache.isis.core.security.authentication.AuthenticationSession;
@@ -128,7 +129,7 @@ public final class IsisSystem {
// ensures that a FixtureClock is installed as the singleton underpinning the ClockService
FixtureClock.initialize();
- isisSessionFactory = isisSessionFactoryBuilder.buildSessionFactory(IsisSessionFactory::new);
+ isisSessionFactory = isisSessionFactoryBuilder.buildSessionFactory(IsisSessionFactoryDefault::new);
// REVIEW: does no harm, but is this required?
closeSession();
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
index cadb54b..7c1d511 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
@@ -19,35 +19,15 @@
package org.apache.isis.core.runtime.system.session;
-import java.util.List;
import java.util.concurrent.Callable;
-import java.util.stream.Collectors;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.Singleton;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
import javax.inject.Inject;
-import org.apache.isis.applib.services.i18n.TranslationService;
import org.apache.isis.applib.services.inject.ServiceInjector;
-import org.apache.isis.applib.services.title.TitleService;
-import org.apache.isis.commons.internal.base._Blackhole;
-import org.apache.isis.commons.internal.context._Context;
-import org.apache.isis.config.IsisConfiguration;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.specloader.ServiceInitializer;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
-import org.apache.isis.core.runtime.fixtures.FixturesInstallerFromConfiguration;
-import org.apache.isis.core.runtime.system.MessageRegistry;
-import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.internal.InitialisationSession;
import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManagerException;
-import org.apache.isis.core.runtime.systemusinginstallers.IsisComponentProvider;
import org.apache.isis.core.security.authentication.AuthenticationSession;
import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
@@ -66,219 +46,31 @@ import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
* it can be {@link Inject}'d into other domain services.
* </p>
*/
-@Singleton @ApplicationScoped
-public class IsisSessionFactory {
+public interface IsisSessionFactory {
- //private final static Logger LOG = LoggerFactory.getLogger(IsisSessionFactory.class);
+ public void destroyServicesAndShutdown();
- @Inject private IsisConfiguration configuration;
-
- private ServiceInjector serviceInjector;
- private SpecificationLoader specificationLoader;
- private AuthenticationManager authenticationManager;
- private AuthorizationManager authorizationManager;
- private PersistenceSessionFactory persistenceSessionFactory;
- private ServiceInitializer serviceInitializer;
+ public IsisSession openSession(final AuthenticationSession authenticationSession);
+ public void closeSession();
- @PostConstruct
- public void init() {
-
- System.out.println("!!!!!!!!!!!!! IsisSessionFactory INIT " + hashCode());
+ public IsisSession getCurrentSession();
- if(_Context.getIfAny(IsisSessionFactory.class)!=null) {
- return;
- }
-
- //System.out.println("!!!!!!!!!!!!! IsisSessionFactory INIT " + hashCode());
-
- final IsisComponentProvider componentProvider = IsisComponentProvider
- .builder()
- .build();
-
- final IsisSessionFactoryBuilder builder =
- new IsisSessionFactoryBuilder(componentProvider);
-
- // as a side-effect, if the metamodel turns out to be invalid, then
- // this will push the MetaModelInvalidException into IsisContext.
- IsisSessionFactory sessionFactory = builder.buildSessionFactory(()->this);
- }
-
- void setServicesInjector(ServiceInjector servicesInjector) {
- this.serviceInjector = servicesInjector;
- this.specificationLoader = IsisContext.getSpecificationLoader();
- this.authenticationManager = IsisContext.getAuthenticationManager();
- this.authorizationManager = IsisContext.getAuthorizationManager();
- this.persistenceSessionFactory = servicesInjector.lookupServiceElseFail(PersistenceSessionFactory.class);
- }
-
- void constructServices() {
-
- // do postConstruct. We store the initializer to do preDestroy on shutdown
- serviceInitializer = new ServiceInitializer(configuration, serviceInjector.streamServices().collect(Collectors.toList()));
- serviceInitializer.validate();
-
- openSession(new InitialisationSession());
-
- try {
- //
- // postConstructInSession
- //
-
- IsisTransactionManager transactionManager = getCurrentSessionTransactionManager();
- transactionManager.executeWithinTransaction(serviceInitializer::postConstruct);
-
- //
- // installFixturesIfRequired
- //
- final FixturesInstallerFromConfiguration fixtureInstaller =
- new FixturesInstallerFromConfiguration(this);
- fixtureInstaller.installFixtures();
-
- //
- // translateServicesAndEnumConstants
- //
-
- final List<Object> services = serviceInjector.streamServices().collect(Collectors.toList());
- final TitleService titleService = serviceInjector.lookupServiceElseFail(TitleService.class);
- for (Object service : services) {
- final String unused = titleService.titleOf(service);
- _Blackhole.consume(unused);
- }
-
- // (previously we took a protective copy to avoid a concurrent modification exception,
- // but this is now done by SpecificationLoader itself)
- for (final ObjectSpecification objSpec : IsisContext.getSpecificationLoader().allSpecifications()) {
- final Class<?> correspondingClass = objSpec.getCorrespondingClass();
- if(correspondingClass.isEnum()) {
- final Object[] enumConstants = correspondingClass.getEnumConstants();
- for (Object enumConstant : enumConstants) {
- final String unused = titleService.titleOf(enumConstant);
- _Blackhole.consume(unused);
- }
- }
- }
-
- // as used by the Wicket UI
- final TranslationService translationService = serviceInjector.lookupServiceElseFail(TranslationService.class);
-
- final String context = IsisSessionFactoryBuilder.class.getName();
- final MessageRegistry messageRegistry = new MessageRegistry();
- final List<String> messages = messageRegistry.listMessages();
- for (String message : messages) {
- translationService.translate(context, message);
- }
-
- } finally {
- closeSession();
- }
- }
-
- @PreDestroy
- public void destroyServicesAndShutdown() {
- destroyServices();
- shutdown();
- }
-
- private void destroyServices() {
- // may not be set if the metamodel validation failed during initialization
- if (serviceInitializer == null) {
- return;
- }
-
- // call @PreDestroy (in a session)
- openSession(new InitialisationSession());
- IsisTransactionManager transactionManager = getCurrentSessionTransactionManager();
- try {
- transactionManager.startTransaction();
- try {
-
- serviceInitializer.preDestroy();
-
- } catch (RuntimeException ex) {
- transactionManager.getCurrentTransaction().setAbortCause(
- new IsisTransactionManagerException(ex));
- } finally {
- // will commit or abort
- transactionManager.endTransaction();
- }
- } finally {
- closeSession();
- }
- }
-
- private void shutdown() {
- persistenceSessionFactory.shutdown();
- authenticationManager.shutdown();
- specificationLoader.shutdown();
- }
-
- // -- openSession, closeSession, currentSession, inSession
-
- /**
- * Inheritable... allows to have concurrent computations utilizing the ForkJoinPool.
- * see {@link IsisContext#compute(java.util.function.Supplier)}
- */
- private final InheritableThreadLocal<IsisSession> currentSession = new InheritableThreadLocal<>();
-
- /**
- * Creates and {@link IsisSession#open() open}s the {@link IsisSession}.
- */
- public IsisSession openSession(final AuthenticationSession authenticationSession) {
-
- closeSession();
-
- final PersistenceSession persistenceSession =
- persistenceSessionFactory.createPersistenceSession(serviceInjector, authenticationSession);
- IsisSession session = new IsisSession(authenticationSession, persistenceSession);
- currentSession.set(session);
- session.open();
- return session;
- }
-
- public void closeSession() {
- final IsisSession existingSessionIfAny = getCurrentSession();
- if (existingSessionIfAny == null) {
- return;
- }
- existingSessionIfAny.close();
- currentSession.set(null);
- }
-
- public IsisSession getCurrentSession() {
- return currentSession.get();
- }
-
- private IsisTransactionManager getCurrentSessionTransactionManager() {
- final IsisSession currentSession = getCurrentSession();
- return currentSession.getPersistenceSession().getTransactionManager();
- }
/**
* @return whether the calling thread is within the context of an open IsisSession
*/
- public boolean isInSession() {
- return getCurrentSession() != null;
- }
+ public boolean isInSession();
/**
* @return whether the calling thread is within the context of an open IsisTransaction
*/
- public boolean isInTransaction() {
- if (isInSession()) {
- if (getCurrentSession().getCurrentTransaction() != null) {
- if (!getCurrentSession().getCurrentTransaction().getState().isComplete()) {
- return true;
- }
- }
- }
- return false;
- }
+ public boolean isInTransaction();
/**
* As per {@link #doInSession(Runnable, AuthenticationSession)}, using a default {@link InitialisationSession}.
* @param runnable
*/
- public void doInSession(final Runnable runnable) {
+ public default void doInSession(final Runnable runnable) {
doInSession(runnable, new InitialisationSession());
}
@@ -290,20 +82,14 @@ public class IsisSessionFactory {
* @param runnable The piece of code to run.
* @param authenticationSession
*/
- public void doInSession(final Runnable runnable, final AuthenticationSession authenticationSession) {
- doInSession(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- runnable.run();
- return null;
- }
- }, authenticationSession);
+ public default void doInSession(final Runnable runnable, final AuthenticationSession authenticationSession) {
+ doInSession(runnable, authenticationSession);
}
/**
* As per {@link #doInSession(Callable), AuthenticationSession}, using a default {@link InitialisationSession}.
*/
- public <R> R doInSession(final Callable<R> callable) {
+ public default <R> R doInSession(final Callable<R> callable) {
return doInSession(callable, new InitialisationSession());
}
@@ -315,25 +101,7 @@ public class IsisSessionFactory {
* @param callable The piece of code to run.
* @param authenticationSession - the user to run under
*/
- public <R> R doInSession(final Callable<R> callable, final AuthenticationSession authenticationSession) {
- final IsisSessionFactory sessionFactory = this;
- boolean noSession = !sessionFactory.isInSession();
- try {
- if (noSession) {
- sessionFactory.openSession(authenticationSession);
- }
-
- return callable.call();
- } catch (Exception x) {
- throw new RuntimeException(
- String.format("An error occurred while executing code in %s session", noSession ? "a temporary" : "a"),
- x);
- } finally {
- if (noSession) {
- sessionFactory.closeSession();
- }
- }
- }
+ public <R> R doInSession(final Callable<R> callable, final AuthenticationSession authenticationSession);
// -- component accessors
@@ -341,19 +109,14 @@ public class IsisSessionFactory {
* The {@link ApplicationScopedComponent application-scoped} {@link ServiceInjector}.
* @deprecated use IsisContext instead
*/
- public ServiceInjector getServicesInjector() {
- return serviceInjector;
- }
+ public ServiceInjector getServicesInjector();
/**
* The {@link ApplicationScopedComponent application-scoped}
* {@link SpecificationLoader}.
* @deprecated use IsisContext instead
*/
- @Produces @ApplicationScoped
- public SpecificationLoader getSpecificationLoader() {
- return specificationLoader;
- }
+ public SpecificationLoader getSpecificationLoader();
/**
* The {@link AuthenticationManager} that will be used to authenticate and
@@ -362,18 +125,14 @@ public class IsisSessionFactory {
* {@link IsisSession}.
* @deprecated use IsisContext instead
*/
- public AuthenticationManager getAuthenticationManager() {
- return authenticationManager;
- }
+ public AuthenticationManager getAuthenticationManager();
/**
* The {@link AuthorizationManager} that will be used to authorize access to
* domain objects.
* @deprecated use IsisContext instead
*/
- public AuthorizationManager getAuthorizationManager() {
- return authorizationManager;
- }
+ public AuthorizationManager getAuthorizationManager();
/**
* The {@link org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory} that will be used to create
@@ -381,9 +140,7 @@ public class IsisSessionFactory {
* within} the {@link IsisSession}.
* @deprecated use IsisContext instead
*/
- public PersistenceSessionFactory getPersistenceSessionFactory() {
- return persistenceSessionFactory;
- }
+ public PersistenceSessionFactory getPersistenceSessionFactory();
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
index 3e3067b..8a65145 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
@@ -27,12 +27,8 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.function.Supplier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.isis.applib.clock.Clock;
import org.apache.isis.applib.fixtures.FixtureClock;
-import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.applib.services.registry.ServiceRegistry;
import org.apache.isis.commons.internal.context._Context;
import org.apache.isis.config.IsisConfiguration;
@@ -55,11 +51,11 @@ import org.apache.isis.schema.utils.ChangesDtoUtils;
import org.apache.isis.schema.utils.CommandDtoUtils;
import org.apache.isis.schema.utils.InteractionDtoUtils;
+import lombok.extern.slf4j.Slf4j;
+@Slf4j
public class IsisSessionFactoryBuilder {
- public static final Logger LOG = LoggerFactory.getLogger(IsisSessionFactoryBuilder.class);
-
// -- constructors, accessors
private final IsisComponentProvider componentProvider;
@@ -74,13 +70,13 @@ public class IsisSessionFactoryBuilder {
// -- buildSessionFactory
- public IsisSessionFactory buildSessionFactory(Supplier<IsisSessionFactory> sfInstanceSupplier) {
+ public IsisSessionFactory buildSessionFactory(Supplier<IsisSessionFactoryDefault> sfInstanceSupplier) {
- LOG.info("initialising Isis System");
- LOG.info("working directory: {}", new File(".").getAbsolutePath());
+ log.info("initialising Isis System");
+ log.info("working directory: {}", new File(".").getAbsolutePath());
final IsisConfiguration configuration = _Config.getConfiguration();
- LOG.info("resource stream source: {}", configuration.getResourceStreamSource());
+ log.info("resource stream source: {}", configuration.getResourceStreamSource());
localeInitializer.initLocale(configuration);
timeZoneInitializer.initTimeZone(configuration);
@@ -93,11 +89,11 @@ public class IsisSessionFactoryBuilder {
FixtureClock.initialize();
}
- IsisSessionFactory isisSessionFactory;
+ IsisSessionFactoryDefault isisSessionFactory;
try {
final ServiceRegistry servicesRegistry = IsisContext.getServiceRegistry();
- final ServiceInjector servicesInjector = IsisContext.getServiceInjector();
+
final AuthenticationManager authenticationManager = componentProvider.provideAuthenticationManager();
final AuthorizationManager authorizationManager = componentProvider.provideAuthorizationManager();
@@ -115,7 +111,7 @@ public class IsisSessionFactoryBuilder {
// instantiate or reuse the IsisSessionFactory
isisSessionFactory = sfInstanceSupplier.get();
- isisSessionFactory.setServicesInjector(servicesInjector);
+ isisSessionFactory.initDependenecies();
// now, add the IsisSessionFactory itself into ServicesInjector, so it can be @javax.inject.Inject'd
// into any internal domain services
@@ -220,8 +216,8 @@ public class IsisSessionFactoryBuilder {
} catch (final MetaModelInvalidException ex) {
// no need to use a higher level, such as error(...); the calling code will expose any metamodel
// validation errors in their own particular way.
- if(LOG.isDebugEnabled()) {
- LOG.debug("Meta model invalid", ex);
+ if(log.isDebugEnabled()) {
+ log.debug("Meta model invalid", ex);
}
_Context.putSingleton(MetaModelInvalidException.class, ex);
}
@@ -230,7 +226,7 @@ public class IsisSessionFactoryBuilder {
} catch (final IsisSystemException ex) {
- LOG.error("failed to initialise", ex);
+ log.error("failed to initialise", ex);
throw new RuntimeException(ex);
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java
similarity index 75%
copy from core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
copy to core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java
index cadb54b..a4793bd 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java
@@ -32,6 +32,7 @@ import javax.inject.Inject;
import org.apache.isis.applib.services.i18n.TranslationService;
import org.apache.isis.applib.services.inject.ServiceInjector;
+import org.apache.isis.applib.services.registry.ServiceRegistry;
import org.apache.isis.applib.services.title.TitleService;
import org.apache.isis.commons.internal.base._Blackhole;
import org.apache.isis.commons.internal.context._Context;
@@ -67,13 +68,14 @@ import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
* </p>
*/
@Singleton @ApplicationScoped
-public class IsisSessionFactory {
+public class IsisSessionFactoryDefault implements IsisSessionFactory {
//private final static Logger LOG = LoggerFactory.getLogger(IsisSessionFactory.class);
@Inject private IsisConfiguration configuration;
private ServiceInjector serviceInjector;
+ private ServiceRegistry serviceRegistry;
private SpecificationLoader specificationLoader;
private AuthenticationManager authenticationManager;
private AuthorizationManager authorizationManager;
@@ -85,7 +87,7 @@ public class IsisSessionFactory {
System.out.println("!!!!!!!!!!!!! IsisSessionFactory INIT " + hashCode());
- if(_Context.getIfAny(IsisSessionFactory.class)!=null) {
+ if(_Context.getIfAny(IsisSessionFactoryDefault.class)!=null) {
return;
}
@@ -100,21 +102,24 @@ public class IsisSessionFactory {
// as a side-effect, if the metamodel turns out to be invalid, then
// this will push the MetaModelInvalidException into IsisContext.
- IsisSessionFactory sessionFactory = builder.buildSessionFactory(()->this);
+ builder.buildSessionFactory(()->this);
}
- void setServicesInjector(ServiceInjector servicesInjector) {
- this.serviceInjector = servicesInjector;
+ void initDependenecies() {
+ this.serviceInjector = IsisContext.getServiceInjector();
+ this.serviceRegistry = IsisContext.getServiceRegistry();
this.specificationLoader = IsisContext.getSpecificationLoader();
this.authenticationManager = IsisContext.getAuthenticationManager();
this.authorizationManager = IsisContext.getAuthorizationManager();
- this.persistenceSessionFactory = servicesInjector.lookupServiceElseFail(PersistenceSessionFactory.class);
+ this.persistenceSessionFactory = IsisContext.getServiceRegistry()
+ .lookupServiceElseFail(PersistenceSessionFactory.class);
}
void constructServices() {
// do postConstruct. We store the initializer to do preDestroy on shutdown
- serviceInitializer = new ServiceInitializer(configuration, serviceInjector.streamServices().collect(Collectors.toList()));
+ serviceInitializer = new ServiceInitializer(configuration,
+ serviceRegistry.streamServices().collect(Collectors.toList()));
serviceInitializer.validate();
openSession(new InitialisationSession());
@@ -138,8 +143,8 @@ public class IsisSessionFactory {
// translateServicesAndEnumConstants
//
- final List<Object> services = serviceInjector.streamServices().collect(Collectors.toList());
- final TitleService titleService = serviceInjector.lookupServiceElseFail(TitleService.class);
+ final List<Object> services = serviceRegistry.streamServices().collect(Collectors.toList());
+ final TitleService titleService = serviceRegistry.lookupServiceElseFail(TitleService.class);
for (Object service : services) {
final String unused = titleService.titleOf(service);
_Blackhole.consume(unused);
@@ -159,7 +164,8 @@ public class IsisSessionFactory {
}
// as used by the Wicket UI
- final TranslationService translationService = serviceInjector.lookupServiceElseFail(TranslationService.class);
+ final TranslationService translationService =
+ serviceRegistry.lookupServiceElseFail(TranslationService.class);
final String context = IsisSessionFactoryBuilder.class.getName();
final MessageRegistry messageRegistry = new MessageRegistry();
@@ -220,9 +226,7 @@ public class IsisSessionFactory {
*/
private final InheritableThreadLocal<IsisSession> currentSession = new InheritableThreadLocal<>();
- /**
- * Creates and {@link IsisSession#open() open}s the {@link IsisSession}.
- */
+ @Override
public IsisSession openSession(final AuthenticationSession authenticationSession) {
closeSession();
@@ -235,6 +239,7 @@ public class IsisSessionFactory {
return session;
}
+ @Override
public void closeSession() {
final IsisSession existingSessionIfAny = getCurrentSession();
if (existingSessionIfAny == null) {
@@ -244,6 +249,7 @@ public class IsisSessionFactory {
currentSession.set(null);
}
+ @Override
public IsisSession getCurrentSession() {
return currentSession.get();
}
@@ -253,16 +259,12 @@ public class IsisSessionFactory {
return currentSession.getPersistenceSession().getTransactionManager();
}
- /**
- * @return whether the calling thread is within the context of an open IsisSession
- */
+ @Override
public boolean isInSession() {
return getCurrentSession() != null;
}
- /**
- * @return whether the calling thread is within the context of an open IsisTransaction
- */
+ @Override
public boolean isInTransaction() {
if (isInSession()) {
if (getCurrentSession().getCurrentTransaction() != null) {
@@ -274,49 +276,9 @@ public class IsisSessionFactory {
return false;
}
- /**
- * As per {@link #doInSession(Runnable, AuthenticationSession)}, using a default {@link InitialisationSession}.
- * @param runnable
- */
- public void doInSession(final Runnable runnable) {
- doInSession(runnable, new InitialisationSession());
- }
-
- /**
- * A template method that executes a piece of code in a session.
- * If there is an open session then it is reused, otherwise a temporary one
- * is created.
- *
- * @param runnable The piece of code to run.
- * @param authenticationSession
- */
- public void doInSession(final Runnable runnable, final AuthenticationSession authenticationSession) {
- doInSession(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- runnable.run();
- return null;
- }
- }, authenticationSession);
- }
-
- /**
- * As per {@link #doInSession(Callable), AuthenticationSession}, using a default {@link InitialisationSession}.
- */
- public <R> R doInSession(final Callable<R> callable) {
- return doInSession(callable, new InitialisationSession());
- }
-
- /**
- * A template method that executes a piece of code in a session.
- * If there is an open session then it is reused, otherwise a temporary one
- * is created.
- *
- * @param callable The piece of code to run.
- * @param authenticationSession - the user to run under
- */
+ @Override
public <R> R doInSession(final Callable<R> callable, final AuthenticationSession authenticationSession) {
- final IsisSessionFactory sessionFactory = this;
+ final IsisSessionFactoryDefault sessionFactory = this;
boolean noSession = !sessionFactory.isInSession();
try {
if (noSession) {
@@ -337,50 +299,28 @@ public class IsisSessionFactory {
// -- component accessors
- /**
- * The {@link ApplicationScopedComponent application-scoped} {@link ServiceInjector}.
- * @deprecated use IsisContext instead
- */
+ @Override
public ServiceInjector getServicesInjector() {
return serviceInjector;
}
- /**
- * The {@link ApplicationScopedComponent application-scoped}
- * {@link SpecificationLoader}.
- * @deprecated use IsisContext instead
- */
@Produces @ApplicationScoped
+ @Override
public SpecificationLoader getSpecificationLoader() {
return specificationLoader;
}
- /**
- * The {@link AuthenticationManager} that will be used to authenticate and
- * create {@link AuthenticationSession}s
- * {@link IsisSession#getAuthenticationSession() within} the
- * {@link IsisSession}.
- * @deprecated use IsisContext instead
- */
+ @Override
public AuthenticationManager getAuthenticationManager() {
return authenticationManager;
}
- /**
- * The {@link AuthorizationManager} that will be used to authorize access to
- * domain objects.
- * @deprecated use IsisContext instead
- */
+ @Override
public AuthorizationManager getAuthorizationManager() {
return authorizationManager;
}
- /**
- * The {@link org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory} that will be used to create
- * {@link PersistenceSession} {@link IsisSession#getPersistenceSession()
- * within} the {@link IsisSession}.
- * @deprecated use IsisContext instead
- */
+ @Override
public PersistenceSessionFactory getPersistenceSessionFactory() {
return persistenceSessionFactory;
}
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/serviceactions/ServiceActionUtil.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/serviceactions/ServiceActionUtil.java
index bdd6279..792fc45 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/serviceactions/ServiceActionUtil.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/serviceactions/ServiceActionUtil.java
@@ -48,7 +48,6 @@ import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
import org.apache.isis.core.runtime.system.SystemConstants;
import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.session.IsisSessionFactoryBuilder;
import org.apache.isis.viewer.wicket.model.models.EntityModel;
import org.apache.isis.viewer.wicket.model.models.ServiceActionsModel;
import org.apache.isis.viewer.wicket.ui.components.actionmenu.CssClassFaBehavior;
@@ -270,11 +269,11 @@ public final class ServiceActionUtil {
final ServiceInjector servicesInjector) {
final TranslationService translationService =
- servicesInjector.lookupService(TranslationService.class).orElse(null);;
+ IsisContext.getServiceRegistry().lookupServiceElseFail(TranslationService.class);
ConfirmationConfig confirmationConfig = new ConfirmationConfig();
- final String context = IsisSessionFactoryBuilder.class.getName();
+ final String context = SystemConstants.class.getName();
final String areYouSure = translationService.translate(context, SystemConstants.MSG_ARE_YOU_SURE);
final String confirm = translationService.translate(context, SystemConstants.MSG_CONFIRM);
final String cancel = translationService.translate(context, SystemConstants.MSG_CANCEL);
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
index f5f74e4..e70a002 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
@@ -138,9 +138,7 @@ class ActionParametersForm extends PromptFormAbstract<ActionModel> {
final ObjectAction action = actionModel.getActionMemento().getAction(getSpecificationLoader());
SemanticsOf semanticsOf = action.getSemantics();
- final ServiceInjector servicesInjector = getPersistenceSession().getServicesInjector();
-
- PanelUtil.addConfirmationDialogIfAreYouSureSemantics(button, semanticsOf, servicesInjector);
+ PanelUtil.addConfirmationDialogIfAreYouSureSemantics(button, semanticsOf);
}
@Override
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
index 26267b1..707dafd 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
@@ -149,15 +149,12 @@ public abstract class PanelAbstract<T extends IModel<?>> extends Panel {
* @return The found domain service
*/
protected <S> S lookupService(final Class<S> serviceClass) {
- return getPersistenceSession().getServicesInjector().lookupService(serviceClass).orElse(null);
+ return IsisContext.getServiceRegistry().lookupService(serviceClass).orElse(null);
}
protected void addConfirmationDialogIfAreYouSureSemantics(final Component component, final SemanticsOf semanticsOf) {
-
- final ServiceInjector servicesInjector = getPersistenceSession().getServicesInjector();
-
- PanelUtil.addConfirmationDialogIfAreYouSureSemantics(component, semanticsOf, servicesInjector);
+ PanelUtil.addConfirmationDialogIfAreYouSureSemantics(component, semanticsOf);
}
// ///////////////////////////////////////////////////////////////////
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
index 00ab64d..e29aa4d 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
@@ -28,10 +28,9 @@ import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.services.i18n.TranslationService;
-import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.commons.internal.base._Strings;
import org.apache.isis.core.runtime.system.SystemConstants;
-import org.apache.isis.core.runtime.system.session.IsisSessionFactoryBuilder;
+import org.apache.isis.core.runtime.system.context.IsisContext;
import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.ConfirmationBehavior;
@@ -91,19 +90,18 @@ public final class PanelUtil {
public static void addConfirmationDialogIfAreYouSureSemantics(
final Component component,
- final SemanticsOf semanticsOf,
- final ServiceInjector servicesInjector) {
+ final SemanticsOf semanticsOf) {
if (!semanticsOf.isAreYouSure()) {
return;
}
final TranslationService translationService =
- servicesInjector.lookupService(TranslationService.class).orElse(null);;
+ IsisContext.getServiceRegistry().lookupServiceElseFail(TranslationService.class);
ConfirmationConfig confirmationConfig = new ConfirmationConfig();
- final String context = IsisSessionFactoryBuilder.class.getName();
+ final String context = SystemConstants.class.getName();
final String areYouSure = translationService.translate(context, SystemConstants.MSG_ARE_YOU_SURE);
final String confirm = translationService.translate(context, SystemConstants.MSG_CONFIRM);
final String cancel = translationService.translate(context, SystemConstants.MSG_CANCEL);
diff --git a/migration-notes.adoc b/migration-notes.adoc
index c96afac..1abac18 100644
--- a/migration-notes.adoc
+++ b/migration-notes.adoc
@@ -467,6 +467,36 @@ isis.viewer.wicket.themes.provider=org.my.IsisWicketThemeSupport
might need to reinstate, or long-term will have SpringBoot etc do the bootstrapping.
+=== Changes to SystemConstant Translations
+
+Was ...
+
+[source,java]
+----
+String context = IsisSessionFactoryBuilder.class.getName();
+
+String areYouSure = translationService.translate(context, SystemConstants.MSG_ARE_YOU_SURE);
+String confirm = translationService.translate(context, SystemConstants.MSG_CONFIRM);
+String cancel = translationService.translate(context, SystemConstants.MSG_CANCEL);
+----
+
+changed to ...
+
+[source,java]
+----
+String context = SystemConstants.class.getName();
+
+...
+----
+
+
+
+
+
+
+
+
+
== Migration Notes 1.x to 2.0.0-M1