diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/DataInjectionCommandLineRunner.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/DataInjectionCommandLineRunner.java index d7a05fdd..8ed6bcfd 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/DataInjectionCommandLineRunner.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/DataInjectionCommandLineRunner.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -151,6 +151,7 @@ private void createOwnPartnerEntity() { private void setupCustomerRole() throws JsonProcessingException { Partner supplierPartner = createAndGetSupplierPartner(); Material semiconductorMaterial = getNewSemiconductorMaterialForCustomer(); + Partner mySelf = partnerService.getOwnPartnerEntity(); semiconductorMaterial = materialService.create(semiconductorMaterial); log.info(String.format("Created material: %s", semiconductorMaterial)); @@ -197,13 +198,25 @@ private void setupCustomerRole() throws JsonProcessingException { semiconductorMaterial, 5, MeasurementUnit.piece, - "BPNS4444444444XX", + mySelf.getSites().first().getBpns(), LocationIdTypeEnum.B_P_N_S, new Date() ); materialStockEntity = materialStockService.create(materialStockEntity); log.info(String.format("Created materialStock: %s", materialStockEntity)); + // Create Product Stock + ProductStock productStockEntity = new ProductStock( + centralControlUnitEntity, + 20, + MeasurementUnit.piece, + mySelf.getSites().first().getBpns(), + LocationIdTypeEnum.B_P_N_S, + new Date(), + nonScenarioCustomer + ); + productStockEntity = productStockService.create(productStockEntity); + log.info(String.format("Created productStock: %s", productStockEntity)); // Create PartnerProductStock semiconductorMaterial = materialService.findByOwnMaterialNumber(semiconductorMaterial.getOwnMaterialNumber()); @@ -222,7 +235,8 @@ private void setupCustomerRole() throws JsonProcessingException { log.info("SAMM-DTO:\n" + objectMapper.writeValueAsString(productStockSammDto)); log.info("Own Street and Number: " + variablesService.getOwnDefaultStreetAndNumber()); - Partner mySelf = partnerService.getOwnPartnerEntity(); + + log.info(mySelf.toString()); var builder = MaterialItemStock.builder(); var materialItemStock = builder.partner(supplierPartner) .material(semiconductorMaterial) @@ -240,7 +254,7 @@ private void setupCustomerRole() throws JsonProcessingException { Address address = new Address("BPNA4444444444DD", "Feldweg 1", "54545 Neustadt", "Germany"); newSite.getAddresses().add(address); mySelf.getSites().add(newSite); - partnerService.update(mySelf); + mySelf = partnerService.update(mySelf); builder = MaterialItemStock.builder(); var otherMaterialItemStock = @@ -272,7 +286,7 @@ private void setupCustomerRole() throws JsonProcessingException { log.info("Created SAMM\n" + node.toPrettyString()); mySelf.getSites().remove(newSite); - partnerService.update(mySelf); + mySelf = partnerService.update(mySelf); ItemStockSamm itemStockSAMM = new ItemStockSamm(); itemStockSAMM.setMaterialNumberSupplier(semiconductorMatNbrSupplier); itemStockSAMM.setMaterialNumberCustomer(semiconductorMatNbrCustomer); @@ -319,6 +333,7 @@ private void setupCustomerRole() throws JsonProcessingException { private void setupSupplierRole() { Partner customerPartner = createAndGetCustomerPartner(); Material semiconductorMaterial = getNewSemiconductorMaterialForSupplier(); + Partner mySelf = partnerService.getOwnPartnerEntity(); semiconductorMaterial = materialService.create(semiconductorMaterial); log.info(String.format("Created product: %s", semiconductorMaterial)); @@ -344,7 +359,7 @@ private void setupSupplierRole() { semiconductorMaterial, 20, MeasurementUnit.piece, - "BPNS1234567890ZZ", + mySelf.getSites().first().getBpns(), LocationIdTypeEnum.B_P_N_S, new Date(), customerPartner @@ -419,6 +434,8 @@ private Partner createAndGetNonScenarioCustomer() { "Non-Scenario Customer", "http://nonscenario-customer.com/api/v1/dsp", "BPNL2222222222RR", + "BPNS2222222222XY", + "Non Scneario Site", "BPNA2222222222XZ", "Fichtenweg 23", "65432 Waldhausen", diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerServiceImpl.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerServiceImpl.java index da0ca5e7..4cbf1447 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerServiceImpl.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerServiceImpl.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -168,11 +168,7 @@ public List findAllCustomerPartnersForMaterialId(String ownMaterialNumb @Override public List findAllSupplierPartnersForMaterialId(String ownMaterialNumber) { - var searchResult = materialRepository.findById(ownMaterialNumber); - if (searchResult.isPresent()) { - return mprService.findAllSuppliersForMaterial(searchResult.get()); - } - return List.of(); + return mprService.findAllSuppliersForOwnMaterialNumber(ownMaterialNumber); } @Override diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewController.java index 58795d57..eb95f10b 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewController.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -28,8 +28,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.puris.backend.common.api.logic.service.VariablesService; 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.domain.model.Site; import org.eclipse.tractusx.puris.backend.masterdata.logic.dto.PartnerDto; import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialPartnerRelationService; import org.eclipse.tractusx.puris.backend.masterdata.logic.service.MaterialService; @@ -37,10 +39,9 @@ import org.eclipse.tractusx.puris.backend.stock.domain.model.MaterialStock; import org.eclipse.tractusx.puris.backend.stock.domain.model.PartnerProductStock; import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStock; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.FrontendMaterialDto; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.MaterialStockDto; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.PartnerProductStockDto; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.ProductStockDto; +import org.eclipse.tractusx.puris.backend.stock.domain.model.Stock; +import org.eclipse.tractusx.puris.backend.stock.logic.dto.*; +import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum; import org.eclipse.tractusx.puris.backend.stock.logic.service.MaterialStockService; import org.eclipse.tractusx.puris.backend.stock.logic.service.PartnerProductStockService; import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockRequestApiService; @@ -54,6 +55,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -90,6 +92,9 @@ public class StockViewController { @Autowired private ModelMapper modelMapper; + @Autowired + private VariablesService variablesService; + private final Pattern materialPattern = Pattern.compile(Material.MATERIAL_NUMBER_REGEX); @GetMapping("materials") @@ -166,6 +171,7 @@ public ProductStockDto updateProductStocks(@RequestBody ProductStockDto productS } existingProductStock.setQuantity(productStockDto.getQuantity()); + existingProductStock.setMeasurementUnit(productStockDto.getMeasurementUnit()); existingProductStock.setLastUpdatedOn(new Date()); existingProductStock = productStockService.update(existingProductStock); @@ -180,6 +186,10 @@ private ProductStockDto convertToDto(ProductStock entity) { var materialPartnerRelation = mprService.find(entity.getMaterial().getOwnMaterialNumber(), entity.getAllocatedToCustomerPartner().getUuid()); dto.getMaterial().setMaterialNumberCustomer(materialPartnerRelation.getPartnerMaterialNumber()); + + Partner myself = partnerService.getOwnPartnerEntity(); + setBpnaAndBpnsOnStockDtoBasedOnPartner(entity, dto, myself); + return dto; } @@ -187,6 +197,29 @@ private ProductStock convertToEntity(ProductStockDto dto) { ProductStock productStock = modelMapper.map(dto, ProductStock.class); Material material = materialService.findByOwnMaterialNumber(dto.getMaterial().getMaterialNumberSupplier()); productStock.setMaterial(material); + + PartnerDto allocationPartner = dto.getAllocatedToPartner(); + + Partner existingPartner; + if(allocationPartner.getUuid() != null){ + + existingPartner = partnerService.findByUuid(allocationPartner.getUuid()); + }else{ + existingPartner = partnerService.findByBpnl(allocationPartner.getBpnl()); + } + + if (existingPartner == null){ + throw new IllegalStateException(String.format( + "Partner for uuid %s and bpnl %s could not be found", + allocationPartner.getUuid(), + allocationPartner.getBpnl()) + ); + } + productStock.setAllocatedToCustomerPartner(existingPartner); + + // always set to bpna and find corresponding site + productStock.setLocationId(dto.getStockLocationBpna()); + productStock.setLocationIdType(LocationIdTypeEnum.B_P_N_A); return productStock; } @@ -225,6 +258,7 @@ public MaterialStockDto updateMaterialStocks(@RequestBody MaterialStockDto mater } existingMaterialStock.setQuantity(materialStockDto.getQuantity()); + existingMaterialStock.setMeasurementUnit(materialStockDto.getMeasurementUnit()); existingMaterialStock.setLastUpdatedOn(new Date()); existingMaterialStock = materialStockService.update(existingMaterialStock); @@ -236,13 +270,26 @@ private MaterialStockDto convertToDto(MaterialStock entity) { MaterialStockDto dto = modelMapper.map(entity, MaterialStockDto.class); dto.getMaterial().setMaterialNumberCx(entity.getMaterial().getMaterialNumberCx()); dto.getMaterial().setMaterialNumberCustomer(entity.getMaterial().getOwnMaterialNumber()); + + dto.setStockLocationBpns(variablesService.getOwnDefaultBpns()); + dto.setStockLocationBpna(variablesService.getOwnDefaultBpna()); + log.info(dto.toString()); + + Partner myself = partnerService.getOwnPartnerEntity(); + setBpnaAndBpnsOnStockDtoBasedOnPartner(entity, dto, myself); + return dto; } private MaterialStock convertToEntity(MaterialStockDto dto) { - MaterialStock stock = modelMapper.map(dto, MaterialStock.class); - stock.getMaterial().setOwnMaterialNumber(dto.getMaterial().getMaterialNumberCustomer()); - return stock; + MaterialStock materialStock = modelMapper.map(dto, MaterialStock.class); + materialStock.getMaterial().setOwnMaterialNumber(dto.getMaterial().getMaterialNumberCustomer()); + + // always set to bpna and find corresponding site + materialStock.setLocationId(dto.getStockLocationBpna()); + materialStock.setLocationIdType(LocationIdTypeEnum.B_P_N_A); + + return materialStock; } @GetMapping("partner-product-stocks") @@ -270,9 +317,39 @@ private PartnerProductStockDto convertToDto(PartnerProductStock entity) { entity.getSupplierPartner().getUuid()); dto.getMaterial().setMaterialNumberSupplier(materialPartnerRelation.getPartnerMaterialNumber()); + Partner customerPartner = partnerService.findByBpnl(entity.getSupplierPartner().getBpnl()); + setBpnaAndBpnsOnStockDtoBasedOnPartner(entity, dto, customerPartner); + return dto; } + /** + * helper method to lookup and set the corresponding bpna or bpns on dto + * + * @param entity Stock to set the data from + * @param dto StockDto to set the data on + * @param partner holding the stock + */ + private void setBpnaAndBpnsOnStockDtoBasedOnPartner(Stock entity, StockDto dto, Partner partner){ + if (entity.getLocationIdType() == LocationIdTypeEnum.B_P_N_A){ + Optional siteForAddress = partner.getSites() + .stream().filter(site -> site.getAddresses().stream().anyMatch(addr -> addr.getBpna().equals(entity.getLocationId()))).findFirst(); + + if (!siteForAddress.isEmpty()){ + dto.setStockLocationBpns(siteForAddress.get().getBpns()); + dto.setStockLocationBpna(entity.getLocationId()); + } + }else{ + dto.setStockLocationBpns(entity.getLocationId()); + Optional siteOfPartner = partner.getSites().stream().filter(site -> site.getBpns().equals(entity.getLocationId())).findFirst(); + if(!siteOfPartner.isEmpty()){ + dto.setStockLocationBpna(siteOfPartner.get().getAddresses().first().getBpna()); + }else{ + throw new IllegalStateException(String.format("Partner %s with Site %s has no Address.", partner.getBpnl(), siteOfPartner.get().getBpns())); + } + } + } + @GetMapping("customer") @Operation(description = "Returns a list of all Partners that are ordering the given material") @ApiResponses(value = { @@ -288,6 +365,21 @@ public ResponseEntity> getCustomerPartnersOrderingMaterial(@Req .collect(Collectors.toList())); } + @GetMapping("supplier") + @Operation(description = "Returns a list of all Partners that are supplying the given material") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "400", description = "Invalid parameter") + }) + public ResponseEntity> getSupplierPartnersSupplyingMaterial(@RequestParam String ownMaterialNumber) { + if(!materialPattern.matcher(ownMaterialNumber).matches()) { + return new ResponseEntity<>(HttpStatusCode.valueOf(400)); + } + return ResponseEntity.ok(partnerService.findAllSupplierPartnersForMaterialId(ownMaterialNumber).stream() + .map(this::convertToDto) + .collect(Collectors.toList())); + } + @GetMapping("update-partner-product-stock") @Operation(description = "For the given material, all known suppliers will be requested to report their" + "current product-stocks. The response body contains a list of those supplier partners that were sent a request." + diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/MaterialStockDto.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/MaterialStockDto.java index ac4d3623..e0a52ef0 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/MaterialStockDto.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/MaterialStockDto.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -27,7 +27,6 @@ import org.eclipse.tractusx.puris.backend.masterdata.logic.dto.MaterialDto; import org.eclipse.tractusx.puris.backend.stock.domain.model.datatype.DT_StockTypeEnum; import org.eclipse.tractusx.puris.backend.stock.domain.model.measurement.MeasurementUnit; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum; import java.util.Date; @@ -36,9 +35,9 @@ @AllArgsConstructor public class MaterialStockDto extends StockDto { - public MaterialStockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String locationId, - LocationIdTypeEnum locationIdType, Date lastUpdatedOn) { - super(material, quantity, measurementUnit, locationId, locationIdType, lastUpdatedOn); + public MaterialStockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String stockLocationBpns, + String stockLocationBpna, Date lastUpdatedOn) { + super(material, quantity, measurementUnit, stockLocationBpns, stockLocationBpna, lastUpdatedOn); this.setType(DT_StockTypeEnum.MATERIAL); } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/PartnerProductStockDto.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/PartnerProductStockDto.java index 6dbee3d9..7d5a20d1 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/PartnerProductStockDto.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/PartnerProductStockDto.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -28,7 +28,6 @@ import org.eclipse.tractusx.puris.backend.masterdata.logic.dto.PartnerDto; import org.eclipse.tractusx.puris.backend.stock.domain.model.datatype.DT_StockTypeEnum; import org.eclipse.tractusx.puris.backend.stock.domain.model.measurement.MeasurementUnit; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum; import java.util.Date; @@ -39,9 +38,9 @@ public class PartnerProductStockDto extends StockDto { private PartnerDto supplierPartner; - public PartnerProductStockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String locationId, - LocationIdTypeEnum locationIdType, PartnerDto supplierPartner, Date lastUpdatedOn) { - super(material, quantity, measurementUnit, locationId, locationIdType, lastUpdatedOn); + public PartnerProductStockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String stockLocationBpns, + String stockLocationBpna, PartnerDto supplierPartner, Date lastUpdatedOn) { + super(material, quantity, measurementUnit, stockLocationBpns, stockLocationBpna, lastUpdatedOn); this.setType(DT_StockTypeEnum.PRODUCT); this.supplierPartner = supplierPartner; } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/ProductStockDto.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/ProductStockDto.java index cae6f65d..7c8716a3 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/ProductStockDto.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/ProductStockDto.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -29,7 +29,6 @@ import org.eclipse.tractusx.puris.backend.masterdata.logic.dto.PartnerDto; import org.eclipse.tractusx.puris.backend.stock.domain.model.datatype.DT_StockTypeEnum; import org.eclipse.tractusx.puris.backend.stock.domain.model.measurement.MeasurementUnit; -import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum; import java.util.Date; @@ -39,12 +38,12 @@ @ToString(callSuper = true) public class ProductStockDto extends StockDto { - private PartnerDto allocatedToCustomerPartner; + private PartnerDto allocatedToPartner; - public ProductStockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String atSiteBpns, - LocationIdTypeEnum locationIdType, PartnerDto allocatedToCustomerPartner, Date lastUpdatedOn) { - super(material, quantity, measurementUnit, atSiteBpns, locationIdType, lastUpdatedOn); + public ProductStockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String stockLocationBpns, + String stockLocationBpna, PartnerDto allocatedToPartner, Date lastUpdatedOn) { + super(material, quantity, measurementUnit, stockLocationBpns, stockLocationBpna, lastUpdatedOn); this.setType(DT_StockTypeEnum.PRODUCT); - this.allocatedToCustomerPartner = allocatedToCustomerPartner; + this.allocatedToPartner = allocatedToPartner; } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/StockDto.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/StockDto.java index 09fa6747..99d33471 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/StockDto.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/dto/StockDto.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. * (represented by Fraunhofer ISST) - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -50,7 +50,9 @@ public abstract class StockDto implements Serializable { private MeasurementUnit measurementUnit; - private String locationId; + private String stockLocationBpns; + + private String stockLocationBpna; private LocationIdTypeEnum locationIdType; @@ -58,13 +60,13 @@ public abstract class StockDto implements Serializable { private Date lastUpdatedOn; - public StockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String locationId, - LocationIdTypeEnum locationIdType, Date lastUpdatedOn) { + public StockDto(MaterialDto material, double quantity, MeasurementUnit measurementUnit, String stockLocationBpns, + String stockLocationBpna, Date lastUpdatedOn) { this.material = material; this.quantity = quantity; this.measurementUnit = measurementUnit; - this.locationId = locationId; - this.locationIdType = locationIdType; + this.stockLocationBpns = stockLocationBpns; + this.stockLocationBpna = stockLocationBpna; this.lastUpdatedOn = lastUpdatedOn; } } diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/MaterialRepositoryTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/MaterialRepositoryTest.java index 6960f0a9..94bc4516 100644 --- a/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/MaterialRepositoryTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/MaterialRepositoryTest.java @@ -1,6 +1,6 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.List; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; @@ -38,12 +39,12 @@ public class MaterialRepositoryTest { @Test void findAllByMaterialFlagTrue_ReturnsListOfMaterials() { // Given - Material material1 = new Material(true, false, "MNR-123", "uuid-value", "Test Material 1", new HashSet<>()); + Material material1 = new Material(true, false, "MNR-123", UUID.randomUUID().toString(), "Test Material 1", new HashSet<>()); - Material material2 = new Material(true, false, "MNR-234", "uuid-value-2", "Test Material 2", new HashSet<>()); + Material material2 = new Material(true, false, "MNR-234", UUID.randomUUID().toString(), "Test Material 2", new HashSet<>()); // would be more realistic with relationship, but didn't add it here as we just want to test the MaterialRepo - Material product = new Material(false, true, "MNR-456", "uuid-value-2", "Test Product 1", new HashSet<>()); + Material product = new Material(false, true, "MNR-456", UUID.randomUUID().toString(), "Test Product 1", new HashSet<>()); materialRepository.save(material1); materialRepository.save(material2); diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepositoryTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepositoryTest.java new file mode 100644 index 00000000..4facc57c --- /dev/null +++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepositoryTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 Volkswagen AG + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.eclipse.tractusx.puris.backend.masterdata.domain.repository; + +import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; +import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Site; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DataJpaTest +public class PartnerRepositoryTest { + + @Autowired + private PartnerRepository partnerRepository; + + @Test + void addSite_WhenSitesArePresent_ReturnsAllSites() { + // Given + Partner supplierPartnerEntity = new Partner( + "Scenario Supplier", + "http://supplier-control-plane:9184/api/v1/dsp", + "BPNL1234567890ZZ", + "BPNS1234567890ZZ", + "Konzernzentrale Dudelsdorf", + "BPNA1234567890AA", + "Heinrich-Supplier-Straße 1", + "77785 Dudelsdorf", + "Germany" + ); + + Partner createdSupplierPartner = partnerRepository.save(supplierPartnerEntity); + + assertEquals(1, createdSupplierPartner.getSites().size()); + + Site newSite = new Site( + "BPNS1234567890SS", + "Added Site", + "BPNA1234567890AA", + "Valid Str. 1", + "1000 Bruxelles", + "Belgium" + ); + + createdSupplierPartner.getSites().add(newSite); + Partner updatedSupplierPartner = partnerRepository.save(createdSupplierPartner); + + assertEquals(2, updatedSupplierPartner.getSites().size()); + } +} diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewControllerTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewControllerTest.java index 5ff4fc9f..57a281b6 100644 --- a/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewControllerTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/stock/controller/StockViewControllerTest.java @@ -1,6 +1,6 @@ /* - * Copyright (c) 2023 Volkswagen AG - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Volkswagen AG + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.tractusx.puris.backend.common.api.logic.service.VariablesService; import org.eclipse.tractusx.puris.backend.common.security.SecurityConfig; import org.eclipse.tractusx.puris.backend.common.security.annotation.WithMockApiKey; import org.eclipse.tractusx.puris.backend.common.security.logic.ApiKeyAuthenticationProvider; @@ -83,6 +84,9 @@ class StockViewControllerTest { @MockBean private ModelMapper modelMapper; + @MockBean + private VariablesService variablesService; + @Test @WithMockApiKey void getMaterials_GivenTwoMaterials_ReturnsListOfMaterials() throws Exception{ diff --git a/charts/puris/README.md b/charts/puris/README.md index 27da50fa..756fb8b2 100644 --- a/charts/puris/README.md +++ b/charts/puris/README.md @@ -134,12 +134,14 @@ $ helm install puris --namespace puris --create-namespace . | frontend.podSecurityContext | object | `{}` | Added security contexts for a pod | | frontend.puris.appName | string | `"PURIS"` | The name of the app displayed in the frontend | | frontend.puris.baseUrl | string | `"your-backend-host-address.com"` | The base URL for the backend base URL without further endpoints | -| frontend.puris.endpointCustomer | string | `"stockView/customer?ownMaterialNumber="` | The endpoint for the customers own material number for the stock view | +| frontend.puris.endpointCustomer | string | `"stockView/customer?ownMaterialNumber="` | The endpoint for the customers who buy a material identified via the own material number for the stock view | | frontend.puris.endpointMaterialStocks | string | `"stockView/material-stocks"` | The endpoint for material stocks for the stock view | | frontend.puris.endpointMaterials | string | `"stockView/materials"` | The endpoint for materials for the stock view | +| frontend.puris.endpointPartnerOwnSites | string | `"partners/ownSites"` | The endpoint for the partners BPNS | | frontend.puris.endpointPartnerProductStocks | string | `"stockView/partner-product-stocks?ownMaterialNumber="` | The endpoint for the partners product stocks and their material numbers for the stock view | | frontend.puris.endpointProductStocks | string | `"stockView/product-stocks"` | The endpoint for product stocks for the stock view | | frontend.puris.endpointProducts | string | `"stockView/products"` | The endpoint for products for the stock view | +| frontend.puris.endpointSupplier | string | `"stockView/supplier?ownMaterialNumber="` | The endpoint for the suppliers who buy a material identified via the own material number for the stock view | | frontend.puris.endpointUpdatePartnerProductStocks | string | `"stockView/update-partner-product-stock?ownMaterialNumber="` | The endpoint for updating the partners product stocks and their material numbers for the stock view | | frontend.puris.keycloak.clientId | string | `"appXYZ"` | Name of the client which is used for the application. | | frontend.puris.keycloak.disabled | bool | `true` | Disable the Keycloak integration. | diff --git a/charts/puris/templates/frontend-deployment.yaml b/charts/puris/templates/frontend-deployment.yaml index d0afc1c9..81cc51f3 100644 --- a/charts/puris/templates/frontend-deployment.yaml +++ b/charts/puris/templates/frontend-deployment.yaml @@ -48,10 +48,14 @@ spec: value: "{{ .Values.frontend.puris.endpointProductStocks }}" - name: ENDPOINT_CUSTOMER value: "{{ .Values.frontend.puris.endpointCustomer }}" + - name: ENDPOINT_SUPPLIER + value: "{{ .Values.frontend.puris.endpointSupplier }}" - name: ENDPOINT_PARTNER_PRODUCT_STOCKS value: "{{ .Values.frontend.puris.endpointPartnerProductStocks }}" - name: ENDPOINT_UPDATE_PARTNER_PRODUCT_STOCK value: "{{ .Values.frontend.puris.endpointUpdatePartnerProductStocks }}" + - name: ENDPOINT_PARTNER_OWNSITES + value: "{{ .Values.frontend.puris.endpointPartnerOwnSites }}" - name: BACKEND_API_KEY value: "test" - name: IDP_DISABLE diff --git a/charts/puris/values.yaml b/charts/puris/values.yaml index f5d77b67..f008e6c8 100644 --- a/charts/puris/values.yaml +++ b/charts/puris/values.yaml @@ -181,12 +181,16 @@ frontend: endpointMaterialStocks: stockView/material-stocks # -- The endpoint for product stocks for the stock view endpointProductStocks: stockView/product-stocks - # -- The endpoint for the customers own material number for the stock view + # -- The endpoint for the customers who buy a material identified via the own material number for the stock view endpointCustomer: stockView/customer?ownMaterialNumber= + # -- The endpoint for the suppliers who buy a material identified via the own material number for the stock view + endpointSupplier: stockView/supplier?ownMaterialNumber= # -- The endpoint for the partners product stocks and their material numbers for the stock view endpointPartnerProductStocks: stockView/partner-product-stocks?ownMaterialNumber= # -- The endpoint for updating the partners product stocks and their material numbers for the stock view endpointUpdatePartnerProductStocks: stockView/update-partner-product-stock?ownMaterialNumber= + # -- The endpoint for the partners BPNS + endpointPartnerOwnSites: partners/ownSites keycloak: # -- Disable the Keycloak integration. disabled: true diff --git a/frontend/.env b/frontend/.env index 7b19ccc1..bdd0b190 100644 --- a/frontend/.env +++ b/frontend/.env @@ -7,8 +7,10 @@ VITE_ENDPOINT_PRODUCTS=stockView/products VITE_ENDPOINT_MATERIAL_STOCKS=stockView/material-stocks VITE_ENDPOINT_PRODUCT_STOCKS=stockView/product-stocks VITE_ENDPOINT_CUSTOMER=stockView/customer?ownMaterialNumber= +VITE_ENDPOINT_SUPPLIER=stockView/supplier?ownMaterialNumber= VITE_ENDPOINT_PARTNER_PRODUCT_STOCKS=stockView/partner-product-stocks?ownMaterialNumber= VITE_ENDPOINT_UPDATE_PARTNER_PRODUCT_STOCK=stockView/update-partner-product-stock?ownMaterialNumber= +VITE_ENDPOINT_PARTNER_OWNSITES=partners/ownSites VITE_IDP_DISABLE=true VITE_IDP_URL=http://localhost:10081/ diff --git a/frontend/.env.dockerbuild b/frontend/.env.dockerbuild index d2bf8ead..d61b0a84 100644 --- a/frontend/.env.dockerbuild +++ b/frontend/.env.dockerbuild @@ -6,8 +6,10 @@ VITE_ENDPOINT_PRODUCTS=\$ENDPOINT_PRODUCTS VITE_ENDPOINT_MATERIAL_STOCKS=\$ENDPOINT_MATERIAL_STOCKS VITE_ENDPOINT_PRODUCT_STOCKS=\$ENDPOINT_PRODUCT_STOCKS VITE_ENDPOINT_CUSTOMER=\$ENDPOINT_CUSTOMER +VITE_ENDPOINT_SUPPLIER=\$ENDPOINT_SUPPLIER VITE_ENDPOINT_PARTNER_PRODUCT_STOCKS=\$ENDPOINT_PARTNER_PRODUCT_STOCKS VITE_ENDPOINT_UPDATE_PARTNER_PRODUCT_STOCK=\$ENDPOINT_UPDATE_PARTNER_PRODUCT_STOCK +VITE_ENDPOINT_PARTNER_OWNSITES=\$ENDPOINT_PARTNER_OWNSITES VITE_IDP_DISABLE=\$IDP_DISABLE VITE_IDP_URL=\$IDP_URL diff --git a/frontend/src/assets/stockViewUom.json b/frontend/src/assets/stockViewUom.json new file mode 100644 index 00000000..e17ba29a --- /dev/null +++ b/frontend/src/assets/stockViewUom.json @@ -0,0 +1,142 @@ +[ + { + "key":"unit:piece", + "value":"pieces" + }, + { + "key":"unit:set", + "value":"sets" + }, + { + "key":"unit:pair", + "value":"pairs" + }, + { + "key":"unit:page", + "value":"pages" + }, + { + "key":"unit:cycle", + "value":"cycles" + }, + { + "key":"unit:kilowattHour", + "value":"kwh" + }, + { + "key":"unit:gram", + "value":"g" + }, + { + "key":"unit:kilogram", + "value":"kg" + }, + { + "key":"unit:tonneMetricTon", + "value":"metric tons" + }, + { + "key":"unit:tonUsOrShortTonUkorus", + "value":"US short tons" + }, + { + "key":"unit:ounceAvoirdupois", + "value":"ounces avoidupois" + }, + { + "key":"unit:pound", + "value":"pounds" + }, + { + "key":"unit:metre", + "value":"m" + }, + { + "key":"unit:centimetre", + "value":"cm" + }, + { + "key":"unit:kilometre", + "value":"km" + }, + { + "key":"unit:inch", + "value":"inch" + }, + { + "key":"unit:foot", + "value":"foot" + }, + { + "key":"unit:yard", + "value":"yard" + }, + { + "key":"unit:squareCentimetre", + "value":"cm²" + }, + { + "key":"unit:squareMetre", + "value":"m²" + }, + { + "key":"unit:squareInch", + "value":"inch²" + }, + { + "key":"unit:squareFoot", + "value":"foot²" + }, + { + "key":"unit:squareYard", + "value":"yard²" + }, + { + "key":"unit:cubicCentimetre", + "value":"cm³" + }, + { + "key":"unit:cubicMetre", + "value":"m³" + }, + { + "key":"unit:cubicInch", + "value":"inch³" + }, + { + "key":"unit:cubicFoot", + "value":"foot³" + }, + { + "key":"unit:cubicYard", + "value":"yard³" + }, + { + "key":"unit:litre", + "value":"l" + }, + { + "key":"unit:millilitre", + "value":"ml" + }, + { + "key":"unit:hectolitre", + "value":"hectolitre" + }, + { + "key":"unit:secondUnitOfTime", + "value":"seconds" + }, + { + "key":"unit:minuteUnitOfTime", + "value":"minutes" + }, + { + "key":"unit:hourUnitOfTime", + "value":"hours" + }, + { + "key":"unit:day", + "value":"day" + } +] diff --git a/frontend/src/components/DisableableSelectInput.vue b/frontend/src/components/DisableableSelectInput.vue new file mode 100644 index 00000000..34dfea9c --- /dev/null +++ b/frontend/src/components/DisableableSelectInput.vue @@ -0,0 +1,75 @@ + + + + + + diff --git a/frontend/src/config.json b/frontend/src/config.json index ed3a5675..962130ba 100644 --- a/frontend/src/config.json +++ b/frontend/src/config.json @@ -7,8 +7,10 @@ "ENDPOINT_MATERIAL_STOCKS": "$ENDPOINT_MATERIAL_STOCKS", "ENDPOINT_PRODUCT_STOCKS": "$ENDPOINT_PRODUCT_STOCKS", "ENDPOINT_CUSTOMER": "$ENDPOINT_CUSTOMER", + "ENDPOINT_SUPPLIER": "$ENDPOINT_SUPPLIER", "ENDPOINT_PARTNER_PRODUCT_STOCKS": "$ENDPOINT_PARTNER_PRODUCT_STOCKS", "ENDPOINT_UPDATE_PARTNER_PRODUCT_STOCK":" $ENDPOINT_UPDATE_PARTNER_PRODUCT_STOCK", + "ENDPOINT_PARTNER_OWNSITES": "$ENDPOINT_PARTNER_OWNSITES", "IDP_DISABLE": "$IDP_DISABLE", "IDP_URL": "$IDP_URL", "IDP_REALM": "$IDP_REALM", diff --git a/frontend/src/services/UnitOfMeasureUtils.js b/frontend/src/services/UnitOfMeasureUtils.js new file mode 100644 index 00000000..1d21aa7f --- /dev/null +++ b/frontend/src/services/UnitOfMeasureUtils.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Volkswagen AG + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +import stockViewUom from "@/assets/stockViewUom.json"; + +const findUomValueByKey = (key) => { + for (let i = 0; i < stockViewUom.length; i++) { + if (stockViewUom[i].key === key) { + return stockViewUom[i].value; + } + } + return null; // Return null if the key is not found +} + +const UomHelper = { + findUomValueByKey, +} + +export default UomHelper; diff --git a/frontend/src/views/StockView.vue b/frontend/src/views/StockView.vue index 307ae5f4..02ef8f43 100644 --- a/frontend/src/views/StockView.vue +++ b/frontend/src/views/StockView.vue @@ -1,7 +1,7 @@ +
+
+
+ + +
+ +
+ + +
+
+
+ -
- -
- + - +
+
+ + +
+
+
+ + +
+
+ + +
+
+ +
+
-
- - + +
+
+ - {{ material.ownMaterialNumber }} ({{ - material.description - }}) - - -
-
- - -
-
- - +
+
+ - {{ customer.name }} - - -
-
- - -
- -
- + +
+ +
@@ -145,10 +203,12 @@ diff --git a/frontend/src/views/stock/PartnerStockSFC.vue b/frontend/src/views/stock/PartnerStockSFC.vue index ce4c411e..33551fc3 100644 --- a/frontend/src/views/stock/PartnerStockSFC.vue +++ b/frontend/src/views/stock/PartnerStockSFC.vue @@ -1,7 +1,7 @@