All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.adorsys.multibanking.impl.BookingRepositoryImpl Maven / Gradle / Ivy

There is a newer version: 4.3.9
Show newest version
package de.adorsys.multibanking.impl;

import de.adorsys.multibanking.domain.BookingEntity;
import de.adorsys.multibanking.pers.spi.repository.BookingRepositoryIf;
import de.adorsys.multibanking.repository.BookingPageableRepositoryMongodb;
import de.adorsys.multibanking.repository.BookingRepositoryMongodb;
import domain.BankApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Profile({"mongo", "fongo"})
@Service
public class BookingRepositoryImpl implements BookingRepositoryIf {

	@Autowired
    private BookingRepositoryMongodb bookingRepository;
	@Autowired
	private BookingPageableRepositoryMongodb bookingPageableRepositoryMongodb;

	@Override
	public Page findPageableByUserIdAndAccountIdAndBankApi(Pageable pageable, String userId, String bankAccountId, BankApi bankApi) {
		return bookingPageableRepositoryMongodb.findByUserIdAndAccountIdAndBankApi(pageable, userId, bankAccountId, bankApi);
	}

	@Override
	public List findByUserIdAndAccountIdAndBankApi(String userId, String bankAccountId,
			BankApi bankApi) {
		return bookingRepository.findByUserIdAndAccountIdAndBankApi(userId, bankAccountId, bankApi, new Sort(Sort.Direction.DESC, "valutaDate"));
	}

	@Override
	public Optional findByUserIdAndId(String userId, String bookingId) {
		return bookingRepository.findByUserIdAndId(userId, bookingId);
	}

	@Override
	public Iterable findByUserIdAndIds(String name, List ids) {
        return bookingRepository.findAllById(ids);
	}


	@Override
	public List save(List bookingEntities) {
        List newEntities = bookingEntities
                .stream()
                .filter(bookingEntity -> bookingEntity.getId() == null)
                .collect(Collectors.toList());
        try {
            bookingRepository.insert(newEntities);
        } catch (DuplicateKeyException e) {
            //ignore it
        }

        List existingEntities = bookingEntities
                .stream()
                .filter(bookingEntity -> bookingEntity.getId() != null)
                .collect(Collectors.toList());

		return bookingRepository.saveAll(existingEntities);
	}

	@Override
	public void deleteByAccountId(String id) {
		bookingRepository.deleteByAccountId(id);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy