You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/11 05:18:52 UTC
[isis] 03/06: ISIS-2726: collapses SudoServiceDefault into
SudoServiec
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2726
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 39f38477388e39e61436c4b0ddfd9a129c5a29c1
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jun 11 06:07:10 2021 +0100
ISIS-2726: collapses SudoServiceDefault into SudoServiec
No need to support multiple implementations here
---
.../org/apache/isis/applib/IsisModuleApplib.java | 4 +-
.../isis/applib/services/sudo/SudoService.java | 57 +++++++++++++++++++---
.../applib/services/sudo/SudoServiceDefault.java | 56 ---------------------
.../applib/services/sudo/SudoServiceListener.java | 9 +---
.../isis/applib/services/sudo/package-info.java | 29 -----------
.../bootstrapping/builtin-domain-services.list | 2 +-
.../bootstrapping/builtin-domain-services.list | 2 +-
7 files changed, 55 insertions(+), 104 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
index fa05dfe..41a2972 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/IsisModuleApplib.java
@@ -51,7 +51,7 @@ import org.apache.isis.applib.services.publishing.log.EntityChangesLogger;
import org.apache.isis.applib.services.publishing.log.EntityPropertyChangeLogger;
import org.apache.isis.applib.services.publishing.log.ExecutionLogger;
import org.apache.isis.applib.services.session.SessionLoggingServiceLogging;
-import org.apache.isis.applib.services.sudo.SudoServiceDefault;
+import org.apache.isis.applib.services.sudo.SudoService;
import org.apache.isis.applib.services.user.ImpersonateMenu;
import org.apache.isis.applib.services.user.RoleMemento;
import org.apache.isis.applib.services.user.UserMemento;
@@ -108,7 +108,7 @@ import org.apache.isis.schema.IsisModuleSchema;
EntityPropertyChangeLogger.class,
ExecutionLogger.class,
SessionLoggingServiceLogging.class,
- SudoServiceDefault.class,
+ SudoService.class,
})
public class IsisModuleApplib {
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
index 652b49c..2a1e880 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
@@ -18,15 +18,29 @@
*/
package org.apache.isis.applib.services.sudo;
+import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.UnaryOperator;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Primary;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Service;
+
+import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.services.iactnlayer.InteractionContext;
+import org.apache.isis.applib.services.iactnlayer.InteractionService;
+import org.apache.isis.applib.services.iactnlayer.InteractionTracker;
+import org.apache.isis.applib.services.iactnlayer.ThrowingRunnable;
import org.apache.isis.applib.services.user.RoleMemento;
import org.apache.isis.applib.services.user.UserService;
-import org.apache.isis.applib.services.iactnlayer.ThrowingRunnable;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import lombok.val;
/**
* Allows a block of code to be executed within an arbitrary
@@ -35,7 +49,7 @@ import lombok.NonNull;
*
* <p>
* Most typically this service is used to temporarily change the
- * &qout;who", that is the user reported by the {@link UserService}'s
+ * "who", that is the user reported by the {@link UserService}'s
* {@link UserService#currentUser() getUser()} - hence the name SudoService.
* But the user's locale and timezome can also be changed, as well as the time
* reported by {@link org.apache.isis.applib.services.clock.ClockService}.
@@ -48,17 +62,27 @@ import lombok.NonNull;
*
* @since 1.x revised for 2.0 {@index}
*/
-public interface SudoService {
+@Service
+@Named("isis.applib.SudoService")
+@Order(OrderPrecedence.MIDPOINT)
+@Primary
+@Qualifier("Default")
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
+public class SudoService {
/**
* If included in the list of roles, then will disable security checks (can view and use all object members).
*/
- RoleMemento ACCESS_ALL_ROLE =
+ public static RoleMemento ACCESS_ALL_ROLE =
new RoleMemento(
SudoService.class.getName() + "#accessAll",
"Sudo, can view and use all object members.");
+ private final InteractionService interactionService;
+ private final InteractionTracker interactionTracker;
+ private final List<SudoServiceListener> sudoListeners;
+
/**
* Executes the supplied {@link Callable} block, within the provided
* {@link InteractionContext}.
@@ -66,9 +90,27 @@ public interface SudoService {
* @param sudoMapper - maps the current {@link InteractionContext} to the sudo one
* @since 2.0
*/
- <T> T call(
+ public <T> T call(
final @NonNull UnaryOperator<InteractionContext> sudoMapper,
- final @NonNull Callable<T> supplier);
+ final @NonNull Callable<T> callable) {
+
+ val currentInteractionLayer = interactionTracker.currentInteractionLayerElseFail();
+ val currentInteractionContext = currentInteractionLayer.getInteractionContext();
+ val sudoInteractionContext = sudoMapper.apply(currentInteractionContext);
+
+ try {
+ for (val sudoListener : sudoListeners) {
+ sudoListener.beforeCall(currentInteractionContext, sudoInteractionContext);
+ }
+
+ return interactionService.call(sudoInteractionContext, callable);
+
+ } finally {
+ for (val sudoListener : sudoListeners) {
+ sudoListener.afterCall(sudoInteractionContext, currentInteractionContext);
+ }
+ }
+ }
/**
* Executes the supplied {@link Callable} block, within the provided
@@ -77,11 +119,10 @@ public interface SudoService {
* @param sudoMapper - maps the current {@link InteractionContext} to the sudo one
* @since 2.0
*/
- default void run(
+ public void run(
final @NonNull UnaryOperator<InteractionContext> sudoMapper,
final @NonNull ThrowingRunnable runnable) {
call(sudoMapper, ThrowingRunnable.toCallable(runnable));
}
-
}
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceDefault.java b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceDefault.java
index 2024e1b..fb1b63d 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceDefault.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceDefault.java
@@ -45,64 +45,8 @@ import lombok.val;
import jakarta.annotation.PostConstruct;
-@Service
-@Named("isis.applib.SudoServiceDefault")
-@Order(OrderPrecedence.MIDPOINT)
-@Primary
-@Qualifier("Default")
-@RequiredArgsConstructor(onConstructor_ = {@Inject})
public class SudoServiceDefault implements SudoService {
- private final InteractionService interactionService;
- private final InteractionTracker interactionTracker;
-
- // -- LISTENERS
-
- private Can<SudoServiceListener> sudoListeners = Can.empty();
-
- @PostConstruct @Inject
- public void init(final ServiceRegistry serviceRegistry) {
- this.sudoListeners = serviceRegistry.select(SudoServiceListener.class);
- }
-
- // -- IMPLEMENTATION
-
- @Override
- public <T> T call(
- final @NonNull UnaryOperator<InteractionContext> sudoMapper,
- final @NonNull Callable<T> callable) {
-
- val currentInteractionLayer = interactionTracker.currentInteractionLayerElseFail();
- val currentInteractionContext = currentInteractionLayer.getInteractionContext();
- val sudoInteractionContext = sudoMapper.apply(currentInteractionContext);
-
- try {
- beforeCall(currentInteractionContext, sudoInteractionContext);
-
- return interactionService
- .call(sudoInteractionContext, callable);
- } finally {
- afterCall(sudoInteractionContext, currentInteractionContext);
- }
- }
-
- // -- HELPER
-
- private void beforeCall(
- final @NonNull InteractionContext before,
- final @NonNull InteractionContext after) {
- for (val sudoListener : sudoListeners) {
- sudoListener.beforeCall(before, after);
- }
- }
-
- private void afterCall(
- final @NonNull InteractionContext before,
- final @NonNull InteractionContext after) {
- for (val sudoListener : sudoListeners) {
- sudoListener.afterCall(before, after);
- }
- }
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceListener.java b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceListener.java
index 2d4c08e..d7b6fd9 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceListener.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoServiceListener.java
@@ -23,13 +23,8 @@ import org.apache.isis.applib.services.iactnlayer.InteractionContext;
import lombok.NonNull;
/**
- * Allows the {@link SudoService} to notify other services/components that
- * the effective user has been changed.
- *
- * <p>
- * The subscribing domain service need only implement this interface,
- * there is no need to explicitly register as a subscriber.
- * </p>
+ * Allows the {@link SudoService} to notify other {@link org.springframework.stereotype.Service}s or
+ * {@link org.springframework.stereotype.Component}s that the effective user has been changed.
*
* @since 2.0
*/
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/package-info.java b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/package-info.java
deleted file mode 100644
index 8d64ee6..0000000
--- a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/package-info.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * The {@link org.apache.isis.applib.services.sudo.SudoService} allows the current user reported by the
- * {@link org.apache.isis.applib.services.user.UserService} to be temporarily changed to some other user. This is
- * useful both for integration testing (eg if testing a workflow system whereby objects are moved from one user to
- * another) and while running fixture scripts (eg setting up objects that would normally require several users to have
- * acted upon the objects).
- *
- *
- */
-package org.apache.isis.applib.services.sudo;
\ No newline at end of file
diff --git a/regressiontests/stable-bootstrapping/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list b/regressiontests/stable-bootstrapping/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list
index e155084..20b36a5 100644
--- a/regressiontests/stable-bootstrapping/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list
+++ b/regressiontests/stable-bootstrapping/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list
@@ -35,6 +35,6 @@ org.apache.isis.core.runtimeservices.confmenu.ConfigurationViewServiceDefault
org.apache.isis.core.runtimeservices.email.EmailServiceDefault
org.apache.isis.core.runtimeservices.i18n.po.TranslationServicePoMenu
org.apache.isis.core.runtimeservices.ixn.InteractionDtoServiceInternalDefault
-org.apache.isis.applib.services.sudo.SudoServiceDefault
+org.apache.isis.applib.services.sudo.SudoService
org.apache.isis.core.runtimeservices.userprof.UserProfileServiceDefault
org.apache.isis.core.runtimeservices.userreg.EmailNotificationServiceDefault
diff --git a/regressiontests/stable-rest/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list b/regressiontests/stable-rest/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list
index e155084..20b36a5 100644
--- a/regressiontests/stable-rest/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list
+++ b/regressiontests/stable-rest/src/test/resources/org/apache/isis/testdomain/bootstrapping/builtin-domain-services.list
@@ -35,6 +35,6 @@ org.apache.isis.core.runtimeservices.confmenu.ConfigurationViewServiceDefault
org.apache.isis.core.runtimeservices.email.EmailServiceDefault
org.apache.isis.core.runtimeservices.i18n.po.TranslationServicePoMenu
org.apache.isis.core.runtimeservices.ixn.InteractionDtoServiceInternalDefault
-org.apache.isis.applib.services.sudo.SudoServiceDefault
+org.apache.isis.applib.services.sudo.SudoService
org.apache.isis.core.runtimeservices.userprof.UserProfileServiceDefault
org.apache.isis.core.runtimeservices.userreg.EmailNotificationServiceDefault