如何更改露天可审核的方面(创建者,修改者等)

时间:2019-07-16 11:19:32

标签: alfresco

我一直在使用Alfresco 4.2。我要复制从原始文件复制的所有可审核属性的文件。问题是,即使如此,我禁用了可审核方面并将我的代码放在属性无法复制的单独事务中。甚至可以复制属性(修改,修饰符,创建,创建者)。在我的Java代码下面:

    result = copy(sourceNodeRef, targetParentNodeRef, assocTypeQName, assocQName, copyChildren);

    UserTransaction userTransaction = transactionService.getUserTransaction();
    try {

        userTransaction.begin();
        this.behaviourFilter.disableBehaviour(result, ContentModel.ASPECT_AUDITABLE);
        this.behaviourFilter.disableBehaviour(QName.createQName("cm:auditable"));

        boolean disableAuditable = this.behaviourFilter.isEnabled(result, ContentModel.ASPECT_AUDITABLE);
        boolean disableCmAuditable = this.behaviourFilter.isEnabled(result, QName.createQName("cm:auditable"));

        copyFileMetadata(sourceNodeRef, result);

        userTransaction.commit();

    } catch (NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        logger.error("Error in disabling AUDITABLE ASPECT: " + e);
    } finally {

        this.behaviourFilter.enableBehaviour(result, ContentModel.ASPECT_AUDITABLE);
        this.behaviourFilter.enableBehaviour(QName.createQName("cm:auditable"));

    }

我希望将属性设置为copyFileMetadata()中的属性,但是值保持不变。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,下面是完整的代码:

UserTransaction userTransaction = transactionService.getUserTransaction();
    Map<QName, Serializable> propertiesCopy = nodeService.getProperties(destinationNode);
    try {

        userTransaction.begin();
        boolean disableAuditable = !this.behaviourFilter.isEnabled(destinationNode, ContentModel.ASPECT_AUDITABLE);
        boolean disableCmAuditable = !this.behaviourFilter.isEnabled(destinationNode, QName.createQName("cm:auditable"));

        if (disableAuditable && disableCmAuditable) {

            //copied node props
            String creator = (String) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CREATOR);
            Date created = (Date) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CREATED);
            String modifier = (String) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_MODIFIER);
            Date modified = (Date) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_MODIFIED);

            //copy of node props

            Map<QName, Serializable> auditableProps = new HashMap<>();
            auditableProps.put(ContentModel.PROP_CREATOR, creator);
            auditableProps.put(ContentModel.PROP_CREATED, created);
            auditableProps.put(ContentModel.PROP_MODIFIER, modifier);
            auditableProps.put(ContentModel.PROP_MODIFIED, modified);

            internalNodeService.setProperties(destinationNode, auditableProps);
        }

        userTransaction.commit();

    } catch (NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        logger.error("Error in disabling AUDITABLE ASPECT: " + e);
    } finally {

        this.behaviourFilter.enableBehaviour(destinationNode, ContentModel.ASPECT_AUDITABLE);
        this.behaviourFilter.enableBehaviour(destinationNode, QName.createQName("cm:auditable"));

        propertiesCopy.remove(ContentModel.PROP_MODIFIED);
        propertiesCopy.remove(ContentModel.PROP_MODIFIER);
        propertiesCopy.remove(ContentModel.PROP_CREATED);
        propertiesCopy.remove(ContentModel.PROP_CREATOR);

        internalNodeService.setProperties(destinationNode, propertiesCopy);

        this.copyAspects(sourceNodeRef, destinationNode);
    }

以上问题是我认为给出了错误的targetNode。这是destinationNode的结果:

NodeRef copyRef = this.services.getCopyService().copyAndRenameAndKeepMeta(this.nodeRef, destination.getNodeRef(),
                    ContentModel.ASSOC_CONTAINS, null, false);
            copy = newInstance(copyRef, this.services, this.scope);