Skip to content

Commit

Permalink
Merge pull request #19 from FraunhoferISST/refactor/material
Browse files Browse the repository at this point in the history
feat: added MaterialPartnerRelation and accompanying services
  • Loading branch information
mhellmeier authored Aug 18, 2023
2 parents 89bfcc9 + 459b884 commit 6f14f0a
Show file tree
Hide file tree
Showing 28 changed files with 699 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
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 @@ -27,6 +27,8 @@
import lombok.Setter;
import lombok.ToString;
import org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype.DT_UseCaseEnum;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockRequest;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStockResponse;

import java.util.Date;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
package org.eclipse.tractusx.puris.backend.common.api.domain.model.datatype;

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;

/**
* Enum to track the status of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
*/
package org.eclipse.tractusx.puris.backend.masterdata.domain.model;

import jakarta.persistence.*;
import lombok.*;
import org.eclipse.tractusx.puris.backend.stock.domain.model.Stock;

import java.util.*;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.util.Objects;
import java.util.Set;

@Entity
@Table(name = "material")
Expand All @@ -35,36 +41,6 @@
@NoArgsConstructor
public class Material {

@Id
@GeneratedValue
private UUID uuid;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "partner_supplies_product",
joinColumns = @JoinColumn(name = "material_uuid", referencedColumnName = "uuid"),
inverseJoinColumns = @JoinColumn(name = "partner_uuid", referencedColumnName = "uuid")
)
@ToString.Exclude
@Setter(AccessLevel.NONE)
private Set<Partner> suppliedByPartners = new HashSet<>();
;;

@ManyToMany(targetEntity = Partner.class, fetch = FetchType.EAGER)
@JoinTable(
name = "partner_orders_product",
joinColumns = @JoinColumn(name = "material_uuid", referencedColumnName = "uuid"),
inverseJoinColumns = @JoinColumn(name = "partner_uuid", referencedColumnName = "uuid")
)
@ToString.Exclude
@Setter(AccessLevel.NONE)
private Set<Partner> orderedByPartners = new HashSet<>();

@OneToMany(mappedBy = "uuid")
@ToString.Exclude
@Setter(AccessLevel.NONE)
private List<Stock> materialOnStocks = new ArrayList<>();

/**
* If true, then the Material is a material (input for production / something I buy).
* <p>
Expand All @@ -79,30 +55,27 @@ public class Material {
*/
private boolean productFlag;

private String materialNumberCustomer;

private String materialNumberSupplier;
@Id
private String ownMaterialNumber;

private String materialNumberCx;

private String name;

public Material(boolean materialFlag, boolean productFlag, String materialNumberCustomer, String materialNumberSupplier, String materialNumberCx, String name) {
this.materialFlag = materialFlag;
this.productFlag = productFlag;
this.materialNumberCustomer = materialNumberCustomer;
this.materialNumberSupplier = materialNumberSupplier;
this.materialNumberCx = materialNumberCx;
this.name = name;
}
@OneToMany(mappedBy = "material")
Set<MaterialPartnerRelation> materialPartnerRelations;

public void addPartnerToSuppliedByPartners(Partner supplierPartner) {
this.suppliedByPartners.add(supplierPartner);
supplierPartner.getSuppliesMaterials().add(this);
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Material)) return false;
Material material = (Material) o;
return Objects.equals(ownMaterialNumber, material.ownMaterialNumber);
}

public void addPartnerToOrderedByPartners(Partner customerPartner) {
this.orderedByPartners.add(customerPartner);
customerPartner.getOrdersProducts().add(this);
@Override
public int hashCode() {
return Objects.hash(ownMaterialNumber);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.*;
import lombok.*;

import java.io.Serializable;
import java.util.Objects;
import java.util.UUID;

@Entity
@Getter
@Setter
@AllArgsConstructor
public class MaterialPartnerRelation {

@EmbeddedId
Key key;

private String partnerMaterialNumber;
private boolean partnerSuppliesMaterial;
private boolean partnerBuysMaterial;

@ManyToOne
@MapsId("ownMaterialNumber")
@JoinColumn(name = "material_ownMaterialNumber")
Material material;

@ManyToOne
@MapsId("uuid")
@JoinColumn(name = "partner_uuid")
Partner partner;

public MaterialPartnerRelation() {
this.key = new Key();
}

public MaterialPartnerRelation(Material material, Partner partner, String partnerMaterialNumber, boolean partnerSupplies, boolean partnerBuys) {
this.material = material;
this.partner = partner;
this.key = new Key(material.getOwnMaterialNumber(), partner.getUuid());
this.partnerMaterialNumber = partnerMaterialNumber;
this.partnerSuppliesMaterial = partnerSupplies;
this.partnerBuysMaterial = partnerBuys;
}

@Override
public String toString() {
return "MaterialPartnerRelation{" +
"key=" + key +
", partnerMaterialNumber='" + partnerMaterialNumber + '\'' +
", partnerSuppliesMaterial=" + partnerSuppliesMaterial +
", partnerBuysMaterial=" + partnerBuysMaterial +
", material=" + material.getOwnMaterialNumber() +
", partner=" + partner.getBpnl() +
'}';
}

@Embeddable
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public static class Key implements Serializable {

@Column(name = "material_ownMaterialNumber")
private String ownMaterialNumber;

@Column(name = "partner_uuid")
private UUID partnerUuid;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Key)) return false;
Key key = (Key) o;
return Objects.equals(ownMaterialNumber, key.ownMaterialNumber) && Objects.equals(partnerUuid, key.partnerUuid);
}

@Override
public int hashCode() {
return Objects.hash(ownMaterialNumber, partnerUuid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package org.eclipse.tractusx.puris.backend.masterdata.domain.model;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import org.eclipse.tractusx.puris.backend.stock.domain.model.PartnerProductStock;
import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductStock;
Expand All @@ -41,38 +40,40 @@ public class Partner {
@GeneratedValue
private UUID uuid;
private String name;
@NotNull
private boolean actsAsCustomerFlag;
@NotNull
private boolean actsAsSupplierFlag;
private String edcUrl;
private String bpnl;
private String siteBpns;

@ManyToMany(mappedBy = "suppliedByPartners", fetch = FetchType.EAGER)
@Setter(AccessLevel.NONE)
private Set<Material> suppliesMaterials = new HashSet<>();

@ManyToMany(mappedBy = "orderedByPartners", fetch = FetchType.EAGER)
@Setter(AccessLevel.NONE)
private Set<Material> ordersProducts = new HashSet<>();
@OneToMany(mappedBy = "partner")
private Set<MaterialPartnerRelation> materialPartnerRelations;

@OneToMany(mappedBy = "uuid", fetch = FetchType.LAZY)
@OneToMany
@ToString.Exclude
@Setter(AccessLevel.NONE)
private List<ProductStock> allocatedProductStocksForCustomer = new ArrayList<>();

@OneToMany(mappedBy = "uuid")
@OneToMany
@ToString.Exclude
@Setter(AccessLevel.NONE)
private List<PartnerProductStock> partnerProductStocks = new ArrayList<>();

public Partner(String name, boolean actsAsCustomerFlag, boolean actsAsSupplierFlag, String edcUrl, String bpnl, String siteBpns) {
public Partner(String name, String edcUrl, String bpnl, String siteBpns) {
this.name = name;
this.actsAsCustomerFlag = actsAsCustomerFlag;
this.actsAsSupplierFlag = actsAsSupplierFlag;
this.edcUrl = edcUrl;
this.bpnl = bpnl;
this.siteBpns = siteBpns;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Partner)) return false;
Partner partner = (Partner) o;
return Objects.equals(uuid, partner.uuid);
}

@Override
public int hashCode() {
return Objects.hash(uuid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.repository;

import org.eclipse.tractusx.puris.backend.masterdata.domain.model.MaterialPartnerRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface MaterialPartnerRelationRepository extends JpaRepository<MaterialPartnerRelation, MaterialPartnerRelation.Key> {

List<MaterialPartnerRelation> findAllByPartner_Uuid(UUID partnerUuid);

List<MaterialPartnerRelation> findAllByPartner_UuidAndPartnerSuppliesMaterialIsTrue(UUID partnerUuid);

List<MaterialPartnerRelation> findAllByPartner_UuidAndPartnerBuysMaterialIsTrue(UUID partnerUuid);

List<MaterialPartnerRelation> findAllByMaterial_OwnMaterialNumber(String ownMaterialNumber);

List<MaterialPartnerRelation> findAllByMaterial_OwnMaterialNumberAndPartnerSuppliesMaterialIsTrue(String ownMaterialNumber);

List<MaterialPartnerRelation> findAllByMaterial_OwnMaterialNumberAndPartnerBuysMaterialIsTrue(String ownMaterialNumber);

List<MaterialPartnerRelation> findAllByPartnerMaterialNumber(String partnerMaterialNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface MaterialRepository extends JpaRepository<Material, UUID> {
public interface MaterialRepository extends JpaRepository<Material, String> {

List<Material> findAllByMaterialFlagTrue();

List<Material> findAllByProductFlagTrue();

public List<Material> findByMaterialNumberCustomer(String materialNumberCustomer);

public List<Material> findByMaterialNumberCx(String materialNumberCx);

public List<Material> findByMaterialNumberCustomerAndMaterialFlagTrue(String materialNumberCustomer);

public List<Material> findByMaterialNumberCustomerAndProductFlagTrue(String materialNumberCustomer);

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,12 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Repository
public interface PartnerRepository extends JpaRepository<Partner, UUID> {

List<Partner> findAllByActsAsCustomerFlagIsTrue();

List<Partner> findAllByActsAsCustomerFlagTrueAndOrdersProducts_Uuid(UUID materialUuid);

List<Partner> findAllByActsAsSupplierFlagTrueAndSuppliesMaterials_Uuid(UUID materialUuid);

List<Partner> findAllByActsAsSupplierFlagTrue();

Optional<Partner> findFirstByBpnl(String bpnl);

Optional<Partner> findFirstBySiteBpns(String siteBpns);
Expand Down
Loading

0 comments on commit 6f14f0a

Please sign in to comment.