Date post: | 02-Jul-2015 |
Category: |
Software |
Upload: | zoran-nikolovski |
View: | 164 times |
Download: | 2 times |
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?