cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a new category?

purplesky
Champ in-the-making
Champ in-the-making
I need to add a new category to the category tree.
5 REPLIES 5

jcustovic
Champ in-the-making
Champ in-the-making

String categoryName = "yourCategoryName";
ParentReference categoryParentRef = new ParentReference();
categoryParentRef.setStore(WORKSPACE_STORE);
categoryParentRef.setPath("/cm:categoryRoot/cm:generalclassifiable");
categoryParentRef.setChildName(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, categoryName));
categoryParentRef.setAssociationType(Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "subcategories"));

NamedValue[] categoryProperties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, categoryName) };
CMLCreate createCategory = new CMLCreate("addCategory", categoryParentRef, null, Constants.ASSOC_CONTAINS, null, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "category"), categoryProperties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{ createCategory });           
UpdateResult[] updateResult = getRepositoryService().update(cml);
Reference categoryReference = updateResult[0].getDestination();

hamptonowen
Champ in-the-making
Champ in-the-making
thanks for sharing..i was looking for the answer of this question…

rleones
Champ in-the-making
Champ in-the-making
And how can I create a new Classification?

scylin
Champ in-the-making
Champ in-the-making
And how can I create a new Classification?

I'd like to know this as well, I finally got the categories to work and now I stumbled upon this new problem Smiley Frustrated

Help appreciated.

openpj
Elite Collaborator
Elite Collaborator
If you need to add a new classification at runtime without restart Alfresco, you have to deploy a new aspect in the Alfresco content model storing the new model in the Data Dictionary -> Models. After you have stored the new model as a XML file you have to activate the model changing the property Model Active.

http://wiki.alfresco.com/wiki/Classification_And_Categories#Adding_your_own_classification

You can perform this operation via Web Services considering the Alfresco Content Model as a standard XML content.

Then you can add a new category as you have seen in the previous post.

Hope this helps.