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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations