Skip to content

Commit

Permalink
consider mixin node types when evaluating nodeType constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Feb 16, 2024
1 parent 47de295 commit 7cd0477
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;

public class NodeTypeConstraintAwareDropConstraint extends AlwaysTrueDropConstraint implements DropConstraint {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down Expand Up @@ -49,7 +51,7 @@ public boolean allowedToMove(final com.vaadin.v7.data.Item sourceItem) {
protected boolean allowedAsChild(final Node src, final Node dst) {
try {
if(Objects.equals(src.getSession().getWorkspace().getName(), dst.getSession().getWorkspace().getName())) {
for (NodeDefinition allowedChildNodeDefinition : dst.getPrimaryNodeType().getChildNodeDefinitions()) {
for (NodeDefinition allowedChildNodeDefinition : getChildNodeDefinitions(dst)) {
for (NodeType allowedChildRequiredPrimaryType : allowedChildNodeDefinition.getRequiredPrimaryTypes()) {
if (Objects.equals(src.getPrimaryNodeType(), allowedChildRequiredPrimaryType)) {
return true;
Expand All @@ -63,6 +65,13 @@ protected boolean allowedAsChild(final Node src, final Node dst) {
return false;
}

private NodeDefinition[] getChildNodeDefinitions(final Node node) throws RepositoryException {
return Stream.concat(
Stream.of(node.getPrimaryNodeType()),
Arrays.stream(node.getMixinNodeTypes())
).map(NodeType::getChildNodeDefinitions).flatMap(Arrays::stream).toArray(NodeDefinition[]::new);
}

private Optional<Node> getParent(final Node node) {
try {
return Optional.ofNullable(node.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Stream;

@SubAppScoped
public class NodeTypeConstraintAwareJcrContentClipboard extends JcrContentClipboard {
Expand Down Expand Up @@ -46,7 +48,7 @@ protected boolean canPasteInto(final Property source, final Node destination) th
}

protected boolean canPasteInto(final Node source, final Node destination) throws RepositoryException {
for (NodeDefinition allowedChildNodeDefinition : destination.getPrimaryNodeType().getChildNodeDefinitions()) {
for (NodeDefinition allowedChildNodeDefinition : getChildNodeDefinitions(destination)) {
for (NodeType allowedChildRequiredPrimaryType : allowedChildNodeDefinition.getRequiredPrimaryTypes()) {
if (Objects.equals(source.getPrimaryNodeType(), allowedChildRequiredPrimaryType)) {
return true;
Expand All @@ -55,4 +57,11 @@ protected boolean canPasteInto(final Node source, final Node destination) throws
}
return false;
}

private NodeDefinition[] getChildNodeDefinitions(final Node node) throws RepositoryException {
return Stream.concat(
Stream.of(node.getPrimaryNodeType()),
Arrays.stream(node.getMixinNodeTypes())
).map(NodeType::getChildNodeDefinitions).flatMap(Arrays::stream).toArray(NodeDefinition[]::new);
}
}

0 comments on commit 7cd0477

Please sign in to comment.