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 2021/09/04 09:36:50 UTC

[isis] branch master updated: ISIS-2865: fixes improper uses of LocalResourcePath

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 f95c7a5  ISIS-2865: fixes improper uses of LocalResourcePath
f95c7a5 is described below

commit f95c7a50f3c6204237b924c60c4fdb6a943bae8d
Author: andi-huber <ah...@apache.org>
AuthorDate: Sat Sep 4 11:36:41 2021 +0200

    ISIS-2865: fixes improper uses of LocalResourcePath
---
 .../isis/applib/value/LocalResourcePath.java       | 24 ++++++++++++----------
 .../LocalResourcePathValueSemanticsProvider.java   | 10 ++++++---
 .../applib/IsisLocalResourcePathConverter.java     |  6 +++---
 .../markup/ListeningMarkupComponent_observing.java |  2 +-
 .../viewer/wicket/model/models/ActionModel.java    |  6 ++++--
 .../actionresponse/ActionResultResponseType.java   |  9 +++++---
 6 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/value/LocalResourcePath.java b/api/applib/src/main/java/org/apache/isis/applib/value/LocalResourcePath.java
index 9ce2564..c6d7c7e 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/value/LocalResourcePath.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/value/LocalResourcePath.java
@@ -21,11 +21,13 @@ package org.apache.isis.applib.value;
 
 import java.io.Serializable;
 import java.net.URISyntaxException;
+import java.util.function.UnaryOperator;
 
-import org.springframework.lang.Nullable;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
+import org.springframework.lang.Nullable;
+
 import org.apache.isis.applib.IsisModuleApplib;
 import org.apache.isis.applib.annotation.Value;
 
@@ -79,13 +81,13 @@ public final class LocalResourcePath implements Serializable {
     }
 
     @NonNull
-    public Object getValue() {
+    public String getValue() {
         return path;
     }
 
     @NonNull
-    public String getPath() {
-        return path;
+    public String getEffectivePath(final @NonNull UnaryOperator<String> contextPathPrepender) {
+        return contextPathPrepender.apply(path);
     }
 
     @Override
@@ -94,7 +96,7 @@ public final class LocalResourcePath implements Serializable {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if(obj==null) {
             return false;
         }
@@ -106,16 +108,16 @@ public final class LocalResourcePath implements Serializable {
         return path.hashCode();
     }
 
-    public boolean isEqualTo(LocalResourcePath other) {
+    public boolean isEqualTo(final LocalResourcePath other) {
         if(other==null) {
             return false;
         }
-        return this.getPath().equals(other.getPath());
+        return this.getValue().equals(other.getValue());
     }
 
     // -- HELPER
 
-    private void validate(String path) throws IllegalArgumentException {
+    private void validate(final String path) throws IllegalArgumentException {
         if(path==null) {
             return;
         }
@@ -130,13 +132,13 @@ public final class LocalResourcePath implements Serializable {
 
     public static class JaxbToStringAdapter extends XmlAdapter<String, LocalResourcePath> {
         @Override
-        public LocalResourcePath unmarshal(String path) {
+        public LocalResourcePath unmarshal(final String path) {
             return path != null ? new LocalResourcePath(path) : null;
         }
 
         @Override
-        public String marshal(LocalResourcePath localResourcePath) {
-            return localResourcePath != null ? localResourcePath.getPath() : null;
+        public String marshal(final LocalResourcePath localResourcePath) {
+            return localResourcePath != null ? localResourcePath.getValue() : null;
         }
     }
 }
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/localrespath/LocalResourcePathValueSemanticsProvider.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/localrespath/LocalResourcePathValueSemanticsProvider.java
index 9344cd1..94a645e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/localrespath/LocalResourcePathValueSemanticsProvider.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/value/localrespath/LocalResourcePathValueSemanticsProvider.java
@@ -74,7 +74,9 @@ extends ValueSemanticsProviderAndFacetAbstract<LocalResourcePath> implements Loc
 
     @Override
     public String titleString(final Object object) {
-        return object instanceof LocalResourcePath ? ((LocalResourcePath)object).getPath(): "";
+        return object instanceof LocalResourcePath
+                ? ((LocalResourcePath)object).getValue()
+                : "";
     }
 
     @Override
@@ -87,8 +89,10 @@ extends ValueSemanticsProviderAndFacetAbstract<LocalResourcePath> implements Loc
     // //////////////////////////////////////////////////////////////////
 
     @Override
-    protected String doEncode(final LocalResourcePath url) {
-        return url != null ? url.getPath() : "NULL";
+    protected String doEncode(final LocalResourcePath localResourcePath) {
+        return localResourcePath != null
+                ? localResourcePath.getValue()
+                : "NULL";
     }
 
     @Override
diff --git a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/typeconverters/applib/IsisLocalResourcePathConverter.java b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/typeconverters/applib/IsisLocalResourcePathConverter.java
index 8e661a4..5d3ff6a 100644
--- a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/typeconverters/applib/IsisLocalResourcePathConverter.java
+++ b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/typeconverters/applib/IsisLocalResourcePathConverter.java
@@ -32,15 +32,15 @@ public class IsisLocalResourcePathConverter implements TypeConverter<LocalResour
     @Override
     public String toDatastoreType(final LocalResourcePath memberValue) {
         return memberValue != null
-                ? memberValue.getPath()
-                        : null;
+                ? memberValue.getValue()
+                : null;
     }
 
     @Override
     public LocalResourcePath toMemberType(final String datastoreValue) {
         return datastoreValue != null
                 ? new LocalResourcePath(datastoreValue)
-                        : null;
+                : null;
     }
 
 }
diff --git a/valuetypes/sse/ui/wicket/src/main/java/org/apache/isis/valuetypes/sse/ui/wkt/markup/ListeningMarkupComponent_observing.java b/valuetypes/sse/ui/wicket/src/main/java/org/apache/isis/valuetypes/sse/ui/wkt/markup/ListeningMarkupComponent_observing.java
index 9c24e93..bed65ae 100644
--- a/valuetypes/sse/ui/wicket/src/main/java/org/apache/isis/valuetypes/sse/ui/wkt/markup/ListeningMarkupComponent_observing.java
+++ b/valuetypes/sse/ui/wicket/src/main/java/org/apache/isis/valuetypes/sse/ui/wkt/markup/ListeningMarkupComponent_observing.java
@@ -58,7 +58,7 @@ final class ListeningMarkupComponent_observing  {
         }
 
         final String targetId = UUID.randomUUID().toString();
-        final String observingPath = webAppContextPath.prependContextPath(observing.getPath());
+        final String observingPath = observing.getEffectivePath(webAppContextPath::prependContextPath);
 
         final StringBuilder sb = new StringBuilder();
         sb
diff --git a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
index ab265b8..0ef7c5e 100644
--- a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
+++ b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
@@ -44,6 +44,7 @@ import org.apache.isis.applib.value.NamedWithMimeType;
 import org.apache.isis.applib.value.OpenUrlStrategy;
 import org.apache.isis.commons.collections.Can;
 import org.apache.isis.commons.internal.base._NullSafe;
+import org.apache.isis.core.config.viewer.web.WebAppContextPath;
 import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.isis.core.metamodel.facetapi.Facet;
 import org.apache.isis.core.metamodel.facetapi.FacetHolder;
@@ -265,7 +266,8 @@ implements FormUiModel, FormExecutorContext, BookmarkableModel {
 
     public static IRequestHandler redirectHandler(
             final Object value,
-            final @NonNull OpenUrlStrategy openUrlStrategy) {
+            final @NonNull OpenUrlStrategy openUrlStrategy,
+            final @NonNull WebAppContextPath webAppContextPath) {
 
         if(value instanceof java.net.URL) {
             val url = (java.net.URL) value;
@@ -274,7 +276,7 @@ implements FormUiModel, FormExecutorContext, BookmarkableModel {
         if(value instanceof LocalResourcePath) {
             val localResourcePath = (LocalResourcePath) value;
             return new RedirectRequestHandlerWithOpenUrlStrategy(
-                    localResourcePath.getPath(),
+                    localResourcePath.getEffectivePath(webAppContextPath::prependContextPath),
                     localResourcePath.getOpenUrlStrategy());
         }
         return null;
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java
index 7c15c78..aa08956 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/actionresponse/ActionResultResponseType.java
@@ -97,8 +97,9 @@ public enum ActionResultResponseType {
         @Override @SneakyThrows
         public ActionResultResponse interpretResult(final ActionModel model, final AjaxRequestTarget target, final ManagedObject resultAdapter) {
             final LocalResourcePath localResPath = (LocalResourcePath)resultAdapter.getPojo();
+            val webAppContextPath = model.getCommonContext().getWebAppContextPath();
             return ActionResultResponse
-                    .openUrlInBrowser(target, localResPath.getPath(), localResPath.getOpenUrlStrategy());
+                    .openUrlInBrowser(target, localResPath.getEffectivePath(webAppContextPath::prependContextPath), localResPath.getOpenUrlStrategy());
         }
     },
     VALUE_LOCALRESPATH_NOAJAX {
@@ -106,7 +107,8 @@ public enum ActionResultResponseType {
         public ActionResultResponse interpretResult(final ActionModel model, final AjaxRequestTarget target, final ManagedObject resultAdapter) {
             // open URL server-side redirect
             final LocalResourcePath localResPath = (LocalResourcePath)resultAdapter.getPojo();
-            IRequestHandler handler = ActionModel.redirectHandler(localResPath, localResPath.getOpenUrlStrategy());
+            val webAppContextPath = model.getCommonContext().getWebAppContextPath();
+            IRequestHandler handler = ActionModel.redirectHandler(localResPath, localResPath.getOpenUrlStrategy(), webAppContextPath);
             return ActionResultResponse.withHandler(handler);
         }
     },
@@ -123,7 +125,8 @@ public enum ActionResultResponseType {
         public ActionResultResponse interpretResult(final ActionModel model, final AjaxRequestTarget target, final ManagedObject resultAdapter) {
             // open URL server-side redirect
             final Object value = resultAdapter.getPojo();
-            IRequestHandler handler = ActionModel.redirectHandler(value, OpenUrlStrategy.NEW_WINDOW); // default behavior
+            val webAppContextPath = model.getCommonContext().getWebAppContextPath();
+            IRequestHandler handler = ActionModel.redirectHandler(value, OpenUrlStrategy.NEW_WINDOW, webAppContextPath); // default behavior
             return ActionResultResponse.withHandler(handler);
         }
     },