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