cancel
Showing results for 
Search instead for 
Did you mean: 

New Custom Evaluator

mrinal3199
Champ in-the-making
Champ in-the-making
Hi,

  What I need to achieve is like below :
- Where ever in document library, I have folder with some specific names eg: flder named as "Extranet" or "Published", I need to show one extra custom action of Bulk operation.
Currently I can see that action to every folders instead specific folder named as such..

I have created an evaluator in my share jar in the package "org.alfresco.web.evaluator.doclib.action" named as NameEqualsEvaluator.java. And in the share cnfig i have defined an action for the folders and evaluator id is given as "evaluator.doclib.action.isInstanceType". So, in Custom-slinshot-applicaton.xml, i have defined this id with parent as "org.alfresco.web.evaluator.doclib.action.NameEqualsEvaluator". I build this jar and laced it in "C:\alfresco\tomcat\webapps\share\WEB-INF\lib". I also have another utils jar which am keeping in "C:\alfresco\tomcat\webapps\alfresco\WEB-INF\lib". The problem is while starting the server, it is giving errr as:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'evaluator.doclib.action.isInstanceType' defined in URL [jar:file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/lib/SkandiaShare.jar!/alfresco/web-extension/custom-slingshot-application-context.xml]: Could not resolve parent bean definition 'org.alfresco.web.evaluator.doclib.action.NameEqualsEvaluator'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.alfresco.web.evaluator.doclib.action.NameEqualsEvaluator' is defined

I am not getting why this class is not being loaded but every webscripts which i have in utils jar are working fine.

Please suggest me how to reslve this issue.

this way my Evaluator not working.

Anyone have achieved like this in alfresco share 4?

Thanks in advance
13 REPLIES 13

tonyrivet
Champ in-the-making
Champ in-the-making
Hi,

If I understand well, you did that :

<bean id="evaluator.doclib.action.isInstanceType" parent="org.alfresco.web.evaluator.doclib.action.NameEqualsEvaluator" />


Whereas you should do that :

<bean id="evaluator.doclib.action.isInstanceType" class="org.alfresco.web.evaluator.doclib.action.NameEqualsEvaluator" />
or
<bean id="evaluator.doclib.action.isInstanceType" parent="evaluator.doclib.action.nameEquals" />
<bean id="evaluator.doclib.action.nameEquals" class="org.alfresco.web.evaluator.doclib.action.NameEqualsEvaluator" />

mrinal3199
Champ in-the-making
Champ in-the-making
Hi Tony,

     Many many thanks Tony!!! Thanks for your rely. It really helped me. Now i could load my evaluator class. Can you help me how to write this evaluator class s that i could get this acton only on some f the specific folder names in alfresco depending on their names. Like in predefined evaluator they did it for types, i want to write this evaluator and add a property which can have a list of values of names of flders on which this action can be shown. I am trying it but if you could suggest me then that will really help me speed up my work.

Thanks in advance.

tonyrivet
Champ in-the-making
Champ in-the-making
I think it's pretty simple now.
Just look at the source code of the org.alfresco.web.evaluator.HasAspectEvaluator evaluator for example. You just have to retrieve the evaluated node name from the jsonModel, compare it to the names you passed as evaluator properties, and return true or false.

Don't hesitate to ask specific questions if you have some Smiley Wink

mrinal3199
Champ in-the-making
Champ in-the-making
Yeah Tony…that is what i am trying to do..But do they have function to retrieve name property. I have seen JsonObject returned only aspect or types but no name of contents. Can you please share it in details with me.

my java class is like this as below:

package org.alfresco.web.evaluator.doclib.action;

import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.ui.common.component.evaluator.BaseEvaluator;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.ParameterizedItemAbstractBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;

import com.skandia.wcm.models.SkandiaContentModel;

public class NameEqualsEvaluator extends BaseEvaluator  {
   ParameterizedItemAbstractBase base ;
   public static final String NAME = "has-name";
   public static final String PARAM_NAME = "name";
   private static final Log logger = LogFactory.getLog(NameEqualsEvaluator.class);
      private NodeService nodeService;
   
      public NodeService getNodeService() {
         return nodeService;
      }

      public void setNodeService(NodeService nodeService) {
         this.nodeService = nodeService;
      }
   
     public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
      {
        boolean result = false;
   
       if (this.nodeService.exists(actionedUponNodeRef) == true)
        {
         if (this.hasName(actionedUponNodeRef, (QName)ruleCondition.getParameterValue("name")) == true)
          {
            result = true;
          }
        }
   
        return result;
     }
   private boolean hasName(NodeRef actionedUponNodeRef, QName parameterValue) {
      boolean value = false;
      String name = nodeService.getProperty(actionedUponNodeRef, SkandiaContentModel.QTYPE_NAME_KEY).toString();
      System.out.println("name is:-"+name);
      if(name.equals(parameterValue)){
         System.out.println("parameterValue is:-"+parameterValue);
         value = true;
      }
      
      return value;
   }
   
     protected void addParameterDefinitions(List<ParameterDefinition> paramList)
      {
        paramList.add(new ParameterDefinitionImpl("name", DataTypeDefinition.QNAME, true, getParamDisplayLabel("name"), true, "name"));
      }
    
     protected String getParamDisplayLabel(String paramName)
       {
          return I18NUtil.getMessage(this.PARAM_NAME + "." + paramName + "." + "display-label");
      }
    

   @Override
   public boolean evaluate() {
      logger.info("evaluator initiated");
      return true;
   }
}


and bean defined in custom slingshot is as in the attachment.


It is giving error as bean property with name as "name" not defined

Thanks in advance

tonyrivet
Champ in-the-making
Champ in-the-making
I'm pretty sure the jsonObject contains all the node information, including its properties.
You should be able to retreive the node name like this (getProperty() is a method inherited from the BaseEvaluator) :


@Override
public boolean evaluate(JSONObject jsonObject)
{
   String nodeName = getProperty(jsonObject, "cm:name");
   …
}

mrinal3199
Champ in-the-making
Champ in-the-making
Yeah you are right. I have gone through this Base Evaluator and HasAsectEvaluator files. Actually this function is there in these files in the package "org.alfresco.web.evaluator.BaseEvaluatr", but the package which i am importing is "org.alfresco.web.ui.common.component.evaluator.BaseEvaluator" and it does nt contain such functions and also HasAspectEvaluator class is different in both the packages. Can you link me to this jar having package "org.alfresco.web.evaluator.BaseEvaluatr".

Thanks Again

tonyrivet
Champ in-the-making
Champ in-the-making
The org.alfresco.web.evaluator.BaseEvaluator is contained in the Share jar (alfresco-share-4.2.0.jar for my version)…

mrinal3199
Champ in-the-making
Champ in-the-making
Thanks a lot Tony. I really apreciate your time. I got this jar and will try and tell you.

Thanks again

mrinal3199
Champ in-the-making
Champ in-the-making
Hi Tony,

   I have defined my evaluator class and bean. Everything is fine. There are no errors. But i am not getting the desired output. I am attaching here my action defined in share-config-custom.xml, bean and java class. Please look into this. Where i am wrong…?

Thanks again