cancel
Showing results for 
Search instead for 
Did you mean: 

assign a category via WebService

danisowa
Champ in-the-making
Champ in-the-making
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");
      }
   }
}
10 REPLIES 10

tara_b
Champ in-the-making
Champ in-the-making
Thanks so much for this piece of code - i've been trying to do this for hours and now its working  Smiley Very Happy
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.