cancel
Showing results for 
Search instead for 
Did you mean: 

Classification in javascript

ale_carraro
Champ in-the-making
Champ in-the-making
Hi to everybody!

I've had the following problem: in the javascript API, i did not found any example regarding classifiying a node quth a category.  I know  I need to apply the aspect cm:generalclassifiable, and i do so in this way:

fileNode.addAspect("cm:generalclassifiable");‍
and now I'd like to add a category defined with the web client, say 'XXX'.

I tried with the following code:
for each (cl in classification.getAllCategoryNodes("cm:generalclassifiable")){  if(cl.name == "XXX"){    cl.createAssociation(fileNode,"cm:categories");  }}‍‍‍‍‍
but I get the following error:
Failed to run Actions due to error: Found 2 integrity violations: The association target type is incorrect: Target Node: workspace://SpacesStore/26bff27f-6e9c-11dd-b8be-7d0580fc6f2a Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/content/1.0}category_root], name={http://www.alfresco.org/model/content/1.0}categories, target class={http://www.alfresco.org/model/content/1.0}category, source role=null, target role=null] Required Target Type: {http://www.alfresco.org/model/content/1.0}category Actual Target Type: {http://www.alfresco.org/model/content/1.0}content The association source type is incorrect: Source Node: workspace://SpacesStore/25f1899a-3e13-11dd-81b1-2be2a0263bea Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/content/1.0}category_root], name={http://www.alfresco.org/model/content/1.0}categories, target class={http://www.alfresco.org/model/content/1.0}category, source role=null, target role=null] Required Source Type: {http://www.alfresco.org/model/content/1.0}category_root Actual Source Type: {http://www.alfresco.org/model/content/1.0}category

while the opposite
for each (cl in classification.getAllCategoryNodes("cm:generalclassifiable")){  if(cl.name == "XXX"){    fileNode.createAssociation(cl,"cm:categories");  }}‍‍‍‍‍
gives me
Failed to run Actions due to error: Found 1 integrity violations: The association source type is incorrect: Source Node: workspace://SpacesStore/83b0abc2-6e9c-11dd-b8be-7d0580fc6f2a Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/content/1.0}category_root], name={http://www.alfresco.org/model/content/1.0}categories, target class={http://www.alfresco.org/model/content/1.0}category, source role=null, target role=null] Required Source Type: {http://www.alfresco.org/model/content/1.0}category_root Actual Source Type: {http://www.alfresco.org/model/content/1.0}content

Another question: is there a way to get a category node by name? for example, if I know its name is Bar and its containing category is Foo, by searching for "Foo/Bar"?

thanks for any advice…
1 REPLY 1

jbarmash
Champ in-the-making
Champ in-the-making
Once you add generalclasifiable aspect, you have a property cm:categories defined. In your code sample, you were treating it as an asociation.  So the code should be more along the lines of (from memory):

fileNode.properties['cm:categories'].push(mycategory); //you need to use push for multi-valued variables, as i recall

for searching, lucene query is your best bet.  Another technique that's used, if you bootstrap your categories for your module, you can set the nodeRef ids as part of the bootstrapping to some known value, and then pull them out based on that noderef. 

There are examples of this in the records management module.