Search in sources :

Example 6 with Evaluatee

use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.

the class SqlDocumentQueryBuilder method getSql.

/**
 * @return SQL to fully load the documents matched by this query.
 */
public String getSql(final List<Object> outSqlParams) {
    final Evaluatee evalCtx = getEvaluationContext();
    final IPair<IStringExpression, List<Object>> sqlAndParams = getSqlAndParams();
    final String sql = sqlAndParams.getLeft().evaluate(evalCtx, OnVariableNotFound.Fail);
    final List<Object> sqlParams = sqlAndParams.getRight();
    outSqlParams.addAll(sqlParams);
    return sql;
}
Also used : ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Evaluatee(org.compiere.util.Evaluatee)

Example 7 with Evaluatee

use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.

the class SqlDocumentQueryBuilder method getSqlWhere.

private String getSqlWhere(final List<Object> sqlParams) {
    final IPair<IStringExpression, List<Object>> sqlWhereAndParams = getSqlWhereAndParams();
    final Evaluatee evalCtx = getEvaluationContext();
    final String sqlWhere = sqlWhereAndParams.getLeft().evaluate(evalCtx, OnVariableNotFound.Fail);
    sqlParams.addAll(sqlWhereAndParams.getRight());
    return sqlWhere;
}
Also used : ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Evaluatee(org.compiere.util.Evaluatee)

Example 8 with Evaluatee

use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.

the class SqlDocumentQueryBuilder method getSqlSelectParentId.

/**
 * SQL to fetch the parent's ID based on given child document.
 *
 * @return SELECT KeyColumnName from ParentTableName WHERE ....
 */
public String getSqlSelectParentId(final List<Object> outSqlParams, final DocumentEntityDescriptor parentEntityDescriptor) {
    final String linkColumnName = entityBinding.getLinkColumnName();
    final String parentLinkColumnName = entityBinding.getParentLinkColumnName();
    if (parentLinkColumnName == null || linkColumnName == null) {
        throw new AdempiereException("Selecting parent ID is not possible because this entity does not have a parent link").setParameter("linkColumnName", linkColumnName).setParameter("parentLinkColumnName", parentLinkColumnName).setParameter("entityBinding", entityBinding);
    }
    // 
    // SELECT linkColumnName from current(child) tableName
    final List<Object> sqlSelectLinkColumnNameParams = new ArrayList<>();
    final CompositeStringExpression.Builder sqlSelectLinkColumnName = IStringExpression.composer();
    {
        final IPair<IStringExpression, List<Object>> sqlWhereAndParams = getSqlWhereAndParams();
        final IStringExpression sqlWhere = sqlWhereAndParams.getLeft();
        final List<Object> sqlWhereParams = sqlWhereAndParams.getRight();
        sqlSelectLinkColumnName.append("SELECT " + linkColumnName).append(// NOTE: we need table alias because the where clause is using it
        " FROM " + entityBinding.getTableName() + " " + entityBinding.getTableAlias()).append("\n WHERE ").append(sqlWhere);
        sqlSelectLinkColumnNameParams.addAll(sqlWhereParams);
    }
    // 
    // 
    final String parentKeyColumnName = extractSingleKeyColumnName(parentEntityDescriptor);
    if (Objects.equals(parentKeyColumnName, parentLinkColumnName)) {
        final Evaluatee evalCtx = getEvaluationContext();
        final String sql = sqlSelectLinkColumnName.build().evaluate(evalCtx, OnVariableNotFound.Fail);
        outSqlParams.addAll(sqlSelectLinkColumnNameParams);
        return sql;
    } else {
        final Evaluatee evalCtx = getEvaluationContext();
        final String sql = IStringExpression.composer().append("SELECT " + parentKeyColumnName + " FROM " + parentEntityDescriptor.getTableName()).append("\n WHERE " + parentLinkColumnName + " IN (").append(sqlSelectLinkColumnName).append(")").build().evaluate(evalCtx, OnVariableNotFound.Fail);
        outSqlParams.addAll(sqlSelectLinkColumnNameParams);
        return sql;
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) ArrayList(java.util.ArrayList) IPair(org.adempiere.util.lang.IPair) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Evaluatee(org.compiere.util.Evaluatee)

Example 9 with Evaluatee

use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.

the class DocumentField method getLookupValuesForQuery.

@Override
public LookupValuesList getLookupValuesForQuery(final String query) {
    final LookupDataSource lookupDataSource = getLookupDataSource();
    final Evaluatee ctx = getDocument().asEvaluatee();
    final LookupValuesList values = lookupDataSource.findEntities(ctx, query);
    lookupValuesStaled = false;
    return values;
}
Also used : LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) Evaluatee(org.compiere.util.Evaluatee)

Aggregations

Evaluatee (org.compiere.util.Evaluatee)9 IStringExpression (org.adempiere.ad.expression.api.IStringExpression)4 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)2 LookupDataSource (de.metas.ui.web.window.model.lookup.LookupDataSource)2 Properties (java.util.Properties)1 ILogicExpression (org.adempiere.ad.expression.api.ILogicExpression)1 LogicExpressionResult (org.adempiere.ad.expression.api.LogicExpressionResult)1 CompositeStringExpression (org.adempiere.ad.expression.api.impl.CompositeStringExpression)1 IAttributeValuesProvider (org.adempiere.mm.attributes.spi.IAttributeValuesProvider)1 IPair (org.adempiere.util.lang.IPair)1 NamePair (org.compiere.util.NamePair)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)1 Aggregation (org.elasticsearch.search.aggregations.Aggregation)1 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)1 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)1