cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to create folder via OpenCMIS

unknown-user
Champ on-the-rise
Champ on-the-rise
I am doing some basic exploration of CMIS and Alfresco.  I am running Alfresco 3.3. Community Edition locally and most things have worked well.
Currently I am trying to use OpenCMIS.  I am able to login, get repository information and navigate without issue; what I can't seem to do is create a folder.  I have tried two different ways, both using the web service bindings:
Folder root = cmisSession.getRootFolder();

Map<String,String> newFolderProps = new HashMap<String, String>();
newFolderProps.put(PropertyIds.CMIS_OBJECT_TYPE_ID, "cmis:folder");
newFolderProps.put(PropertyIds.CMIS_NAME, "Test Folder 1");

//Method 1
Folder newFolder = root.createFolder(newFolderProps, null, null, null, cmisSession.getDefaultContext());

//Method 2
ObjectId rootId = cmisSession.createObjectId(root.getId());
ObjectId newFolderId = cmisSession.createFolder(newFolderProps, rootId, null, null, null);
Folder newFolder = (Folder)cmisSession.getObject(newFolderId);

For both methods, I get the following exception:
Exception in thread "main" org.apache.opencmis.commons.exceptions.CmisInvalidArgumentException: Type Id property required
   at org.apache.opencmis.client.provider.spi.webservices.AbstractWebServicesService.convertException(AbstractWebServicesService.java:83)
   at org.apache.opencmis.client.provider.spi.webservices.ObjectServiceImpl.createFolder(ObjectServiceImpl.java:166)
   at org.apache.opencmis.client.runtime.PersistentFolderImpl.createFolder(PersistentFolderImpl.java:178)
   at OpenCMISTest.runTest(OpenCMISTest.java:138)
   at OpenCMISTest.main(OpenCMISTest.java:120)

I can't seem to find any information on what this means, any examples of using the OpenCMIS "createFolder" method or documentation on it.  Does anyone have any idea as to what I am doing wrong?  I have searched and searched but can't find the answer.

I guess option might be to go via the Atom bindings to see if there is any difference.
9 REPLIES 9

unknown-user
Champ on-the-rise
Champ on-the-rise
After some digging, I am beginning to wonder if this is bug in OpenCMIS.  When I ran the test via the Atom bindings, it said that I needed to provide "cmisObjectTypeId", but I had done that!  So I started tracing the OpenCMIS code and I could see that where it validated my properties (something it does not do with the web service bindings) I could see clearly that it only had "cmis:name", something had removed "cmisObjectTypeId".

I tracked this to PersistentObjectFactoryImpl, line 501 which gets invoked with the "READWRITE" and "ONCREATE" updatability filters ("…" is for code I have skipped)
public PropertiesData convertProperties(Map<String, ?> properties, ObjectType type,  Set<Updatability> updatabilityFilter) {

// get the type
if (type == null) {
  Object typeId = properties.get(PropertyIds.CMIS_OBJECT_TYPE_ID);

  if (!(typeId instanceof String)) {
   throw new IllegalArgumentException("Type or type property must be set!");
  }

  type = session.getTypeDefinition(typeId.toString());
}

// the big loop
for (Map.Entry<String, ?> property : properties.entrySet()) {

  String id = property.getKey();
  Object value = property.getValue();

  // get the property definition
  PropertyDefinition<?> definition = type.getPropertyDefintions().get(id);
..
  // check updatability
  if (updatabilityFilter != null) {
   if (!updatabilityFilter.contains(definition.getUpdatability())) {
     continue;
   }
  }

}
I can see that the definition reports the updatability as "READONLY" for the type property and thus it gets skipped, meaning that later on it complains that "cmisSmiley SurprisedbjectTypeId" is missing.  I modified the values at run time and forced it to keep "cmisSmiley SurprisedbjectTypeId".  Creation worked perfectly.

This doesn't make much sense to me.  During creation you need to be able to set the object type, after that it is fixed.  So either I am invoking OpenCMIS incorrectly, Alfresco is reporting value incorrectly or there is a bug within OpenCMIS.  I hope this helps someone help me!

nikes
Champ on-the-rise
Champ on-the-rise
I am having the same problem !

Even after specifying cmisSmiley SurprisedbjectTypeId it asks for it !!

gclaussn
Champ in-the-making
Champ in-the-making
hey guys,
i'm dealing with CMIS since a few weeks within the scope of my pracitical work. Also I am using the OpenCMIS framework, which is honestly poorly documented. After browsing through the source code, i got a lot of things realized.
Here my way to create a folder:


ArrayList<Property<?>> propertyData = new ArrayList<Property<?>>();

//Necessary properties
propertyData.add(session.getProvider().getObjectFactory().createPropertyStringData(PropertyIds.CMIS_NAME, "folderName"));
propertyData.add(session.getProvider().getObjectFactory().createPropertyIdData(PropertyIds.CMIS_OBJECT_TYPE_ID, "cmis:folder"));

//Create folder
session.getProvider().getObjectService().createFolder(
    session.getRepositoryInfo().getId(), //Repository ID
    session.getProvider().getObjectFactory().createPropertiesData(propertyData), //Properties
    parentFolderId, //Parent folder ID
    null, //Policies
    null, //AccessControlList add
    null, //AccessControlList remove
    null); //ExtensionsData
The id of the folder is returned.

regards, gclaussn

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

I wrote a lot of the OpenCMIS code, so I can comment on that.

@J.I.: That's an Alfresco bug. The CMIS spec defines the updatability of cmisSmiley SurprisedbjectTypeId as ONCREATE but Alfresco returns READONLY. Since OpenCMIS filters all READONLY properties to create a spec compliant request, cmisSmiley SurprisedbjectTypeId is filtered as well.

@gclaussn: You are right, we have to work on the documentation. You are using the provider API (which was recently renamed to client binding API). For this API the CMIS specification could serve as the documentation. You already found the object factory. That should be all you need. You might want to switch to client API, though. It's more intuitive.

gclaussn
Champ in-the-making
Champ in-the-making
hi fmui,
thanks for the advice.
I'm already using a lot of CMIS material, especially the CMIS Specification Template (http://docs.oasis-open.org/cmis/CMIS/v1.0/cmis-spec-v1.0.html), which should help beginners to deal with CMIS (hint from me for all others).

unknown-user
Champ on-the-rise
Champ on-the-rise
Thanks fmui.  I thought I was going crazy.  I will see if I can raise a bug against Alfresco for this.
Just create ALF-2637 http://issues.alfresco.com/jira/browse/ALF-2637

I have already read a lot of the spec, but it raises more questions than it answers.  Smiley Sad
Can I check for group membership?
Can I get a list of users with a specific permission? etc.

davidc
Star Contributor
Star Contributor
Thanks for investigating and reporting this issue.

We'll fix it for our imminent 3.3g Community release.

davidc
Star Contributor
Star Contributor
The fix is now available in SVN HEAD.

I hope to update cmis.alfresco.com to latest HEAD by end of today.

It'll be in 3.3g which will be released imminently.

unknown-user
Champ on-the-rise
Champ on-the-rise
Awesome.  That seems to be working!