cancel
Showing results for 
Search instead for 
Did you mean: 

Creating folders saving each noderefs

spilby
Confirmed Champ
Confirmed Champ
I have two questions about a path creation and properties.

This is my scene: I need to create a complete path of folders. Each one has own properties, and in the last folder, the user will put contents. Depends of these contents, the properties of each folder changes.

An user gives me the path. The folders inside may exists or not. For know if folder exists, I obtain the node (and look if is not null) doing something like this:

StringTokenizer tokenizer = new StringTokenizer(path, "/");
while (tokenizer.hasMoreTokens()) {
    String folderName = tokenizer.nextToken();
    NodeRef newNode = getNodeService().getChildByName(nodeParent, ContentModel.ASSOC_CONTAINS, folderName );
    // —> *
}

First question: all ok about this? Is the best way to create a full path?


When I finish the creation of folder and put the content, I need to update the properties of the parents. I'm thinking about this on 3 ways:

1 - Create a list of NodeRefs and store each one while create each folder, in the hasMoreTokens iteration (look at —> *).

2 - Do the same but store the uuids String of each nodeRef, not the NodeRef. And then, obtain the nodeRef from these uuids.

3 - Doing anything on the iteration and out of there, later, use the nodeService.getPrimaryParent(nodeRef).getParentRef() for update the properties of each parent node from the son.

Second question: which option do you think is better? The tree of folders will be very big. I need a efficient and quickly solution because of this.

I think that option 3 is slower than store a list of nodes to acces them quickly, but I'm not sure. And between option 1 and 2, maybe 1 is quickly too (I have the nodeRef directly without doing more operations) but I don't know if it consumes a lot of memory. I don't know if NodeRef is a big objects and having a list of NodeRefs is a handicap for the memory.

Thanks a lot!


5 REPLIES 5

romschn
Star Collaborator
Star Collaborator
When you say you need to update property of each folder, does it mean that for example if there is a property lastuploadedby available in entire folder hierarchy and when a content is added then you want to propogate the uploaded by username in entire hierarchy. Is this kind of a scenario or on each folder you need to update different properties altogether. Please elaborate more on your requirement.

spilby
Confirmed Champ
Confirmed Champ
Oks. The properties are the same in all folders, but the value may be different. I need to update 2 properties.

One have the size of all the contents. If I put a content of 2Mb and another of 3mb, this property will be updated to 5mb.

The other property give me the number of sons in the hierarchy. Not the direct sons, all the sons. Each folder in this case, may be have a different value. Each time a folder is created, I need to update this property from all the parents.


Both of these 2 properties appears in all the folders.

Thanks!

mrogers
Star Contributor
Star Contributor
The nodes in the path are cached so each of your solutions should be o.k.    There's not a lot to choose between them.

However what you may have problems with is contention on your root node.   If you have a large number of concurrent updates you may like to think about how those updates feed up your tree.   Perhaps aggregating changes together.  Or doing something clever.

spilby
Confirmed Champ
Confirmed Champ
Ups, you're right. Maybe different users change the tree concurrently. Exists a solution for block the nodes and execute the update when the tree isn't blocked? How I can do this?

romschn
Star Collaborator
Star Collaborator
You can use LockService to get this done. getLockStatus method will give you the current lock status for the node.