@Test public void checkUndoWhenChildHasExistingParent() { setChildNode(parent, candidate, index, originalParent, originalIndex); final Node<View<?>, Edge> newParent = CommandTestUtils.makeNode("uuid3", "existingParent", 10.0, 20.0, 50.0, 50.0); final CaseManagementSetChildNodeGraphCommand addToNewParentCommand = setChildNode(newParent, candidate, index, Optional.of(parent), OptionalInt.of(0)); addToNewParentCommand.undo(context); assertEquals(0, newParent.getOutEdges().size()); assertEquals(1, parent.getOutEdges().size()); assertEquals(1, candidate.getInEdges().size()); assertEquals(parent.getOutEdges().get(0), candidate.getInEdges().get(0)); final Edge edge = parent.getOutEdges().get(0); assertEquals(parent, edge.getSourceNode()); assertEquals(candidate, edge.getTargetNode()); assertTrue(edge.getContent() instanceof Child); }
@Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { getEdgeForTarget(in, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, in.get(), child, context)); getEdgeForSource(out, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, out.get(), context)); getEdgeForTarget(Optional.of(parent), child, childPredicate()) .ifPresent((e) -> removeRelationship(e, parent, child, context)); edge.ifPresent(e -> addRelationship(in.get(), out.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); if (originalIn.isPresent() && originalOut.isPresent()) { getEdgeForTarget(originalIn, originalOut.get(), sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), originalOut.get(), context)); } originalOut.ifPresent((p) -> addRelationship(child, originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); originalIn.ifPresent((p) -> addRelationship(originalIn.get(), child, OptionalInt.empty(), context, sequenceFlowSupplier())); originalParent.ifPresent((p) -> addRelationship(originalParent.get(), child, originalIndex, context, Child::new)); undoResizeNodes(); return GraphCommandResultBuilder.SUCCESS; }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { getEdgeForTarget(in, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, in.get(), child, context)); getEdgeForSource(out, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, out.get(), context)); getEdgeForTarget(Optional.of(parent), child, childPredicate()) .ifPresent((e) -> removeRelationship(e, parent, child, context)); edge.ifPresent(e -> addRelationship(in.get(), out.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); if (originalIn.isPresent() && originalOut.isPresent()) { getEdgeForTarget(originalIn, originalOut.get(), sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), originalOut.get(), context)); } originalOut.ifPresent((p) -> addRelationship(child, originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); originalIn.ifPresent((p) -> addRelationship(originalIn.get(), child, OptionalInt.empty(), context, sequenceFlowSupplier())); originalParent.ifPresent((p) -> addRelationship(originalParent.get(), child, originalIndex, context, Child::new)); undoResizeNodes(); return GraphCommandResultBuilder.SUCCESS; } }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { getEdgeForTarget(in, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, in.get(), child, context)); getEdgeForSource(out, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, out.get(), context)); getEdgeForTarget(Optional.of(parent), child, childPredicate()) .ifPresent((e) -> removeRelationship(e, parent, child, context)); edge.ifPresent(e -> addRelationship(in.get(), out.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); if (originalIn.isPresent() && originalOut.isPresent()) { getEdgeForTarget(originalIn, originalOut.get(), sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), originalOut.get(), context)); } originalOut.ifPresent((p) -> addRelationship(child, originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); originalIn.ifPresent((p) -> addRelationship(originalIn.get(), child, OptionalInt.empty(), context, sequenceFlowSupplier())); originalParent.ifPresent((p) -> addRelationship(originalParent.get(), child, originalIndex, context, Child::new)); undoResizeNodes(); return GraphCommandResultBuilder.SUCCESS; } 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 { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { getEdgeForTarget(in, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, in.get(), child, context)); getEdgeForSource(out, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, out.get(), context)); getEdgeForTarget(Optional.of(parent), child, childPredicate()) .ifPresent((e) -> removeRelationship(e, parent, child, context)); edge.ifPresent(e -> addRelationship(in.get(), out.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); if (originalIn.isPresent() && originalOut.isPresent()) { getEdgeForTarget(originalIn, originalOut.get(), sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), originalOut.get(), context)); } originalOut.ifPresent((p) -> addRelationship(child, originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); originalIn.ifPresent((p) -> addRelationship(originalIn.get(), child, OptionalInt.empty(), context, sequenceFlowSupplier())); originalParent.ifPresent((p) -> addRelationship(originalParent.get(), child, originalIndex, context, Child::new)); undoResizeNodes(); return GraphCommandResultBuilder.SUCCESS; } 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 { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { getEdgeForTarget(in, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, in.get(), child, context)); getEdgeForSource(out, child, sequencePredicate()) .ifPresent((e) -> removeRelationship(e, child, out.get(), context)); getEdgeForTarget(Optional.of(parent), child, childPredicate()) .ifPresent((e) -> removeRelationship(e, parent, child, context)); edge.ifPresent(e -> addRelationship(in.get(), out.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); if (originalIn.isPresent() && originalOut.isPresent()) { getEdgeForTarget(originalIn, originalOut.get(), sequencePredicate()) .ifPresent((e) -> removeRelationship(e, originalIn.get(), originalOut.get(), context)); } originalOut.ifPresent((p) -> addRelationship(child, originalOut.get(), OptionalInt.empty(), context, sequenceFlowSupplier())); originalIn.ifPresent((p) -> addRelationship(originalIn.get(), child, OptionalInt.empty(), context, sequenceFlowSupplier())); originalParent.ifPresent((p) -> addRelationship(originalParent.get(), child, originalIndex, context, Child::new)); undoResizeNodes(); return GraphCommandResultBuilder.SUCCESS; } 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();  }