use of de.metas.ui.web.process.json.JSONCreateProcessInstanceRequest in project metasfresh-webui-api by metasfresh.
the class ProcessRestController method createInstanceFromRequest.
@RequestMapping(value = "/{processId}", method = RequestMethod.POST)
public JSONProcessInstance createInstanceFromRequest(@PathVariable("processId") final String processIdStr, @RequestBody final JSONCreateProcessInstanceRequest jsonRequest) {
userSession.assertLoggedIn();
final ViewRowIdsSelection viewRowIdsSelection = jsonRequest.getViewRowIdsSelection();
final ViewId viewId = viewRowIdsSelection != null ? viewRowIdsSelection.getViewId() : null;
final DocumentIdsSelection viewSelectedRowIds = viewRowIdsSelection != null ? viewRowIdsSelection.getRowIds() : DocumentIdsSelection.EMPTY;
// Get the effective singleDocumentPath, i.e.
// * if provided, use it
// * if not provided and we have a single selected row in the view, ask the view's row to provide the effective document path
DocumentPath singleDocumentPath = jsonRequest.getSingleDocumentPath();
if (singleDocumentPath == null && viewSelectedRowIds.isSingleDocumentId()) {
final IView view = viewsRepo.getView(viewId);
singleDocumentPath = view.getById(viewSelectedRowIds.getSingleDocumentId()).getDocumentPath();
}
final CreateProcessInstanceRequest request = CreateProcessInstanceRequest.builder().processId(ProcessId.fromJson(processIdStr)).singleDocumentPath(singleDocumentPath).selectedIncludedDocumentPaths(jsonRequest.getSelectedIncludedDocumentPaths()).viewRowIdsSelection(viewRowIdsSelection).parentViewRowIdsSelection(jsonRequest.getParentViewRowIdsSelection()).childViewRowIdsSelection(jsonRequest.getChildViewRowIdsSelection()).build();
// Validate request's AD_Process_ID
// (we are not using it, but just for consistency)
request.assertProcessIdEquals(jsonRequest.getProcessId());
final IProcessInstancesRepository instancesRepository = getRepository(request.getProcessId());
return Execution.callInNewExecution("pinstance.create", () -> {
final IProcessInstanceController processInstance = instancesRepository.createNewProcessInstance(request);
return JSONProcessInstance.of(processInstance, newJSONOptions());
});
}
Aggregations