AnsweredAssumed Answered

assign a category via WebService

Question asked by danisowa on Apr 26, 2007
Latest reply on Jul 24, 2009 by tara_b
Hell,
i just solved my problem of uploading a file.
but now i want to assign one or more categories to this file……
how to manage this….. i have really no idea and searched now for more than 4 ours in the web.
Please help me.

Thx a lot
public class AddIssue
{
   
   private final static Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
   
   private String username = "admin";
   private String password = "admin";
   private static final String ASSOC_CONTAINS = "{http://www.alfresco.org/model/content/1.0}contains";

   public static void main(String[] args) {
      new AddIssue();
   }

   public AddIssue() {
     //filename for the document
      String filename = "issue1.jpg";
     
      // path to the file that should be uploaded
      String file = "org/alfresco/webservice/test/resources/test.jpg";
     
      // where to put the file
      String location = "/app:company_home/cm:Dokumente/cm:Daniel";
     
      // what kind of file is it?
      String filetype = "image/jpeg";
           
        try {
           // Authentication
           AuthenticationUtils.startSession(username, password);
         
           // get classification Service
           ClassificationServiceSoapBindingStub classificationService = WebServiceFactory.getClassificationService();
          
       
          
           // Upload
          
           // Upload binary content into the repository
           //Reference reference = Query1.executeSearch();
          
           ParentReference parentReference = new ParentReference(STORE, null, location ,ASSOC_CONTAINS, ASSOC_CONTAINS);
          
         
           // Create the content
           NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, filename)};
         
           CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
                      CML cml = new CML();
           cml.setCreate(new CMLCreate[]{create});
           UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
         
          
           // Get the created node and create the format
           Reference newContentNode = result[0].getDestination();             
           ContentFormat format = new ContentFormat(filetype, "UTF-8"); 
          
           // Open the file and convert to byte array
           InputStream viewStream = newContentNode.getClass().getClassLoader().getResourceAsStream(file);
           byte[] bytes = ContentUtils.convertToByteArray(viewStream);
          
          
           // Write the content
           WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, format);
          
          
          
          
          
             } catch (Exception e) {
         e.printStackTrace();
      } finally {
         AuthenticationUtils.endSession();
         System.out.println("Everything seems to be good");
      }
   }
}

Outcomes