Alfresco Upload Content with Custom Aspect


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static Reference createNewContent(ContentServiceSoapBindingStub contentService, String name, String contentString)
  2. throws Exception
  3. {
  4. // Update name
  5. name = System.currentTimeMillis() + "_" + name;
  6.  
  7. // Create a parent reference, this contains information about the association we are createing to the new content and the
  8. // parent of the new content (the space retrived from the search)
  9. ParentReference parentReference = new ParentReference(STORE, null, "/app:company_home/cm:sample_folder", ASSOC_CONTAINS,
  10. "{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + name);
  11.  
  12. // Define the content format for the content we are adding
  13. ContentFormat contentFormat = new ContentFormat("text/plain", "UTF-8");
  14.  
  15.  
  16.  
  17. NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, name)};
  18. CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
  19. CML cml = new CML();
  20. cml.setCreate(new CMLCreate[]{create});
  21.  
  22. // [email protected], Sat Jan 9, 2010 {{
  23. NamedValue custName = Utils.createNamedValue("{custom.model}CustomerName", "wearetherock");
  24. NamedValue contName = Utils.createNamedValue("{custom.model}CustomerContactName", "Wk Ok");
  25. NamedValue contPhone = Utils.createNamedValue("{custom.model}CustomerContactPhone", "000xxxxxx");
  26. NamedValue projID = Utils.createNamedValue("{custom.model}CustomerProjectID", "3943");
  27. NamedValue newCust = Utils.createNamedValue("{custom.model}NewCustomer", "true");
  28. NamedValue[] ascProperties = new NamedValue[]{custName,contName,contPhone,projID,newCust};
  29. CMLAddAspect addaspect = new CMLAddAspect();
  30. addaspect.setAspect("{custom.model}CustomerDetails");
  31. addaspect.setProperty(ascProperties);
  32. addaspect.setWhere_id("1");
  33. cml.setAddAspect(new CMLAddAspect[]{addaspect});
  34.  
  35. // }}
  36.  
  37.  
  38. UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
  39.  
  40. Reference newContentNode = result[0].getDestination();
  41. Content content = contentService.write(newContentNode, Constants.PROP_CONTENT, contentString.getBytes(), contentFormat);
  42.  
  43. // Get a reference to the newly created content
  44. System.out.println("wk >> " + content.getNode());
  45.  
  46. return content.getNode();
  47. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.