From 6832ccd4f6ddd13a56506b78a0b09406f457f41b Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 2 Apr 2024 11:02:48 +0200 Subject: [PATCH 1/4] fix: samm mapping logic --- .../logic/adapter/ItemStockSammMapper.java | 24 ++++++++++++++----- .../adapter/ItemStockSammMapperTest.java | 17 +++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java index 7bf6d027..bb3097ca 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java @@ -20,20 +20,19 @@ package org.eclipse.tractusx.puris.backend.stock.logic.adapter; -import java.util.HashSet; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.puris.backend.common.domain.model.measurement.ItemQuantityEntity; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialPartnerRelationService; import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialService; import org.eclipse.tractusx.puris.backend.stock.domain.model.*; import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.*; -import org.eclipse.tractusx.puris.backend.common.domain.model.measurement.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; -import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; @@ -106,6 +105,7 @@ private ItemStockSamm listToItemStockSamm(List itemStocks, allocatedStocksList.add(allocatedStock); } } + log.info("CREATED SAMM \n" + samm); return samm; } @@ -121,13 +121,17 @@ public List itemStockSammToReportedProductItemStock(It log.warn("Direction should be INBOUND, aborting"); return outputList; } - var mpr = mprService.findByPartnerAndPartnerCXNumber(partner, matNbrCatenaX); - if (mpr == null) { + Material material = materialService.findByMaterialNumberCx(matNbrCatenaX); + if (material == null) { log.warn("Could not identify materialPartnerRelation with matNbrCatenaX " + matNbrCatenaX + " and partner bpnl " + partner.getBpnl()); return outputList; } + var mpr = mprService.find(material, partner); + + + for (var position : samm.getPositions()) { String supplierOrderId = null, customerOrderPositionId = null, customerOrderId = null; if (position.getOrderPositionReference() != null) { @@ -163,11 +167,19 @@ public List itemStockSammToReportedMaterialItemStock( log.warn("Direction should be OUTBOUND, aborting"); return outputList; } - Material material = materialService.findByMaterialNumberCx(matNbrCatenaX); + var mpr = mprService.findByPartnerAndPartnerCXNumber(partner, matNbrCatenaX); + + if (mpr == null) { + log.warn("Could not identify materialPartnerRelation with matNbrCatenaX " + matNbrCatenaX + " and partner bpnl " + partner.getBpnl()); + return outputList; + } + Material material = mpr.getMaterial(); if (material == null) { log.warn("Could not identify material with CatenaXNbr " + matNbrCatenaX); return outputList; } + + for (var position : samm.getPositions()) { String supplierOrderId = null, customerOrderPositionId = null, customerOrderId = null; if (position.getOrderPositionReference() != null) { diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java index 6d29fb0f..8b1fefed 100644 --- a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java @@ -20,6 +20,8 @@ package org.eclipse.tractusx.puris.backend.stock.logic.adapter; import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.tractusx.puris.backend.common.domain.model.measurement.ItemQuantityEntity; +import org.eclipse.tractusx.puris.backend.common.domain.model.measurement.ItemUnitEnumeration; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.MaterialPartnerRelation; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; @@ -29,7 +31,6 @@ import org.eclipse.tractusx.puris.backend.stock.domain.model.ItemStock; import org.eclipse.tractusx.puris.backend.stock.domain.model.MaterialItemStock; import org.eclipse.tractusx.puris.backend.stock.domain.model.ReportedProductItemStock; -import org.eclipse.tractusx.puris.backend.common.domain.model.measurement.*; import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.*; import org.junit.jupiter.api.*; import org.junit.platform.commons.logging.Logger; @@ -91,6 +92,9 @@ public class ItemStockSammMapperTest { @Mock private MaterialPartnerRelationService mprService; + @Mock + private MaterialService materialService; + @InjectMocks private ItemStockSammMapper itemStockSammMapper; @@ -284,7 +288,8 @@ void map_WhenReportedSammToProductItemStock_ReturnsMultipleReportedProductItemSt // When // Find material based on CX number and mpr - when(mprService.findByPartnerAndPartnerCXNumber(customerPartner, CX_MAT_NUMBER)).thenReturn(mpr); + when(mprService.find(semiconductorProduct, customerPartner)).thenReturn(mpr); + when(materialService.findByMaterialNumberCx(CX_MAT_NUMBER)).thenReturn(semiconductorProduct); // Then we should build 5 reported product stocks: // - no OrderPositionReference (OPR), blocked, 10 pieces, BPNS & BPNA @@ -386,8 +391,9 @@ void test_unmarshalling() { mpr.setPartnerBuysMaterial(true); mpr.setPartnerMaterialNumber(CUSTOMER_MAT_NUMBER); mpr.setPartnerCXNumber(CX_MAT_NUMBER); - - when(mprService.findByPartnerAndPartnerCXNumber(customerPartner, CX_MAT_NUMBER)).thenReturn(mpr); + + when(materialService.findByMaterialNumberCx(CX_MAT_NUMBER)).thenReturn(material); + when(mprService.find(material, customerPartner)).thenReturn(mpr); var list = itemStockSammMapper.itemStockSammToReportedProductItemStock(SAMM_FROM_CUSTOMER_PARTNER, supplierPartner); assertNotNull(list); @@ -419,7 +425,8 @@ void test_deserializationFromJson() throws Exception { mpr.setPartnerMaterialNumber(SUPPLIER_MAT_NUMBER); mpr.setPartnerCXNumber(CX_MAT_NUMBER); - when(mprService.findByPartnerAndPartnerCXNumber(customerPartner, CX_MAT_NUMBER)).thenReturn(mpr); + when(materialService.findByMaterialNumberCx(CX_MAT_NUMBER)).thenReturn(material); + when(mprService.find(material, customerPartner)).thenReturn(mpr); ObjectMapper objectMapper = new ObjectMapper(); From 220b18105a7d0e63367dcbaef712711230a11565 Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 2 Apr 2024 11:06:42 +0200 Subject: [PATCH 2/4] chore: updated backend dependencies --- DEPENDENCIES_BACKEND | 8 ++++---- backend/DEPENDENCIES | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DEPENDENCIES_BACKEND b/DEPENDENCIES_BACKEND index 787a41fa..b8eb1e37 100644 --- a/DEPENDENCIES_BACKEND +++ b/DEPENDENCIES_BACKEND @@ -42,7 +42,7 @@ maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.18, Apach maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined maven/mavencentral/org.aspectj/aspectjweaver/1.9.21, Apache-2.0 AND BSD-3-Clause AND EPL-1.0 AND BSD-3-Clause AND Apache-1.1, approved, #7695 maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161 -maven/mavencentral/org.awaitility/awaitility/4.2.0, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.awaitility/awaitility/4.2.0, Apache-2.0, approved, #14178 maven/mavencentral/org.checkerframework/checker-qual/3.42.0, MIT, approved, clearlydefined maven/mavencentral/org.eclipse.angus/angus-activation/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus maven/mavencentral/org.glassfish.jaxb/jaxb-core/4.0.4, BSD-3-Clause, approved, ee4j.jaxb @@ -54,9 +54,9 @@ maven/mavencentral/org.hibernate.orm/hibernate-core/6.4.1.Final, LGPL-2.1-or-lat maven/mavencentral/org.hibernate.validator/hibernate-validator/8.0.1.Final, Apache-2.0, approved, clearlydefined maven/mavencentral/org.hsqldb/hsqldb/2.7.1, BSD-3-Clause, approved, #12699 maven/mavencentral/org.jboss.logging/jboss-logging/3.5.3.Final, Apache-2.0, approved, #9471 -maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.22, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.9.22, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.9.22, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.22, Apache-2.0, approved, #14186 +maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.9.22, Apache-2.0, approved, #14188 +maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.9.22, Apache-2.0, approved, #14185 maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/1.9.22, Apache-2.0, approved, #11827 maven/mavencentral/org.jetbrains/annotations/13.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.10.1, EPL-2.0, approved, #9714 diff --git a/backend/DEPENDENCIES b/backend/DEPENDENCIES index 787a41fa..b8eb1e37 100644 --- a/backend/DEPENDENCIES +++ b/backend/DEPENDENCIES @@ -42,7 +42,7 @@ maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.18, Apach maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined maven/mavencentral/org.aspectj/aspectjweaver/1.9.21, Apache-2.0 AND BSD-3-Clause AND EPL-1.0 AND BSD-3-Clause AND Apache-1.1, approved, #7695 maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161 -maven/mavencentral/org.awaitility/awaitility/4.2.0, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.awaitility/awaitility/4.2.0, Apache-2.0, approved, #14178 maven/mavencentral/org.checkerframework/checker-qual/3.42.0, MIT, approved, clearlydefined maven/mavencentral/org.eclipse.angus/angus-activation/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus maven/mavencentral/org.glassfish.jaxb/jaxb-core/4.0.4, BSD-3-Clause, approved, ee4j.jaxb @@ -54,9 +54,9 @@ maven/mavencentral/org.hibernate.orm/hibernate-core/6.4.1.Final, LGPL-2.1-or-lat maven/mavencentral/org.hibernate.validator/hibernate-validator/8.0.1.Final, Apache-2.0, approved, clearlydefined maven/mavencentral/org.hsqldb/hsqldb/2.7.1, BSD-3-Clause, approved, #12699 maven/mavencentral/org.jboss.logging/jboss-logging/3.5.3.Final, Apache-2.0, approved, #9471 -maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.22, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.9.22, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.9.22, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.22, Apache-2.0, approved, #14186 +maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.9.22, Apache-2.0, approved, #14188 +maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.9.22, Apache-2.0, approved, #14185 maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/1.9.22, Apache-2.0, approved, #11827 maven/mavencentral/org.jetbrains/annotations/13.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.10.1, EPL-2.0, approved, #9714 From b693ba41fd03d0e49963d0240169d933cbc60213 Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 2 Apr 2024 11:39:33 +0200 Subject: [PATCH 3/4] fix: minor cleanup --- .../backend/stock/logic/adapter/ItemStockSammMapperTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java index 8b1fefed..ab1066de 100644 --- a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java @@ -391,7 +391,8 @@ void test_unmarshalling() { mpr.setPartnerBuysMaterial(true); mpr.setPartnerMaterialNumber(CUSTOMER_MAT_NUMBER); mpr.setPartnerCXNumber(CX_MAT_NUMBER); - + +// when(mprService.findByPartnerAndPartnerCXNumber(customerPartner, CX_MAT_NUMBER)).thenReturn(mpr); when(materialService.findByMaterialNumberCx(CX_MAT_NUMBER)).thenReturn(material); when(mprService.find(material, customerPartner)).thenReturn(mpr); @@ -424,7 +425,7 @@ void test_deserializationFromJson() throws Exception { mpr.setPartnerBuysMaterial(true); mpr.setPartnerMaterialNumber(SUPPLIER_MAT_NUMBER); mpr.setPartnerCXNumber(CX_MAT_NUMBER); - + when(materialService.findByMaterialNumberCx(CX_MAT_NUMBER)).thenReturn(material); when(mprService.find(material, customerPartner)).thenReturn(mpr); From ffca4e19f398ea6a96d99648890de06210ba86d4 Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Wed, 3 Apr 2024 07:58:16 +0200 Subject: [PATCH 4/4] fix: review changes --- .../stock/logic/adapter/ItemStockSammMapper.java | 11 ++++++++--- .../stock/logic/adapter/ItemStockSammMapperTest.java | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java index bb3097ca..05119dbf 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapper.java @@ -122,6 +122,10 @@ public List itemStockSammToReportedProductItemStock(It return outputList; } + // When deserializing a Samm from a customer, who has sent a report on the + // stocks he received from us, the materialGlobalAssetId used in the communication + // was set by us (as the supplying side). Therefore the materialGlobalAssetId in + // the Samm is the one in our Material entity. Material material = materialService.findByMaterialNumberCx(matNbrCatenaX); if (material == null) { log.warn("Could not identify materialPartnerRelation with matNbrCatenaX " + matNbrCatenaX + " and partner bpnl " + partner.getBpnl()); @@ -130,8 +134,6 @@ public List itemStockSammToReportedProductItemStock(It var mpr = mprService.find(material, partner); - - for (var position : samm.getPositions()) { String supplierOrderId = null, customerOrderPositionId = null, customerOrderId = null; if (position.getOrderPositionReference() != null) { @@ -173,13 +175,16 @@ public List itemStockSammToReportedMaterialItemStock( log.warn("Could not identify materialPartnerRelation with matNbrCatenaX " + matNbrCatenaX + " and partner bpnl " + partner.getBpnl()); return outputList; } + // When deserializing a Samm from a supplier, who has sent a report on the + // stocks he has prepared for us, the materialGlobalAssetId used in the communication + // was set by the supplying partner. Therefore the materialGlobalAssetId in + // the Samm is the one in our MaterialPartnerRelation entity with that partner. Material material = mpr.getMaterial(); if (material == null) { log.warn("Could not identify material with CatenaXNbr " + matNbrCatenaX); return outputList; } - for (var position : samm.getPositions()) { String supplierOrderId = null, customerOrderPositionId = null, customerOrderId = null; if (position.getOrderPositionReference() != null) { diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java index ab1066de..a161adad 100644 --- a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ItemStockSammMapperTest.java @@ -392,7 +392,6 @@ void test_unmarshalling() { mpr.setPartnerMaterialNumber(CUSTOMER_MAT_NUMBER); mpr.setPartnerCXNumber(CX_MAT_NUMBER); -// when(mprService.findByPartnerAndPartnerCXNumber(customerPartner, CX_MAT_NUMBER)).thenReturn(mpr); when(materialService.findByMaterialNumberCx(CX_MAT_NUMBER)).thenReturn(material); when(mprService.find(material, customerPartner)).thenReturn(mpr);