i made a connection to repository using JCRUtils and got session. Next, I need the resource but, when I am trying to fetch resource using resourceResolver, I am getting null. Whereas, if I use session.getNode, i am getting the node (not null). I also tried to use AdaptManager to convert the node to resource, but I am getting null in this case also.
How do I get the resource from the node? or How do I fetch resource directly from session?
[I need to use valueMap, thus I need resource]
Solved! Go to Solution.
Views
Replies
Total Likes
final ResourceResolver resource_resolver = request.getResourceResolver();
Iterator<Resource> some_it = resource_resolver.findResources("select * from [dam:Asset] as asset", "JCR-SQL2");
some_it.forEachRemaining(object_from_iterator -> {
Node jcr_node = object_from_iterator.adaptTo(Node.class);
try {
String someProperty = jcr_node.getProperty("some:Property").getString();
jcr_node.getSession().getWorkspace().getObservationManager().setUserData("changedByWorkflowProcess");
jcr_node.setProperty("some:Property", "some new value");
logger.info("blah blah made some changes");
jcr_node.getSession().save();
}
catch { ... }
finally { ... }
}
Hi, Are you trying to get ValueMap to fetch properties? if so you can use session.getNode("path to the node you wanna access").getProperties();
When you try to get resource this way (adapterManager.getAdapter(nodeObj, Resource.class)) are getting null ?
final ResourceResolver resource_resolver = request.getResourceResolver();
Iterator<Resource> some_it = resource_resolver.findResources("select * from [dam:Asset] as asset", "JCR-SQL2");
some_it.forEachRemaining(object_from_iterator -> {
Node jcr_node = object_from_iterator.adaptTo(Node.class);
try {
String someProperty = jcr_node.getProperty("some:Property").getString();
jcr_node.getSession().getWorkspace().getObservationManager().setUserData("changedByWorkflowProcess");
jcr_node.setProperty("some:Property", "some new value");
logger.info("blah blah made some changes");
jcr_node.getSession().save();
}
catch { ... }
finally { ... }
}
WHen using the JCR API - you can get props - as Marc as shown.
You can get Resource from from jcr session like below:
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("user.jcr.session", session);
resourceResolver = resourceFactory.getResourceResolver(paramMap);
Resource resource=resourceResolver.getResource("/apps/AEM64App");
where session is JCR Session object
Views
Replies
Total Likes
the requirement is that i make use of value map
yes, I am getting null
You can adapt resource to ValueMap
Example :
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("user.jcr.session", session);
resourceResolver = resourceFactory.getResourceResolver(paramMap);
Resource resource=resourceResolver.getResource("/content/AEM64App/en/jcr:content/par/mycomponent");
ValueMap prop = resource.adaptTo(ValueMap.class);
String lastModified = prop.get("jcr:lastModified", String.class);