use of com.paypal.kyc.model.KYCDocumentNotificationModel in project mirakl-hyperwallet-connector by paypal.
the class AbstractKYCUserStatusNotificationStrategy method deleteInvalidDocuments.
protected void deleteInvalidDocuments(final KYCUserStatusNotificationBodyModel kycUserNotification) {
final String clientUserId = kycUserNotification.getClientUserId();
final KYCDocumentInfoModel kycDocumentInfoModel = miraklSellerDocumentsExtractService.extractKYCSellerDocuments(clientUserId);
final Map<String, LocalDateTime> documentsToBeDeleted = kycUserNotification.getDocuments().stream().filter(kycDocumentNotificationModel -> KYCDocumentStatusEnum.INVALID.equals(kycDocumentNotificationModel.getDocumentStatus())).map(kycDocumentNotificationModel -> Pair.of(kycDocumentNotificationModelListConverter.convert(kycDocumentNotificationModel), kycDocumentNotificationModel.getCreatedOn())).map(this::getMapDocumentUploadTime).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(documentsToBeDeleted)) {
final List<MiraklShopDocument> miraklDocumentsToBeDeleted = kycDocumentInfoModel.getMiraklShopDocuments().stream().filter(miraklShopDocument -> documentsToBeDeleted.containsKey(miraklShopDocument.getTypeCode())).filter(Predicate.not(miraklShopDocument -> isANewMiraklDocument(documentsToBeDeleted, miraklShopDocument))).collect(Collectors.toList());
final String documentTypeCodesToBeDeleted = miraklDocumentsToBeDeleted.stream().map(MiraklShopDocument::getTypeCode).collect(Collectors.joining(COMMA));
if (!StringUtils.isEmpty(documentTypeCodesToBeDeleted)) {
log.info("Deleting documents [{}] for shop [{}]", documentTypeCodesToBeDeleted, clientUserId);
miraklSellerDocumentsExtractService.deleteDocuments(miraklDocumentsToBeDeleted);
log.info("Documents deleted");
}
}
}
Aggregations