0

I use createfolder or streamupdate , the problems is , thats version twice , i mean every upload alfresco do:

call to uploadFile.... back to document version version 0.2 version 0 1

again.. call to uploadFile.... back to document version

version 0.4 version 0.3

.... how can i do to versión just one versión for uploadfile?

Here is the code for Create Document and Update Document.

Create Document...

    FileInputStream fis = new FileInputStream(file);
    DataInputStream dis = new DataInputStream(fis);
    byte[] bytes = new byte[(int) file.length()];
    dis.readFully(bytes);

    Map<String, String> newDocProps = new HashMap<String, String>();
    newDocProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
    newDocProps.put(PropertyIds.NAME, file.getName());
    newDocProps.put(PropertyIds.IS_LATEST_VERSION, "TRUE");
    List<Ace> addAces = new LinkedList<Ace>();
    List<Ace> removeAces = new LinkedList<Ace>();
    List<Policy> policies = new LinkedList<Policy>();
    try {
        ContentStream contentStream = new ContentStreamImpl(file.getName(),  BigInteger.valueOf(bytes.length), fileType, new ByteArrayInputStream(bytes));
        Document doc = folder.createDocument(newDocProps, contentStream, VersioningState.MINOR, policies, removeAces, addAces, session.getDefaultContext());
        AlfrescoDocument alfDoc = (AlfrescoDocument) doc; 
        if(alfDoc.hasAspect("P:cm:versionable")) { 
          Map<String, Object> properties = new HashMap<String, Object>(); 
          properties.put("cm:autoVersion", true); 
          alfDoc.updateProperties(properties); 
        }
    } catch (Exception e) {
        if(e.getMessage().contains("Conflict")){
            Document document = (Document) session.getObject(session.getObjectByPath(".../Space/"+file.getName()).getId());
            ContentStream contentStream = new ContentStreamImpl(file.getName(), BigInteger.valueOf(bytes.length), fileType, new ByteArrayInputStream(bytes));
            updateDcoument(document,contentStream);             

        }

    }
}
Dhaval Soni
  • 85
  • 1
  • 10
  • 2
    there's no such a thing as uploadFile in OpenCMIS, I guess it's custom code. Can you please post it? – skuro Feb 21 '13 at 09:48
  • When I call folder.createDocument(...), It works fine but when I going to check version History on my browser for this document, it saws me 0.1 and 0.2 version. And both version contain same content. – Dhaval Soni Feb 21 '13 at 10:05

1 Answers1

0

In your code you really create two versions of the document:

Document doc = folder.createDocument(newDocProps, contentStream, VersioningState.MINOR, policies, removeAces, addAces, session.getDefaultContext());

and

alfDoc.updateProperties(properties);

As by default cm:versionable is set to have cm:autoVersionOnUpdateProps set to true the latter call issues a new version to be created. You can set that property to false on the object or globally by altering the cm:versionable definition. See the docs.

skuro
  • 13,414
  • 1
  • 48
  • 67
  • I have delete alfDoc.updateProperties(properties); portion from my code but still have same prob. Should we update version manually of document with code?? I mean Alfresco do version itself. – Dhaval Soni Feb 21 '13 at 11:39