cancel
Showing results for 
Search instead for 
Did you mean: 

java : affecter une catégory à un document [résolu]

fmarin
Champ in-the-making
Champ in-the-making
j'ai compris que, pour affecter une categorie existante à un document, il fallait
1) connaître le noderef de la categorie (qui est, pour l'exemple, aaaa, existante dans l'arbre des category)
2) connaître le noderef du document

pour connaître le noderef de la category, j'utilise un search lucene :

stRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,"SpacesStore");      
SearchParameters searchParameters = new SearchParameters();
searchParameters.addStore(stRef);
searchParameters.setQuery("PATH:\"/cm:generalclassifiable" +
         "/cm:" + ISO9075.encode("aaaa")+
         "/member\""
         );
searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE);


de fait, je n'obtiens rien …, et ne suis plus du tout assuré de la méthode …

pour lier la category au docupent :

categories = new ArrayList<NodeRef>(1);
categories.add(categoryNodeRef);
getServiceRegistry().getNodeService().setProperty(nodeRefDoc, ContentModel.PROP_CATEGORIES, categories);


je n'ai pas encore pu passer sur ce snippet, mais le code doit être juste

qu'en pensez vous ?

merci pour votre conseil /votre aide

Frédéric Marin
3 REPLIES 3

jayjayecl
Confirmed Champ
Confirmed Champ
Bonjour,
Spontanément je pencherais pour l'utilisation du CategoryService pour parser et récupérer une référence de catégorie.
Avez-vous regardé de ce côté ?

fmarin
Champ in-the-making
Champ in-the-making
bonsoir

humm … je n'ai pas encore tous les bons réflexes … je regarde

merci

Fredéric Marin

fmarin
Champ in-the-making
Champ in-the-making
bonsoir

effectivement, cela va beaucoup mieux

pour l'exemple :

   //obtain the root category
   Collection coll = getServiceRegistry().getCategoryService().getRootCategories(
      new StoreRef(StoreRef.PROTOCOL_WORKSPACE,"SpacesStore"),
      ContentModel.ASPECT_GEN_CLASSIFIABLE);


Il s'agit ensuite d'explorer la collection et de trouver l'objet recherché (c'est un ChildAssociationRef) alors …

it = coll.iterator();
while(it.hasNext())
{  
   ChildAssociationRef temp=(ChildAssociationRef) it.next();
   System.out.println("     QName="+temp.getQName());
   System.out.println("     value=" + temp.getQName().getPrefixString()+"___");
   System.out.println("     nodeRef=" + temp.getChildRef());
}


merci pour votre rappel à l'ordre des "Services"

Frédéric Marin