cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS Type 'cmis:document,P:cm:titled' is unknown!

lukas
Champ in-the-making
Champ in-the-making
Hi

I'm trying to add some custom files and folders with custom metadata to alfresco.
That didn't worked, so I'm trying to execute the default code from:
http://code.google.com/a/apache-extras.org/p/alfresco-opencmis-extension/

I always got the follwing Error:
Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException:
Type 'cmis:document,P:cm:titled' is unknown!


Thanks for your help!

package Main;

import java.util.HashMap;
import java.util.Map;


import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;


public class Test {

   /**
    * @param args
    */
   public static void main(String[] args) {
      Map<String, String> parameter = new HashMap<String, String>();

      // Set the user credentials
      parameter.put(SessionParameter.USER, "admin");
      parameter.put(SessionParameter.PASSWORD, "admin");

      // Specify the connection settings
      parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/cmisatom");
      parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

      // Set the alfresco object factory
      parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

      // Create a session
      SessionFactory factory = SessionFactoryImpl.newInstance();
      Session session = factory.getRepositories(parameter).get(0).createSession();
      
      
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(PropertyIds.NAME, "doc1");
      properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
      properties.put("cm:description", "My document");

      Document doc = session.getRootFolder().createDocument(properties, null, null);
      
   }

}


used libraries:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
   <classpathentry kind="src" path="src"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
   <classpathentry kind="lib" path="lib/activation-1.1.jar"/>
   <classpathentry kind="lib" path="lib/alfresco-opencmis-extension-0.3.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-client-api-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-client-bindings-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-client-impl-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-commons-api-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-commons-impl-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-test-tck-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/chemistry-opencmis-workbench-0.9.0.jar"/>
   <classpathentry kind="lib" path="lib/groovy-all-2.1.3.jar"/>
   <classpathentry kind="lib" path="lib/jaxb-api-2.1.jar"/>
   <classpathentry kind="lib" path="lib/jaxb-impl-2.1.11.jar"/>
   <classpathentry kind="lib" path="lib/jaxws-api-2.1.jar"/>
   <classpathentry kind="lib" path="lib/jaxws-rt-2.1.7.jar"/>
   <classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
   <classpathentry kind="lib" path="lib/mimepull-1.3.jar"/>
   <classpathentry kind="lib" path="lib/resolver-20050927.jar"/>
   <classpathentry kind="lib" path="lib/saaj-api-1.3.jar"/>
   <classpathentry kind="lib" path="lib/saaj-impl-1.3.3.jar"/>
   <classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
   <classpathentry kind="lib" path="lib/slf4j-log4j12-1.7.5.jar"/>
   <classpathentry kind="lib" path="lib/sqljdbc4.jar"/>
   <classpathentry kind="lib" path="lib/stax-api-1.0-2.jar"/>
   <classpathentry kind="lib" path="lib/stax-api-1.0.jar"/>
   <classpathentry kind="lib" path="lib/stax-ex-1.2.jar"/>
   <classpathentry kind="lib" path="lib/stax2-api-3.1.1.jar"/>
   <classpathentry kind="lib" path="lib/streambuffer-0.9.jar"/>
   <classpathentry kind="lib" path="lib/woodstox-core-asl-4.2.0.jar"/>
   <classpathentry kind="lib" path="lib/commons-lang3-3.1.jar"/>
   <classpathentry kind="lib" path="lib/commons-io-2.4.jar"/>
   <classpathentry kind="lib" path="lib/commons-io-2.4-javadoc.jar"/>
   <classpathentry kind="lib" path="lib/commons-io-2.4-sources.jar"/>
   <classpathentry kind="lib" path="lib/commons-io-2.4-tests.jar"/>
   <classpathentry kind="lib" path="lib/commons-io-2.4-test-sources.jar"/>
   <classpathentry kind="output" path="bin"/>
</classpath>
11 REPLIES 11

baaka
Champ in-the-making
Champ in-the-making
Hello Lukas,

Don't you try without "P:cm:titled"?
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");

kaynezhang
World-Class Innovator
World-Class Innovator
There is nothing wrong with your code,it just work fine.
Maybe there is something wrong with your alfresco repository.

lukas
Champ in-the-making
Champ in-the-making
Thanks a lot for your response
I have testet the following:

Map<String, Object> props = new HashMap<String, Object>();
props.put(PropertyIds.NAME, "doc1");
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
props.put("cm:description", "My document");
Folder doc = session.getRootFolder().createFolder(props);

Exception in thread "main" java.lang.IllegalArgumentException: Property 'cm:description' is not valid for this type or one of the secondary types!


I have also testet this code with two different alfresco installations, both with the same error.
Could there be anything wrong with my eclipse project-config?

I also tried to connect with the cmis-workbench to my alfresco installtion.
I added "apache.chemistry.opencmis.objectfactory.class=org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl" to the session settings.

I'm not able to see any title or description information in the workbench.

Allowed Child Object Types Ids   cmis:allowedChildObjectTypeIds   id   []
Object Type Id   cmis:objectTypeId   id   [cmis:folder]
Path   cmis:path   string   [/IMAP-Anlagen]
Name   cmis:name   string   [IMAP-Anlagen]
Creation Date   cmis:creationDate   datetime   [java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+02:00",offset=7200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=?,YEAR=2013,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=15,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=21,MINUTE=0,SECOND=56,MILLISECOND=614,ZONE_OFFSET=?,DST_OFFSET=?]]
Change token   cmis:changeToken   string   []
Last Modified By   cmis:lastModifiedBy   string   [System]
Created by   cmis:createdBy   string   [System]
Object Id   cmis:objectId   id   [workspace://SpacesStore/250cfec1-867c-49ca-bea9-00967f322478]
Base Type Id   cmis:baseTypeId   id   [cmis:folder]
Alfresco Node Ref   alfcmis:nodeRef   id   [workspace://SpacesStore/250cfec1-867c-49ca-bea9-00967f322478]
Parent Id   cmis:parentId   id   [workspace://SpacesStore/a1e29e1c-1250-4085-916d-c5ed5fc7bab4]
Last Modified Date   cmis:lastModificationDate   datetime   [java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+02:00",offset=7200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=?,YEAR=2013,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=15,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=21,MINUTE=1,SECOND=15,MILLISECOND=505,ZONE_OFFSET=?,DST_OFFSET=?]]


I have created a temporary login to my test alfresco installation with no content.

parameter.put(SessionParameter.USER, "***");
parameter.put(SessionParameter.PASSWORD, "***");
parameter.put(SessionParameter.ATOMPUB_URL, "***");  *removed

Could anyone test the script against my Alfresco Installtion?

Thanks for your help

kaynezhang
World-Class Innovator
World-Class Innovator
Since cm:description is a property of aspect cm:titled but not a property of cmis:document,so you cann't get any title or description information from type cmis:document.
If you want to add cm:description or cm:title property to your node. you should add cm:titled aspect to your node ,and your code should be like this:
<strong>
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
</strong>

lukas
Champ in-the-making
Champ in-the-making
Thanks for your reply, but i don't understand that.
How can i add cm:titled to my node? The new-content wizard already contains title and description.
How should this code looks like, if i want to create a folder with description and title?

I also have some custom types, do i need to change there something to access cm:description?
<code>
<type name="em:emailfolder">
                        <title>Email Archive</title>
                        <parent>cm:folder</parent>
                        <properties>
                                <property name="em:mailfolder.mailid">
                                        <type>d:text</type>
                                </property>
                                <property name="em:mailfolder.from">
                                        <type>d:text</type>
                                </property>
                                <property name="em:mailfolder.to">
                                        <type>d:text</type>
                                </property>
                                <property name="em:mailfolder.subject">
                                        <type>d:text</type>
                                </property>
                        </properties>
                </type>
                <type name="em:email">
                        <title>Email</title>
                        <parent>cm:content</parent>
                        <properties>
                                <property name="em:mail.mailid">
                                        <type>d:text</type>
                                </property>
                                <property name="em:mail.subject">
                                        <type>d:text</type>
                                </property>
                        </properties>
                </type>

<\code>
I want to store some mails as pdf

Thanks for your help

Lukas

kaynezhang
World-Class Innovator
World-Class Innovator
You can add cm:titled as a  mandatory-aspects  to your  custom types,Then your object will always have cm:title and cm:description property.

<type name="em:emailfolder">

                        <title>Email Archive</title>

                        <parent>cm:folder</parent>

                        <properties>

                                <property name="em:mailfolder.mailid">

                                        <type>d:text</type>

                                </property>

                                <property name="em:mailfolder.from">

                                        <type>d:text</type>

                                </property>

                                <property name="em:mailfolder.to">

                                        <type>d:text</type>

                                </property>

                                <property name="em:mailfolder.subject">

                                        <type>d:text</type>

                                </property>

                        </properties>
         <mandatory-aspects>
            <aspect>cm:titled</aspect>
         </mandatory-aspects>
                </type>

                <type name="em:email">

                        <title>Email</title>

                        <parent>cm:content</parent>

                        <properties>

                                <property name="em:mail.mailid">

                                        <type>d:text</type>

                                </property>

                                <property name="em:mail.subject">

                                        <type>d:text</type>

                                </property>

                        </properties>
         <mandatory-aspects>
            <aspect>cm:titled</aspect>
         </mandatory-aspects>

                </type>

sindhu
Champ in-the-making
Champ in-the-making
I have made all the above changes to set values for cm:title and cm:description. Eventhough I could not set the values to them and create a document with those values. error "not found".
properties[PropertyIds.ObjectTypeId] = "sampleSmiley Surprisedutlook_doc,P:cm:titled";
                    properties["cm:title"] = title;
IDocument doc = folder.CreateDocument(properties, contentStream, null);

kaynezhang
World-Class Innovator
World-Class Innovator
sampleSmiley Surprisedutlook_doc is your custom type ,you should write it like this:
<strong>
properties.put(PropertyIds.OBJECT_TYPE_ID, "D:sampleSmiley Surprisedutlook_doc,P:cm:titled");
</strong>

Following code is for testing in my environment,it works fine.
You can use it to check whether your development environment is set up correctly

   public void createDocument()

   {
      String servalUrl = "http://localhost:8080/alfresco/cmisatom";
      String userName = "admin";
      String password = "admin";
      Map<String, Object> properties = new HashMap<String, Object>();
      //properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
      properties.put(PropertyIds.OBJECT_TYPE_ID, "D:em:email,P:cm:titled");      
      properties.put(PropertyIds.NAME, "TESTDOCUMENT2");
      properties.put(PropertyIds.CREATED_BY, "admin");
      properties.put("cm:title", "Title");
      properties.put("cm:description", "Desc");
      Session session = getSession(servalUrl, userName, password);

      try {
         AlfrescoFolder folder1 = (AlfrescoFolder) session
               .getObjectByPath("/TESTFOLDER1/TESTFOLDER4");
         File file = new File("C:\\userguide.pdf");
         InputStream fis = new FileInputStream(file);
         VersioningState vs = VersioningState.MAJOR;
         DataInputStream dis = new DataInputStream(fis);
         byte[] bytes = new byte[(int) file.length()];
         dis.readFully(bytes);
         ContentStream contentStream = new ContentStreamImpl(file
               .getAbsolutePath(), null, "application/pdf",
               new ByteArrayInputStream(bytes));
         
         AlfrescoDocument newDocument = (AlfrescoDocument) folder1
               .createDocument(properties, contentStream, vs);

         System.out.println(newDocument.getId());
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

   }
   public static void main(String[] args) {
      CMISTest t = new CMISTest();
      t.createDocument();
   }

daparicio1
Champ in-the-making
Champ in-the-making
Hello,
I had a very similar problem by assigning aspects to a document.
Check your version of Alfresco. I had that problem in version 4.2.e.
To solve instead of using CMIS 1.0 use version 1.1 and works for me. Jeff Potts has a reference to this very interesting. https://gist.github.com/jpotts/7242070
I leave here my code in Java if it's any help.

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.*;

import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;



public class Sesion {
   
    private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
   public  Session session = null;
   public Session getSession() {
      if (session == null) {
         

         // default factory implementation
         SessionFactory factory = SessionFactoryImpl.newInstance();
         Map<String, String> parameter = new HashMap<String, String>();
   
         // user credentials
         parameter.put(SessionParameter.USER, "admin");
         parameter.put(SessionParameter.PASSWORD, "admin");
   
         // connection settings
         parameter.put(SessionParameter.ATOMPUB_URL, serviceUrl); // Uncomment for Atom Pub binding
         parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // Uncomment for Atom Pub binding

         
         
         /*
         parameter.put(SessionParameter.BROWSER_URL, serviceUrl); // Uncomment for Browser binding
         parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value()); // Uncomment for Browser binding
         *
         // Uncomment for Web Services binding
         /*
         parameter.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value()); // Uncomment for Web Services binding
         
         parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, getServiceUrl() + "/ACLService");
         parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, getServiceUrl() + "/DiscoveryService");
         parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, getServiceUrl() + "/MultiFilingService");
         parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, getServiceUrl() + "/NavigationService");
         parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, getServiceUrl() + "/ObjectService");
         parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, getServiceUrl() + "/PolicyService");
         parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, getServiceUrl() + "/RelationshipService");
         parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, getServiceUrl() + "/RepositoryService");
         parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, getServiceUrl() + "/VersioningService");
         */
         
         // Set the alfresco object factory
         // Used when using the CMIS extension for Alfresco for working with aspects
         //parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
         System.out.println("Repositorio");
         List<Repository> repositories = factory.getRepositories(parameter);
         System.out.println("Repositorio listo");
         this.session = repositories.get(0).createSession();
         System.out.println("sesion");
      }
      return this.session;
   }
public static void main(String args[]){
   
   Sesion s=new Sesion();

   Session session = s.getSession();
   System.out.println(session.toString());
   // Grab a reference to the folder where we want to create content
   Folder folder = (Folder) session.getObjectByPath("/");
          
   String timeStamp = new Long(System.currentTimeMillis()).toString();
   String filename = "nombrecillo"+ " (" + timeStamp + ")";   
   // Create a Map of objects with the props we want to set
   Map <String, Object> properties = new HashMap<String, Object>();
   // Following sets the content type and adds the webable and productRelated aspects
   // This works because we are using the OpenCMIS extension for Alfresco
   
    properties.put("cmis:name", filename);
    properties.put("cmisSmiley SurprisedbjectTypeId", "D:vi:doc");
   
   
   //properties.put("cm:description", "My document");


   

   
   String docText = "This is a sample document called  nombrecillo";
      byte[] content = docText.getBytes();
      InputStream stream = new ByteArrayInputStream(content);
      ContentStream contentStream = session.getObjectFactory().
          createContentStream(
              filename, Long.valueOf(content.length), "text/plain", stream
          );
      System.out.println("intenta crear documento");
      Document doc = folder.createDocument(properties, contentStream,
              VersioningState.MAJOR);
      //System.out.println(doc.getProperty("cmis:secondaryObjectTypeIds"));
      

         System.out.println("Content Length: " + doc.getContentStreamLength());

         List<Object> aspects = doc.getProperty("cmis:secondaryObjectTypeIds").getValues();
         if (!aspects.contains("P:viSmiley Tongueroducto")) {
            aspects.add("P:viSmiley Tongueroducto");
            HashMap<String, Object> props = new HashMap<String, Object>();
            props.put("cmis:secondaryObjectTypeIds", aspects);
            doc.updateProperties(props);
            System.out.println("Added aspect");
         } else {
            System.out.println("Doc already had aspect");
         }
   
         HashMap<String, Object> props = new HashMap<String, Object>();
         props.put("vi:marca", "ALTET");
         props.put("vi:unidad", "APILADORAS ELECTRICAS");      
         doc.updateProperties(props);

}
}

If this post was helpful, please click Yes on the Post Rating