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);
}
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);
}
}
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();
}
Aggregations