This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-3676
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/CAUSEWAY-3676 by this push:
new 40eb109304 CAUSEWAY-3676: adds validation of setting properties
40eb109304 is described below
commit 40eb1093046bdd5487d20025e5426625c451383e
Author: danhaywood <[email protected]>
AuthorDate: Wed Jan 24 19:59:16 2024 +0000
CAUSEWAY-3676: adds validation of setting properties
---
.../graphql/model/domain/GqlvActionInvoke.java | 1 +
.../graphql/model/domain/GqlvPropertySet.java | 9 ++++++++
.../graphql/model/domain/GqlvPropertyValidate.java | 5 ++---
.../graphql/viewer/test/e2e/Domain_IntegTest.java | 8 ++++++++
..._IntegTest.staff_member_name_edit_invalid._.gql | 15 ++++++++++++++
...st.staff_member_name_edit_invalid.approved.json | 24 ++++++++++++++++++++++
6 files changed, 59 insertions(+), 3 deletions(-)
diff --git
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvActionInvoke.java
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvActionInvoke.java
index 80460b0742..f941fefa23 100644
---
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvActionInvoke.java
+++
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvActionInvoke.java
@@ -181,6 +181,7 @@ public class GqlvActionInvoke {
return ManagedObject.adaptParameter(oap, argumentValue);
});
+ // TODO: should validate args first.
val resultManagedObject = objectAction
.execute(actionInteractionHead, canOfParams,
InteractionInitiatedBy.USER);
diff --git
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertySet.java
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertySet.java
index 26d589a401..ed3735415f 100644
---
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertySet.java
+++
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertySet.java
@@ -18,7 +18,10 @@
*/
package org.apache.causeway.viewer.graphql.model.domain;
+import org.apache.causeway.applib.services.wrapper.InvalidException;
+import org.apache.causeway.applib.services.wrapper.events.PropertyModifyEvent;
import org.apache.causeway.commons.collections.Can;
+import org.apache.causeway.core.metamodel.consent.Consent;
import org.apache.causeway.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.causeway.core.metamodel.object.ManagedObject;
import org.apache.causeway.core.metamodel.spec.feature.ObjectActionParameter;
@@ -127,6 +130,12 @@ public class GqlvPropertySet {
Map<String, Object> arguments = dataFetchingEnvironment.getArguments();
Object argumentValue = arguments.get(association.getId());
ManagedObject argumentManagedObject =
ManagedObject.adaptProperty(association, argumentValue);
+
+ Consent consent = association.isAssociationValid(managedObject,
argumentManagedObject, InteractionInitiatedBy.USER);
+ if (consent.isVetoed()) {
+ throw new
IllegalArgumentException(consent.getReasonAsString().orElse("Invalid"));
+ }
+
association.set(managedObject, argumentManagedObject,
InteractionInitiatedBy.USER);
return managedObject; // return the original object because setters
return void
diff --git
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertyValidate.java
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertyValidate.java
index b80cf07cca..9416f9a9db 100644
---
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertyValidate.java
+++
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvPropertyValidate.java
@@ -125,9 +125,8 @@ public class GqlvPropertyValidate {
Map<String, Object> arguments = dataFetchingEnvironment.getArguments();
Object argumentValue = arguments.get(association.getId());
ManagedObject argumentManagedObject =
ManagedObject.adaptProperty(association, argumentValue);
- Consent associationValid =
association.isAssociationValid(managedObject, argumentManagedObject,
InteractionInitiatedBy.USER);
-
- return associationValid.isVetoed() ?
associationValid.getReasonAsString().orElse("invalid") : null;
+ Consent consent = association.isAssociationValid(managedObject,
argumentManagedObject, InteractionInitiatedBy.USER);
+ return consent.isVetoed() ?
consent.getReasonAsString().orElse("invalid") : null;
}
}
diff --git
a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
index dd4b70177a..67b9c97774 100644
---
a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
+++
b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
@@ -168,6 +168,14 @@ public class Domain_IntegTest extends
CausewayViewerGraphqlTestModuleIntegTestAb
Approvals.verify(submit(), jsonOptions());
}
+ @Test
+ @UseReporter(DiffReporter.class)
+ void staff_member_name_edit_invalid() throws Exception {
+
+ // when, then
+ Approvals.verify(submit(), jsonOptions());
+ }
+
@Test
@UseReporter(DiffReporter.class)
void find_depthead_by_name() throws Exception {
diff --git
a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.staff_member_name_edit_invalid._.gql
b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.staff_member_name_edit_invalid._.gql
new file mode 100644
index 0000000000..084c856726
--- /dev/null
+++
b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.staff_member_name_edit_invalid._.gql
@@ -0,0 +1,15 @@
+{
+ university_dept_Staff {
+ findByName {
+ invoke(name: "Gerry Jones") {
+ name {
+ set(name: "Gerry!") {
+ name {
+ get
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git
a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.staff_member_name_edit_invalid.approved.json
b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.staff_member_name_edit_invalid.approved.json
new file mode 100644
index 0000000000..6d36ceb611
--- /dev/null
+++
b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.staff_member_name_edit_invalid.approved.json
@@ -0,0 +1,24 @@
+{
+ "errors" : [ {
+ "message" : "Exception while fetching data
(/university_dept_Staff/findByName/invoke/name/set) : Name cannot contain '!'
character",
+ "locations" : [ {
+ "line" : 6,
+ "column" : 11
+ } ],
+ "path" : [ "university_dept_Staff", "findByName", "invoke", "name", "set"
],
+ "extensions" : {
+ "classification" : "DataFetchingException"
+ }
+ } ],
+ "data" : {
+ "university_dept_Staff" : {
+ "findByName" : {
+ "invoke" : {
+ "name" : {
+ "set" : null
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file