SlideShare a Scribd company logo
1 of 56
Download to read offline
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 1
JCR, Sling or AEM? Which API should I use and
when?
Maciej Matuszewski
maciej.matuszewski@cognifide.com
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 2
What is the High-level API?
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 3
What is the Low-level API?
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 4
JCR, Sling and AEM
AEM
Sling
JCR
Other
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 5
Why bother?
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 6
Become an AEM Expert
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 7
resource.getChild("text")
node.getNode("text")
node.getProperty("jcr:title").getString()
resource.getChild("jcr:title").adaptTo(String.class)
page.getTitle()
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 8
node.addNode(String relPath)
resourceResolver.create(Resource parent, String name,
Map<String,Object> properties)
node.orderBefore(String srcChildRelPath, String destChildRelPath)
pageManager.order(Page page, String beforeName)
pageManager.order(Resource resource, String beforeName)
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 9
Don’t mix abstraction layers
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 10
Session session = resourceResolver.adaptTo(Session.class);
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(QUERY_STRING, Query.JCR_SQL2);
QueryResult queryResult = query.execute();
NodeIterator nodeIterator = queryResult.getNodes();
while (nodeIterator.hasNext()) {
Node nextNode = nodeIterator.nextNode();
String path = nextNode.getPath();
Resource resource = resourceResolver.getResource(path);
veryImportantMethod(resource);
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 11
Iterator<Resource> resourcesIterator = resourceResolver
.findResources(QUERY_STRING, Query.JCR_SQL2);
while (resourcesIterator.hasNext()) {
Resource resource = resourcesIterator.next();
veryImportantMethod(resource);
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 12
@Inject
public CarModel(Resource resource) throws RepositoryException {
Node node = resource.adaptTo(Node.class);
Node pageNode;
if (node.getParent().getName().equals("rightParsys")) {
pageNode = node.getParent().getParent().getParent().getParent();
} else {
pageNode = node.getParent().getParent().getParent();
}
String pageTitle = node.getProperty("jcr:title").getString();
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 13
@Inject
public CarModel(@CurrentPage Page page) {
String pageTitle = page.getTitle();
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 14
resourceResolver.commit();
Session session = resourceResolver.adaptTo(Session.class);
session.save();
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 15
What are your tools?
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 16
Components
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 17
Components
Servlets
Filters
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 18
Components
OSGi Services
Servlets
Filters
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 19
Components
OSGi Services
Servlets
Filters
Templates
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 20
Components
OSGi Services
Servlets
Filters
Templates
Replication
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 21
Components
OSGi Services
Servlets
Filters
Templates
Querying Repository
Replication
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 22
Components
OSGi Services
Servlets
Filters
Templates
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 23
Components
OSGi Services
Servlets
Filters
Workflows
Templates
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 24
Components
OSGi Services
Servlets
Dynamic dialogs
Filters
Workflows
Templates
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 25
Components
OSGi Services
Servlets
Dynamic dialogs
Filters
Events
Jobs
Workflows
Templates
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 26
Components
OSGi Services
Servlets
Dynamic dialogs
Filters
Events
Jobs
Workflows
Templates
Digital Assets
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 27
Components
OSGi Services
Servlets
Dynamic dialogs
Filters
Events
Jobs
Workflows
Templates
Users and groups
ACLs
Digital Assets
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 28
Components
OSGi Services
Servlets
Dynamic dialogs
Filters
Events
Jobs
Workflows
Templates
Users and groups
ACLs
Digital Assets
Targeting and Analytics
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 29
Components
OSGi Services
Servlets
Dynamic dialogs
Filters
Events
Jobs
Workflows
Templates
Users and groups
ACLs
Digital Assets
Multi-Site Management
Targeting and Analytics
Querying Repository
Replication
Dispatcher
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 30
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 31
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 32
Sling advantages
More extendable/customizable
Simpler API, less exceptions
Adapters - http://localhost:4502/system/console/adapters
Support for ResourceDecorator, ResourceMerger and custom ResourceProviders
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 33
Models
SlingModels
Slice
Neba
etc.
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 34
@SlingServlet(resourceTypes = "myapp/core/components/car",
extensions = "json", selectors = "version")
public class CarServlet extends SlingSafeMethodsServlet {
@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response)
throws ServletException, IOException {
Resource resource = request.getResource();
CarModel model = resource.adaptTo(CarModel.class);
model.getVersion();
model.getRegistration();
model.getFuelType();
//TODO
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 35
<div class="car-info">
Name: ${model.name}
Registration: ${model.registration}
Version: ${model.version}
</div>
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 36
AEM API is helpful
Authoring pages
Tagging
DAM
Replication
Workflows
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 37
Pages
Page containingPage = pageManager.getContainingPage(resource);
containingPage.getTitle();
Page newPage = pageManager.create(resource.getPath(), "child-page",
"/apps/myapp/core/templates/basic", "Child Page");
resource.adaptTo(ReplicationStatus.class).isActivated()
pageManager.touch(Node page, boolean shallow, Calendar now,
boolean clearRepl)
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 38
Digital Asset Management
DamUtils
Asset
Metadata
MIME type
Renditions
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 39
Tags
RangeIterator<Resource> tagsIterator = tagManager.find("geometrixx:events");
TagManager.FindResults findResults = tagManager.findByTitle("Events");
Tag[] tags = tagManager.getTags(resource);
for (Tag tag : tags) {
long count = tag.getCount();
Iterator<Resource> resources = tag.find();
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 40
Keep JCR for special occasions
Workspace Management
Versioning
Access Control Management
Users and Groups
Locking
Lifecycle Management
Mixins
Node Type Management
Primary Type Change
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 41
Performance
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 42
Performance
Important argument to use low level API
Higher level API usually means additional overhead
Best performance is always achieved by using lowest possible API
Let’s test it!
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 43
Node rootNode = getNode("/content/geometrixx")
println countChildren(rootNode)
long countChildren(Node root) {
long count = 0
NodeIterator iterator = root.getNodes()
while (iterator.hasNext()) {
Node child = iterator.nextNode()
count += countChildren(child)
count++
}
return count
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 44
Resource root = getResource("/content/geometrixx")
println countChildren(root)
long countChildren(Resource root) {
long count = 0
Iterator<Resource> iterator = root.listChildren()
while (iterator.hasNext()) {
Resource child = iterator.next()
count += countChildren(child)
count++
}
return count
}
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 45
0 2 4 6 8
AEM 5.6.1
AEM 6.0 SP2
Traversing /content/geometrixx tree
Sling API JCR API
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 46
GEOMETRIXX_CONTENT_PATH =
"/content/geometrixx/en/toolbar/profiles/forgot/thank_you/jcr:content/par"
Node parsysNode = getNode(GEOMETRIXX_CONTENT_PATH)
for (int i = 0; i < 10000; i++) parsysNode.getNode("text")
Resource parsysResource = getResource(GEOMETRIXX_CONTENT_PATH)
for (int i = 0; i < 10000; i++) parsysResource.getChild("text")
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 47
GEOMETRIXX_CONTENT_PATH =
"/content/geometrixx/en/toolbar/profiles/forgot/thank_you/jcr:content/par"
Node parsysNode = getNode(GEOMETRIXX_CONTENT_PATH)
for (int i = 0; i < 10000; i++) parsysNode.getNode("text")
Resource parsysResource = getResource(GEOMETRIXX_CONTENT_PATH)
for (int i = 0; i < 10000; i++) parsysResource.getChild("text")
JCR time – 37 ms
Sling time – 931 ms
Times for 10000 operations
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 48
Performance summary
JCR is much faster than Sling
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 49
Performance summary
JCR is much faster than Sling
Q.E.D.
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 50
Performance summary
JCR is much faster than Sling
Q.E.D.
So what?!
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 51
Component’s performance
Sample page with 3 Rich Text components
Let each component get it’s child 3 times
Resource.getChild() operation takes 0.0931 ms
Node.getNode() operation takes 0.0037 ms
Header
Menu
Carousel
Rich Text
Rich Text Rich Text
Article List
Footer
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 52
Component’s performance
Sample page with 3 Rich Text components
Let each component get it’s child 3 times
Resource.getChild() operation takes 0.0931 ms
Node.getNode() operation takes 0.0037 ms
Difference between JCR and Sling for entire
page is less than 1 ms!
Header
Menu
Carousel
Rich Text
Rich Text Rich Text
Article List
Footer
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 53
Component’s performance
Sample page with 3 Rich Text components
Let each component get it’s child 3 times
Resource.getChild() operation takes 0.0931 ms
Node.getNode() operation takes 0.0037 ms
Difference between JCR and Sling for entire
page is less than 1 ms!
And it’s without cache on dispather
or performance tunning.
Header
Menu
Carousel
Rich Text
Rich Text Rich Text
Article List
Footer
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 54
Batch operations
Data import/export
Non-cached
Constantly repeated
Low-level
Components
Servlets
Non-critical
One time ops
High-level
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 55
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 56
Thank you!
Przemysław Pakulski
Tomasz Rękawek
maciej.matuszewski@cognifide.com

More Related Content

What's hot

AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101Adobe
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEMAccunity Software
 
Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6DEEPAK KHETAWAT
 
Heap Dump Analysis - AEM: Real World Issues
Heap Dump Analysis - AEM: Real World IssuesHeap Dump Analysis - AEM: Real World Issues
Heap Dump Analysis - AEM: Real World IssuesKanika Gera
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMBojana Popovska
 
Experience and Content Fragment
Experience and Content FragmentExperience and Content Fragment
Experience and Content FragmentHeena Madan
 
Introduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsIntroduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsStefano Celentano
 
Introduction to Sightly
Introduction to SightlyIntroduction to Sightly
Introduction to SightlyAnkit Gubrani
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowPrabhdeep Singh
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsStormpath
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentGabriel Walt
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatAEM HUB
 
The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architectureAshokkumar T A
 
Apache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTApache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTCarsten Ziegeler
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesGabriel Walt
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAndrew Khoury
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsGabriel Walt
 

What's hot (20)

AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEM
 
AEM - Client Libraries
AEM - Client LibrariesAEM - Client Libraries
AEM - Client Libraries
 
Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6
 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
 
Heap Dump Analysis - AEM: Real World Issues
Heap Dump Analysis - AEM: Real World IssuesHeap Dump Analysis - AEM: Real World Issues
Heap Dump Analysis - AEM: Real World Issues
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
 
Experience and Content Fragment
Experience and Content FragmentExperience and Content Fragment
Experience and Content Fragment
 
Introduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsIntroduction to Sightly and Sling Models
Introduction to Sightly and Sling Models
 
Introduction to Sightly
Introduction to SightlyIntroduction to Sightly
Introduction to Sightly
 
slingmodels
slingmodelsslingmodels
slingmodels
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component Development
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
 
The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architecture
 
Apache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTApache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and REST
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
 

Similar to AEM, Sling or JCR API guide

When dispatcher caching is not enough...
When dispatcher caching is not enough...When dispatcher caching is not enough...
When dispatcher caching is not enough...Jakub Wadolowski
 
An Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech CompanyAn Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech CompanyRoger Giuffre
 
Boost your productivity for free!
Boost your productivity for free!Boost your productivity for free!
Boost your productivity for free!Maciej Majchrzak
 
Aftermarket2012 cargotec malcolmyoull
Aftermarket2012 cargotec malcolmyoullAftermarket2012 cargotec malcolmyoull
Aftermarket2012 cargotec malcolmyoullCopperberg
 
API Monetization
API MonetizationAPI Monetization
API MonetizationCapgemini
 
An Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech CompanyAn Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech CompanyRoger Giuffre
 
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019VMware Tanzu
 
Introduction to tag management
Introduction to tag managementIntroduction to tag management
Introduction to tag managementQubit
 
TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"
TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"
TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"TourismFastForward
 
TechEvent DWH Modernization
TechEvent DWH ModernizationTechEvent DWH Modernization
TechEvent DWH ModernizationTrivadis
 
Realising Digital’s Full Potential in the Value Chain
Realising Digital’s Full Potential in the Value ChainRealising Digital’s Full Potential in the Value Chain
Realising Digital’s Full Potential in the Value ChainCognizant
 
BIG IoT Marketplace & API
BIG IoT Marketplace & APIBIG IoT Marketplace & API
BIG IoT Marketplace & APIBIG IoT Project
 
[apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs
[apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs [apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs
[apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs WSO2
 
It’s Not About What You Know. It’s About What You Can Do
It’s Not About What You Know. It’s About What You Can DoIt’s Not About What You Know. It’s About What You Can Do
It’s Not About What You Know. It’s About What You Can DoMichal Hodinka
 
Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...
Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...
Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...Flink Forward
 
The next generation of ap is luis weir.cwin18.telford
The next generation of ap is   luis weir.cwin18.telfordThe next generation of ap is   luis weir.cwin18.telford
The next generation of ap is luis weir.cwin18.telfordCapgemini
 
The Rise Of Event Streaming – Why Apache Kafka Changes Everything
The Rise Of Event Streaming – Why Apache Kafka Changes EverythingThe Rise Of Event Streaming – Why Apache Kafka Changes Everything
The Rise Of Event Streaming – Why Apache Kafka Changes EverythingKai Wähner
 
Apache kafka event_streaming___kai_waehner
Apache kafka event_streaming___kai_waehnerApache kafka event_streaming___kai_waehner
Apache kafka event_streaming___kai_waehnerconfluent
 
INTERFACE, by apidays - From Monolith to Open Finance with APIs by Marcilio ...
INTERFACE, by apidays  - From Monolith to Open Finance with APIs by Marcilio ...INTERFACE, by apidays  - From Monolith to Open Finance with APIs by Marcilio ...
INTERFACE, by apidays - From Monolith to Open Finance with APIs by Marcilio ...apidays
 
Agile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul Jadhav
Agile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul JadhavAgile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul Jadhav
Agile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul JadhavAgileNetwork
 

Similar to AEM, Sling or JCR API guide (20)

When dispatcher caching is not enough...
When dispatcher caching is not enough...When dispatcher caching is not enough...
When dispatcher caching is not enough...
 
An Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech CompanyAn Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech Company
 
Boost your productivity for free!
Boost your productivity for free!Boost your productivity for free!
Boost your productivity for free!
 
Aftermarket2012 cargotec malcolmyoull
Aftermarket2012 cargotec malcolmyoullAftermarket2012 cargotec malcolmyoull
Aftermarket2012 cargotec malcolmyoull
 
API Monetization
API MonetizationAPI Monetization
API Monetization
 
An Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech CompanyAn Innovative Big-Data Web Scraping Tech Company
An Innovative Big-Data Web Scraping Tech Company
 
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
Operationalizing AI at scale using MADlib Flow - Greenplum Summit 2019
 
Introduction to tag management
Introduction to tag managementIntroduction to tag management
Introduction to tag management
 
TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"
TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"
TFF2015, Christian Bizer, Uni Mannheim "Schema.org-Annotationen in Webseiten"
 
TechEvent DWH Modernization
TechEvent DWH ModernizationTechEvent DWH Modernization
TechEvent DWH Modernization
 
Realising Digital’s Full Potential in the Value Chain
Realising Digital’s Full Potential in the Value ChainRealising Digital’s Full Potential in the Value Chain
Realising Digital’s Full Potential in the Value Chain
 
BIG IoT Marketplace & API
BIG IoT Marketplace & APIBIG IoT Marketplace & API
BIG IoT Marketplace & API
 
[apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs
[apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs [apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs
[apidays LIVE HONK KONG] - Building an Integrated Supply Chain for APIs
 
It’s Not About What You Know. It’s About What You Can Do
It’s Not About What You Know. It’s About What You Can DoIt’s Not About What You Know. It’s About What You Can Do
It’s Not About What You Know. It’s About What You Can Do
 
Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...
Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...
Flink Forward Berlin 2017: Bas Geerdink, Martijn Visser - Fast Data at ING - ...
 
The next generation of ap is luis weir.cwin18.telford
The next generation of ap is   luis weir.cwin18.telfordThe next generation of ap is   luis weir.cwin18.telford
The next generation of ap is luis weir.cwin18.telford
 
The Rise Of Event Streaming – Why Apache Kafka Changes Everything
The Rise Of Event Streaming – Why Apache Kafka Changes EverythingThe Rise Of Event Streaming – Why Apache Kafka Changes Everything
The Rise Of Event Streaming – Why Apache Kafka Changes Everything
 
Apache kafka event_streaming___kai_waehner
Apache kafka event_streaming___kai_waehnerApache kafka event_streaming___kai_waehner
Apache kafka event_streaming___kai_waehner
 
INTERFACE, by apidays - From Monolith to Open Finance with APIs by Marcilio ...
INTERFACE, by apidays  - From Monolith to Open Finance with APIs by Marcilio ...INTERFACE, by apidays  - From Monolith to Open Finance with APIs by Marcilio ...
INTERFACE, by apidays - From Monolith to Open Finance with APIs by Marcilio ...
 
Agile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul Jadhav
Agile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul JadhavAgile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul Jadhav
Agile Network India | Industry 4.0 - Digital Agility Vade Mecum | Atul Jadhav
 

More from connectwebex

Jackrabbit OCM in practice
Jackrabbit OCM in practiceJackrabbit OCM in practice
Jackrabbit OCM in practiceconnectwebex
 
Building Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience ManagerBuilding Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience Managerconnectwebex
 
AEM 6 DAM - Integrations, Integrations, Integrations
AEM 6 DAM - Integrations, Integrations, IntegrationsAEM 6 DAM - Integrations, Integrations, Integrations
AEM 6 DAM - Integrations, Integrations, Integrationsconnectwebex
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMconnectwebex
 
Presentation daniel takai
Presentation daniel takaiPresentation daniel takai
Presentation daniel takaiconnectwebex
 
Presentation thomas simlinger
Presentation thomas simlingerPresentation thomas simlinger
Presentation thomas simlingerconnectwebex
 
five Sling features you should know
five Sling features you should knowfive Sling features you should know
five Sling features you should knowconnectwebex
 
Efficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQEfficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQconnectwebex
 
Web, Mobile, App and Back!
Web, Mobile, App and Back!Web, Mobile, App and Back!
Web, Mobile, App and Back!connectwebex
 
Tighten your Security and Privacy
Tighten your Security and PrivacyTighten your Security and Privacy
Tighten your Security and Privacyconnectwebex
 
THE BREAK-UP - A user interface love story
THE BREAK-UP - A user interface love storyTHE BREAK-UP - A user interface love story
THE BREAK-UP - A user interface love storyconnectwebex
 
Configuring CQ Security
Configuring CQ SecurityConfiguring CQ Security
Configuring CQ Securityconnectwebex
 
Integration Testing in AEM
Integration Testing in AEMIntegration Testing in AEM
Integration Testing in AEMconnectwebex
 
Sling Component Filters in CQ5
Sling Component Filters in CQ5 Sling Component Filters in CQ5
Sling Component Filters in CQ5 connectwebex
 
Integrating Backend Systems
Integrating Backend SystemsIntegrating Backend Systems
Integrating Backend Systemsconnectwebex
 
Auto-testing production CQ instances with Muppet
Auto-testing production CQ instances with MuppetAuto-testing production CQ instances with Muppet
Auto-testing production CQ instances with Muppetconnectwebex
 

More from connectwebex (19)

Jackrabbit OCM in practice
Jackrabbit OCM in practiceJackrabbit OCM in practice
Jackrabbit OCM in practice
 
Building Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience ManagerBuilding Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience Manager
 
AEM 6 DAM - Integrations, Integrations, Integrations
AEM 6 DAM - Integrations, Integrations, IntegrationsAEM 6 DAM - Integrations, Integrations, Integrations
AEM 6 DAM - Integrations, Integrations, Integrations
 
Build single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
 
SonarQube for AEM
SonarQube for AEMSonarQube for AEM
SonarQube for AEM
 
Presentation daniel takai
Presentation daniel takaiPresentation daniel takai
Presentation daniel takai
 
Presentation thomas simlinger
Presentation thomas simlingerPresentation thomas simlinger
Presentation thomas simlinger
 
five Sling features you should know
five Sling features you should knowfive Sling features you should know
five Sling features you should know
 
Efficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQEfficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQ
 
Web, Mobile, App and Back!
Web, Mobile, App and Back!Web, Mobile, App and Back!
Web, Mobile, App and Back!
 
Tighten your Security and Privacy
Tighten your Security and PrivacyTighten your Security and Privacy
Tighten your Security and Privacy
 
THE BREAK-UP - A user interface love story
THE BREAK-UP - A user interface love storyTHE BREAK-UP - A user interface love story
THE BREAK-UP - A user interface love story
 
Configuring CQ Security
Configuring CQ SecurityConfiguring CQ Security
Configuring CQ Security
 
Integration Testing in AEM
Integration Testing in AEMIntegration Testing in AEM
Integration Testing in AEM
 
Sling Component Filters in CQ5
Sling Component Filters in CQ5 Sling Component Filters in CQ5
Sling Component Filters in CQ5
 
Integrating Backend Systems
Integrating Backend SystemsIntegrating Backend Systems
Integrating Backend Systems
 
Scaling CQ5
Scaling CQ5Scaling CQ5
Scaling CQ5
 
Auto-testing production CQ instances with Muppet
Auto-testing production CQ instances with MuppetAuto-testing production CQ instances with Muppet
Auto-testing production CQ instances with Muppet
 
CQ Maven Methods
CQ Maven MethodsCQ Maven Methods
CQ Maven Methods
 

AEM, Sling or JCR API guide

  • 1. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 1 JCR, Sling or AEM? Which API should I use and when? Maciej Matuszewski maciej.matuszewski@cognifide.com
  • 2. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 2 What is the High-level API?
  • 3. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 3 What is the Low-level API?
  • 4. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 4 JCR, Sling and AEM AEM Sling JCR Other
  • 5. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 5 Why bother?
  • 6. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 6 Become an AEM Expert
  • 7. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 7 resource.getChild("text") node.getNode("text") node.getProperty("jcr:title").getString() resource.getChild("jcr:title").adaptTo(String.class) page.getTitle()
  • 8. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 8 node.addNode(String relPath) resourceResolver.create(Resource parent, String name, Map<String,Object> properties) node.orderBefore(String srcChildRelPath, String destChildRelPath) pageManager.order(Page page, String beforeName) pageManager.order(Resource resource, String beforeName)
  • 9. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 9 Don’t mix abstraction layers
  • 10. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 10 Session session = resourceResolver.adaptTo(Session.class); QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery(QUERY_STRING, Query.JCR_SQL2); QueryResult queryResult = query.execute(); NodeIterator nodeIterator = queryResult.getNodes(); while (nodeIterator.hasNext()) { Node nextNode = nodeIterator.nextNode(); String path = nextNode.getPath(); Resource resource = resourceResolver.getResource(path); veryImportantMethod(resource); }
  • 11. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 11 Iterator<Resource> resourcesIterator = resourceResolver .findResources(QUERY_STRING, Query.JCR_SQL2); while (resourcesIterator.hasNext()) { Resource resource = resourcesIterator.next(); veryImportantMethod(resource); }
  • 12. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 12 @Inject public CarModel(Resource resource) throws RepositoryException { Node node = resource.adaptTo(Node.class); Node pageNode; if (node.getParent().getName().equals("rightParsys")) { pageNode = node.getParent().getParent().getParent().getParent(); } else { pageNode = node.getParent().getParent().getParent(); } String pageTitle = node.getProperty("jcr:title").getString(); }
  • 13. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 13 @Inject public CarModel(@CurrentPage Page page) { String pageTitle = page.getTitle(); }
  • 14. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 14 resourceResolver.commit(); Session session = resourceResolver.adaptTo(Session.class); session.save();
  • 15. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 15 What are your tools?
  • 16. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 16 Components
  • 17. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 17 Components Servlets Filters
  • 18. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 18 Components OSGi Services Servlets Filters
  • 19. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 19 Components OSGi Services Servlets Filters Templates
  • 20. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 20 Components OSGi Services Servlets Filters Templates Replication
  • 21. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 21 Components OSGi Services Servlets Filters Templates Querying Repository Replication
  • 22. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 22 Components OSGi Services Servlets Filters Templates Querying Repository Replication Dispatcher
  • 23. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 23 Components OSGi Services Servlets Filters Workflows Templates Querying Repository Replication Dispatcher
  • 24. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 24 Components OSGi Services Servlets Dynamic dialogs Filters Workflows Templates Querying Repository Replication Dispatcher
  • 25. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 25 Components OSGi Services Servlets Dynamic dialogs Filters Events Jobs Workflows Templates Querying Repository Replication Dispatcher
  • 26. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 26 Components OSGi Services Servlets Dynamic dialogs Filters Events Jobs Workflows Templates Digital Assets Querying Repository Replication Dispatcher
  • 27. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 27 Components OSGi Services Servlets Dynamic dialogs Filters Events Jobs Workflows Templates Users and groups ACLs Digital Assets Querying Repository Replication Dispatcher
  • 28. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 28 Components OSGi Services Servlets Dynamic dialogs Filters Events Jobs Workflows Templates Users and groups ACLs Digital Assets Targeting and Analytics Querying Repository Replication Dispatcher
  • 29. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 29 Components OSGi Services Servlets Dynamic dialogs Filters Events Jobs Workflows Templates Users and groups ACLs Digital Assets Multi-Site Management Targeting and Analytics Querying Repository Replication Dispatcher
  • 30. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 30
  • 31. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 31
  • 32. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 32 Sling advantages More extendable/customizable Simpler API, less exceptions Adapters - http://localhost:4502/system/console/adapters Support for ResourceDecorator, ResourceMerger and custom ResourceProviders
  • 33. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 33 Models SlingModels Slice Neba etc.
  • 34. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 34 @SlingServlet(resourceTypes = "myapp/core/components/car", extensions = "json", selectors = "version") public class CarServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource resource = request.getResource(); CarModel model = resource.adaptTo(CarModel.class); model.getVersion(); model.getRegistration(); model.getFuelType(); //TODO }
  • 35. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 35 <div class="car-info"> Name: ${model.name} Registration: ${model.registration} Version: ${model.version} </div>
  • 36. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 36 AEM API is helpful Authoring pages Tagging DAM Replication Workflows
  • 37. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 37 Pages Page containingPage = pageManager.getContainingPage(resource); containingPage.getTitle(); Page newPage = pageManager.create(resource.getPath(), "child-page", "/apps/myapp/core/templates/basic", "Child Page"); resource.adaptTo(ReplicationStatus.class).isActivated() pageManager.touch(Node page, boolean shallow, Calendar now, boolean clearRepl)
  • 38. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 38 Digital Asset Management DamUtils Asset Metadata MIME type Renditions
  • 39. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 39 Tags RangeIterator<Resource> tagsIterator = tagManager.find("geometrixx:events"); TagManager.FindResults findResults = tagManager.findByTitle("Events"); Tag[] tags = tagManager.getTags(resource); for (Tag tag : tags) { long count = tag.getCount(); Iterator<Resource> resources = tag.find(); }
  • 40. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 40 Keep JCR for special occasions Workspace Management Versioning Access Control Management Users and Groups Locking Lifecycle Management Mixins Node Type Management Primary Type Change
  • 41. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 41 Performance
  • 42. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 42 Performance Important argument to use low level API Higher level API usually means additional overhead Best performance is always achieved by using lowest possible API Let’s test it!
  • 43. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 43 Node rootNode = getNode("/content/geometrixx") println countChildren(rootNode) long countChildren(Node root) { long count = 0 NodeIterator iterator = root.getNodes() while (iterator.hasNext()) { Node child = iterator.nextNode() count += countChildren(child) count++ } return count }
  • 44. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 44 Resource root = getResource("/content/geometrixx") println countChildren(root) long countChildren(Resource root) { long count = 0 Iterator<Resource> iterator = root.listChildren() while (iterator.hasNext()) { Resource child = iterator.next() count += countChildren(child) count++ } return count }
  • 45. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 45 0 2 4 6 8 AEM 5.6.1 AEM 6.0 SP2 Traversing /content/geometrixx tree Sling API JCR API
  • 46. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 46 GEOMETRIXX_CONTENT_PATH = "/content/geometrixx/en/toolbar/profiles/forgot/thank_you/jcr:content/par" Node parsysNode = getNode(GEOMETRIXX_CONTENT_PATH) for (int i = 0; i < 10000; i++) parsysNode.getNode("text") Resource parsysResource = getResource(GEOMETRIXX_CONTENT_PATH) for (int i = 0; i < 10000; i++) parsysResource.getChild("text")
  • 47. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 47 GEOMETRIXX_CONTENT_PATH = "/content/geometrixx/en/toolbar/profiles/forgot/thank_you/jcr:content/par" Node parsysNode = getNode(GEOMETRIXX_CONTENT_PATH) for (int i = 0; i < 10000; i++) parsysNode.getNode("text") Resource parsysResource = getResource(GEOMETRIXX_CONTENT_PATH) for (int i = 0; i < 10000; i++) parsysResource.getChild("text") JCR time – 37 ms Sling time – 931 ms Times for 10000 operations
  • 48. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 48 Performance summary JCR is much faster than Sling
  • 49. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 49 Performance summary JCR is much faster than Sling Q.E.D.
  • 50. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 50 Performance summary JCR is much faster than Sling Q.E.D. So what?!
  • 51. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 51 Component’s performance Sample page with 3 Rich Text components Let each component get it’s child 3 times Resource.getChild() operation takes 0.0931 ms Node.getNode() operation takes 0.0037 ms Header Menu Carousel Rich Text Rich Text Rich Text Article List Footer
  • 52. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 52 Component’s performance Sample page with 3 Rich Text components Let each component get it’s child 3 times Resource.getChild() operation takes 0.0931 ms Node.getNode() operation takes 0.0037 ms Difference between JCR and Sling for entire page is less than 1 ms! Header Menu Carousel Rich Text Rich Text Rich Text Article List Footer
  • 53. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 53 Component’s performance Sample page with 3 Rich Text components Let each component get it’s child 3 times Resource.getChild() operation takes 0.0931 ms Node.getNode() operation takes 0.0037 ms Difference between JCR and Sling for entire page is less than 1 ms! And it’s without cache on dispather or performance tunning. Header Menu Carousel Rich Text Rich Text Rich Text Article List Footer
  • 54. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 54 Batch operations Data import/export Non-cached Constantly repeated Low-level Components Servlets Non-critical One time ops High-level
  • 55. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 55
  • 56. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 56 Thank you! Przemysław Pakulski Tomasz Rękawek maciej.matuszewski@cognifide.com