-
Task
-
Resolution: Done
-
Major
-
None
-
0.12.0
-
None
-
2020 Week 28-30 (from Jul 6), 2020 Week 31-33 (from Jul 27)
The body of the generated REST endpoint contains a lot of "conversion" logic for model handling:
protected ApprovalsModelOutput getModel(ProcessInstance<ApprovalsModel> pi) { if (pi.status() == ProcessInstance.STATE_ERROR && pi.error().isPresent()) { throw new ProcessInstanceExecutionException(pi.id(), pi.error().get().failedNodeId(), pi.error().get().errorMessage()); } return mapOutput(new ApprovalsModelOutput(), pi.variables()); } protected ApprovalsModel mapInput(@javax.validation.Valid() @javax.validation.constraints.NotNull() ApprovalsModelInput input, ApprovalsModel resource) { resource.fromMap(input.toMap()); return resource; } protected ApprovalsModelOutput mapOutput(ApprovalsModelOutput output, ApprovalsModel resource) { output.fromMap(resource.getId(), resource.toMap()); return output; }
Move the logic from the generated REST endpoint to the generated models. For instance,
getModel(pi) could be turned into pi.checkError().variables().toOutput();
where checkError() verifies the error and throws; toOutput() is a method of the Model interface that substitutes mapOutput.
mapInput could be substituted by a method: MyOutputModel.toModel();
example:
ApprovalsModel model = resource.toModel(); // instead of mapInput return org.kie.kogito.services.uow.UnitOfWorkExecutor.executeInUnitOfWork( application.unitOfWorkManager(), () -> { ProcessInstance<ApprovalsModel> pi = process.createInstance(businessKey, model); pi.start(); return pi.checkError().variables().toOutput(); }); }
see also https://gist.github.com/evacchi/d0ee8b08d6fe97c909568a1ae24f4fd4 for a more complete example
- is incorporated by
-
KOGITO-2455 Rework Kogito code generation for scaffolding (processes)
- Resolved