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 entity #16

Large diffs are not rendered by default.

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 @@ -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
Expand Up @@ -30,8 +30,8 @@
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SuccessfullRequestDto {
public class SuccessfulRequestDto {

@JsonProperty("request-id")
@JsonProperty("requestId")
private UUID requestId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ public class VariablesService {

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

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

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

/**
* Returns the asset-id as defined in the properties file for the given api method
* under request.apiassetid or response.apiassetid respectively.
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,85 @@
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,26 @@
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);

}
Loading
Loading