Search in sources :

Example 1 with DocumentTypeRepository

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;
}
Also used : Action(org.apache.isis.applib.annotation.Action) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) PaperclipRepository(org.incode.module.document.dom.impl.paperclips.PaperclipRepository) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) Predicate(java.util.function.Predicate) DocumentTypeRepository(org.incode.module.document.dom.impl.types.DocumentTypeRepository) Objects(java.util.Objects) Inject(javax.inject.Inject) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) List(java.util.List) DocumentService(org.incode.module.document.dom.api.DocumentService) DeriveBlobFromDummyPdfArg0(org.incode.module.base.spi.DeriveBlobFromDummyPdfArg0) BankAccount(org.estatio.module.financial.dom.BankAccount) Parameter(org.apache.isis.applib.annotation.Parameter) Blob(org.apache.isis.applib.value.Blob) DocumentTypeData(org.estatio.module.invoice.dom.DocumentTypeData) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) Action(org.apache.isis.applib.annotation.Action)

Aggregations

List (java.util.List)1 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1 Inject (javax.inject.Inject)1 Action (org.apache.isis.applib.annotation.Action)1 Mixin (org.apache.isis.applib.annotation.Mixin)1 Parameter (org.apache.isis.applib.annotation.Parameter)1 SemanticsOf (org.apache.isis.applib.annotation.SemanticsOf)1 Blob (org.apache.isis.applib.value.Blob)1 BankAccount (org.estatio.module.financial.dom.BankAccount)1 DocumentTypeData (org.estatio.module.invoice.dom.DocumentTypeData)1 DeriveBlobFromDummyPdfArg0 (org.incode.module.base.spi.DeriveBlobFromDummyPdfArg0)1 DocumentService (org.incode.module.document.dom.api.DocumentService)1 Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)1 PaperclipRepository (org.incode.module.document.dom.impl.paperclips.PaperclipRepository)1 DocumentType (org.incode.module.document.dom.impl.types.DocumentType)1 DocumentTypeRepository (org.incode.module.document.dom.impl.types.DocumentTypeRepository)1