use of de.metas.ui.web.view.descriptor.SqlViewBinding in project metasfresh-webui-api by metasfresh.
the class SqlViewFactory method createViewLayout.
private ViewLayout createViewLayout(final SqlViewBindingKey sqlViewBindingKey, final JSONViewDataType viewDataType) {
final ViewLayout viewLayoutOrig = documentDescriptorFactory.getDocumentDescriptor(sqlViewBindingKey.getWindowId()).getViewLayout(viewDataType);
final SqlViewBinding sqlViewBinding = getViewBinding(sqlViewBindingKey);
final Collection<DocumentFilterDescriptor> filters = sqlViewBinding.getViewFilterDescriptors().getAll();
final boolean hasTreeSupport = sqlViewBinding.hasGroupingFields();
final ViewLayout.ChangeBuilder viewLayoutBuilder = viewLayoutOrig.toBuilder().profileId(sqlViewBindingKey.getProfileId()).filters(filters).treeSupport(hasTreeSupport, true, /* treeCollapsible */
ViewLayout.TreeExpandedDepth_AllCollapsed);
final SqlViewCustomizer sqlViewCustomizer = getSqlViewCustomizer(sqlViewBindingKey.getWindowId(), sqlViewBindingKey.getProfileId());
if (sqlViewCustomizer != null) {
sqlViewCustomizer.customizeViewLayout(viewLayoutBuilder);
}
return viewLayoutBuilder.build();
}
use of de.metas.ui.web.view.descriptor.SqlViewBinding in project metasfresh-webui-api by metasfresh.
the class SqlViewFactory method createViewBinding.
private SqlViewBinding createViewBinding(@NonNull final SqlViewBindingKey key) {
final WindowId windowId = key.getWindowId();
final DocumentEntityDescriptor entityDescriptor = documentDescriptorFactory.getDocumentEntityDescriptor(windowId);
final Set<String> displayFieldNames = entityDescriptor.getFieldNamesWithCharacteristic(key.getRequiredFieldCharacteristic());
final SqlDocumentEntityDataBindingDescriptor entityBinding = SqlDocumentEntityDataBindingDescriptor.cast(entityDescriptor.getDataBinding());
final DocumentFilterDescriptorsProvider filterDescriptors = entityDescriptor.getFilterDescriptors();
final SqlViewBinding.Builder builder = createBuilderForEntityBindingAndFieldNames(entityBinding, displayFieldNames).filterDescriptors(filterDescriptors).viewInvalidationAdvisor(getViewInvalidationAdvisor(windowId));
if (windowId2SqlDocumentFilterConverterDecorator.containsKey(windowId)) {
builder.filterConverterDecorator(windowId2SqlDocumentFilterConverterDecorator.get(windowId));
}
final SqlViewCustomizer sqlViewCustomizer = getSqlViewCustomizer(windowId, key.getProfileId());
if (sqlViewCustomizer != null) {
final ViewRowCustomizer rowCustomizer = sqlViewCustomizer;
builder.rowCustomizer(rowCustomizer);
sqlViewCustomizer.customizeSqlViewBinding(builder);
}
return builder.build();
}
use of de.metas.ui.web.view.descriptor.SqlViewBinding in project metasfresh-webui-api by metasfresh.
the class HUEditorViewFactoryTemplate method createSqlViewBinding.
private SqlViewBinding createSqlViewBinding() {
// Get HU's standard entity descriptor. We will needed all over.
final DocumentEntityDescriptor huEntityDescriptor = getHUEntityDescriptor();
//
// Static where clause
final StringBuilder sqlWhereClause = new StringBuilder();
{
// top level
sqlWhereClause.append(I_M_HU.COLUMNNAME_M_HU_Item_Parent_ID + " is null");
// Consider window tab's where clause if any
final I_AD_Tab huTab = Services.get(IADWindowDAO.class).retrieveFirstTab(WEBUI_HU_Constants.WEBUI_HU_Window_ID.toInt());
if (!Check.isEmpty(huTab.getWhereClause(), true)) {
sqlWhereClause.append("\n AND (").append(huTab.getWhereClause()).append(")");
}
}
//
// Start preparing the sqlViewBinding builder
final List<String> displayFieldNames = ImmutableList.of(I_M_HU.COLUMNNAME_M_HU_ID);
final SqlViewBinding.Builder sqlViewBinding = SqlViewBinding.builder().tableName(I_M_HU.Table_Name).displayFieldNames(displayFieldNames).sqlWhereClause(sqlWhereClause.toString()).rowIdsConverter(HUSqlViewRowIdsConverter.instance);
//
// View fields: from M_HU's entity descriptor
{
// NOTE: we need to add all HU's standard fields because those might be needed for some of the standard filters defined
final SqlDocumentEntityDataBindingDescriptor huEntityBindings = SqlDocumentEntityDataBindingDescriptor.cast(huEntityDescriptor.getDataBinding());
huEntityBindings.getFields().stream().map(huField -> SqlViewFactory.createViewFieldBindingBuilder(huField, displayFieldNames).build()).forEach(sqlViewBinding::field);
}
//
// View field: BestBeforeDate
{
sqlViewBinding.field(SqlViewRowFieldBinding.builder().fieldName(HUEditorRow.FIELDNAME_BestBeforeDate).widgetType(DocumentFieldWidgetType.Date).columnSql(Constants.sqlBestBeforeDate(sqlViewBinding.getTableAlias() + "." + I_M_HU.COLUMNNAME_M_HU_ID)).fieldLoader((rs, adLanguage) -> rs.getTimestamp(HUEditorRow.FIELDNAME_BestBeforeDate)).build());
}
//
// View filters and converters
{
sqlViewBinding.filterDescriptors(createFilterDescriptorsProvider()).filterConverter(HUBarcodeSqlDocumentFilterConverter.FILTER_ID, HUBarcodeSqlDocumentFilterConverter.instance).filterConverter(HUIdsFilterHelper.FILTER_ID, HUIdsFilterHelper.SQL_DOCUMENT_FILTER_CONVERTER);
createFilterConvertersIndexedByFilterId().forEach(sqlViewBinding::filterConverter);
}
//
return sqlViewBinding.build();
}
use of de.metas.ui.web.view.descriptor.SqlViewBinding 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.view.descriptor.SqlViewBinding in project metasfresh-webui-api by metasfresh.
the class SqlViewFactory method createAutoFilters.
private List<DocumentFilter> createAutoFilters(final SqlViewBindingKey sqlViewBindingKey) {
final SqlViewBinding sqlViewBinding = getViewBinding(sqlViewBindingKey);
final Collection<DocumentFilterDescriptor> filters = sqlViewBinding.getViewFilterDescriptors().getAll();
return filters.stream().filter(DocumentFilterDescriptor::isAutoFilter).map(SqlViewFactory::createAutoFilter).collect(ImmutableList.toImmutableList());
}
Aggregations