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 2020/01/13 14:05:26 UTC

[isis] branch master updated: ISIS-2262: polishing + sync adoc

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 9435767  ISIS-2262: polishing + sync adoc
9435767 is described below

commit 943576796658cda212f32b11e033120026294ccf
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 13 15:05:16 2020 +0100

    ISIS-2262: polishing + sync adoc
---
 .../exceprecog/ExceptionRecognizerAbstract.java    | 11 +++-----
 .../exceprecog/ExceptionRecognizerForType.java     |  9 ++++---
 .../exceprecog/ExceptionRecognizerService.java     | 23 +++++++++++++---
 .../exceprecog/ExceptionRecognizerService.java     | 15 +++++++----
 .../apache/isis/core/commons/collections/Can.java  |  1 +
 .../isis/core/commons/collections/Can_Empty.java   |  5 ++++
 .../core/commons/collections/Can_Multiple.java     | 11 ++++++++
 .../core/commons/collections/Can_Singleton.java    | 15 +++++++++++
 .../ExceptionRecognizerServiceDefault.java         | 31 +++++-----------------
 .../viewer/integration/WebRequestCycleForIsis.java |  6 ++++-
 10 files changed, 82 insertions(+), 45 deletions(-)

diff --git a/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerAbstract.java b/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerAbstract.java
index 77433b4..dd849bb 100644
--- a/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerAbstract.java
+++ b/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerAbstract.java
@@ -22,6 +22,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
 
 import javax.inject.Inject;
 
@@ -79,14 +80,8 @@ public abstract class ExceptionRecognizerAbstract implements ExceptionRecognizer
      * Convenience for subclass implementations that always prefixes the exception message
      * with the supplied text
      */
-    protected static Function<String, String> prefix(final String prefix) {
-        return new Function<String, String>() {
-
-            @Override
-            public String apply(String input) {
-                return prefix + ": " + input;
-            }
-        };
+    protected static UnaryOperator<String> prefix(final String prefix) {
+        return $->prefix + ": " + $;
     }
 
     // //////////////////////////////////////
diff --git a/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerForType.java b/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerForType.java
index 0cb2674..ee4feeb 100644
--- a/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerForType.java
+++ b/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerForType.java
@@ -21,6 +21,7 @@ package org.apache.isis.applib.services.exceprecog;
 import java.util.List;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
 import java.util.stream.Stream;
 
 import org.apache.isis.core.commons.internal.exceptions._Exceptions;
@@ -147,14 +148,14 @@ public class ExceptionRecognizerForType extends ExceptionRecognizerAbstract {
     public ExceptionRecognizerForType(
             Category category,
             final Class<? extends Exception> exceptionType,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(category, ofType(exceptionType), messageParser);
     }
 
     public ExceptionRecognizerForType(
             Category category,
             final Predicate<Throwable> predicate,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         super(category, predicate, messageParser);
     }
 
@@ -164,13 +165,13 @@ public class ExceptionRecognizerForType extends ExceptionRecognizerAbstract {
 
     public ExceptionRecognizerForType(
             final Class<? extends Exception> exceptionType,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(Category.OTHER, exceptionType, messageParser);
     }
 
     public ExceptionRecognizerForType(
             final Predicate<Throwable> predicate,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(Category.OTHER, predicate, messageParser);
     }
 
diff --git a/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerService.java b/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerService.java
index 8c6cf6f..ed2ef57 100644
--- a/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerService.java
+++ b/api/applib/src/main/doc/modules/applib-svc/examples/services/exceprecog/ExceptionRecognizerService.java
@@ -32,12 +32,29 @@ public interface ExceptionRecognizerService {
 
     /**
      * 
-     * @return all ExceptionRecognizer implementations as discovered by the IoC container. 
+     * @return all ExceptionRecognizer implementations as discovered by the IoC container, 
+     * honoring order of precedence. 
      */
     Can<ExceptionRecognizer> getExceptionRecognizers();
 
-    Optional<Recognition> recognize(Exception ex);
+    /**
+     * Takes into consideration ExceptionRecognizers as given by {@link #getExceptionRecognizers()}.
+     * @param ex
+     * @return optionally a recognition object, that describes both the category and reason, 
+     * that will be included with the user-friendly message. 
+     */
+    default Optional<Recognition> recognize(Exception ex) {
+        return recognizeFromSelected(getExceptionRecognizers(), ex);
+    }
+
+    /**
+     * Takes into consideration ExceptionRecognizers as given by {@code recognizers}.
+     * @param recognizers
+     * @param ex
+     * @return optionally a recognition object, that describes both the category and reason, 
+     * that will be included with the user-friendly message. 
+     */
+    Optional<Recognition> recognizeFromSelected(Can<ExceptionRecognizer> recognizers, Exception ex);
 
-    Optional<Recognition> recognize(Exception ex, Can<ExceptionRecognizer> additionalRecognizers);
 
 }
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java
index a25350d..ed2ef57 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java
@@ -38,18 +38,23 @@ public interface ExceptionRecognizerService {
     Can<ExceptionRecognizer> getExceptionRecognizers();
 
     /**
+     * Takes into consideration ExceptionRecognizers as given by {@link #getExceptionRecognizers()}.
      * @param ex
      * @return optionally a recognition object, that describes both the category and reason, 
      * that will be included with the user-friendly message. 
      */
-    Optional<Recognition> recognize(Exception ex);
+    default Optional<Recognition> recognize(Exception ex) {
+        return recognizeFromSelected(getExceptionRecognizers(), ex);
+    }
 
     /**
-     * Extends {@link #recognize(Exception)} with additional recognizers to be taken into consideration,
-     * with least precedence order.  
+     * Takes into consideration ExceptionRecognizers as given by {@code recognizers}.
+     * @param recognizers
      * @param ex
-     * @param additionalRecognizers
+     * @return optionally a recognition object, that describes both the category and reason, 
+     * that will be included with the user-friendly message. 
      */
-    Optional<Recognition> recognize(Exception ex, Can<ExceptionRecognizer> additionalRecognizers);
+    Optional<Recognition> recognizeFromSelected(Can<ExceptionRecognizer> recognizers, Exception ex);
+
 
 }
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java
index bc615d0..9ea69a4 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can.java
@@ -371,6 +371,7 @@ public interface Can<T> extends Iterable<T> {
     // -- MANIPULATION
     
     Can<T> add(T element);
+    Can<T> addAll(Can<T> other);
     
     /**
      * Inserts the specified element at the specified position in this list
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java
index acb595b..cde6418 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Empty.java
@@ -81,6 +81,11 @@ final class Can_Empty<T> implements Can<T> {
     }
     
     @Override
+    public Can<T> addAll(@NonNull Can<T> other) {
+        return other;
+    }
+    
+    @Override
     public Can<T> add(int index, @NonNull T element) {
         if(index!=0) {
             throw new IndexOutOfBoundsException(
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java
index d120f09..fbc75e7 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Multiple.java
@@ -92,6 +92,17 @@ final class Can_Multiple<T> implements Can<T> {
     }
     
     @Override
+    public Can<T> addAll(@NonNull Can<T> other) {
+        if(other.isEmpty()) {
+            return this;
+        }
+        val newElements = new ArrayList<T>(this.size() + other.size());
+        newElements.addAll(elements);
+        other.forEach(newElements::add);
+        return Can_Multiple.of(newElements);
+    }
+    
+    @Override
     public Can<T> add(int index, @NonNull T element) {
         val newElements = new ArrayList<T>(elements);
         newElements.add(index, element);
diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java
index 0962676..57a1a23 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/collections/Can_Singleton.java
@@ -19,6 +19,7 @@
 package org.apache.isis.core.commons.collections;
 
 import java.lang.reflect.Array;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -78,6 +79,20 @@ final class Can_Singleton<T> implements Can<T> {
     }
     
     @Override
+    public Can<T> addAll(@NonNull Can<T> other) {
+        if(other.isEmpty()) {
+            return this;
+        }
+        if(other.isCardinalityOne()) {
+            return add(other.getSingleton().get());
+        }
+        val newElements = new ArrayList<T>(other.size()+1);
+        newElements.add(element);
+        other.forEach(newElements::add);
+        return Can_Multiple.of(newElements);
+    }
+    
+    @Override
     public Can<T> add(int index, @NonNull T element) {
         if(index==0) {
             return Can.ofStream(Stream.of(element, this.element)); // insert before
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/exceprecog/ExceptionRecognizerServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/exceprecog/ExceptionRecognizerServiceDefault.java
index 1e3da61..15ca716 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/exceprecog/ExceptionRecognizerServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/exceprecog/ExceptionRecognizerServiceDefault.java
@@ -58,22 +58,16 @@ public class ExceptionRecognizerServiceDefault implements ExceptionRecognizerSer
     public Can<ExceptionRecognizer> getExceptionRecognizers() {
         return exceptionRecognizers.get();
     }
-    
-    @Override
-    public Optional<Recognition> recognize(@NonNull final Exception ex) {
-        return handleMultiple(getExceptionRecognizers(), ex);
-    }
 
     @Override
-    public Optional<Recognition> recognize(
-            @NonNull final Exception ex, 
-            @NonNull final Can<ExceptionRecognizer> additionalRecognizers) {
+    public Optional<Recognition> recognizeFromSelected(
+            @NonNull final Can<ExceptionRecognizer> recognizers,
+            @NonNull final Exception ex) {
         
-        val recognized = recognize(ex);
-        if(recognized.isPresent()) {
-            return recognized; 
-        }
-        return handleMultiple(additionalRecognizers, ex);
+        return recognizers.stream()
+                .map($->handleSingle($, ex))
+                .filter(_NullSafe::isPresent)
+                .findFirst();
     }
     
     // -- HELPER
@@ -93,15 +87,4 @@ public class ExceptionRecognizerServiceDefault implements ExceptionRecognizerSer
         
     }
     
-    private static Optional<Recognition> handleMultiple(
-            @NonNull final Can<ExceptionRecognizer> recognizers, 
-            @NonNull final Exception ex) {
-        
-        return recognizers.stream()
-            .map($->handleSingle($, ex))
-            .filter(_NullSafe::isPresent)
-            .findFirst();
-    }
-
-    
 }
diff --git a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java
index 0989516..02ce194 100644
--- a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java
+++ b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java
@@ -43,6 +43,7 @@ import org.apache.wicket.request.cycle.PageRequestHandlerTracker;
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer.Recognition;
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerService;
@@ -303,7 +304,10 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
             .lookupServiceElseFail(ExceptionRecognizerService.class);
             
             recognition = exceptionRecognizerService
-                    .recognize(ex, Can.ofSingleton(pageExpiredExceptionRecognizer));
+                    .recognizeFromSelected(
+                            Can.<ExceptionRecognizer>ofSingleton(pageExpiredExceptionRecognizer)
+                            .addAll(exceptionRecognizerService.getExceptionRecognizers()),
+                            ex);
             
         } else {