import nl.strohalm.cyclos.entities.accounts.Currency; //导入方法依赖的package包/类
@Override
public ValidationError validate(final Object object, final Object property, final Object value) {
final TransferType transferType = (TransferType) object;
// Get source and destination account types
final AccountType from = fetchService.fetch(transferType.getFrom(), AccountType.Relationships.CURRENCY);
AccountType to = (AccountType) value;
// Validate if the currency of the source account type is the same currency of the destination account type
final Currency sourceAccountTypeCurrency = from.getCurrency();
to = fetchService.fetch(to, AccountType.Relationships.CURRENCY);
final Currency destinationAccountTypeCurrency = to.getCurrency();
if (!sourceAccountTypeCurrency.equals(destinationAccountTypeCurrency)) {
return new ValidationError("transferType.error.invalidDestinationType");
}
if (from != null && to != null) {
if (from.equals(to) && from.getNature() == AccountType.Nature.SYSTEM) {
// Cannot be from and to the same account if system
return new InvalidError();
}
if (transferType.isLoanType() && ((from.getNature() == AccountType.Nature.MEMBER) || (to.getNature() == AccountType.Nature.SYSTEM))) {
// When is a loan, can only be from system to member
return new InvalidError();
}
}
return null;
}