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/04/25 19:36:11 UTC
[isis] 07/08: ISIS-2340: share logic of
ObjectAdapterAccessHelper/UpdateHelper (7)
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 65d83a500fdd49b9c794837b295427148a915a2d
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Apr 24 13:47:51 2020 +0200
ISIS-2340: share logic of ObjectAdapterAccessHelper/UpdateHelper (7)
---
.../binding/interaction/ActionAccessChain.java | 53 +++++++++++++++++++++
.../binding/interaction/CollectionAccessChain.java | 54 ++++++++++++++++++++++
.../model/binding/interaction/ObjectBinding.java | 35 ++++++++------
.../resources/ObjectAdapterAccessHelper.java | 24 ++++------
4 files changed, 137 insertions(+), 29 deletions(-)
diff --git a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionAccessChain.java b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionAccessChain.java
new file mode 100644
index 0000000..a082ead
--- /dev/null
+++ b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ActionAccessChain.java
@@ -0,0 +1,53 @@
+package org.apache.isis.viewer.common.model.binding.interaction;
+
+import java.util.function.Consumer;
+
+import org.apache.isis.core.commons.internal.base._Either;
+import org.apache.isis.core.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor(staticName = "of")
+public class ActionAccessChain {
+
+ @NonNull private _Either<ActionBinding, InteractionResponse> chain;
+
+// public ActionAccessChain modifyProperty(
+// @NonNull final Function<OneToOneAssociation, ManagedObject> newProperyValueProvider) {
+//
+// chain = chain.leftRemap(propertyBinding->{
+// final InteractionResponse iResponse = propertyBinding.modifyProperty(newProperyValueProvider);
+// if(iResponse.isFailure()) {
+// _Either.right(iResponse);
+// }
+// return _Either.left(propertyBinding);
+// });
+//
+// return this;
+// }
+
+ public ActionAccessChain onFailure(Consumer<InteractionResponse> onFailure) {
+ chain.right().ifPresent(onFailure);
+ return this;
+ }
+
+ public ActionBinding getBinding() {
+ return chain.left()
+ .orElseThrow(_Exceptions::noSuchElement);
+ }
+
+ public ObjectAction getAction() {
+ return chain.left()
+ .map(ActionBinding::getAction)
+ .orElseThrow(_Exceptions::noSuchElement);
+ }
+
+ public ActionAccessChain ifPresent(Consumer<ActionBinding> actionBindingConsumer) {
+ chain.left().ifPresent(actionBindingConsumer::accept);
+ return this;
+ }
+
+
+}
diff --git a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionAccessChain.java b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionAccessChain.java
new file mode 100644
index 0000000..e00fff7
--- /dev/null
+++ b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/CollectionAccessChain.java
@@ -0,0 +1,54 @@
+package org.apache.isis.viewer.common.model.binding.interaction;
+
+import java.util.function.Consumer;
+
+import org.apache.isis.core.commons.internal.base._Either;
+import org.apache.isis.core.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor(staticName = "of")
+public class CollectionAccessChain {
+
+ @NonNull private _Either<CollectionBinding, InteractionResponse> chain;
+
+// public CollectionAccessChain modifyProperty(
+// @NonNull final Function<OneToManyAssociation, ManagedObject> newProperyValueProvider) {
+//
+// chain = chain.leftRemap(propertyBinding->{
+// final InteractionResponse iResponse = propertyBinding.modifyProperty(newProperyValueProvider);
+// if(iResponse.isFailure()) {
+// _Either.right(iResponse);
+// }
+// return _Either.left(propertyBinding);
+// });
+//
+// return this;
+// }
+
+ public CollectionAccessChain onFailure(Consumer<InteractionResponse> onFailure) {
+ chain.right().ifPresent(onFailure);
+ return this;
+ }
+
+ public CollectionBinding getBinding() {
+ return chain.left()
+ .orElseThrow(_Exceptions::noSuchElement);
+ }
+
+ public OneToManyAssociation getCollection() {
+ return chain.left()
+ .map(CollectionBinding::getCollection)
+ .orElseThrow(_Exceptions::noSuchElement);
+ }
+
+ public CollectionAccessChain ifPresent(Consumer<CollectionBinding> collectionBindingConsumer) {
+ chain.left().ifPresent(collectionBindingConsumer::accept);
+ return this;
+ }
+
+
+
+}
diff --git a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectBinding.java b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectBinding.java
index d15f67d..64f2a81 100644
--- a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectBinding.java
+++ b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectBinding.java
@@ -129,16 +129,18 @@ public class ObjectBinding {
/**
* @param actionId
* @param where
- * @return either an editable or readonly ActionBinding, based on visibility and usability
+ * @return ActionAccessChain with either an editable or readonly ActionBinding,
+ * based on visibility and usability
*/
- public _Either<ActionBinding, InteractionResponse> getActionBinding(String actionId, Where where) {
- return getActionThatIsVisible(actionId, where)
+ public ActionAccessChain getActionBinding(String actionId, Where where) {
+ val either = getActionThatIsVisible(actionId, where)
.map(
action->
checkUsability(action, where).isSuccess()
? ActionBindingUsable.of(managedObject, action)
: ActionBindingReadonly.of(managedObject, action),
UnaryOperator.identity());
+ return ActionAccessChain.of(either);
}
/**
@@ -146,14 +148,15 @@ public class ObjectBinding {
* @param actionId
* @param where
* @param accessIntent
- * @return either an editable or readonly PropertyBinding, based on visibility and accessIntent
+ * @return ActionAccessChain with either an editable or readonly PropertyBinding,
+ * based on visibility and accessIntent
*/
- public _Either<ActionBinding, InteractionResponse> getActionBinding(
+ public ActionAccessChain getActionBinding(
final String actionId,
final Where where,
final AccessIntent accessIntent) {
- return getActionThatIsVisibleForIntent(actionId, where, accessIntent)
+ val either = getActionThatIsVisibleForIntent(actionId, where, accessIntent)
.map(
action->{
switch(accessIntent) {
@@ -166,7 +169,7 @@ public class ObjectBinding {
}
},
UnaryOperator.identity());
-
+ return ActionAccessChain.of(either);
}
/**
@@ -218,16 +221,19 @@ public class ObjectBinding {
/**
* @param collectionId
* @param where
- * @return either an editable or readonly CollectionBinding, based on visibility and usability
+ * @return CollectionAccessChain with either an editable or readonly CollectionBinding,
+ * based on visibility and usability
*/
- public _Either<CollectionBinding, InteractionResponse> getCollectionBinding(String collectionId, Where where) {
- return getCollectionThatIsVisible(collectionId, where)
+ public CollectionAccessChain getCollectionBinding(String collectionId, Where where) {
+ val either = getCollectionThatIsVisible(collectionId, where)
.map(
coll->
checkUsability(coll, where).isSuccess()
? CollectionBindingEditable.of(managedObject, coll)
: CollectionBindingReadonly.of(managedObject, coll),
UnaryOperator.identity());
+
+ return CollectionAccessChain.of(either);
}
/**
@@ -235,14 +241,15 @@ public class ObjectBinding {
* @param collectionId
* @param where
* @param accessIntent
- * @return either an editable or readonly CollectionBinding, based on visibility and accessIntent
+ * @return CollectionAccessChain with either an editable or readonly CollectionBinding,
+ * based on visibility and accessIntent
*/
- public _Either<CollectionBinding, InteractionResponse> getCollectionBinding(
+ public CollectionAccessChain getCollectionBinding(
final String collectionId,
final Where where,
final AccessIntent accessIntent) {
- return getCollectionThatIsVisibleForIntent(collectionId, where, accessIntent)
+ val either = getCollectionThatIsVisibleForIntent(collectionId, where, accessIntent)
.map(
coll->{
switch(accessIntent) {
@@ -255,6 +262,8 @@ public class ObjectBinding {
}
},
UnaryOperator.identity());
+
+ return CollectionAccessChain.of(either);
}
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 5d7625e..fee1000 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
@@ -28,7 +28,6 @@ import org.apache.isis.viewer.common.model.binding.interaction.ObjectBinding.Acc
import org.apache.isis.viewer.restfulobjects.rendering.IResourceContext;
import lombok.RequiredArgsConstructor;
-import lombok.val;
/**
* Utility class that encapsulates the logic for checking access to the specified
@@ -52,31 +51,24 @@ public class ObjectAdapterAccessHelper {
final String propertyId, final AccessIntent intent) {
return objectInteractor.getPropertyBinding(propertyId, where, intent)
- .onFailure(InteractionFailureHandler::onFailure)
- .getProperty();
+ .onFailure(InteractionFailureHandler::onFailure)
+ .getProperty();
}
public OneToManyAssociation getCollectionThatIsVisibleForIntent(
final String collectionId, final AccessIntent intent) {
- val collectionBindingOrFailure = objectInteractor.getCollectionBinding(collectionId, where, intent);
-
- collectionBindingOrFailure.right()
- .ifPresent(InteractionFailureHandler::onFailure);
-
- return collectionBindingOrFailure.leftIfAny().getCollection();
+ return objectInteractor.getCollectionBinding(collectionId, where, intent)
+ .onFailure(InteractionFailureHandler::onFailure)
+ .getCollection();
}
public ObjectAction getObjectActionThatIsVisibleForIntent(
final String actionId, final AccessIntent intent) {
- val actionBindingOrFailure = objectInteractor.getActionBinding(actionId, where, intent);
-
- actionBindingOrFailure.right()
- .ifPresent(InteractionFailureHandler::onFailure);
-
- return actionBindingOrFailure.leftIfAny().getAction();
-
+ return objectInteractor.getActionBinding(actionId, where, intent)
+ .onFailure(InteractionFailureHandler::onFailure)
+ .getAction();
}