【问题标题】:javax.jcr.nodetype.ConstraintViolationException Mandatory child node jcr:content not found in a new nodejavax.jcr.nodetype.ConstraintViolationException Mandatory child node jcr:content not found in a new node
【发布时间】:2018-03-01 06:56:57
【问题描述】:

在 AEM 中使用 JcrUtil.createPath 在 DAM Asset 中创建文件夹(目录)时,抛出异常,错误为 OakConstraint0025: /content/dam/upload/Type/99/MBT/front[[nt: file]]: 强制子节点 jcr:content not found in a new node。这可能意味着需要与目录同时创建子 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


    【解决方案1】:

    问题是 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()
    

    【讨论】:

    • 它确实有效,但只有当我删除“resourceResolver.commit()”时才有效,因为它会导致错误。我改用“session.save()”。
    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-27
    • 1970-01-01
    • 2020-10-22
    • 2011-07-20
    • 2020-11-25
    相关资源
    最近更新 更多