how to get node property base on node id ?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
dharmraj
Active Member

how to get node property base on node id ?

i am passing node from  UI to Back end to fetch node property based on node id and set property value .

String nodeId = req.getParameter(ID);
logger.info(nodeId);
NodeRef node = serviceRegistry.getNodeService().getNodeRef(Long.valueOf(nodeId));
if(node!= null) {
serviceRegistry.getNodeService().setProperty(node, NOTIFICATION_IS_EMAIL_SENT, true);

}

Is it correct ?

1 Reply
Moderator
Moderator

Re: how to get node property base on node id ?

Its correct, but better to wrap as system user to avoid any permission issues. Refer the below code sample:

String nodeId = request.getParamater("nodeId"); //You can get the param from request for example

if (StringUtils.isNumeric(nodeId)) {
final NodeRef nodeReference = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() {
return nodeService.getNodeRef(Long.valueOf(nodeId));
}
}, AuthenticationUtil.getSystemUserName());

if (nodeReference !=null){
//Get all properties from the node
final Map<QName, Serializable> properties = nodeService.getProperties(nodeReference);

//OR

//Get A property from the node. Example: ContentModel.PROP_TITLE
final QName aProp = nodeService.getProperty(nodeReference, propQName);


//OR

nodeService.setProperty(actionedUponNodeRef, propQName, "A value");

}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍