use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class ADProcessDescriptorsFactory method createProcessParaDescriptor.
private DocumentFieldDescriptor.Builder createProcessParaDescriptor(final WebuiProcessClassInfo webuiProcesClassInfo, final I_AD_Process_Para adProcessParam) {
final IModelTranslationMap adProcessParaTrlsMap = InterfaceWrapperHelper.getModelTranslationMap(adProcessParam);
final String parameterName = adProcessParam.getColumnName();
//
// Ask the provider if it has some custom lookup descriptor
LookupDescriptorProvider lookupDescriptorProvider = webuiProcesClassInfo.getLookupDescriptorProviderOrNull(parameterName);
// Fallback: create an SQL lookup descriptor based on adProcessParam
if (lookupDescriptorProvider == null) {
lookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(null).setCtxColumnName(parameterName).setDisplayType(adProcessParam.getAD_Reference_ID()).setAD_Reference_Value_ID(adProcessParam.getAD_Reference_Value_ID()).setAD_Val_Rule_ID(adProcessParam.getAD_Val_Rule_ID()).setReadOnlyAccess().buildProvider();
}
//
final LookupDescriptor lookupDescriptor = lookupDescriptorProvider.provideForScope(LookupDescriptorProvider.LookupScope.DocumentField);
final DocumentFieldWidgetType widgetType = extractWidgetType(parameterName, adProcessParam.getAD_Reference_ID(), lookupDescriptor, adProcessParam.isRange());
final Class<?> valueClass = DescriptorsFactoryHelper.getValueClass(widgetType, lookupDescriptor);
// process parameters shall always allow displaying the password
final boolean allowShowPassword = widgetType == DocumentFieldWidgetType.Password ? true : false;
final ILogicExpression readonlyLogic = expressionFactory.compileOrDefault(adProcessParam.getReadOnlyLogic(), ConstantLogicExpression.FALSE, ILogicExpression.class);
final ILogicExpression displayLogic = expressionFactory.compileOrDefault(adProcessParam.getDisplayLogic(), ConstantLogicExpression.TRUE, ILogicExpression.class);
final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(adProcessParam.isMandatory());
final Optional<IExpression<?>> defaultValueExpr = defaultValueExpressions.extractDefaultValueExpression(adProcessParam.getDefaultValue(), parameterName, widgetType, valueClass, mandatoryLogic.isConstantTrue(), // don't allow using auto sequence
false);
final DocumentFieldDescriptor.Builder paramDescriptor = DocumentFieldDescriptor.builder(parameterName).setCaption(adProcessParaTrlsMap.getColumnTrl(I_AD_Process_Para.COLUMNNAME_Name, adProcessParam.getName())).setDescription(adProcessParaTrlsMap.getColumnTrl(I_AD_Process_Para.COLUMNNAME_Description, adProcessParam.getDescription())).setValueClass(valueClass).setWidgetType(widgetType).setAllowShowPassword(allowShowPassword).setLookupDescriptorProvider(lookupDescriptorProvider).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField);
// Add a callout to forward process parameter value (UI) to current process instance
if (webuiProcesClassInfo.isForwardValueToJavaProcessInstance(parameterName)) {
paramDescriptor.addCallout(ProcessParametersCallout::forwardValueToCurrentProcessInstance);
}
return paramDescriptor;
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause.
/**
* Build document filter parameter where clause
*/
private String buildSqlWhereClause(final SqlParamsCollector sqlParams, final String filterId, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
// SQL filter
if (filterParam.isSqlFilter()) {
String sqlWhereClause = filterParam.getSqlWhereClause();
if (sqlOpts.isUseTableAlias()) {
sqlWhereClause = replaceTableNameWithTableAlias(sqlWhereClause, sqlOpts.getTableAlias());
}
final List<Object> sqlWhereClauseParams = filterParam.getSqlWhereClauseParams();
sqlParams.collectAll(sqlWhereClauseParams);
return sqlWhereClause;
}
//
// Labels filter
final String parameterName = filterParam.getFieldName();
final DocumentFieldWidgetType widgetType = getParameterWidgetType(parameterName);
if (widgetType == DocumentFieldWidgetType.Labels) {
final DocumentFilterParamDescriptor paramDescriptor = getParameterDescriptor(filterId, parameterName);
return buildSqlWhereClause_LabelsWidget(filterParam, paramDescriptor, sqlParams, sqlOpts);
} else //
// Standard filter
{
return buildSqlWhereClause_StandardWidget(sqlParams, filterParam, sqlOpts);
}
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class SqlDefaultDocumentFilterConverter method convertToSqlValue.
private Object convertToSqlValue(final Object value, final SqlEntityFieldBinding fieldBinding, final IQueryFilterModifier modifier) {
final String columnName = fieldBinding.getColumnName();
final DocumentFieldWidgetType widgetType = fieldBinding.getWidgetType();
final Class<?> targetClass = fieldBinding.getSqlValueClass();
final Object sqlValue = SqlDocumentsRepository.convertValueToPO(value, columnName, widgetType, targetClass);
return modifier.convertValue(columnName, sqlValue, null);
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class DocumentFilterDescriptorsProviderFactory method createFilterParam.
private final DocumentFilterParamDescriptor.Builder createFilterParam(final DocumentFieldDescriptor field) {
final ITranslatableString displayName = field.getCaption();
final String fieldName = field.getFieldName();
final DocumentFieldWidgetType widgetType = extractFilterWidgetType(field);
final DocumentFieldDefaultFilterDescriptor filteringInfo = field.getDefaultFilterInfo();
final LookupDescriptor lookupDescriptor = field.getLookupDescriptor(LookupDescriptorProvider.LookupScope.DocumentFilter);
final Operator operator;
if (widgetType.isText()) {
operator = Operator.LIKE_I;
} else if (filteringInfo.isRangeFilter()) {
operator = Operator.BETWEEN;
} else {
operator = Operator.EQUAL;
}
return DocumentFilterParamDescriptor.builder().setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setLookupDescriptor(lookupDescriptor).setMandatory(false).setShowIncrementDecrementButtons(filteringInfo.isShowFilterIncrementButtons()).setAutoFilterInitialValue(filteringInfo.getAutoFilterInitialValue());
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class SqlDocumentQueryBuilder method buildSqlWhereClause.
private IPair<IStringExpression, List<Object>> buildSqlWhereClause() {
final SqlParamsCollector sqlParams = SqlParamsCollector.newInstance();
final CompositeStringExpression.Builder sqlWhereClauseBuilder = IStringExpression.composer();
//
// Entity's WHERE clause
{
final IStringExpression entityWhereClauseExpression = entityBinding.getSqlWhereClause();
if (!entityWhereClauseExpression.isNullExpression()) {
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* entity where clause */ (").append(entityWhereClauseExpression).append(")");
}
}
//
// Key column
// FIXME: handle AD_Reference/AD_Ref_List(s). In that case the recordId will be AD_Ref_List.Value,
// so the SQL where clause which is currently build is AD_Ref_List_ID=<the AD_Ref_List.Value>.
// The build SQL where clause shall be something like AD_Reference_ID=<the reference, i think we shall fetch it somehow from Lookup> AND Value=<the value, which currently is the recordId>
final DocumentId recordId = getRecordId();
if (recordId != null) {
final List<SqlDocumentFieldDataBindingDescriptor> keyFields = entityBinding.getKeyFields();
if (keyFields.isEmpty()) {
throw new AdempiereException("Failed building where clause because there is no Key Column defined in " + entityBinding);
} else // Single primary key
if (keyFields.size() == 1) {
final String keyColumnName = keyFields.get(0).getColumnName();
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* key */ ").append(keyColumnName).append("=").append(sqlParams.placeholder(recordId.toInt()));
} else // Composed primary key
{
final Map<String, Object> keyColumnName2value = extractComposedKey(recordId, keyFields);
keyColumnName2value.forEach((keyColumnName, value) -> {
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* key */ ").append(keyColumnName).append("=").append(sqlParams.placeholder(value));
});
}
}
//
// Parent link where clause (if any)
final Document parentDocument = getParentDocument();
if (parentDocument != null) {
final String parentLinkColumnName = entityBinding.getParentLinkColumnName();
final String linkColumnName = entityBinding.getLinkColumnName();
if (parentLinkColumnName != null && linkColumnName != null) {
final IDocumentFieldView parentLinkField = parentDocument.getFieldView(parentLinkColumnName);
final Object parentLinkValue = parentLinkField.getValue();
final DocumentFieldWidgetType parentLinkWidgetType = parentLinkField.getWidgetType();
final Class<?> targetClass = entityBinding.getFieldByFieldName(linkColumnName).getSqlValueClass();
final Object sqlParentLinkValue = SqlDocumentsRepository.convertValueToPO(parentLinkValue, parentLinkColumnName, parentLinkWidgetType, targetClass);
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* parent link */ ").append(linkColumnName).append("=").append(sqlParams.placeholder(sqlParentLinkValue));
}
}
//
// Document filters
{
final String sqlFilters = SqlDocumentFilterConverters.createEntityBindingEffectiveConverter(entityBinding).getSql(sqlParams, getDocumentFilters(), SqlOptions.usingTableAlias(entityBinding.getTableAlias()));
if (!Check.isEmpty(sqlFilters, true)) {
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* filters */ (\n").append(sqlFilters).append(")\n");
}
}
// Build the final SQL where clause
return ImmutablePair.of(sqlWhereClauseBuilder.build(), Collections.unmodifiableList(sqlParams.toList()));
}
Aggregations