The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 1
Jackrabbit OCM in practice
Kasia Kozłowska
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 2
• unique slide URL
• alt text as slide URL
• all slides modifiable within one page
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 3
Gallery JSON, model and JCR
public class Gallery implements CqPage {
private String id;
private JcrContent jcrContent;
public Gallery() {
jcrContent = new JcrContent();
jcrContent.setCqPage(this);
}
}
public class JcrContent {
private String galleryTitle;
}
{
id="/content/examplegallery",
galleryTitle="My example gallery"
}
• examplegallery
 jcr:primaryType = "cq:Page"
• jcr:content
jcr:primaryType = "cq:PageContent"
galleryTitle = "My example gallery"
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 4
JCR
API
Sling
API
AEM
API
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 5
Jackrabbit OCM Gallery
@JsonSerialize(using = GallerySerializer.class)
@JsonDeserialize(using = GalleryDeserializer.class)
@Node(jcrType = "cq:Page", jcrMixinTypes = "ocm:discriminator")
public class Gallery implements CqPage {
private String id;
@Bean(jcrName = "jcr:content")
private JcrContent jcrContent;
public Gallery() {
jcrContent = new JcrContent();
jcrContent.setCqPage(this);
}
@Field(path = true)
public String getId() {
return id;
}
// getters and setters
}
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 6
Jackrabbit OCM JcrContent
@Node(jcrType = "cq:PageContent", jcrMixinTypes = "ocm:discriminator")
public class JcrContent {
private String path = "/jcr:content";
private CqPage page;
@Field(jcrName="sling:resourceType")
private String slingResourceType;
@Field private String galleryTitle;
@Field(path = true)
public String getId() {
return page.getId() + path;
}
// getters and setters
}
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 7
Kjhkuhhkihihihoi
pk
List<Class> classes = new ArrayList<Class>();
classes.add(Gallery.class);
classes.add(JcrContent.class);
// @Node, @Field, @Bean, @Collection, @Implement
ReflectionUtils.setClassLoader(dynamicClassLoaderManager
.getDynamicClassLoader());
Session session = resolver.adaptTo(Session.class);
Mapper mapper = new AnnotationMapperImpl(classes);
new ObjectContentManagerImpl(session, mapper);
// ocm: insert(object), update(object),
remove(object), getObject(path),
objectExists(path), getObjects(query),
save()
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 8
PROS
• Clear, easy to maintain code
• Simplified unit tests
• No jumping between APIs
CONS
• Internal JCR/Sling data
exposed in models
• ocm:discriminator
The future of digital marketing. London, Poland, Copenhagen.
© 08/07/2015 Page 9
Thank you!
kasia.kozlowska@cognifide.com
Jackrabbit OCM docs
Jackrabbit OCM git
example project : zip
example osgi project : zip

Jackrabbit OCM in practice

  • 1.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 1 Jackrabbit OCM in practice Kasia Kozłowska
  • 2.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 2 • unique slide URL • alt text as slide URL • all slides modifiable within one page
  • 3.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 3 Gallery JSON, model and JCR public class Gallery implements CqPage { private String id; private JcrContent jcrContent; public Gallery() { jcrContent = new JcrContent(); jcrContent.setCqPage(this); } } public class JcrContent { private String galleryTitle; } { id="/content/examplegallery", galleryTitle="My example gallery" } • examplegallery  jcr:primaryType = "cq:Page" • jcr:content jcr:primaryType = "cq:PageContent" galleryTitle = "My example gallery"
  • 4.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 4 JCR API Sling API AEM API
  • 5.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 5 Jackrabbit OCM Gallery @JsonSerialize(using = GallerySerializer.class) @JsonDeserialize(using = GalleryDeserializer.class) @Node(jcrType = "cq:Page", jcrMixinTypes = "ocm:discriminator") public class Gallery implements CqPage { private String id; @Bean(jcrName = "jcr:content") private JcrContent jcrContent; public Gallery() { jcrContent = new JcrContent(); jcrContent.setCqPage(this); } @Field(path = true) public String getId() { return id; } // getters and setters }
  • 6.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 6 Jackrabbit OCM JcrContent @Node(jcrType = "cq:PageContent", jcrMixinTypes = "ocm:discriminator") public class JcrContent { private String path = "/jcr:content"; private CqPage page; @Field(jcrName="sling:resourceType") private String slingResourceType; @Field private String galleryTitle; @Field(path = true) public String getId() { return page.getId() + path; } // getters and setters }
  • 7.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 7 Kjhkuhhkihihihoi pk List<Class> classes = new ArrayList<Class>(); classes.add(Gallery.class); classes.add(JcrContent.class); // @Node, @Field, @Bean, @Collection, @Implement ReflectionUtils.setClassLoader(dynamicClassLoaderManager .getDynamicClassLoader()); Session session = resolver.adaptTo(Session.class); Mapper mapper = new AnnotationMapperImpl(classes); new ObjectContentManagerImpl(session, mapper); // ocm: insert(object), update(object), remove(object), getObject(path), objectExists(path), getObjects(query), save()
  • 8.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 8 PROS • Clear, easy to maintain code • Simplified unit tests • No jumping between APIs CONS • Internal JCR/Sling data exposed in models • ocm:discriminator
  • 9.
    The future ofdigital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 9 Thank you! kasia.kozlowska@cognifide.com Jackrabbit OCM docs Jackrabbit OCM git example project : zip example osgi project : zip