Hi i need to add "mandatory aspect" on the default alfresco type "cm:content" on runtime without touching the xml model configurations.
So the solution i'm using now is the classic create a custom type with parent "cm:content" like in the following code:
<types>
<type name="up:UploadFile">
<title>Uploader Plus File</title>
<parent>cm:content</parent>
<properties>
<property name="up:classifiCationAspect2">
<title>Classification Aspect 2</title>
<type>d:text</type>
<multiple>true</multiple>
<index enabled="true">
<atomic>true</atomic>
<stored>false</stored>
<tokenised>false</tokenised>
</index>
<constraints>
<constraint ref="up:classificationAspectListConstraint" />
</constraints>
</property>
</properties>
<associations>
<association name="up:files">
<title>Related Documents</title>
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>cm:content</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
<mandatory-aspects>
<aspect>up:UploadFolder</aspect>
</mandatory-aspects>
</type>
</types>
But i need to the same thing with java code, by adding the mandatory aspect to the "cm:content" on runtime. There is some alfresco service to do that?
I can accept even a java code to modify custom model on runtime .
Greetings.
Solved! Go to Solution.
You can create policy/behavior of OnCreateNodePolicy and add aspect on created node.
Behaviors/Policies | Alfresco Documentation
Thanks,
You can create policy/behavior of OnCreateNodePolicy and add aspect on created node.
Behaviors/Policies | Alfresco Documentation
Thanks,
As Sanjay Bandhniya said, the most consistent way is to create a binding between your new aspect and your type (or another aspect) during the creation of a new node against the repo.
Anyway, there is an alternative way that strongly depends on how you are building the space tree structure for your contents.
You can also configure a rule on a space that includes the "Add Aspect" action for any new content dropped in the space. You can also select the domain of contents in the space that should be involved, for example you can consider only contents with specific types, property values or that have any other aspects. This will help you on implementing your decoration policy for any type.
Only when these conditions are validated then the aspect will be added at runtime as a decoration for the node just arrived in the space.
Please see the following page from the documentation for creating a new rule:
Creating a rule | Alfresco Documentation
I suggest to try this method because it is very quick and you don't need to implement in Java your own behaviors.
Hope this helps.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.