cancel
Showing results for 
Search instead for 
Did you mean: 

How to write and read aspect property of type d:content ?

pucfg1
Champ in-the-making
Champ in-the-making
Hi all,

I have created the following custom aspect:

….
<namespace uri="http://www.alfresco.org/model/myNameSpace/1.0" prefix="myNs"/>
….
<aspects>
   <aspect name="myNs:myAspect">
      <title>MyAspect</title>
      <properties>
         <property name="myNs:content">
            <title>MyContent</title>
            <type>d:content</type>
         </property>
         <property name="myNs:user">
            <title>User</title>
            <type>d:text</type>
            <multiple>true</multiple>
         </property>       
      </properties>
   </aspect>
</aspects>
The purpose of myNs:content is to store binary data(application/octet-stream).
The purpose of myNs:user is to store a list of users who modified myNs:content(using a java applet).

At first I`m adding an aspect myNs:myAspect with myNs:user property to node and then I`m using the following
code snippet to write and read myNs:content property:

Write:
String propertyName = "{http://www.alfresco.org/model/myNameSpace/1.0}content";

Content propertyContent = WebServiceFactory.getContentService().write(nodeReference, propertyName,
      ContentUtils.convertToByteArray(new FileInputStream(propertyFilePath)), new ContentFormat("application/octet-stream", "UTF-8"));
            
Read:
Content[] contents = WebServiceFactory.getContentService().read(new Predicate(new Reference[]{nodeReference}, store, null), propertyName);
   for (Content content : contents) {
      System.out.println("Content.length:" + content.getLength());
      ContentUtils.copyContentToFile(content, new File("./propertyContent"));
}
In the result I`m getting valid content size(content.getLength()) but the result of calling ContentUtils.copyContentToFile is invalid - it is
always main document content (property {http://www.alfresco.org/model/content/1.0}content).
      
What is the proper way to write and read myNs:content property?

Thanks in advance !
3 REPLIES 3

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

I've taken a quick look at this and there is a bug in content web service repository code.

The URL being returned is pointing to the content in the cm:content property, not your custom property.

It would be good to raise this as an issue in JIRA (issues.alfresco.com) so we can schedule a fix.

Cheers,
Roy

pucfg1
Champ in-the-making
Champ in-the-making
Thanks for the reply.
I have raised an issue in JIRA for this bug.

Lukasz

rwetherall
Confirmed Champ
Confirmed Champ
Thanks