problems alfresco add twice version opencmis

339 views
Skip to first unread message

positivefresh

unread,
Feb 7, 2013, 11:51:07 AM2/7/13
to alfresco-open...@googlegroups.com

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?

Mi code:

  private static void uploadDocument(Session session, Folder folder, File file) throws IOException {
  
  
    FileInputStream fis = new FileInputStream(file);
    dis = new DataInputStream(fis);
    byte[] bytes = new byte[(int) file.length()];
    dis.readFully(bytes);
    Document doc22;
 
   
    List<Ace> addAces = new LinkedList<Ace>();
    List<Ace> removeAces = new LinkedList<Ace>();
    List<Policy> policies = new LinkedList<Policy>();
   

    try{
     System.out.println("intenta obtener con el patch AC/pdfpruebas");   
     doc22 = (Document) session.getObjectByPath("/AC/jls7.pdf");
    }catch(CmisObjectNotFoundException e){
        System.out.println("file not exist:" + "/pruebas/jls7.pdf");
         byte[] bytes2 = new byte[(int) file.length()];
         FileNameMap fileNameMap = URLConnection.getFileNameMap();
         String mimetype = fileNameMap.getContentTypeFor(file.getName());
         //FIRST TIME CREATE THE DOCUMENT 
         String idoc= uploadFile(folder,bytes2,file.getName().toString(),mimetype.toString());

       return;
    }

     //here if carry on file in server exist and i make a setcontentstream instead create.. its work for me .. but maybe there is better way to do....


        Map<String, String> newDocProps2 = new HashMap<String, String>();
        newDocProps2.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        newDocProps2.put(PropertyIds.NAME, "jls7.pdf");
        newDocProps2.put(PropertyIds.CREATED_BY, "bestbyte");

           
         
        try{
         
         ContentStream    contentStream2 = new ContentStreamImpl(file.getAbsolutePath(), null, "application/pdf",
                    new ByteArrayInputStream(bytes));
         ObjectId doc=doc22.setContentStream(contentStream2, true, true);
         try{

         }catch(Exception e){

         }finally{

         }

        

        }catch(Exception err){
            System.out.println("un error" + err.toString());
        }


    }   




    public static String uploadFile(Folder folder,byte[] bytes,String fileName,String contentType) {
        String idDoc = null;
        // properties
        Map<String, Object> newDocProps = new HashMap<String, Object>();
        newDocProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        newDocProps.put(PropertyIds.NAME, fileName);
        //newDocProps.put(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, "TRUE");
        newDocProps.put(PropertyIds.IS_LATEST_VERSION, "TRUE");
     
        ContentStream contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(bytes.length),contentType, new ByteArrayInputStream(bytes));
        try{
            // create the file                        
            Document doc = folder.createDocument(newDocProps, contentStream,VersioningState.MINOR);
            idDoc = doc.getId();
        } catch(CmisConstraintException e){
            //org.apache.log4j.Logger.logger.error("Could not create file");
        }
        return idDoc;
    }


P.D
I configure to make all versionable documents y alfresco config.




positivefresh ok

unread,
Feb 14, 2013, 10:59:56 AM2/14/13
to alfresco-open...@googlegroups.com
Solve the problems was auto version conflicts , i config as false at least for me works ok


2013/2/7 positivefresh <positi...@gmail.com>




--
You received this message because you are subscribed to the Google Groups "Alfresco OpenCMIS Extension" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alfresco-opencmis-e...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dhaval Soni

unread,
Feb 21, 2013, 4:03:58 AM2/21/13
to alfresco-open...@googlegroups.com
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();


2013/2/7 positivefresh <positi...@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to alfresco-opencmis-extension+unsub...@googlegroups.com.

positivefresh ok

unread,
Feb 22, 2013, 7:24:27 AM2/22/13
to alfresco-open...@googlegroups.com
Im my case the problem was thats i configure in 2 diferents places as versionable true, as global and as single config.  

positivefresh ok

unread,
Feb 22, 2013, 7:25:29 AM2/22/13
to alfresco-open...@googlegroups.com
sorry ..i mean autoversion ...


2013/2/22 positivefresh ok <positi...@gmail.com>

positivefresh ok

unread,
Feb 22, 2013, 7:33:11 AM2/22/13
to alfresco-open...@googlegroups.com
Check it in contentModel.xml , at least for me solve , with this you dont need to set the version properties in cmis, you just have to indicate if Major... in create..

            <property name="cm:autoVersion">
               <title>Auto Version</title>
               <type>d:boolean</type>
               <default>true</default>
            </property>



2013/2/22 positivefresh ok <positi...@gmail.com>
Reply all
Reply to author
Forward
0 new messages