Search in sources :

Example 1 with FileAttachmentData

use of io.lumeer.core.task.executor.operation.data.FileAttachmentData in project engine by Lumeer.

the class LumeerBridge method writePdf.

@SuppressWarnings("unused")
public void writePdf(final LinkBridge l, final String attrId, final String fileName, final boolean overwrite, final String html) throws IOException {
    try {
        if (html.length() > 5L * 1024 * 1024) {
            throw new IllegalArgumentException("Input HTML too large.");
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfCreator.createPdf(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)), baos);
        var relatedOperation = setLinkAttribute(l, attrId, Value.asValue(getUpdateFileAttachmentsList(l, attrId, fileName, overwrite)));
        operations.add(new AddLinkFileAttachmentOperation(l.getLink(), attrId, new FileAttachmentData(baos.toByteArray(), fileName, overwrite), relatedOperation));
    } catch (Exception e) {
        cause = e;
        throw e;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AddLinkFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation)

Example 2 with FileAttachmentData

use of io.lumeer.core.task.executor.operation.data.FileAttachmentData in project engine by Lumeer.

the class LumeerBridge method writePdf.

@SuppressWarnings("unused")
public void writePdf(final DocumentBridge d, final String attrId, final String fileName, final boolean overwrite, final String html) throws IOException {
    try {
        if (html.length() > 5L * 1024 * 1024) {
            throw new IllegalArgumentException("Input HTML too large.");
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfCreator.createPdf(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)), baos);
        var relatedOperation = setDocumentAttribute(d, attrId, Value.asValue(getUpdateFileAttachmentsList(d, attrId, fileName, overwrite)));
        operations.add(new AddDocumentFileAttachmentOperation(d.getDocument(), attrId, new FileAttachmentData(baos.toByteArray(), fileName, overwrite), relatedOperation));
    } catch (Exception e) {
        cause = e;
        throw e;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

FileAttachmentData (io.lumeer.core.task.executor.operation.data.FileAttachmentData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 AddDocumentFileAttachmentOperation (io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation)1 AddLinkFileAttachmentOperation (io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation)1