use of com.google.cloud.videointelligence.v1.TextAnnotation in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallNode.
protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
if (properties == null) {
properties = new LinkedHashMap<String, Object>();
}
putDocumentationProperty(node, properties);
if (node.getName() != null) {
properties.put(NAME, StringEscapeUtils.unescapeXml(node.getName()));
} else {
if (node instanceof TextAnnotation) {
if (((TextAnnotation) node).getText() != null) {
properties.put(NAME, ((TextAnnotation) node).getText());
} else {
properties.put(NAME, "");
}
} else {
properties.put(NAME, "");
}
}
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put("name", elementName);
}
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
generator.writeObjectField("id", stencil);
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
for (SequenceFlow outgoing : node.getOutgoing()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", outgoing.getId());
generator.writeEndObject();
}
// we need to also add associations as outgoing elements
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, node.getId(), generator);
// and boundary events for activities
List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
findBoundaryEvents(process, boundaryEvents);
for (BoundaryEvent be : boundaryEvents) {
if (be.getAttachedToRef().getId().equals(node.getId())) {
generator.writeStartObject();
generator.writeObjectField("resourceId", be.getId());
generator.writeEndObject();
}
}
generator.writeEndArray();
// boundary events have a docker
if (node instanceof BoundaryEvent) {
Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator();
boolean foundDockerInfo = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("dockerinfo")) {
foundDockerInfo = true;
String dockerInfoStr = String.valueOf(entry.getValue());
if (dockerInfoStr != null && dockerInfoStr.length() > 0) {
if (dockerInfoStr.endsWith("|")) {
dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1);
String[] dockerInfoParts = dockerInfoStr.split("\\|");
String infoPartsToUse = dockerInfoParts[0];
String[] infoPartsToUseParts = infoPartsToUse.split("\\^");
if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) {
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0]));
generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1]));
generator.writeEndObject();
generator.writeEndArray();
}
}
}
}
}
// backwards compatibility to older versions -- BZ 1196259
if (!foundDockerInfo) {
// find the edge associated with this boundary event
for (DiagramElement element : plane.getPlaneElement()) {
if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) {
List<Point> waypoints = ((BPMNEdge) element).getWaypoint();
if (waypoints != null && waypoints.size() > 0) {
// one per boundary event
Point p = waypoints.get(0);
if (p != null) {
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", p.getX());
generator.writeObjectField("y", p.getY());
generator.writeEndObject();
generator.writeEndArray();
}
}
}
}
}
}
BPMNShape shape = (BPMNShape) findDiagramElement(plane, node);
Bounds bounds = shape.getBounds();
correctEventNodeSize(shape);
generator.writeObjectFieldStart("bounds");
generator.writeObjectFieldStart("lowerRight");
generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
generator.writeEndObject();
generator.writeObjectFieldStart("upperLeft");
generator.writeObjectField("x", bounds.getX() - xOffset);
generator.writeObjectField("y", bounds.getY() - yOffset);
generator.writeEndObject();
generator.writeEndObject();
}
use of com.google.cloud.videointelligence.v1.TextAnnotation in project kie-wb-common by kiegroup.
the class TextAnnotationConverter method dmnFromNode.
@Override
public org.kie.dmn.model.v1_1.TextAnnotation dmnFromNode(final Node<View<TextAnnotation>, ?> node) {
TextAnnotation source = node.getContent().getDefinition();
org.kie.dmn.model.v1_1.TextAnnotation result = new org.kie.dmn.model.v1_1.TextAnnotation();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setText(source.getText().getValue());
result.setTextFormat(source.getTextFormat().getValue());
return result;
}
use of com.google.cloud.videointelligence.v1.TextAnnotation in project kie-wb-common by kiegroup.
the class TextAnnotationConverter method nodeFromDMN.
@Override
public Node<View<TextAnnotation>, ?> nodeFromDMN(final org.kie.dmn.model.v1_1.TextAnnotation dmn) {
@SuppressWarnings("unchecked") Node<View<TextAnnotation>, ?> node = (Node<View<TextAnnotation>, ?>) factoryManager.newElement(dmn.getId(), TextAnnotation.class).asNode();
Id id = new Id(dmn.getId());
Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
Text text = new Text(dmn.getText());
TextFormat textFormat = new TextFormat(dmn.getTextFormat());
TextAnnotation textAnnotation = new TextAnnotation(id, description, text, textFormat, new BackgroundSet(), new FontSet(), new RectangleDimensionsSet());
node.getContent().setDefinition(textAnnotation);
return node;
}
use of com.google.cloud.videointelligence.v1.TextAnnotation in project kie-wb-common by kiegroup.
the class DMNMarshaller method marshall.
@Override
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
Graph<?, Node<View, ?>> g = diagram.getGraph();
Map<String, org.kie.dmn.model.v1_1.DRGElement> nodes = new HashMap<>();
Map<String, org.kie.dmn.model.v1_1.TextAnnotation> textAnnotations = new HashMap<>();
@SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
Definitions definitionsStunnerPojo = dmnDiagramRoot.getContent().getDefinition().getDefinitions();
org.kie.dmn.model.v1_1.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
if (definitions.getExtensionElements() == null) {
definitions.setExtensionElements(new org.kie.dmn.model.v1_1.Definitions.ExtensionElements());
}
org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram dmnDDDMNDiagram = new org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram();
definitions.getExtensionElements().getAny().add(dmnDDDMNDiagram);
for (Node<?, ?> node : g.nodes()) {
if (node.getContent() instanceof View<?>) {
View<?> view = (View<?>) node.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement n = (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) view.getDefinition();
nodes.put(n.getId().getValue(), stunnerToDMN(node));
dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
} else if (view.getDefinition() instanceof TextAnnotation) {
TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node));
dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
List<org.kie.dmn.model.v1_1.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
definitions.getArtifact().addAll(associations);
}
}
}
nodes.values().forEach(definitions.getDrgElement()::add);
textAnnotations.values().forEach(definitions.getArtifact()::add);
String marshalled = marshaller.marshal(definitions);
return marshalled;
}
use of com.google.cloud.videointelligence.v1.TextAnnotation in project spring-cloud-gcp by spring-cloud.
the class DocumentOcrTemplateIntegrationTests method testDocumentOcrTemplate.
@Test
public void testDocumentOcrTemplate() throws ExecutionException, InterruptedException, InvalidProtocolBufferException, TimeoutException {
GoogleStorageLocation document = GoogleStorageLocation.forFile("vision-integration-test-bucket", "test.pdf");
GoogleStorageLocation outputLocationPrefix = GoogleStorageLocation.forFile("vision-integration-test-bucket", "it_output/test-");
ListenableFuture<DocumentOcrResultSet> result = this.documentOcrTemplate.runOcrForDocument(document, outputLocationPrefix);
DocumentOcrResultSet ocrPages = result.get(5, TimeUnit.MINUTES);
String page1Text = ocrPages.getPage(1).getText();
assertThat(page1Text).contains("Hello World. Is mayonnaise an instrument?");
String page2Text = ocrPages.getPage(2).getText();
assertThat(page2Text).contains("Page 2 stuff");
ArrayList<String> pageContent = new ArrayList<>();
Iterator<TextAnnotation> pageIterator = ocrPages.getAllPages();
while (pageIterator.hasNext()) {
pageContent.add(pageIterator.next().getText());
}
assertThat(pageContent).containsExactly("Hello World. Is mayonnaise an instrument?\n", "Page 2 stuff\n", "Page 3 stuff\n", "Page 4 stuff\n");
}
Aggregations