use of org.incode.module.document.dom.impl.types.DocumentTypeRepository in project estatio by estatio.
the class BankAccount_attachPdfAsIbanProof method act.
@Action(semantics = SemanticsOf.IDEMPOTENT, commandDtoProcessor = DeriveBlobFromDummyPdfArg0.class)
public BankAccount act(@Parameter(fileAccept = "application/pdf") final Blob document) {
final DocumentType ibanProofDocType = DocumentTypeData.IBAN_PROOF.findUsing(documentTypeRepository);
final List<Paperclip> ibanProofPaperclips = paperclipRepository.findByAttachedToAndRoleName(bankAccount, ROLE_NAME_FOR_IBAN_PROOF);
// delete all existing paperclips for this role whose type is also not IBAN_PROOF
// (ie any incoming invoices that were automatically attached as candidate iban proofs)
final Predicate<Paperclip> hasIbanProofDocType = paperclip -> Objects.equals(ibanProofDocType, paperclip.getDocument().getType());
final Predicate<Paperclip> doesNotHaveIbanProofDocType = hasIbanProofDocType.negate();
ibanProofPaperclips.stream().filter(doesNotHaveIbanProofDocType).forEach(paperclip -> paperclipRepository.delete(paperclip));
final String name = document.getName();
documentService.createAndAttachDocumentForBlob(ibanProofDocType, bankAccount.getAtPath(), name, document, ROLE_NAME_FOR_IBAN_PROOF, bankAccount);
return bankAccount;
}
Aggregations