AnsweredAssumed Answered

role integrity checking

Question asked by epritchard on Jan 30, 2007
Latest reply on Jun 3, 2008 by sacco
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.

Outcomes