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