Search in sources :

Example 1 with Document

use of org.jbpm.document.Document 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 Document

use of org.jbpm.document.Document 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 Document

use of org.jbpm.document.Document 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 Document

use of org.jbpm.document.Document in project jbpm by kiegroup.

the class DocumentsMarshallingStrategyTest method testSingleDocMarshallUnmarshall.

@Test
public void testSingleDocMarshallUnmarshall() throws IOException, ClassNotFoundException {
    DocumentMarshallingStrategy docMarshallingStrategy = new DocumentMarshallingStrategy();
    Document document = getDocument("docOne");
    byte[] marshalledDocument = docMarshallingStrategy.marshal(null, null, document);
    Document unmarshalledDocument = (Document) docMarshallingStrategy.unmarshal(null, null, marshalledDocument, this.getClass().getClassLoader());
    assertEquals(document.getName(), unmarshalledDocument.getName());
    assertEquals(document.getLink(), unmarshalledDocument.getLink());
}
Also used : Document(org.jbpm.document.Document) Test(org.junit.Test)

Example 5 with Document

use of org.jbpm.document.Document 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)

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