FECRequestDealLink.java
package com.tradecloud.domain.model;
import com.tradecloud.domain.common.Percentage;
import com.tradecloud.domain.helper.XMLHelper;
import com.tradecloud.domain.model.deal.Deal;
import com.tradecloud.domain.model.fecrequest.FECRequest;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.io.Serializable;
/**
* The linkage between the FEC requests and DEALs.
*/
@SuppressWarnings("serial")
@Entity
@Table(name = "fec_request_deal_link")
public class FECRequestDealLink extends DealLink implements Serializable {
@ManyToOne(fetch = FetchType.EAGER, optional = false)
public FECRequest fecRequest;
/**
* This constructor is for Hibernate use only.
*/
public FECRequestDealLink() {
}
public FECRequestDealLink(Deal deal, FECRequest fecRequest, Money amount, Percentage percentage) {
super(deal, amount, percentage);
this.fecRequest = fecRequest;
}
public FECRequest getFecRequest() {
return fecRequest;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getAmount() == null) ? 0 : getAmount().hashCode());
result = prime * result + ((getDeal() == null) ? 0 : getDeal().hashCode());
result = prime * result + ((fecRequest == null) ? 0 : fecRequest.hashCode());
result = prime * result + ((getPercentage() == null) ? 0 : getPercentage().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FECRequestDealLink other = (FECRequestDealLink) obj;
if (getAmount() == null) {
if (other.getAmount() != null)
return false;
} else if (!getAmount().equals(other.getAmount()))
return false;
if (getDeal() == null) {
if (other.getDeal() != null)
return false;
} else if (!getDeal().equals(other.getDeal()))
return false;
if (fecRequest == null) {
if (other.fecRequest != null)
return false;
} else if (!fecRequest.equals(other.fecRequest))
return false;
if (getPercentage() == null) {
if (other.getPercentage() != null)
return false;
} else if (!getPercentage().equals(other.getPercentage()))
return false;
return true;
}
public String getStateAsXML() {
StringBuilder result = new StringBuilder();
result.append("<fecRequestDealLink>");
result.append("<dealId>").append(getDeal().getId()).append("</dealId>");
result.append("<fecRequestId>").append(fecRequest.getId()).append("</fecRequestId>");
result.append("<amount>").append(XMLHelper.getMoneyXML(getAmount())).append("</amount>");
result.append("<percentage>").append(getPercentage().getValue()).append("</percentage>");
result.append("</fecRequestDealLink>");
return result.toString();
}
}