Search in sources :

Example 36 with Document

use of org.jbpm.document.Document in project jbpm-work-items by kiegroup.

the class GoogleDriveWorkitemHandlerTest method testDownload.

@Test
public void testDownload() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("DocumentPath", "/some/download/path/testdoc.txt");
    MediaDownloadWorkitemHandler handler = new MediaDownloadWorkitemHandler("myAppName", "{}");
    handler.setAuth(auth);
    handler.executeWorkItem(workItem, manager);
    assertNotNull(manager.getResults());
    assertEquals(1, manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
    assertTrue((manager.getResults().get(workItem.getId())).get("Document") instanceof Document);
    Document downloadedDoc = (Document) manager.getResults().get(workItem.getId()).get("Document");
    assertNotNull(downloadedDoc);
    assertEquals("testdoc.txt", downloadedDoc.getName());
    assertEquals("/some/download/path/testdoc.txt", downloadedDoc.getIdentifier());
    assertEquals("test doc content", new String(downloadedDoc.getContent()));
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Matchers.anyString(org.mockito.Matchers.anyString) Document(org.jbpm.document.Document) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with Document

use of org.jbpm.document.Document in project jbpm-work-items by kiegroup.

the class SendMailWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    String paramTo = (String) workItem.getParameter("To");
    String paramFrom = (String) workItem.getParameter("From");
    String paramSubject = (String) workItem.getParameter("Subject");
    String paramBodyText = (String) workItem.getParameter("BodyText");
    Document paramAttachment = (Document) workItem.getParameter("Attachment");
    try {
        Gmail gmailService = auth.getGmailService(appName, clientSecret);
        Message outEmailMessage = sendMessage(gmailService, paramTo, paramFrom, paramSubject, paramBodyText, paramAttachment);
    } catch (Exception e) {
        handleException(e);
    }
    workItemManager.completeWorkItem(workItem.getId(), null);
}
Also used : Message(com.google.api.services.gmail.model.Message) MimeMessage(javax.mail.internet.MimeMessage) Gmail(com.google.api.services.gmail.Gmail) Document(org.jbpm.document.Document) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Example 38 with Document

use of org.jbpm.document.Document in project jbpm-work-items by kiegroup.

the class UploadFileWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        if (auth == null) {
            auth = new DropboxAuth();
        }
        client = auth.authorize(clientIdentifier, accessToken);
        String dropboxPath = (String) workItem.getParameter("Path");
        Document documentToUpload = (Document) workItem.getParameter("Document");
        ByteArrayInputStream docStream = new ByteArrayInputStream(documentToUpload.getContent());
        client.files().uploadBuilder(dropboxPath + "/" + documentToUpload.getName()).withMode(WriteMode.ADD).withClientModified(documentToUpload.getLastModified()).uploadAndFinish(docStream);
        workItemManager.completeWorkItem(workItem.getId(), null);
    } catch (Exception e) {
        logger.error("Unable to upload file: " + e.getMessage());
        handleException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Document(org.jbpm.document.Document)

Aggregations

Document (org.jbpm.document.Document)38 Test (org.junit.Test)21 Date (java.util.Date)14 DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)9 HashMap (java.util.HashMap)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DocumentData (org.kie.workbench.common.forms.dynamic.model.document.DocumentData)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Documents (org.jbpm.document.Documents)3 Drive (com.google.api.services.drive.Drive)2 VisualRecognition (com.ibm.watson.developer_cloud.visual_recognition.v3.VisualRecognition)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 DroolsObjectInputStream (org.drools.core.common.DroolsObjectInputStream)2 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)2 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)2