Search in sources :

Example 11 with Document

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);
}
Also used : Document(org.jbpm.document.Document) Test(org.junit.Test)

Example 12 with Document

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();
}
Also used : Document(org.jbpm.document.Document) Test(org.junit.Test)

Example 13 with Document

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.");
    }
}
Also used : StatusUpdate(twitter4j.StatusUpdate) ByteArrayInputStream(java.io.ByteArrayInputStream) Twitter(twitter4j.Twitter) Document(org.jbpm.document.Document)

Example 14 with Document

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);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 15 with Document

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

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