cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a Category to a noderef

mr_apples
Champ in-the-making
Champ in-the-making
Hi all,
I'm facing problems trying to add a category to a noderef.

My webscript downloads a file from an external source, then loads properties for an aspect, then applies the aspect to file, then stores the file at specified path.
Now the boss asked for a category. the following doesn't work:

//nds = nodeService;
ArrayList<NodeRef> categories = new ArrayList<NodeRef>();            
categories.add(categoryNode);
HashMap<QName, Serializable> categoriesProps = new HashMap<QName, Serializable>();
categoriesProps.put(ContentModel.PROP_CATEGORIES, categories);
if(nds.hasAspect(file_info.getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE) == false) {
    nds.addAspect(file_info.getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, categoriesProps);
} else {
    nds.setProperty(file_info.getNodeRef(), QName.createQName("{http://www.alfresco.org/model/content/1.0}subcategories"), "{http://www.alfresco.org/model/content/1.0}Tags");
}
setProperty doesn't work in any of my attempts:
nds.setProperty(file_info.getNodeRef(), QName.createQName("http://www.alfresco.org/model/content/1.0", "subcategories"), QName.createQName("http://www.alfresco.org/model/content/1.0", "Tags");
or any other combination of the above.

Any idea?
2 REPLIES 2

mr_apples
Champ in-the-making
Champ in-the-making
I did find an answer by myself. It's not the final one, but it covers the problem for a while:


// reference to a category node. The reference is by its id.
NodeRef categoryNode = new NodeRef("workspace://SpacesStore/170ca17e-5625-4285-bd2f-898efae39128");

if (nds.hasAspect(file_info.getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE) == false) {
    // List of categories. At first step only categoryNode will be added
    ArrayList<NodeRef> categories = new ArrayList<NodeRef>();
    categories.add(categoryNode);

    HashMap<QName, Serializable> categoriesProps = new HashMap<QName, Serializable>();
    categoriesProps.put(ContentModel.PROP_CATEGORIES, categories);

    // Adds the generalclassifiable aspect to the file, so it can be classifiable via categories
    nds.addAspect(file_info.getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, categoriesProps);
} else {
    // The file is already classifiable, so we simply add the category
    nds.setProperty(file_info.getNodeRef(), ContentModel.PROP_CATEGORIES, categoryNode);
}
The problem is that categoryNode is referred by an id that can be changed at any time. It will probably change in production environment, so now the question is: how can I get a category node without using a search?

toze
Champ in-the-making
Champ in-the-making
You got it solved?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.