Search in sources :

Example 1 with TrackingId

use of de.metas.vendor.gateway.api.availability.TrackingId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowsLoader method handleResultForAsyncAvailabilityCheck_Success.

private void handleResultForAsyncAvailabilityCheck_Success(final PurchaseRowsList rows, final AvailabilityMultiResult availabilityResults) {
    final List<DocumentId> changedRowIds = new ArrayList<>();
    for (final TrackingId trackingId : availabilityResults.getTrackingIds()) {
        final PurchaseRow lineRow = rows.getPurchaseRowByTrackingId(trackingId);
        if (lineRow == null) {
            logger.warn("No row found for {}. Skip updating the row with availability results.", trackingId);
            continue;
        }
        final ImmutableList<PurchaseRow> availabilityResultRows = availabilityResults.getByTrackingId(trackingId).stream().map(availabilityResult -> purchaseRowFactory.availabilityDetailSuccessBuilder().lineRow(lineRow).availabilityResult(availabilityResult).build()).collect(ImmutableList.toImmutableList());
        lineRow.setAvailabilityInfoRows(availabilityResultRows);
        changedRowIds.add(rows.getTopLevelDocumentIdByTrackingId(trackingId, lineRow.getId()));
    }
    notifyViewOfChanges(changedRowIds);
}
Also used : LogManager(de.metas.logging.LogManager) Getter(lombok.Getter) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Env(org.compiere.util.Env) AvailabilityException(de.metas.purchasecandidate.availability.AvailabilityException) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AvailabilityMultiResult(de.metas.purchasecandidate.availability.AvailabilityMultiResult) ImmutableList(com.google.common.collect.ImmutableList) IView(de.metas.ui.web.view.IView) ISysConfigBL(org.adempiere.service.ISysConfigBL) PurchaseDemandWithCandidates(de.metas.purchasecandidate.PurchaseDemandWithCandidates) CoalesceUtil(de.metas.util.lang.CoalesceUtil) Nullable(javax.annotation.Nullable) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) PurchaseDemand(de.metas.purchasecandidate.PurchaseDemand) Properties(java.util.Properties) Logger(org.slf4j.Logger) AvailabilityCheckService(de.metas.purchasecandidate.availability.AvailabilityCheckService) ImmutableMap(com.google.common.collect.ImmutableMap) NonNull(lombok.NonNull) PurchaseCandidatesAvailabilityRequest(de.metas.purchasecandidate.availability.PurchaseCandidatesAvailabilityRequest) TrackingId(de.metas.vendor.gateway.api.availability.TrackingId) Services(de.metas.util.Services) List(java.util.List) Builder(lombok.Builder) ViewChangesCollector(de.metas.ui.web.view.event.ViewChangesCollector) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PurchaseCandidatesGroup(de.metas.purchasecandidate.PurchaseCandidatesGroup) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ArrayList(java.util.ArrayList) TrackingId(de.metas.vendor.gateway.api.availability.TrackingId)

Example 2 with TrackingId

use of de.metas.vendor.gateway.api.availability.TrackingId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowsLoader method handleResultForAsyncAvailabilityCheck_Error.

private void handleResultForAsyncAvailabilityCheck_Error(final PurchaseRowsList rows, final Throwable throwable) {
    if (throwable instanceof AvailabilityException) {
        final AvailabilityException availabilityException = AvailabilityException.cast(throwable);
        final List<DocumentId> changedRowIds = new ArrayList<>();
        for (final AvailabilityException.ErrorItem errorItem : availabilityException.getErrorItems()) {
            final TrackingId trackingId = errorItem.getTrackingId();
            final PurchaseRow lineRow = rows.getPurchaseRowByTrackingId(trackingId);
            if (lineRow == null) {
                logger.warn("No line row found for {}. Skip updating the row with availability errors: {}", trackingId, errorItem);
                continue;
            }
            final PurchaseRow availabilityResultRow = purchaseRowFactory.availabilityDetailErrorBuilder().lineRow(lineRow).throwable(errorItem.getError()).build();
            lineRow.setAvailabilityInfoRow(availabilityResultRow);
            changedRowIds.add(rows.getTopLevelDocumentIdByTrackingId(trackingId, lineRow.getId()));
        }
        notifyViewOfChanges(changedRowIds);
    } else {
        // TODO: display an error-message in the webui
        logger.warn("Got unknown exception while doing availability check. Ignored.", throwable);
    }
}
Also used : AvailabilityException(de.metas.purchasecandidate.availability.AvailabilityException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ArrayList(java.util.ArrayList) TrackingId(de.metas.vendor.gateway.api.availability.TrackingId)

Example 3 with TrackingId

use of de.metas.vendor.gateway.api.availability.TrackingId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowsLoader method load.

@VisibleForTesting
PurchaseRowsList load() {
    final PurchaseRowsList.PurchaseRowsListBuilder resultBuilder = PurchaseRowsList.builder();
    for (final PurchaseDemandWithCandidates demandWithCandidates : purchaseDemandWithCandidatesList) {
        final PurchaseDemand demand = demandWithCandidates.getPurchaseDemand();
        final List<PurchaseRow> purchaseCandidateRows = new ArrayList<>();
        final List<TrackingId> trackingIds = new ArrayList<>();
        for (final PurchaseCandidatesGroup purchaseCandidatesGroup : demandWithCandidates.getPurchaseCandidatesGroups()) {
            final PurchaseRow purchaseCandidateRow = purchaseRowFactory.lineRowBuilder().purchaseCandidatesGroup(purchaseCandidatesGroup).convertAmountsToCurrencyId(demand.getCurrencyIdOrNull()).build();
            purchaseCandidateRows.add(purchaseCandidateRow);
            final TrackingId trackingId = TrackingId.random();
            trackingIds.add(trackingId);
            resultBuilder.purchaseCandidatesGroup(trackingId, purchaseCandidatesGroup);
            resultBuilder.purchaseCandidateRow(trackingId, purchaseCandidateRow);
        }
        final PurchaseRow groupRow = purchaseRowFactory.createGroupRow(demand, purchaseCandidateRows);
        resultBuilder.topLevelRow(groupRow);
        final PurchaseRowId groupRowId = groupRow.getRowId();
        trackingIds.forEach(trackingId -> resultBuilder.trackingIdsByTopLevelRowId(trackingId, groupRowId));
    }
    return resultBuilder.build();
}
Also used : PurchaseDemandWithCandidates(de.metas.purchasecandidate.PurchaseDemandWithCandidates) PurchaseDemand(de.metas.purchasecandidate.PurchaseDemand) ArrayList(java.util.ArrayList) PurchaseCandidatesGroup(de.metas.purchasecandidate.PurchaseCandidatesGroup) TrackingId(de.metas.vendor.gateway.api.availability.TrackingId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

TrackingId (de.metas.vendor.gateway.api.availability.TrackingId)3 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 PurchaseCandidatesGroup (de.metas.purchasecandidate.PurchaseCandidatesGroup)2 PurchaseDemand (de.metas.purchasecandidate.PurchaseDemand)2 PurchaseDemandWithCandidates (de.metas.purchasecandidate.PurchaseDemandWithCandidates)2 AvailabilityException (de.metas.purchasecandidate.availability.AvailabilityException)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 LogManager (de.metas.logging.LogManager)1 AvailabilityCheckService (de.metas.purchasecandidate.availability.AvailabilityCheckService)1 AvailabilityMultiResult (de.metas.purchasecandidate.availability.AvailabilityMultiResult)1 PurchaseCandidatesAvailabilityRequest (de.metas.purchasecandidate.availability.PurchaseCandidatesAvailabilityRequest)1 IView (de.metas.ui.web.view.IView)1 ViewChangesCollector (de.metas.ui.web.view.event.ViewChangesCollector)1 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)1 Services (de.metas.util.Services)1 CoalesceUtil (de.metas.util.lang.CoalesceUtil)1 List (java.util.List)1