Search in sources :

Example 6 with DocumentInstance

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Example 7 with DocumentInstance

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);
}
Also used : DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) Test(org.junit.Test)

Example 8 with DocumentInstance

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");
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) Test(org.junit.Test)

Example 9 with DocumentInstance

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");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) ProcessDefinitionList(org.kie.server.api.model.definition.ProcessDefinitionList) RequestInfoInstanceList(org.kie.server.api.model.instance.RequestInfoInstanceList) KieServerInfo(org.kie.server.api.model.KieServerInfo) ProcessDefinition(org.kie.server.api.model.definition.ProcessDefinition) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) ServiceResponse(org.kie.server.api.model.ServiceResponse) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance)

Example 10 with DocumentInstance

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();
}
Also used : DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) Document(org.jbpm.document.Document)

Aggregations

DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)17 Test (org.junit.Test)9 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Document (org.jbpm.document.Document)4 KieServerRuntimeException (org.kie.server.services.api.KieServerRuntimeException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 ResponseHeader (io.swagger.annotations.ResponseHeader)2 IOException (java.io.IOException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Variant (javax.ws.rs.core.Variant)2 KieServicesException (org.kie.server.api.exception.KieServicesException)2 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 DocumentInstanceList (org.kie.server.api.model.instance.DocumentInstanceList)2 Header (org.kie.server.remote.rest.common.Header)2 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)2