Search in sources :

Example 51 with DocumentId

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

the class HighVolumeReadWriteIncludedDocumentsCollection method addChangedDocument.

private final void addChangedDocument(final Document document) {
    final DocumentId documentId = document.getDocumentId();
    _documentsWithChanges.put(documentId, document);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 52 with DocumentId

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

the class SqlHUEditorViewRepository method extractBestBeforeDate.

private static Date extractBestBeforeDate(final HUEditorRowAttributesProvider attributesProvider, final HUEditorRowId rowId) {
    if (attributesProvider == null) {
        return null;
    }
    final DocumentId attributesKey = attributesProvider.createAttributeKey(rowId.getHuId());
    final HUEditorRowAttributes attributes = attributesProvider.getAttributes(rowId.toDocumentId(), attributesKey);
    return attributes.getBestBeforeDate().orElse(null);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 53 with DocumentId

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

the class WEBUI_M_HU_MoveTUsToDirectWarehouse method checkPreconditionsApplicable.

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (!isHUEditorView()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (!selectedRowIds.isSingleDocumentId()) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
    }
    final DocumentId rowId = selectedRowIds.getSingleDocumentId();
    final HUEditorRow huRow = getView().getById(rowId);
    if (huRow.isLU()) {
        if (!huRow.hasIncludedTUs()) {
            return ProcessPreconditionsResolution.rejectWithInternalReason("no TUs");
        }
    } else if (huRow.isTU()) {
    // OK
    } else {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not a LU or TU");
    }
    if (!huRow.isHUStatusActive()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("HUStatus is not Active");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 54 with DocumentId

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

the class WEBUI_M_HU_ReturnTUsToVendor method checkPreconditionsApplicable.

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (!isHUEditorView()) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (!selectedRowIds.isSingleDocumentId()) {
        return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
    }
    final DocumentId rowId = selectedRowIds.getSingleDocumentId();
    final HUEditorRow huRow = getView().getById(rowId);
    if (huRow.isLU()) {
        if (!huRow.hasIncludedTUs()) {
            return ProcessPreconditionsResolution.rejectWithInternalReason("no TUs");
        }
    } else if (huRow.isTU()) {
    // OK
    } else {
        return ProcessPreconditionsResolution.rejectWithInternalReason("not a LU or TU");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 55 with DocumentId

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

the class SqlDocumentsRepository method retriveDocuments.

public OrderedDocumentsList retriveDocuments(final DocumentQuery query, final int limit, final IDocumentChangesCollector changesCollector) {
    logger.debug("Retrieving records: query={}, limit={}", query, limit);
    final DocumentEntityDescriptor entityDescriptor = query.getEntityDescriptor();
    assertThisRepository(entityDescriptor);
    final Document parentDocument = query.getParentDocument();
    final Function<DocumentId, Document> existingDocumentsSupplier = query.getExistingDocumentsSupplier();
    final List<Object> sqlParams = new ArrayList<>();
    final SqlDocumentQueryBuilder sqlBuilder = SqlDocumentQueryBuilder.of(query);
    final String sql = sqlBuilder.getSql(sqlParams);
    final String adLanguage = sqlBuilder.getAD_Language();
    logger.debug("Retrieving records: SQL={} -- {}", sql, sqlParams);
    final int loadLimitWarn = this.loadLimitWarn;
    final int loadLimitMax = this.loadLimitMax;
    int maxRowsToFetch = limit;
    if (maxRowsToFetch <= 0) {
        maxRowsToFetch = loadLimitMax;
    }
    final OrderedDocumentsList documentsCollector = OrderedDocumentsList.newEmpty(query.getOrderBys());
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, ITrx.TRXNAME_ThreadInherited);
        if (maxRowsToFetch > 0) {
            pstmt.setMaxRows(maxRowsToFetch);
        }
        DB.setParameters(pstmt, sqlParams);
        rs = pstmt.executeQuery();
        boolean loadLimitWarnReported = false;
        while (rs.next()) {
            final ResultSetDocumentValuesSupplier documentValuesSupplier = new ResultSetDocumentValuesSupplier(entityDescriptor, adLanguage, rs);
            Document document = null;
            if (existingDocumentsSupplier != null) {
                final DocumentId documentId = documentValuesSupplier.getDocumentId();
                document = existingDocumentsSupplier.apply(documentId);
            }
            if (document == null) {
                document = Document.builder(entityDescriptor).setParentDocument(parentDocument).setChangesCollector(changesCollector).initializeAsExistingRecord(documentValuesSupplier);
            }
            documentsCollector.addDocument(document);
            final int loadCount = documentsCollector.size();
            // Stop if we reached the limit
            if (limit > 0 && loadCount >= limit) {
                break;
            }
            // Stop if we reached the MAXIMUM limit
            if (loadLimitMax > 0 && loadCount >= loadLimitMax) {
                logger.warn("Reached load count MAXIMUM level. Stop loading. \n SQL: {} \n SQL Params: {} \n loadCount: {}", sql, sqlParams, loadCount);
                break;
            }
            // WARN if we reached the Warning limit
            if (!loadLimitWarnReported && loadLimitWarn > 0 && loadCount >= loadLimitWarn) {
                logger.warn("Reached load count Warning level. Continue loading. \n SQL: {} \n SQL Params: {} \n loadCount: {}", sql, sqlParams, loadCount);
                loadLimitWarnReported = true;
            }
        }
    } catch (final SQLException e) {
        throw new DBException(e, sql, sqlParams);
    } finally {
        DB.close(rs, pstmt);
    }
    logger.debug("Retrieved {} records.", documentsCollector.size());
    return documentsCollector;
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) OrderedDocumentsList(de.metas.ui.web.window.model.OrderedDocumentsList) Document(de.metas.ui.web.window.model.Document) ResultSet(java.sql.ResultSet) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

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