首页 > 解决方案 > 如何更改 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() 中的属性,但值保持不变。

标签: alfresco

解决方案


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

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);

推荐阅读