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 66ec01e7..bddb51e9 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 @@ -27,6 +27,7 @@ import org.eclipse.tractusx.puris.backend.common.api.domain.model.MessageHeader; import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_RequestStateEnum; import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_UseCaseEnum; +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.MaterialPartnerRelation; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; @@ -40,7 +41,6 @@ import org.eclipse.tractusx.puris.backend.stock.logic.service.PartnerProductStockService; import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockRequestService; import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockService; -import org.modelmapper.ModelMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; @@ -78,6 +78,9 @@ public class DataInjectionCommandLineRunner implements CommandLineRunner { @Autowired private ProductStockRequestService productStockRequestService; + @Autowired + private VariablesService variablesService; + @Value("${puris.demonstrator.role}") private String demoRole; @@ -94,7 +97,7 @@ public DataInjectionCommandLineRunner(ObjectMapper objectMapper) { @Override public void run(String... args) throws Exception { - + createOwnPartnerEntity(); log.info("Creating setup for " + demoRole.toUpperCase()); if (demoRole.equals("supplier")) { setupSupplierRole(); @@ -107,7 +110,42 @@ public void run(String... args) throws Exception { } /** - * Generates an initial set of data for a customer within the demonstration context. + * Generates and persists a Partner entity that holds all + * relevant data about the owner of the running instance of + * the PURIS application. + */ + private void createOwnPartnerEntity() { + Partner mySelf; + if(variablesService.getOwnDefaultBpns()!= null && variablesService.getOwnDefaultBpns().length()!=0) { + mySelf = new Partner(variablesService.getOwnName(), + variablesService.getOwnEdcIdsUrl(), + variablesService.getOwnBpnl(), + variablesService.getOwnDefaultBpns(), + variablesService.getOwnDefaultSiteName(), + variablesService.getOwnDefaultBpna(), + variablesService.getOwnDefaultStreetAndNumber(), + variablesService.getOwnDefaultZipCodeAndCity(), + variablesService.getOwnDefaultCountry()); + } else { + mySelf = new Partner(variablesService.getOwnName(), + variablesService.getOwnEdcIdsUrl(), + variablesService.getOwnBpnl(), + variablesService.getOwnDefaultBpna(), + variablesService.getOwnDefaultStreetAndNumber(), + variablesService.getOwnDefaultZipCodeAndCity(), + variablesService.getOwnDefaultCountry() + ); + } + mySelf = partnerService.create(mySelf); + log.info("Successfully created own Partner Entity: " + (partnerService.findByBpnl(mySelf.getBpnl()) != null)); + if(mySelf != null) { + log.info(mySelf.toString()); + } + } + + /** + * Generates an initial set of data for a customer within the demonstration context. + * * @throws JsonProcessingException */ private void setupCustomerRole() throws JsonProcessingException { @@ -121,6 +159,8 @@ private void setupCustomerRole() throws JsonProcessingException { log.info(String.format("UUID of supplier partner: %s", supplierPartner.getUuid())); supplierPartner = partnerService.findByUuid(supplierPartner.getUuid()); log.info(String.format("Found supplier partner: %s", supplierPartner)); + supplierPartner = partnerService.findByBpns(supplierPartner.getSites().stream().findFirst().get().getBpns()); + log.info("Found supplier partner by bpns: " + (supplierPartner != null)); MaterialPartnerRelation semiconductorPartnerRelation = new MaterialPartnerRelation(semiconductorMaterial, @@ -154,10 +194,10 @@ private void setupCustomerRole() throws JsonProcessingException { // Create Material Stock MaterialStock materialStockEntity = new MaterialStock( - semiconductorMaterial, - 5, - "BPNS4444444444XX", - new Date() + semiconductorMaterial, + 5, + "BPNS4444444444XX", + new Date() ); materialStockEntity = materialStockService.create(materialStockEntity); log.info(String.format("Created materialStock: %s", materialStockEntity)); @@ -166,19 +206,22 @@ private void setupCustomerRole() throws JsonProcessingException { // Create PartnerProductStock semiconductorMaterial = materialService.findByOwnMaterialNumber(semiconductorMaterial.getOwnMaterialNumber()); PartnerProductStock partnerProductStockEntity = new PartnerProductStock( - semiconductorMaterial, - 10, - supplierPartner.getSiteBpns(), - new Date(), - supplierPartner + semiconductorMaterial, + 10, + supplierPartner.getSites().stream().findFirst().get().getBpns(), + new Date(), + supplierPartner ); log.info(String.format("Created partnerProductStock: %s", partnerProductStockEntity)); partnerProductStockEntity = partnerProductStockService.create(partnerProductStockEntity); ProductStockSammDto productStockSammDto = productStockSammMapper.toSamm(partnerProductStockEntity); log.info("SAMM-DTO:\n" + objectMapper.writeValueAsString(productStockSammDto)); + + log.info("Own Street and Number: " + variablesService.getOwnDefaultStreetAndNumber()); } + /** - * Generates an initial set of data for a supplier within the demonstration context. + * Generates an initial set of data for a supplier within the demonstration context. */ private void setupSupplierRole() { Partner customerPartner = createAndGetCustomerPartner(); @@ -205,11 +248,11 @@ private void setupSupplierRole() { ProductStock productStockEntity = new ProductStock( - semiconductorMaterial, - 20, - "BPNS1234567890ZZ", - new Date(), - customerPartner + semiconductorMaterial, + 20, + "BPNS1234567890ZZ", + new Date(), + customerPartner ); productStockEntity = productStockService.create(productStockEntity); log.info(String.format("Created productStock: %s", productStockEntity.toString())); @@ -217,21 +260,27 @@ private void setupSupplierRole() { List foundProductStocks = productStockService. findAllByMaterialNumberCustomer(semiconductorMatNbrCustomer, customerPartner); log.info(String.format("Found productStocks by material number and allocated to customer " + - "bpnl: %s", foundProductStocks)); + "bpnl: %s", foundProductStocks)); } /** * creates a new customer Partner entity, stores it to - * the database and returns this entity. + * the database and returns this entity. + * * @return a reference to the newly created customer */ private Partner createAndGetCustomerPartner() { Partner customerPartnerEntity = new Partner( - "Scenario Customer", - "http://sokrates-controlplane:8084/api/v1/ids", - "BPNL4444444444XX", - "BPNS4444444444XX" + "Scenario Customer", + "http://sokrates-controlplane:8084/api/v1/ids", + "BPNL4444444444XX", + "BPNS4444444444XY", + "Hauptwerk Musterhausen", + "BPNA4444444444ZZ", + "Musterstraße 35b", + "77777 Musterhausen", + "Germany" ); customerPartnerEntity = partnerService.create(customerPartnerEntity); log.info(String.format("Created customer partner: %s", customerPartnerEntity)); @@ -242,15 +291,21 @@ private Partner createAndGetCustomerPartner() { /** * creates a new supplier Partner entity, stores it to - * the database and returns this entity. + * the database and returns this entity. + * * @return a reference to the newly created supplier */ private Partner createAndGetSupplierPartner() { Partner supplierPartnerEntity = new Partner( - "Scenario Supplier", - "http://plato-controlplane:8084/api/v1/ids", - "BPNL1234567890ZZ", - "BPNS1234567890ZZ" + "Scenario Supplier", + "http://plato-controlplane:8084/api/v1/ids", + "BPNL1234567890ZZ", + "BPNS1234567890XY", + "Konzernzentrale Dudelsdorf", + "BPNA1234567890AA", + "Heinrich-Supplier-Straße 1", + "77785 Dudelsdorf", + "Germany" ); supplierPartnerEntity = partnerService.create(supplierPartnerEntity); log.info(String.format("Created supplier partner: %s", supplierPartnerEntity)); @@ -261,15 +316,19 @@ private Partner createAndGetSupplierPartner() { /** * creates a new (non-scenario) customer entity, stores - * it to the database and returns this entity. + * it to the database and returns this entity. + * * @return a reference to the newly created non-scenario customer */ private Partner createAndGetNonScenarioCustomer() { Partner nonScenarioCustomer = new Partner( - "Non-Scenario Customer", - "(None Provided!)>", - "BPNL2222222222RR", - "BPNL2222222222RR" + "Non-Scenario Customer", + "(None Provided!)>", + "BPNL2222222222RR", + "BPNS2222222222XZ", + "Zentraleinkaufsabteilung", + "BPNA2222222222HH", + "54.321N, 8.7654E" ); nonScenarioCustomer = partnerService.create(nonScenarioCustomer); log.info(String.format("Created non-scenario customer partner: %s", nonScenarioCustomer)); @@ -295,8 +354,9 @@ private Material getNewSemiconductorMaterialForCustomer() { } /** - * creates a new central control unit Material object. - * Note: this object is not yet stored to the database + * creates a new central control unit Material object. + * Note: this object is not yet stored to the database + * * @return a reference to the newly created central control unit material */ private Material getNewCentralControlUnitMaterial() { @@ -334,11 +394,10 @@ private void createRequest() throws JsonProcessingException { request = productStockRequestService.createRequest(request); - String stringOutput = objectMapper.writeValueAsString(request); - log.info("SAMPLE-Request\n" + objectMapper.readTree(stringOutput).toPrettyString()); + log.info("SAMPLE-Request\n" + objectMapper.readTree(stringOutput).toPrettyString()); - var deserializedRequest = objectMapper.readValue(stringOutput, ProductStockRequest.class); + var deserializedRequest = objectMapper.readValue(stringOutput, ProductStockRequest.class); log.info(deserializedRequest.toString()); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/api/logic/service/VariablesService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/api/logic/service/VariablesService.java index 7e5b1600..5a7cf177 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/api/logic/service/VariablesService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/api/logic/service/VariablesService.java @@ -22,6 +22,7 @@ package org.eclipse.tractusx.puris.backend.common.api.logic.service; import org.eclipse.tractusx.puris.backend.common.edc.logic.dto.datatype.DT_ApiMethodEnum; +import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -47,8 +48,23 @@ public class VariablesService { @Value("${own.bpnl}") private String ownBpnl; + @Value("${own.name}") + private String ownName; @Value("${edc.idsUrl}") private String ownEdcIdsUrl; + @Value("${own.default.bpns}") + private String ownDefaultBpns; + @Value("${own.default.streetandnumber}") + private String ownDefaultStreetAndNumber; + @Value("${own.default.site.name}") + private String ownDefaultSiteName; + @Value("${own.default.bpna}") + private String ownDefaultBpna; + @Value("${own.default.zipcodeandcity}") + private String ownDefaultZipCodeAndCity; + @Value("${own.default.country}") + private String ownDefaultCountry; + /** * Returns the asset-id as defined in the properties file for the given api method diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java index 5267cd00..078ed1c4 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java @@ -65,27 +65,15 @@ public class EdcAdapterService { @Value("${edc.controlplane.data.port}") private Integer dataPort; - @Value("${edc.backend.url}") - private String backendUrl; - @Value("${edc.controlplane.key}") private String edcApiKey; @Value("${server.port}") private String serverPort; - @Value("${edc.dataplane.public.port}") - private String dataplanePort; - @Value("${minikube.ip}") private String minikubeIp; - @Value("${request.serverendpoint}") - private String requestServerEndpointURL; - - @Value("${response.serverendpoint}") - private String responseServerEndpointURL; - private ObjectMapper objectMapper; @Autowired @@ -504,7 +492,6 @@ public String[] getContractForResponseApi(String partnerIdsUrl) { */ public String[] getContractForRequestOrResponseApiApi(String partnerIdsUrl, Map filter) { try { - // String catalog = getCatalog(partnerIdsUrl, Optional.of(filter)); JsonNode objectNode = getCatalogFilteredByAssetPropertyObjectFilter(partnerIdsUrl, filter); JsonNode contractOffer = objectNode.get("contractOffers").get(0); String assetApi = contractOffer.get("asset").get("id").asText(); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Address.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Address.java new file mode 100644 index 00000000..fe3fe500 --- /dev/null +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Address.java @@ -0,0 +1,96 @@ +/* + * 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.masterdata.domain.model; + +import jakarta.persistence.Embeddable; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +/** + *

An Address either specifies the usual properties like street, house number, + * zip code, city and country.

+ *

All Addresses are uniquely identified by their BPNA

+ */ +@Embeddable +@NoArgsConstructor +@Getter +@Setter +@ToString +public class Address implements Comparable
{ + + /** + * The BPNA of this Address. + */ + private String bpna; + + /** + * The street and house number of this Address. + */ + private String streetAndNumber; + /** + * The zip code and city of this Address. + */ + private String zipCodeAndCity; + /** + * The country of this Address. + */ + private String country; + + /** + * Use this constructor to generate a new Address, consisting of the BPNA, street and + * number, zip code and city and country. + * + * @param bpna + * @param streetAndNumber + * @param zipCodeAndCity + * @param country + */ + public Address(String bpna, String streetAndNumber, String zipCodeAndCity, String country) { + this.bpna = bpna; + this.streetAndNumber = streetAndNumber; + this.zipCodeAndCity = zipCodeAndCity; + this.country = country; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj instanceof Address) { + return bpna.equals(((Address) obj).bpna); + } + return false; + } + + @Override + public int hashCode() { + return bpna.hashCode(); + } + + @Override + public int compareTo(Address o) { + return bpna.compareTo(o.bpna); + } +} diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Partner.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Partner.java index 6110f858..a2f91ff2 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Partner.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Partner.java @@ -28,6 +28,17 @@ import java.util.*; +/** + *

This class represents business partner entities. + * Each Partner is required to have a BPNL number, a BPNA and + * an EDC-URL.

+ * + *

Each Partner may have zero or more BPNS. + * Since each BPNS contains a BPNA, the requirement of having a BPNA + * is fulfilled by having at least one BPNS.

+ *

If there is no BPNS, then this Partner has to have at least one + * BPNA, that is not attached to any other BPNS.

+ */ @Entity @Table(name = "partner") @Getter @@ -39,31 +50,95 @@ public class Partner { @Id @GeneratedValue private UUID uuid; + /** + * A human-readable, distinctive name of this partner. + */ private String name; + /** + * The EDC-URL of the partner. + */ private String edcUrl; + /** + * The BPNL of the partner. + */ + private String bpnl; - private String siteBpns; + @ElementCollection + /** + * Contains all Addresses (BPNAs) that are directly assigned to this + * Partner's BPNL. + */ + private SortedSet
addresses = new TreeSet<>(); + @OneToMany(cascade = CascadeType.ALL) + /** + * Contains all Sites (BPNSs) that are assigned to this + * Partner's BPNL. Each BPNS has one or more addresses (BPNAs). + */ + private SortedSet sites = new TreeSet<>(); @OneToMany(mappedBy = "partner") + /** + * Contains all MaterialPartnerRelations that this Partner is involved in. + */ private Set materialPartnerRelations; @OneToMany @ToString.Exclude @Setter(AccessLevel.NONE) + /** + * Contains all ProductStocks that are created for this Partner. + */ private List allocatedProductStocksForCustomer = new ArrayList<>(); @OneToMany @ToString.Exclude @Setter(AccessLevel.NONE) + /** + * Contains all PartnerProductStocks that this Partner has for us. + */ private List partnerProductStocks = new ArrayList<>(); - public Partner(String name, String edcUrl, String bpnl, String siteBpns) { + /** + * Use this constructor to generate a new Partner with a BPNS and a BPNA attached. + * + * @param name the human-readable name of this Partner + * @param edcUrl the edc-url of this Partner + * @param bpnl the BPNL of this Partner + * @param siteBpns the BPNS of this Partner + * @param siteName the name of the BPNS-site + * @param siteBpna the BPNA attached to the site + * @param streetAndNumber street and number of this BPNA + * @param zipCodeAndCity zip code and city of this BPNA + * @param country country of this BPNA + */ + public Partner(String name, String edcUrl, String bpnl, String siteBpns, String siteName, String siteBpna, String streetAndNumber, + String zipCodeAndCity, String country) { + this.name = name; + this.edcUrl = edcUrl; + this.bpnl = bpnl; + Site site = new Site(siteBpns, siteName, siteBpna, streetAndNumber, zipCodeAndCity, country); + sites.add(site); + } + + /** + * Use this constructor to generate a new Partner with a BPNS and a BPNA, but no Site/BPNS. + * + * @param name the human-readable name of this Partner + * @param edcUrl the edc-url of this Partner + * @param bpnl the BPNL of this Partner + * @param bpna the BPNA attached to the Partner + * @param streetAndNumber street and number of this BPNA + * @param zipCodeAndCity zip code and city of this BPNA + * @param country country of this BPNA + */ + public Partner(String name, String edcUrl, String bpnl, String bpna, String streetAndNumber, String zipCodeAndCity, String country) { this.name = name; this.edcUrl = edcUrl; this.bpnl = bpnl; - this.siteBpns = siteBpns; + addresses.add(new Address(bpna, streetAndNumber, zipCodeAndCity, country)); } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -76,4 +151,5 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(uuid); } + } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Site.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Site.java new file mode 100644 index 00000000..4283ebfc --- /dev/null +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/model/Site.java @@ -0,0 +1,100 @@ +/* + * 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.masterdata.domain.model; + +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.validation.constraints.NotNull; +import lombok.*; + +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * A Site represents a real estate business asset of a business partner. + * It may be a production plant, office building, warehouse, etc. + * Each Site is uniquely identified by its BPNS. + * For every Site there is at least one business address, which is in turn + * represented by the {@link Address}. + */ +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class Site implements Comparable { + + @Id + @NotNull + /** + * The BPNS of this Site. + */ + private String bpns; + /** + * A human-readable, distinctive name of this site. + */ + private String name; + @ElementCollection + /** + * Contains all Addresses (BPNAs) that are directly assigned to this + * Site's BPNS. + */ + private SortedSet
addresses = new TreeSet<>(); + + + /** + * This constructor generates a new Site. + * + * @param bpns the BPNS of this Site + * @param siteName the human-readable description of this Site + * @param bpna the BPNA assigned to this Site + * @param streetAndNumber street and number assigned to the BPNA + * @param zipCodeAndCity zip code and city assigned to the BPNA + * @param country the country assigned to the BPNA + */ + public Site(String bpns, String siteName, String bpna, String streetAndNumber, String zipCodeAndCity, String country) { + this.bpns = bpns; + this.name = siteName; + addresses.add(new Address(bpna, streetAndNumber, zipCodeAndCity, country)); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj instanceof Site) { + return bpns.equals(((Site) obj).bpns); + } + return false; + } + + @Override + public int hashCode() { + return bpns.hashCode(); + } + + @Override + public int compareTo(Site o) { + return bpns.compareTo(o.bpns); + } +} diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepository.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepository.java index 6d155ae6..ef212218 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepository.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/domain/repository/PartnerRepository.java @@ -33,6 +33,5 @@ public interface PartnerRepository extends JpaRepository { Optional findFirstByBpnl(String bpnl); - Optional findFirstBySiteBpns(String siteBpns); - + Optional findFirstBySites_Bpns(String siteBpns); } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerService.java index 8d91307d..d2e84e51 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/masterdata/logic/service/PartnerService.java @@ -42,4 +42,6 @@ public interface PartnerService { Partner findByBpns(String bpns); + Partner getOwnPartnerEntity(); + } 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 3a59cb00..5e069e6c 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 @@ -22,6 +22,7 @@ package org.eclipse.tractusx.puris.backend.masterdata.logic.service; 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.Partner; import org.eclipse.tractusx.puris.backend.masterdata.domain.repository.MaterialRepository; import org.eclipse.tractusx.puris.backend.masterdata.domain.repository.PartnerRepository; @@ -45,6 +46,9 @@ public class PartnerServiceImpl implements PartnerService { @Autowired private MaterialPartnerRelationService mprService; + @Autowired + private VariablesService variablesService; + @Override public Partner create(Partner partner) { @@ -53,7 +57,7 @@ public Partner create(Partner partner) { } var searchResult = partnerRepository.findById(partner.getUuid()); - if(searchResult.isEmpty()) { + if (searchResult.isEmpty()) { return partnerRepository.save(partner); } log.error("Could not create Partner " + partner.getBpnl() + " because it already existed before"); @@ -62,11 +66,7 @@ public Partner create(Partner partner) { @Override public Partner findByUuid(UUID partnerUuid) { - Optional foundPartner = partnerRepository.findById(partnerUuid); - if (foundPartner.isPresent()) { - return foundPartner.get(); - } - return null; + return partnerRepository.findById(partnerUuid).orElse(null); } @Override @@ -76,7 +76,7 @@ public List findAllCustomerPartnersForMaterialId(String ownMaterialNumb @Override public List findAllSupplierPartnersForMaterialId(String ownMaterialNumber) { - var searchResult = materialRepository.findById(ownMaterialNumber); + var searchResult = materialRepository.findById(ownMaterialNumber); if (searchResult.isPresent()) { return mprService.findAllSuppliersForMaterial(searchResult.get()); } @@ -86,7 +86,7 @@ public List findAllSupplierPartnersForMaterialId(String ownMaterialNumb @Override public Partner update(Partner partner) { Optional existingPartner = - partnerRepository.findById(partner.getUuid()); + partnerRepository.findById(partner.getUuid()); if (existingPartner.isPresent()) { return partnerRepository.save(partner); } @@ -96,21 +96,16 @@ public Partner update(Partner partner) { @Override public Partner findByBpnl(String bpnl) { - Optional existingPartner = - partnerRepository.findFirstByBpnl(bpnl); - - if (existingPartner.isPresent()) { - return existingPartner.get(); - } else return null; + return partnerRepository.findFirstByBpnl(bpnl).orElse(null); } @Override public Partner findByBpns(String bpns) { - Optional existingPartner = - partnerRepository.findFirstBySiteBpns(bpns); + return partnerRepository.findFirstBySites_Bpns(bpns).orElse(null); + } - if (existingPartner.isPresent()) { - return existingPartner.get(); - } else return null; + @Override + public Partner getOwnPartnerEntity() { + return partnerRepository.findFirstByBpnl(variablesService.getOwnBpnl()).orElse(null); } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/MaterialStock.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/MaterialStock.java index 267e0d31..75210c2c 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/MaterialStock.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/MaterialStock.java @@ -40,10 +40,10 @@ @NoArgsConstructor public class MaterialStock extends Stock { - public MaterialStock(Material material, double quantity, String atSiteBpnl, + public MaterialStock(Material material, double quantity, String atSiteBpns, Date lastUpdatedOn) { - super(material, quantity, atSiteBpnl, lastUpdatedOn); + super(material, quantity, atSiteBpns, lastUpdatedOn); super.setType(DT_StockTypeEnum.MATERIAL); } -} \ No newline at end of file +} diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/PartnerProductStock.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/PartnerProductStock.java index 29acdc7f..9b9335e2 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/PartnerProductStock.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/PartnerProductStock.java @@ -46,15 +46,15 @@ public class PartnerProductStock extends Stock { @NotNull private Partner supplierPartner; - public PartnerProductStock(Material material, double quantity, String atSiteBpnl, + public PartnerProductStock(Material material, double quantity, String atSiteBpns, Date lastUpdatedOn, Partner supplierPartner) { - super(material, quantity, atSiteBpnl, lastUpdatedOn); + super(material, quantity, atSiteBpns, lastUpdatedOn); super.setType(DT_StockTypeEnum.PRODUCT); this.setSupplierPartner(supplierPartner); } - public PartnerProductStock(Material material, double quantity, String atSiteBpnl, Date lastUpdatedOn) { - super(material, quantity, atSiteBpnl, lastUpdatedOn); + public PartnerProductStock(Material material, double quantity, String atSiteBpns, Date lastUpdatedOn) { + super(material, quantity, atSiteBpns, lastUpdatedOn); super.setType(DT_StockTypeEnum.PRODUCT); } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/ProductStock.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/ProductStock.java index b7209d72..d10943f9 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/ProductStock.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/ProductStock.java @@ -45,14 +45,14 @@ public class ProductStock extends Stock { @NotNull private Partner allocatedToCustomerPartner; - public ProductStock(Material material, double quantity, String atSiteBpnl, Date lastUpdatedOn, Partner allocatedToCustomerPartner) { - super(material, quantity, atSiteBpnl, lastUpdatedOn); + public ProductStock(Material material, double quantity, String atSiteBpns, Date lastUpdatedOn, Partner allocatedToCustomerPartner) { + super(material, quantity, atSiteBpns, lastUpdatedOn); super.setType(DT_StockTypeEnum.PRODUCT); this.setAllocatedToCustomerPartner(allocatedToCustomerPartner); } - public ProductStock(Material material, double quantity, String atSiteBpnl, Date lastUpdatedOn) { - super(material, quantity, atSiteBpnl, lastUpdatedOn); + public ProductStock(Material material, double quantity, String atSiteBpns, Date lastUpdatedOn) { + super(material, quantity, atSiteBpns, lastUpdatedOn); super.setType(DT_StockTypeEnum.PRODUCT); } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/Stock.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/Stock.java index 2e9bd297..6c2faa3a 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/Stock.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/domain/model/Stock.java @@ -55,7 +55,7 @@ public class Stock { private double quantity; @NotNull - private String atSiteBpnl; + private String atSiteBpns; @Enumerated(EnumType.STRING) @NotNull @@ -65,10 +65,10 @@ public class Stock { @NotNull private Date lastUpdatedOn; - public Stock(Material material, double quantity, String atSiteBpnl, Date lastUpdatedOn) { + public Stock(Material material, double quantity, String atSiteBpns, Date lastUpdatedOn) { this.material = material; this.quantity = quantity; - this.atSiteBpnl = atSiteBpnl; + this.atSiteBpns = atSiteBpns; this.lastUpdatedOn = lastUpdatedOn; } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ProductStockSammMapper.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ProductStockSammMapper.java index 248bb980..615fec6c 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ProductStockSammMapper.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/adapter/ProductStockSammMapper.java @@ -82,7 +82,7 @@ public ProductStockSammDto toSamm(Stock stock) { AllocatedStock allocatedStock = new AllocatedStock( new Quantity(stock.getQuantity(), "unit:piece"), - new LocationId(LocationIdTypeEnum.B_P_N_S, stock.getAtSiteBpnl()) + new LocationId(LocationIdTypeEnum.B_P_N_S, stock.getAtSiteBpns()) ); List allocatedStocks = new ArrayList<>(); allocatedStocks.add(allocatedStock); 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 0e174559..36464e38 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 @@ -34,8 +34,8 @@ @AllArgsConstructor public class MaterialStockDto extends StockDto { - public MaterialStockDto(MaterialDto material, double quantity, String atSiteBpnl) { - super(material, quantity, atSiteBpnl, new Date()); + public MaterialStockDto(MaterialDto material, double quantity, String atSiteBpns) { + super(material, quantity, atSiteBpns, new Date()); 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 d533f2c2..28b82e1c 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 @@ -37,14 +37,14 @@ public class PartnerProductStockDto extends StockDto { private PartnerDto supplierPartner; - public PartnerProductStockDto(MaterialDto material, double quantity, String atSiteBpnl) { - super(material, quantity, atSiteBpnl, new Date()); + public PartnerProductStockDto(MaterialDto material, double quantity, String atSiteBpns) { + super(material, quantity, atSiteBpns, new Date()); this.setType(DT_StockTypeEnum.PRODUCT); } - public PartnerProductStockDto(MaterialDto material, double quantity, String atSiteBpnl, + public PartnerProductStockDto(MaterialDto material, double quantity, String atSiteBpns, PartnerDto supplierPartner) { - super(material, quantity, atSiteBpnl, new Date()); + super(material, quantity, atSiteBpns, new Date()); 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 743da799..c25a1eda 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 @@ -39,14 +39,14 @@ public class ProductStockDto extends StockDto { private PartnerDto allocatedToCustomerPartner; - public ProductStockDto(MaterialDto material, double quantity, String atSiteBpnl) { - super(material, quantity, atSiteBpnl, new Date()); + public ProductStockDto(MaterialDto material, double quantity, String atSiteBpns) { + super(material, quantity, atSiteBpns, new Date()); this.setType(DT_StockTypeEnum.PRODUCT); } - public ProductStockDto(MaterialDto material, double quantity, String atSiteBpnl, + public ProductStockDto(MaterialDto material, double quantity, String atSiteBpns, PartnerDto allocatedToCustomerPartner) { - super(material, quantity, atSiteBpnl, new Date()); + super(material, quantity, atSiteBpns, new Date()); this.setType(DT_StockTypeEnum.PRODUCT); this.allocatedToCustomerPartner = allocatedToCustomerPartner; } 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 e252c0f7..5b18f7d6 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 @@ -46,16 +46,16 @@ public abstract class StockDto implements Serializable { private double quantity; - private String atSiteBpnl; + private String atSiteBpns; private DT_StockTypeEnum type; private Date lastUpdatedOn; - public StockDto(MaterialDto material, double quantity, String atSiteBpnl, Date lastUpdatedOn) { + public StockDto(MaterialDto material, double quantity, String atSiteBpns, Date lastUpdatedOn) { this.material = material; this.quantity = quantity; - this.atSiteBpnl = atSiteBpnl; + this.atSiteBpns = atSiteBpns; this.lastUpdatedOn = lastUpdatedOn; } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java index aa500712..38aba4bd 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java @@ -27,7 +27,6 @@ import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockRequest; import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_RequestStateEnum; import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_UseCaseEnum; -import org.eclipse.tractusx.puris.backend.common.api.logic.dto.*; import org.eclipse.tractusx.puris.backend.common.edc.logic.service.EdcAdapterService; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; @@ -203,7 +202,7 @@ public void handleRequest(ProductStockRequest productStockRequest) { if (productStocks.size() > 1) { List distinctProductStocks = productStocks.stream() - .filter(distinctByKey(p -> p.getAtSiteBpnl())) + .filter(distinctByKey(p -> p.getAtSiteBpns())) .collect(Collectors.toList()); if (distinctProductStocks.size() > 1) { log.warn(String.format("More than one site is not yet supported per " + diff --git a/backend/src/main/resources/application-customer.properties b/backend/src/main/resources/application-customer.properties index cfd5825b..9af7f3d3 100755 --- a/backend/src/main/resources/application-customer.properties +++ b/backend/src/main/resources/application-customer.properties @@ -31,8 +31,26 @@ spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true # Own EDC-IDS-URL edc.idsUrl=${EDC_IDSURL:http://sokrates-controlplane:8084/api/v1/ids} + +# Own BPNL own.bpnl=${OWN_BPNL:BPNL4444444444XX} -own.bpns=${OWN_BPNS:BPNS4444444444XX} + +# Own name (self-description) +own.name=${OWN_NAME:Scenario Customer} + +# Own BPNS (optional: if this is set, then set own.default.site.name as well) +#own.default.bpns=${OWN_BPNS:BPNS4444444444XY} +own.default.bpns= +# Name of Site (see above) +#own.default.site.name=${OWN_SITE:Hauptwerk Musterhausen} +own.default.site.name= + +# If a BPNS is set, then this BPNA will be attached to it. +# Otherwise it will be attached immediately to the BPNL (see above) +own.default.bpna=${OWN_BPNS:BPNA4444444444ZZ} +own.default.streetandnumber=${OWN_STREETANDNUMBER:Musterstrasse 35b} +own.default.zipcodeandcity=${OWN_ZIPCODEANDCITY:77777 Musterhausen} +own.default.country=${OWN_COUNTRY:Germany} # The number of minutes before received authentication data # in the context of a consumer pull is removed from memory diff --git a/backend/src/main/resources/application-supplier.properties b/backend/src/main/resources/application-supplier.properties index f7ce8784..c567743f 100644 --- a/backend/src/main/resources/application-supplier.properties +++ b/backend/src/main/resources/application-supplier.properties @@ -31,8 +31,25 @@ spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true # Own EDC-IDS-URL edc.idsUrl=${EDC_IDSURL:http://plato-controlplane:8084/api/v1/ids} + +# Own BPNL own.bpnl=${OWN_BPNL:BPNL1234567890ZZ} -own.bpns=${OWN_BPNS:BPNS1234567890ZZ} + +# Own name (self-description) +own.name=${OWN_NAME:Scenario Supplier} + +# Own BPNS (optional: if this is set, then set own.default.site.name as well) +own.default.bpns=${OWN_BPNS:BPNS1234567890ZZ} + +# Name of Site (see above) +own.default.site.name=${OWN_SITE:Konzernzentrale Dudelsdorf} + +# If a BPNS is set, then this BPNA will be attached to it. +# Otherwise it will be attached immediately to the BPNL (see above) +own.default.bpna=${OWN_BPNS:BPNA1234567890AA} +own.default.streetandnumber=${OWN_STREETANDNUMBER:Heinrich-Supplier-Strasse 1} +own.default.zipcodeandcity=${OWN_ZIPCODEANDCITY:77785 Dudelsdorf} +own.default.country=${OWN_COUNTRY:Germany} # The number of minutes before received authentication data # in the context of a consumer pull is removed from memory diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index ea4ed486..756e30fe 100755 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,6 +1,6 @@ # Server Config server.port=${SERVER_PORT:8081} -my.base.url=http://localhost +my.base.url=http://host.minikube.internal request.serverendpoint=${my.base.url}:${server.port}/catena/product-stock/request request.apiassetid=product-stock-request-api response.serverendpoint=${my.base.url}:${server.port}/catena/product-stock/response @@ -12,30 +12,45 @@ spring.datasource.url=${DATASOURCE_URL:jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1} spring.datasource.username=${DATASOURCE_USERNAME:sa} spring.datasource.password=${DATASOURCE_PASSWORD:} spring.jpa.hibernate.ddl-auto=create - # API Root server.servlet.context-path=${API_ROOTDIR:/catena} - # EDC Config -edc.controlplane.host=${EDC_CONTROLPLANE_HOST:172.17.0.2} -edc.controlplane.data.port=${EDC_CONTROLPLANE_DATA_PORT:31960} +edc.controlplane.host=${EDC_CONTROLPLANE_HOST:192.168.49.2} +edc.controlplane.data.port=${EDC_CONTROLPLANE_DATA_PORT:31944} edc.controlplane.key=${EDC_CONTROLPLANE_KEY:password} -edc.backend.url=${EDC_BACKEND_URL:http://172.17.0.2:31048} -minikube.ip=${MINIKUBE_IP:host.minikube.internal} edc.applydataplaneworkaround=true -edc.dataplane.public.port=30784 - +edc.dataplane.public.port=30703 +minikube.ip=${MINIKUBE_IP:host.minikube.internal} # Jackson (JSON) #spring.jackson.default-property-inclusion=non_empty #logging.level.org.hibernate.SQL=DEBUG #logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true + # Own EDC-IDS-URL -edc.idsUrl=${EDC_IDSURL:http://plato-controlplane:8084/api/v1/ids} -own.bpnl=${OWN_BPNL:BPNL1234567890ZZ} -own.bpns=${OWN_BPNS:BPNS1234567890ZZ} +edc.idsUrl=${EDC_IDSURL:http://sokrates-controlplane:8084/api/v1/ids} + +# Own BPNL +own.bpnl=${OWN_BPNL:BPNL4444444444XX} + +# Own name (self-description) +own.name=${OWN_NAME:Scenario Customer} + +# Own BPNS (optional: if this is set, then set own.default.site.name as well) +#own.default.bpns=${OWN_BPNS:BPNS4444444444XY} +own.default.bpns=${OWN_BPNS:BPNS4444444444XY} +# Name of Site (see above) +#own.default.site.name=${OWN_SITE:Hauptwerk Musterhausen} +own.default.site.name=${OWN_SITE:Hauptwerk Musterhausen} + +# If a BPNS is set, then this BPNA will be attached to it. +# Otherwise it will be attached immediately to the BPNL (see above) +own.default.bpna=${OWN_BPNS:BPNA4444444444ZZ} +own.default.streetandnumber=${OWN_STREETANDNUMBER:Musterstrasse 35b} +own.default.zipcodeandcity=${OWN_ZIPCODEANDCITY:77777 Musterhausen} +own.default.country=${OWN_COUNTRY:Germany} # The number of minutes before received authentication data # in the context of a consumer pull is removed from memory @@ -43,3 +58,5 @@ own.edr.deletiontimer=2 puris.apiversion=1.0.0 puris.demonstrator.role=customer +# run with: +# mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=customer