dimanche 20 octobre 2019

How can I send a JsonObject request, and recieve a NodeResponse in the MeshRestClient?

In my Gentics Mesh plugin, I'm creating Nodes from json files.

I've created a scripting process that replaces variable placeholders in a json file, with actual values [for example, from a previous node creation event].

This works great if I have a strongly typed object added to the variable resolver...

Because the variable resolver uses reflection to find the property names on a variable value, and does the replacement in json. But if the variable added to the resolver is a JsonObject, the properties I need are not available.

Examples:

I set a variable called 'project' in the resolver, from the output of this method. [projectResponse.rootNode]

private ProjectResponse createProject(String project) {
    ProjectCreateRequest createProject = new ProjectCreateRequest()
            .setName(project)
            .setSchemaRef("folder");
    return this.adminClient.createProject(createProject).blockingGet();
}

Json Files -

First json file works because I added the project NodeReference to the variable resolver -

{
  "parentNode" : {
    "uuid" : "<project.uuid>"
  },
  "schema" : {
    "name" : "folder"
  },
  "language" : "en",
  "fields" : {
    "name" : "node1 - child of project root node"
  }
}

The response of that creation is a JsonObject, which I then pass into the variable resolver.
Then I create a second node.
Note I'm using the generic post method [I don't know how to create a NodeCreateRequest from a json string, which could also solve this]

private JsonObject createNode(String project, String processedNode) {
        JsonObject request = new JsonObject(processedNode);
        JsonObject response = this.adminClient.post(String.format("/%s/nodes", project), request).blockingGet();
        return response;
    }

Second json file doesn't work because node1 is a JsonObject, and doesn't have a uuid property -

{
  "parentNode" : {
    "uuid" : "<node1.uuid>"
  },
  "schema" : {
    "name" : "folder"
  },
  "language" : "en",
  "fields" : {
    "name" : "node2 - child of node1"
  }
}

I can't automatically map the JsonObject to a NodeResponse -

private NodeResponse createNode(String project, String processedNode) {
        JsonObject request = new JsonObject(processedNode);
        JsonObject response = this.adminClient.post(String.format("/%s/nodes", project), request).blockingGet();
        return mapper.convertValue(response, NodeResponse.class);
    }

SEVERE: Plugin registration failed with error java.lang.IllegalArgumentException: Unrecognized field "map" (class com.gentics.mesh.core.rest.node.NodeResponse), not marked as ignorable (22 known properties: "schema", "breadcrumb", "permissions", "path", "created", "edited", "creator", "editor", "availableLanguages", "languagePaths", "language", "tags", "uuid", "container", "parentNode", "project", "childrenInfo", "displayField", "displayName", "fields", "version", "rolePerms"]) at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.gentics.mesh.core.rest.node.NodeResponse["map"])





Aucun commentaire:

Enregistrer un commentaire