I have got the same problem like uploading the new document, it will version twice of the the document. i don't understand why this happens.
here is my code....
private static void uploadDocument(Session session, Folder folder, File file, String fileType) throws IOException {
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_VERSION_SERIES_CHECKED_OUT, "TRUE");
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);
}
}
}
private static void updateDcoument(Document document){
try{
String cont = "second Update Document";
ContentStream contentStream2 = new ContentStreamImpl(null,
null, "plain/text", new ByteArrayInputStream(cont.getBytes()));
document.setContentStream(contentStream2, true,true);
System.out.println("Document update with Name :" + document.getName());
System.out.println("Document update with Version :" + document.getVersionLabel());
}
catch (Exception e) {
e.printStackTrace();