Upload
zoran-nikolovski
View
167
Download
2
Embed Size (px)
DESCRIPTION
Synthetic Models are not a new concept – but the concept is rarely used when developing in AEM/Sling/JCR. They Define domain objects where the domain is not exclusive to the content repository Their property collection is defined against the data from each data source Must be orchestrated by Sling’s resource resolution mechanism Leverage the Presentation Model design pattern Name is inspired by the SyntheticResource class This definition came out of several past experiences where data from external sources was required to be brought into AEM and exposed to the presentation layer as if it was content. Also through research on the problem I cam upon the SyntheticResource class. Think of it as the lesser-known cousin of Resource. It is often used to define resource objects that don’t exist in the JCR content tree or resources that are created at run-time
Citation preview
SYNTHETIC MODELS
by Zoran Nikolovski
RESOURCE RESOLUTION
• 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
• 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
• Resolving a Resource is simple
The ResourceResolver
takes in the resource path
• Resolving a Resource is simple
It identifies a suitable
ResourceProvider
The ResourceResolver
takes in the resource path
Which calls it’s getResource
method
• Resolving a Resource is simple
It identifies a suitable
ResourceProvider
The ResourceResolver
will take in the resource path
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
• 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
DOMAIN MODELLING
• 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
• 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!
What if your domain is NOT uniquely defined in the repository?
• Legacy Apps
• 3rd party services
• CRMs
• ERPs
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
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
• 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
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
@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
@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
DEMO
QUESTIONS?