use of de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader in project metasfresh-webui-api by metasfresh.
the class SqlViewDataRepository method loadViewRow.
private ViewRow.Builder loadViewRow(final ResultSet rs, final WindowId windowId, final String adLanguage) throws SQLException {
final boolean isRecordMissing = DisplayType.toBoolean(rs.getString(SqlViewSelectData.COLUMNNAME_IsRecordMissing));
if (isRecordMissing) {
return null;
}
final ViewRow.Builder viewRowBuilder = ViewRow.builder(windowId);
final DocumentId parentRowId = keyColumnNamesMap.retrieveRowId(rs, SqlViewSelectData.COLUMNNAME_Paging_Parent_Prefix, false);
if (parentRowId != null) {
viewRowBuilder.setParentRowId(parentRowId);
viewRowBuilder.setType(DefaultRowType.Line);
} else {
viewRowBuilder.setType(DefaultRowType.Row);
}
final DocumentId rowId = retrieveRowId(rs, adLanguage);
if (rowId == null) {
logger.warn("No ID found for current row. Skipping the row.");
return null;
}
viewRowBuilder.setRowId(rowId);
for (final Map.Entry<String, SqlViewRowFieldLoader> fieldNameAndLoader : rowFieldLoaders.entrySet()) {
final String fieldName = fieldNameAndLoader.getKey();
final SqlViewRowFieldLoader fieldLoader = fieldNameAndLoader.getValue();
final Object value = fieldLoader.retrieveValueAsJson(rs, adLanguage);
viewRowBuilder.putFieldValue(fieldName, value);
}
if (rowCustomizer != null) {
rowCustomizer.customizeViewRow(viewRowBuilder);
}
return viewRowBuilder;
}
use of de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader in project metasfresh-webui-api by metasfresh.
the class SqlViewDataRepository method retrieveRowId_MultiKey.
private DocumentId retrieveRowId_MultiKey(final ResultSet rs, final String adLanguage) throws SQLException {
final List<Object> rowIdParts = new ArrayList<>(keyColumnNamesMap.getKeyPartsCount());
boolean onlyNullValues = true;
for (final String keyColumnName : keyColumnNamesMap.getKeyColumnNames()) {
final SqlViewRowFieldLoader fieldLoader = rowFieldLoaders.get(keyColumnName);
// Check.assumeNotNull(fieldLoader, "fieldLoader shall exist for {}", keyColumnName);
final Object rowIdPartObj = fieldLoader.retrieveValueAsJson(rs, adLanguage);
if (JSONNullValue.isNull(rowIdPartObj)) {
rowIdParts.add(null);
}
{
rowIdParts.add(convertToRowIdPart(rowIdPartObj));
onlyNullValues = false;
}
}
if (onlyNullValues) {
return null;
}
return DocumentId.ofComposedKeyParts(rowIdParts);
}
use of de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader in project metasfresh-webui-api by metasfresh.
the class SqlViewDataRepository method retrieveRowId_SingleKey.
private DocumentId retrieveRowId_SingleKey(final ResultSet rs, final String adLanguage) throws SQLException {
final String keyColumnName = keyColumnNamesMap.getSingleKeyColumnName();
final SqlViewRowFieldLoader fieldLoader = rowFieldLoaders.get(keyColumnName);
final Object jsonRowIdObj = fieldLoader.retrieveValueAsJson(rs, adLanguage);
if (JSONNullValue.isNull(jsonRowIdObj)) {
return null;
} else if (jsonRowIdObj instanceof DocumentId) {
return (DocumentId) jsonRowIdObj;
} else if (jsonRowIdObj instanceof Integer) {
return DocumentId.of((Integer) jsonRowIdObj);
} else if (jsonRowIdObj instanceof String) {
return DocumentId.of(jsonRowIdObj.toString());
} else if (jsonRowIdObj instanceof JSONLookupValue) {
// case: usually this is happening when a view's column which is Lookup is also marked as KEY.
final JSONLookupValue jsonLookupValue = (JSONLookupValue) jsonRowIdObj;
return DocumentId.of(jsonLookupValue.getKey());
} else {
throw new IllegalArgumentException("Cannot convert id '" + jsonRowIdObj + "' (" + jsonRowIdObj.getClass() + ") to integer");
}
}
Aggregations