jackrabbit ocm in practice

9

Click here to load reader

Upload: connectwebex

Post on 10-Aug-2015

26 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Jackrabbit OCM in practice

The future of digital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 1

Jackrabbit OCM in practiceKasia Kozłowska

Page 2: Jackrabbit OCM in practice

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

Page 3: Jackrabbit OCM in practice

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"

Page 4: Jackrabbit OCM in practice

The future of digital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 4

JCR

API

Sling

API AE

M

AP

I

Page 5: Jackrabbit OCM in practice

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

}

Page 6: Jackrabbit OCM in practice

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

}

Page 7: Jackrabbit OCM in practice

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

Page 8: Jackrabbit OCM in practice

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

Page 9: Jackrabbit OCM in practice

The future of digital marketing. London, Poland, Copenhagen. © 08/07/2015 Page 9

Thank you!

[email protected]

Jackrabbit OCM docs

Jackrabbit OCM git

example project : zip

example osgi project : zip