cancel
Showing results for 
Search instead for 
Did you mean: 

How to add custom behaviour to AVM Store?

dfundak
Champ in-the-making
Champ in-the-making
Hi, I'm trying to execute javascript every time file updated at wcm webproject.
I'm trying to add custom javascript behaviour to trigger update of content in AVM store.

I've added bean like this:


<bean id="onUpdateDoc" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration">
  <property name="policyName">
    <value>{http://www.alfresco.org}onContentUpdate</value>
        </property>
        <property name="className">
            <value>{http://www.alfresco.org/model/content/1.0}content</value>
        </property>
        <property name="behaviour">
           <bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
                        <property name="location">
                                <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
                                <constructor-arg>
                                        <value>alfresco/extension/scripts/onUpdateNode.js</value>
                                </constructor-arg>
                                </bean>
                        </property>
           </bean>
        </property>
    </bean>

When I'am updating files in dcm script get triggered.
But at wcm it doesn't.

Are there any way to trigger update/create content at wcm?

Thanks, sorry for my english.
3 REPLIES 3

pmonks
Star Contributor
Star Contributor
By default content policies aren't fired for modifications to AVM content.  You can enable it by adding the following bean definition to a custom Spring *-context.xml file in ${ALFRESCO_HOME}/tomcat/shared/classes/alfresco/extension:


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

  <bean id="avmNodeService" class="org.alfresco.repo.avm.AVMNodeService" init-method="init">
    <property name="dictionaryService" ref="dictionaryService" />
    <property name="avmService"        ref="avmLockingAwareService" />
    <property name="policyComponent"   ref="policyComponent" />
    <property name="invokePolicies"    value="true" />
  </bean>

</beans>
Cheers,
Peter

dfundak
Champ in-the-making
Champ in-the-making
Thanks a lot, Peter.
Now everything works perfect!
I own you a beer!

I've also changed property classname to {http://www.alfresco.org/model/wcmmodel/1.0}avmcontent.
Here's the code:

<bean id="avmNodeService" class="org.alfresco.repo.avm.AVMNodeService" init-method="init">
    <property name="dictionaryService" ref="dictionaryService" />
    <property name="avmService"        ref="avmLockingAwareService" />
    <property name="policyComponent"   ref="policyComponent" />
    <property name="invokePolicies"    value="true" />
  </bean>

   <bean
   id="onUpdateAVMDoc"
   class="org.alfresco.repo.policy.registration.ClassPolicyRegistration"
   parent="policyRegistration">
        <property name="policyName">
          <value>{http://www.alfresco.org}onContentUpdate</value>
              </property>
              <property name="className">
                  <value>{http://www.alfresco.org/model/wcmmodel/1.0}avmcontent</value>
              </property>
              <property name="behaviour">
                 <bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour">
                              <property name="location">
                                      <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
                                      <constructor-arg>
                                         <value>alfresco/extension/scripts/onContentUpdate.js</value>
                  </constructor-arg>
                                     </bean>
                              </property>
                 </bean>
              </property>
    </bean>

skuro
Champ in-the-making
Champ in-the-making
it looks like this does no longer works:


    public ChildAssociationRef createNode(
            NodeRef parentRef,
            QName assocTypeQName,
            QName assocQName,
            QName nodeTypeQName,
            Map<QName, Serializable> properties)
            throws InvalidNodeRefException, InvalidTypeException
    {
        // AVM stores only allow simple child associations.
        if (!assocTypeQName.equals(ContentModel.ASSOC_CONTAINS))
        {
            throw new InvalidTypeException(assocTypeQName);
        }
        String nodeName = assocQName.getLocalName();
        Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(parentRef);
        int version = avmVersionPath.getFirst();
        if (version >= 0)
        {
            throw new InvalidNodeRefException("Read only store.", parentRef);
        }
        String avmPath = avmVersionPath.getSecond();
        // Invoke policy behavior.
        // invokeBeforeUpdateNode(parentRef);
        // invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName);
        // Look up the type definition in the dictionary.
        TypeDefinition nodeTypeDef = dictionaryService.getType(nodeTypeQName);
        // Do the creates for supported types, or error out.
        try
        {

the policy invokations are all commented out. Is there any good reason why I should NOT uncomment it? 🙂