Search in sources :

Example 1 with MiraklBusinessStakeholderDocumentDownloadExtractService

use of com.paypal.kyc.service.documents.files.mirakl.MiraklBusinessStakeholderDocumentDownloadExtractService in project mirakl-hyperwallet-connector by paypal.

the class MiraklBusinessStakeholderDocumentsExtractServiceImpl method extractBusinessStakeholderDocuments.

/**
 * {@inheritDoc}
 */
@Override
public List<KYCDocumentBusinessStakeHolderInfoModel> extractBusinessStakeholderDocuments(final Date delta) {
    final MiraklGetShopsRequest miraklGetShopsRequest = miraklGetShopsRequestConverter.convert(delta);
    log.info("Retrieving modified shops since [{}]", delta);
    final MiraklShops shops = miraklOperatorClient.getShops(miraklGetShopsRequest);
    // @formatter:off
    log.info("Retrieved modified shops since [{}]: [{}]", delta, Stream.ofNullable(shops.getShops()).flatMap(Collection::stream).map(MiraklShop::getId).collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR)));
    // @formatter:on
    // @formatter:off
    final List<KYCDocumentBusinessStakeHolderInfoModel> kycBusinessStakeHolderInfoModelList = Stream.ofNullable(shops.getShops()).flatMap(Collection::stream).map(this::populateBusinessStakeholderForMiraklShop).flatMap(Collection::stream).collect(Collectors.toList());
    // @formatter:on
    // @formatter:off
    final Map<String, List<KYCDocumentBusinessStakeHolderInfoModel>> shopsWithBusinessStakeholderVerificationRequired = kycBusinessStakeHolderInfoModelList.stream().filter(kycDocStk -> kycDocStk.isRequiresKYC() || kycDocStk.isRequiresLetterOfAuthorization()).collect(Collectors.groupingBy(KYCDocumentInfoModel::getClientUserId));
    if (!CollectionUtils.isEmpty(shopsWithBusinessStakeholderVerificationRequired)) {
        // @formatter:off
        log.info("Shops with KYC business stakeholder verification required: [{}]", String.join(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR, shopsWithBusinessStakeholderVerificationRequired.keySet()));
    // @formatter:on
    }
    skipShopsWithNonBusinessStakeholderSelectedDocuments(shopsWithBusinessStakeholderVerificationRequired);
    final List<KYCDocumentBusinessStakeHolderInfoModel> shopsWithBusinessSelectedVerificationDocuments = shopsWithBusinessStakeholderVerificationRequired.values().stream().filter(bstkList -> bstkList.stream().allMatch(KYCDocumentBusinessStakeHolderInfoModel::hasSelectedDocumentsControlFieldsInBusinessStakeholder)).flatMap(Collection::stream).collect(Collectors.toList());
    // @formatter:off
    return shopsWithBusinessSelectedVerificationDocuments.stream().filter(kycBusinessStakeHolderInfoModel -> !ObjectUtils.isEmpty(kycBusinessStakeHolderInfoModel.getUserToken())).map(miraklBusinessStakeholderDocumentDownloadExtractService::getBusinessStakeholderDocumentsSelectedBySeller).collect(Collectors.toList());
// @formatter:on
}
Also used : IntStream(java.util.stream.IntStream) Converter(com.paypal.infrastructure.converter.Converter) java.util(java.util) MiraklUpdateShopsRequest(com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest) MiraklUpdatedShops(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops) KYCBusinessStakeHolderConverter(com.paypal.kyc.converter.KYCBusinessStakeHolderConverter) MiraklUpdateShop(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop) MiraklException(com.mirakl.client.core.exception.MiraklException) Service(org.springframework.stereotype.Service) MiraklMarketplacePlatformOperatorApiClient(com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient) KYCConstants(com.paypal.kyc.model.KYCConstants) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel) Predicate(java.util.function.Predicate) ObjectUtils(org.springframework.util.ObjectUtils) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) AbstractMiraklShop(com.mirakl.client.mmp.domain.shop.AbstractMiraklShop) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) MiraklAdditionalFieldValue(com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue) MiraklUpdatedShopReturn(com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn) MiraklRequestAdditionalFieldValue(com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue) MiraklBusinessStakeholderDocumentsExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklBusinessStakeholderDocumentsExtractService) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) LoggingConstantsUtil(com.paypal.infrastructure.util.LoggingConstantsUtil) CollectionUtils(org.springframework.util.CollectionUtils) MiraklBusinessStakeholderDocumentDownloadExtractService(com.paypal.kyc.service.documents.files.mirakl.MiraklBusinessStakeholderDocumentDownloadExtractService) KYCDocumentInfoModel(com.paypal.kyc.model.KYCDocumentInfoModel) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) AbstractMiraklShop(com.mirakl.client.mmp.domain.shop.AbstractMiraklShop) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) KYCDocumentBusinessStakeHolderInfoModel(com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)

Aggregations

MiraklException (com.mirakl.client.core.exception.MiraklException)1 MiraklAdditionalFieldValue (com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue)1 AbstractMiraklShop (com.mirakl.client.mmp.domain.shop.AbstractMiraklShop)1 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)1 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)1 MiraklMarketplacePlatformOperatorApiClient (com.mirakl.client.mmp.operator.core.MiraklMarketplacePlatformOperatorApiClient)1 MiraklUpdateShop (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop)1 MiraklUpdatedShopReturn (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShopReturn)1 MiraklUpdatedShops (com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdatedShops)1 MiraklUpdateShopsRequest (com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest)1 MiraklRequestAdditionalFieldValue (com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue)1 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)1 Converter (com.paypal.infrastructure.converter.Converter)1 MailNotificationUtil (com.paypal.infrastructure.mail.MailNotificationUtil)1 LoggingConstantsUtil (com.paypal.infrastructure.util.LoggingConstantsUtil)1 MiraklLoggingErrorsUtil (com.paypal.infrastructure.util.MiraklLoggingErrorsUtil)1 KYCBusinessStakeHolderConverter (com.paypal.kyc.converter.KYCBusinessStakeHolderConverter)1 KYCConstants (com.paypal.kyc.model.KYCConstants)1 KYCDocumentBusinessStakeHolderInfoModel (com.paypal.kyc.model.KYCDocumentBusinessStakeHolderInfoModel)1 KYCDocumentInfoModel (com.paypal.kyc.model.KYCDocumentInfoModel)1