通过行为向Alfresco中上载的文档添加类型
我试图将一个文档类型与xz:xylo相关联,每当一个文档上传到Alfresco的特定工作区时,它都应该附加到我在xylomodel.xml中定义的类型 我正试图通过露天行为实现这一点,因为通过共享处理对我的要求有一些限制 如果所附代码在语法上是正确的,并且我正在正确接近,请任何人纠正我通过行为向Alfresco中上载的文档添加类型,alfresco,Alfresco,我试图将一个文档类型与xz:xylo相关联,每当一个文档上传到Alfresco的特定工作区时,它都应该附加到我在xylomodel.xml中定义的类型 我正试图通过露天行为实现这一点,因为通过共享处理对我的要求有一些限制 如果所附代码在语法上是正确的,并且我正在正确接近,请任何人纠正我 enter code here 公共类ApplyXyloAspect实现NodeServicePolicys.OnCreateNodePolicy{` private NodeService nodeServi
enter code here
公共类ApplyXyloAspect实现NodeServicePolicys.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
然后,如果创建的节点的父节点与该节点匹配,我将只签入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/工作区是文件夹还是站点或其他内容)
希望这能有所帮助。根据您的需求,您最好通过以下方式实现这一点 如果文件夹规则不充分,或者我误解了您对
workspace://SpacesStore/973e1b8d-bf61-8196-3278-fbbf0b4375gg
然后,如果创建的节点的父节点与该节点匹配,我将只签入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/工作区是文件夹还是站点或其他内容)
希望这能有所帮助。非常感谢您的回复和帮助。我的代码在if(nodeService.exists(nodeRef)和&nodeService.exists(parentRef)和&nodeService.exists(idealParentNodeRef))处被删除…声明空点异常。是否需要执行任何声明才能使用nodeService?是的,与policyComponent非常相似,您需要为该属性引用nodeService bean(确保您也为其创建了setter方法)在为该类定义bean的上下文文件中。Hi-看起来我的代码现在没有错误,但当我尝试调用onAddDocument方法时,它不会触发,并且我的控件永远不会指向该方法。getPolicyComponent().BindClassBehavior(NodeServicePolicys.OnCreateNodePolicy.QNAME、ContentModel.TYPE_XYLO、new JavaBehavior(这是“onAddDocument”、Behavior.NotificationFrequency.FIRST_事件));检查bean定义,确保将init-method属性设置为类中的init方法。非常感谢您的回复和帮助。如果(nodeService.exists(nodeRef)&&nodeService.exists(parentRef)&&nodeService.exists(idealParentNodeRef))…声明空点异常。使用nodeService需要做什么声明吗?是的,很像policyComponent,您需要为该属性引用nodeService bean(确保您也为其创建了setter方法)在为该类定义bean的上下文文件中。Hi-看起来我的代码现在没有错误,但当我尝试调用onAddDocument方法时,它不会触发,并且我的控件永远不会指向该方法。getPolicyComponent().BindClassBehavior(NodeServicePolicys.OnCreateNodePolicy.QNAME、ContentModel.TYPE_XYLO、new JavaBehavior(这是“onAddDocument”、Behavior.NotificationFrequency.FIRST_事件));检查bean定义并确保将init method属性设置为类中的init方法。