cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using childByNamePath and upper / lower case

damiar
Champ in-the-making
Champ in-the-making
Hey guys,

actually I'm checking if a node already exists before creating it, so I can handle this case properly.
For example, suppose you want to create the node 'day' but a node named 'Day' (upper case D) already exists. What is happening now is that the function childByNamePath is returning 'null' if I use parentNode.childByNamePath('day'). That would be ok, since 'day' != 'Day', but the problem here is that if I want to create the node I get the error "Existing file or folder day already exists".

This is the code I'm using:

var documentExists = parentNode.childByNamePath('day') != null;
if (documentExists == true) { // documentExists is false, never is true
  status.code = 500;
  status.message = "Document already exist, please pick another name";
  status.redirect = true;
}

// stuff

var newDocument = parentNode.createFolder('day'); // Throws an exception ("Existing file or folder day already exists")

I cannot figure out of what is happening here… Any suggestion?

Alfresco Labs 3B running on Windows XP (development) and CentOS Linux (Production).
7 REPLIES 7

lista
Star Contributor
Star Contributor
Hi,

childByNamePath() is supposed to be case sensitive, do I don't see a problem there.
Why don't you try creating that node differently, for instance:

varnewDocument = parentNode.createNode("day", "cm:folder");

Cheers,
Lista.

damiar
Champ in-the-making
Champ in-the-making
Sorry for the delay Smiley Happy
I tried that and it is the same, nothing different happened Smiley Sad

damiar
Champ in-the-making
Champ in-the-making
Could you please try this?
I mean, just create a folder named "asd" and then try to create another one called "Asd". You will get an error telling you that the folder "Asd" already exists. The problem here is that when you ask for the existence of the folder with something like "companyhome.childByNamePath('Asd')" you get null (which means that the folder "Asd" doesn't exist).

Is this a bug?

mikeh
Star Contributor
Star Contributor
Hi

Yes, it's a known issue - currently planned to be fixed in v3.2. Please see https://issues.alfresco.com/jira/browse/ETHREEOH-34

Thanks,
Mike

damiar
Champ in-the-making
Champ in-the-making
Well… thank you Mike.
I do agree that this bug is not a 'critical' one, but it is undoubtedly a very important one! Because if you cannot check for the existence of a node how will you avoid errors when users execute a webscript that create nodes?
Remember that you cannot catch exceptions inside webscripts, so a very simple example (as the one I've suggested) just simply won't work…

Cheers

mikeh
Star Contributor
Star Contributor
Yep, I agree - that's why it's marked as to be fixed in the next version.

Thanks,
Mike

ziggypcl
Champ in-the-making
Champ in-the-making
Thanks for this information, i see the bug has been flagged as fixed in version 3.2r?
https://issues.alfresco.com/jira/browse/ETHREEOH-34?page=com.atlassian.jira.plugin.system.issuetabpa...

What is the fix exactly for this, does the childByNamePath() work as it did before or does it now ignore case?

I am also trying to create a folder based on the results of this call, i have a scenario of a folder names MacP existing but the childByNamePath() returns null when looking for a folder call Macp. But the createFolder() throws the error saying the file or folder already exists.

Example code.

      var folders;
      var parentFolder;
      var temp = "/";
      folders = folderName.split("/");
      parentFolder = companyhome;
      for (var i = 0; i < folders.length; i++) {
        temp += "/" + folders[i];
       
        var folder;
        folder = companyhome.childByNamePath(temp);
        if (folder == null) {
          var folder = parentFolder.createFolder(folders[i]);
          folder.properties["cm:title"] = folders[i];
          folder.properties["cm:description"] = folders[i];
          folder.properties["app:icon"] = "space-icon-default";
          folder.save();
        }
        parentFolder = folder;
      }   

      upload = folder.createFile(filename);
Kind Regards,
Andrew Siggemann.