javax.jcr.nodetype.ConstraintViolationException必需的子节点jcr:在新节点中找不到内容

问题描述 投票:1回答:1

当使用JcrUtil.createPath在AEM中的DAM Asset中创建文件夹(目录)时,抛出异常,出现错误OakConstraint0025:/ content / dam / upload / Type / 99 / MBT / front [[nt:file]]:强制子node jcr:在新节点中找不到内容。这可能意味着需要在目录的同一时间创建子jcr:content节点。所以我真的不知道如何解决这个问题。

    // get resource resolver
    ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(Collections.<String, Object>singletonMap(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session));

    AssetManager assetMgr = resourceResolver.adaptTo(AssetManager.class);

    // creating directory in DAM Asset
    Node newParentNode = JcrUtil.createPath(splitParentPath, true, "sling:OrderedFolder", "nt:file", session, true);
    newParentNode.addNode("jcr:content", "nt:resource");

    // moving DAM Asset
    assetMgr.moveAsset(fileNode.getPath(), splitParentPath + "/" + newFileName); 

我确实遵循了这个JCRUtil API https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/reference-materials/javadoc/com/day/cq/commons/jcr/JcrUtil.html#createPath(Node,%20java.lang.String,%20boolean,%20java.lang.String,%20java.lang.String,%20Session,%20boolean),以及这个How to create a directory on the basis of path in cq5?

请帮忙 !

aem cq5
1个回答
2
投票

问题是打开了createPath方法的自动保存标志。这将尝试在您能够添加jcr:content子节点节点之前将节点提交到repo。

添加子节点后尝试保存

// creating directory in DAM Asset
Node newParentNode = JcrUtil.createPath(splitParentPath, true, "sling:OrderedFolder", "nt:file", session, false);
newParentNode.addNode("jcr:content", "nt:resource");
session.save()
© www.soinside.com 2019 - 2024. All rights reserved.