Expand my Community achievements bar.

How to store data in Java content repository in AEM 6.4

Avatar

Level 2

Hello Friends

I am new to AEM and trying to save data in the java content repository and following the below link :

Adobe Experience Manager Help | Persisting Adobe Experience Manager 5 data in the Java Content Repos...

but as this is for older version of AEM, this was not helpful and i didn't able to save data in the JCR.

by the above link what is clear to me is we have to save all the fields of customer as a property in the JCR node ,

but how to call this service which they have defined is not clear to me.

I have implemented a component which as all the fields shown in example and i have called the simpleservlet using ajax call and i have all the field data in this servlet but dont know what should be next step to call this service and save data in JCR.

Thanks in advance.

Yash

3 Replies

Avatar

Former Community Member

Hi Yash,

You can refer to the below helpx article (AEM version: Adobe Experience Manager 6.x).

The aim of the below article is to store customer data in JCR and then retrieve the content which is stored in JCR by triggering the queries. The results of the query will be displayed on the web page in the form of grid table as shown in the below article.

In the below helpx article, search for injestCustData method. This method is responsible for storing customer data in the AEM JCR.

Adobe Experience Manager Help | Querying Adobe Experience Manager 6 data using the Sling getServiceR...

This article uses the Sling method named getServiceResourceResolver to obtain a Session instance. This method replaces the use of the getAdministrativeResourceResolver method, as it deprecated.

so, you must perform the below two tasks, as outlined in the below article, prior to running the sample example mentioned in the helpx article.

1) Create an AEM system user (or system user for AEM 6.1) named data with the permissions

2) Map the user with the Sling Mapper service

To create system user in AEM, please refer:

http://www.aemcq5tutorials.com/tutorials/create-system-user-in-aem/

I hope this information helps!

Regards,

Lavanya Malyala

Avatar

Community Advisor

Hi,

in AEM data is store in JCR in forms of nodes and properties.

So to save data in JCR, you need to create nodes or/and properties.

In your servlet get the data and create node/property using JCR Node API.

Node (Content Repository for Java Technology API Version 2.0)

Example :

Node custNode = customerRoot.addNode("customer"+firstName+lastName+custId);

        //make sure name of node is unique

    custNode.setProperty("id", custId);

    custNode.setProperty("firstName", firstName);

    custNode.setProperty("lastName", lastName);

    custNode.setProperty("phone", phone); 

    custNode.setProperty("desc", desc);



Arun Patidar

Avatar

Level 10

Only difference between that older AEM community article and what you need to do now (as these other community members have pointed out) - is you need to use a system user to obtain a session.

Scott's Digital Community: How to create an Adobe Experience Manager System User and use Sling Mappi...