AnsweredAssumed Answered

Workflow custom contraint, inject serviceRegistry

Question asked by eml3400 on Sep 16, 2010
I defined a custom workflow. Within the custom workflow I defined a custom constraint so I will only see certain values that I want. When I start alfresco I am getting the "ERROR [org.springframework.web.context.ContextLoader] Context initialization failed" error. It is a null pointer exception on the following line in my custom constraint class:

Set<String> groups = this.serviceRegistry.getAuthorityService().getContainedAuthorities(… , … , ….);


It appears I am not injecting the serviceRegistry or authorityService corrrectly.

The constraint is defined within the workflow as follows in the workflow model xml file:

   
   <constraints>
        <constraint name="my:groupAssignmentConstraint" type="org.mycompany.constraints.GroupAssignmentConstraint"></constraint>
   </constraints>


Custom Contraint Class:

public class GroupAssignmentConstraint extends ListOfValuesConstraint {
   
   protected ServiceRegistry serviceRegistry;
   protected AuthorityService authorityService;
  
   public void setAllowedValues(List allowedValues) {}

   @Override
   public void initialize() {
   }

   @Override
   public List<String> getAllowedValues(){
         
      List<String> allowedGroups = new ArrayList<String>();
      Set<String> groups = this.serviceRegistry.getAuthorityService().getContainedAuthorities(code to get authorities I want);
      return allowedValues;
   }
   
   @Override
   public Map<String, Object> getParameters()
   {
       return new HashMap<String, Object>();
   }
  
   protected AuthorityService getAuthorityService() {

      AuthorityService returnAuthorityService = this.serviceRegistry.getAuthorityService();

      return returnAuthorityService;
   }
   
   public ServiceRegistry getServiceRegistry(){
      return serviceRegistry;
   }

   public void setServiceRegistry(ServiceRegistry serviceRegistry){
      this.serviceRegistry = serviceRegistry;
   }
   

   public void setAuthorityService(AuthorityService authorityService){
      this.authorityService = authorityService;
   }
}

I am attempting to inject the authorityService and serviceRegistry in an extended workflow-context.xml file as follows:


   <bean id="GroupAssignmentConstraint" class="org.mycompany.constraints.GroupAssignmentConstraint">
      <property name="serviceRegistry">
         <ref bean="ServiceRegistry"/>
      </property>
      <property name="authorityService">
         <ref bean="AuthorityService"/>
      </property>
   </bean>
     <bean id="parallel.workflowBootstrap" parent="workflowDeployer">
      <property name="workflowDefinitions">……
      </property>
   </bean>



Parital output of stacktrace:


09:13:07,282 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
java.lang.NullPointerException
   at org.mycompany.constraints.GroupAssignmentConstraint.getAllowedValues(GroupAssignmentConstraint.java:36)
   at org.alfresco.cmis.dictionary.CMISBasePropertyDefinition.<init>(CMISBasePropertyDefinition.java:108)
   at org.alfresco.cmis.dictionary.CMISAbstractTypeDefinition.createProperty(CMISAbstractTypeDefinition.java:126)
   at org.alfresco.cmis.dictionary.CMISAbstractTypeDefinition.createProperties(CMISAbstractTypeDefinition.java:104)
   at org.alfresco.cmis.dictionary.CMISAbstractDictionaryService.init(CMISAbstractDictionaryService.java:394)
   at org.alfresco.cmis.dictionary.CMISAbstractDictionaryService.afterDictionaryInit(CMISAbstractDictionaryService.java:465)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl.initDictionaryRegistry(DictionaryDAOImpl.java:260)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl.access$100(DictionaryDAOImpl.java:66)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl$1.doWork(DictionaryDAOImpl.java:196)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl$1.doWork(DictionaryDAOImpl.java:189)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:489)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl.initDictionary(DictionaryDAOImpl.java:187)
   at org.alfresco.repo.dictionary.DictionaryDAOImpl.init(DictionaryDAOImpl.java:135)
   at org.alfresco.repo.dictionary.NamespaceDAOImpl.reset(NamespaceDAOImpl.java:125)
   at org.alfresco.repo.dictionary.NamespaceDAOImpl.getNamespaceRegistry(NamespaceDAOImpl.java:424)
   at org.alfresco.repo.dictionary.NamespaceDAOImpl.getPrefixesCtx(NamespaceDAOImpl.java:551)
   at org.alfresco.repo.dictionary.NamespaceDAOImpl.getPrefixesCtx(NamespaceDAOImpl.java:540)
   at org.alfresco.repo.dictionary.NamespaceDAOImpl.getPrefixes(NamespaceDAOImpl.java:235)
   at org.alfresco.repo.dictionary.DictionaryNamespaceComponent.getPrefixes(DictionaryNamespaceComponent.java:70)
   at org.alfresco.repo.search.NodeServiceXPath.<init>(NodeServiceXPath.java:172)
   at org.alfresco.repo.search.impl.NodeSearcher.selectNodes(NodeSearcher.java:137)
   at org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.selectNodes(ADMLuceneSearcherImpl.java:698)
   at org.alfresco.repo.search.SearcherComponent.selectNodes(SearcherComponent.java:107)


I am pretty sure the issue is the incorrect injection of the serviceRegisty. I can use some help on the proper way to do this.

Thanks,

Eric

Outcomes