use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class UserQueryDocumentFilterDescriptorsProvider method createFilterDescriptor0.
private static final DocumentFilterDescriptor createFilterDescriptor0(@NonNull final IUserQuery userQuery) {
final DocumentFilterDescriptor.Builder filter = DocumentFilterDescriptor.builder().setFilterId("userquery-" + userQuery.getId()).setDisplayName(userQuery.getCaption()).setFrequentUsed(false);
if (WindowConstants.isProtocolDebugging()) {
filter.putDebugProperty("userQuery", userQuery.toString());
}
for (final IUserQueryRestriction queryRestriction : userQuery.getRestrictions()) {
final Join join = queryRestriction.getJoin();
final UserQueryField searchField = UserQueryField.cast(queryRestriction.getSearchField());
final String fieldName = searchField.getColumnName();
final Operator operator = MQueryDocumentFilterHelper.fromMQueryOperator(queryRestriction.getOperator());
final Object value = queryRestriction.getValue();
final Object valueTo = queryRestriction.getValueTo();
final boolean isParameter;
if (operator.isRangeOperator()) {
isParameter = value == null || valueTo == null;
} else {
isParameter = value == null;
}
if (isParameter) {
final ITranslatableString displayName = searchField.getDisplayName();
final DocumentFieldWidgetType widgetType = searchField.getWidgetType();
final LookupDescriptor lookupDescriptor = searchField.getLookupDescriptor();
filter.addParameter(DocumentFilterParamDescriptor.builder().setJoinAnd(join == Join.AND).setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setDefaultValue(value).setDefaultValueTo(valueTo).setMandatory(// mandatory if there is no default value
value == null).setLookupDescriptor(lookupDescriptor));
} else {
filter.addInternalParameter(DocumentFilterParam.builder().setJoinAnd(join == Join.AND).setFieldName(fieldName).setOperator(operator).setValue(value).setValueTo(valueTo).build());
}
}
return filter.build();
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause_StandardWidget.
private final String buildSqlWhereClause_StandardWidget(final SqlParamsCollector sqlParams, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
final SqlEntityFieldBinding paramBinding = getParameterBinding(filterParam.getFieldName());
final DocumentFieldWidgetType widgetType = paramBinding.getWidgetType();
//
// Regular filter
final IQueryFilterModifier fieldModifier = extractFieldModifier(widgetType);
final IQueryFilterModifier valueModifier = extractValueModifier(widgetType);
final String columnSql = extractColumnSql(paramBinding, fieldModifier, sqlOpts);
final Operator operator = filterParam.getOperator();
switch(operator) {
case EQUAL:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final boolean negate = false;
return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
}
case NOT_EQUAL:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final boolean negate = true;
return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
}
case IN_ARRAY:
{
final List<Object> sqlValuesList = filterParam.getValueAsList(itemObj -> convertToSqlValue(itemObj, paramBinding, valueModifier));
return buildSqlWhereClause_InArray(columnSql, sqlValuesList, sqlParams);
}
case GREATER:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
return buildSqlWhereClause_Compare(columnSql, ">", sqlValue, sqlParams);
}
case GREATER_OR_EQUAL:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
return buildSqlWhereClause_Compare(columnSql, ">=", sqlValue, sqlParams);
}
case LESS:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
return buildSqlWhereClause_Compare(columnSql, "<", sqlValue, sqlParams);
}
case LESS_OR_EQUAL:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
return buildSqlWhereClause_Compare(columnSql, "<=", sqlValue, sqlParams);
}
case LIKE:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final boolean negate = false;
final boolean ignoreCase = false;
return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
}
case NOT_LIKE:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final boolean negate = true;
final boolean ignoreCase = false;
return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
}
case LIKE_I:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final boolean negate = false;
final boolean ignoreCase = true;
return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
}
case NOT_LIKE_I:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final boolean negate = true;
final boolean ignoreCase = true;
return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
}
case BETWEEN:
{
final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
final Object sqlValueTo = convertToSqlValue(filterParam.getValueTo(), paramBinding, valueModifier);
return buildSqlWhereClause_Between(columnSql, sqlValue, sqlValueTo, sqlParams);
}
default:
{
throw new IllegalArgumentException("Operator not supported: " + operator);
}
}
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class HUEditorRowAttributesHelper method createLayoutElement.
private static final DocumentLayoutElementDescriptor createLayoutElement(final IAttributeValue attributeValue, final int warehouseId) {
final I_M_Attribute attribute = attributeValue.getM_Attribute();
final IModelTranslationMap attributeTrlMap = InterfaceWrapperHelper.getModelTranslationMap(attribute);
final ITranslatableString caption = attributeTrlMap.getColumnTrl(I_M_Attribute.COLUMNNAME_Name, attribute.getName());
final ITranslatableString description = attributeTrlMap.getColumnTrl(I_M_Attribute.COLUMNNAME_Description, attribute.getDescription());
final String attributeName = HUEditorRowAttributesHelper.extractAttributeName(attributeValue);
final DocumentFieldWidgetType widgetType = HUEditorRowAttributesHelper.extractWidgetType(attributeValue);
return DocumentLayoutElementDescriptor.builder().setCaption(caption).setDescription(description).setWidgetType(widgetType).addField(DocumentLayoutElementFieldDescriptor.builder(attributeName).setPublicField(true).addDevices(createDevices(attribute.getValue(), warehouseId))).build();
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class HUEditorRowAttributes method toJSONDocumentField.
private final JSONDocumentField toJSONDocumentField(final IAttributeValue attributeValue) {
final String fieldName = HUEditorRowAttributesHelper.extractAttributeName(attributeValue);
final Object jsonValue = HUEditorRowAttributesHelper.extractJSONValue(attributesStorage, attributeValue);
final DocumentFieldWidgetType widgetType = HUEditorRowAttributesHelper.extractWidgetType(attributeValue);
return JSONDocumentField.ofNameAndValue(fieldName, jsonValue).setDisplayed(isDisplayed(fieldName)).setMandatory(false).setReadonly(isReadonly(fieldName)).setWidgetType(JSONLayoutWidgetType.fromNullable(widgetType));
}
use of de.metas.ui.web.window.descriptor.DocumentFieldWidgetType in project metasfresh-webui-api by metasfresh.
the class ViewExcelExporter method getValueAt.
@Override
public CellValue getValueAt(final int rowIndex, final int columnIndex) {
final String fieldName = getFieldName(columnIndex);
final IViewRow row = getRow(rowIndex);
if (row == null) {
return null;
}
final Object value = row.getFieldNameAndJsonValues().get(fieldName);
if (value == null) {
return null;
}
final DocumentFieldWidgetType widgetType = getWidgetType(columnIndex);
if (widgetType.isDateOrTime()) {
return CellValue.ofDate(JSONDate.fromJson(value.toString(), widgetType));
} else if (value instanceof JSONLookupValue) {
final String valueStr = ((JSONLookupValue) value).getCaption();
return CellValues.toCellValue(valueStr, widgetType.getDisplayType());
} else {
return CellValues.toCellValue(value, widgetType.getDisplayType());
}
}
Aggregations