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

时间:2018-03-01 06:56:57

标签: aem cq5

当使用JcrUtil.createPath在AEM中的DAM Asset中创建文件夹(目录)时,会抛出一个错误 OakConstraint0025:/ content / dam / upload / Type / 99 / MBT / front [[nt: file]]:强制子节点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?

请帮忙!

1 个答案:

答案 0 :(得分: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()