Search in sources :

Example 1 with ViewRowIdsSelection

use of de.metas.ui.web.view.ViewRowIdsSelection 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)

Example 2 with ViewRowIdsSelection

use of de.metas.ui.web.view.ViewRowIdsSelection in project metasfresh-webui-api by metasfresh.

the class ViewBasedProcessTemplate method loadParametersFromContext.

@Override
protected void loadParametersFromContext(final boolean failIfNotValid) {
    super.loadParametersFromContext(failIfNotValid);
    // shall not happen
    Check.assumeNotEmpty(p_WebuiViewId, "Process parameter {} is set", PARAM_ViewId);
    final IView view = viewsRepo.getView(p_WebuiViewId);
    final ViewRowIdsSelection viewRowIdsSelection = ViewRowIdsSelection.of(view.getViewId(), DocumentIdsSelection.ofCommaSeparatedString(p_WebuiViewSelectedIdsStr));
    final ViewRowIdsSelection parentViewRowIdsSelection = ViewRowIdsSelection.ofNullableStrings(p_WebuiParentViewId, p_WebuiParentViewSelectedIdsStr);
    final ViewRowIdsSelection childViewRowIdsSelection = ViewRowIdsSelection.ofNullableStrings(p_WebuiChildViewId, p_WebuiChildViewSelectedIdsStr);
    setViewInfos(ViewAsPreconditionsContext.builder().view(view).viewRowIdsSelection(viewRowIdsSelection).parentViewRowIdsSelection(parentViewRowIdsSelection).childViewRowIdsSelection(childViewRowIdsSelection).build());
}
Also used : IView(de.metas.ui.web.view.IView) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection)

Example 3 with ViewRowIdsSelection

use of de.metas.ui.web.view.ViewRowIdsSelection in project metasfresh-webui-api by metasfresh.

the class ADProcessInstancesRepository method createProcessInfo.

private ProcessInfo createProcessInfo(@NonNull final CreateProcessInstanceRequest request) {
    final DocumentPath singleDocumentPath = request.getSingleDocumentPath();
    final String tableName;
    final int recordId;
    final String sqlWhereClause;
    final int adWindowId;
    // View
    if (request.getViewRowIdsSelection() != null) {
        final ViewRowIdsSelection viewRowIdsSelection = request.getViewRowIdsSelection();
        final ViewId viewId = viewRowIdsSelection.getViewId();
        final IView view = viewsRepo.getView(viewId);
        final DocumentIdsSelection viewDocumentIds = viewRowIdsSelection.getRowIds();
        adWindowId = viewId.getWindowId().toIntOr(-1);
        if (viewDocumentIds.isSingleDocumentId()) {
            final DocumentId viewSingleDocumentId = viewDocumentIds.getSingleDocumentId();
            final TableRecordReference recordRef = view.getTableRecordReferenceOrNull(viewSingleDocumentId);
            if (recordRef != null) {
                tableName = recordRef.getTableName();
                recordId = recordRef.getRecord_ID();
            } else {
                tableName = view.getTableNameOrNull(viewSingleDocumentId);
                recordId = -1;
            }
        } else {
            tableName = view.getTableNameOrNull(null);
            recordId = -1;
        }
        final boolean emptyTableName = Check.isEmpty(tableName);
        if (viewDocumentIds.isEmpty() || emptyTableName) {
            // Note: in the case of material cockpit, there is no single tableName to be returned by view.getTableNameOrNull,
            // so we do have selected rows, but no table name, which is OK
            sqlWhereClause = null;
        } else {
            sqlWhereClause = view.getSqlWhereClause(viewDocumentIds, SqlOptions.usingTableName(tableName));
        }
    } else // Single document call
    if (singleDocumentPath != null) {
        final DocumentEntityDescriptor entityDescriptor = documentDescriptorFactory.getDocumentEntityDescriptor(singleDocumentPath);
        adWindowId = singleDocumentPath.getWindowId().toIntOr(-1);
        tableName = entityDescriptor.getTableNameOrNull();
        if (singleDocumentPath.isRootDocument()) {
            recordId = singleDocumentPath.getDocumentId().toInt();
        } else {
            recordId = singleDocumentPath.getSingleRowId().toInt();
        }
        sqlWhereClause = entityDescriptor.getDataBinding(SqlDocumentEntityDataBindingDescriptor.class).getSqlWhereClauseById(recordId);
    } else // 
    // From menu
    {
        tableName = null;
        recordId = -1;
        sqlWhereClause = null;
        adWindowId = -1;
    }
    // 
    final Set<TableRecordReference> selectedIncludedRecords = request.getSelectedIncludedDocumentPaths().stream().map(documentDescriptorFactory::getTableRecordReference).collect(ImmutableSet.toImmutableSet());
    final ProcessInfoBuilder processInfoBuilder = ProcessInfo.builder().setCtx(Env.getCtx()).setCreateTemporaryCtx().setAD_Process_ID(request.getProcessIdAsInt()).setAD_Window_ID(adWindowId).setRecord(tableName, recordId).setSelectedIncludedRecords(selectedIncludedRecords).setWhereClause(sqlWhereClause);
    // View related internal parameters
    if (request.getViewRowIdsSelection() != null) {
        final ViewRowIdsSelection viewRowIdsSelection = request.getViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ViewId, viewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ViewSelectedIds, viewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    if (request.getParentViewRowIdsSelection() != null) {
        final ViewRowIdsSelection parentViewRowIdsSelection = request.getParentViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ParentViewId, parentViewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ParentViewSelectedIds, parentViewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    if (request.getChildViewRowIdsSelection() != null) {
        final ViewRowIdsSelection childViewRowIdsSelection = request.getChildViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ChildViewId, childViewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ChildViewSelectedIds, childViewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    return processInfoBuilder.build();
}
Also used : IView(de.metas.ui.web.view.IView) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection) ViewId(de.metas.ui.web.view.ViewId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessInfoBuilder(de.metas.process.ProcessInfo.ProcessInfoBuilder) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 4 with ViewRowIdsSelection

use of de.metas.ui.web.view.ViewRowIdsSelection in project metasfresh-webui-api by metasfresh.

the class ViewBasedProcessTemplate method getChildView.

protected final <T extends IView> T getChildView(@NonNull final Class<T> viewType) {
    final ViewRowIdsSelection childViewRowIdsSelection = getChildViewRowIdsSelection();
    Check.assumeNotNull(childViewRowIdsSelection, "child view is set");
    final IView childView = viewsRepo.getView(childViewRowIdsSelection.getViewId());
    return viewType.cast(childView);
}
Also used : IView(de.metas.ui.web.view.IView) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection)

Aggregations

IView (de.metas.ui.web.view.IView)4 ViewRowIdsSelection (de.metas.ui.web.view.ViewRowIdsSelection)4 ViewId (de.metas.ui.web.view.ViewId)2 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 ProcessInfoBuilder (de.metas.process.ProcessInfo.ProcessInfoBuilder)1 JSONCreateProcessInstanceRequest (de.metas.ui.web.process.json.JSONCreateProcessInstanceRequest)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)1 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)1 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1