use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AbstractEdgeBuilder method buildTargetConnection.
private void buildTargetConnection(BuilderContext context, T edge, Node node, GraphCommandFactory commandFactory) {
Double[] targetDocker = null;
if (dockers != null && dockers.size() > 1) {
targetDocker = dockers.get(dockers.size() - 1);
}
Connection targetConnection = null;
if (null != targetDocker) {
targetConnection = MagnetConnection.Builder.at(targetDocker[0], targetDocker[1]).setAuto(isTargetAutoConnection());
}
SetConnectionTargetNodeCommand setTargetNodeCommand = commandFactory.setTargetNode(node, edge, targetConnection);
CommandResult<RuleViolation> setTargetResult = context.execute(setTargetNodeCommand);
if (hasErrors(setTargetResult)) {
throw new RuntimeException("Error building BPMN graph. Command 'SetConnectionTargetNodeCommand' execution failed.");
}
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AbstractNodeBuilder method afterNodeBuild.
@SuppressWarnings("unchecked")
protected void afterNodeBuild(final BuilderContext context, final T node) {
// Outgoing connections.
if (outgoingResourceIds != null && !outgoingResourceIds.isEmpty()) {
for (String outgoingNodeId : outgoingResourceIds) {
GraphObjectBuilder<?, ?> outgoingBuilder = getBuilder(context, outgoingNodeId);
if (outgoingBuilder == null) {
throw new RuntimeException("No outgoing edge builder for " + outgoingNodeId);
}
final List<Command<GraphCommandExecutionContext, RuleViolation>> commands = new LinkedList<>();
// If outgoing element it's a node means that it's docked.
if (outgoingBuilder instanceof AbstractNodeBuilder) {
// Command - Create the docked node.
Node docked = (Node) outgoingBuilder.build(context);
commands.add(context.getCommandFactory().addDockedNode(node, docked));
// Obtain docked position and use those for the docked node.
final List<Double[]> dockers = ((AbstractNodeBuilder) outgoingBuilder).dockers;
if (!dockers.isEmpty()) {
// TODO: Use not only first docker coordinates?
Double[] dCoords = dockers.get(0);
double x = dCoords[0];
double y = dCoords[1];
commands.add(context.getCommandFactory().updatePosition(docked, new Point2D(x, y)));
}
} else {
// Create the outgoing edge.
AbstractEdgeBuilder edgeBuilder = (AbstractEdgeBuilder) outgoingBuilder;
Edge edge = (Edge) edgeBuilder.build(context);
if (edge != null) {
// Command - Execute the graph command to set the node as the edge connection's source..
Double[] sourceDocker = null;
final List<Double[]> dockers = ((AbstractEdgeBuilder) outgoingBuilder).dockers;
if (dockers != null && dockers.size() > 1) {
sourceDocker = dockers.get(0);
}
Connection sourceConnection = null;
if (null != sourceDocker) {
sourceConnection = MagnetConnection.Builder.at(sourceDocker[0], sourceDocker[1]).setAuto(edgeBuilder.isSourceAutoConnection());
}
commands.add(context.getCommandFactory().setSourceNode(node, edge, sourceConnection));
}
}
if (!commands.isEmpty()) {
for (Command<GraphCommandExecutionContext, RuleViolation> command : commands) {
doExecuteCommand(context, command);
}
}
}
}
// Children connections.
if (childNodeIds != null && !childNodeIds.isEmpty()) {
for (String childNodeId : childNodeIds) {
GraphObjectBuilder<?, ?> childNodeBuilder = getBuilder(context, childNodeId);
if (childNodeBuilder == null) {
throw new RuntimeException("No child node builder for " + childNodeId);
}
Command<GraphCommandExecutionContext, RuleViolation> command = null;
if (childNodeBuilder instanceof NodeObjectBuilder) {
// Command - Create the child node and the parent-child relationship.
Node childNode = (Node) childNodeBuilder.build(context);
command = context.getCommandFactory().addChildNode(node, childNode);
}
if (null != command) {
doExecuteCommand(context, command);
}
}
}
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SessionDiagramEditorScreen method validateAndSave.
private void validateAndSave() {
final Command save = this::save;
final EditorToolbar toolbar = (EditorToolbar) presenter.getToolbar();
toolbar.getValidateToolbarCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
log(Level.INFO, "Validation success.");
save.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
log(Level.WARNING, "Validation failed [violations=" + violations.toString() + "].");
// Allow saving when only warnings founds.
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (!maxSeverity.equals(Violation.Type.ERROR)) {
save.execute();
}
}
});
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SessionDiagramEditorScreen method validateAndSave.
private void validateAndSave() {
final Command save = this::save;
final EditorToolbar toolbar = (EditorToolbar) presenter.getToolbar();
toolbar.getValidateToolbarCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
log(Level.INFO, "Validation success.");
save.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
log(Level.WARNING, "Validation failed [violations=" + violations.toString() + "].");
// Allow saving when only warnings founds.
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (!maxSeverity.equals(Violation.Type.ERROR)) {
save.execute();
}
}
});
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class AddChildNodeCommand method allow.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> allow(final GraphCommandExecutionContext context) {
ensureInitialized(context);
// Check if rules are present.
if (null == context.getRuleManager()) {
return GraphCommandResultBuilder.SUCCESS;
}
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(getGraph(context), Optional.of(candidate), Optional.of(CardinalityContext.Operation.ADD)));
final Collection<RuleViolation> violations = new LinkedList<RuleViolation>();
violations.addAll(containmentRuleViolations);
violations.addAll(cardinalityRuleViolations);
return new GraphCommandResultBuilder(violations).build();
}
Aggregations