@Test public void testRemoveExistingRelationship() { final Node diagram = createNode(CaseManagementDiagram.class); final Node stage = createNode(AdHocSubprocess.class); final Node start = createNode(StartNoneEvent.class); final Node end = createNode(EndNoneEvent.class); createChildEdge(diagram, start); createChildEdge(diagram, stage); createChildEdge(diagram, end); createSequenceFlow(start, stage); createSequenceFlow(stage, end); final CaseManagementSetChildNodeGraphCommand command = new CaseManagementSetChildNodeGraphCommand(diagram, stage, index, Optional.of(diagram), originalIndex); command.removeExistingRelationship(context); assertTrue(command.originalIn.isPresent()); assertEquals(start, command.originalIn.get()); assertTrue(command.originalOut.isPresent()); assertEquals(end, command.originalOut.get()); assertEquals(2, diagram.getOutEdges().size()); assertEquals(1, start.getOutEdges().size()); assertEquals(2, end.getInEdges().size()); assertEquals(end, ((Edge) start.getOutEdges().get(0)).getTargetNode()); }
@SuppressWarnings("unchecked") void removeExistingRelationship(final GraphCommandExecutionContext context) { originalParent.ifPresent(p -> { if (isStage(p, child)) { originalIn = child.getInEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getSourceNode()).findAny(); originalOut = child.getOutEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getTargetNode()).findAny(); } }); getEdgeForTarget(originalParent, child, childPredicate()) .ifPresent((e) -> removeRelationship(e, originalParent.get(), child, context)); getEdgeForTarget(originalIn, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), child, context)); getEdgeForSource(originalOut, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, originalOut.get(), context)); if (originalIn.isPresent() && originalOut.isPresent()) { addRelationship(originalIn.get(), originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier()); } }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void removeExistingRelationship(final GraphCommandExecutionContext context) { originalParent.ifPresent(p -> { if (isStage(p, child)) { originalIn = child.getInEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getSourceNode()).findAny(); originalOut = child.getOutEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getTargetNode()).findAny(); } }); getEdgeForTarget(originalParent, child, childPredicate()) .ifPresent((e) -> removeRelationship(e, originalParent.get(), child, context)); getEdgeForTarget(originalIn, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), child, context)); getEdgeForSource(originalOut, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, originalOut.get(), context)); if (originalIn.isPresent() && originalOut.isPresent()) { addRelationship(originalIn.get(), originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier()); } } }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void removeExistingRelationship(final GraphCommandExecutionContext context) { originalParent.ifPresent(p -> { if (isStage(p, child)) { originalIn = child.getInEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getSourceNode()).findAny(); originalOut = child.getOutEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getTargetNode()).findAny(); } }); getEdgeForTarget(originalParent, child, childPredicate()) .ifPresent((e) -> removeRelationship(e, originalParent.get(), child, context)); getEdgeForTarget(originalIn, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), child, context)); getEdgeForSource(originalOut, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, originalOut.get(), context)); if (originalIn.isPresent() && originalOut.isPresent()) { addRelationship(originalIn.get(), originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier()); } } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void removeExistingRelationship(final GraphCommandExecutionContext context) { originalParent.ifPresent(p -> { if (isStage(p, child)) { originalIn = child.getInEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getSourceNode()).findAny(); originalOut = child.getOutEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getTargetNode()).findAny(); } }); getEdgeForTarget(originalParent, child, childPredicate()) .ifPresent((e) -> removeRelationship(e, originalParent.get(), child, context)); getEdgeForTarget(originalIn, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), child, context)); getEdgeForSource(originalOut, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, originalOut.get(), context)); if (originalIn.isPresent() && originalOut.isPresent()) { addRelationship(originalIn.get(), originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier()); } } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); OptionalInt getIndex(); OptionalInt getOriginalIndex(); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void removeExistingRelationship(final GraphCommandExecutionContext context) { originalParent.ifPresent(p -> { if (isStage(p, child)) { originalIn = child.getInEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getSourceNode()).findAny(); originalOut = child.getOutEdges().stream() .filter(sequencePredicate()).map(e -> (Node<View<?>, Edge>) e.getTargetNode()).findAny(); } }); getEdgeForTarget(originalParent, child, childPredicate()) .ifPresent((e) -> removeRelationship(e, originalParent.get(), child, context)); getEdgeForTarget(originalIn, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), child, context)); getEdgeForSource(originalOut, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, originalOut.get(), context)); if (originalIn.isPresent() && originalOut.isPresent()) { addRelationship(originalIn.get(), originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier()); } } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); OptionalInt getIndex(); OptionalInt getOriginalIndex();  }