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