Skip to main content

Posts

Showing posts from July, 2016

Toolkit - Cache Factory

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post describes the Cache Factory the Toolkit uses to store commonly used models. The factory interfaces with an underlying EHCache instance named ' toolkit-cache '. Configuring the cache is possible either using a ehcache.properties file present at run-time in the application's class-path, or in the Toolkit configuration file toolkit.properties . Configuring the Toolkit cache is described in post Installation and Configuration . Creating an EHCache programmatically is described in post Create an EHCache Programmatically . The Cache Factory is used mainly by the Model Factory in its interaction with storing/retrieving JSON models. The factory provides three main operations: get, put, remove. The EHCache stores CacheElement generic objects that are simply Java beans around properties: payload of generic type and a last-check timestamp used in deter...

Toolkit - File System Provider

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post explains the logic in the FileSystemProvider class that perform the actual CRUD operations on the JSON model files as it interacts with the underlying file system. The provider handles also the serialization/deserialization between model objects and JSON by making use of the FasterXML Jackson serializer. The FileSystemProvider is a singleton that implements the following methods: Method create(TcmUri) This is one of the trickier methods of the provider because it has to create different stub objects based on the type of the TcmUri passed as parameter. Namely, it will create either a ComponentMetaImpl or a PageMetaImpl object and it will populate its TcmUri property. I chose to implement this method using reflection, because it can provide more flexibility in the future, in case other types are required to be initialized. public < T extends ...

Toolkit - Model Factory

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post presents the Model Factory, an layer that offers CRUD operations on models backed by a cache and a file system provider. The Model Factory is a singleton that allows the creation, retrieval, update and deletion of a model. It works using a CacheFactory and a File System Provider that acts as a data abstraction layer. The Model Factory works on two types of models only: ComponentMeta and PageMeta. They are both generics passed to the factory methods or inferred from the returned type. Method getOrCreate(TcmUri) This method tries first to read a model from the cache. If it doesn't exist in cache, it tries to read it from the file system provider. If there is no such model on disk, then it will proceed to create a stub model that only has its TcmUri property set. The idea is that the user will populate the other model properties and will execute a up...

Toolkit - JSON Models

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post explains the format of JSON model files, which look typically like this: { "cp" : [ { "c" : 10 , "cnt" : "Rendered CP content" , "pr" : 300 , "p" : 6 , "t" : 15 }, { "c" : 10 , "cnt" : "Rendered CP content" , "pr" : 200 , "p" : 6 , "t" : 25 } ], "cstm" : { "meta" : { "Float" : { "k" : "Price" , "n" : [ 2.0 ], "t" : "NUMERIC" }, "Date" : { "k" : "ArticleDate" , "d" : [ 72602000 ], "t" : "DATE" }, "String" : { "k" :...