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);
}
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);
}
Aggregations