AnsweredAssumed Answered

How can I use specific properties

Question asked by z3r0 on Sep 20, 2009
Latest reply on Sep 21, 2009 by z3r0
Hi,
I have a class which upload a file to Alfresco. Moreover, I have uploaded an own ContentModel to the folder "Company Home -> Data Dictionary -> Models". What do I need to change in my class, that the stored content use my specific model? In my code, I raised the standard features such as name and description. How can I address the properties of my content model?
Here is my code.

public class CopyOfContentReadAndWrite
{
    /** The type of the association we are creating to the new content */
    private static final String ASSOC_CONTAINS = "{http://www.alfresco.org/model/content/1.0}contains";
   
    public ArrayList readAndWrite() {
       
       ArrayList answer = new ArrayList();
       
       // Start the session
        try {
         AuthenticationUtils.startSession("admin", "admin");
      } catch (AuthenticationFault e) {
         answer.add("Authentication failed!");
      }
       
        try
        {           
            // Create a reference to the parent where we want to create content
            Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            ParentReference companyHomeParent = new ParentReference(storeRef, null, "/app:company_home", ASSOC_CONTAINS, "{" + Constants.NAMESPACE_CONTENT_MODEL + "}test.jpg");
           
            // Create the content
            NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, "test.jpg")};
            CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_CONTENT, properties);
            CML cml = new CML();
            cml.setCreate(new CMLCreate[]{create});
               // Construct CML statement to add titled aspect
               NamedValue[] titledProps = new NamedValue[2];
               titledProps[0] = Utils.createNamedValue(Constants.PROP_TITLE, "einBild");
               titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, "ein bild wie geil");
               CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_TITLED, titledProps, null, "1");
               cml.setAddAspect(new CMLAddAspect[] {addAspect});
            UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);    
           
            // Get the created node and create the format
            Reference newContentNode = result[0].getDestination();             
            ContentFormat format = new ContentFormat("image/jpeg", "UTF-8"); 
           
            // Open the file and convert to byte array
            InputStream viewStream = newContentNode.getClass().getClassLoader().getResourceAsStream("org/alfresco/webservice/test/resources/test.jpg");
            byte[] bytes = ContentUtils.convertToByteArray(viewStream);
           
            // Write the content
            WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, format);
       
        }
        catch (Exception e){
           
        }
        // End the session
        AuthenticationUtils.endSession();
           
        return answer;
    } 
}

Outcomes