Search in sources :

Example 6 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class DocAndCommAbstract_download method act.

@Action(semantics = SemanticsOf.SAFE, invokeOn = InvokeOn.OBJECT_ONLY)
@ActionLayout(contributed = Contributed.AS_ACTION)
public Blob act() throws IOException {
    final List<byte[]> pdfBytes = Lists.newArrayList();
    final Document document = getDocument();
    appendBytes(document, pdfBytes);
    final List<Document> supportingDocs = attachmentsProvider.attachmentsFor(document);
    for (Document supportingDoc : supportingDocs) {
        appendBytes(supportingDoc, pdfBytes);
    }
    final byte[] mergedBytes = pdfBoxService.merge(pdfBytes.toArray(new byte[][] {}));
    return new Blob(fileName, MIME_TYPE_APPLICATION_PDF, mergedBytes);
}
Also used : Blob(org.apache.isis.applib.value.Blob) Document(org.incode.module.document.dom.impl.docs.Document) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 7 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class DocAndCommAbstract_downloadSelected method act.

@Action(semantics = SemanticsOf.SAFE, invokeOn = InvokeOn.COLLECTION_ONLY)
@ActionLayout(contributed = Contributed.AS_ACTION)
public Object act() throws IOException {
    final List<byte[]> pdfBytes = createOrLookupPdfBytes();
    final Document document = getDocument();
    // we just ignore those that do not
    if (document != null) {
        appendBytes(document, pdfBytes);
        final List<Document> supportingDocs = attachmentsProvider.attachmentsFor(document);
        for (Document supportingDoc : supportingDocs) {
            appendBytes(supportingDoc, pdfBytes);
        }
    }
    if (interactionContext.isLast()) {
        if (pdfBytes.isEmpty()) {
            messageService.warnUser("No documents to be merged");
            return null;
        }
        final byte[] mergedBytes = pdfBoxService.merge(pdfBytes.toArray(new byte[][] {}));
        return new Blob(fileName, MIME_TYPE_APPLICATION_PDF, mergedBytes);
    }
    return null;
}
Also used : Blob(org.apache.isis.applib.value.Blob) Document(org.incode.module.document.dom.impl.docs.Document) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 8 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class Invoice_DocumentManagement_IntegTest method asBlob.

static Blob asBlob(final String fileName) throws IOException {
    final URL url = Resources.getResource(Invoice_DocumentManagement_IntegTest.class, fileName);
    final byte[] bytes = Resources.toByteArray(url);
    return new Blob(fileName, "application/pdf", bytes);
}
Also used : Blob(org.apache.isis.applib.value.Blob) URL(java.net.URL)

Example 9 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class Communication_downloadPdfForPosting method appendBytes.

private void appendBytes(final Document document, final List<byte[]> pdfBytes) {
    final Blob blob = asBlob(document);
    final byte[] bytes = blob.getBytes();
    pdfBytes.add(bytes);
}
Also used : Document_downloadExternalUrlAsBlob(org.incode.module.document.dom.impl.docs.Document_downloadExternalUrlAsBlob) Blob(org.apache.isis.applib.value.Blob)

Example 10 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class Communication_downloadPdfForPosting method act.

@Action(semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(named = "Download PDF for posting", cssClassFa = "download")
public Blob act(@ParameterLayout(named = "File name") final String fileName) throws IOException {
    // the act of downloading implicitly sends the communication
    if (communication.getState() == CommunicationState.PENDING) {
        communication.sent();
    }
    final List<byte[]> pdfBytes = Lists.newArrayList();
    final Document primaryDoc = communication.getPrimaryDocument();
    appendBytes(primaryDoc, pdfBytes);
    // merge any and all attachments
    final List<Document> attachedDocuments = findAttachedPdfDocuments();
    attachedDocuments.sort(Ordering.natural().onResultOf(Document::getCreatedAt));
    for (final Document attachedDoc : attachedDocuments) {
        appendBytes(attachedDoc, pdfBytes);
    }
    final byte[] mergedBytes = pdfBoxService.merge(pdfBytes.toArray(new byte[][] {}));
    return new Blob(fileName, DocumentConstants.MIME_TYPE_APPLICATION_PDF, mergedBytes);
}
Also used : Document_downloadExternalUrlAsBlob(org.incode.module.document.dom.impl.docs.Document_downloadExternalUrlAsBlob) Blob(org.apache.isis.applib.value.Blob) Document(org.incode.module.document.dom.impl.docs.Document) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

Blob (org.apache.isis.applib.value.Blob)19 Action (org.apache.isis.applib.annotation.Action)10 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)8 Document (org.incode.module.document.dom.impl.docs.Document)7 List (java.util.List)4 SemanticsOf (org.apache.isis.applib.annotation.SemanticsOf)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 DomainObject (org.apache.isis.applib.annotation.DomainObject)3 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)3 Nature (org.apache.isis.applib.annotation.Nature)3 Clob (org.apache.isis.applib.value.Clob)3 LocalDate (org.joda.time.LocalDate)3 URL (java.net.URL)2 Getter (lombok.Getter)2 Setter (lombok.Setter)2 CollectionLayout (org.apache.isis.applib.annotation.CollectionLayout)2 Contributed (org.apache.isis.applib.annotation.Contributed)2 Parameter (org.apache.isis.applib.annotation.Parameter)2