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

commit 026b8717d4f4d5c9913e33df7a17578954f91228
Author: Andi Huber <[email protected]>
AuthorDate: Fri Apr 24 06:23:23 2020 +0200

    ISIS-2340: share logic of ObjectAdapterAccessHelper/UpdateHelper (3)
---
 .../binding/interaction/ActionInteractor.java      | 20 +++++++++++-
 .../binding/interaction/CollectionInteractor.java  | 20 +++++++++++-
 .../binding/interaction/MemberInteractor.java      | 38 ++++++++++++++++++----
 .../binding/interaction/PropertyInteractor.java    | 23 +++++++++++--
 .../resources/ObjectAdapterAccessHelper.java       | 22 ++++---------
 5 files changed, 95 insertions(+), 28 deletions(-)

diff --git 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionInteractor.java
 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionInteractor.java
index 3136316..60f5ae4 100644
--- 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionInteractor.java
+++ 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionInteractor.java
@@ -1,3 +1,21 @@
+/*
+ *  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.
+ */
 package org.apache.isis.viewer.common.model.binding.interaction;
 
 import org.apache.isis.applib.annotation.Where;
@@ -25,7 +43,7 @@ public class ActionInteractor extends MemberInteractor {
         val action = spec.getObjectAction(actionId).orElse(null);
         
         if(action==null) {
-            return _Either.right(InteractionResponse.failed(Veto.NOT_FOUND));
+            return super.notFound(MemberType.ACTION, actionId, Veto.NOT_FOUND);
         }
         
         return super.memberThatIsVisibleForIntent(
diff --git 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionInteractor.java
 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionInteractor.java
index 1459243..b30f0a8 100644
--- 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionInteractor.java
+++ 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionInteractor.java
@@ -1,3 +1,21 @@
+/*
+ *  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.
+ */
 package org.apache.isis.viewer.common.model.binding.interaction;
 
 import org.apache.isis.applib.annotation.Where;
@@ -24,7 +42,7 @@ public class CollectionInteractor extends MemberInteractor {
         val spec = managedObject.getSpecification();
         val collection = spec.getAssociation(collectionId).orElse(null);
         if(collection==null || !collection.isOneToOneAssociation()) {
-            return _Either.right(InteractionResponse.failed(Veto.NOT_FOUND));
+            return super.notFound(MemberType.COLLECTION, collectionId, 
Veto.NOT_FOUND);
         }
         
         return super.memberThatIsVisibleForIntent(
diff --git 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/MemberInteractor.java
 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/MemberInteractor.java
index a9168d0..7651891 100644
--- 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/MemberInteractor.java
+++ 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/MemberInteractor.java
@@ -1,3 +1,21 @@
+/*
+ *  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.
+ */
 package org.apache.isis.viewer.common.model.binding.interaction;
 
 import org.apache.isis.applib.annotation.Where;
@@ -12,7 +30,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.val;
 
 @RequiredArgsConstructor
-public class MemberInteractor {
+class MemberInteractor {
     
     // only used to create failure messages
     static enum MemberType {
@@ -23,7 +41,7 @@ public class MemberInteractor {
     
     protected final ObjectInteractor objectInteractor;
 
-    public <T extends ObjectMember> 
+    protected <T extends ObjectMember> 
     _Either<T, InteractionResponse> memberThatIsVisibleForIntent(
             final MemberType memberType,
             final T objectMember, 
@@ -36,11 +54,7 @@ public class MemberInteractor {
                         managedObject, InteractionInitiatedBy.USER, where);
         if (visibilityConsent.isVetoed()) {
             val memberId = objectMember.getId();
-            return _Either.right(InteractionResponse.failed(
-                    Veto.HIDDEN,
-                    String.format("%s '%s' either does not exist, is disabled 
or is not visible", 
-                            memberId, 
-                            memberType.name().toLowerCase())));
+            return notFound(memberType, memberId, Veto.HIDDEN);
         }
         if (intent.isMutate()) {
             final Consent usabilityConsent = objectMember.isUsable(
@@ -54,4 +68,14 @@ public class MemberInteractor {
         return _Either.left(objectMember);
     }
     
+    protected <T extends ObjectMember> 
+    _Either<T, InteractionResponse> notFound(MemberType memberType, String 
memberId, Veto veto) {
+        return _Either.right(InteractionResponse.failed(
+                veto,
+                String.format("%s '%s' either does not exist, is disabled or 
is not visible", 
+                        memberId, 
+                        memberType.name().toLowerCase())));
+    }
+    
+    
 }
diff --git 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/PropertyInteractor.java
 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/PropertyInteractor.java
index 83352d5..853be97 100644
--- 
a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/PropertyInteractor.java
+++ 
b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/PropertyInteractor.java
@@ -1,3 +1,21 @@
+/*
+ *  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.
+ */
 package org.apache.isis.viewer.common.model.binding.interaction;
 
 import org.apache.isis.applib.annotation.Where;
@@ -24,12 +42,11 @@ public class PropertyInteractor extends MemberInteractor {
         val spec = managedObject.getSpecification();
         val property = spec.getAssociation(propertyId).orElse(null);
         if(property==null || !property.isOneToOneAssociation()) {
-            return _Either.right(InteractionResponse.failed(Veto.NOT_FOUND));
+            return super.notFound(MemberType.PROPERTY, propertyId, 
Veto.NOT_FOUND);
         }
         
         return super.memberThatIsVisibleForIntent(
-                MemberType.PROPERTY,
-                (OneToOneAssociation)property, where, intent);
+                MemberType.PROPERTY, (OneToOneAssociation)property, where, 
intent);
     }
 
 }
diff --git 
a/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/ObjectAdapterAccessHelper.java
 
b/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/ObjectAdapterAccessHelper.java
index 2785cee..e77e859 100644
--- 
a/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/ObjectAdapterAccessHelper.java
+++ 
b/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/ObjectAdapterAccessHelper.java
@@ -41,16 +41,6 @@ import lombok.val;
 @RequiredArgsConstructor
 public class ObjectAdapterAccessHelper {
 
-    public static RestfulObjectsApplicationException notFoundException(
-            final String memberId, final MemberType memberType) {
-        final String memberTypeStr = memberType.name().toLowerCase();
-        return RestfulObjectsApplicationException.createWithMessage(
-                RestfulResponse.HttpStatusCode.NOT_FOUND, 
-                "%s '%s' either does not exist, is disabled or is not 
visible", 
-                memberTypeStr,
-                memberId);
-    }
-    
     public static ObjectAdapterAccessHelper of(
             final IResourceContext resourceContext,
             final ManagedObject managedObject) {
@@ -64,9 +54,9 @@ public class ObjectAdapterAccessHelper {
 
     public OneToOneAssociation getPropertyThatIsVisibleForIntent(
             final String propertyId, final AccessIntent intent) {
-        
+
         val propertyInteractor = objectInteractor.getPropertyInteractor();
-        
+
         val check = 
propertyInteractor.getPropertyThatIsVisibleForIntent(propertyId, where, intent);
         check.right()
         .ifPresent(failure->handleFailure(failure, propertyId, 
MemberType.PROPERTY));
@@ -76,9 +66,9 @@ public class ObjectAdapterAccessHelper {
 
     public OneToManyAssociation getCollectionThatIsVisibleForIntent(
             final String collectionId, final AccessIntent intent) {
-        
+
         val propertyInteractor = objectInteractor.getCollectionInteractor();
-        
+
         val check = 
propertyInteractor.getPropertyThatIsVisibleForIntent(collectionId, where, 
intent);
         check.right()
         .ifPresent(failure->handleFailure(failure, collectionId, 
MemberType.COLLECTION));
@@ -90,7 +80,7 @@ public class ObjectAdapterAccessHelper {
             final String actionId, final AccessIntent intent) {
 
         val actionInteractor = objectInteractor.getActionInteractor();
-        
+
         val check = actionInteractor.getActionThatIsVisibleForIntent(actionId, 
where, intent);
         check.right()
         .ifPresent(failure->handleFailure(failure, actionId, 
MemberType.ACTION));
@@ -112,5 +102,5 @@ public class ObjectAdapterAccessHelper {
                     failure.getFailureMessage());
         }
     }
-    
+
 }

Reply via email to