Search in sources :

Example 86 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class HUEditorRowId method ofHU.

public static HUEditorRowId ofHU(final int huId, final int topLevelHUId) {
    final int storageProductId = -1;
    // to be computed when needed
    final String json = null;
    // to be computed when needed
    final DocumentId documentId = null;
    return new HUEditorRowId(huId, storageProductId, topLevelHUId, json, documentId);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 87 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class HUEditorRowId method toTopLevelRowId.

public HUEditorRowId toTopLevelRowId() {
    if (isTopLevel()) {
        return this;
    }
    final int huId = getTopLevelHUId();
    final int storageProductId = -1;
    final int topLevelHUId = -1;
    final String json = null;
    final DocumentId documentId = null;
    return new HUEditorRowId(huId, storageProductId, topLevelHUId, json, documentId);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 88 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class SqlViewDataRepository method retrieveRowIdsByPage.

@Override
public List<DocumentId> retrieveRowIdsByPage(final ViewEvaluationCtx viewEvalCtx, final ViewRowIdsOrderedSelection orderedSelection, final int firstRow, final int pageLength) {
    logger.debug("Getting page: firstRow={}, pageLength={} - {}", firstRow, pageLength, this);
    logger.debug("Using: {}", orderedSelection);
    final ViewId viewId = orderedSelection.getViewId();
    final SqlAndParams sqlAndParams = sqlViewSelect.selectRowIdsByPage().viewEvalCtx(viewEvalCtx).viewId(viewId).firstRowZeroBased(firstRow).pageLength(pageLength).build();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sqlAndParams.getSql(), ITrx.TRXNAME_ThreadInherited);
        pstmt.setMaxRows(pageLength);
        DB.setParameters(pstmt, sqlAndParams.getSqlParams());
        rs = pstmt.executeQuery();
        final ImmutableList.Builder<DocumentId> rowIds = ImmutableList.builder();
        // N/A, not important
        final String adLanguage = null;
        while (rs.next()) {
            final DocumentId rowId = retrieveRowId(rs, adLanguage);
            if (rowId == null) {
                continue;
            }
            rowIds.add(rowId);
        }
        return rowIds.build();
    } catch (final SQLException | DBException e) {
        throw DBException.wrapIfNeeded(e).setSqlIfAbsent(sqlAndParams.getSql(), sqlAndParams.getSqlParams());
    } finally {
        DB.close(rs, pstmt);
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) ResultSet(java.sql.ResultSet) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PreparedStatement(java.sql.PreparedStatement)

Example 89 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId 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)

Example 90 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class SqlViewDataRepository method loadViewRows.

private final ImmutableList<IViewRow> loadViewRows(final ResultSet rs, final ViewEvaluationCtx viewEvalCtx, final ViewId viewId, final int limit) throws SQLException {
    final Map<DocumentId, ViewRow.Builder> rowBuilders = new LinkedHashMap<>();
    final Set<DocumentId> rootRowIds = new HashSet<>();
    while (rs.next()) {
        final ViewRow.Builder rowBuilder = loadViewRow(rs, viewId.getWindowId(), viewEvalCtx.getAD_Language());
        if (rowBuilder == null) {
            continue;
        }
        final DocumentId rowId = rowBuilder.getRowId();
        rowBuilders.put(rowId, rowBuilder);
        if (rowBuilder.isRootRow()) {
            rootRowIds.add(rowId);
        }
        // Enforce limit
        if (limit > 0 && limit <= rowBuilders.size()) {
            break;
        }
    }
    // Load lines
    if (hasIncludedRows && !rootRowIds.isEmpty()) {
        retrieveRowLines(viewEvalCtx, viewId, DocumentIdsSelection.of(rootRowIds)).forEach(line -> {
            final DocumentId parentId = ViewRow.cast(line).getParentId();
            final ViewRow.Builder rowBuilder = rowBuilders.get(parentId);
            if (rowBuilder == null) {
                // shall not happen
                return;
            }
            rowBuilder.addIncludedRow(line);
        });
    }
    return rowBuilders.values().stream().map(rowBuilder -> rowBuilder.build()).collect(ImmutableList.toImmutableList());
}
Also used : LogManager(de.metas.logging.LogManager) TypedSqlQueryFilter(org.adempiere.ad.dao.impl.TypedSqlQueryFilter) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider) SqlViewRowFieldBinding(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ITrx(org.adempiere.ad.trx.api.ITrx) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) PlainContextAware(org.adempiere.model.PlainContextAware) SqlViewSelectData(de.metas.ui.web.view.descriptor.SqlViewSelectData) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) SqlDocumentFilterConverters(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverters) DB(org.compiere.util.DB) ImmutableList(com.google.common.collect.ImmutableList) ResultSet(java.sql.ResultSet) Map(java.util.Map) DisplayType(org.compiere.util.DisplayType) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) DocumentQueryOrderBy(de.metas.ui.web.window.model.DocumentQueryOrderBy) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) JSONNullValue(de.metas.ui.web.window.datatypes.json.JSONNullValue) Logger(org.slf4j.Logger) SqlViewKeyColumnNamesMap(de.metas.ui.web.view.descriptor.SqlViewKeyColumnNamesMap) ImmutableMap(com.google.common.collect.ImmutableMap) NonNull(lombok.NonNull) SqlViewRowFieldLoader(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding.SqlViewRowFieldLoader) Set(java.util.Set) MoreObjects(com.google.common.base.MoreObjects) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) WindowId(de.metas.ui.web.window.datatypes.WindowId) PreparedStatement(java.sql.PreparedStatement) IQueryBL(org.adempiere.ad.dao.IQueryBL) DBException(org.adempiere.exceptions.DBException) Services(org.adempiere.util.Services) SqlDocumentFilterConverter(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) DefaultRowType(de.metas.ui.web.view.ViewRow.DefaultRowType) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Aggregations

DocumentId (de.metas.ui.web.window.datatypes.DocumentId)99 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)18 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)14 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 AdempiereException (org.adempiere.exceptions.AdempiereException)11 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)9 ArrayList (java.util.ArrayList)9 Set (java.util.Set)9 NonNull (lombok.NonNull)9 Test (org.junit.Test)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 UserSession (de.metas.ui.web.session.UserSession)8 ViewId (de.metas.ui.web.view.ViewId)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)8 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8