diff --git a/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareDropConstraint.java b/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareDropConstraint.java index 17a2303..663f880 100644 --- a/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareDropConstraint.java +++ b/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareDropConstraint.java @@ -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()); @@ -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; @@ -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 getParent(final Node node) { try { return Optional.ofNullable(node.getParent()); diff --git a/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareJcrContentClipboard.java b/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareJcrContentClipboard.java index 42fa3a7..b3c0e36 100644 --- a/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareJcrContentClipboard.java +++ b/src/main/java/com/namics/oss/magnolia/appbuilder/ui5/dropconstraint/NodeTypeConstraintAwareJcrContentClipboard.java @@ -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 { @@ -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; @@ -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); + } }