Adding type to a document uploaded in Alfresco through behaviour

cancel
Showing results for 
Search instead for 
Did you mean: 
rs1603
Member II

Adding type to a document uploaded in Alfresco through behaviour

I am trying to associate a document type to xz:xylo, whenever a document is uploaded in a particular workspace of Alfresco, it should get attached to a type which I defined in xyloModel.xml.

I am trying to achieve this via Alfresco behaviour as procceding via Share has some limitation for my requirement.

Can anyone please correct me if the code attached is syntacially correct and I am approaching correctly.

public class ApplyXyloAspect implements NodeServicePolicies.OnCreateNodePolicy {
// Dependencies
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
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);
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
1 Reply
afaust
Master

Re: Adding type to a document uploaded in Alfresco through behaviour

A compiler can check for you if the code is syntactically correct.

If your use case is to assign aspects to nodes of your custom type, then there is no need for a behaviour / policy. You can specify default aspects in your type and Alfresco will always make sure these aspects are applied to any node of that type.

But from the sound of your question I reckon you have been using the Share Content Model Manager to define the model, so maybe you are restricted by that tool.

I don't see any implementation of the onCreateNode method in your code. Your code formatting seems to be quite off, which would likely cause errors in a compiler. There are no setters for the dependencies. I particularly dislike the use of "init" (init-method specified in Spring) for initialisation, but that is a personal preference and unfortunately all examples you find online are full of that. I just find it better / cleaner to use the afterPropertiesSet lifecycle method defined by implementing the interface InitializingBean.

I am going ahead and applying code highlighting to your post...