use of org.kie.workbench.common.stunner.core.diagram.Metadata 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 org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class AbstractProjectDiagramEditor method open.
@SuppressWarnings("unchecked")
protected void open(final ProjectDiagram diagram) {
showLoadingViews();
setOriginalHash(diagram.hashCode());
final Metadata metadata = diagram.getMetadata();
sessionManager.getSessionFactory(metadata, ClientFullSession.class).newSession(metadata, s -> {
final AbstractClientFullSession session = (AbstractClientFullSession) s;
presenter = sessionPresenterFactory.newPresenterEditor();
getView().setWidget(presenter.getView());
presenter.withToolbar(false).withPalette(true).displayNotifications(type -> true).open(diagram, session, new SessionPresenter.SessionPresenterCallback<AbstractClientFullSession, Diagram>() {
@Override
public void afterSessionOpened() {
}
@Override
public void afterCanvasInitialized() {
}
@Override
public void onSuccess() {
bindCommands();
updateTitle(diagram.getMetadata().getTitle());
hideLoadingViews();
setOriginalHash(getCurrentDiagramHash());
}
@Override
public void onError(final ClientRuntimeError error) {
onLoadError(error);
}
});
});
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class ExpandedPaletteDefinitionBuilder method createItem.
@Override
protected DefaultPaletteItem createItem(final Object definition, final String categoryId, final Metadata metadata, final Function<String, DefaultPaletteItem> itemSupplier) {
final DefinitionAdapter<Object> definitionAdapter = getDefinitionManager().adapters().forDefinition();
final String id = definitionAdapter.getId(definition);
DefaultPaletteCategory result = null;
DefaultPaletteCategory category = (DefaultPaletteCategory) itemSupplier.apply(categoryId);
if (null == category) {
final int catPriority = getItemPriority(categoryId);
final String catDefId = categoryDefinitionIdProvider.apply(categoryId);
final String catTitle = categoryMessageProvider.getTitle(categoryId);
final String catDesc = categoryMessageProvider.getDescription(categoryId);
final Glyph categoryGlyph = categoryGlyphProvider.apply(categoryId);
category = new CategoryBuilder().setPriority(catPriority).setItemId(categoryId).setDefinitionId(catDefId).setTitle(catTitle).setDescription(catDesc).setTooltip(catTitle).setGlyph(categoryGlyph).build();
result = category;
}
final MorphDefinition morphDefinition = morphDefinitionProvider.apply(definition);
final boolean hasMorphBase = null != morphDefinition;
String morphDefault = null;
DefaultPaletteGroup group = null;
if (hasMorphBase) {
final String morphBaseId = morphDefinition.getBase();
if (groupFilter.test(morphBaseId)) {
morphDefault = morphDefinition.getDefault();
final Optional<DefaultPaletteItem> groupOp = category.getItems().stream().filter(g -> g.getId().equals(morphBaseId)).findFirst();
if (!groupOp.isPresent()) {
final int groupPriority = getItemPriority(morphBaseId);
final String groupTitle = groupMessageProvider.getTitle(morphBaseId);
final String groupDesc = groupMessageProvider.getDescription(morphBaseId);
group = new GroupBuilder().setPriority(groupPriority).setItemId(morphBaseId).setDefinitionId(morphDefault).setTitle(groupTitle).setDescription(groupDesc).build();
category.getItems().add(group);
} else {
group = (DefaultPaletteGroup) groupOp.get();
}
}
} else {
// item has no morph base, but might belong to a custom group
final String customGroupId = customGroupIdProvider != null ? customGroupIdProvider.apply(id) : null;
if (customGroupId != null && groupFilter.test(customGroupId)) {
final Optional<DefaultPaletteItem> groupOp = category.getItems().stream().filter(g -> g.getId().equals(customGroupId)).findFirst();
if (!groupOp.isPresent()) {
final int groupPriority = getItemPriority(customGroupId);
final String groupTitle = customGroupMessageProvider.getTitle(customGroupId);
final String groupDesc = groupMessageProvider.getDescription(customGroupId);
group = new GroupBuilder().setPriority(groupPriority).setItemId(customGroupId).setTitle(groupTitle).setDescription(groupDesc).build();
category.getItems().add(group);
} else {
group = (DefaultPaletteGroup) groupOp.get();
}
}
}
final int itemPriority = getItemPriority(id);
final String title = definitionAdapter.getTitle(definition);
final String description = definitionAdapter.getDescription(definition);
final DefaultPaletteItem item = new ItemBuilder().setPriority(itemPriority).setItemId(id).setDefinitionId(id).setTitle(title).setDescription(description).build();
if (null != group) {
if (null != morphDefault && morphDefault.equals(id)) {
group.getItems().add(0, item);
} else {
group.getItems().add(item);
}
} else {
category.getItems().add(item);
}
return result;
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class StunnerClientLogger method logSessionInfo.
public static void logSessionInfo(final AbstractClientSession session) {
log("************ Session Info ****************");
if (null != session) {
log("Session = " + session.toString());
log("Canvas = " + session.getCanvas().toString());
if (null != session.getCanvasHandler()) {
final CanvasHandler canvasHandler = session.getCanvasHandler();
log("CanvasHandler = " + canvasHandler.toString());
final Diagram diagram = canvasHandler.getDiagram();
if (null != diagram) {
log("Diagram name = " + diagram.getName());
log("Graph uuid = " + (null != diagram.getGraph() ? diagram.getGraph().getUUID() : "null"));
final Metadata metadata = diagram.getMetadata();
if (null != metadata) {
log("Metadata defSetId = " + metadata.getDefinitionSetId());
log("Metadata shapeSetId = " + metadata.getShapeSetId());
log("Metadata canvas root = " + metadata.getCanvasRootUUID());
log("Metadata title = " + metadata.getTitle());
} else {
log("Metadata = null");
}
} else {
log("Diagram = null");
}
} else {
log("CanvasHandler = null");
}
if (session instanceof ClientFullSession) {
logFullSessionInfo((ClientFullSession) session);
}
} else {
log("Session is null");
}
log("******************************************");
}
use of org.kie.workbench.common.stunner.core.diagram.Metadata in project kie-wb-common by kiegroup.
the class MapSelectionControlTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
ShapeViewExtStub shapeView = new ShapeViewExtStub(shapeEventHandler, hasControlPoints);
when(element.getUUID()).thenReturn(ELEMENT_UUID);
when(element.getContent()).thenReturn(new ViewImpl<>(definition, BoundsImpl.build(0, 0, 10, 10)));
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(diagram.getMetadata()).thenReturn(metadata);
when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
when(canvasHandler.getCanvas()).thenReturn(canvas);
when(canvas.getLayer()).thenReturn(layer);
when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
when(shape.getUUID()).thenReturn(ELEMENT_UUID);
when(shape.getShapeView()).thenReturn(shapeView);
when(shapeEventHandler.supports(eq(ViewEventType.MOUSE_CLICK))).thenReturn(true);
this.tested = new MapSelectionControl(e -> elementSelectedEvent.fire((CanvasSelectionEvent) e), e -> clearSelectionEvent.fire((CanvasClearSelectionEvent) e));
this.tested.setReadonly(false);
}
Aggregations