cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading custom object type to repository with CMIS

loshmeey
Champ in-the-making
Champ in-the-making
Hello everyone,

i have a little problem,  which is a bit basic i guess, but i just cant find a solution!

I am trying to upload a file into alfresco repository trough my java application. For this purposes i am using apache.chemistry libraries 0.8 version. I have also extended my content model with the following lines:

<blockcode>


     
        <type name="my:request">
         <title>Request</title>
         <parent>cm:content</parent>
         <properties>
            <property name="my:firstField">
               <type>d:text</type>
            </property>
            <property name="my:id">
               <type>d:text</type>   
            </property>
            <property name="my:soruceId">
               <type>d:text</type>
            </property>
         </properties>
      </type>   
    


</blockcode>

and Java code that i am using to upload the file is:



ContentStream cs = session.getObjectFactory().createContentStream("testUploadFile", x.length(), "text/xml", bais);
      
      Map<String,Object> folderProps = new HashMap<String, Object>();
      folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,my:request");
      folderProps.put(PropertyIds.NAME, "testApload");
      folderProps.put("my:firstField", "testAplodFile");
      folderProps.put("my:id", "testAplodFile");
      folderProps.put("my:sourceId", "testAplodFile");
      
      
      org.apache.chemistry.opencmis.client.api.Document doc2 = parrent.createDocument(folderProps, cs, VersioningState.MAJOR);
      



And the exception that i am getting is:


org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Bad Request
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:423)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:554)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getTypeDefinitionInternal(AbstractAtomPubService.java:821)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.RepositoryServiceImpl.getTypeDefinition(RepositoryServiceImpl.java:88)
   at org.apache.chemistry.opencmis.client.bindings.impl.RepositoryServiceImpl.getTypeDefinition(RepositoryServiceImpl.java:137)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.getTypeDefinition(SessionImpl.java:518)
   at org.apache.chemistry.opencmis.client.runtime.repository.ObjectFactoryImpl.convertProperties(ObjectFactoryImpl.java:294)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createDocument(SessionImpl.java:726)
   at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImpl.java:88)
   at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImpl.java:443)
   at Connector.upload(Connector.java:186)
   at TestMain.main(TestMain.java:68)



And i am puzzled a little bit. I have tried different combinations of object type id, and both ways to connect to alfresco (/alfresco/service/cmis and /alfresco/cmisatom) and they both fail.

Has anyone got any idea how to solve this problem?

Thanks in advance
Milos D.
3 REPLIES 3

raoul
Champ in-the-making
Champ in-the-making
Hello,

Maybe it's the little error in "my:soruceId"?

loshmeey
Champ in-the-making
Champ in-the-making
That was embarrassing.

Thank you for pointing that out tough!

But unfortunately it is still not working! I went trough alfresco logs a bit more and found out that this exception comes up when i call the method:

<java>

ERROR [extensions.webscripts.AbstractRuntime] [http-8084-8] Exception from executeScript - redirecting to status template error: 02260003 Invalid typeId cmis:document,D:my:request
org.springframework.extensions.webscripts.WebScriptException: 02260003 Invalid typeId cmis:document,D:my:request
        at org.alfresco.repo.cmis.rest.CMISScript.queryType(CMISScript.java:563)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
        at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
        at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
        at org.mozilla.javascript.gen.c3._c0(file:/E:/alatke/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/cmis/type.get.js:5)
        at org.mozilla.javascript.gen.c3.call(file:/E:/alatke/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/cmis/type.get.js)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
        at org.mozilla.javascript.gen.c3.call(file:/E:/alatke/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/cmis/type.get.js)
        at org.mozilla.javascript.gen.c3.exec(file:/E:/alatke/alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/cmis/type.get.js)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:492)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:198)
        at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:212)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:174)
        at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
        at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1288)
        at org.alfresco.repo.cmis.rest.CMISWebScript.executeScript(CMISWebScript.java:46)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
        at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:410)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:479)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:517)
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
        at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.alfresco.cmis.CMISInvalidArgumentException: Invalid typeId cmis:document,D:my:request
        at org.alfresco.cmis.mapping.CMISServicesImpl.getTypeDefinition(CMISServicesImpl.java:953)
        at org.alfresco.repo.cmis.rest.CMISScript.queryType(CMISScript.java:559)
        … 46 more


</java>

and i checked if the content model is registered within the alfresco, and it is! Thank you in advance.!

loshmeey
Champ in-the-making
Champ in-the-making
Solved it. All i should`ve done is this:

<java>
folderProps.put(PropertyIds.OBJECT_TYPE_ID, "D:my:request");
</java>

Thanks everyone!