cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to set a custom properties

nicolasb
Champ in-the-making
Champ in-the-making
Hello,

Using the webservice API, I have to set values in a custom object.

Predicate predicate = new Predicate(new Reference[] { reference },
                null, null);
        Node[] tabNode = WebServiceFactory.getRepositoryService().get(predicate);
        Node node = tabNode[0];
        NamedValue nv = new NamedValue("{http://zzz.zzzz.zz.zz/zzzz/model/1.0}publication_execution" , false, "my value", null);
        node.setProperties(0,nv);       
    }

This code don't work but I have no error message.

Thanks in advance for your help !

Regards,

Nicolas
2 REPLIES 2

nimind
Champ in-the-making
Champ in-the-making
here you have a fucntio that set properties that you want


public void setMetadata(Strin name, Hashtable metadata){
      Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
//      Start the session
      
      try{
         AuthenticationUtils.startSession("admin", "admin");
   
         RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();        
   
         // Create a query object, looking for all items with alfresco in the name of text
         Query query = new Query(Constants.QUERY_LANG_LUCENE, "@cm\\:title:\""+name+"\"") ;
       
         // Execute the query
         QueryResult queryResult = repositoryService.query(store, query, false);
       
         // Display the results
         ResultSet resultSet = queryResult.getResultSet();
         ResultSetRow[] rows = resultSet.getRows();
         if (rows == null)
         {
            System.out.println("No query results found.");
                     }
         else
         {
            //Get the id of the first result
            String firstResultId = rows[0].getNode().getId();
      
            //get reference
            Reference reference = new Reference(store, firstResultId, null);
            Predicate predicate = new Predicate(new Reference[]{reference}, store, null);       
            Node[] nodes = WebServiceFactory.getRepositoryService().get(predicate);
      
            //set new properties
            NamedValue[] properties = new NamedValue[metadata.size()];
            Enumeration keys = metadata.keys();
            Enumeration values = metadata.elements();
      
            for (int i = 0; i < metadata.size(); i++){
                properties[i] = new NamedValue();
                properties[i].setName("{http://www.alfresco.org/model/content/1.0}'+keys.nextElement());
                properties[i].setValue(values.nextElement().toString());
                properties[i].setIsMultiValue(false);
                //System.out.println(properties[i].getName());
            }
      
            nodes[0].setProperties(properties);
      
            CMLUpdate update = new CMLUpdate(properties,predicate,firstResultId);
            CML cml = new CML();
            cml.setUpdate(new CMLUpdate[]{update});
      
            WebServiceFactory.getRepositoryService().update(cml);
         }
      }catch(DocumentManagementException e){
         System.out.println(e.getMessage());
      }catch(Exception e){
         System.out.println(e.getMessage());
      }
      finally
        {
            // End the session
            AuthenticationUtils.endSession();
        }
      
   }

nicolasb
Champ in-the-making
Champ in-the-making
Thanks for your help. I forgot this :

        CMLUpdate update = new CMLUpdate(tnv,predicate,uuid);
        CML cml = new CML();
        cml.setUpdate(new CMLUpdate[]{update}); 
        WebServiceFactory.getRepositoryService().update(cml);

Now it works fine.