class ApplicationFinanceServiceImpl extends AbstractFinanceService<ApplicationFinance, ApplicationFinanceResource> implements ApplicationFinanceService {

    @Override
    @Transactional
    public ServiceResult<ApplicationFinanceResource> updateApplicationFinance(long applicationFinanceId, ApplicationFinanceResource applicationFinance) {
        return getOpenApplication(applicationFinance.getApplication()).andOnSuccess(app ->
                find(applicationFinance(applicationFinanceId)).andOnSuccess(dbFinance -> {
                    updateFinancialYearData(dbFinance, applicationFinance);
                    if (applicationFinance.getWorkPostcode() != null) {
                        dbFinance.setWorkPostcode(applicationFinance.getWorkPostcode());
                    }
                    if (applicationFinance.getInternationalLocation() != null) {
                        dbFinance.setInternationalLocation(applicationFinance.getInternationalLocation());
                    }

                    if (StringUtils.isEmpty(applicationFinance.getJustification())) {
                        dbFinance.setJustification(null);
                    } else {
                        dbFinance.setJustification(applicationFinance.getJustification());
                    }

                    Long financeFileEntryId = applicationFinance.getFinanceFileEntry();
                    dbFinance = setFinanceUpload(dbFinance, financeFileEntryId);
                    dbFinance = applicationFinanceRepository.save(dbFinance);
                    return serviceSuccess(applicationFinanceMapper.mapToResource(dbFinance));
                })
        );
    }

}