Thursday, January 19, 2012

Using RIDC lib to checkin file into UCM from ADF application.


       Below given code snippet shows, checking in file into UCM repository from ADF application    
       using RIDC lib to . So if you are not using Webcenter, and do not have an access to OOTB  
        taskflow for file upload , this code can help you.


       // Get the file using the file upload component in ADF
       UploadedFile newFile = (UploadedFile)getIf1().getValue();

        // store the file in a temporary location on server
        String tempFold = "C:/tempFold/";
        String fileName =  newFile.getFilename();
        String filetype =  newFile.getContentType();
        InputStream is = null;
        try {
            is = newFile.getInputStream();
            File f= new File(tempFold + fileName);
            OutputStream out=new FileOutputStream(f);
            byte buf[]=new byte[1024];
            int len;
            while((len=is.read(buf))>0)
            out.write(buf,0,len);
            out.close();
            is.close();
        } catch (IOException e) {
        }
       
        // Get Ridc client manager
        IdcClientManager manager = new IdcClientManager();
        IdcClient idcClient = null;
       
        try {
              // create the client to check in the file in the ucm
              idcClient = manager.createClient(<UCM url as string>);
              IdcContext userContext = new IdcContext("weblogic", "welcome1");    
              DataBinder binder = idcClient.createBinder();

              binder.putLocal ("IdcService", "CHECKIN_UNIVERSAL");
              // get the binder
             
              binder.putLocal ("dDocTitle", "File1");
              binder.putLocal ("dDocName", "Despicableme");
              binder.putLocal ("dDocType", "DigitalMedia");
              binder.putLocal ("dSecurityGroup", "Public");
              // add a file
           
              binder.addFile ("primaryFile", new TransferFile( new java.io.File(tempFold + fileName)));
              // checkin the file
              ServiceResponse response = idcClient.sendRequest(userContext, binder);
              // get the response as a string
              String responseString = response.getResponseAsString ();
           
              System.out.println("done");
              System.out.println("st:"+responseString);
        } catch (IdcClientException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
          }

1 comment:

  1. What will be the response string here. And will we get Content Id which we can use for invoking HDL service

    ReplyDelete