Skip to content

Commit

Permalink
fix: make sure create methods dont overwrite existing stocks
Browse files Browse the repository at this point in the history
  • Loading branch information
eschrewe committed Oct 9, 2023
1 parent ca8b6b7 commit a13e0c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.eclipse.tractusx.puris.backend.stock.logic.service;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;
Expand All @@ -38,6 +39,7 @@
import java.util.stream.Collectors;
@Service
@AllArgsConstructor
@Slf4j
public class PartnerProductStockServiceImpl implements PartnerProductStockService {

private PartnerProductStockRepository partnerProductStockRepository;
Expand All @@ -46,6 +48,9 @@ public class PartnerProductStockServiceImpl implements PartnerProductStockServic

@Override
public PartnerProductStock create(PartnerProductStock partnerProductStock) {
// avoid unintentional overwriting of an existing PartnerProductStock
partnerProductStock.setUuid(null);

return partnerProductStockRepository.save(partnerProductStock);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class ProductStockServiceImpl implements ProductStockService {

@Override
public ProductStock create(ProductStock productStock) {
// avoid unintentional overwriting of an existing ProductStock
productStock.setUuid(null);

// validate, if material is missing
if (productStock.getMaterial() == null || productStock.getMaterial().getOwnMaterialNumber() == null){
Expand All @@ -67,8 +69,8 @@ public ProductStock create(ProductStock productStock) {
}
Optional<Material> existingMaterial = materialRepository.findById(productStock.getMaterial().getOwnMaterialNumber());

if (!existingMaterial.isPresent()) {
log.error(String.format("Material for uuid %s not found", productStock.getMaterial().getOwnMaterialNumber()));
if (existingMaterial.isEmpty()) {
log.error(String.format("Material %s not found", productStock.getMaterial().getOwnMaterialNumber()));
return null;
}

Expand Down

0 comments on commit a13e0c3

Please sign in to comment.