Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/material logic #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockResponse;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockResponse;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockResponse;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockResponse;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_RequestStateEnum;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.ProductStockRequestForMaterialDto;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockResponse;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockResponse;

/**
* Dto for {@link ProductStockResponse}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
* (represented by Fraunhofer ISST)
* Copyright (c) 2023 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.common.api.logic.service;

import org.eclipse.tractusx.puris.backend.common.edc.logic.dto.datatype.DT_ApiMethodEnum;
Expand All @@ -19,9 +40,16 @@ public class VariablesService {

@Value("${request.apiassetid}")
private String requestApiAssetId;

@Value("${response.apiassetid}")
private String responseApiAssetId;

@Value("${own.bpnl}")
private String ownBpnl;

@Value("${edc.idsUrl}")
private String ownEdcIdsUrl;

/**
* Returns the asset-id as defined in the properties file for the given api method
* under request.apiassetid or response.apiassetid respectively.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@

import lombok.extern.slf4j.Slf4j;
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;
import org.eclipse.tractusx.puris.backend.masterdata.logic.dto.MaterialDto;
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;
import org.eclipse.tractusx.puris.backend.masterdata.logic.service.PartnerService;
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.domain.model.Stock;
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.logic.dto.samm.*;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -51,29 +54,35 @@ public class ProductStockSammMapper {
private MaterialService materialService;

@Autowired
private PartnerService partnerService;
private MaterialPartnerRelationService mprService;

@Autowired
private ModelMapper modelMapper;

public ProductStockSammDto toSamm(ProductStockDto productStockDto) {
/**
* Utility method to serialize a ProductStock or PartnerProduct on the side
* of the responding supplier;
* @param stock MUST be either ProductStock or PartnerProductStock
* @return the corresponding ProductStockSammDto
*/
public ProductStockSammDto toSamm(Stock stock) {

GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(productStockDto.getLastUpdatedOn());
calendar.setTime(stock.getLastUpdatedOn());
XMLGregorianCalendar lastUpdatedOn = null;
try {
lastUpdatedOn =
DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
} catch (DatatypeConfigurationException e) {
log.error(String.format("Could not create XML Gregorian " +
"Calender from PartnerProductStock.lastUpdatedOn: %s",
productStockDto.getLastUpdatedOn().toString()));
stock.getLastUpdatedOn().toString()));
return null;
}

AllocatedStock allocatedStock = new AllocatedStock(
new Quantity(productStockDto.getQuantity(), "unit:piece"),
new LocationId(LocationIdTypeEnum.B_P_N_S, productStockDto.getAtSiteBpnl())
new Quantity(stock.getQuantity(), "unit:piece"),
new LocationId(LocationIdTypeEnum.B_P_N_S, stock.getAtSiteBpnl())
);
List<AllocatedStock> allocatedStocks = new ArrayList<>();
allocatedStocks.add(allocatedStock);
Expand All @@ -85,17 +94,42 @@ public ProductStockSammDto toSamm(ProductStockDto productStockDto) {
);
List<Position> positions = new ArrayList<>();
positions.add(position);
String materialNumberCustomer = null;
String materialNumberSupplier = null;
if (stock instanceof ProductStock) {
// Partner is customer
ProductStock productStock = (ProductStock) stock;
Partner partner = productStock.getAllocatedToCustomerPartner();
materialNumberCustomer = mprService.find(stock.getMaterial(), partner).getPartnerMaterialNumber();
materialNumberSupplier = stock.getMaterial().getOwnMaterialNumber();
} else if (stock instanceof PartnerProductStock) {
// Partner is supplier
PartnerProductStock partnerProductStock = (PartnerProductStock) stock;
Partner partner = partnerProductStock.getSupplierPartner();
materialNumberSupplier = mprService.find(stock.getMaterial(), partner).getPartnerMaterialNumber();
materialNumberCustomer = stock.getMaterial().getOwnMaterialNumber();
} else {
// stock is neither ProductStock nor PartnerProductStock,
// therefore it is not possible to create a ProductStockSammDto
return null;
}

return new ProductStockSammDto(
positions,
productStockDto.getMaterial().getMaterialNumberCustomer(),
Optional.ofNullable(productStockDto.getMaterial().getMaterialNumberCx()),
Optional.ofNullable(productStockDto.getMaterial().getMaterialNumberSupplier())
materialNumberCustomer,
Optional.ofNullable(stock.getMaterial().getMaterialNumberCx()),
Optional.ofNullable(materialNumberSupplier)
);
}


public PartnerProductStockDto fromSamm(ProductStockSammDto samm) {
/**
* Utility method to deserialize a ProductStockSammDto on the side of the customer
* @param samm a ProductStockSammDto received from a supplier
* @param partner the partner you received the message from
* @return a PartnerProductStockDto
*/
public PartnerProductStockDto fromSamm(ProductStockSammDto samm, Partner partner) {
// application currently only supports:
// - an AGGREGATED Partner stock
// - one Site per Partner
Expand All @@ -110,9 +144,12 @@ public PartnerProductStockDto fromSamm(ProductStockSammDto samm) {
).sum();

// determine material
Material foundMaterial =
materialService.findProductByMaterialNumberCustomer(samm.getMaterialNumberCustomer());
MaterialDto foundMaterialDto = modelMapper.map(foundMaterial, MaterialDto.class);

Material foundMaterial = materialService.findByOwnMaterialNumber(samm.getMaterialNumberCustomer());
MaterialPartnerRelation materialPartnerRelation = mprService.find(foundMaterial, partner);
MaterialDto foundMaterialDto = new MaterialDto(foundMaterial.isMaterialFlag(), foundMaterial.isProductFlag(),
foundMaterial.getOwnMaterialNumber(), materialPartnerRelation.getPartnerMaterialNumber(), foundMaterial.getMaterialNumberCx(),
foundMaterial.getName());

// find bpns - we use the first one as we currently only have one site per partner.
// alternative would be to inject the bpnl of the partner.
Expand All @@ -122,9 +159,7 @@ public PartnerProductStockDto fromSamm(ProductStockSammDto samm) {
.stream().findFirst().get().getAllocatedStocks()
.stream().findFirst().get().getSupplierStockLocationId().getLocationId();

// find partner by bpns
Partner foundPartner = partnerService.findByBpns(atSiteBpns);
PartnerDto supplierPartner = modelMapper.map(foundPartner, PartnerDto.class);
PartnerDto supplierPartner = modelMapper.map(partner, PartnerDto.class);

return new PartnerProductStockDto(
foundMaterialDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ public PartnerProductStockDto(MaterialDto material, double quantity, String atSi
super(material, quantity, atSiteBpnl, new Date());
this.setType(DT_StockTypeEnum.PRODUCT);
this.supplierPartner = supplierPartner;
supplierPartner.addPartnerProductStock(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.ProductStockResponse;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockResponse;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_RequestStateEnum;
import org.eclipse.tractusx.puris.backend.common.api.logic.dto.MessageHeaderDto;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.UUID;

@Service
public interface MaterialStockService {

MaterialStock create(MaterialStock materialStock);
Expand All @@ -36,7 +35,9 @@ public interface MaterialStockService {

MaterialStock findByUuid(UUID materialStockUuid);

List<MaterialStock> findAllByMaterialNumberCustomer(String materialNumberCustomer);
List<MaterialStock> findAllByPartnerMaterialNumber(String partnerMaterialNumber);

List<MaterialStock> findAllByOwnMaterialNumber(String ownMaterialNumber);

MaterialStock update(MaterialStock materialStock);

Expand Down
Loading
Loading