use of de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor 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.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor 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.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor 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.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor in project metasfresh-webui-api by metasfresh.
the class SqlDocumentsRepository method retrieveVersion.
@Override
public String retrieveVersion(final DocumentEntityDescriptor entityDescriptor, final int documentIdAsInt) {
final SqlDocumentEntityDataBindingDescriptor binding = SqlDocumentEntityDataBindingDescriptor.cast(entityDescriptor.getDataBinding());
final String sql = binding.getSqlSelectVersionById().orElseThrow(() -> new AdempiereException("Versioning is not supported for " + entityDescriptor));
final Timestamp version = DB.getSQLValueTSEx(ITrx.TRXNAME_ThreadInherited, sql, documentIdAsInt);
return version == null ? VERSION_DEFAULT : String.valueOf(version.getTime());
}
use of de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor in project metasfresh-webui-api by metasfresh.
the class SqlDocumentsRepository method retrieveOrCreatePO.
private PO retrieveOrCreatePO(final Document document) {
final SqlDocumentEntityDataBindingDescriptor dataBinding = SqlDocumentEntityDataBindingDescriptor.cast(document.getEntityDescriptor().getDataBinding());
final String sqlTableName = dataBinding.getTableName();
//
// Load the PO / Create new PO instance
final PO po;
if (document.isNew()) {
po = TableModelLoader.instance.newPO(document.getCtx(), sqlTableName, ITrx.TRXNAME_ThreadInherited);
} else if (dataBinding.isSingleKey()) {
final boolean checkCache = false;
po = TableModelLoader.instance.getPO(document.getCtx(), sqlTableName, document.getDocumentIdAsInt(), checkCache, ITrx.TRXNAME_ThreadInherited);
} else {
po = toQueryBuilder(dataBinding, document.getDocumentId()).create().firstOnly(PO.class);
}
if (po == null) {
throw new DBException("No PO found for " + document);
}
//
//
po.set_ManualUserAction(document.getWindowNo());
// allow changing any columns
InterfaceWrapperHelper.ATTR_ReadOnlyColumnCheckDisabled.setValue(po, true);
return po;
}
Aggregations