How can add mandatory aspect on cm:content type on runtime

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
4535992
Established Member II

How can add mandatory aspect on cm:content type on runtime

Jump to solution

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.

1 Solution

Accepted Solutions
sanjaybandhniya
Senior Member

Re: How can add mandatory aspect on cm:content type on runtime

Jump to solution

You can create policy/behavior of OnCreateNodePolicy  and add  aspect on created node.

Behaviors/Policies | Alfresco Documentation

Thanks,

Contcentric

View solution in original post

2 Replies
sanjaybandhniya
Senior Member

Re: How can add mandatory aspect on cm:content type on runtime

Jump to solution

You can create policy/behavior of OnCreateNodePolicy  and add  aspect on created node.

Behaviors/Policies | Alfresco Documentation

Thanks,

Contcentric

View solution in original post

Moderator
Moderator

Re: How can add mandatory aspect on cm:content type on runtime

Jump to solution

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.