Search in sources :

Example 1 with JSONCreateProcessInstanceRequest

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());
    });
}
Also used : IView(de.metas.ui.web.view.IView) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ViewId(de.metas.ui.web.view.ViewId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONCreateProcessInstanceRequest(de.metas.ui.web.process.json.JSONCreateProcessInstanceRequest) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONCreateProcessInstanceRequest (de.metas.ui.web.process.json.JSONCreateProcessInstanceRequest)1 IView (de.metas.ui.web.view.IView)1 ViewId (de.metas.ui.web.view.ViewId)1 ViewRowIdsSelection (de.metas.ui.web.view.ViewRowIdsSelection)1 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1