Skip to content

Commit

Permalink
fix: improved logic to identify requested material
Browse files Browse the repository at this point in the history
  • Loading branch information
eschrewe committed Aug 4, 2023
1 parent 739c17d commit 539a189
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ public List<PartnerDto> triggerPartnerProductStockUpdateForMaterial(@RequestPara

Material materialEntity = materialService.findByOwnMaterialNumber(ownMaterialNumber);
log.info("Found material: " + (materialEntity != null));
log.info("All materials: " + materialService.findAllMaterials());

List<Partner> allSupplierPartnerEntities = mprService.findAllSuppliersForOwnMaterialNumber(ownMaterialNumber);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,27 @@ public void handleRequest(ProductStockRequest productStockRequest) {
if (searchResult.size() == 1) {
existingMaterial = searchResult.get(0);
} else {
// MaterialNumberCustomer is ambiguous or unknown
// try to use MaterialNumberSupplier
if (productStockRequestForMaterial.getMaterialNumberSupplier() != null) {
existingMaterial = materialService.findByOwnMaterialNumber(productStockRequestForMaterial.getMaterialNumberSupplier());
if (productStockRequestForMaterial.getMaterialNumberCustomer() != null) {
if (productStockRequestForMaterial.getMaterialNumberSupplier() == null
|| productStockRequestForMaterial.getMaterialNumberSupplier().equals(productStockRequestForMaterial.getMaterialNumberCustomer())) {
// possible case: customer did not define his own material number
// and is using the supplier's material number (see CX 0085) as his own material number.
existingMaterial = materialService.findByOwnMaterialNumber(productStockRequestForMaterial.getMaterialNumberCustomer());
} else {
// MaterialNumberCustomer is ambiguous or unknown
// try to use MaterialNumberSupplier
if (productStockRequestForMaterial.getMaterialNumberSupplier() != null) {
existingMaterial = materialService.findByOwnMaterialNumber(productStockRequestForMaterial.getMaterialNumberSupplier());
}
}
}
}
}
}

if (existingMaterial == null) {
MessageContentErrorDto messageContentErrorDto = new MessageContentErrorDto();
messageContentErrorDto.setMaterialNumberCustomer(productStockRequestForMaterial.getMaterialNumberCustomer());
messageContentErrorDto.setError("PURIS-01");
messageContentErrorDto.setMessage("Material is unknown.");
// resultProductStocks.add(messageContentErrorDto);
log.warn(String.format("No Material found for ID Customer %s in request %s",
productStockRequestForMaterial.getMaterialNumberCustomer(),
productStockRequest.getHeader().getRequestId()));
log.warn("Material unknown");
// Material is unknown, error messages in this case currently not supported
continue;
} else {
log.info("Found requested Material: " + existingMaterial.getOwnMaterialNumber());
Expand All @@ -175,11 +178,6 @@ public void handleRequest(ProductStockRequest productStockRequest) {
boolean ordersProducts = mprService.partnerOrdersProduct(existingMaterial, requestingPartner);
log.info("Requesting entity orders this Material? " + ordersProducts);
if (!ordersProducts) {
MessageContentErrorDto messageContentErrorDto = new MessageContentErrorDto();
messageContentErrorDto.setMaterialNumberCustomer(productStockRequestForMaterial.getMaterialNumberCustomer());
messageContentErrorDto.setError("PURIS-02");
messageContentErrorDto.setMessage("Partner is not authorized.");
// resultProductStocks.add(messageContentErrorDto);
log.warn(String.format("Partner %s is not an ordering Partner of Material " +
"found for ID Customer %s in request %s",
requestingPartnerBpnl,
Expand All @@ -196,11 +194,6 @@ public void handleRequest(ProductStockRequest productStockRequest) {

ProductStock productStock = null;
if (productStocks.size() == 0) {
MessageContentErrorDto messageContentErrorDto = new MessageContentErrorDto();
messageContentErrorDto.setMaterialNumberCustomer(productStockRequestForMaterial.getMaterialNumberCustomer());
messageContentErrorDto.setError("PURIS-03");
messageContentErrorDto.setMessage("No Product Stock found.");
// resultProductStocks.add(messageContentErrorDto);
log.warn("No Product Stocks of Material " + productStockRequestForMaterial.getMaterialNumberCustomer()
+ " found for " + productStockRequest.getHeader().getSender());
continue;
Expand Down

0 comments on commit 539a189

Please sign in to comment.