cancel
Showing results for 
Search instead for 
Did you mean: 

how to update file description on versioning

verodriguez1
Champ in-the-making
Champ in-the-making
Hello

I'm trying to update file description when make a new version of file in the Alfresco Repository. The update is OK, but the lastest description doesn't shows in the alfresco web ui.

here is the code:

  public String updateFile (String fileName, String filePath, String username,
            String fileDescription, String folderPath, String mimeType) throws Exception {

        AuthenticationUtils.startSession(USERNAME, PASSWORD);
        try
        {         
            RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
            AuthoringServiceSoapBindingStub authoringService = WebServiceFactory.getAuthoringService();
        
            Reference reference = this.obtenerArchivoRepositorio(fileName,folderPath);
            if (reference != null){
                makeVersionable(repositoryService, reference);
        
                // Checkout the newly created content, placing the working document in the same folder
                Predicate itemsToCheckOut = new Predicate(new Reference[]{reference}, null, null);
                CheckoutResult checkOutResult = authoringService.checkout(itemsToCheckOut, null);
           
                // Get a reference to the working copy
                Reference workingCopyReference = checkOutResult.getWorkingCopies()[0];
               
           
                // Update the content of the working copy
                ContentFormat format = new ContentFormat(mimeType, "UTF-8");
               
                //loads the file from remote or local machine
                InputStream in;
                if (filePath.indexOf("http") >= 0 || filePath.indexOf("ftp") >= 0){
                    in = new URL(filePath).openStream();
                    try {
                        contentService.write(workingCopyReference, Constants.PROP_CONTENT,
                                IOUtils.toByteArray(in), format);
                    } finally {
                       IOUtils.closeQuietly(in);
                    }      
                }else{
                    File archivoOrigen = new  File (filePath);
                    contentService.write(workingCopyReference, Constants.PROP_CONTENT,
                            FileUtils.readFileToByteArray(archivoOrigen), format);
                }                     
           
                // Now check the working copy in with a description of the change made that will be recorded in the version history
                Predicate predicate = new Predicate(new Reference[]{workingCopyReference}, null, null);
                NamedValue [] propiedades = new NamedValue[5];
                propiedades[0] = Utils.createNamedValue(Constants.PROP_DESCRIPTION,fileDescription);
                propiedades[1] = Utils.createNamedValue(Constants.OWNER_AUTHORITY,username);
                propiedades[2] = Utils.createNamedValue(Constants.PROP_NAME,fileName);
                propiedades[3] = Utils.createNamedValue(Constants.PROP_TITLE,fileName);
                propiedades[4] = Utils.createNamedValue(Constants.PROP_USERNAME,username);
                authoringService.checkin(predicate, propiedades, false);
                return "TRUE";
            }else{
                return "FALSE";
            }
        }finally{
            // End the session
            AuthenticationUtils.endSession();
        }
    }

I will apreciate the help

Vladimir
2 REPLIES 2

prateekgoyal
Champ in-the-making
Champ in-the-making
hey Vladimir,

here is the description your problem.

Predicate itemsToCheckOut = new Predicate(new Reference[]{contentReference}, null, null);
CMLUpdate cmlUpdate = new CMLUpdate();
cmlUpdate.setWhere(itemsToCheckOut);
cmlUpdate.setWhere_id(itemsToCheckOut.getNodes(0).getUuid());
cmlUpdate.setProperty(titledProps);        
cml.setUpdate(new CMLUpdate[] { cmlUpdate });
UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml);

here "contentReference" is the refrenence of original document.

mandavasateesh
Champ in-the-making
Champ in-the-making
Hi,

I am also looking for updating the file from Java. I have used the SDK to upload the files to Alfresco Server.

Can some one suggest on how to update the file contents in Alfresco.

The above post suggests that the code is working for update. May I request you to please share this code, so that I can also test the update of files.

Thanks in Advance