cancel
Showing results for 
Search instead for 
Did you mean: 

role integrity checking

epritchard
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to add a role to the target of a child-association thus:

   
   <aspect name="contacts:HasLocalisedContact">
         <title>Has Localised Contact</title>
         <associations>
            <child-association name="contacts:localisedContact">
               <source>
                  <mandatory>false</mandatory>
                  <many>false</many>
               </source>
               <target>
                  <class>cms:LocalisedNodeRef</class>
                  <role>cms:isPropertyOf</role>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </child-association>
         </associations>
      </aspect>

(my higher level API is (ab)using some associations as special properties, I need to know where this behavior is used generically, hence the need for a role).

However, when attempting to commit a transaction which creates nodes with this role I get two problems:

1/ a java.util.regex.PatternSyntaxException: Illegal repetition
from org.alfresco.service.namespace.RegexQNamePattern.isMatch(RegexQNamePattern.java:121).
org.alfresco.repo.node.integrity.AssocTargetRoleIntegrityEvent.checkAssocQNameRegex(AssocTargetRoleIntegrityEvent.java:93)

This is a result of a QName in {uri}localName form being passed as a pattern: the {} is interpreted as a regex repetition expression:


AssocTargetRoleIntegrityEvent.checkAssocQNameRegex:91

            RegexQNamePattern rolePattern = new RegexQNamePattern(assocRoleQName.toString());
I've fixed this locally as:

            RegexQNamePattern rolePattern = new RegexQNamePattern(assocRoleQName.getNamespaceURI(),assocRoleQName.getLocalName());

2/ With the above fix applied, it seems that the AssocTargetRoleIntegrityEvent is trying to match the name of the association with the role name, and I get:

The association name does not match the allowed role names:
   Association: Association[ class=ClassDef[name={http://researchresearch.com/contacts}HasLocalisedContact], name={http://researchresearch.com/contacts}localisedContact, target class={http://researchresearch.com/cms}LocalisedNodeRef, source role=null, target role={http://researchresearch.com/cms}isPropertyOf]
   Allowed roles: RegexQNamePattern[ uri=http://researchresearch.com/cms, localname=http://researchresearch.com/cms ]
   Name assigned: {http://researchresearch.com/cms}isPropertyOf
(NB there is another bug here: RegexQNamePattern.toString() prints out the URI of the pattern twice, rather than the URI and the localName! The above should read:

The association name does not match the allowed role names:
   Association: Association[ class=ClassDef[name={http://researchresearch.com/contacts}HasLocalisedContact], name={http://researchresearch.com/contacts}localisedContact, target class={http://researchresearch.com/cms}LocalisedNodeRef, source role=null, target role={http://researchresearch.com/cms}isPropertyOf]
   Allowed roles: RegexQNamePattern[ uri=http://researchresearch.com/cms, localname=isPropertyOf ]
   Name assigned: {http://researchresearch.com/cms}isPropertyOf
)

Why is this integrity check attempting to match the association name with the role name?

3/ I also notice that there is no integrity checking at all for roles in an association source, and thus association source roles don't have any problems!


Is this just very immature code? Should I avoid using child-association roles currently?

Ellis.
5 REPLIES 5

jbaton
Champ in-the-making
Champ in-the-making
Hi,

thanks for this post and your analysis.

I had the same weird problem, that cost me (a lot of) time as I thought the error was in my code.

Removing the role from the target solved it.

I opened a JIRA  http://issues.alfresco.com/browse/AR-2157


Jerome

derek
Star Contributor
Star Contributor
Thanks for posting this.
The association name must match the role name.  Since we don't persist the name of the source, there is no such constraint.  In this respect, we are incomplete.  This feature is not used much as the code is not new at all.  I'll fix it for 2.1.3 and 2.2.0.

sacco
Champ in-the-making
Champ in-the-making
Thanks for posting this.
The association name must match the role name.

Is there some reason for this?

derek
Star Contributor
Star Contributor
Thanks for posting this.
The association name must match the role name.
Is there some reason for this?
No (good) reason.  It was just a bug that hadn't been hit before: JIRA AR-2157
It'll be in the HEAD code if you're feeling lucky.

sacco
Champ in-the-making
Champ in-the-making
Thanks for posting this.
The association name must match the role name.
Is there some reason for this?
No (good) reason. 
It was just a bug that hadn't been hit before: JIRA AR-2157

Does that mean that it's no longer necessary for the association to match the role name,
or just that the regexp escaping bug is fixed?

It'll be in the HEAD code if you're feeling lucky.

:?  I already am on a HEAD (problems with the official build).
On the other hand, as you suggest, once you've been lucky enough to
find one that works fairly well, you need a significant incentive to hop onto
the next lillypad…