use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentImplTest method testFullConstructor.
@Test
public void testFullConstructor() {
Document document = new DocumentImpl(ID, NAME, SIZE, LAST_MODIFIED, LINK);
Assertions.assertThat(document.getIdentifier()).isNotNull().isEqualTo(ID);
Assertions.assertThat(document.getName()).isNotNull().isEqualTo(NAME);
Assertions.assertThat(document.getSize()).isEqualTo(SIZE);
Assertions.assertThat(document.getLastModified()).isEqualTo(LAST_MODIFIED);
Assertions.assertThat(document.getLink()).isNotNull().isNotEmpty().isEqualTo(LINK);
}
use of org.jbpm.document.Document in project jbpm by kiegroup.
the class DocumentImplTest method testDefaultConstructor.
@Test
public void testDefaultConstructor() {
Document document = new DocumentImpl();
Assertions.assertThat(document.getIdentifier()).isNotNull();
}
use of org.jbpm.document.Document in project jbpm-work-items by kiegroup.
the class UpdateStatusWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
String statusMessage = (String) workItem.getParameter("StatusUpdate");
// media is optional
Document statusMedia = null;
if (workItem.getParameter("Media") != null) {
statusMedia = (Document) workItem.getParameter("Media");
}
// debug is optional (default to false)
boolean debugOption = false;
if (workItem.getParameter("DebugEnabled") != null) {
debugOption = Boolean.parseBoolean((String) workItem.getParameter("DebugEnabled"));
}
if (StringUtils.isNotEmpty(statusMessage)) {
try {
Twitter twitter = auth.getTwitterService(this.consumerKey, this.consumerSecret, this.accessKey, this.accessSecret, debugOption);
statusUpdate = new StatusUpdate(statusMessage);
if (statusMedia != null) {
statusUpdate.setMedia(FilenameUtils.getBaseName(statusMedia.getName()) + "." + FilenameUtils.getExtension(statusMedia.getName()), new ByteArrayInputStream(statusMedia.getContent()));
}
twitter.updateStatus(statusUpdate);
workItemManager.completeWorkItem(workItem.getId(), null);
} catch (Exception e) {
handleException(e);
}
} else {
logger.error("Missing status message.");
throw new IllegalArgumentException("Missing status message.");
}
}
use of org.jbpm.document.Document in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseWithCaseFileAndDocument.
@Test
public void testStartEmptyCaseWithCaseFileAndDocument() {
byte[] docContent = "first case document".getBytes();
DocumentImpl document = new DocumentImpl(UUID.randomUUID().toString(), "test case doc", docContent.length, new Date());
document.setContent(docContent);
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
data.put("document", document);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertNotNull(cInstance.getCaseFile());
assertEquals("my first case", cInstance.getCaseFile().getData("name"));
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Object doc = cInstance.getCaseFile().getData("document");
assertNotNull(doc);
assertTrue(doc instanceof Document);
Document caseDoc = (Document) doc;
assertEquals("test case doc", caseDoc.getName());
assertEquals(docContent.length, caseDoc.getSize());
assertEquals(new String(docContent), new String(caseDoc.getContent()));
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.document.Document 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());
}
Aggregations