Search in sources :

Example 1 with SqlViewRowFieldLoader

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;
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) SqlViewRowFieldLoader(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SqlViewKeyColumnNamesMap(de.metas.ui.web.view.descriptor.SqlViewKeyColumnNamesMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with SqlViewRowFieldLoader

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);
}
Also used : ArrayList(java.util.ArrayList) SqlViewRowFieldLoader(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader)

Example 3 with SqlViewRowFieldLoader

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");
    }
}
Also used : JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) SqlViewRowFieldLoader(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader)

Aggregations

SqlViewRowFieldLoader (de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader)3 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 SqlViewKeyColumnNamesMap (de.metas.ui.web.view.descriptor.SqlViewKeyColumnNamesMap)1 JSONLookupValue (de.metas.ui.web.window.datatypes.json.JSONLookupValue)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1