use of org.adempiere.ad.expression.api.IStringExpression in project metasfresh-webui-api by metasfresh.
the class DefaultValueExpressionsFactory method extractDefaultValueExpression.
public Optional<IExpression<?>> extractDefaultValueExpression(final String defaultValueStr, final String columnName, final DocumentFieldWidgetType widgetType, final Class<?> fieldValueClass, final boolean isMandatory, final boolean allowUsingAutoSequence) {
final boolean isDetailTab = isDetailTab();
// Case: "Line" field in included tabs
if (WindowConstants.FIELDNAME_Line.equals(columnName) && // only on included tabs
isDetailTab) {
return DEFAULT_VALUE_EXPRESSION_NextLineNo;
}
// If there is no default value expression, use some defaults
if (defaultValueStr == null || defaultValueStr.isEmpty()) {
if (WindowConstants.FIELDNAME_AD_Client_ID.equals(columnName)) {
return DEFAULT_VALUE_AD_Client_ID;
} else if (WindowConstants.FIELDNAME_AD_Org_ID.equals(columnName)) {
return DEFAULT_VALUE_AD_Org_ID;
} else if (WindowConstants.FIELDNAME_Created.equals(columnName) || WindowConstants.FIELDNAME_Updated.equals(columnName)) {
return DEFAULT_VALUE_ContextDate;
} else if (WindowConstants.FIELDNAME_CreatedBy.equals(columnName) || WindowConstants.FIELDNAME_UpdatedBy.equals(columnName)) {
return DEFAULT_VALUE_ContextUser_ID;
} else //
if (WindowConstants.FIELDNAME_Value.equals(columnName) && getTableName() != null && allowUsingAutoSequence) {
return Optional.of(AutoSequenceDefaultValueExpression.of(getTableName()));
} else if (Boolean.class.equals(fieldValueClass)) {
if (WindowConstants.FIELDNAME_IsActive.equals(columnName)) {
return DEFAULT_VALUE_EXPRESSION_Yes;
} else {
return DEFAULT_VALUE_EXPRESSION_No;
}
} else if (Integer.class.equals(fieldValueClass)) {
if (isMandatory) {
return DEFAULT_VALUE_EXPRESSION_Zero_Integer;
}
} else if (BigDecimal.class.equals(fieldValueClass)) {
// e.g. C_OrderLine.QtyReserved
return DEFAULT_VALUE_EXPRESSION_Zero_BigDecimal;
} else if (widgetType == DocumentFieldWidgetType.ProductAttributes) {
return DEFAULT_VALUE_EXPRESSION_M_AttributeSetInstance_ID;
}
return Optional.empty();
} else // Explicit NULL
if ("null".equalsIgnoreCase(defaultValueStr.trim())) {
return Optional.of(IStringExpression.NULL);
} else // If it's a SQL expression => compile it as SQL expression
if (defaultValueStr.startsWith("@SQL=")) {
final String sqlTemplate = defaultValueStr.substring(5).trim();
final IStringExpression sqlTemplateStringExpression = expressionFactory.compile(sqlTemplate, IStringExpression.class);
return Optional.of(SqlDefaultValueExpression.of(sqlTemplateStringExpression, fieldValueClass));
} else // Regular default value expression
{
return buildExpression(expressionFactory, defaultValueStr, fieldValueClass);
}
}
use of org.adempiere.ad.expression.api.IStringExpression in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method retrieveCardCandidates.
public List<BoardCard> retrieveCardCandidates(final int boardId, final List<Integer> cardIds) {
if (cardIds.isEmpty()) {
return ImmutableList.of();
}
final BoardDescriptor boardDescriptor = getBoardDescriptor(boardId);
final String keyColumnName = boardDescriptor.getKeyColumnName();
final String userIdColumnName = boardDescriptor.getUserIdColumnName();
//
final List<Object> sqlParams = new ArrayList<>();
final CompositeStringExpression.Builder sqlExpr;
{
final IStringExpression sqlSelectDocument = buildSqlSelectDocument(boardDescriptor);
final String tableAlias = "r";
final String keyColumnNameFQ = tableAlias + "." + keyColumnName;
final String userIdColumnNameFQ = tableAlias + "." + userIdColumnName;
final SqlLookupDescriptor documentLookup = SqlLookupDescriptor.cast(boardDescriptor.getDocumentLookupDescriptorProvider().provideForScope(LookupScope.DocumentField));
sqlExpr = IStringExpression.composer().append("SELECT ").append("\n NULL AS " + I_WEBUI_Board_RecordAssignment.COLUMNNAME_WEBUI_Board_Lane_ID).append("\n, " + keyColumnNameFQ + " AS " + I_WEBUI_Board_RecordAssignment.COLUMNNAME_Record_ID).append("\n, (").append(documentLookup.getSqlForFetchingDisplayNameByIdExpression(keyColumnNameFQ)).append(") AS card$caption").append("\n, u." + I_AD_User.COLUMNNAME_AD_User_ID + " AS card$user_id").append("\n, u." + I_AD_User.COLUMNNAME_Avatar_ID + " AS card$user_avatar_id").append("\n, u." + I_AD_User.COLUMNNAME_Name + " AS card$user_fullname").append(// all exported document fields
"\n, " + tableAlias + ".*").append("\n FROM (").append(sqlSelectDocument).append(") " + tableAlias).append("\n LEFT OUTER JOIN " + I_AD_User.Table_Name + " u ON (u." + I_AD_User.COLUMNNAME_AD_User_ID + " = " + userIdColumnNameFQ + ")");
sqlExpr.append("\n WHERE ").append("\n " + DB.buildSqlList(keyColumnNameFQ, cardIds, sqlParams));
}
final String sql = sqlExpr.build().evaluate(Evaluatees.empty(), OnVariableNotFound.Fail);
return retrieveCardsFromSql(sql, sqlParams, boardDescriptor);
}
use of org.adempiere.ad.expression.api.IStringExpression in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method buildSqlSelectDocument.
private static final IStringExpression buildSqlSelectDocument(final BoardDescriptor boardDescriptor) {
final String tableName = boardDescriptor.getTableName();
final String tableAlias = boardDescriptor.getTableAlias();
final String keyColumnName = boardDescriptor.getKeyColumnName();
final String userIdColumnName = boardDescriptor.getUserIdColumnName();
final LinkedHashSet<String> sqlSelectValuesList = new LinkedHashSet<>();
sqlSelectValuesList.add(keyColumnName);
sqlSelectValuesList.add(userIdColumnName);
final List<IStringExpression> sqlSelectDisplayNamesList = new ArrayList<>();
boardDescriptor.getCardFields().forEach(cardField -> {
sqlSelectValuesList.addAll(cardField.getSqlSelectValues());
if (cardField.isUsingDisplayColumn()) {
sqlSelectDisplayNamesList.add(cardField.getSqlSelectDisplayValue());
}
});
final CompositeStringExpression.Builder sql = IStringExpression.composer();
sql.append("SELECT ").append("\n").append(tableAlias).append(// Value fields
".*");
if (!sqlSelectDisplayNamesList.isEmpty()) {
// DisplayName fields
sql.append("\n, ").appendAllJoining("\n, ", sqlSelectDisplayNamesList);
}
sql.append("\n FROM (").append("\n SELECT ").append("\n ").append(Joiner.on("\n , ").join(sqlSelectValuesList)).append("\n FROM ").append(tableName).append("\n WHERE IsActive='Y'").append(// FROM
"\n ) " + tableAlias);
return sql.build();
}
use of org.adempiere.ad.expression.api.IStringExpression in project metasfresh-webui-api by metasfresh.
the class SqlViewSelectData method selectByIdBuilder.
@Builder(builderMethodName = "selectById", builderClassName = "SelectByIdBuilder")
private SqlAndParams selectByIdBuilder(@NonNull final ViewEvaluationCtx viewEvalCtx, @NonNull final ViewId viewId, @NonNull final DocumentId rowId) {
final String viewSelectionId = viewId.getViewId();
final IStringExpression sqlSelectById = getSqlSelectById();
final String sql = sqlSelectById.evaluate(viewEvalCtx.toEvaluatee(), OnVariableNotFound.Fail);
return SqlAndParams.of(sql, viewSelectionId, rowId.toInt());
}
use of org.adempiere.ad.expression.api.IStringExpression in project metasfresh-webui-api by metasfresh.
the class SqlViewSelectData method selectByIdPageBuilder.
@Builder(builderMethodName = "selectByPage", builderClassName = "SelectByPageBuilder")
private SqlAndParams selectByIdPageBuilder(@NonNull final ViewEvaluationCtx viewEvalCtx, @NonNull final ViewId viewId, final int firstRowZeroBased, final int pageLength) {
Check.assume(firstRowZeroBased >= 0, "firstRow >= 0 but it was {}", firstRowZeroBased);
Check.assume(pageLength > 0, "pageLength > 0 but it was {}", pageLength);
final String viewSelectionId = viewId.getViewId();
// NOTE: firstRow is 0-based while SeqNo are 1-based
final int firstSeqNo = firstRowZeroBased + 1;
final int lastSeqNo = firstRowZeroBased + pageLength;
final IStringExpression sqlSelectByPage = getSqlSelectByPage();
final String sql = sqlSelectByPage.evaluate(viewEvalCtx.toEvaluatee(), OnVariableNotFound.Fail);
return SqlAndParams.of(sql, viewSelectionId, firstSeqNo, lastSeqNo);
}
Aggregations