cancel
Showing results for 
Search instead for 
Did you mean: 

Adding children to store root

hsjawanda
Champ in-the-making
Champ in-the-making
Hi,

I have been trying a few things, have been getting unexpected results, and now I am confused.  So here are my questions:

Is there anything special about adding a node (say, a folder) directly as a child of a store root? I have a store with protocol "workspace" – will the following code work for adding a folder directly under the store root:


// this.storeRef points to the store I am interested in.
NodeRef rootNode = nodeService.getRootNode(this.storeRef);

// Creating a folder as a direct child of storeRef
ChildAssociationRef childAssocRef = nodeService.createNode(rootNode,
        ContentModel.PROP_CONTAINS, QName.createQName(
                NamespaceService.CONTENT_MODEL_1_0_URI, folderName),
        ContentModel.TYPE_FOLDER);

Does it matter whether I use ContentModel.PROP_CONTAINS or some other QName as the assocTypeQName when adding a child to a store's root?

What are the differences between creating child associations and creating plain-jane associations (NodeService#createAssociation())? I think one of the differences is that (recursive) searching under a parent node will search those nodes related through child associations, but not those related through plain associations – is this correct?

If I don't put any "PATH:" term in my Lucene search, does the whole store get searched? For example, if I construct a query like this:


String query = "+TYPE:\"" + ContentModel.TYPE_FOLDER.toString() + "\"";

will I get back a list of all the folders in the store being searched?  Will the assocTypeQName I use while adding children make a difference to the results of the above query?

I apologize for asking so many questions in a single post, but I am getting confused by some of the results I am seeing :-).

Thanks.
28 REPLIES 28

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

No there is nothing special about the the root node other than its association to its children is called 'children' rather than a folder which is called 'contains'.

I've updated the code below to reflect this:


// this.storeRef points to the store I am interested in.
NodeRef rootNode = nodeService.getRootNode(this.storeRef);

// Creating a folder as a direct child of storeRef
ChildAssociationRef childAssocRef = nodeService.createNode(rootNode,
        ContentModel.PROP_CHILDREN, QName.createQName(
                NamespaceService.CONTENT_MODEL_1_0_URI, folderName),
        ContentModel.TYPE_FOLDER);

What are the differences between creating child associations and creating plain-jane associations (NodeService#createAssociation())?

* A child association implies a hierarchy between nodes.
* An association is a relationship between two nodes (with no hierarchy).

Cheers,
Roy

hsjawanda
Champ in-the-making
Champ in-the-making
Hi Roy,
No there is nothing special about the the root node other than its association to its children is called 'children' rather than a folder which is called 'contains'.
This is only a naming convention, right?  Will any constraints be violated if the wrong child-association name gets used?

Deleting a container node deletes its children too, right?

Thanks for your reply to my first posting.

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Yes, the name of the association can be anything you want, it is the type of the association (eg: 'children') that must follow the model defintion.

Yes, when a node is deleted its children are deleted too.

Cheers,
Roy

soeursourire
Champ in-the-making
Champ in-the-making
I was thinking I understood how to add a new node in MySQL and I wanted to add a node function in this database under the node People at the same level than Person but not in the node Person. (Person and function are brothers). So I was doing as follow:

- a new class FunctionService that is almost exactly the same than PersonServiceImpl

- in MyNewUserWizard in init() I initialize my function service :
this.functionService = new FunctionService();
this.functionService.setNodeService(this.nodeService);
this.functionService.setSearchService(this.searchService);
//this.functionService.setStoreRef(Repository.getStoreRef());

-in MyNewUserWizard in startWizardForEdit() I added this:
Node nodeFN = new Node(ref);  setFunction(nodeFN);
I have a node Node function;

-in MyNewUserWizard in populate() I added this: 
Map<String, Object> propsFN = getFunction().getProperties();

-And in finish(), I added :
Map<QName, Serializable> propsFN = new HashMap<QName, Serializable>(5);
propsFN.put(MyContentModel.PROP_FN_ID, this.functionId);
String assocNameFN = QName.createValidLocalName(String.valueOf(this.functionId));
NodeRef newFunction = this.functionService.createFunction(propsFN);

However, while doing that when I call the function finish() I have errors such as  Java.lang.NullPointerException. I have apparently a problem in getPeopleContainer (called by createFunction) while doing this:
NodeRef rootNodeRef = this.nodeService.getRootNode(storeRef);
List<NodeRef> results = searchService.selectNodes(rootNodeRef, PEOPLE_FOLDER, null, namespacePrefixResolver, false);

What do I do wrong here?
Thanks for help.

soeursourire
Champ in-the-making
Champ in-the-making
I found the problem… my NameSpacePrefixResolver was null. So now I can add a node function in the node People at the same level than the node person however while browsing the NodeBrowser if I first check a node person then the node function has the same properties than person and respectively. And then when I want to check again the node function I have this error:

cannot add component with id 'aspects' and path : {Component-Path : [Class: javax.faces.component.html.HtmlDataTable,Id: aspects]} to its parent component. This might be a problem due to duplicate ids.

I hope somebody will agree for helping me.. thanks

gavinc
Champ in-the-making
Champ in-the-making
This is more than likely a bug with the node browser. This error happens in JSF sometimes when a component is not given an explicit id.

Try closing the node browser and returing to it as a workaround.

An issue in JIRA has been raised for this: http://www.alfresco.org/jira/browse/AWC-563

soeursourire
Champ in-the-making
Champ in-the-making
Thanks a lot for the answer. So does that mean as well that when I go in my node function and I see the properties of my node person instead it is a bug of nodebrowser? How and where can I check in the database if my nodes are correctly filled?

I also noticed than when I delete some users that I created, they are removed from node browser but all usernames are kept in the database, is it normal?
Thus I wanted to delete some of these usernames from MySQL by command line but now I cannot log in to Alfresco as admin…

Thanks again

soeursourire
Champ in-the-making
Champ in-the-making
My god!! Help please!
Since I modified something in the database I cannot log in as admin and have this error page:

javax.portlet.PortletException: Error calling action method of component with id loginForm:submit

caused by:
javax.faces.FacesException: Error calling action method of component with id loginForm:submit

caused by:
javax.faces.el.EvaluationException: Exception while invoking expression #{LoginBean.login}

caused by:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.alfresco.repo.security.permissions.impl.hibernate.RecipientImpl#org.alfresco.repo.security.permissions.impl.hibernate.RecipientImpl@35f5b8]


What can I do now? I reinstalled MySQL and installed the last version of Alfresco and have this error!!

kevinr
Star Contributor
Star Contributor
Your issue may be related to this problem?
http://www.alfresco.org/forums/viewtopic.php?t=1125&highlight=

It looks like a similar error (it may not be) - keep an eye on the post and we should resolve it soon.

Kevin