Search in sources :

Example 21 with Document

use of org.jbpm.document.Document in project jbpm-work-items by kiegroup.

the class DetectFacesWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    Document detectionImage = (Document) workItem.getParameter("ImageToDetect");
    Map<String, Object> widResults = new HashMap<String, Object>();
    if (detectionImage != null) {
        try {
            VisualRecognition service = auth.getService(apiKey);
            ByteArrayInputStream imageStream = new ByteArrayInputStream(detectionImage.getContent());
            DetectFacesOptions detectFacesOptions = new DetectFacesOptions.Builder().imagesFile(imageStream).build();
            DetectedFaces result = service.detectFaces(detectFacesOptions).execute();
            if (result == null || result.getImages() == null || result.getImages().size() < 1) {
                logger.error("Unable to detect faces on provided image.");
                workItemManager.abortWorkItem(workItem.getId());
            } else {
                List<FaceDetectionResult> resultList = new ArrayList<>();
                for (ImageWithFaces imageWithFaces : result.getImages()) {
                    for (Face face : imageWithFaces.getFaces()) {
                        resultList.add(new FaceDetectionResult(imageWithFaces, face));
                    }
                }
                widResults.put(RESULT_VALUE, resultList);
                workItemManager.completeWorkItem(workItem.getId(), widResults);
            }
        } catch (Exception e) {
            handleException(e);
        }
    } else {
        logger.error("Missing image for face detection.");
        throw new IllegalArgumentException("Missing image for face detection.");
    }
}
Also used : FaceDetectionResult(org.jbpm.process.workitem.ibm.watson.result.FaceDetectionResult) HashMap(java.util.HashMap) VisualRecognition(com.ibm.watson.developer_cloud.visual_recognition.v3.VisualRecognition) ArrayList(java.util.ArrayList) DetectedFaces(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces) Document(org.jbpm.document.Document) ImageWithFaces(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ImageWithFaces) DetectFacesOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions) ByteArrayInputStream(java.io.ByteArrayInputStream) Face(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Face)

Example 22 with Document

use of org.jbpm.document.Document in project jbpm-work-items by kiegroup.

the class CreateGistWorkitemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
    try {
        Document content = (Document) workItem.getParameter("Content");
        String description = (String) workItem.getParameter("Description");
        String isPublicStr = (String) workItem.getParameter("IsPublic");
        if (content != null) {
            Map<String, Object> results = new HashMap<String, Object>();
            GistService gistService = auth.getGistService(this.userName, this.password);
            Gist gist = new Gist();
            gist.setPublic(Boolean.parseBoolean(isPublicStr));
            gist.setDescription(description);
            GistFile file = new GistFile();
            file.setContent(new String(content.getContent(), StandardCharsets.UTF_8));
            file.setFilename(content.getName());
            gist.setFiles(Collections.singletonMap(file.getFilename(), file));
            gist = gistService.createGist(gist);
            results.put(RESULTS_VALUE, gist.getHtmlUrl());
            workItemManager.completeWorkItem(workItem.getId(), results);
        } else {
            logger.error("Missing gist content information.");
            throw new IllegalArgumentException("Missing gist content information.");
        }
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : Gist(org.eclipse.egit.github.core.Gist) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) GistFile(org.eclipse.egit.github.core.GistFile) GistService(org.eclipse.egit.github.core.service.GistService)

Example 23 with Document

use of org.jbpm.document.Document in project kie-wb-common by kiegroup.

the class DocumentFieldValueProcessorTest method testDocument2FlatValue.

@Test
public void testDocument2FlatValue() {
    Document doc = spy(new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date()));
    Map result = new HashMap();
    result.put(DocumentFieldValueProcessor.SERVER_TEMPLATE_ID, SERVER_TEMPLATE_ID);
    when(context.getAttributes()).thenReturn(result);
    DocumentData documentData = processor.toFlatValue(field, doc, context);
    verify(doc, never()).getLink();
    assertNotNull(documentData);
    assertEquals(doc.getName(), documentData.getFileName());
    assertEquals(doc.getSize(), documentData.getSize());
    assertEquals(EXPECTED_DOWNLOAD_LINK, documentData.getLink());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Example 24 with Document

use of org.jbpm.document.Document in project kie-wb-common by kiegroup.

the class DocumentFieldValueProcessorTest method testNewFlatValue2Document.

@Test
public void testNewFlatValue2Document() {
    DocumentData data = new DocumentData(DOCUMENT_ID, 1024, null);
    data.setContentId("content");
    Document doc = processor.toRawValue(field, data, null, context);
    verify(uploadedDocumentManager).getFile(anyString());
    verify(uploadedDocumentManager).removeFile(anyString());
    assertNotNull("Document cannot be null!", doc);
    assertEquals("Names are not equal", data.getFileName(), doc.getName());
    assertEquals("Sizes are not equal", data.getSize(), doc.getSize());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) Document(org.jbpm.document.Document) Test(org.junit.Test)

Example 25 with Document

use of org.jbpm.document.Document in project kie-wb-common by kiegroup.

the class DocumentFieldValueProcessorTest method testNullFlatValue2Document.

@Test
public void testNullFlatValue2Document() {
    Document doc = processor.toRawValue(field, null, null, context);
    assertNull("Document must be null!", doc);
}
Also used : Document(org.jbpm.document.Document) Test(org.junit.Test)

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