use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method createBoardDescriptor.
private BoardDescriptor createBoardDescriptor(final int boardId) {
//
// Retrieve the board PO
final IQueryBL queryBL = Services.get(IQueryBL.class);
final I_WEBUI_Board boardPO = queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board.class).addEqualsFilter(I_WEBUI_Board.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().create().firstOnly(I_WEBUI_Board.class);
if (boardPO == null) {
throw new EntityNotFoundException("No board found for ID=" + boardId);
}
//
// Board document mappings
final String tableName = Services.get(IADTableDAO.class).retrieveTableName(boardPO.getAD_Table_ID());
final String keyColumnName = InterfaceWrapperHelper.getKeyColumnName(tableName);
// TODO: hardcoded
final String userIdColumnName = "UpdatedBy";
//
// Board document info
// TODO boardPO.getAD_Window_ID();
int adWindowId = 0;
if (adWindowId <= 0) {
adWindowId = RecordZoomWindowFinder.findAD_Window_ID(tableName);
}
final WindowId documentWindowId = WindowId.of(adWindowId);
final DocumentEntityDescriptor documentEntityDescriptor = documentDescriptors.getDocumentEntityDescriptor(documentWindowId);
final SqlDocumentEntityDataBindingDescriptor documentBinding = documentEntityDescriptor.getDataBinding(SqlDocumentEntityDataBindingDescriptor.class);
final String tableAlias = documentBinding.getTableAlias();
//
// Board document lookup provider
final int adValRuleId = boardPO.getAD_Val_Rule_ID();
final LookupDescriptorProvider documentLookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(null).setCtxColumnName(keyColumnName).setDisplayType(DisplayType.Search).setWidgetType(DocumentFieldWidgetType.Lookup).setAD_Val_Rule_ID(adValRuleId).buildProvider();
//
// Board descriptor
final IModelTranslationMap boardTrlMap = InterfaceWrapperHelper.getModelTranslationMap(boardPO);
final BoardDescriptorBuilder boardDescriptor = BoardDescriptor.builder().boardId(boardPO.getWEBUI_Board_ID()).caption(boardTrlMap.getColumnTrl(I_WEBUI_Board.COLUMNNAME_Name, boardPO.getName())).documentWindowId(documentWindowId).documentLookupDescriptorProvider(documentLookupDescriptorProvider).tableName(tableName).tableAlias(tableAlias).keyColumnName(keyColumnName).userIdColumnName(userIdColumnName).websocketEndpoint(WebSocketConfig.buildBoardTopicName(boardId));
// Source document filters: AD_Val_Rule_ID
if (adValRuleId > 0) {
final IValidationRule validationRule = Services.get(IValidationRuleFactory.class).create(tableName, adValRuleId, // ctx table name
null, // ctx column name
null);
final String sqlWhereClause = validationRule.getPrefilterWhereClause().evaluate(Evaluatees.ofCtx(Env.getCtx()), OnVariableNotFound.Fail);
final DocumentFilter adValRuleFilter = DocumentFilter.builder().setFilterId("AD_Val_Rule_" + adValRuleId).addParameter(DocumentFilterParam.ofSqlWhereClause(true, sqlWhereClause)).build();
boardDescriptor.documentFilter(adValRuleFilter);
}
//
// Lanes
{
queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board_Lane.class).addEqualsFilter(I_WEBUI_Board_Lane.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().orderBy().addColumn(I_WEBUI_Board_Lane.COLUMN_SeqNo).addColumn(// just have a predictable order
I_WEBUI_Board_Lane.COLUMN_WEBUI_Board_Lane_ID).endOrderBy().create().stream(I_WEBUI_Board_Lane.class).map(this::createBoardLaneDescriptor).forEach(lane -> boardDescriptor.lane(lane.getLaneId(), lane));
}
//
// Board card fields
{
queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board_CardField.class).addEqualsFilter(I_WEBUI_Board_CardField.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().orderBy().addColumn(I_WEBUI_Board_CardField.COLUMN_SeqNo).addColumn(I_WEBUI_Board_CardField.COLUMN_WEBUI_Board_CardField_ID).endOrderBy().create().stream(I_WEBUI_Board_CardField.class).map(cardFieldPO -> createBoardCardFieldDescriptor(cardFieldPO, documentEntityDescriptor)).forEach(cardField -> boardDescriptor.cardFieldByFieldName(cardField.getFieldName(), cardField));
}
//
return boardDescriptor.build();
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class SqlDocumentFilterConverter method getSql.
default String getSql(@NonNull final SqlParamsCollector sqlParamsOut, @NonNull final List<DocumentFilter> filters, @NonNull final SqlOptions sqlOpts) {
if (filters.isEmpty()) {
return "";
}
final StringBuilder sqlWhereClauseBuilder = new StringBuilder();
for (final DocumentFilter filter : filters) {
final String sqlFilter = getSql(sqlParamsOut, filter, sqlOpts);
if (Check.isEmpty(sqlFilter, true)) {
continue;
}
if (sqlWhereClauseBuilder.length() > 0) {
sqlWhereClauseBuilder.append("\n AND ");
}
sqlWhereClauseBuilder.append(DB.TO_COMMENT(filter.getFilterId())).append("(").append(sqlFilter).append(")");
}
return sqlWhereClauseBuilder.toString();
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class HUEditorViewFactoryTemplate method createView.
@Override
public final HUEditorView createView(final CreateViewRequest request) {
final ViewId viewId = request.getViewId();
//
// Referencing documentPaths and tableName (i.e. from where are we coming, e.g. receipt schedule)
final Set<DocumentPath> referencingDocumentPaths = request.getReferencingDocumentPaths();
final String referencingTableName = extractReferencingTablename(referencingDocumentPaths);
final SqlViewBinding sqlViewBinding = getSqlViewBinding();
//
// HUEditorView rows repository
final HUEditorViewRepository huEditorViewRepository;
{
final WindowId windowId = viewId.getWindowId();
final boolean attributesAlwaysReadonly = rowAttributesAlwaysReadonlyByReferencingTableName.getOrDefault(referencingTableName, Boolean.TRUE);
final SqlHUEditorViewRepositoryBuilder huEditorViewRepositoryBuilder = SqlHUEditorViewRepository.builder().windowId(windowId).rowProcessedPredicate(getRowProcessedPredicate(referencingTableName)).attributesProvider(HUEditorRowAttributesProvider.builder().readonly(attributesAlwaysReadonly).build()).sqlViewBinding(sqlViewBinding);
customizeHUEditorViewRepository(huEditorViewRepositoryBuilder);
huEditorViewRepository = huEditorViewRepositoryBuilder.build();
}
//
// HUEditorView
{
// Filters
// as long as the deprecated getFilterOnlyIds() is around we can't ignore it
@SuppressWarnings("deprecation") final List<DocumentFilter> stickyFilters = extractStickyFilters(request.getStickyFilters(), request.getFilterOnlyIds());
final DocumentFilterDescriptorsProvider filterDescriptors = getViewFilterDescriptors();
final List<DocumentFilter> filters = request.getOrUnwrapFilters(filterDescriptors);
// Start building the HUEditorView
final HUEditorViewBuilder huViewBuilder = HUEditorView.builder().setParentViewId(request.getParentViewId()).setParentRowId(request.getParentRowId()).setViewId(viewId).setViewType(request.getViewType()).setStickyFilters(stickyFilters).setFilters(filters).setFilterDescriptors(filterDescriptors).setReferencingDocumentPaths(referencingTableName, referencingDocumentPaths).orderBys(sqlViewBinding.getDefaultOrderBys()).setActions(request.getActions()).addAdditionalRelatedProcessDescriptors(request.getAdditionalRelatedProcessDescriptors()).setHUEditorViewRepository(huEditorViewRepository).setParameters(request.getParameters());
//
// Call view customizers
getViewCustomizers(referencingTableName).forEach(viewCustomizer -> viewCustomizer.beforeCreate(huViewBuilder));
customizeHUEditorView(huViewBuilder);
return huViewBuilder.build();
}
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class HUEditorViewBuilder method createRowsBuffer.
final HUEditorViewBuffer createRowsBuffer() {
final ViewId viewId = getViewId();
final List<DocumentFilter> stickyFilters = getStickyFilters();
final List<DocumentFilter> filters = getFilters();
if (HUEditorViewBuffer_HighVolume.isHighVolume(stickyFilters)) {
return new HUEditorViewBuffer_HighVolume(viewId, huEditorViewRepository, stickyFilters, filters, getOrderBys());
} else {
return new HUEditorViewBuffer_FullyCached(viewId, huEditorViewRepository, stickyFilters, filters, getOrderBys());
}
}
use of de.metas.ui.web.document.filter.DocumentFilter in project metasfresh-webui-api by metasfresh.
the class DocumentFilterToHuTraceQueryTest method createTraceQueryFromDocumentFilter.
@Test
public void createTraceQueryFromDocumentFilter() {
final DocumentFilter emptyFilter = DocumentFilter.builder().setFilterId("simple-M_InOut_ID-filter").addParameter(DocumentFilterParam.ofNameOperatorValue(I_M_HU_Trace.COLUMNNAME_M_InOut_ID, Operator.EQUAL, IntegerLookupValue.of(20, "test-inout-id"))).build();
final HUTraceEventQuery huTraceQuery = HuTraceQueryCreator.createTraceQueryFromDocumentFilter(emptyFilter);
assertThat(huTraceQuery).isNotNull();
assertThat(huTraceQuery.getRecursionMode()).isEqualTo(RecursionMode.BOTH);
assertThat(huTraceQuery.getInOutId()).isEqualTo(20);
}
Aggregations