use of com.google.cloud.vision.v1p3beta1.TextAnnotation in project kie-wb-common by kiegroup.
the class DMNMarshaller method stunnerToDDExt.
private static DMNShape stunnerToDDExt(View<? extends DMNElement> v) {
DMNShape result = new DMNShape();
result.setId("dmnshape-" + v.getDefinition().getId().getValue());
result.setDmnElementRef(v.getDefinition().getId().getValue());
Bounds bounds = new Bounds();
result.setBounds(bounds);
bounds.setX(v.getBounds().getUpperLeft().getX());
bounds.setY(v.getBounds().getUpperLeft().getY());
if (v.getDefinition() instanceof Decision) {
Decision d = (Decision) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getBackgroundSet(), result);
result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
} else if (v.getDefinition() instanceof InputData) {
InputData d = (InputData) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getBackgroundSet(), result);
result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
} else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getBackgroundSet(), result);
result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
} else if (v.getDefinition() instanceof KnowledgeSource) {
KnowledgeSource d = (KnowledgeSource) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getBackgroundSet(), result);
result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
} else if (v.getDefinition() instanceof TextAnnotation) {
TextAnnotation d = (TextAnnotation) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getBackgroundSet(), result);
result.setFontStyle(FontSetPropertyConverter.dmnFromWB(d.getFontSet()));
}
return result;
}
use of com.google.cloud.vision.v1p3beta1.TextAnnotation in project kie-wb-common by kiegroup.
the class DMNMarshaller method unmarshall.
@Override
public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException {
org.kie.dmn.model.v1_1.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input));
Map<String, Entry<org.kie.dmn.model.v1_1.DRGElement, Node>> elems = dmnXml.getDrgElement().stream().collect(Collectors.toMap(org.kie.dmn.model.v1_1.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn))));
Optional<org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml);
for (Entry<org.kie.dmn.model.v1_1.DRGElement, Node> kv : elems.values()) {
org.kie.dmn.model.v1_1.DRGElement elem = kv.getKey();
Node currentNode = kv.getValue();
ddExtAugmentStunner(dmnDDDiagram, currentNode);
// DMN spec table 2: Requirements connection rules
if (elem instanceof org.kie.dmn.model.v1_1.Decision) {
org.kie.dmn.model.v1_1.Decision decision = (org.kie.dmn.model.v1_1.Decision) elem;
for (org.kie.dmn.model.v1_1.InformationRequirement ir : decision.getInformationRequirement()) {
if (ir.getRequiredInput() != null) {
String reqInputID = getId(ir.getRequiredInput());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
if (ir.getRequiredDecision() != null) {
String reqInputID = getId(ir.getRequiredDecision());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
}
for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) {
String reqInputID = getId(kr.getRequiredKnowledge());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : decision.getAuthorityRequirement()) {
String reqInputID = getId(kr.getRequiredAuthority());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
} else if (elem instanceof org.kie.dmn.model.v1_1.BusinessKnowledgeModel) {
org.kie.dmn.model.v1_1.BusinessKnowledgeModel bkm = (org.kie.dmn.model.v1_1.BusinessKnowledgeModel) elem;
for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) {
String reqInputID = getId(kr.getRequiredKnowledge());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : bkm.getAuthorityRequirement()) {
String reqInputID = getId(kr.getRequiredAuthority());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
} else if (elem instanceof org.kie.dmn.model.v1_1.KnowledgeSource) {
org.kie.dmn.model.v1_1.KnowledgeSource ks = (org.kie.dmn.model.v1_1.KnowledgeSource) elem;
for (org.kie.dmn.model.v1_1.AuthorityRequirement ir : ks.getAuthorityRequirement()) {
if (ir.getRequiredInput() != null) {
String reqInputID = getId(ir.getRequiredInput());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
if (ir.getRequiredDecision() != null) {
String reqInputID = getId(ir.getRequiredDecision());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
if (ir.getRequiredAuthority() != null) {
String reqInputID = getId(ir.getRequiredAuthority());
Node requiredNode = elems.get(reqInputID).getValue();
Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
connectEdge(myEdge, requiredNode, currentNode);
setConnectionMagnets(myEdge);
}
}
}
}
Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.TextAnnotation.class::isInstance).map(org.kie.dmn.model.v1_1.TextAnnotation.class::cast).collect(Collectors.toMap(org.kie.dmn.model.v1_1.TextAnnotation::getId, textAnnotationConverter::nodeFromDMN));
textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n));
List<org.kie.dmn.model.v1_1.Association> associations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.Association.class::isInstance).map(org.kie.dmn.model.v1_1.Association.class::cast).collect(Collectors.toList());
for (org.kie.dmn.model.v1_1.Association a : associations) {
String sourceId = getId(a.getSourceRef());
Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId));
String targetId = getId(a.getTargetRef());
Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId));
@SuppressWarnings("unchecked") Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(UUID.uuid(), Association.class).asEdge();
Id id = new Id(a.getId());
Description description = new Description(a.getDescription());
Association definition = new Association(id, description);
myEdge.getContent().setDefinition(definition);
connectEdge(myEdge, sourceNode, targetNode);
setConnectionMagnets(myEdge);
}
Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph();
elems.values().stream().map(kv -> kv.getValue()).forEach(graph::addNode);
textAnnotations.values().forEach(graph::addNode);
@SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = findDMNDiagramRoot(graph);
Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml);
dmnDiagramRoot.getContent().getDefinition().setDefinitions(definitionsStunnerPojo);
elems.values().stream().map(kv -> kv.getValue()).forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
return graph;
}
use of com.google.cloud.vision.v1p3beta1.TextAnnotation in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallAssociation.
protected void marshallAssociation(Association association, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>();
Iterator<FeatureMap.Entry> iter = association.getAnyAttribute().iterator();
boolean foundBrColor = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("type")) {
properties.put(TYPE, entry.getValue());
}
if (entry.getEStructuralFeature().getName().equals("bordercolor")) {
properties.put(BORDERCOLOR, entry.getValue());
foundBrColor = true;
}
}
if (!foundBrColor) {
properties.put("bordercolor", defaultSequenceflowColor);
}
putDocumentationProperty(association, properties);
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
if (association.getAssociationDirection().equals(AssociationDirection.ONE)) {
generator.writeObjectField("id", "Association_Unidirectional");
} else if (association.getAssociationDirection().equals(AssociationDirection.BOTH)) {
generator.writeObjectField("id", "Association_Bidirectional");
} else {
generator.writeObjectField("id", "Association_Undirected");
}
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
generator.writeStartObject();
generator.writeObjectField("resourceId", association.getTargetRef().getId());
generator.writeEndObject();
generator.writeEndArray();
Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, association.getSourceRef())).getBounds();
Bounds targetBounds = null;
float tbx = 0;
float tby = 0;
if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNShape) {
targetBounds = ((BPMNShape) findDiagramElement(plane, association.getTargetRef())).getBounds();
} else if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNEdge) {
// connect it to first waypoint on edge
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association.getTargetRef())).getWaypoint();
if (waypoints != null && waypoints.size() > 0) {
tbx = waypoints.get(0).getX();
tby = waypoints.get(0).getY();
}
}
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", sourceBounds.getWidth() / 2);
generator.writeObjectField("y", sourceBounds.getHeight() / 2);
generator.writeEndObject();
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association)).getWaypoint();
for (int i = 1; i < waypoints.size() - 1; i++) {
Point waypoint = waypoints.get(i);
generator.writeStartObject();
generator.writeObjectField("x", waypoint.getX());
generator.writeObjectField("y", waypoint.getY());
generator.writeEndObject();
}
if (targetBounds != null) {
generator.writeStartObject();
// text annotations have to be treated specia
if (association.getTargetRef() instanceof TextAnnotation) {
generator.writeObjectField("x", 1);
generator.writeObjectField("y", targetBounds.getHeight() / 2);
} else {
generator.writeObjectField("x", targetBounds.getWidth() / 2);
generator.writeObjectField("y", targetBounds.getHeight() / 2);
}
generator.writeEndObject();
generator.writeEndArray();
} else {
generator.writeStartObject();
generator.writeObjectField("x", tbx);
generator.writeObjectField("y", tby);
generator.writeEndObject();
generator.writeEndArray();
}
}
use of com.google.cloud.vision.v1p3beta1.TextAnnotation in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method checkTextAnnotationGraph.
private void checkTextAnnotationGraph(Graph<?, Node<?, ?>> graph) {
Node<?, ?> textAnnotation = graph.getNode("60915990-9E1D-42DF-B7F6-0D28383BE9D1");
assertNodeContentDefinitionIs(textAnnotation, TextAnnotation.class);
TextAnnotation textAnnotationDefinition = ((View<TextAnnotation>) textAnnotation.getContent()).getDefinition();
assertEquals("描述", textAnnotationDefinition.getDescription().getValue());
assertEquals("<b>This Annotation holds some Long text and also UTF-8 characters</b>", textAnnotationDefinition.getText().getValue());
assertEquals("text/html", textAnnotationDefinition.getTextFormat().getValue());
}
use of com.google.cloud.vision.v1p3beta1.TextAnnotation in project kie-wb-common by kiegroup.
the class FlowElementConverterTest method convertSupported.
@Test
public void convertSupported() {
StartEvent startEvent = mock(StartEvent.class);
tested.convertNode(startEvent);
verify(startEventConverter).convert(startEvent);
EndEvent endEvent = mock(EndEvent.class);
tested.convertNode(endEvent);
verify(endEventConverter).convert(endEvent);
BoundaryEvent boundaryEvent = mock(BoundaryEvent.class);
tested.convertNode(boundaryEvent);
verify(eventConverter).convertBoundaryEvent(boundaryEvent);
IntermediateCatchEvent intermediateCatchEvent = mock(IntermediateCatchEvent.class);
tested.convertNode(intermediateCatchEvent);
verify(eventConverter).convert(intermediateCatchEvent);
IntermediateThrowEvent intermediateThrowEvent = mock(IntermediateThrowEvent.class);
tested.convertNode(intermediateThrowEvent);
verify(throwEventConverter).convert(intermediateThrowEvent);
Task task = mock(Task.class);
tested.convertNode(task);
verify(taskConverter).convert(task);
Gateway gateway = mock(Gateway.class);
tested.convertNode(gateway);
verify(gatewayConverter).convert(gateway);
SubProcess subProcess = mock(SubProcess.class);
tested.convertNode(subProcess);
verify(subProcessConverter).convertSubProcess(subProcess);
CallActivity callActivity = mock(CallActivity.class);
tested.convertNode(callActivity);
verify(callActivityConverter).convert(callActivity);
TextAnnotation textAnnotation = mock(TextAnnotation.class);
tested.convertNode(textAnnotation);
verify(artifactsConverter).convert(textAnnotation);
DataObjectReference dataObjectReference = mock(DataObjectReference.class);
tested.convertNode(dataObjectReference);
verify(artifactsConverter).convert(dataObjectReference);
}
Aggregations