class EuGrantTransferServiceImpl implements EuGrantTransferService {

    @Override
    @Transactional
    public ServiceResult<Void> updateGrantTransferByApplicationId(EuGrantTransferResource euGrantTransferResource, long applicationId) {
        return findGrantTransferByApplicationIdCreateIfNotExists(applicationId).andOnSuccessReturnVoid(domain -> {
            domain.setGrantAgreementNumber(euGrantTransferResource.getGrantAgreementNumber());
            domain.setParticipantId(euGrantTransferResource.getParticipantId());
            domain.setProjectStartDate(euGrantTransferResource.getProjectStartDate());
            domain.setProjectEndDate(euGrantTransferResource.getProjectEndDate());
            domain.setFundingContribution(euGrantTransferResource.getFundingContribution());
            domain.setProjectCoordinator(euGrantTransferResource.getProjectCoordinator());

            ofNullable(euGrantTransferResource.getProjectEndDate()).ifPresent(endDate -> {
                long duration = Period.between(horizon2020StartDate, endDate).toTotalMonths();
                domain.getApplication().setDurationInMonths(max(duration, 1L));
                domain.getApplication().setStartDate(horizon2020StartDate);
            });

            ofNullable(euGrantTransferResource.getActionType())
                    .map(EuActionTypeResource::getId)
                    .ifPresent(id -> {
                        EuActionType type = new EuActionType();
                        type.setId(id);
                        domain.setActionType(type);
                    });

            domain.getApplication().setName(euGrantTransferResource.getProjectName());
        });
    }

}