@SuppressWarnings("deprecation")
@Override
public Payment convertFrom(PaymentEntity source, Payment destination) {
Payment result = null;
PaymentEntity tmp = null;
if (source != null) {
tmp = HibernateHelper.initializeAndUnproxy(source);
}
if (tmp instanceof IncomingPaymentEntity) {
IncomingPayment incomingPayment = new IncomingPayment();
incomingPayment.setCompleted(tmp.isCompleted());
incomingPayment.setCreationDate(tmp.getCreationDate());
incomingPayment.setDirection(EPaymentDirection.INCOMING);
incomingPayment.setId(tmp.getId());
CustomerEntity customerEntity = ((IncomingPaymentEntity) tmp).getPayer();
Customer customer = null;
if (customerEntity instanceof PersonalCustomerEntity) {
customer = DozerHelper.map(customerEntity, PersonalCustomer.class);
}
if (customerEntity instanceof CorporateCustomerEntity) {
customer = DozerHelper.map(customerEntity, CorporateCustomer.class);
}
incomingPayment.setPayer(customer);
incomingPayment.setPaymentDate(tmp.getPaymentDate());
incomingPayment.setSubject(tmp.getSubject());
Subsidiary subsidiary = DozerHelper.map(tmp.getSubsidiary(),
Subsidiary.class);
incomingPayment.setSubsidiary(subsidiary);
incomingPayment.setTotal(tmp.getTotal());
incomingPayment.setType(tmp.getType());
result = incomingPayment;
}
if (tmp instanceof OutgoingPaymentEntity) {
OutgoingPayment outgoingPayment = new OutgoingPayment();
outgoingPayment.setCompleted(tmp.isCompleted());
outgoingPayment.setCreationDate(tmp.getCreationDate());
outgoingPayment.setDirection(EPaymentDirection.OUTGOING);
outgoingPayment.setId(tmp.getId());
outgoingPayment.setPaymentDate(tmp.getPaymentDate());
EmployeeEntity employeeEntity = ((OutgoingPaymentEntity) tmp)
.getRecipient();
Employee employee = null;
if (employeeEntity instanceof MechanicEntity) {
employee = DozerHelper.map(employee, Mechanic.class);
}
if (employeeEntity instanceof EmployeeEntity) {
employee = DozerHelper.map(employee, Employee.class);
}
outgoingPayment.setRecipient(employee);
outgoingPayment.setSubject(tmp.getSubject());
Subsidiary subsidiary = DozerHelper.map(tmp.getSubsidiary(),
Subsidiary.class);
outgoingPayment.setSubsidiary(subsidiary);
outgoingPayment.setTotal(tmp.getTotal());
outgoingPayment.setType(tmp.getType());
result = outgoingPayment;
}
return result;