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