cancel
Showing results for 
Search instead for 
Did you mean: 

Mimetype and ContentFormat

cburghardt
Champ in-the-making
Champ in-the-making
Hi,

I'm a little bit confused. I create new content with the webservice so I call ContentService.create() which takes a ContentFormat. This one is constructed with a mimetype and encoding. But how do I add a new mimetype (like rfc/822)? I found the tutorial to create a new content type but how is this linked to the mimetype? I want to create a new content with the mentioned mimetype (which is not available in alfresco yet) and I need to add some properties to the content (which is probably done with the content type). Can somebody please enlighten me how this is supposed to work?

Thanks a bunch!

Carsten
12 REPLIES 12

gavinc
Champ in-the-making
Champ in-the-making
Hi,

To add new mime types you edit the mimetype-map.xml file which you will find in projects/repository/config/alfresco if you are running from the source, in <alfresco-home>/tomcat/webapps/alfresco/WEB-INF/classes if you are running from the Tomcat bundle or <alfresco-home>/jboss/server/default/conf if you are running from the JBoss bundle.

cburghardt
Champ in-the-making
Champ in-the-making
Thanks for your answer. So I add the mimetype to the map and create the content with that. But then I need to assign the content type somehow so that I can set the properties. How is this done?

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

At the moment there is no way to set the content type using the content  service.

If you want to create a content node of a specific content type then use a CML update via the repository service.

Have a look at WebServiceSample4 for an example of this and the Wiki has some documentation relating to the CML capabilities.

Adding the ability to set the content type via the content service is defiantly an enhancement we need to do and I'll add a JIRA task to ensure it gets done.

Thanks,
Roy

rwetherall
Confirmed Champ
Confirmed Champ

cburghardt
Champ in-the-making
Champ in-the-making
This would be great!

In the meantime I tried to create a content node with CML but this fails. I have defined my own model, placed it in the alfresco/extension directory and added it to extension-context.xml (alfresco/extension/rfc822.xml).

<model name="inovox:model" xmlns="http://www.alfresco.org/model/dictionary/1.0">
   <description>RFC 822</description>
   <author>Inovox</author>
   <version>1.0</version>
   <imports>
        <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>
   <namespaces>
      <namespace uri="http://www.inovox.de/model/1.0" prefix="inovox"/>
   </namespaces>
   <types>
      <type name="inovox:email">
         <title>RFC 822 EMail</title>
         <parent>cm:content</parent>
         <properties>
            <property name="inovoxSmiley Very Happyate">
               <type>d:datetime</type>
            </property>
            <property name="inovoxSmiley Frustratedubject">
               <type>d:text</type>
            </property>
            <property name="inovox:From">
               <type>d:text</type>
            </property>
            <property name="inovox:To">
               <type>d:text</type>
            </property>
         </properties>
      </type>
    </types>  
</model>

Now I fire a CMLCreate:
CMLCreate create = new CMLCreate(uid, parentReference, "inovox:email", props);

The result is this:
RepositoryFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>Class {}inovox:email has not been defined in the data dictionary</ns1:message>

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Try …

CMLCreate create = new CMLCreate(uid, parentReference, "{http://www.inovox.de/model/1.0}email", props); 

… instead.

Hope this helps,
Roy

cburghardt
Champ in-the-making
Champ in-the-making
Yes, that helped.
So now I can create a content node of my type and set the properties with the NamedValue[]. But how can I set the content? Probably a stupid question but everything I found referred to the java api and not to the webservice.

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Try using the write method on the content web service.

Have a look in WebServiceSample3.java for an example and here http://www.alfresco.org/mediawiki/index.php/Web_Service_Samples_for_Java for a little detail on what the web service samples include.

Hope this helps,
Roy

cburghardt
Champ in-the-making
Champ in-the-making
Thank you for the super-fast response 🙂
I already tried that but all I got was an exception:
       {http://www.alfresco.org/ws/service/content/1.0}ContentFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>Failed to set content property on stream closure:
   node: workspace://SpacesStore/176db206-5ba4-11da-94ca-ad548187be52
   property: {http://www.alfresco.org/model/content/1.0}content
   writer: ContentAccessor[ contentUrl=store://2005/11/22/17b9af2a-5ba4-11da-94ca-ad548187be52.bin, mimetype=null, size=4, encoding=UTF-8]</ns1:message>

The exception is thrown when I try to write the content:

            UpdateResult[] result = repositoryService.update(cml);
            contentService.write(result[0].getDestination(), bytes);