通过行为为在Alfresco上传的文档添加类型



我正在尝试将文档类型与xz:xylo相关联,每当文档上传到Alfresco的特定工作区时,它都应该附加到我在xylomodel.xml中定义的类型。

我正在尝试通过Alfresco行为来实现这一点,因为通过Share处理对我的要求有一些限制。

如果附加的代码在语法上正确并且我正在正确接近,任何人都可以纠正我。

enter code here

public class ApplyXyloAspect 实现 NodeServicePolicies.OnCreateNodePolicy {'

private NodeService nodeService;
private PolicyComponent policyComponent;
// Behaviours
private Behaviour onCreateNode;
}
/**
^When a document of type @XyloCmsType(name = "X:xz:Xylo") is created than aspects from xyloModel.xml
^needs to be applied
*/
public void init() {
// Create behaviours
if workspace=workspace://SpacesStore/973e1b8d-bf61-8196-3278-fbbf0b4375gg
org.alfresco.repo.node.NodeServicePolicies this.onCreateNode = new JavaBehaviour(this, "onCreateNode", NotificationFrequency.FIRST_EVENT);
// Bind behaviours to node policies
this.policyComponent.bindClassBehaviour(Qname.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),
Qname.createQName(XYLO.NAMESPACE_XYLO_CONTENT_MODEL, XYLO.TYPE_xz_xyloModel),
this.onCreateNode
);
}

根据您的要求,最好通过文件夹规则来实现此目的。

如果文件夹规则不够,或者如果我误解了您对workspace://SpacesStore/973e1b8d-bf61-8196-3278-fbbf0b4375gg非常具体的 NodeRef 的使用,那么如果创建的节点的父节点与该 NodeRef 匹配,我只会签入 onCreateNode 方法,而不是尝试签入 init 方法。

所以在你的 init 方法中,你只会做这样的事情:

this.onCreateNode = new JavaBehaviour(this, "onCreateNode", Behaviour.NotificationFrequency.FIRST_EVENT);
this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnCreateNodePolicy.QNAME, Qname.createQName(XYLO.NAMESPACE_XYLO_CONTENT_MODEL, XYLO.TYPE_xz_xyloModel), this.onCreateNode);

然后只需检查该节点是否是您尝试成为父节点的子节点,在这种情况下,您说它会workspace://SpacesStore/973e1b8d-bf61-8196-3278-fbbf0b4375gg

所以onCreateNode方法看起来像这样。

@Override
public void onCreateNode(ChildAssociationRef childAssociationRef){
NodeRef idealParentNodeRef = new NodeRef("workspace://SpacesStore/973e1b8d-bf61-8196-3278-fbbf0b4375gg");
NodeRef nodeRef = childAssociationRef.getChildRef();
NodeRef parentRef = childAssociationRef.getParentRef();
//First double check and make sure all the nodes exist.
if(nodeService.exists(nodeRef) && nodeService.exists(parentRef) && nodeService.exists(idealParentNodeRef)){
//then check if the parentRef and the idealParentNodeRef match
if(parentRef.equals(idealParentNodeRef)){
nodeService.addAspect(nodeRef, /*QName of the Aspect you want to add*/);
}
}
}

如果您知道您要上传到的节点/工作区每次都可以执行此操作时都非常具体,尽管我可能还建议引入一些错误处理、日志记录等,但这至少会让您入门。

请注意,一般来说,您不一定期望 NodeRef 每次都保持不变,当然,我只是根据帖子中的信息向您展示您可以做什么,而不是您应该做什么(这将找到其他方法来引用您尝试使用的 NodeRef/工作区,然后从那里继续,取决于该 NodeRef/工作区是文件夹还是站点,还是其他内容(。

希望这有帮助。

最新更新