use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.
the class HUEditorViewBuffer_FullyCached method getSqlWhereClause.
@Override
public String getSqlWhereClause(final DocumentIdsSelection rowIds) {
final DocumentIdsSelection rowIdsEffective = getRows().streamByIdsExcludingIncludedRows(HUEditorRowFilter.onlyRowIds(rowIds)).map(HUEditorRow::getId).collect(DocumentIdsSelection.toDocumentIdsSelection());
final Set<Integer> huIds = huEditorRepo.getRowIdsConverter().convertToRecordIds(rowIdsEffective);
// NOTE: accept it even if is empty. In case it's empty, we will return something like M_HU_ID in (-1)
// same this is happening for the others HUEditorViewBuffer implementation
// see https://github.com/metasfresh/metasfresh-webui-api/issues/764
final String sqlKeyColumnNameFK = I_M_HU.Table_Name + "." + I_M_HU.COLUMNNAME_M_HU_ID;
return sqlKeyColumnNameFK + " IN " + DB.buildSqlList(huIds);
}
use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.
the class HUEditorViewBuffer_HighVolume method removeHUIds.
@Override
public boolean removeHUIds(final Collection<Integer> huIdsToRemove) {
if (huIdsToRemove == null || huIdsToRemove.isEmpty()) {
return false;
}
final DocumentIdsSelection rowIdsToRemove = HUEditorRowId.rowIdsFromTopLevelM_HU_IDs(huIdsToRemove);
rowIdsToRemove.forEach(rowId -> cache_huRowsById.remove(rowId));
return changeSelection(defaultSelection -> huEditorRepo.removeRowIdsFromSelection(defaultSelection, rowIdsToRemove));
}
use of de.metas.ui.web.window.datatypes.DocumentIdsSelection 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();
}
use of de.metas.ui.web.window.datatypes.DocumentIdsSelection 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;
}
use of de.metas.ui.web.window.datatypes.DocumentIdsSelection 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);
}
Aggregations