Search in sources :

Example 1 with SqlLookupDescriptor

use of de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method retrieveCards.

private List<BoardCard> retrieveCards(final int boardId, final Collection<Integer> onlyCardIds) {
    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  a." + I_WEBUI_Board_RecordAssignment.COLUMNNAME_WEBUI_Board_Lane_ID).append("\n, a." + 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(I_WEBUI_Board_RecordAssignment.Table_Name).append(" a").append("\n INNER JOIN (").append(sqlSelectDocument).append(") " + tableAlias + " ON (" + keyColumnNameFQ + " =a." + I_WEBUI_Board_RecordAssignment.COLUMNNAME_Record_ID + ")").append("\n LEFT OUTER JOIN " + I_AD_User.Table_Name + " u ON (u." + I_AD_User.COLUMNNAME_AD_User_ID + " = " + userIdColumnNameFQ + ")").append("\n WHERE ").append("\n a." + I_WEBUI_Board_RecordAssignment.COLUMNNAME_WEBUI_Board_ID + "=?");
        sqlParams.add(boardId);
        if (!onlyCardIds.isEmpty()) {
            sqlExpr.append("\n AND ").append(DB.buildSqlList(I_WEBUI_Board_RecordAssignment.COLUMNNAME_Record_ID, onlyCardIds, sqlParams));
        }
    }
    final String sql = sqlExpr.build().evaluate(Evaluatees.empty(), OnVariableNotFound.Fail);
    return retrieveCardsFromSql(sql, sqlParams, boardDescriptor);
}
Also used : CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) ArrayList(java.util.ArrayList) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) DateTimeTranslatableString(de.metas.i18n.DateTimeTranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) IStringExpression(org.adempiere.ad.expression.api.IStringExpression)

Example 2 with SqlLookupDescriptor

use of de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor 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);
}
Also used : CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) ArrayList(java.util.ArrayList) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) DateTimeTranslatableString(de.metas.i18n.DateTimeTranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) IStringExpression(org.adempiere.ad.expression.api.IStringExpression)

Aggregations

DateTimeTranslatableString (de.metas.i18n.DateTimeTranslatableString)2 ITranslatableString (de.metas.i18n.ITranslatableString)2 ImmutableTranslatableString (de.metas.i18n.ImmutableTranslatableString)2 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)2 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)2 ArrayList (java.util.ArrayList)2 ToString (lombok.ToString)2 IStringExpression (org.adempiere.ad.expression.api.IStringExpression)2 CompositeStringExpression (org.adempiere.ad.expression.api.impl.CompositeStringExpression)2