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 7340bac commit e0f16d7
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 @@ -16,7 +16,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 JcrClipboard implements JcrContentClipboard {
Expand Down Expand Up @@ -57,7 +59,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 @@ -66,4 +68,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,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 implements DropConstraint<Item> {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down Expand Up @@ -48,7 +50,7 @@ private boolean allowedAsSibling(final Item sourceItem, final Item targetItem) {
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 @@ -62,6 +64,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

0 comments on commit e0f16d7

Please sign in to comment.