cancel
Showing results for 
Search instead for 
Did you mean: 

SOLVED: Modified category name is still old in Lucene path!

dwilson
Champ in-the-making
Champ in-the-making
I've changed the name of a category in Alfresco, and now my PHP web application that displays content lists by category is broken.  The name property of the category node is correct, but when I turn around and query Lucene by category it still has the old name.  I'm using queries like this:

     http://wiki.alfresco.com/wiki/Search#Category_Queries

For example, I changed the category from "Old Category Name" to "Updated Category Name".   The path indicates the old name as evidenced by the data in the Node Browser:
Primary Path:   /{http://www.alfresco.org/model/content/1.0}categoryRoot/{http://www.alfresco.org/model/content/1.0}ge... Category Name
But under the properties table a few lines down the screen:
{http://www.alfresco.org/model/content/1.0}name = Updated Category Name
The first thing I did was a FULL reindexing on the server, and it did not update the paths to the new name as I had hoped it would.  One other tidbit, these categories have the "Incomplete" aspect on so there must be a mandatory property missing- perhaps this prevents it from being reindexed properly? 

Is there something I am missing?  Perhaps I should be using different information to generate my Lucene Category queries?  I need to get it fixed ASAP.

Thanks in advance!
Dave
7 REPLIES 7

dwilson
Champ in-the-making
Champ in-the-making
bump :!:

dwilson
Champ in-the-making
Champ in-the-making
bump 2.

rogier_oudshoor
Champ in-the-making
Champ in-the-making
This is not a Lucene issue, it's an issue in the Alfresco repository. What you have to do, is utilize the (JAVA!) nodeService's  getPath() function on your category to build the correct lucene query. I'm not fully knowledgable on the PHP API, so you may be in trouble if you're not able to access Java.

dwilson
Champ in-the-making
Champ in-the-making
Update for archival purposes: We have since converted our PHP application to access Alfresco via webscripts.  (more complete API, recommendation on forums and from Alf devs)

Now to overcome the issue above we are using getting children from nodes using the Category API instead of lucene queries.

Cheers,
Dave

andy
Champ on-the-rise
Champ on-the-rise
Hi

If you wish the PATH and the name to be in sync for catageories you need to change cm:name AND the local name on the child association to the category. The association name is used in the PATH and not cm:name. The FileFolder Service keeps these two in sync. There is no such contract for any other service (e.g. the category service) . Changing the name of a category is independant of its path.

Andy

anya
Champ in-the-making
Champ in-the-making
Hi

If you wish the PATH and the name to be in sync for catageories you need to change cm:name AND the local name on the child association to the category. The association name is used in the PATH and not cm:name. The FileFolder Service keeps these two in sync. There is no such contract for any other service (e.g. the category service) . Changing the name of a category is independant of its path.

Andy


Hi, Andy!

How I can change child association? Could you please give an example?

dbachem
Champ in-the-making
Champ in-the-making
Hi Anya!

Some weeks ago i had the same problem. I made some tests and sourcecode research and found out the following behaviour:

  • there are 2 different meanings of the name - the cm:name property and the child-assoc QName (don't misswatch with assoc type qname!)

  • only the Alfresco Web-Client manages to rename both in synch (renaming files/folders)

  • note, the nobody else in the system helps you keeping the 2 names in synch (in my opinion this is a conceptual problem)
:idea: So i implemented a behaviour which helps:


public class NameQNameSynchBehaviour implements OnUpdatePropertiesPolicy, OnMoveNodePolicy {
 
  /** a class specific logger */
  private Logger logger = Logger.getLogger(NameQNameSynchBehaviour.class);
 
  PocService pocService;
 
 
  public void onUpdateProperties(
              NodeRef nodeRef,
              Map<QName, Serializable> before,
              Map<QName, Serializable> after) {
   
    logger.debug("onUpdateProperties: " + nodeRef);
   
    // name changes
    String  nameBefore  = before.get(ContentModel.PROP_NAME);
    String  nameAfter   =  after.get(ContentModel.PROP_NAME);
    boolean nameChanged = (nameBefore != null && nameBefore != nameAfter)
    if (nameChanged==true) {
      logger.debug("Poc name has changed – nameBefore: $nameBefore,  nameAfter: $nameAfter");
      ChildAssociationRef newChildRef = pocService.changePrimaryParent2ChildAssocQName(nodeRef, nameAfter);
      logger.debug("Poc qname has been synched: ${newChildRef.getQName()}");
    }
   
  }
 
 
  /*
   * (non-Javadoc)
   *
   * @see
   * org.alfresco.repo.node.NodeServicePolicies.OnDeleteNodePolicy#onDeleteNode
   * (org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
   */
  public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef) {
    logger.debug("onMoveNode - OLD: " + oldChildAssocRef + " - NEW: " + newChildAssocRef);
    // track qname changes (we can't do any more here)
    QName qnameBefore = oldChildAssocRef.getQName();
    QName qnameAfter  = newChildAssocRef.getQName();
    boolean qnameChanged = (!qnameBefore.equals(qnameAfter));
    if (qnameChanged==true) {
      logger.debug("Poc qname has changed – qnameBefore: $qnameBefore,  qnameAfter: $qnameAfter");
      // FIXME we can't backward-synch the cm:name, cause the qname may be a cutted version of a longer name
    }
  }
 
}


public class PocService {

  NodeService nodeService;

  public QName createNewChildAssocQName(ChildAssociationRef childAssoc, String newNameWithExt) {
    String localName = QName.createValidLocalName(newNameWithExt); // name will be croped to a maximum of 100 chars
    return QName.createQName(childAssoc.getQName().getNamespaceURI(), localName);
  }
 
  public ChildAssociationRef changePrimaryParent2ChildAssocQName(NodeRef node, String newNameWithExt) {
    return changeChildAssocQName(nodeService.getPrimaryParent(node), newNameWithExt);
  }
 
  public ChildAssociationRef changeChildAssocQName(ChildAssociationRef childAssoc, String newNameWithExt) {
    QName newAssocQName = createNewChildAssocQName(childAssoc, newNameWithExt);
    if (newAssocQName.equals(childAssoc.getQName())) {
      return childAssoc; // qname has not changed!
    }
    return nodeService.moveNode(
          childAssoc.getChildRef(), childAssoc.getParentRef(),
            childAssoc.getTypeQName(), newAssocQName);
  }
 
}

But there are some problems around this:
  • current user needs the permission "createChildren" to change the child assoc

  • the QName will be cutted to a maximum length of 100 chars, so the names may even differ!
:cry: problems like this make alfresco development a very hard job! :cry: