cancel
Showing results for 
Search instead for 
Did you mean: 

problem with createDocument()

miro156
Champ in-the-making
Champ in-the-making
Hi, I have a problem with creating document with CMIS WS Binding in Alfresco Labs 3.0b.
I tried some methods in CMIS API in Java and it works; for example objectService.getProperties(), repositoryService.get
So I decided to deploy my own model dynamcally to the Alfresco. Model worked with Web client so everything seems to work in Alfresco.
Next I wanted to create some new document of type as my deployed model, but there were a lot of runtime errors like: "Namespace is not recognized…"
I wanted to make things simpler so I removed my own model from Alfrresco and try to make new document of some standart type, but I have error like this:

"The type is not supported by this service: {http://www.alfresco.org/model/cmis/0.5}Document"

There is code:


// properties
CmisPropertiesType createCmisPropertiesType = of.createCmisPropertiesType();
List<CmisProperty> properties = createCmisPropertiesType.getProperty();

CmisPropertyString property = of.createCmisPropertyString();
property.setName("ObjectTypeId");
property.setValue("[color=#FFBF00]Document[/color]");
      
CmisPropertyString property2 = of.createCmisPropertyString();
property2.setName("Name");
property2.setValue("Some name");
      
properties.add(property);
properties.add(property2);

// content
CmisContentStreamType cmisContentStreamType = of.createCmisContentStreamType();
DataHandler handler = new DataHandler(new InpuStreamDataSource(new FileInputStream(new File("c:/a.txt")),"a.txt"));
cmisContentStreamType.setStream(handler);
cmisContentStreamType.setFilename("a.txt");

// create document - does not work 😞
objectService.createDocument(repoId,"[color=#FFBF00]Document[/color]",createCmisPropertiesType, rootFolderId, cmisContentStreamType, EnumVersioningState.MAJOR);


I also try to change value from "Document" to some others like "Content" but there was an exacaption like this: Malformed type id 'Content'

Can anybode help me what am I making bad?
Thank you in advance.
8 REPLIES 8

bharathganesh
Champ in-the-making
Champ in-the-making
I also facing the same issue. Any help would be appreciated.

monitloth
Champ on-the-rise
Champ on-the-rise
Hi, I have the same with custom contents, did you find solution?

Thanks.

gressho
Champ in-the-making
Champ in-the-making
Hi,

I have the same issue and from my results with createFolder where I had to use the objectID "F\cm_folder" (it works!)
I tried "D\cm_content". This leads to a ConstraintViolationException (type is not allowed). So I had a look in the
sources and found that the methods to check the validity of object ids is totally different between createFolder and
createDocument. I guess it's not working at all  :cry:

onewnan
Champ in-the-making
Champ in-the-making
FYI I got this to work:

                        ObjectFactory of = new ObjectFactory();
      CmisContentStreamType cs = of.createCmisContentStreamType();
      File file = new File (".");
      String currdir = "";
      try {
         currdir = file.getCanonicalPath();
      } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
      }
      String contentPath = currdir + "/data/" + "alfresco-logo.gif";
      cs.setFilename(contentPath);
      file = new File(contentPath);
      cs.setLength(BigInteger.valueOf(file.length()));
      FileDataSource fds = new FileDataSource(file);
      DataHandler dh = new DataHandler(fds);
      cs.setStream(dh);
      cs.setMimeType("image/gif");
      CmisPropertiesType type = of.createCmisPropertiesType();
      List<CmisProperty> props = type.getProperty();
      CmisPropertyString name = of.createCmisPropertyString();
      name.setName("Name");
      name.setValue("demo");
      props.add(name);
      String outcome = null;
      try {
            outcome = osp.createDocument(
            repositoryId,
            "document",
            type,
            folderId,
            cs,
            EnumVersioningState.MAJOR
            );
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

srinid
Champ in-the-making
Champ in-the-making
The following code worked for me. You need to obviously replace the repository and folder ids with your ones.

ObjectWebService.ObjectServicePortClient objProxy = new StatementsOnlinePOC.ObjectWebService.ObjectServicePortClient();
                    
            ObjectWebService.cmisProperty[] cmisPropertis = { new ObjectWebService.cmisPropertyString { name = "Name", value = new string[] { "test.pdf" } } };
            ObjectWebService.cmisPropertiesType cmisPropertiesType = new ObjectWebService.cmisPropertiesType { Items = cmisPropertis };
           

            ObjectWebService.cmisContentStreamType cmisContentStreamType = new StatementsOnlinePOC.ObjectWebService.cmisContentStreamType();
            using (FileStream fsSource = new FileStream("test.pdf", FileMode.Open, FileAccess.Read))
            {

                // Read the source file into a byte array.
                byte[] bytes = new byte[fsSource.Length];
                int numBytesToRead = (int)fsSource.Length;
                int numBytesRead = 0;
                while (numBytesToRead > 0)
                {
                    // Read may return anything from 0 to numBytesToRead.
                    int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);

                    // Break when the end of the file is reached.
                    if (n == 0)
                        break;

                    numBytesRead += n;
                    numBytesToRead -= n;
                }

                cmisContentStreamType.length = bytes.Length.ToString();
                cmisContentStreamType.stream = bytes;
                cmisContentStreamType.mimeType = "application/pdf";

                string s = objProxy.createDocument("23d59f4c-166a-44bb-a3cb-f849d3858eec", "document", cmisPropertiesType, "workspace://SpacesStore/362a0fb0-6336-417f-b0f5-1aabe3bed663", cmisContentStreamType, ObjectWebService.enumVersioningState.major);

nikes
Champ on-the-rise
Champ on-the-rise
Dear friends,

I have developed Axis2 client code using Apache ADB generated stub classes.

I am able fetch information from Alfresco.

Now I want to createFolder and createDocument in alfresco, but I dont know how to set properties for the same.

Following is my incomplete code, kindly guide me to set properties.


package cmis;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.jaxws.description.xml.handler.ObjectFactory;
import org.oasis_open.docs.ns.cmis.core._200908.CmisAccessControlListType;
import org.oasis_open.docs.ns.cmis.core._200908.CmisPropertiesType;
import org.oasis_open.docs.ns.cmis.messaging._200908.CreateFolder;
import org.oasis_open.docs.ns.cmis.messaging._200908.CreateFolderResponse;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub;

public class ObjectClient {

   public static void main(String[] args) throws Exception
   {
      ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("D:\\Softwares\\axis2-1.5.1-bin\\axis2-1.5.1\\repository","D:\\Softwares\\axis2-1.5.1-bin\\axis2-1.5.1\\repository\\modules\\client.axis2.xml");
      
      ObjectServiceStub stub = new ObjectServiceStub(ctx, "http://localhost:8080/alfresco/cmis/ObjectService");
      
      CreateFolder cf = new CreateFolder();
      cf.setRepositoryId("46f8b242-9f61-423b-b824-c6118f470f01");
      cf.setFolderId("workspace://SpacesStore/0fceb8de-fe45-439a-9ac4-30b32c7671e0");
         /*  How to set properties?  */
   
   }
}

When i tried creating CmisPropertiesType object from CreateFolder (cf) object it doesn't have any method to create CmisPropertiesType object.

Thanks for any help.

openpj
Elite Collaborator
Elite Collaborator
You have to use the ObjectFactory class exactly imported from this package:
org.oasis_open.docs.ns.cmis.core._200908.ObjectFactory;

The other one is not the right class, so probably you have imported the following class in your code:
org.oasis_open.docs.ns.cmis.messaging._200908.ObjectFactory
But this is not the same class!

Check your imports  :wink:

Then you can add the value for your new property using add method in this way:

//this is the list for all your properties
CmisPropertiesType newNodeProperties = new CmisPropertiesType();

//build your custom name property
CmisPropertyString nameProperty = objectFactory.createCmisPropertyString();
nameProperty.setPropertyDefinitionId("cmis:name");
nameProperty.getValue().add("This is the name value of your new node");

//add the new property value to the properties list
newNodeProperties.getProperty().add(nameProperty);
Hope this helps.

silvia1983
Champ in-the-making
Champ in-the-making
Hi!

Sorry, but how can i get that class? because I've created the client with axis1 from the wsdl files, but I can't get that class in generated classes.

Where is the libraries that contain that classes?

Thanks