
nl.tno.bim.mapping.domain.Mapping Maven / Gradle / Ivy
package nl.tno.bim.mapping.domain;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
@Entity
@Table(name = "mappings")
public class Mapping {
@Id
@GeneratedValue
private Long id;
@Column(name = "nmd_totaal_product_id")
private Long nmdTotaalProductId;
@Column(name = "nlsfb_code")
private String nlsfbCode;
@Column(name = "own_ifc_type")
private String ownIfcType;
@Column(name = "query_ifc_type")
private String queryIfcType;
@OneToMany(mappedBy = "mappingSet", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JsonIgnore
List mappingSetMaps;
@JsonManagedReference(value = "materialmapping-1")
@OneToMany(mappedBy = "mapping", cascade = CascadeType.ALL)
List materialMappings;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getNmdTotaalProductId() {
return nmdTotaalProductId;
}
public void setNmdTotaalProductId(Long nmdTotaalProductId) {
this.nmdTotaalProductId = nmdTotaalProductId;
}
public String getNlsfbCode() {
return nlsfbCode;
}
public void setNlsfbCode(String nlsfbCode) {
this.nlsfbCode = nlsfbCode;
}
public String getOwnIfcType() {
return ownIfcType;
}
public void setOwnIfcType(String ownIfcType) {
this.ownIfcType = ownIfcType;
}
public String getQueryIfcType() {
return queryIfcType;
}
public void setQueryIfcType(String queryIfcType) {
this.queryIfcType = queryIfcType;
}
public List getMappingSetMaps() {
return mappingSetMaps;
}
public void setMappingSetMaps(List mappingSetMaps) {
this.mappingSetMaps = mappingSetMaps;
}
public List getMaterialMappings() {
return materialMappings;
}
public void setMaterialMappings(List materialMappings) {
this.materialMappings = materialMappings;
}
@JsonIgnore
public List getAllNmdProductIds() {
List res = new ArrayList<>();
if (this.nmdTotaalProductId != null) {
res.add(this.nmdTotaalProductId);
}
this.materialMappings.forEach(mMap -> {
if (mMap.getNmdProductId() != null && mMap.getNmdProductId() > 0) {
res.add(mMap.getNmdProductId());
}
});
return res;
}
/**
* method to check whether this object is equal in values (no record ids) to
* another Mappings object
*
* @return
*/
public boolean equalByValues(Mapping other) {
boolean propertiesAreEqual = this.getNmdTotaalProductId() == other.getNmdTotaalProductId()
&& this.getNlsfbCode().equals(other.getNlsfbCode())
&& this.getOwnIfcType().equals(other.getOwnIfcType())
&& this.getQueryIfcType().equals(other.getQueryIfcType());
// quick check by dimensions
int thisSize = this.getMaterialMappings() == null ? -1 : this.getMaterialMappings().size();
int otherSize = other.getMaterialMappings() == null ? -1 : other.getMaterialMappings().size();
if ((thisSize != otherSize) || !propertiesAreEqual) {
return false;
}
// lists are empty or have th esame elements.
return (thisSize <= 0) || this.getMaterialMappings().stream()
.allMatch(mMap1 -> other.getMaterialMappings().stream().anyMatch(mMap2 -> mMap1.equalByValues(mMap2)));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy