Search in sources :

Example 71 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class ViewAsPreconditionsContext method getSingleSelectedRecordId.

@Override
public int getSingleSelectedRecordId() {
    final DocumentId rowId = getSelectedRowIds().getSingleDocumentId();
    final TableRecordReference recordRef = view.getTableRecordReferenceOrNull(rowId);
    if (recordRef == null) {
        throw new AdempiereException("Cannot extract Record_ID from single selected rowId: " + rowId);
    }
    return recordRef.getRecord_ID();
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 72 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId 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 73 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class ADProcessParametersRepository method refresh.

@Override
public void refresh(final Document processParameters) {
    final DocumentId adPInstanceId = processParameters.getDocumentId();
    final Map<String, ProcessInfoParameter> processInfoParameters = retrieveProcessInfoParameters(adPInstanceId);
    processParameters.refreshFromSupplier(new ProcessInfoParameterDocumentValuesSupplier(adPInstanceId, processInfoParameters));
}
Also used : ProcessInfoParameter(de.metas.process.ProcessInfoParameter) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 74 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class WEBUI_Picking_Launcher method doIt.

@Override
protected String doIt() throws Exception {
    // repeat the verification from checkPreconditionsApplicable() just to be sure.
    // We had cases where the selected rows of checkPreconditionsApplicable() were not the selected rows of doIt()
    final ProcessPreconditionsResolution verifySelectedDocuments = verifySelectedDocuments();
    if (verifySelectedDocuments.isRejected()) {
        throw new AdempiereException(verifySelectedDocuments().getRejectReason().translate(Env.getAD_Language(getCtx())));
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRootDocumentIds();
    final List<TableRecordReference> records = getView().streamByIds(selectedRowIds).flatMap(selectedRow -> selectedRow.getIncludedRows().stream()).map(IViewRow::getId).map(DocumentId::removeDocumentPrefixAndConvertToInt).map(recordId -> TableRecordReference.of(I_M_Packageable_V.Table_Name, recordId)).collect(ImmutableList.toImmutableList());
    if (records.isEmpty()) {
        throw new AdempiereException("@NoSelection@");
    }
    getResult().setRecordsToOpen(records, PickingConstants.WINDOWID_PickingView.toInt());
    return MSG_OK;
}
Also used : ViewBasedProcessTemplate(de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate) NonNull(lombok.NonNull) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PickingConstants(de.metas.ui.web.picking.PickingConstants) Set(java.util.Set) Env(org.compiere.util.Env) Collectors(java.util.stream.Collectors) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) MSG_WEBUI_PICKING_DIVERGING_LOCATIONS(de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_DIVERGING_LOCATIONS) I_M_Packageable_V(de.metas.inoutcandidate.model.I_M_Packageable_V) List(java.util.List) IViewRow(de.metas.ui.web.view.IViewRow) ImmutableList(com.google.common.collect.ImmutableList) AdempiereException(org.adempiere.exceptions.AdempiereException) MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P(de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) IProcessPrecondition(de.metas.process.IProcessPrecondition) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 75 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class ViewBasedProcessTemplate method getSingleSelectedRow.

@OverridingMethodsMustInvokeSuper
protected IViewRow getSingleSelectedRow() {
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    final DocumentId documentId = selectedRowIds.getSingleDocumentId();
    return getView().getById(documentId);
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Aggregations

DocumentId (de.metas.ui.web.window.datatypes.DocumentId)99 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)18 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)14 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 AdempiereException (org.adempiere.exceptions.AdempiereException)11 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)9 ArrayList (java.util.ArrayList)9 Set (java.util.Set)9 NonNull (lombok.NonNull)9 Test (org.junit.Test)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 UserSession (de.metas.ui.web.session.UserSession)8 ViewId (de.metas.ui.web.view.ViewId)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)8 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8