You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2024/02/17 12:36:44 UTC
(causeway) 02/02: CAUSEWAY-3676: reworks grid to return a URL
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
commit 260b623a5607b77a7c56ae6fa6af932011dba9a9
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Sat Feb 17 12:36:17 2024 +0000
CAUSEWAY-3676: reworks grid to return a URL
---
.../viewer/graphql/model/domain/GqlvMeta.java | 11 +++----
...d_staff_member_by_name_and_download_photo._.gql | 3 ++
...member_by_name_and_download_photo.approved.json | 3 ++
.../e2e/queryandmutations/Staff_IntegTest.java | 37 +++++++++++++++-------
4 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
index 832055e349..cdec355cc8 100644
--- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
+++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
@@ -31,6 +31,7 @@ import org.apache.causeway.core.metamodel.facets.members.cssclass.CssClassFacet;
import org.apache.causeway.core.metamodel.facets.object.entity.EntityFacet;
import org.apache.causeway.core.metamodel.facets.object.grid.GridFacet;
import org.apache.causeway.core.metamodel.facets.object.layout.LayoutFacet;
+import org.apache.causeway.core.metamodel.object.Bookmarkable;
import org.apache.causeway.core.metamodel.object.ManagedObject;
import org.apache.causeway.core.metamodel.objectmanager.ObjectManager;
import org.apache.causeway.viewer.graphql.model.context.Context;
@@ -191,13 +192,9 @@ public class GqlvMeta extends GqlvAbstractCustom {
public String grid() {
return managedObject()
- .map(managedObject -> {
- val facet = managedObject.getSpecification().getFacet(GridFacet.class);
- return facet != null ? facet.getGrid(managedObject) : null;
- })
- .filter(obj -> Objects.nonNull(obj))
- .map(JaxbUtils::toStringUtf8)
- .map(x -> x.replaceAll("(\r\n)", "\n"))
+ .flatMap(Bookmarkable::getBookmark
+ ).map(x -> String.format(
+ "///%s/object/%s:%s/grid", "graphql", x.getLogicalTypeName(), x.getIdentifier()))
.orElse(null);
}
diff --git a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo._.gql b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo._.gql
index 51ac1345c4..7bcd1390a7 100644
--- a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo._.gql
+++ b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo._.gql
@@ -5,6 +5,9 @@
name {
get
}
+ _meta {
+ grid
+ }
photo {
get {
bytes
diff --git a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo.approved.json b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo.approved.json
index 376620cb6a..4f69d1a11a 100644
--- a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo.approved.json
+++ b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.find_staff_member_by_name_and_download_photo.approved.json
@@ -6,6 +6,9 @@
"name" : {
"get" : "Gerry Jones"
},
+ "_meta" : {
+ "grid" : "///graphql/object/university.dept.StaffMember:NNN/grid"
+ },
"photo" : {
"get" : {
"bytes" : "///graphql/object/university.dept.StaffMember:NNN/photo/blobBytes"
diff --git a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.java b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.java
index f5568939cc..a67b433248 100644
--- a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.java
+++ b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/queryandmutations/Staff_IntegTest.java
@@ -51,7 +51,6 @@ import lombok.val;
//NOT USING @Transactional since we are running server within same transaction otherwise
@Order(60)
@ActiveProfiles("test")
-@DisabledIfEnvironmentVariable(named = "PROJECT_ROOT_PATH", matches = ".*isis") // disable for isis build
public class Staff_IntegTest extends Abstract_IntegTest {
@Test
@@ -131,25 +130,41 @@ public class Staff_IntegTest extends Abstract_IntegTest {
String response = submit();
Approvals.verify(response, jsonOptions());
- ObjectMapper mapper = new ObjectMapper();
- JsonNode root = mapper.readTree(response);
+ val objectMapper = new ObjectMapper();
+ val jsonNodeRoot = objectMapper.readTree(response);
- String url = root
- .at("/data/university_dept_Staff/findStaffMemberByName/invoke/photo/get/bytes")
+ val gridUrl = jsonNodeRoot
+ .at("/data/university_dept_Staff/findStaffMemberByName/invoke/_meta/grid")
.asText();
- assertThat(url).matches("///graphql/object/university.dept.StaffMember:(\\d+)/photo/blobBytes");
+ assertThat(gridUrl).matches("///graphql/object/university.dept.StaffMember:(\\d+)/grid");
+ val gridHttpResponse = submitReturningString(gridUrl);
+
+ assertThat(gridHttpResponse.statusCode()).isEqualTo(200);
+ val gridChars = gridHttpResponse.body();
+ assertThat(gridChars).isNotEmpty();
- val httpResponse = submitReturningBytes(url);
- assertThat(httpResponse.statusCode()).isEqualTo(200);
- byte[] bytes = httpResponse.body();
- assertThat(bytes).isNotEmpty();
+ val photoBytesUrl = jsonNodeRoot
+ .at("/data/university_dept_Staff/findStaffMemberByName/invoke/photo/get/bytes")
+ .asText();
+ assertThat(photoBytesUrl).matches("///graphql/object/university.dept.StaffMember:(\\d+)/photo/blobBytes");
+ val photoBytesResponse = submitReturningBytes(photoBytesUrl);
+ assertThat(photoBytesResponse.statusCode()).isEqualTo(200);
+ val photoBytes = photoBytesResponse.body();
+ assertThat(photoBytes).isNotEmpty();
}
private HttpResponse<byte[]> submitReturningBytes(String url) throws IOException, InterruptedException {
+ return submitReturningResponseHandledBy(url, HttpResponse.BodyHandlers.ofByteArray());
+ }
+
+ private HttpResponse<String> submitReturningString(String url) throws IOException, InterruptedException {
+ return submitReturningResponseHandledBy(url, HttpResponse.BodyHandlers.ofString());
+ }
+ private <T> HttpResponse<T> submitReturningResponseHandledBy(String url, HttpResponse.BodyHandler<T> responseBodyHandler) throws IOException, InterruptedException {
val urlSuffix = url.substring(3); // strip off the '///' prefix
val uri = URI.create(String.format("http://0.0.0.0:%d/%s", port, urlSuffix));
@@ -159,7 +174,7 @@ public class Staff_IntegTest extends Abstract_IntegTest {
build();
HttpClient httpClient = HttpClient.newHttpClient();
- return httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofByteArray());
+ return httpClient.send(httpRequest, responseBodyHandler);
}
}