Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NXP-30658: take into account schema prefix could be different than name #5038

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.nuxeo.ecm.core.io.registry.reflect.Setup;
import org.nuxeo.ecm.core.schema.SchemaManager;
import org.nuxeo.ecm.core.schema.types.CompositeType;
import org.nuxeo.ecm.core.schema.types.Schema;
import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants;
import org.nuxeo.ecm.platform.routing.core.impl.GraphNode;
import org.nuxeo.ecm.platform.routing.core.impl.GraphRoute;
Expand Down Expand Up @@ -90,8 +91,6 @@ public TaskCompletionRequest readEntity(JsonNode jn) throws IOException {
String comment = getStringField(jn, "comment");

// get the task and workflow schema names
String nodeSchema;
String workflowSchema;
Map<String, Serializable> variables = new HashMap<>();
try (SessionWrapper closeable = ctx.getSession(null)) {
CoreSession session = closeable.getSession();
Expand All @@ -111,27 +110,28 @@ public TaskCompletionRequest readEntity(JsonNode jn) throws IOException {
// get the variables
JsonNode variablesNode = jn.get("variables");
if (variablesNode != null) {
String workflowSchemaFacet = (String) graphRoute.getDocument().getPropertyValue(
GraphRoute.PROP_VARIABLES_FACET);
String workflowSchemaFacet = (String) graphRoute.getDocument()
.getPropertyValue(GraphRoute.PROP_VARIABLES_FACET);
CompositeType type = schemaManager.getFacet(workflowSchemaFacet);
workflowSchema = type.getSchemaNames()[0];
variables.putAll(getVariables(variablesNode, workflowSchema));
variables.putAll(getVariables(variablesNode, type.getSchemas().stream().findFirst().get()));

String nodeSchemaFacet = (String) node.getDocument().getPropertyValue(GraphNode.PROP_VARIABLES_FACET);
type = schemaManager.getFacet(nodeSchemaFacet);
nodeSchema = type.getSchemaNames()[0];
variables.putAll(getVariables(variablesNode, nodeSchema));
variables.putAll(getVariables(variablesNode, type.getSchemas().stream().findFirst().get()));
}

}

return new TaskCompletionRequest(comment, variables, false);
}

private Map<String, Serializable> getVariables(JsonNode variables, String schemaName) throws IOException {
private Map<String, Serializable> getVariables(JsonNode variables, Schema schema) throws IOException {
Map<String, Serializable> variable = new HashMap<>();
String schemaName = schema.getNamespace() != null && schema.getNamespace().hasPrefix()
? schema.getNamespace().prefix
: schema.getName();
ParameterizedType genericType = TypeUtils.parameterize(List.class, Property.class);
try (Closeable resource = ctx.wrap().with(DEFAULT_SCHEMA_NAME, schemaName).open()) {
try (Closeable resource = ctx.wrap().with(DEFAULT_SCHEMA_NAME, schema.getName()).open()) {
List<Property> properties = readEntity(List.class, genericType, variables);
for (Property property : properties) {
variable.put(property.getName().substring(schemaName.length() + 1), property.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ public void testRejectTaskInSubWorkflow() throws IOException {

/*
* NXP-29171
* NXP-30658
*/
@Test
@Deploy("org.nuxeo.ecm.platform.restapi.server.routing.test:test-specific-task-request-unmarshalling.xml")
Expand All @@ -1455,7 +1456,7 @@ public void testSpecificTaskRequestWithFetchedGroup() throws IOException {
taskId = node.get("entries").get(0).get("id").textValue();
}

NuxeoGroup group = userManager.getGroup("administrators");
NuxeoGroup group = userManager.getGroup("members");

String groupJson = MarshallerHelper.objectToJson(group, RenderingContext.CtxBuilder.get());
String body = String.format("{\"entity-type\":\"task\", \"id\":\"%s\", \"variables\":{\"assignees\":[%s]}}",
Expand All @@ -1475,7 +1476,7 @@ public void testSpecificTaskRequestWithFetchedGroup() throws IOException {

ArrayNode arrayAssignees = (ArrayNode) nodeAssignees;
assertEquals("Number of assignees is wrong", 1, arrayAssignees.size());
assertEquals("group:administrators", arrayAssignees.get(0).textValue());
assertEquals("group:members", arrayAssignees.get(0).textValue());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<component name="org.nuxeo.ecm.platform.restapi.server.routing.test.task.action" version="1.0.0">

<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="var_confirm-20200527183138945-start-node" prefix="var_confirm-20200527183138945-start-node" override="true" src="task-request-unmarshalling/schemas/var_confirm-20200527183138945-start-node.xsd"/>
<schema name="var_confirm-20200527183138946-stop-node" prefix="var_confirm-20200527183138946-stop-node" override="true" src="task-request-unmarshalling/schemas/var_confirm-20200527183138946-stop-node.xsd"/>
<schema name="var_global_confirm-20200527183230146-approve-task" prefix="var_global_confirm-20200527183230146-approve-task" override="true" src="task-request-unmarshalling/schemas/var_global_confirm-20200527183230146-approve-task.xsd"/>
<schema name="var_confirm-20200527183230146-approve-task" prefix="var_confirm-20200527183230146-approve-task" override="true" src="task-request-unmarshalling/schemas/var_confirm-20200527183230146-approve-task.xsd"/>
<schema name="var_confirm" prefix="var_confirm" override="true" src="task-request-unmarshalling/schemas/var_confirm.xsd"/>
<schema name="var_confirm-20200527183138945-start-node" prefix="v_conf-20200527183138945-start-node" override="true" src="task-request-unmarshalling/schemas/var_confirm-20200527183138945-start-node.xsd"/>
<schema name="var_confirm-20200527183138946-stop-node" prefix="v_conf-20200527183138946-stop-node" override="true" src="task-request-unmarshalling/schemas/var_confirm-20200527183138946-stop-node.xsd"/>
<schema name="var_global_confirm-20200527183230146-approve-task" prefix="v__global_conf-20200527183230146-approve-task" override="true" src="task-request-unmarshalling/schemas/var_global_confirm-20200527183230146-approve-task.xsd"/>
<schema name="var_confirm-20200527183230146-approve-task" prefix="v_conf-20200527183230146-approve-task" override="true" src="task-request-unmarshalling/schemas/var_confirm-20200527183230146-approve-task.xsd"/>
<schema name="var_confirm" prefix="v_conf" override="true" src="task-request-unmarshalling/schemas/var_confirm.xsd"/>
</extension>

<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
Expand Down