Skip to content

Commit

Permalink
Merge pull request #306 from FraunhoferISST/fix/sammmapping_logic
Browse files Browse the repository at this point in the history
Fix: samm mapping logic
  • Loading branch information
tom-rm-meyer-ISST authored Apr 4, 2024
2 parents cc06608 + ffca4e1 commit 620d42b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
8 changes: 4 additions & 4 deletions DEPENDENCIES_BACKEND
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions backend/DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -106,6 +105,7 @@ private ItemStockSamm listToItemStockSamm(List<? extends ItemStock> itemStocks,
allocatedStocksList.add(allocatedStock);
}
}
log.info("CREATED SAMM \n" + samm);
return samm;
}

Expand All @@ -121,13 +121,19 @@ public List<ReportedProductItemStock> itemStockSammToReportedProductItemStock(It
log.warn("Direction should be INBOUND, aborting");
return outputList;
}
var mpr = mprService.findByPartnerAndPartnerCXNumber(partner, matNbrCatenaX);

if (mpr == null) {
// 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());
return outputList;
}

var mpr = mprService.find(material, partner);

for (var position : samm.getPositions()) {
String supplierOrderId = null, customerOrderPositionId = null, customerOrderId = null;
if (position.getOrderPositionReference() != null) {
Expand Down Expand Up @@ -163,11 +169,22 @@ public List<ReportedMaterialItemStock> 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;
}
// 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -91,6 +92,9 @@ public class ItemStockSammMapperTest {
@Mock
private MaterialPartnerRelationService mprService;

@Mock
private MaterialService materialService;

@InjectMocks
private ItemStockSammMapper itemStockSammMapper;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -387,7 +392,8 @@ 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);

var list = itemStockSammMapper.itemStockSammToReportedProductItemStock(SAMM_FROM_CUSTOMER_PARTNER, supplierPartner);
assertNotNull(list);
Expand Down Expand Up @@ -418,8 +424,9 @@ void test_deserializationFromJson() throws Exception {
mpr.setPartnerBuysMaterial(true);
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();

Expand Down

0 comments on commit 620d42b

Please sign in to comment.