use of org.incode.module.document.dom.impl.docs.Document in project estatio by estatio.
the class Communication method sendByEmail.
// so can invoke via BackgroundService
@Action(hidden = Where.EVERYWHERE)
public Communication sendByEmail() {
// body...
final Document coverNoteDoc = findDocument(DocumentConstants.PAPERCLIP_ROLE_COVER);
final String emailBody = coverNoteDoc.asChars();
// (email) attachments..
// this corresponds to the primary document and any attachments
final List<DataSource> attachments = Lists.newArrayList();
final Document primaryDocument = getPrimaryDocument();
if (primaryDocument != null) {
// should be the case
attachments.add(primaryDocument.asDataSource());
}
attachments.addAll(findDocumentsInRoleAsStream(DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT).map(DocumentAbstract::asDataSource).collect(Collectors.toList()));
// cc..
final List<String> toList = findCorrespondents(CommChannelRoleType.TO);
final List<String> ccList = findCorrespondents(CommChannelRoleType.CC);
final List<String> bccList = findCorrespondents(CommChannelRoleType.BCC);
// subject ...
final String subject = getSubject();
// finally, we send
final boolean send = emailService.send(toList, ccList, bccList, subject, emailBody, attachments.toArray(new DataSource[] {}));
if (!send) {
throw new ApplicationException("Failed to send email; see system logs for details.");
}
// mark this comm as having been sent.
sent();
return this;
}
use of org.incode.module.document.dom.impl.docs.Document 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);
}
use of org.incode.module.document.dom.impl.docs.Document in project estatio by estatio.
the class SuppressContributionsForCoverNoteDocument method hideIfCoverNote.
private void hideIfCoverNote(final org.apache.isis.applib.services.eventbus.ActionDomainEvent<?> ev) {
if (ev.getEventPhase() != AbstractDomainEvent.Phase.HIDE) {
return;
}
final Object mixedIn = ev.getMixedIn();
if (!(mixedIn instanceof Document)) {
return;
}
final Document document = (Document) mixedIn;
final Communication communication = evaluator.coverNoteFor(document);
if (communication != null) {
ev.hide();
}
}
use of org.incode.module.document.dom.impl.docs.Document in project estatio by estatio.
the class Document_sendByPost method act.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT, domainEvent = ActionDomainEvent.class)
@ActionLayout(cssClassFa = "envelope-o", contributed = Contributed.AS_ACTION)
public Communication act(@ParameterLayout(named = "to:") final PostalAddress toChannel) throws IOException {
if (this.document.getState() == DocumentState.NOT_RENDERED) {
// this shouldn't happen, but want to fail-fast in case a future programmer calls this directly
throw new IllegalArgumentException("Document is not yet rendered");
}
// create comm and correspondents
final String atPath = document.getAtPath();
final String subject = document.getName();
final Communication communication = communicationRepository.createPostal(subject, atPath, toChannel);
transactionService.flushTransaction();
// attach this "primary" document to the comm
paperclipRepository.attach(this.document, DocumentConstants.PAPERCLIP_ROLE_PRIMARY, communication);
// also copy over as attachments to the comm anything else also attached to original document
final List<Document> communicationAttachments = attachmentProvider.attachmentsFor(document);
for (Document communicationAttachment : communicationAttachments) {
paperclipRepository.attach(communicationAttachment, DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT, communication);
}
transactionService.flushTransaction();
return communication;
}
use of org.incode.module.document.dom.impl.docs.Document in project estatio by estatio.
the class DocumentService method createAndAttachDocumentForBlob.
/**
* @param documentName - override the name of the blob (if null, then uses the blob's name)
*/
@Programmatic
public Document createAndAttachDocumentForBlob(final DocumentType documentType, final String documentAtPath, String documentName, final Blob blob, final String paperclipRoleName, final Object paperclipAttachTo) {
final Document document = createForBlob(documentType, documentAtPath, documentName, blob);
paperclipRepository.attach(document, paperclipRoleName, paperclipAttachTo);
return document;
}
Aggregations