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