Skip to content

Commit

Permalink
fix: changed to findfirst, sites/addresses now in alphabetical order,…
Browse files Browse the repository at this point in the history
… some javadoc
  • Loading branch information
eschrewe committed Aug 31, 2023
1 parent 8f378b5 commit fb083ab
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ 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().findAny().get().getBpns());
supplierPartner = partnerService.findByBpns(supplierPartner.getSites().stream().findFirst().get().getBpns());
log.info("Found supplier partner by bpns: " + (supplierPartner != null));


Expand Down Expand Up @@ -208,7 +208,7 @@ private void setupCustomerRole() throws JsonProcessingException {
PartnerProductStock partnerProductStockEntity = new PartnerProductStock(
semiconductorMaterial,
10,
supplierPartner.getSites().stream().findAny().get().getBpns(),
supplierPartner.getSites().stream().findFirst().get().getBpns(),
new Date(),
supplierPartner
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,38 @@

/**
* <p>An Address either specifies the usual properties like street, house number,
* zip code, city and country. Or instead of these it may just contain the
* geographical coordinates, specified by longitude and latitude, like
* for example "51.524784N, 7.443659E"</p>
* zip code, city and country.</p>
* <p>All Addresses are uniquely identified by their BPNA</p>
*/
@Embeddable
@NoArgsConstructor
@Getter
@Setter
@ToString
public class Address {
public class Address implements Comparable<Address> {

/**
* 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
Expand All @@ -77,4 +88,9 @@ public boolean equals(Object obj) {
public int hashCode() {
return bpna.hashCode();
}

@Override
public int compareTo(Address o) {
return bpna.compareTo(o.bpna);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* is fulfilled by having at least one BPNS. </p>
* <p>If there is no BPNS, then this Partner has to have at least one
* BPNA, that is not attached to any other BPNS. </p>
*
*/
@Entity
@Table(name = "partner")
Expand All @@ -51,38 +50,66 @@ 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;
@ElementCollection
private Set<Address> addresses = new HashSet<>();
/**
* Contains all Addresses (BPNAs) that are directly assigned to this
* Partner's BPNL.
*/
private SortedSet<Address> addresses = new TreeSet<>();
@OneToMany(cascade = CascadeType.ALL)
private Set<Site> sites = new HashSet<>();
/**
* Contains all Sites (BPNSs) that are assigned to this
* Partner's BPNL. Each BPNS has one or more addresses (BPNAs).
*/
private SortedSet<Site> sites = new TreeSet<>();

@OneToMany(mappedBy = "partner")
/**
* Contains all MaterialPartnerRelations that this Partner is involved in.
*/
private Set<MaterialPartnerRelation> materialPartnerRelations;

@OneToMany
@ToString.Exclude
@Setter(AccessLevel.NONE)
/**
* Contains all ProductStocks that are created for this Partner.
*/
private List<ProductStock> allocatedProductStocksForCustomer = new ArrayList<>();

@OneToMany
@ToString.Exclude
@Setter(AccessLevel.NONE)
/**
* Contains all PartnerProductStocks that this Partner has for us.
*/
private List<PartnerProductStock> partnerProductStocks = new ArrayList<>();

/**
* 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 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
* @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) {
Expand All @@ -95,13 +122,14 @@ public Partner(String name, String edcUrl, String bpnl, String siteBpns, String

/**
* 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 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
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.util.HashSet;
import java.util.Set;
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 it's BPNS.
* 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}.
*/
Expand All @@ -43,24 +43,35 @@
@Getter
@Setter
@ToString
public class Site {
public class Site implements Comparable<Site> {

@Id
@NotNull
/**
* The BPNS of this Site.
*/
private String bpns;
/**
* A human-readable, distinctive name of this site.
*/
private String name;
@ElementCollection
private Set<Address> addresses = new HashSet<>();
/**
* Contains all Addresses (BPNAs) that are directly assigned to this
* Site's BPNS.
*/
private SortedSet<Address> 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 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
* @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;
Expand All @@ -81,4 +92,9 @@ public boolean equals(Object obj) {
public int hashCode() {
return bpns.hashCode();
}

@Override
public int compareTo(Site o) {
return bpns.compareTo(o.bpns);
}
}

0 comments on commit fb083ab

Please sign in to comment.