Skip to content

Commit

Permalink
refactor: refactored itemstock and its variants
Browse files Browse the repository at this point in the history
  • Loading branch information
eschrewe committed Dec 18, 2023
1 parent 5a2fd2e commit 23c66ed
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.tractusx.puris.backend.stock.domain.model.*;
import org.eclipse.tractusx.puris.backend.stock.domain.model.measurement.MeasurementUnit;
import org.eclipse.tractusx.puris.backend.stock.logic.adapter.ProductStockSammMapper;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.DirectionCharacteristic;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.ItemUnitEnumeration;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.ProductStockSammDto;
Expand Down Expand Up @@ -70,7 +69,9 @@ public class DataInjectionCommandLineRunner implements CommandLineRunner {
private ProductStockService productStockService;

@Autowired
private ItemStockService itemStockService;
private MaterialItemStockService materialItemStockService;
@Autowired
private ReportedMaterialItemStockService reportedMaterialItemStockService;

@Autowired
private PartnerProductStockService partnerProductStockService;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void run(String... args) throws Exception {
*/
private void createOwnPartnerEntity() {
Partner mySelf;
if(variablesService.getOwnDefaultBpns()!= null && variablesService.getOwnDefaultBpns().length()!=0) {
if (variablesService.getOwnDefaultBpns() != null && variablesService.getOwnDefaultBpns().length() != 0) {
mySelf = new Partner(variablesService.getOwnName(),
variablesService.getEdcProtocolUrl(),
variablesService.getOwnBpnl(),
Expand All @@ -137,7 +138,7 @@ private void createOwnPartnerEntity() {
}
mySelf = partnerService.create(mySelf);
log.info("Successfully created own Partner Entity: " + (partnerService.findByBpnl(mySelf.getBpnl()) != null));

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
mySelf
may be null at this access as suggested by
this
null guard.
if(mySelf != null) {
if (mySelf != null) {
log.info(mySelf.toString());
}
}
Expand Down Expand Up @@ -221,30 +222,34 @@ private void setupCustomerRole() throws JsonProcessingException {
log.info("SAMM-DTO:\n" + objectMapper.writeValueAsString(productStockSammDto));

log.info("Own Street and Number: " + variablesService.getOwnDefaultStreetAndNumber());

ItemStock.Builder builder = ItemStock.Builder.newInstance();
var itemStock = builder
.direction(DirectionCharacteristic.INBOUND)
Partner mySelf = partnerService.getOwnPartnerEntity();
var builder = MaterialItemStock.builder();
var materialItemStock = builder.partner(supplierPartner)
.material(semiconductorMaterial)
.lastUpdatedOnDateTime(new Date())
.locationBpna(mySelf.getSites().first().getAddresses().first().getBpna())
.locationBpns(mySelf.getSites().first().getBpns())
.measurementUnit(ItemUnitEnumeration.UNIT_PIECE)
.locationBpns(supplierPartner.getSites().first().getBpns())
.locationBpna(supplierPartner.getSites().first().getAddresses().first().getBpna())
.partner(supplierPartner)
.quantity(5)
.quantity(20)
.build();
itemStock = itemStockService.create(itemStock);
log.info("Created ItemStock: \n" + itemStock);
var foundItemStock = itemStockService.findById(itemStock.getKey());
log.info("Found ItemStock: " + foundItemStock.equals(itemStock));
log.info("\n" + foundItemStock);
try {
log.info("Trying to serialize: ");
var json = objectMapper.readTree(objectMapper.writeValueAsString(itemStock));
log.info("\n" + json.toPrettyString());
} catch (Exception e) {
log.info("fail");
log.error(e.getMessage());
}
var createdMaterialItemStock = materialItemStockService.create(materialItemStock);
log.info("Created MaterialItemStock: \n" + createdMaterialItemStock.toString());

var builder2 = ReportedMaterialItemStock.builder();
var reportedMaterialItemStock =
builder2
.material(semiconductorMaterial)
.partner(supplierPartner)
.lastUpdatedOnDateTime(new Date())
.locationBpns(supplierPartner.getSites().first().getBpns())
.locationBpna(supplierPartner.getSites().first().getAddresses().first().getBpna())
.measurementUnit(ItemUnitEnumeration.UNIT_PIECE)
.quantity(50)
.build();

var createdReportedMaterialItemStock = reportedMaterialItemStockService.create(reportedMaterialItemStock);
log.info("Created ReportedMaterialItemStock: \n" + createdReportedMaterialItemStock);

}

/**
Expand Down
Loading

0 comments on commit 23c66ed

Please sign in to comment.