cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced search authority association

mtielemans
Champ in-the-making
Champ in-the-making
As the title suggests, I have a custom type that includes an authority type association. I want this to be visible in advanced search.

I have read another post stating this is not by default possible, the suggested workaround being one my co-worker and I came up with ourselves as well: adding a new property text field, and writing the picked authority name to it whenever it changes, then make that searchable. I foresee two propblems with this option:

<ul>
<li>The field will only be searchable by a username, or whichever value of the authority we decide to store in the textfield.</li>
<li>If the stored property, e.g. username, changes on the authority itself, the stored value doesn't change.</li>
<li>The user has to type the username or other stored property out, since the picker isn't working in the advanced search form for some reason.</li>
<li>All ways of changing the association property must be modified to also change the stored property, and there's a realistic chance the fields go out of sync, for example after a modification of the association property from outside (e.g. via cmis).</li>
</ul>

All in all, I really don't want to burn my hands on this option, as the entire value of having the field searchable in the first place is degraded to barely any. Is there any other, better way I can do this, for example:

<ul>
<li>Add the possibility to search on authorities to adv search</li>
<li>Connect two property fields so one responds to the other being changed, in whatever way (e.g. add a propertyChangeListener to my textfield property, that listens to changes on my association property and updates itself accordingly)?</li>
<li>Use the authority picker on an association property in adv search?</li>
</ul>
2 REPLIES 2

alhol
Champ in-the-making
Champ in-the-making
Hello!
1) As I understood such types of associations are not indexed by search engine (e.g. lucene) somehow, so you can't search anything by it.
2) To use authority picker on an association property in adv search you have to implement custom field component based on association.ftl which fills search field with authority credentials after selection. I must say, it's tricky enough.
3) You should read about policies in alfresco (http://wiki.alfresco.com/wiki/Policy_Component). The point is, you can implement a piece of Java code, which is executed every time somethings happens with node (in your case - authority). Look at this, for example:
<java>
public class MyAuthorityPolicy implements OnUpdatePropertiesPolicy{

   private PolicyComponent policyComponent;
   private NodeService nodeService;
   private Behaviour onUpdatePropertiesPolicy;

   public void init() {
      this.onUpdatePropertiesPolicy = new JavaBehaviour(this, OnUpdatePropertiesPolicy.QNAME.getLocalName(), NotificationFrequency.EVERY_EVENT);
      policyComponent.bindClassBehaviour(OnUpdatePropertiesPolicy.QNAME, ContentModel.TYPE_AUTHORITY, this.onUpdatePropertiesPolicy);
   }

   void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) {
      List<AssociationRef> myTypeSourceAssocs = nodeService.getSourceAssocs(nodeRef, MY_TYPE_ASSOC_QNAME);
      for(AssociationRef myTypeNodeAssoc : myTypeSourceAssocs){
         NodeRef myTypeNodeRef = myTypeNodeAssoc.getSourceRef();
         nodeService.setProperty(myTypeNodeRef, MY_FIELD_QNAME, after.get(ContentModel.PROP_FIRSTNAME) + " " + after.get(ContentModel.PROP_LASTNAME));
      }
   }
   …
}
</java>

Explanation:
Every time user node properties updated, all nodes authority being attached to by your association are retrieved and thier respective field values are changed to new ones. You can check which fields of authority are actually changed by comparing before and after items.

mtielemans
Champ in-the-making
Champ in-the-making
As this post still hasn't been answered:
1. I have found an association of type cmSmiley Tongueerson searchable in Alfresco 5.0.d.
2. You can make this work simply by using the authority.ftl form control, as long as your datatype is cmSmiley Tongueerson.
3. Unfortunately, the authority.ftl's picker layout is messed up in search forms in 5.0.d.

Also, thanks for your take on it, Alhol, if you're still out there.