use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.
the class DMNCommonActionsToolboxFactoryTest method testBuildToolboxForBusinessKnowledgeModelType.
@Test
@SuppressWarnings("unchecked")
public void testBuildToolboxForBusinessKnowledgeModelType() {
final Node<View<BusinessKnowledgeModel>, Edge> bkmNode = new NodeImpl<>("bkmNode1");
final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel();
final Bounds bounds = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 150d));
final View<BusinessKnowledgeModel> nodeContent = new ViewImpl<>(bkm, bounds);
bkmNode.setContent(nodeContent);
final Optional<Toolbox<?>> _toolbox = tested.build(canvasHandler, bkmNode);
assertTrue(_toolbox.isPresent());
Toolbox<?> toolbox = _toolbox.get();
assertTrue(toolbox instanceof ActionsToolbox);
final ActionsToolbox actionsToolbox = (ActionsToolbox) toolbox;
assertEquals("bkmNode1", actionsToolbox.getElementUUID());
assertEquals(2, actionsToolbox.size());
final Iterator<ToolboxAction> actionsIt = actionsToolbox.iterator();
assertEquals(deleteNodeAction, actionsIt.next());
assertEquals(editBusinessKnowledgeModelToolboxAction, actionsIt.next());
assertFalse(actionsIt.hasNext());
verify(view, times(1)).init(eq(actionsToolbox));
verify(view, times(2)).addButton(any(Glyph.class), anyString(), any(Consumer.class));
}
use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method dmnFromNode.
@Override
public org.kie.dmn.model.v1_1.KnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node) {
KnowledgeSource source = node.getContent().getDefinition();
org.kie.dmn.model.v1_1.KnowledgeSource result = new org.kie.dmn.model.v1_1.KnowledgeSource();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setName(source.getName().getValue());
result.setType(source.getType().getValue());
result.setLocationURI(source.getLocationURI().getValue());
// DMN spec table 2: Requirements connection rules
List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredDecision(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredAuthority(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
iReq.setRequiredInput(ri);
result.getAuthorityRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
use of org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method nodeFromDMN.
@Override
public Node<View<KnowledgeSource>, ?> nodeFromDMN(final org.kie.dmn.model.v1_1.KnowledgeSource dmn) {
@SuppressWarnings("unchecked") Node<View<KnowledgeSource>, ?> node = (Node<View<KnowledgeSource>, ?>) factoryManager.newElement(dmn.getId(), KnowledgeSource.class).asNode();
Id id = new Id(dmn.getId());
Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
Name name = new Name(dmn.getName());
KnowledgeSourceType ksType = new KnowledgeSourceType(dmn.getType());
LocationURI locationURI = new LocationURI(dmn.getLocationURI());
KnowledgeSource ks = new KnowledgeSource(id, description, name, ksType, locationURI, new BackgroundSet(), new FontSet(), new RectangleDimensionsSet());
node.getContent().setDefinition(ks);
return node;
}
use of org.kie.workbench.common.stunner.core.graph.content.view.View 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 org.kie.workbench.common.stunner.core.graph.content.view.View in project kie-wb-common by kiegroup.
the class DMNEditBusinessKnowledgeModelToolboxAction method onMouseClick.
@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
// Notice the toolbox factory ensure this action is only being included
// for BusinessKnowledgeModel definitions, next cast is safe.
final Node<View<? extends BusinessKnowledgeModel>, Edge> bkmNode = (Node<View<? extends BusinessKnowledgeModel>, Edge>) AbstractToolboxAction.getElement(canvasHandler, uuid).asNode();
final BusinessKnowledgeModel bkm = bkmNode.getContent().getDefinition();
editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, bkm.getEncapsulatedLogic(), Optional.of(bkm)));
return this;
}
Aggregations