Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

get resource from session

Avatar

Avatar
Validate 1
Level 3
shaheenas113483
Level 3

Likes

9 likes

Total Posts

57 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 1
Level 3
shaheenas113483
Level 3

Likes

9 likes

Total Posts

57 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 5
View profile
shaheenas113483
Level 3

08-05-2019

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]

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Ignite 1
Employee
aemmarc
Employee

Likes

184 likes

Total Posts

243 posts

Correct Reply

92 solutions
Top badges earned
Ignite 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Ignite 1
Employee
aemmarc
Employee

Likes

184 likes

Total Posts

243 posts

Correct Reply

92 solutions
Top badges earned
Ignite 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
aemmarc
Employee

08-05-2019

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 { ... }

}

Answers (7)

Answers (7)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

08-05-2019

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

Avatar

Avatar
Ignite 1
Level 2
k_ra
Level 2

Likes

4 likes

Total Posts

25 posts

Correct Reply

1 solution
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
Level 2
k_ra
Level 2

Likes

4 likes

Total Posts

25 posts

Correct Reply

1 solution
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
k_ra
Level 2

08-05-2019

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();

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

09-05-2019

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);

Avatar

Avatar
Validate 1
Level 3
shaheenas113483
Level 3

Likes

9 likes

Total Posts

57 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 1
Level 3
shaheenas113483
Level 3

Likes

9 likes

Total Posts

57 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 5
View profile
shaheenas113483
Level 3

08-05-2019

yes, I am getting null

Avatar

Avatar
Validate 1
Level 3
shaheenas113483
Level 3

Likes

9 likes

Total Posts

57 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 5
View profile

Avatar
Validate 1
Level 3
shaheenas113483
Level 3

Likes

9 likes

Total Posts

57 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 5
View profile
shaheenas113483
Level 3

08-05-2019

the requirement is that i make use of value map

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

08-05-2019

WHen using the JCR API - you can get props - as Marc as shown.

Avatar

Avatar
Ignite 1
Level 2
k_ra
Level 2

Likes

4 likes

Total Posts

25 posts

Correct Reply

1 solution
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
Level 2
k_ra
Level 2

Likes

4 likes

Total Posts

25 posts

Correct Reply

1 solution
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
k_ra
Level 2

08-05-2019

When you try to get resource this way (adapterManager.getAdapter(nodeObj, Resource.class)) are getting null ?