You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by GitBox <gi...@apache.org> on 2021/06/09 14:14:05 UTC

[GitHub] [isis] danhaywood opened a new pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

danhaywood opened a new pull request #590:
URL: https://github.com/apache/isis/pull/590


   This includes bringing in InteractionLayer (renamed from AuthenticationLayer) to the applib as well.  And ThrowingRunnable has gone from commons to applib.
   
   This new interface is implemented by InteractionFactoryDefault.  The main difference is that whereas we used to require an Authentication (even an anonymous one) in order to create a new interaction layer, we can now do this with just InteractionContext (the new name for ExecutionContext as was).  We allow an Authentiation to not get lost by having InteractionContext hold onto an arbitrary map of attributes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] andi-huber merged pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
andi-huber merged pull request #590:
URL: https://github.com/apache/isis/pull/590


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] danhaywood commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
danhaywood commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648485085



##########
File path: api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionService.java
##########
@@ -0,0 +1,102 @@
+package org.apache.isis.applib.services.iactnlayer;
+
+import java.util.concurrent.Callable;
+
+import lombok.NonNull;
+
+/**
+ * A low-level service to programmatically &quot;connect&quot; (or create a
+ * session, or interact with; choose your term) the the framework's runtime.
+ *
+ * <p>
+ *     This service is used internally by the framework itself, for example
+ *     when a viewer receives a request a new {@link InteractionLayer} is created
+ *     for the duration of the users's interaction.  It is also used by integration
+ *     tests, to be able to connect to the database.
+ * </p>
+ *
+ * <p>
+ *     You could think of this as analogous to an <code>HttpRequest</code>, or
+ *     a JPA <code>EntityManager</code> or JDO <code>PersistenceManager</code>.
+ * </p>
+ *
+ * <p>
+ *     There are two main APIs exposed.  One is to
+ *     {@link #openInteraction(InteractionContext) open} a new {@link InteractionLayer},
+ *     to be {@link #closeInteractionLayers() closed later}.  The other is to
+ *     execute a {@link Callable} or {@link ThrowingRunnable runnable} within the
+ *     duration of an {@link InteractionLayer}, wrapping up automatically.
+ *     This is what is used by {@link org.apache.isis.applib.services.sudo.SudoService}, for example.
+ * </p>
+ *
+ * @since 2.x {@index}
+ */
+public interface InteractionService {

Review comment:
       Agree, I think I intended to do this then forgot.  Will add it in.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] danhaywood commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
danhaywood commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648483475



##########
File path: api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContext.java
##########
@@ -69,15 +75,53 @@
     @With @Getter @Builder.Default
     @NonNull TimeZone timeZone = TimeZone.getDefault();
 
+    Map<String, Serializable> attributes = new HashMap<>();

Review comment:
       Hmm, ok.  What I was aiming to do, as I hope is clear, is have the new InteractionService only know about InteractionContext, not about the fact that usually an InteractionContext comes from an Authentication.  So this was a way to invert the dependency (or make it bidirectional, in fact).
   
   Where we are now is that InteractionLayer binds together (Isis)Interation = "what" is being executed + InteractionContext (= "who", "when" and "where" being executed).  Authentication is just a thin wrapper around InteractionContext, which holds the "who".  Using (Isis)Interaction to hold onto these "who" attributes seems a bit wierd.
   
   I'm just wondering - perhaps InteractionLayer might be a better place for these attributes than either (Isis)Interaction or InteractionContext.  Thoughts?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] danhaywood commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
danhaywood commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648484780



##########
File path: commons/src/main/java/org/apache/isis/commons/functional/Result.java
##########
@@ -61,10 +61,6 @@
         }
     }
 
-    public static Result<Void> ofVoid(final @NonNull ThrowingRunnable runnable) {

Review comment:
       applib -[depends upon]-> common, but not vice versa, which is why this had to go.  Instead it has become ThrowingRunnable.resultOf(...)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] danhaywood commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
danhaywood commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648485320



##########
File path: core/security/src/main/java/org/apache/isis/core/security/authentication/Authentication.java
##########
@@ -91,8 +101,24 @@ default Type getType() {
     // -- WITHERS
 
     /**
-     * Returns a copy with given {@code executionContext}.
-     * @param executionContext
+     * Returns a copy with given {@code interactionContext}.
+     * @param interactionContext
      */
-    Authentication withExecutionContext(ExecutionContext executionContext);
+    Authentication withInteractionContext(InteractionContext interactionContext);
+
+    /**
+     * Looks up an {@link Authentication} from the provided {@link InteractionContext}.
+     *
+     * <p>
+     *     If the {@link InteractionContext} was created as the result of an authentication process (as opposed to
+     *     programmatically) then there will be an attached {@link Authentication} object.
+     * </p>
+     *
+     * @param interactionContext
+     * @return
+     */
+    public static Optional<Authentication> authenticationFrom(final @NonNull InteractionContext interactionContext) {

Review comment:
       per comment above, perhaps use InteractionLayer ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] danhaywood commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
danhaywood commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648484147



##########
File path: api/applib/src/main/java/org/apache/isis/applib/services/xactn/TransactionalProcessor.java
##########
@@ -25,7 +25,7 @@
 import org.springframework.transaction.support.DefaultTransactionDefinition;
 
 import org.apache.isis.commons.functional.Result;
-import org.apache.isis.commons.functional.ThrowingRunnable;

Review comment:
       Domain apps depend on applib but as the dependency from applib -> common is only scope="provided", in my view they shouldn't have a hard dependency on common as well.  So this was to ensure that everything that a domain app might use is also in applib.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] danhaywood commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
danhaywood commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648485455



##########
File path: core/security/src/main/java/org/apache/isis/core/security/authentication/manager/AnonymousInteractionFactory.java
##########
@@ -38,10 +38,19 @@
  */
 public interface AnonymousInteractionFactory {

Review comment:
       yup




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [isis] andi-huber commented on a change in pull request #590: Isis 2727 : factors out InteractionService as a low-level service available in the applib.

Posted by GitBox <gi...@apache.org>.
andi-huber commented on a change in pull request #590:
URL: https://github.com/apache/isis/pull/590#discussion_r648429168



##########
File path: api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContext.java
##########
@@ -69,15 +75,53 @@
     @With @Getter @Builder.Default
     @NonNull TimeZone timeZone = TimeZone.getDefault();
 
+    Map<String, Serializable> attributes = new HashMap<>();

Review comment:
       Breaks with the original idea of InteractionContext being a value (immutable). Functionality for storing attributes is in IsisInteraction.

##########
File path: core/security/src/main/java/org/apache/isis/core/security/authentication/Authentication.java
##########
@@ -91,8 +101,24 @@ default Type getType() {
     // -- WITHERS
 
     /**
-     * Returns a copy with given {@code executionContext}.
-     * @param executionContext
+     * Returns a copy with given {@code interactionContext}.
+     * @param interactionContext
      */
-    Authentication withExecutionContext(ExecutionContext executionContext);
+    Authentication withInteractionContext(InteractionContext interactionContext);
+
+    /**
+     * Looks up an {@link Authentication} from the provided {@link InteractionContext}.
+     *
+     * <p>
+     *     If the {@link InteractionContext} was created as the result of an authentication process (as opposed to
+     *     programmatically) then there will be an attached {@link Authentication} object.
+     * </p>
+     *
+     * @param interactionContext
+     * @return
+     */
+    public static Optional<Authentication> authenticationFrom(final @NonNull InteractionContext interactionContext) {

Review comment:
       relates to a comment above, that InteractionContext should be immutable; I hope there are alternative ways to get the (current) Authentication; not sure

##########
File path: api/applib/src/main/java/org/apache/isis/applib/services/xactn/TransactionalProcessor.java
##########
@@ -25,7 +25,7 @@
 import org.springframework.transaction.support.DefaultTransactionDefinition;
 
 import org.apache.isis.commons.functional.Result;
-import org.apache.isis.commons.functional.ThrowingRunnable;

Review comment:
       Why not keep using 'commons' for ThrowingRunnable?

##########
File path: api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionService.java
##########
@@ -0,0 +1,102 @@
+package org.apache.isis.applib.services.iactnlayer;
+
+import java.util.concurrent.Callable;
+
+import lombok.NonNull;
+
+/**
+ * A low-level service to programmatically &quot;connect&quot; (or create a
+ * session, or interact with; choose your term) the the framework's runtime.
+ *
+ * <p>
+ *     This service is used internally by the framework itself, for example
+ *     when a viewer receives a request a new {@link InteractionLayer} is created
+ *     for the duration of the users's interaction.  It is also used by integration
+ *     tests, to be able to connect to the database.
+ * </p>
+ *
+ * <p>
+ *     You could think of this as analogous to an <code>HttpRequest</code>, or
+ *     a JPA <code>EntityManager</code> or JDO <code>PersistenceManager</code>.
+ * </p>
+ *
+ * <p>
+ *     There are two main APIs exposed.  One is to
+ *     {@link #openInteraction(InteractionContext) open} a new {@link InteractionLayer},
+ *     to be {@link #closeInteractionLayers() closed later}.  The other is to
+ *     execute a {@link Callable} or {@link ThrowingRunnable runnable} within the
+ *     duration of an {@link InteractionLayer}, wrapping up automatically.
+ *     This is what is used by {@link org.apache.isis.applib.services.sudo.SudoService}, for example.
+ * </p>
+ *
+ * @since 2.x {@index}
+ */
+public interface InteractionService {

Review comment:
       I think we could merge those methods from AnonymousInteractionFactory, then remove AnonymousInteractionFactory.

##########
File path: commons/src/main/java/org/apache/isis/commons/functional/Result.java
##########
@@ -61,10 +61,6 @@
         }
     }
 
-    public static Result<Void> ofVoid(final @NonNull ThrowingRunnable runnable) {

Review comment:
       maybe keep for convenience?

##########
File path: core/security/src/main/java/org/apache/isis/core/security/authentication/manager/AnonymousInteractionFactory.java
##########
@@ -38,10 +38,19 @@
  */
 public interface AnonymousInteractionFactory {

Review comment:
       probably merge into InteractionService, then remove.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org