Search in sources :

Example 6 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method attachAndAssertPoliceReport.

protected void attachAndAssertPoliceReport() {
    caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Submit police report", null);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertNotNull(tasks);
    assertEquals(2, tasks.size());
    assertTask(tasks.get(0), null, "Submit police report", Status.Ready);
    assertTask(tasks.get(1), null, "File property damage claim", Status.Ready);
    byte[] docContent = "police report content".getBytes();
    DocumentImpl document = new DocumentImpl(UUID.randomUUID().toString(), "car-accident-police-report.txt", docContent.length, new Date());
    document.setContent(docContent);
    Map<String, Object> params = new HashMap<>();
    params.put("policeReport_", document);
    userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
    // police report should be stored in case file data
    CaseFileInstance caseFile = caseService.getCaseFileInstance(CAR_INS_CASE_ID);
    assertNotNull(caseFile);
    Document policeReport = (Document) caseFile.getData("policeReport");
    assertNotNull(policeReport);
    assertEquals("car-accident-police-report.txt", policeReport.getName());
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date)

Example 7 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.

the class MediaDownloadWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Map<String, Object> results = new HashMap<String, Object>();
    String documentPath = (String) workItem.getParameter("DocumentPath");
    if (documentPath != null) {
        try {
            Drive drive = auth.getDriveService(appName, clientSecret);
            Drive.Files.Get request = drive.files().get(documentPath);
            request.getMediaHttpDownloader().setProgressListener(new MediaDownloadProgressListener());
            request.getMediaHttpDownloader().setDirectDownloadEnabled(true);
            InputStream docInputStream = request.executeMediaAsInputStream();
            Document doc = new DocumentImpl();
            String docBaseName = FilenameUtils.getBaseName(documentPath);
            String docExtension = FilenameUtils.getExtension(documentPath);
            doc.setName(docBaseName + "." + docExtension);
            doc.setIdentifier(documentPath);
            doc.setLastModified(new Date());
            doc.setContent(IOUtils.toByteArray(docInputStream));
            results.put(RESULTS_DOCUMENT, doc);
            workItemManager.completeWorkItem(workItem.getId(), results);
        } catch (Exception e) {
            handleException(e);
        }
    } else {
        logger.error("Missing download document information.");
        throw new IllegalArgumentException("Missing download document information.");
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Drive(com.google.api.services.drive.Drive)

Example 8 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.

the class GoogleDriveWorkitemHandlerTest method testUpload.

@Test
public void testUpload() throws Exception {
    DocumentImpl testUploadDoc = new DocumentImpl();
    testUploadDoc.setContent(new String("Test file to upload").getBytes());
    testUploadDoc.setName("testFileToUpload.txt");
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("DocToUpload", testUploadDoc);
    workItem.setParameter("DocMimeType", "text/plain");
    workItem.setParameter("UploadPath", "/some/upload/path");
    MediaUploadWorkitemHandler handler = new MediaUploadWorkitemHandler("myAppName", "{}");
    handler.setAuth(auth);
    handler.executeWorkItem(workItem, manager);
    assertNotNull(manager.getResults());
    assertEquals(1, manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Matchers.anyString(org.mockito.Matchers.anyString) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.

the class GoogleMailWorkitemHandlerTest method testSendEmailWithAttachment.

@Test
public void testSendEmailWithAttachment() throws Exception {
    DocumentImpl attachmentDoc = new DocumentImpl();
    attachmentDoc.setContent(new String("Attachment sources").getBytes());
    attachmentDoc.setName("attachmentFileName.txt");
    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("To", "someone@gmail.com");
    workItem.setParameter("From", "me@gmail.com");
    workItem.setParameter("Subject", "Hello!");
    workItem.setParameter("BodyText", "Hello from me!");
    workItem.setParameter("Attachment", attachmentDoc);
    SendMailWorkitemHandler handler = new SendMailWorkitemHandler("myAppName", "{}");
    handler.setAuth(auth);
    handler.executeWorkItem(workItem, manager);
    assertNotNull(manager.getResults());
    assertEquals(1, manager.getResults().size());
    assertTrue(manager.getResults().containsKey(workItem.getId()));
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Matchers.anyString(org.mockito.Matchers.anyString) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 10 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project jbpm-work-items by kiegroup.

the class DownloadFileWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Map<String, Object> results = new HashMap<String, Object>();
    try {
        if (auth == null) {
            auth = new DropboxAuth();
        }
        client = auth.authorize(clientIdentifier, accessToken);
        String dropboxDocumentPath = (String) workItem.getParameter("DocumentPath");
        InputStream inStream = client.files().downloadBuilder(dropboxDocumentPath).start().getInputStream();
        Path path = Paths.get(dropboxDocumentPath);
        Document doc = new DocumentImpl();
        doc.setName(path.getFileName().toString());
        doc.setIdentifier(dropboxDocumentPath);
        doc.setLastModified(new Date());
        doc.setContent(IOUtils.toByteArray(inStream));
        results.put(RESULTS_DOCUMENT, doc);
        workItemManager.completeWorkItem(workItem.getId(), results);
    } catch (Exception e) {
        logger.error("Unable to download file: " + e.getMessage());
        handleException(e);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date)

Aggregations

DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)16 Date (java.util.Date)10 Test (org.junit.Test)10 Document (org.jbpm.document.Document)9 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)6 HashMap (java.util.HashMap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)4 InputStream (java.io.InputStream)3 DocumentData (org.kie.workbench.common.forms.dynamic.model.document.DocumentData)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 WriteMode (com.dropbox.core.v2.files.WriteMode)1 Drive (com.google.api.services.drive.Drive)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1