class CmsAspspAisExportServiceInternal implements CmsAspspAisExportService {

    @Override
    @Transactional
    public Collection<CmsAisAccountConsent> exportConsentsByAccountId(@NotNull String aspspAccountId,
                                                                      @Nullable LocalDate createDateFrom,
                                                                      @Nullable LocalDate createDateTo,
                                                                      @NotNull String instanceId) {

        if (StringUtils.isBlank(instanceId)) {
            log.info("InstanceId: [{}], aspspAccountId: [{}]. Export consents by accountId failed, instanceId is empty or null.",
                     instanceId, aspspAccountId);
            return Collections.emptyList();
        }

        Specification<ConsentEntity> specification = aisConsentSpecification.byAspspAccountIdAndCreationPeriodAndInstanceId(aspspAccountId,
                                                                                                                            createDateFrom,
                                                                                                                            createDateTo,
                                                                                                                            instanceId);
        List<ConsentEntity> consents = consentJpaRepository.findAll(specification)
                                           .stream()
                                           .distinct()
                                           .map(aisConsentLazyMigrationService::migrateIfNeeded)
                                           .collect(Collectors.toList());

        return consents
                   .stream()
                   .map(this::mapToCmsAisAccountConsentWithAuthorisations)
                   .collect(Collectors.toList());
    }

}