cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Action not working

doblek
Champ in-the-making
Champ in-the-making
Hi all,

I don't know if this is the appropiate forum, but I'll give it a shot…


I'm trying to develop a Custom Action following the steps that I've founded in the wiki:
So, taking these guidelines into account, I've created the following files:

[size=150]01_tagsModel.xml[/size] [located at 'WEB-INF/classes/alfresco/extension' folder]

<?xml version="1.0" encoding="UTF-8"?>

<!– Definition of new Model –>
<model name="tag:tagsmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Tagging Model</description>
   <author>Gavin Cornwell</author>
   <version>1.0</version>

   <!– Imports are required to allow references to definitions in other models –>  
   <imports>
      <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <namespaces>
      <namespace uri="extension.tags" prefix="tag"/>
   </namespaces>
 
    <aspects>
     
      <!– Definition of new Taggable Aspect –>
      <aspect name="tag:taggable">
         <title>Taggable</title>
         <properties>
            <property name="tag:tags">
               <title>Tags</title>
               <type>d:text</type>
               <multiple>true</multiple>
            </property>
         </properties>
      </aspect>
     
   </aspects>
  
</model>

[size=150]01_tags-context.xml[/size] [located at 'WEB-INF/classes/alfresco/extension' folder]

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

<!– Tags bean definitions –>
<beans>
   <bean id="tags.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
      <property name="models">
         <list>
            <value>alfresco/extension/01_tagsModel.xml</value>
         </list>
      </property>
   </bean>
   
   <!– <bean id="tag" class="org.alfresco.sample.TagActionExecuter" parent="action-executer" > –>
   <bean id="tag" class="dit.alfresco.ext.action.executer.TagActionExecuter" parent="action-executer" >
      <property name="nodeService">
         <ref bean="nodeService" />
      </property>
   </bean>
   
   <bean id="tag-action-messages" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>dit.alfresco.ext.action.executer.01_tag-action-messages</value>
         </list>
      </property>
   </bean>

</beans>

And I have an ext-action-tag.jar file at 'WEB-INF/lib' containing:
dit»alfresco»ext»action»executer»TagActionExecuter.class
dit»alfresco»ext»action»executer»01_tag-action-messages.properties

where the java file is:

package dit.alfresco.ext.action.executer;

import org.alfresco.repo.action.executer.*;
import org.alfresco.service.cmr.repository.*;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.namespace.QName;
import java.util.List;

public class TagActionExecuter extends ActionExecuterAbstractBase
{
      public static final String NAME = "tag";

      private NodeService nodeService;

      public void setNodeService(NodeService nodeService)
      {
         this.nodeService = nodeService;
      }
     
      @Override
      public void executeImpl(Action action, NodeRef actionedUponNodeRef){
         if (this.nodeService.exists(actionedUponNodeRef) == true){
            // add the aspect if it is not already present on the node
            QName tagAspect = QName.createQName("extension.tags", "taggable");
            if (this.nodeService.hasAspect(actionedUponNodeRef, tagAspect) == false){
               this.nodeService.addAspect(actionedUponNodeRef, tagAspect, null);
            }
         }
     }
     
      @Override
      protected void addParameterDefintions(List<ParameterDefinition> paramList){
         //there are no parameters
      }
}

but I'm always getting this error message when creating the bean and I don't know why:
18:37:27,778 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco]] Excepción enviando evento de contexto destruído a instancia de escuchador de clase org.alfresco.web.app.ContextListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tag' defined in file [C:\apache-tomcat-5.5.17\webapps\alfresco\WEB-INF\classes\alfresco\extension\01_tags-context.xml]: Initialization of bean failed; nested exception is java.lang.AbstractMethodError: null
java.lang.AbstractMethodError
   at org.alfresco.repo.action.ParameterizedItemAbstractBase.getParameterDefintions(ParameterizedItemAbstractBase.java:76)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.getActionDefinition(ActionExecuterAbstractBase.java:97)
   at org.alfresco.repo.action.ActionServiceImpl.registerActionExecuter(ActionServiceImpl.java:549)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.init(ActionExecuterAbstractBase.java:56)
   at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1093)
[…]

Can anyone give some advice, please?
I really need your help.

Regards,
Enrique
2 REPLIES 2

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

From sight there seems to be nothing wrong with the code and the config.

Looking up the meaning of the error on Google I get ..

'Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.'

I'd suggest double checking for compile errors when constructing the jar and ensureing that the jars you are comiling against are the same as those in the runtime environment.

Perhaps a unit test (see those in the repository code for examples) will help to prove that your action is working and this is a deployment issue.

Cheers,
Roy

doblek
Champ in-the-making
Champ in-the-making
Hi Roy,

I've made a unit test, as you suggest me, that looks like this:

package dit.alfresco.ext.action.executer;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.*;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;


public class TagActionExecuterTest extends BaseSpringTest{
   
   private NodeService nodeService;      //The node service
   private StoreRef testStoreRef;         //The store reference
   private NodeRef rootNodeRef;         //The root node reference
   private NodeRef nodeRef;            //The test node reference
   private TagActionExecuter executer;      //The tag action executer
   private final static String ID = GUID.generate();      //ID used to identify the test action created
   
   @Override
   protected void onSetUpInTransaction() throws Exception{
      this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
      
      //Create the store and get the root node
      this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_"+System.currentTimeMillis());
      this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
      
      //Create the node used for tests
      this.nodeRef = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_CONTENT).getChildRef();
      
      //Get the executer instance
      this.executer = (TagActionExecuter) this.applicationContext.getBean(TagActionExecuter.NAME);
   }
   
   //Test execution
   public void testExecution(){
      
      //Check that the node does not have the taggable aspect
      assertFalse(this.nodeService.hasAspect(this.nodeRef, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "taggable")));
      
      //Execute the action
      ActionImpl action = new ActionImpl(ID, TagActionExecuter.NAME, null);
      //action.setParameterValue();
      this.executer.execute(action, this.nodeRef);
      
      //Check that hte node now has the classifiable aspect applied
      assertTrue(this.nodeService.hasAspect(this.nodeRef, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "taggable")));
   }
}

But it crashes:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userBootstrap' defined in class path resource [alfresco/bootstrap-context.xml]: Can't resolve reference to bean 'nodeService' while setting property 'nodeService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nodeService' defined in class path resource [alfresco/node-services-context.xml]: Can't resolve reference to bean 'dbNodeService' while setting property 'defaultBinding'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.alfresco.repo.node.db.DbNodeServiceImpl#1e13e07' defined in class path resource [alfresco/node-services-context.xml]: Can't resolve reference to bean 'policyComponent' while setting property 'constructor argument'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'policyComponent' defined in class path resource [alfresco/core-services-context.xml]: Can't resolve reference to bean 'dictionaryService' while setting property 'constructor argument with index 0'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictionaryBootstrap' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: Could not import bootstrap model alfresco/model/dictionaryModel.xml
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nodeService' defined in class path resource [alfresco/node-services-context.xml]: Can't resolve reference to bean 'dbNodeService' while setting property 'defaultBinding'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.alfresco.repo.node.db.DbNodeServiceImpl#1e13e07' defined in class path resource [alfresco/node-services-context.xml]: Can't resolve reference to bean 'policyComponent' while setting property 'constructor argument'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'policyComponent' defined in class path resource [alfresco/core-services-context.xml]: Can't resolve reference to bean 'dictionaryService' while setting property 'constructor argument with index 0'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictionaryBootstrap' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: Could not import bootstrap model alfresco/model/dictionaryModel.xml
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.alfresco.repo.node.db.DbNodeServiceImpl#1e13e07' defined in class path resource [alfresco/node-services-context.xml]: Can't resolve reference to bean 'policyComponent' while setting property 'constructor argument'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'policyComponent' defined in class path resource [alfresco/core-services-context.xml]: Can't resolve reference to bean 'dictionaryService' while setting property 'constructor argument with index 0'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictionaryBootstrap' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: Could not import bootstrap model alfresco/model/dictionaryModel.xml
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'policyComponent' defined in class path resource [alfresco/core-services-context.xml]: Can't resolve reference to bean 'dictionaryService' while setting property 'constructor argument with index 0'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictionaryBootstrap' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: Could not import bootstrap model alfresco/model/dictionaryModel.xml
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictionaryBootstrap' defined in class path resource [alfresco/core-services-context.xml]: Initialization of bean failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: Could not import bootstrap model alfresco/model/dictionaryModel.xml
org.alfresco.service.cmr.dictionary.DictionaryException: Could not import bootstrap model alfresco/model/dictionaryModel.xml
   at org.alfresco.repo.dictionary.DictionaryBootstrap.bootstrap(DictionaryBootstrap.java:94)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1093)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1063)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:312)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveConstructorArguments(AbstractAutowireCapableBeanFactory.java:706)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:611)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:329)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveConstructorArguments(AbstractAutowireCapableBeanFactory.java:714)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:611)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:329)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:203)
   at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:614)
   at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:496)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
   at org.springframework.test.AbstractSpringContextTests.loadContextLocations(AbstractSpringContextTests.java:121)
   at org.springframework.test.AbstractDependencyInjectionSpringContextTests.loadContextLocations(AbstractDependencyInjectionSpringContextTests.java:210)
   at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:101)
   at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:178)
   at junit.framework.TestCase.runBare(TestCase.java:125)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.alfresco.service.cmr.dictionary.DictionaryException: Failed to parse model
   at org.alfresco.repo.dictionary.M2Model.createModel(M2Model.java:91)
   at org.alfresco.repo.dictionary.DictionaryBootstrap.bootstrap(DictionaryBootstrap.java:89)
   … 66 more
Caused by: org.jibx.runtime.JiBXException: Unable to access binding information for class org.alfresco.repo.dictionary.M2Model
Make sure the binding has been compiled
   at org.jibx.runtime.BindingDirectory.getBindingList(BindingDirectory.java:77)
   at org.jibx.runtime.BindingDirectory.getFactory(BindingDirectory.java:189)
   at org.alfresco.repo.dictionary.M2Model.createModel(M2Model.java:84)
   … 67 more

Though I think maybe I'm doing test in a bad way… because it seems that it's unable to create the 'nodeService' bean =/

I've just run the 'testExecution' method in Eclipse calling "Run As » JUnit Test"… is that right?

Thanks anyway, Roy =D