Search in sources :

Example 1 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project kie-wb-common by kiegroup.

the class DocumentFieldValueProcessor method toRawValue.

@Override
public Document toRawValue(DocumentFieldDefinition field, DocumentData documentData, Document originalValue, BackendFormRenderingContext context) {
    if (documentData == null) {
        return null;
    }
    if (documentData.getStatus().equals(DocumentStatus.STORED)) {
        return originalValue;
    }
    File content = uploadedDocumentManager.getFile(documentData.getContentId());
    if (content != null) {
        try {
            Document doc = new DocumentImpl(documentData.getFileName(), content.length(), new Date(content.lastModified()));
            doc.setContent(getFileContent(content));
            uploadedDocumentManager.removeFile(documentData.getContentId());
            return doc;
        } catch (IOException e) {
            logger.warn("Error reading file content: ", e);
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) Document(org.jbpm.document.Document) File(java.io.File) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date)

Example 2 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project kie-wb-common by kiegroup.

the class DocumentFieldValueProcessorTest method testExistingFlatValue2Document.

@Test
public void testExistingFlatValue2Document() {
    Document doc = new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date(), "aLink");
    DocumentData data = new DocumentData(doc.getName(), doc.getSize(), doc.getLink());
    data.setStatus(DocumentStatus.STORED);
    Document rawDoc = processor.toRawValue(field, data, doc, context);
    assertEquals("Documents must be equal!", doc, rawDoc);
    verify(uploadedDocumentManager, never()).getFile(anyString());
    verify(uploadedDocumentManager, never()).removeFile(anyString());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Test(org.junit.Test)

Example 3 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl in project kie-wb-common by kiegroup.

the class DocumentFieldValueProcessorTest method testDocument2FlatValueEmptyLinkPattern.

@Test
public void testDocument2FlatValueEmptyLinkPattern() {
    Document doc = spy(new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date()));
    DocumentData documentData = processor.toFlatValue(field, doc, context);
    verify(doc).getLink();
    assertNotNull(documentData);
    assertEquals(doc.getName(), documentData.getFileName());
    assertEquals(doc.getSize(), documentData.getSize());
    assertEquals("", documentData.getLink());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Test(org.junit.Test)

Example 4 with DocumentImpl

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

the class DocumentsMarshallingStrategyTest method getDocument.

private Document getDocument(String documentName) {
    Document documentOne = new DocumentImpl();
    documentOne.setIdentifier(documentName);
    documentOne.setLastModified(new Date());
    documentOne.setLink("http://" + documentName);
    documentOne.setName(documentName + " Name");
    documentOne.setSize(1);
    documentOne.setContent(documentName.getBytes());
    return documentOne;
}
Also used : Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date)

Example 5 with DocumentImpl

use of org.jbpm.document.service.impl.DocumentImpl 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)

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