AnsweredAssumed Answered

Classification in javascript

Question asked by ale_carraro on Aug 20, 2008
Latest reply on Aug 26, 2008 by jbarmash
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…

Outcomes