use of de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method createCard.
private BoardCard createCard(final ResultSet rs, final BoardDescriptor boardDescriptor) throws SQLException {
final String adLanguage = null;
final int laneId = rs.getInt(I_WEBUI_Board_RecordAssignment.COLUMNNAME_WEBUI_Board_Lane_ID);
final int recordId = rs.getInt(I_WEBUI_Board_RecordAssignment.COLUMNNAME_Record_ID);
final String caption = rs.getString("card$caption");
final int userId = rs.getInt("card$user_id");
final String userAvatarId = rs.getString("card$user_avatar_id");
final String userFullname = rs.getString("card$user_fullname");
//
// Retrieve card fields
final Map<String, Object> cardValues = new LinkedHashMap<>();
for (final BoardCardFieldDescriptor cardField : boardDescriptor.getCardFields()) {
final BoardFieldLoader fieldLoader = cardField.getFieldLoader();
final Object fieldValue = fieldLoader.retrieveValueAsJson(rs, adLanguage);
if (fieldValue == null) {
continue;
}
cardValues.put(cardField.getFieldName(), fieldValue);
}
final ITranslatableString description = buildDescription(cardValues, boardDescriptor);
return BoardCard.builder().cardId(recordId).laneId(laneId).caption(ImmutableTranslatableString.constant(caption)).description(description).documentPath(DocumentPath.rootDocumentPath(boardDescriptor.getDocumentWindowId(), DocumentId.of(recordId))).user(BoardCardUser.builder().userId(userId).avatarId(userAvatarId).fullname(userFullname).build()).build();
}
use of de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method createBoardCardFieldDescriptor.
private final BoardCardFieldDescriptor createBoardCardFieldDescriptor(final I_WEBUI_Board_CardField cardFieldPO, final DocumentEntityDescriptor documentEntityDescriptor) {
// TODO: might be not so performant, we just need the ColumnName
final String fieldName = cardFieldPO.getAD_Column().getColumnName();
final DocumentFieldDescriptor documentField = documentEntityDescriptor.getField(fieldName);
final SqlDocumentFieldDataBindingDescriptor fieldBinding = documentField.getDataBindingNotNull(SqlDocumentFieldDataBindingDescriptor.class);
final DocumentFieldWidgetType widgetType = documentField.getWidgetType();
final boolean isDisplayColumnAvailable = fieldBinding.isUsingDisplayColumn();
final ImmutableSet<String> sqlSelectValues;
final BoardFieldLoader fieldLoader;
if (widgetType == DocumentFieldWidgetType.Amount && documentEntityDescriptor.hasField(WindowConstants.FIELDNAME_C_Currency_ID)) {
sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue(), WindowConstants.FIELDNAME_C_Currency_ID);
fieldLoader = (rs, adLanguage) -> {
final BigDecimal valueBD = rs.getBigDecimal(fieldBinding.getColumnName());
if (valueBD == null) {
return null;
}
final int currencyId = rs.getInt(WindowConstants.FIELDNAME_C_Currency_ID);
final String currencyCode = Services.get(ICurrencyDAO.class).getISO_Code(Env.getCtx(), currencyId);
if (currencyCode == null) {
return valueBD;
}
return Amount.of(valueBD, currencyCode);
};
} else {
sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue());
final DocumentFieldValueLoader documentFieldValueLoader = fieldBinding.getDocumentFieldValueLoader();
final LookupDescriptor lookupDescriptor = documentField.getLookupDescriptor(LookupScope.DocumentField);
fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, lookupDescriptor);
}
return BoardCardFieldDescriptor.builder().caption(documentField.getCaption()).fieldName(fieldBinding.getColumnName()).widgetType(widgetType).sqlSelectValues(sqlSelectValues).usingDisplayColumn(isDisplayColumnAvailable).sqlSelectDisplayValue(fieldBinding.getSqlSelectDisplayValue()).sqlOrderBy(fieldBinding.getSqlOrderBy()).fieldLoader(fieldLoader).build();
}
Aggregations