Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 1
JCR, Sling or AEM? Which API should I use...
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("t...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 8
node.addNode(String relPath)
resourceReso...
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.adapt...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 11
Iterator<Resource> resourcesIterator = r...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 12
@Inject
public CarModel(Resource resourc...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 13
@Inject
public CarModel(@CurrentPage Pag...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 14
resourceResolver.commit();
Session sessi...
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
Filter...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 20
Components
OSGi Services
Servlets
Filter...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 21
Components
OSGi Services
Servlets
Filter...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 22
Components
OSGi Services
Servlets
Filter...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 23
Components
OSGi Services
Servlets
Filter...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 24
Components
OSGi Services
Servlets
Dynami...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 25
Components
OSGi Services
Servlets
Dynami...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 26
Components
OSGi Services
Servlets
Dynami...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 27
Components
OSGi Services
Servlets
Dynami...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 28
Components
OSGi Services
Servlets
Dynami...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 29
Components
OSGi Services
Servlets
Dynami...
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/customi...
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/cor...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 35
<div class="car-info">
Name: ${model.nam...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 36
AEM API is helpful
Authoring pages
Taggi...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 37
Pages
Page containingPage = pageManager....
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 38
Digital Asset Management
DamUtils
Asset
...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 39
Tags
RangeIterator<Resource> tagsIterato...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 40
Keep JCR for special occasions
Workspace...
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 lo...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 43
Node rootNode = getNode("/content/geomet...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 44
Resource root = getResource("/content/ge...
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
Traversi...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 46
GEOMETRIXX_CONTENT_PATH =
"/content/geom...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 47
GEOMETRIXX_CONTENT_PATH =
"/content/geom...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 48
Performance summary
JCR is much faster t...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 49
Performance summary
JCR is much faster t...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 50
Performance summary
JCR is much faster t...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 51
Component’s performance
Sample page with...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 52
Component’s performance
Sample page with...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 53
Component’s performance
Sample page with...
The future of digital marketing. London, Poland, Copenhagen.
© 29/06/2015 Page 54
Batch operations
Data import/export
Non-...
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ę...
Upcoming SlideShare
Loading in …5
×

JCR, Sling or AEM? Which API should I use and when?

9,463 views

Published on

Presentation “KISS your Authors - Simple Tools in AEM“ by Thomas Simlinger at CONNECT Web Experience in Basel on June 24/25, 2015.

  • Dating for everyone is here: ♥♥♥ http://bit.ly/39pMlLF ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Are You Heartbroken? Don't be upset, let Justin help you get your Ex back. ★★★ http://goo.gl/nkXEkK
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • ♣♣ 10 Easy Ways to Improve Your Performance in Bed... ★★★ https://tinyurl.com/rockhardxx
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • GOLD !! Thanks for sharing.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

JCR, Sling or AEM? Which API should I use and when?

  1. 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. 2. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 2 What is the High-level API?
  3. 3. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 3 What is the Low-level API?
  4. 4. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 4 JCR, Sling and AEM AEM Sling JCR Other
  5. 5. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 5 Why bother?
  6. 6. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 6 Become an AEM Expert
  7. 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. 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. 9. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 9 Don’t mix abstraction layers
  10. 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. 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. 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. 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. 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. 15. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 15 What are your tools?
  16. 16. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 16 Components
  17. 17. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 17 Components Servlets Filters
  18. 18. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 18 Components OSGi Services Servlets Filters
  19. 19. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 19 Components OSGi Services Servlets Filters Templates
  20. 20. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 20 Components OSGi Services Servlets Filters Templates Replication
  21. 21. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 21 Components OSGi Services Servlets Filters Templates Querying Repository Replication
  22. 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. 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. 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. 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. 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. 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. 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. 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. 30. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 30
  31. 31. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 31
  32. 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. 33. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 33 Models SlingModels Slice Neba etc.
  34. 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. 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. 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. 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. 38. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 38 Digital Asset Management DamUtils Asset Metadata MIME type Renditions
  39. 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. 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. 41. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 41 Performance
  42. 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. 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. 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. 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. 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. 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. 48. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 48 Performance summary JCR is much faster than Sling
  49. 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. 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. 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. 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. 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. 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. 55. The future of digital marketing. London, Poland, Copenhagen. © 29/06/2015 Page 55
  56. 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

×