cancel
Showing results for 
Search instead for 
Did you mean: 

how to catch DuplicateChildNodeNameException

cszamudio
Champ on-the-rise
Champ on-the-rise
Hi,

I'm using the Web Service to upload files into a repository.  I have a question about what exception actually gets thrown when a duplicate is identified by the Repository.

Currently, in my code I get a RepositoryFault exception when the Repository system encounters a duplicate. If I use the getMessage1() method of the fault,  I can see from the message text that the actual exception is org.alfresco.service.cmr.repository.DuplicateChildNodeNameException.

Assuming that there are other reasons why a RepositoryFault could occur, is there any way to catch the DuplicateChildNodeNameException directly as a thrown Exception from the Repository rather than parsing the message text to figure out what happened? (I do note that the returned errorCode is set to 0).

Thanks for any advice on this.

Carlos S. Zamudio
3 REPLIES 3

madhurao
Champ in-the-making
Champ in-the-making
Rather than directly upload file before check if file was already exists or not based on method return type, if file is not there then upload the file o.w show message like file alreay exists in the repository.
I have used the following code, i guess  this might be useful to you.

public static boolean checkSpaceAvailable(String parSpacePath, String filename)
{
   boolean result = true;
   try
   {
      parSpacePath = StringEncription.encode(parSpacePath);
      
      if(parSpacePath.contains("_x002f_")) parSpacePath = parSpacePath.replaceAll("_x002f_", "/");
      
      if(parSpacePath.contains("/")) parSpacePath = parSpacePath.replaceAll("/", "/cm:");
      
      //use "/" or "/cm:" before StringEncription.encode(filename) in the below line
      parSpacePath = "/app:company_home"+parSpacePath+"/"+StringEncription.encode(filename);
      
      System.out.println("Decoded Parent Space Path =======>>" + StringEncription.decode(parSpacePath));
            
      Reference checkFolder = new Reference(storeRef, null, parSpacePath);
      
      // Check to see if the parent folder has already been created or not
       WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{checkFolder}, storeRef, null));
      
   }catch(Exception e){
      System.out.println("!!! FILE ALREADY EXISTS IN THE REPOSITORY !!!");
      result = false;
   }
   System.out.println("Space Available :" + result);
   return result;
}

Regards,
Madhu

cszamudio
Champ on-the-rise
Champ on-the-rise
Thank you Madhu for you generous support to my questions.

The reason I did not take the approach you have suggested is that it entails performing an additional web service request for each file being uploaded.  I am supporting the ability to upload a large number of files at one time, and so I figured that the overhead of an additional service call for the possibly rare event that the file already exists would degrade performance.  However, I am not comfortable with my own solution of parsing the message text from the RepositoryFault to determine the duplicate exception since it feels vulnerable to breakage down the road, so I think I will need to follow your suggestion. Thank you.

Carlos S. Zamudio

cszamudio
Champ on-the-rise
Champ on-the-rise
Hi,
Just out of curiosity, where does the StringEncription function come from? Thanks.
Carlos S. Zamudio