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 f123278b435e51057a8ca9bba0a4139da2c83a74 Author: Andi Huber <[email protected]> AuthorDate: Thu Apr 23 16:49:40 2020 +0200 ISIS-2340: share logic of ObjectAdapterAccessHelper/UpdateHelper (1) --- .../model/binding/interaction/ObjectInteractor.java | 8 ++++++++ .../resources/DomainObjectResourceServerside.java | 11 +++++------ .../viewer/resources/DomainResourceHelper.java | 13 +++++++------ .../viewer/resources/ObjectAdapterAccessHelper.java | 17 +++++------------ 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectInteractor.java b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectInteractor.java index 156ec3f..8693986 100644 --- a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectInteractor.java +++ b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/binding/interaction/ObjectInteractor.java @@ -35,6 +35,14 @@ import lombok.val; @RequiredArgsConstructor(staticName = "bind") public class ObjectInteractor { + + public static enum AccessIntent { + ACCESS, MUTATE; + + public boolean isMutate() { + return this == MUTATE; + } + } private final ManagedObject managedObject; diff --git a/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainObjectResourceServerside.java b/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainObjectResourceServerside.java index a464b87..f767583 100644 --- a/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainObjectResourceServerside.java +++ b/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainObjectResourceServerside.java @@ -59,7 +59,6 @@ import org.apache.isis.core.metamodel.spec.ManagedObject; import org.apache.isis.core.metamodel.spec.ObjectSpecId; import org.apache.isis.core.metamodel.spec.ObjectSpecification; import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; -import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; import org.apache.isis.core.runtime.iactn.IsisInteractionTracker; import org.apache.isis.viewer.common.model.binding.interaction.ObjectInteractor; import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; @@ -455,7 +454,7 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements val accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); val property = accessHelper.getPropertyThatIsVisibleForIntent(propertyId, - ObjectAdapterAccessHelper.Intent.MUTATE); + ObjectInteractor.AccessIntent.MUTATE); val proposedNewValue = new JsonParserHelper(resourceContext, property.getSpecification()) .parseAsMapWithSingleValue(Util.asStringUtf8(body)); @@ -493,7 +492,7 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements val accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); val property = accessHelper.getPropertyThatIsVisibleForIntent( - propertyId, ObjectAdapterAccessHelper.Intent.MUTATE); + propertyId, ObjectInteractor.AccessIntent.MUTATE); val objectInteractor = ObjectInteractor.bind(objectAdapter); val iResponse = objectInteractor.modifyProperty(property, null); @@ -555,7 +554,7 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); final OneToManyAssociation collection = accessHelper.getCollectionThatIsVisibleForIntent( - collectionId, ObjectAdapterAccessHelper.Intent.MUTATE); + collectionId, ObjectInteractor.AccessIntent.MUTATE); if (!collection.getCollectionSemantics().isAnySet()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Collection '%s' does not have set semantics", collectionId); @@ -594,7 +593,7 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); final OneToManyAssociation collection = accessHelper.getCollectionThatIsVisibleForIntent( - collectionId, ObjectAdapterAccessHelper.Intent.MUTATE); + collectionId, ObjectInteractor.AccessIntent.MUTATE); if (!collection.getCollectionSemantics().isListOrArray()) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.METHOD_NOT_ALLOWED, "Collection '%s' does not have list or array semantics", collectionId); @@ -633,7 +632,7 @@ public class DomainObjectResourceServerside extends ResourceAbstract implements final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); final OneToManyAssociation collection = accessHelper.getCollectionThatIsVisibleForIntent( - collectionId, ObjectAdapterAccessHelper.Intent.MUTATE); + collectionId, ObjectInteractor.AccessIntent.MUTATE); final ObjectSpecification collectionSpec = collection.getSpecification(); final ManagedObject argAdapter = new JsonParserHelper(resourceContext, collectionSpec) diff --git a/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainResourceHelper.java b/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainResourceHelper.java index dcd1c61..b82338d 100644 --- a/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainResourceHelper.java +++ b/viewers/restfulobjects/viewer/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/DomainResourceHelper.java @@ -27,6 +27,7 @@ import org.apache.isis.core.metamodel.spec.ManagedObject; import org.apache.isis.core.metamodel.spec.feature.ObjectAction; import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; +import org.apache.isis.viewer.common.model.binding.interaction.ObjectInteractor; import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; import org.apache.isis.viewer.restfulobjects.applib.RestfulResponse; import org.apache.isis.viewer.restfulobjects.rendering.IResourceContext; @@ -108,7 +109,7 @@ class DomainResourceHelper { ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); - final OneToOneAssociation property = accessHelper.getPropertyThatIsVisibleForIntent(propertyId, ObjectAdapterAccessHelper.Intent.ACCESS); + final OneToOneAssociation property = accessHelper.getPropertyThatIsVisibleForIntent(propertyId, ObjectInteractor.AccessIntent.ACCESS); transactionService.flushTransaction(); return representationService.propertyDetails(resourceContext, new ObjectAndProperty2(objectAdapter, property, memberMode), memberMode); @@ -126,7 +127,7 @@ class DomainResourceHelper { ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); - final OneToManyAssociation collection = accessHelper.getCollectionThatIsVisibleForIntent(collectionId, ObjectAdapterAccessHelper.Intent.ACCESS); + final OneToManyAssociation collection = accessHelper.getCollectionThatIsVisibleForIntent(collectionId, ObjectInteractor.AccessIntent.ACCESS); transactionService.flushTransaction(); return representationService.collectionDetails(resourceContext, new ObjectAndCollection2(objectAdapter, collection, memberMode), memberMode); @@ -142,7 +143,7 @@ class DomainResourceHelper { ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); - final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectAdapterAccessHelper.Intent.ACCESS); + final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectInteractor.AccessIntent.ACCESS); transactionService.flushTransaction(); return representationService.actionPrompt(resourceContext, new ObjectAndAction(objectAdapter, action)); @@ -162,7 +163,7 @@ class DomainResourceHelper { final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); - final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectAdapterAccessHelper.Intent.MUTATE); + final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectInteractor.AccessIntent.MUTATE); final SemanticsOf actionSemantics = action.getSemantics(); if (! actionSemantics.isSafeInNature()) { @@ -186,7 +187,7 @@ class DomainResourceHelper { final ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); - final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectAdapterAccessHelper.Intent.MUTATE); + final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectInteractor.AccessIntent.MUTATE); final SemanticsOf actionSemantics = action.getSemantics(); if (!actionSemantics.isIdempotentInNature()) { @@ -204,7 +205,7 @@ class DomainResourceHelper { ObjectAdapterAccessHelper accessHelper = new ObjectAdapterAccessHelper(resourceContext, objectAdapter); - final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectAdapterAccessHelper.Intent.MUTATE); + final ObjectAction action = accessHelper.getObjectActionThatIsVisibleForIntent(actionId, ObjectInteractor.AccessIntent.MUTATE); return invokeActionUsingAdapters(action, arguments, ActionResultReprRenderer.SelfLink.EXCLUDED); } 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 df9873e..b8b8b2f 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 @@ -26,6 +26,7 @@ import org.apache.isis.core.metamodel.spec.feature.ObjectAction; import org.apache.isis.core.metamodel.spec.feature.ObjectMember; import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; +import org.apache.isis.viewer.common.model.binding.interaction.ObjectInteractor.AccessIntent; import org.apache.isis.viewer.restfulobjects.applib.RestfulResponse; import org.apache.isis.viewer.restfulobjects.rendering.IResourceContext; import org.apache.isis.viewer.restfulobjects.rendering.RestfulObjectsApplicationException; @@ -48,14 +49,6 @@ public class ObjectAdapterAccessHelper { memberId); } - static enum Intent { - ACCESS, MUTATE; - - public boolean isMutate() { - return this == MUTATE; - } - } - private final ManagedObject objectAdapter; private final IResourceContext resourceContext; @@ -65,7 +58,7 @@ public class ObjectAdapterAccessHelper { } public OneToOneAssociation getPropertyThatIsVisibleForIntent( - final String propertyId, final Intent intent) { + final String propertyId, final AccessIntent intent) { val spec = objectAdapter.getSpecification(); val association = spec.getAssociation(propertyId) @@ -80,7 +73,7 @@ public class ObjectAdapterAccessHelper { } public OneToManyAssociation getCollectionThatIsVisibleForIntent( - final String collectionId, final Intent intent) { + final String collectionId, final AccessIntent intent) { val spec = objectAdapter.getSpecification(); val association = spec.getAssociation(collectionId) @@ -95,7 +88,7 @@ public class ObjectAdapterAccessHelper { } public ObjectAction getObjectActionThatIsVisibleForIntent( - final String actionId, final Intent intent) { + final String actionId, final AccessIntent intent) { val spec = objectAdapter.getSpecification(); val action = spec.getObjectAction(actionId) @@ -105,7 +98,7 @@ public class ObjectAdapterAccessHelper { } public <T extends ObjectMember> T memberThatIsVisibleForIntent( - final T objectMember, final MemberType memberType, final Intent intent) { + final T objectMember, final MemberType memberType, final AccessIntent intent) { final Where where = resourceContext.getWhere();
