cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Cascading Constraints

thestorm
Champ in-the-making
Champ in-the-making
Hey people,

i found the Cascading Constraints from Jean Barmash (http://blogs.alfresco.com/wp/jbarmash/2008/08/08/dynamic-data-driven-drop-downs-for-list-properties/)and need them for my current project. What i wanna do is to generate the List of values out of spaces that are in my customer folder. My problem is now to set the Lucene query for the constraint.


<constraint name=”my:customConstraint”
type=”org.alfresco.sample.constraints.LuceneSearchBasedListConstraint” >
<parameter name=”query”>
<value> TYPE:”{http://www.alfresco.org/model/content/1.0}folder” AND@\http://www.alfresco.org/model/content/1.0\}name:'Customer"
</value>
</parameter>
</constraint>

I get following error in the log file:


22:35:01,259 User:System ERROR [web.context.ContextLoader] Context initialization failed
net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:477)
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:355)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:275)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy23.query(Unknown Source)
        at org.alfresco.sample.constraints.LuceneSearchBasedListConstraint.getSearchResult(LuceneSearchBasedListConstraint.java:69)
        at org.alfresco.sample.constraints.SearchBasedListConstraint.getAllowedValues(SearchBasedListConstraint.java:62)

I think it is related to my Lucene query not working. Can some1 please help me.
27 REPLIES 27

jbarmash
Champ in-the-making
Champ in-the-making
Sorry, I forgot the hierarchy - LuceneSearchBasedListConstraint is the right one to use.  Once again not sure what's going on - I suggest you try if it works with a simpler query just to see if it works at all.  Use one without any substitutions first to get confidence that it works, then move on to a simple query with a very simple substitution. 

why is he failing to create the instance? do i need to provide any default value maybe for the dynamic list of custom:AKunde (generated out of a Space) but normally that should be handled by custom component generator….

I'd definitely worry about default values - make sure that you have some kind of default value on your property in the content model definition.  The component generator is UI, it doesn't set underlying properties on the nodes.

mbailen
Champ in-the-making
Champ in-the-making
Hi Jean,

I'm using your drop downs and having similar problems.  I had it working in 3.0, but it won't boot in 3.2.  If I comment out just the constraint line in the aspect definition and leave the rest of the code as is, it does not bomb.  I'm using a simple category query:
 <constraint name="me:group_constraint" type="org.alfresco.sample.constraints.LuceneSearchBasedListConstraint" >
       <parameter name="query">
         <value> PATH:"/cm:generalclassifiable/cm:Group/*" </value>
       </parameter>
/constraint>
The log says:
15:53:54,295 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:477)
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:355)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:275)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy44.query(Unknown Source)
        at org.alfresco.sample.constraints.LuceneSearchBasedListConstraint.getSearchResult(LuceneSearchBasedListConstraint.java:71)
Am I missing something simple?  If you have any ideas, please let me know.  I found the feature very useful.  Thanks

jbarmash
Champ in-the-making
Champ in-the-making
Not sure - seems like some infrastructure has changed in 3.2.  "The Storm" seems to be having the same issues. 

If it works in 3.0 but not in 3.2, then it might be some kind of regression bug - I'd encourage you to create a JIRA issue.  All the code is trying to do is get SearchService via ServiceRegistry.  I suppose another thing to try is to inject the SearchService directly into the constraint definition - maybe that will set the security context correctly.

I don't have a 3.2 environment to test this in (not doing an Alfresco project right now), but to diagnose this further I'd try to debug deep down into Eclipse until something jumps out at me. 

Yet another thing to try potentially, since it seems like CMIS code is not part of the call stack, is to perhaps try to do a search using CMIS querying (maybe that will allow to bypass the faulty code).  

Sorry can't be more helpful, seems like something is amiss here.

thestorm
Champ in-the-making
Champ in-the-making
its not working in 3.2 sadly

but still struggling with my Depency Constraint :X

//made another step:

with this i get no error, but an empty list for my dependency list:


          <constraint name="custom:Auftragsliste"
       type="org.alfresco.sample.constraints.LuceneSearchBasedListConstraint" >

   <parameter name="query">
   <value> PATH:"/app:company_home/cm:ComTeam_x20020_AG/cm:${custom:AKunde}/cm:_x0030_2_x0020_Auftragsordner/*" AND TYPE:"{http://www.alfresco.org/model/content/1.0}folder" </value>
   </parameter>
     </constraint>

and


                 <property name="custom:AKunde">
                 <title>Kunde</title>
                 <type>d:text</type>
                 <mandatory>true</mandatory>
       <default>BMW</default>
                 <constraints>
                  <constraint ref="custom:Kundenliste" />
                 </constraints>
                 </property>

(default value is one of the spaces in the Kundenliste Space.

but why is the Dependency List empty? Smiley Sad

PS: jbmarsh i can give u remote access to my 3.0 testbox if it helps u


/edit2:

maybe its cause my lucene query is broken :X :X testing with correct one now

/edit3:

ITS WORKING w000000000000000000000000000000t

i'll pass a tutorial soon what I did to make it work.


another intresting thing would be, how can i make the Search work for Dependency List, cause now it only shows the dependency List for my default value, no matter if i change it in the list or not

mbailen
Champ in-the-making
Champ in-the-making
Just a quick update on my attempts to get this working with 3.2.  I tried the search using an inline constraint and it failed.  Also I tried creating a class for doing a CMIS search which used the same method for grabbing a security context and it failed.

At this point, I'm not familiar enough with the faces client to get much further…  If anybody can point me to an example of a better way to make the query, I will give it a shot.

thestorm
Champ in-the-making
Champ in-the-making
Hi guys,

long time not been around but now I got a new problem.

I tryed to use 2 Variables in one query:

          <constraint name="custom:Themenliste"
       type="org.alfresco.sample.constraints.LuceneSearchBasedListConstraint" >

        <parameter name="query">
        <value> PATH:"/app:company_home/cm:ComTeam_x0020_AG/cm:Kunden/cm:${custom:AKunde}/cm:_x0030_2_x0020_Auftragsordner/cm:${custom:AAuftrag}//*" AND TYPE:"{http://www.alfresco.org/model/content/1.0}folder" </value>
        </parameter>
     </constraint>
the error i get:


javax.faces.FacesException: org.alfresco.repo.search.SearcherException: Failed to parse query: PATH:"/app:company_home/cm:ComTeam_x0020_AG/cm:Kunden/cm:ComTeam/cm:_x0030_2_x0020_Auftragsordner/cm:${custom:AAuftrag}//*" AND TYPE:"{http://www.alfresco.org/model/content/1.0}folder"
caused by:
org.apache.jasper.JasperException: org.alfresco.repo.search.SearcherException: Failed to parse query: PATH:"/app:company_home/cm:ComTeam_x0020_AG/cm:Kunden/cm:ComTeam/cm:_x0030_2_x0020_Auftragsordner/cm:${custom:AAuftrag}//*" AND TYPE:"{http://www.alfresco.org/model/content/1.0}folder"
caused by:
org.alfresco.repo.search.SearcherException: Failed to parse query: PATH:"/app:company_home/cm:ComTeam_x0020_AG/cm:Kunden/cm:ComTeam/cm:_x0030_2_x0020_Auftragsordner/cm:${custom:AAuftrag}//*" AND TYPE:"{http://www.alfresco.org/model/content/1.0}folder"
caused by:
org.alfresco.repo.search.impl.lucene.ParseException: Failed to parse XPath…
Unexpected '$'

seems like he parses the Query after replacing the first Variable, but when i look to the Java Code


    /**
     * Pulls out tokens corresponding to property names
     *
     * @param query
     * @return
     */
    private String replaceQueryParametersWithValues(String query, Map<String, String> props)
    {
        String finalQuery = query;
        for (String key : props.keySet())
        {
            String token = "\\$\\{" + key + "\\}";
            finalQuery = query.replaceAll(token, props.get(key));
        }
        return finalQuery;
    }

it should replace all tokens, any1 see a mistake? I used default vars that are existing, so that cant be the problem.

thestorm
Champ in-the-making
Champ in-the-making
small update, tryed it with 3 values and still only the first one gets replaced:


javax.faces.FacesException: org.alfresco.repo.search.SearcherException: Failed to parse query: PATH:"/app:company_home/cm:ComTeam_x0020_AG/cm:Kunden/cm:ComTeam/cm:_x0030_2_x0020_Auftragsordner/cm:${custom:AAuftrag}/cm:${custom:AStruktur}//*" AND TYPE:"{http://www.alfresco.org/model/content/1.0}folder"

the function to do this is:


    private List<String> getPropertyNames(String query, String tokenRegexpExpression)
    {
        Pattern patternMatcher = Pattern.compile(tokenRegexpExpression);
        Matcher matcher = patternMatcher.matcher(query);
        List<String> arr = new ArrayList<String>();
        while (matcher.find())
        {
            String propToken = matcher.group();
            propToken = propToken.substring(2, propToken.length() - 1);
            arr.add(propToken);
        }
        return arr;
    }

from my understanding this function adds all ${} regex pattern things to the array and returns it, but seems like it only does it for the first, some1 know why?


////////////////////////////////////////////////////////////////////////
SOLUTION:
////////////////////////////////////////////////////////////////////////


    /**
     * Pulls out tokens corresponding to property names
     *
     * @param query
     * @return
     */
    private String replaceQueryParametersWithValues(String query, Map<String, String> props)
    {
        String finalQuery = query;
        for (String key : props.keySet())
        {
            String token = "\\$\\{" + key + "\\}";
            finalQuery = query.replaceAll(token, props.get(key));
        }
        return finalQuery;
    }

the line:


finalQuery = query.replaceAll(token, props.get(key));

needs to replaceAll in finalQuery not in query

so it must be:


finalQuery = finalQuery.replaceAll(token, props.get(key));

dynamolalit
Champ on-the-rise
Champ on-the-rise
Hi All,

I am using Alferesco3.2r with Tomcat 6.0.

I am also following same blog post for categories & getting the same error.I have posted @

http://forums.alfresco.com/en/viewtopic.php?f=4&t=25855&p=84025#p84025

I tried with other approach, i am getting some other error there which i posted @

http://forums.alfresco.com/en/viewtopic.php?f=4&t=25837&p=84043#p84043

Is there any JIRA for this till now or any workaround as i am struggling with it for some time. Smiley Surprisedops:

Is there any other thing exists to be used for categories instead of this as default alfresco category selector is not user friendly.

thestorm
Champ in-the-making
Champ in-the-making
hi,

its not working with versions past 3.0 since they changed the security model …

sadly, this function is a must have in my opinion so I have to stick with 3.0 :-S

dynamolalit
Champ on-the-rise
Champ on-the-rise
Hi Storm,

Thanks for your reply.

I have to use 3.2 only here but bad part  :?:  is that there is no JIRA issue I could find for this so that i can present it to others.

Also Alfresco engineers are not replying on it which is again heartbreaking so that i can try to persuade on this. :roll:


Can you tell me, if you know, any other way to achieve this.

I tried with AjaxCategorySelector but i am getting Base is null error .

Here is my edit-content-properties.jsp

  
<%
EditNodeCategoriesDialog dialog2 = (EditNodeCategoriesDialog) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "EditNodeCategoriesDialog"););
%>
….

<f:verbatim>
<table cellpadding="2" cellspacing="2" border="0" width="100%">
<tr>
<td colspan="2" class="paddingRow"></td></tr>
<tr>
<td></f:verbatim><h:outputText value="#{msg.categories}" /><f:verbatim>:</td>
<td width="98%">
</f:verbatim>
<r:multiValueSelector id="multi-category-selector"
value="#{dialog2.getCategories}"
lastItemAdded="#{dialog2.getAddedCategory}"
selectItemMsg="#{msg.select_category}"
selectedItemsMsg="#{msg.selected_categories}"
noSelectedItemsMsg="#{msg.no_selected_categories}"
styleClass="multiValueSelector">
<f:subview id="categorySelector">
<r:ajaxCategorySelector id="catSelector" styleClass="selector"
value="#{dialog2.getAddedCategory}"
label="#{msg.select_category_prompt}" />
</f:subview>
</r:multiValueSelector>
<f:verbatim>
</td>
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
</table>
</f:verbatim>

Any idea is welcome!