Search in sources :

Example 21 with DocumentIdsSelection

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

the class MD_Cockpit_DocumentDetail_Display method retrieveCockpitRecordIds.

private ImmutableSet<Integer> retrieveCockpitRecordIds() {
    final MaterialCockpitView materialCockpitView = (MaterialCockpitView) getView();
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    final ImmutableSet<Integer> cockpitRowIds = selectedRowIds.stream().map(rowId -> {
        return materialCockpitView.getById(rowId);
    }).flatMap(row -> {
        return row.getAllIncludedCockpitRecordIds().stream();
    }).collect(ImmutableSet.toImmutableSet());
    return cockpitRowIds;
}
Also used : ViewBasedProcessTemplate(de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate) ImmutableSet(com.google.common.collect.ImmutableSet) NonNull(lombok.NonNull) MaterialCockpitView(de.metas.ui.web.material.cockpit.MaterialCockpitView) IQueryBL(org.adempiere.ad.dao.IQueryBL) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) Services(org.adempiere.util.Services) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) I_MD_Cockpit_DocumentDetail(de.metas.material.cockpit.model.I_MD_Cockpit_DocumentDetail) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) IProcessPrecondition(de.metas.process.IProcessPrecondition) MaterialCockpitConstants(de.metas.ui.web.material.cockpit.MaterialCockpitConstants) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) MaterialCockpitView(de.metas.ui.web.material.cockpit.MaterialCockpitView)

Example 22 with DocumentIdsSelection

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

the class WEBUI_HUsToPick_PickCU method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable() {
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (selectedRowIds.isEmpty()) {
        return ProcessPreconditionsResolution.rejectBecauseNoSelection();
    } else if (selectedRowIds.isMoreThanOneDocumentId()) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
    }
    final HUEditorRow huRow = getSingleSelectedRow();
    if (!isEligible(huRow)) {
        final ITranslatableString reason = Services.get(IMsgBL.class).getTranslatableMsgText(MSG_WEBUI_SELECT_ACTIVE_UNSELECTED_HU);
        return ProcessPreconditionsResolution.reject(reason);
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : IMsgBL(de.metas.i18n.IMsgBL) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ITranslatableString(de.metas.i18n.ITranslatableString) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 23 with DocumentIdsSelection

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

the class ViewRestController method getByIds.

@GetMapping("/{viewId}/byIds")
public List<JSONViewRow> getByIds(// 
@PathVariable(PARAM_WindowId) final String windowId, // 
@PathVariable("viewId") final String viewIdStr, // 
@RequestParam("ids") @ApiParam("comma separated IDs") final String idsListStr) {
    userSession.assertLoggedIn();
    final DocumentIdsSelection rowIds = DocumentIdsSelection.ofCommaSeparatedString(idsListStr);
    if (rowIds.isAll()) {
        throw new AdempiereException("retrieving ALL rows is not allowed here");
    }
    final ViewId viewId = ViewId.of(windowId, viewIdStr);
    final IView view = viewsRepo.getView(viewId);
    final List<? extends IViewRow> result = view.streamByIds(rowIds).collect(ImmutableList.toImmutableList());
    final IViewRowOverrides rowOverrides = ViewRowOverridesHelper.getViewRowOverrides(view);
    return JSONViewRow.ofViewRows(result, rowOverrides, userSession.getAD_Language());
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 24 with DocumentIdsSelection

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

the class ViewActionDescriptor method toWebuiRelatedProcessDescriptor.

public final WebuiRelatedProcessDescriptor toWebuiRelatedProcessDescriptor(final ViewAsPreconditionsContext viewContext) {
    final IView view = viewContext.getView();
    final DocumentIdsSelection selectedDocumentIds = viewContext.getSelectedRowIds();
    return WebuiRelatedProcessDescriptor.builder().processId(ViewProcessInstancesRepository.buildProcessId(view.getViewId(), actionId)).processCaption(caption).processDescription(description).defaultQuickAction(defaultAction).quickAction(true).preconditionsResolutionSupplier(() -> checkPreconditions(view, selectedDocumentIds)).build();
}
Also used : IView(de.metas.ui.web.view.IView) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection)

Example 25 with DocumentIdsSelection

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

the class SqlViewKeyColumnNamesMap method getSqlFilterByRowIds.

@Builder(builderMethodName = "prepareSqlFilterByRowIds", builderClassName = "SqlFilterByRowIdsBuilder")
private SqlAndParams getSqlFilterByRowIds(@NonNull final DocumentIdsSelection rowIds, final SqlViewRowIdsConverter rowIdsConverter, final String sqlColumnPrefix, final boolean useKeyColumnName, final boolean embedSqlParams) {
    if (rowIds.isEmpty()) {
        throw new AdempiereException("rowIds shall not be empty");
    }
    if (isSingleKey()) {
        final String selectionColumnName = useKeyColumnName ? getSingleKeyColumnName() : getSingleWebuiSelectionColumnName();
        final String keyColumnName = (sqlColumnPrefix != null ? sqlColumnPrefix : "") + selectionColumnName;
        final Set<Integer> recordIds = rowIdsConverter != null ? rowIdsConverter.convertToRecordIds(rowIds) : rowIds.toIntSet();
        final List<Object> sqlParams = embedSqlParams ? null : new ArrayList<>();
        final String sql = DB.buildSqlList(keyColumnName, recordIds, sqlParams);
        return SqlAndParams.of(sql, sqlParams != null ? sqlParams : ImmutableList.of());
    } else {
        final List<SqlAndParams> sqls = rowIds.toSet().stream().map(rowId -> getSqlFilterByRowId(rowId, sqlColumnPrefix, useKeyColumnName, embedSqlParams)).collect(ImmutableList.toImmutableList());
        return SqlAndParams.and(sqls);
    }
}
Also used : Singular(lombok.Singular) BiFunction(java.util.function.BiFunction) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Function(java.util.function.Function) I_T_WEBUI_ViewSelection(de.metas.ui.web.base.model.I_T_WEBUI_ViewSelection) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) DB(org.compiere.util.DB) ImmutableList(com.google.common.collect.ImmutableList) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) ResultSet(java.sql.ResultSet) Map(java.util.Map) PlainSqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.PlainSqlEntityFieldBinding) ToString(lombok.ToString) Predicates(com.google.common.base.Predicates) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ImmutableMap(com.google.common.collect.ImmutableMap) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) DBException(org.adempiere.exceptions.DBException) List(java.util.List) Builder(lombok.Builder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) SqlDocumentQueryBuilder(de.metas.ui.web.window.model.sql.SqlDocumentQueryBuilder) AdempiereException(org.adempiere.exceptions.AdempiereException) ToString(lombok.ToString) Builder(lombok.Builder) SqlDocumentQueryBuilder(de.metas.ui.web.window.model.sql.SqlDocumentQueryBuilder)

Aggregations

DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)25 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)8 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)6 IProcessPrecondition (de.metas.process.IProcessPrecondition)5 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)5 List (java.util.List)5 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)5 ImmutableList (com.google.common.collect.ImmutableList)4 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)4 IView (de.metas.ui.web.view.IView)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ViewBasedProcessTemplate (de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate)3 Collection (java.util.Collection)3 Set (java.util.Set)3 NonNull (lombok.NonNull)3 Services (org.adempiere.util.Services)3 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)2 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 Param (de.metas.process.Param)2