Content Model - maksudsharif/Armedia-Training-Module GitHub Wiki

Content Model

If you haven't completed Jeff Pott's tutorial on Content Modelling, read and complete that before following along here.

Content Models are the foundation for all other aspects of customizing Alfresco. Generally a Content Model will outline and provide the overarching goal for a specific type of content. A Content Model includes properties, aspects, associations and constraints which can be used elsewhere. You can choose to display to Share the aforementioned things, or use them as global variables to perform business logic. Content Models also follow a sort of inheritance scheme where you can follow an OO model of development.

The way to create a Content Model is simple:

  • Create a Model xml file that defines it.
  • Add the model location to the dictionaryBootstrap bean.

When creating a Content Model, be sure to understand that you should consider a starting model as permanent. While technically it isn't, deleting definitions in the model.xml file later down the road will cause ambiguous errors that are hard to recover from unless you are willing to start from scratch. Properties previously set to content will persist regardless of whether it exists in the content model or not. Adding properties should also be done with care as previous content will not "inherit" the properties simply because they are of that model type.

If you have completed the Jeff Potts tutorial on Content Models, you should have a good foundation of the types of things that can be done with them. For the assignment, you are going to be extending (or creating a new model) to support your workflows and behaviors.

Things to Know

Structure of a Content Type

Model definitions must follow the model schema or the bootstrap will fail. The link to the schema is: Model Schema Aspects are the easiest way to add common properties that aren't tightly coupled with a content type. Properties can be of any of the base types (d:text, d:boolean, etc.)

When using mandatory properties, make sure to be aware of that when creating new content of that type or setting new properties. Alfresco will not alert you of any mandatory properties but any assumptions made from setting it as mandatory will still give errors.

Types of Base Content

Types Equivalent Java
text java.lang.String
content org.alfresco.service.cmr.repository.ContentData
int java.lang.Integer
long java.lang.Long
float java.lang.Float
double java.lang.Double
date java.util.Date
datetime java.util.Date
boolean java.lang.Boolean
qname(Qualified Name) org.alfresco.service.namespace.QName
category(Reference to a category within a classification) java.lang.String
noderef(Node Reference) org.alfresco.service.cmr.repository.NodeRef
period(Period/duration/cron/...) org.alfresco.service.cmr.repository.Period
path org.alfresco.service.cmr.repository.Path
any java.lang.Object

Model Interfaces

When creating a new model, it is very helpful also create a corresponding Java class (interface for example) that holds the QNames for all definitions of that model. This is helpful when you need to interact with the repository and retrieve properties, check aspects, etc. An example of this shown in the Jeff Potts' tutorials as well as in the included completed demo code.

Assignments

Extend sc:doc

You should add a new type that inherits from sc:doc which adds:

  • Revision status property
  • Aspects to keep track of flags for workflows and folder operations for Publish Folders behavior
  • Aspect to support generateID behavior

If you have completed Content Model tutorial from Jeff Potts, you should have good framework for adding/extending the Content Model to complete the task.