Download - Synthetic models

Transcript
Page 1: Synthetic models

SYNTHETIC MODELS

by Zoran Nikolovski

Page 2: Synthetic models

RESOURCE RESOLUTION

Page 3: Synthetic models

• Traditional web frameworks

– Resolve a Controller based on the data type

– Elaborate mechanics to load the data

• Sling

– A web framework based entirely on REST principals

– The data is at the center or the process

– Everything is a Resource

Page 4: Synthetic models

• Sling maintains a virtual tree of resources

• Each Resource type has a ResourceProvider which provides the root of its

resolution path

• Resource types in the tree

– JCR nodes

– File System

– Bundles

– Servlets

– Other (Non-JCR) Resources

System provided

Page 5: Synthetic models

• Resolving a Resource is simple

The ResourceResolver

takes in the resource path

Page 6: Synthetic models

• Resolving a Resource is simple

It identifies a suitable

ResourceProvider

The ResourceResolver

takes in the resource path

Page 7: Synthetic models

Which calls it’s getResource

method

• Resolving a Resource is simple

It identifies a suitable

ResourceProvider

The ResourceResolver

will take in the resource path

Page 8: Synthetic models

And provide us with the right

Resource

Which calls it’s getResource

method

• Resolving a Resource is simple

It identifies a suitable

ResourceProvider

The ResourceResolver

takes in the resource path

Page 9: Synthetic models

• Resource is a central concept to Sling

• Has a number of essential properties

– Including a reference to the rendering script

• Can be adapted to other compatible types

• It’s the starting point in any domain modelling in Sling

Page 10: Synthetic models

DOMAIN MODELLING

Page 11: Synthetic models

• With Sling, domain modelling should be done against resources

• Each Resource is a collection of properties

– Entirely defined in the repository

– Uniquely identified by it’s sling:resourceType

• The domain model thus is a representation of the type and properties

Page 12: Synthetic models

• There are MANY ways to implement your domain model

– Direct access to resource properties from the view

– A custom mapping framework

– Cognifide’s Slice framework

– Sling Models (available in AEM6 as a standard)

– Neba.io My new favorite!

Page 13: Synthetic models

What if your domain is NOT uniquely defined in the repository?

• Legacy Apps

• 3rd party services

• CRMs

• ERPs

Page 14: Synthetic models

Ask yourselves:

• How do we bring this data into our application?

• How do we expose it to the UI?

• How do we maintain Sling’s RESTful principles?

question mark on road: image via Flickr/ milos milosevic

Page 15: Synthetic models

SYNTHETIC MODELS

Page 16: Synthetic models

• Synthetic Models

– Define domain objects where the domain is not exclusive to the content

repository

– Their property collection is defined against all data sources

– Must be resolvable by Sling’s resource resolution mechanism

– Leverage the Presentation Model design pattern

– Name is inspired by SyntheticResource

Page 17: Synthetic models
Page 18: Synthetic models

• Synthetic Model

– They inherently rely on Sling’s resource resolution mechanism

– A ResourceProvider is required for each external domain object

• Think of this as writing a service to expose the external data

– These ResourceProviders will return either an instance of SyntheticResource or

a custom Resource implementation

• I’d advise caution when deciding on a custom Resource implementation

Page 19: Synthetic models

Writing your Synthetic Models with Neba.io

• Using Neba.io makes it easy!

– In reality you can achieve this with most of the mapping frameworks especially

Sling Models

• Annotation driven

• Integrates the Spring Framework in Sling

• Main features

– Resource Models

– Spring MVC

Page 20: Synthetic models

@ResourceModel(types = "/apps/synthetic-models/components/book")

public class Book {

@This

private Resource resource;

@Path("/content/book-store/bookinfo/${isbn}")

private Resource bookInfo;

private String isbn;

private String imagePath;

private String title;

private String description;

private String genre;

private String author;

The Synthetic Model

A JCR resource reference

External resource reference

Synthetic Model Example

Page 21: Synthetic models

@Component(metatype = false)

@Service

@Properties({

@Property(name="service.description", value="A DB backed Book Resource"),

@Property(name="service.vendor", value="Odecee Pty Ltd"),

@Property(name=ResourceProvider.ROOTS, value="/content/book-store/bookinfo"),

@Property(name=SlingConstants.PROPERTY_RESOURCE_TYPE, value="/apps/synthetic-

models/components/book/book.jsp")

})

public class BookResourceProviderImpl implements BookResourceProvider {

ResourceProvider example

Page 22: Synthetic models

DEMO

Page 23: Synthetic models

QUESTIONS?

Page 24: Synthetic models

THANK YOU!

• Code: http://bit.ly/1tWgSbg• Presentation: SlideShare

Page 25: Synthetic models

Top Related