cancel
Showing results for 
Search instead for 
Did you mean: 

Restricting a menu item to a specific Space

vasuki
Champ in-the-making
Champ in-the-making
Hi, I have added a new menu item (using web-client-config-custom.xml) that will trigger a Javascript. Now, I would like to limit the Spaces that this menu item shows up…
I assume I need to use the "evaluator" and "condition" attributes (config tag) to do this, but I cannot find any documentation on how these are used. Should I be using the "string-compare" evaluator, and if so, how do I specify that I want this action restricted to a single space (and all documents and subspaces within it)?
31 REPLIES 31

elenaor
Champ in-the-making
Champ in-the-making
Thanks vasuki, thanks rivarola.

It works perfectly now!

Elena

rivarola
Champ on-the-rise
Champ on-the-rise
Hello all,

I tried your path comparison this morning and ran through an unexpected problem : the node.getPath method does not return the concatenation of the traversed node names, but the concatenation of the navigated child association names.
The result is the same… excepted when one of the nodes have been created with a copy/paste or cut/paste operation. In this case the new node name is the same as the source node (if pasted in another space) but the association name is cm:move (and not cm:[THE NAME OF THE NODE]).
Conclusion : if one of the node of the hierarchy is the result of a paste or move operation the comparison based on path may not have the expected result.  :twisted:

vasuki
Champ in-the-making
Champ in-the-making
Hello rivarola,

I'm not sure what you're talking about here.  But I tried to do a node.getPath() on a document called "TestingEvaluator" in a space called "MySpace" and this is what I got:

/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1....

Then I copied the same document to a different space called "MyCopySpace". When I did a node.getPath() on the copy, this is what I get:

/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1....

So, as you can see, there is no difference in the path other than the name of the space, which was expected.
Therefore, my method of using node.getPath().contains(…) works on all nodes, whether copied or not…

rivarola
Champ on-the-rise
Champ on-the-rise
Hello vasuki,

It seems OK for the copy but try the Move action of the "Run action" wizard on a space.
It changes the name of the child association holding the moved space. For instance I moved the "Workflow" space with original path :
   /{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1.... 

to the Chantier2 space, and its path became :
   /{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1.... 

The space name is still "Workflow" but its path does not contain "Workflow".  :roll:

paullewon
Champ in-the-making
Champ in-the-making
Hi,

I'm attempting to implement this in almost exactly the same way, but I'm getting an error to the catalina.out log file when I try to start Alfresco. Excerpted here:

14:47:41,798 ERROR [web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webClientConfigService' defined in class path resource [alfresco/web-client-application-context.xml]: Invocation of init method failed; nested exception is org.alfresco.config.ConfigException: Unable to construct action 'approve' evaluator classname: org.alfresco.web.action.evaluator.SciRCFolderIsReview
Caused by:
org.alfresco.config.ConfigException: Unable to construct action 'approve' evaluator classname: org.alfresco.web.action.evaluator.SciRCFolderIsReview
   at org.alfresco.web.config.ActionsElementReader.parseActionDefinition(ActionsElementReader.java:222)
   at org.alfresco.web.config.ActionsElementReader.parse(ActionsElementReader.java:92)
   at org.alfresco.config.xml.XMLConfigService.parseConfigElement(XMLConfigService.java:258)
   at org.alfresco.config.xml.XMLConfigService.parse(XMLConfigService.java:114)
   at org.alfresco.config.BaseConfigService.parse(BaseConfigService.java:221)
   at org.alfresco.config.xml.XMLConfigService.init(XMLConfigService.java:78)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
.
.
.
14:47:41,920 ERROR [[Catalina].[localhost].[/alfresco]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webClientConfigService' defined in class path resource [alfresco/web-client-application-context.xml]: Invocation of init method failed; nested exception is org.alfresco.config.ConfigException: Unable to construct action 'approve' evaluator classname: org.alfresco.web.action.evaluator.SciRCFolderIsReview
Caused by:
org.alfresco.config.ConfigException: Unable to construct action 'approve' evaluator classname: org.alfresco.web.action.evaluator.SciRCFolderIsReview
   at org.alfresco.web.config.ActionsElementReader.parseActionDefinition(ActionsElementReader.java:222)
   at org.alfresco.web.config.ActionsElementReader.parse(ActionsElementReader.java:92)
   at org.alfresco.config.xml.XMLConfigService.parseConfigElement(XMLConfigService.java:258)
   at org.alfresco.config.xml.XMLConfigService.parse(XMLConfigService.java:114)
   at org.alfresco.config.BaseConfigService.parse(BaseConfigService.java:221)
   at org.alfresco.config.xml.XMLConfigService.init(XMLConfigService.java:78)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
.
.
.
14:47:42,005 ERROR [[Catalina].[localhost].[/alfresco]] Exception sending context initialized event to listener instance of class org.alfresco.web.app.ContextListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webClientConfigService' defined in class path resource [alfresco/web-client-application-context.xml]: Invocation of init method failed; nested exception is org.alfresco.config.ConfigException: Unable to construct action 'approve' evaluator classname: org.alfresco.web.action.evaluator.SciRCFolderIsReview
Caused by:
org.alfresco.config.ConfigException: Unable to construct action 'approve' evaluator classname: org.alfresco.web.action.evaluator.SciRCFolderIsReview
   at org.alfresco.web.config.ActionsElementReader.parseActionDefinition(ActionsElementReader.java:222)
   at org.alfresco.web.config.ActionsElementReader.parse(ActionsElementReader.java:92)
   at org.alfresco.config.xml.XMLConfigService.parseConfigElement(XMLConfigService.java:258)
   at org.alfresco.config.xml.XMLConfigService.parse(XMLConfigService.java:114)
   at org.alfresco.config.BaseConfigService.parse(BaseConfigService.java:221)
   at org.alfresco.config.xml.XMLConfigService.init(XMLConfigService.java:78)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
.
.
.
Nov 26, 2007 2:47:42 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart

Here's my .jar:

package org.alfresco.web.action.evaluator;

import org.alfresco.web.action.ActionEvaluator;
import org.alfresco.web.bean.repository.Node;

public class SciRCFolderIsReview implements ActionEvaluator
{
    public boolean evaluate(Node node)
    {
        return (node.getPath().contains("Ready for Review"));
    }
}

What am I missing?

Thanks,

Paul

vasuki
Champ in-the-making
Champ in-the-making
Hi Paul,

Your code looks ok, so the only thing I can assume is that Alfresco is unable to find your custom class in the classpath. Where are you placing your .jar file?

Vasuki.

paullewon
Champ in-the-making
Champ in-the-making
Hi Vasuki,

It's in /opt/alfresco/tomcat/webapps/alfresco/WEB-INF/lib

Thanks,

Paul

vasuki
Champ in-the-making
Champ in-the-making
Well, that should be the right place! Can you post the relevant section of your web-client-application-context.xml file?

Also, note that I made my changes to a different config file - web-client-config-custom.xml - maybe you are updating the wrong file? I am not an expert on the many config files in Alfresco, but I'm just throwing this out there as a possibility.

paullewon
Champ in-the-making
Champ in-the-making
Hmm…I reference my evaluator in my web-client-config-custom.xml in /opt/alfresco/tomcat/shared/classes/alfresco/extension:

<action id="approve">
            <evaluator>org.alfresco.web.action.evaluator.SciRCFolderIsReview</evaluator>
            <label>Approve</label>
            <onclick>javascript:myhandler</onclick>
            <!– script attribute for specifying a javascript file to execute - by Path or NodeRef –>
            <script>/Company Home/Data Dictionary/Scripts/SciRC_Status_to_Publishable.js</script>
            <!– params specify the <f:param> tags to be generated as children of the action component –>
            <!– accessable by an ActionEvent handler or passed directly as href/script URL arguments –>
            <params>
               <param name="id">#{actionContext.id}</param>
            </params>
         </action>
        
Am I missing a necessary customization to /opt/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/web-client-application-context.xml ?


Paul

vasuki
Champ in-the-making
Champ in-the-making
Paul -
Everything looks fine to my eye. Based on your error message, the only possibilities I see are that the evaluator class is not being found in the classpath, or the XML has some errors in it (parsing problem). But after reading your replies, I don't see how either is possible. Unless your JAR file is somehow not correctly packaged - I noticed you used an alfresco package name for your class - maybe this is a problem? If it is an XML parsing issue, you may want to remove one line at a time from the action configuration, and see if the error goes away…