2

I am trying to update the content type of files in alfresco through OpenCMIS.

The CMIS workbench shows the type in the types windows, with as only disabled switch 'Policy controlable'. Its local name is document, queryname is prefix:document and Base type is cmis:document.

In the groovy console, I tried the following:

Folder folder = (Folder) session.getObjectByPath("/Sites/mySite");

CmisObject o = session.getObject(aNodeRef);
cmis.printObjectSummary(o);

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "D:prefix:document");
properties.put(PropertyIds.NAME, "itsanewname!");

println("\n\nFrom "+PropertyIds.OBJECT_TYPE_ID+" cmis:document to " + " D:prefix:document:\n\n\n");

o.updateProperties(properties);
cmis.printObjectSummary(o);

The name is updated alright, but the content type remains cmis:document.

This code was written to the following example of mister Potts himself:

properties.put(PropertyIds.OBJECT_TYPE_ID, "D:sc:whitepaper,P:sc:webable,P:sc:productRelated");
properties.put(PropertyIds.NAME, filename);
properties.put("sc:isActive", true);
GregorianCalendar publishDate = new GregorianCalendar(2007,4,1,5,0);
properties.put("sc:published", publishDate);

However, he uses this example snippet to create a node, not update it.

I also tried this code in a java application that is linked to alfresco, to no avail.

Jeff Potts
  • 10,468
  • 17
  • 40
Mark Tielemans
  • 1,528
  • 3
  • 20
  • 40

2 Answers2

4

You cannot change an object's type once it is created through CMIS. If you look at the cmis:objectTypeId property definition, you'll notice that its updatability is set to "ONCREATE" and not "READWRITE".

Jeff

Jeff Potts
  • 10,468
  • 17
  • 40
0

Trying to do something similar here.

I have a few documents that were originally uploaded as .doc files with the mimetype of Microsoft Word (application/msword) to alfresco share.

Now I've been able to successfully change the extension and update the mime type property to Microsoft Word 2007. But, when the file is downloaded and opened with microsoft word, it throws an error saying that the file format doesn't match the extension.

I thought I was doing it correctly but apparently not. Here is the part of the code that's supposed to handle the mime type conversion.

Map<String, Object> updateProperties = new HashMap<String, Object>();

updateProperties.put("cmis:name", changeName);
updateProperties.put("cmis:contentStreamFileName", changeName);
document.updateProperties(updateProperties);

ContentStream contentStream = document.getContentStream();
InputStream stream = contentStream.getStream();
ContentStream cs1 = session.getObjectFactory().createContentStream(changeName, docLength, MimeTypes.getMIMEType("docx"), stream);

document.setContentStream(cs1, true);
Emir Memic
  • 270
  • 1
  • 3
  • 14
  • You should really start your own question for this. Having said that, you can use the nodebrowser to see what the mimetype is after you run this update code. You could also check what `MimeTypes.getMIMEType("docx")` evaluates to. – Mark Tielemans Jan 10 '18 at 22:51