AnsweredAssumed Answered

.Net code for adding category is not working

Question asked by sharad_panchal on Oct 28, 2011
Hi,

I have written following C# code for adding category to the document. The code get executed without any error.
But nothing happens. No category is added to the node. Can anybody tell me what is missing in the code ?


private void addCategory(Alfresco.RepositoryWebService.Reference rwsRef, String category)
       {
         //rwsRef :- is the valid referance node of the document on with the category to be added
         //category :- Name of the exisiting category. Tring with "Regions"
           Alfresco.ClassificationWebService.ClassificationService cws = WebServiceFactory.getClassificationService();
           ResultSetRow categoryRow = getCategory(category); //This call returns the category.

           if (categoryRow != null)
           {
               Alfresco.ClassificationWebService.AppliedCategory newCategory = new Alfresco.ClassificationWebService.AppliedCategory();
               newCategory.classification = categoryRow.node.type;
               newCategory.categories = new Alfresco.ClassificationWebService.Reference[1];
               newCategory.categories[0] = new Alfresco.ClassificationWebService.Reference();
               newCategory.categories[0].uuid = categoryRow.node.id;
               newCategory.categories[0].path = categoryRow.columns[0].value;
               Alfresco.ClassificationWebService.Store clStore = new Alfresco.ClassificationWebService.Store();
               clStore.address = this.spacesStore.address; //SpaceStore
               clStore.scheme = (Alfresco.ClassificationWebService.StoreEnum)this.spacesStore.scheme; //Alfresco.RepositoryWebService.StoreEnum.workspace
               newCategory.categories[0].store = clStore;

               Alfresco.ClassificationWebService.AppliedCategory[] newCategories = new Alfresco.ClassificationWebService.AppliedCategory[1];
               newCategories[0] = newCategory;

               Alfresco.ClassificationWebService.Predicate p = getClassificationPredicate(rwsRef);

               cws.setCategories(p, newCategories);

           }
           

       }
     
      private ResultSetRow getCategory(String category)
       {
           String categoryLucenceString = "PATH:\"/cm:generalclassifiable/cm:"+category+"\"";
           Query categoryQuery = new Query();
           categoryQuery.language = Alfresco.RepositoryWebService.QueryLanguageEnum.lucene;
           categoryQuery.statement = categoryLucenceString;

           QueryResult result = reposervice.query(this.spacesStore,categoryQuery, false);
           ResultSetRow[] rows = result.resultSet.rows;
           if (rows != null && rows.Length == 1)
           {
               return rows[0];
           }
           return null;
       }
     
      private Alfresco.ClassificationWebService.Predicate getClassificationPredicate(Alfresco.RepositoryWebService.Reference rwsRef)
       {
           Alfresco.ClassificationWebService.Predicate p = new Alfresco.ClassificationWebService.Predicate();

           Alfresco.ClassificationWebService.Reference content = new Alfresco.ClassificationWebService.Reference();
           content.path = rwsRef.path;
           content.store = new Alfresco.ClassificationWebService.Store();
           content.store.address = rwsRef.store.address;
           content.store.scheme = (Alfresco.ClassificationWebService.StoreEnum)rwsRef.store.scheme;
           content.uuid = rwsRef.uuid;

           p.Items = new Alfresco.ClassificationWebService.Reference[] { content };

           return p;
       }


Thanking in advance.

Regards
Sharad

Outcomes