use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testDocumentProcess.
@Test
public void testDocumentProcess() {
DocumentImpl docToTranslate = new DocumentImpl();
docToTranslate.setContent(document.getContent());
docToTranslate.setLastModified(document.getLastModified());
docToTranslate.setName(document.getName());
docToTranslate.setSize(document.getSize());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("original_document", docToTranslate);
Long processInstanceId = null;
try {
processInstanceId = processClient.startProcess("definition-project", "xyz-translations", parameters);
assertNotNull(processInstanceId);
assertTrue(processInstanceId.longValue() > 0);
List<DocumentInstance> docs = documentClient.listDocuments(0, 10);
assertNotNull(docs);
assertEquals(1, docs.size());
Object docVar = processClient.getProcessInstanceVariable("definition-project", processInstanceId, "original_document");
assertNotNull(docVar);
assertTrue(docVar instanceof Document);
Document doc = (Document) docVar;
assertDocuments(docToTranslate, doc);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner("yoda", 0, 10);
assertNotNull(tasks);
assertEquals(1, tasks.size());
// review task
long taskId = tasks.get(0).getId();
taskClient.claimTask("definition-project", taskId, "yoda");
taskClient.startTask("definition-project", taskId, "yoda");
Map<String, Object> taskInputs = taskClient.getTaskInputContentByTaskId("definition-project", taskId);
assertNotNull(taskInputs);
assertEquals(6, taskInputs.size());
docVar = taskInputs.get("in_doc");
assertNotNull(docVar);
assertTrue(docVar instanceof Document);
doc = (Document) docVar;
assertDocuments(docToTranslate, doc);
Map<String, Object> result = new HashMap<String, Object>();
result.put("out_comments", "ready to translate");
result.put("out_status", "OK");
taskClient.completeTask("definition-project", taskId, "yoda", result);
tasks = taskClient.findTasksAssignedAsPotentialOwner("yoda", 0, 10);
assertNotNull(tasks);
assertEquals(1, tasks.size());
// translate task
taskId = tasks.get(0).getId();
taskClient.claimTask("definition-project", taskId, "yoda");
taskClient.startTask("definition-project", taskId, "yoda");
taskInputs = taskClient.getTaskInputContentByTaskId("definition-project", taskId);
assertNotNull(taskInputs);
assertEquals(8, taskInputs.size());
docVar = taskInputs.get("in_doc");
assertNotNull(docVar);
assertTrue(docVar instanceof Document);
doc = (Document) docVar;
assertDocuments(docToTranslate, doc);
result = new HashMap<String, Object>();
DocumentImpl translated = new DocumentImpl();
translated.setContent("translated document content".getBytes());
translated.setLastModified(new Date());
translated.setName("translated document");
translated.setSize(translated.getContent().length);
result.put("out_translated", translated);
result.put("out_comments", "translated");
result.put("out_status", "DONE");
taskClient.completeTask("definition-project", taskId, "yoda", result);
// now lets check if the document was updated
docVar = processClient.getProcessInstanceVariable("definition-project", processInstanceId, "translated_document");
assertNotNull(docVar);
assertTrue(docVar instanceof Document);
doc = (Document) docVar;
assertDocuments(translated, doc);
docs = documentClient.listDocuments(0, 10);
assertNotNull(docs);
assertEquals(2, docs.size());
} finally {
if (processInstanceId != null) {
processClient.abortProcessInstance("definition-project", processInstanceId);
}
}
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testCreateDocument.
@Test
public void testCreateDocument() {
String documentId = documentClient.createDocument(document);
assertNotNull(documentId);
DocumentInstance fromServer = documentClient.getDocument(documentId);
assertEquals(documentId, fromServer.getIdentifier());
assertDocumentInstances(document, fromServer, true);
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class KieClientServicesIntegrationTest method testDocumentServiceCamelProducer.
@Test
public void testDocumentServiceCamelProducer() throws Exception {
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedMessageCount(1);
Map<String, Object> headers = new HashMap<>();
headers.put(KIE_CLIENT, "document");
headers.put(KIE_OPERATION, "getDocument");
headers.put(asCamelKieName("identifier"), "1234");
template.sendBodyAndHeaders("direct:start", null, headers);
assertMockEndpointsSatisfied();
DocumentInstance documentInstance = getResultMessage(mockEndpoint.getExchanges().get(0)).getBody(DocumentInstance.class);
assertEquals(documentInstance.getIdentifier(), "1234");
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class KieClientServicesIntegrationTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
KieServerInfo info = new KieServerInfo("mock", "1.2.3");
List<String> capabilities = Arrays.asList(KieServerConstants.CAPABILITY_BPM, KieServerConstants.CAPABILITY_BPM_UI, KieServerConstants.CAPABILITY_BRM, KieServerConstants.CAPABILITY_BRP, KieServerConstants.CAPABILITY_CASE, KieServerConstants.CAPABILITY_DMN);
info.setCapabilities(capabilities);
ServiceResponse<KieServerInfo> response = new ServiceResponse<KieServerInfo>(ResponseType.SUCCESS, "Kie Server info");
response.setResult(info);
stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(response, KieServerInfo.class, ServiceResponse.class))));
// case mock response
ProcessDefinitionList caseResponse = new ProcessDefinitionList();
caseResponse.setProcesses(new ProcessDefinition[] { new ProcessDefinition() });
stubFor(get(urlMatching("/queries/cases/processes.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(caseResponse, ProcessDefinitionList.class, ProcessDefinition.class))));
// document mock response
DocumentInstance documentResponse = new DocumentInstance();
documentResponse.setIdentifier("1234");
stubFor(get(urlMatching("/documents/1234")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(documentResponse, DocumentInstance.class))));
// job service mock response
RequestInfoInstanceList jobResponse = new RequestInfoInstanceList();
stubFor(get(urlMatching("/jobs.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(jobResponse, RequestInfoInstanceList.class))));
// query service mock response
NodeInstanceList queryResponse = new NodeInstanceList();
stubFor(get(urlMatching("/queries/processes/instances/100/nodes/instances.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(queryResponse, NodeInstanceList.class))));
// solver service mock response
SolverInstanceList solverResponse = new SolverInstanceList();
stubFor(get(urlMatching("/containers/my-container/solvers")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(solverResponse, SolverInstanceList.class))));
// ui service mock response
stubFor(get(urlMatching("/containers/my-container/forms/processes/my-process.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody("my form")));
// user task mock response
TaskSummaryList userTaskResponse = new TaskSummaryList();
stubFor(get(urlMatching("/queries/tasks/instances.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(toXML(userTaskResponse, TaskSummaryList.class))));
return new RouteBuilder() {
@Override
public void configure() {
from("direct:start").to("kie:" + getAuthenticadUrl("admin", "admin")).to("mock:result");
}
};
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceBase method storeDocument.
public String storeDocument(String documentPayload, String marshallingType) {
logger.debug("About to unmarshal document payload '{}' with marshaling type {}", documentPayload, marshallingType);
DocumentInstance documentInstance = marshallerHelper.unmarshal(documentPayload, marshallingType, DocumentInstance.class);
logger.debug("Document created from payload {}", documentInstance);
Document document = documentStorageService.buildDocument(documentInstance.getName(), documentInstance.getSize(), documentInstance.getLastModified(), new HashMap<String, String>());
logger.debug("Document created by the service {}", document);
documentStorageService.saveDocument(document, documentInstance.getContent());
logger.debug("Document {} stored successfully", document);
return document.getIdentifier();
}
Aggregations